cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % QQQ U U AAA N N TTTTT U U M M % |
| 7 | % Q Q U U A A NN N T U U MM MM % |
| 8 | % Q Q U U AAAAA N N N T U U M M M % |
| 9 | % Q QQ U U A A N NN T U U M M % |
| 10 | % QQQQ UUU A A N N T UUU M M % |
| 11 | % % |
| 12 | % MagicCore Methods to Acquire / Destroy Quantum Pixels % |
| 13 | % % |
| 14 | % Software Design % |
| 15 | % John Cristy % |
| 16 | % October 1998 % |
| 17 | % % |
| 18 | % % |
| 19 | % Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization % |
| 20 | % dedicated to making software imaging solutions freely available. % |
| 21 | % % |
| 22 | % You may not use this file except in compliance with the License. You may % |
| 23 | % obtain a copy of the License at % |
| 24 | % % |
| 25 | % http://www.imagemagick.org/script/license.php % |
| 26 | % % |
| 27 | % Unless required by applicable law or agreed to in writing, software % |
| 28 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 29 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 30 | % See the License for the specific language governing permissions and % |
| 31 | % limitations under the License. % |
| 32 | % % |
| 33 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 34 | % |
| 35 | % |
| 36 | */ |
| 37 | |
| 38 | /* |
| 39 | Include declarations. |
| 40 | */ |
| 41 | #include "magick/studio.h" |
| 42 | #include "magick/property.h" |
| 43 | #include "magick/blob.h" |
| 44 | #include "magick/blob-private.h" |
| 45 | #include "magick/color-private.h" |
| 46 | #include "magick/exception.h" |
| 47 | #include "magick/exception-private.h" |
| 48 | #include "magick/cache.h" |
| 49 | #include "magick/constitute.h" |
| 50 | #include "magick/delegate.h" |
| 51 | #include "magick/geometry.h" |
| 52 | #include "magick/list.h" |
| 53 | #include "magick/magick.h" |
| 54 | #include "magick/memory_.h" |
| 55 | #include "magick/monitor.h" |
| 56 | #include "magick/option.h" |
| 57 | #include "magick/pixel.h" |
| 58 | #include "magick/pixel-private.h" |
| 59 | #include "magick/quantum.h" |
| 60 | #include "magick/quantum-private.h" |
| 61 | #include "magick/resource_.h" |
| 62 | #include "magick/semaphore.h" |
| 63 | #include "magick/statistic.h" |
| 64 | #include "magick/stream.h" |
| 65 | #include "magick/string_.h" |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 66 | #include "magick/string-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 67 | #include "magick/thread-private.h" |
| 68 | #include "magick/utility.h" |
| 69 | |
| 70 | /* |
| 71 | Define declarations. |
| 72 | */ |
| 73 | #define QuantumSignature 0xab |
| 74 | |
| 75 | /* |
| 76 | Forward declarations. |
| 77 | */ |
| 78 | static void |
| 79 | DestroyQuantumPixels(QuantumInfo *); |
| 80 | |
| 81 | /* |
| 82 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 83 | % % |
| 84 | % % |
| 85 | % % |
| 86 | % A c q u i r e Q u a n t u m I n f o % |
| 87 | % % |
| 88 | % % |
| 89 | % % |
| 90 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 91 | % |
| 92 | % AcquireQuantumInfo() allocates the QuantumInfo structure. |
| 93 | % |
| 94 | % The format of the AcquireQuantumInfo method is: |
| 95 | % |
| 96 | % QuantumInfo *AcquireQuantumInfo(const ImageInfo *image_info,Image *image) |
| 97 | % |
| 98 | % A description of each parameter follows: |
| 99 | % |
| 100 | % o image_info: the image info. |
| 101 | % |
| 102 | % o image: the image. |
| 103 | % |
| 104 | */ |
| 105 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 106 | static inline size_t MagickMax(const size_t x, |
| 107 | const size_t y) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 108 | { |
| 109 | if (x > y) |
| 110 | return(x); |
| 111 | return(y); |
| 112 | } |
| 113 | |
| 114 | MagickExport QuantumInfo *AcquireQuantumInfo(const ImageInfo *image_info, |
| 115 | Image *image) |
| 116 | { |
| 117 | MagickBooleanType |
| 118 | status; |
| 119 | |
| 120 | QuantumInfo |
| 121 | *quantum_info; |
| 122 | |
cristy | 9082321 | 2009-12-12 20:48:33 +0000 | [diff] [blame] | 123 | quantum_info=(QuantumInfo *) AcquireAlignedMemory(1,sizeof(*quantum_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 124 | if (quantum_info == (QuantumInfo *) NULL) |
| 125 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 126 | quantum_info->signature=MagickSignature; |
| 127 | GetQuantumInfo(image_info,quantum_info); |
| 128 | if (image == (const Image *) NULL) |
| 129 | return(quantum_info); |
| 130 | status=SetQuantumDepth(image,quantum_info,image->depth); |
| 131 | if (status == MagickFalse) |
| 132 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 133 | return(quantum_info); |
| 134 | } |
| 135 | |
| 136 | /* |
| 137 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 138 | % % |
| 139 | % % |
| 140 | % % |
| 141 | + A c q u i r e Q u a n t u m P i x e l s % |
| 142 | % % |
| 143 | % % |
| 144 | % % |
| 145 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 146 | % |
| 147 | % AcquireQuantumPixels() allocates the unsigned char structure. |
| 148 | % |
| 149 | % The format of the AcquireQuantumPixels method is: |
| 150 | % |
| 151 | % MagickBooleanType AcquireQuantumPixels(QuantumInfo *quantum_info, |
| 152 | % const size_t extent) |
| 153 | % |
| 154 | % A description of each parameter follows: |
| 155 | % |
| 156 | % o quantum_info: the quantum info. |
| 157 | % |
| 158 | % o extent: the quantum info. |
| 159 | % |
| 160 | */ |
| 161 | static MagickBooleanType AcquireQuantumPixels(QuantumInfo *quantum_info, |
| 162 | const size_t extent) |
| 163 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 164 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 165 | i; |
| 166 | |
| 167 | assert(quantum_info != (QuantumInfo *) NULL); |
| 168 | assert(quantum_info->signature == MagickSignature); |
| 169 | quantum_info->number_threads=GetOpenMPMaximumThreads(); |
| 170 | quantum_info->pixels=(unsigned char **) AcquireQuantumMemory( |
| 171 | quantum_info->number_threads,sizeof(*quantum_info->pixels)); |
| 172 | if (quantum_info->pixels == (unsigned char **) NULL) |
| 173 | return(MagickFalse); |
| 174 | quantum_info->extent=extent; |
| 175 | (void) ResetMagickMemory(quantum_info->pixels,0, |
| 176 | sizeof(*quantum_info->pixels)); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 177 | for (i=0; i < (ssize_t) quantum_info->number_threads; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 178 | { |
| 179 | quantum_info->pixels[i]=(unsigned char *) AcquireQuantumMemory(extent+1, |
| 180 | sizeof(**quantum_info->pixels)); |
cristy | 8478793 | 2009-10-06 19:18:19 +0000 | [diff] [blame] | 181 | if (quantum_info->pixels[i] == (unsigned char *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 182 | return(MagickFalse); |
| 183 | (void) ResetMagickMemory(quantum_info->pixels[i],0,(extent+1)* |
| 184 | sizeof(**quantum_info->pixels)); |
| 185 | quantum_info->pixels[i][extent]=QuantumSignature; |
| 186 | } |
| 187 | return(MagickTrue); |
| 188 | } |
| 189 | |
| 190 | /* |
| 191 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 192 | % % |
| 193 | % % |
| 194 | % % |
| 195 | % D e s t r o y Q u a n t u m I n f o % |
| 196 | % % |
| 197 | % % |
| 198 | % % |
| 199 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 200 | % |
| 201 | % DestroyQuantumInfo() deallocates memory associated with the QuantumInfo |
| 202 | % structure. |
| 203 | % |
| 204 | % The format of the DestroyQuantumInfo method is: |
| 205 | % |
| 206 | % QuantumInfo *DestroyQuantumInfo(QuantumInfo *quantum_info) |
| 207 | % |
| 208 | % A description of each parameter follows: |
| 209 | % |
| 210 | % o quantum_info: the quantum info. |
| 211 | % |
| 212 | */ |
| 213 | MagickExport QuantumInfo *DestroyQuantumInfo(QuantumInfo *quantum_info) |
| 214 | { |
| 215 | assert(quantum_info != (QuantumInfo *) NULL); |
| 216 | assert(quantum_info->signature == MagickSignature); |
| 217 | if (quantum_info->pixels != (unsigned char **) NULL) |
| 218 | DestroyQuantumPixels(quantum_info); |
| 219 | if (quantum_info->semaphore != (SemaphoreInfo *) NULL) |
| 220 | DestroySemaphoreInfo(&quantum_info->semaphore); |
| 221 | quantum_info->signature=(~MagickSignature); |
| 222 | quantum_info=(QuantumInfo *) RelinquishMagickMemory(quantum_info); |
| 223 | return(quantum_info); |
| 224 | } |
| 225 | |
| 226 | /* |
| 227 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 228 | % % |
| 229 | % % |
| 230 | % % |
| 231 | + D e s t r o y Q u a n t u m P i x e l s % |
| 232 | % % |
| 233 | % % |
| 234 | % % |
| 235 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 236 | % |
| 237 | % DestroyQuantumPixels() destroys the quantum pixels. |
| 238 | % |
| 239 | % The format of the DestroyQuantumPixels() method is: |
| 240 | % |
| 241 | % void DestroyQuantumPixels(QuantumInfo *quantum_info) |
| 242 | % |
| 243 | % A description of each parameter follows: |
| 244 | % |
| 245 | % o quantum_info: the quantum info. |
| 246 | % |
| 247 | */ |
| 248 | static void DestroyQuantumPixels(QuantumInfo *quantum_info) |
| 249 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 250 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 251 | i; |
| 252 | |
| 253 | assert(quantum_info != (QuantumInfo *) NULL); |
| 254 | assert(quantum_info->signature == MagickSignature); |
| 255 | assert(quantum_info->pixels != (unsigned char **) NULL); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 256 | for (i=0; i < (ssize_t) quantum_info->number_threads; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 257 | { |
cristy | 8744047 | 2010-05-15 14:21:45 +0000 | [diff] [blame] | 258 | /* |
| 259 | Did we overrun our quantum buffer? |
| 260 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 261 | assert(quantum_info->pixels[i][quantum_info->extent] == QuantumSignature); |
| 262 | quantum_info->pixels[i]=(unsigned char *) RelinquishMagickMemory( |
| 263 | quantum_info->pixels[i]); |
| 264 | } |
| 265 | quantum_info->pixels=(unsigned char **) RelinquishMagickMemory( |
| 266 | quantum_info->pixels); |
| 267 | } |
| 268 | |
| 269 | /* |
| 270 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 271 | % % |
| 272 | % % |
| 273 | % % |
| 274 | % G e t Q u a n t u m E x t e n t % |
| 275 | % % |
| 276 | % % |
| 277 | % % |
| 278 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 279 | % |
| 280 | % GetQuantumExtent() returns the quantum pixel buffer extent. |
| 281 | % |
| 282 | % The format of the GetQuantumExtent method is: |
| 283 | % |
| 284 | % size_t GetQuantumExtent(Image *image,const QuantumInfo *quantum_info, |
| 285 | % const QuantumType quantum_type) |
| 286 | % |
| 287 | % A description of each parameter follows: |
| 288 | % |
| 289 | % o image: the image. |
| 290 | % |
| 291 | % o quantum_info: the quantum info. |
| 292 | % |
| 293 | % o quantum_type: Declare which pixel components to transfer (red, green, |
| 294 | % blue, opacity, RGB, or RGBA). |
| 295 | % |
| 296 | */ |
| 297 | MagickExport size_t GetQuantumExtent(const Image *image, |
| 298 | const QuantumInfo *quantum_info,const QuantumType quantum_type) |
| 299 | { |
| 300 | size_t |
| 301 | packet_size; |
| 302 | |
| 303 | assert(quantum_info != (QuantumInfo *) NULL); |
| 304 | assert(quantum_info->signature == MagickSignature); |
| 305 | packet_size=1; |
| 306 | switch (quantum_type) |
| 307 | { |
| 308 | case GrayAlphaQuantum: packet_size=2; break; |
| 309 | case IndexAlphaQuantum: packet_size=2; break; |
| 310 | case RGBQuantum: packet_size=3; break; |
| 311 | case RGBAQuantum: packet_size=4; break; |
cristy | 4a16cd5 | 2010-01-05 14:04:01 +0000 | [diff] [blame] | 312 | case BGRAQuantum: packet_size=4; break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 313 | case RGBOQuantum: packet_size=4; break; |
| 314 | case CMYKQuantum: packet_size=4; break; |
| 315 | case CMYKAQuantum: packet_size=5; break; |
| 316 | default: break; |
| 317 | } |
| 318 | if (quantum_info->pack == MagickFalse) |
cristy | c9672a9 | 2010-01-06 00:57:45 +0000 | [diff] [blame] | 319 | return((size_t) (packet_size*image->columns*((quantum_info->depth+7)/8))); |
| 320 | return((size_t) ((packet_size*image->columns*quantum_info->depth+7)/8)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | /* |
| 324 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 325 | % % |
| 326 | % % |
| 327 | % % |
| 328 | % G e t Q u a n t u m I n f o % |
| 329 | % % |
| 330 | % % |
| 331 | % % |
| 332 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 333 | % |
| 334 | % GetQuantumInfo() initializes the QuantumInfo structure to default values. |
| 335 | % |
| 336 | % The format of the GetQuantumInfo method is: |
| 337 | % |
| 338 | % GetQuantumInfo(const ImageInfo *image_info,QuantumInfo *quantum_info) |
| 339 | % |
| 340 | % A description of each parameter follows: |
| 341 | % |
| 342 | % o image_info: the image info. |
| 343 | % |
| 344 | % o quantum_info: the quantum info. |
| 345 | % |
| 346 | */ |
| 347 | MagickExport void GetQuantumInfo(const ImageInfo *image_info, |
| 348 | QuantumInfo *quantum_info) |
| 349 | { |
| 350 | const char |
| 351 | *option; |
| 352 | |
| 353 | assert(quantum_info != (QuantumInfo *) NULL); |
| 354 | (void) ResetMagickMemory(quantum_info,0,sizeof(*quantum_info)); |
| 355 | quantum_info->quantum=8; |
| 356 | quantum_info->maximum=1.0; |
| 357 | quantum_info->scale=QuantumRange; |
| 358 | quantum_info->pack=MagickTrue; |
| 359 | quantum_info->semaphore=AllocateSemaphoreInfo(); |
| 360 | quantum_info->signature=MagickSignature; |
| 361 | if (image_info == (const ImageInfo *) NULL) |
| 362 | return; |
| 363 | option=GetImageOption(image_info,"quantum:format"); |
| 364 | if (option != (char *) NULL) |
| 365 | quantum_info->format=(QuantumFormatType) ParseMagickOption( |
| 366 | MagickQuantumFormatOptions,MagickFalse,option); |
| 367 | option=GetImageOption(image_info,"quantum:minimum"); |
| 368 | if (option != (char *) NULL) |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 369 | quantum_info->minimum=StringToDouble(option); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 370 | option=GetImageOption(image_info,"quantum:maximum"); |
| 371 | if (option != (char *) NULL) |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 372 | quantum_info->maximum=StringToDouble(option); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 373 | if ((quantum_info->minimum == 0.0) && (quantum_info->maximum == 0.0)) |
| 374 | quantum_info->scale=0.0; |
| 375 | else |
| 376 | if (quantum_info->minimum == quantum_info->maximum) |
| 377 | { |
| 378 | quantum_info->scale=(MagickRealType) QuantumRange/quantum_info->minimum; |
| 379 | quantum_info->minimum=0.0; |
| 380 | } |
| 381 | else |
| 382 | quantum_info->scale=(MagickRealType) QuantumRange/(quantum_info->maximum- |
| 383 | quantum_info->minimum); |
| 384 | option=GetImageOption(image_info,"quantum:scale"); |
| 385 | if (option != (char *) NULL) |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 386 | quantum_info->scale=StringToDouble(option); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 387 | option=GetImageOption(image_info,"quantum:polarity"); |
| 388 | if (option != (char *) NULL) |
| 389 | quantum_info->min_is_white=LocaleCompare(option,"min-is-white") == 0 ? |
| 390 | MagickTrue : MagickFalse; |
| 391 | } |
| 392 | |
| 393 | /* |
| 394 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 395 | % % |
| 396 | % % |
| 397 | % % |
| 398 | % G e t Q u a n t u m P i x e l s % |
| 399 | % % |
| 400 | % % |
| 401 | % % |
| 402 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 403 | % |
| 404 | % GetQuantumPixels() returns the quantum pixels. |
| 405 | % |
| 406 | % The format of the GetQuantumPixels method is: |
| 407 | % |
| 408 | % unsigned char *QuantumPixels GetQuantumPixels( |
| 409 | % const QuantumInfo *quantum_info) |
| 410 | % |
| 411 | % A description of each parameter follows: |
| 412 | % |
| 413 | % o image: the image. |
| 414 | % |
| 415 | */ |
| 416 | MagickExport unsigned char *GetQuantumPixels(const QuantumInfo *quantum_info) |
| 417 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 418 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 419 | id; |
| 420 | |
| 421 | assert(quantum_info != (QuantumInfo *) NULL); |
| 422 | assert(quantum_info->signature == MagickSignature); |
| 423 | id=GetOpenMPThreadId(); |
| 424 | return(quantum_info->pixels[id]); |
| 425 | } |
| 426 | |
| 427 | /* |
| 428 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 429 | % % |
| 430 | % % |
| 431 | % % |
| 432 | % G e t Q u a n t u m T y p e % |
| 433 | % % |
| 434 | % % |
| 435 | % % |
| 436 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 437 | % |
| 438 | % GetQuantumType() returns the quantum type of the image. |
| 439 | % |
| 440 | % The format of the GetQuantumType method is: |
| 441 | % |
| 442 | % QuantumType GetQuantumType(Image *image,ExceptionInfo *exception) |
| 443 | % |
| 444 | % A description of each parameter follows: |
| 445 | % |
| 446 | % o image: the image. |
| 447 | % |
| 448 | */ |
| 449 | MagickExport QuantumType GetQuantumType(Image *image,ExceptionInfo *exception) |
| 450 | { |
| 451 | QuantumType |
| 452 | quantum_type; |
| 453 | |
| 454 | assert(image != (Image *) NULL); |
| 455 | assert(image->signature == MagickSignature); |
| 456 | if (image->debug != MagickFalse) |
| 457 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 458 | quantum_type=RGBQuantum; |
| 459 | if (image->matte != MagickFalse) |
| 460 | quantum_type=RGBAQuantum; |
| 461 | if (image->colorspace == CMYKColorspace) |
| 462 | { |
| 463 | quantum_type=CMYKQuantum; |
| 464 | if (image->matte != MagickFalse) |
| 465 | quantum_type=CMYKAQuantum; |
| 466 | } |
| 467 | if (IsGrayImage(image,exception) != MagickFalse) |
| 468 | { |
| 469 | quantum_type=GrayQuantum; |
| 470 | if (image->matte != MagickFalse) |
| 471 | quantum_type=GrayAlphaQuantum; |
| 472 | } |
| 473 | else |
| 474 | if (image->storage_class == PseudoClass) |
| 475 | { |
| 476 | quantum_type=IndexQuantum; |
| 477 | if (image->matte != MagickFalse) |
| 478 | quantum_type=IndexAlphaQuantum; |
| 479 | } |
| 480 | return(quantum_type); |
| 481 | } |
| 482 | |
| 483 | /* |
| 484 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 485 | % % |
| 486 | % % |
| 487 | % % |
| 488 | % S e t Q u a n t u m F o r m a t % |
| 489 | % % |
| 490 | % % |
| 491 | % % |
| 492 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 493 | % |
| 494 | % SetQuantumAlphaType() sets the quantum format. |
| 495 | % |
| 496 | % The format of the SetQuantumAlphaType method is: |
| 497 | % |
| 498 | % void SetQuantumAlphaType(QuantumInfo *quantum_info, |
| 499 | % const QuantumAlphaType type) |
| 500 | % |
| 501 | % A description of each parameter follows: |
| 502 | % |
| 503 | % o quantum_info: the quantum info. |
| 504 | % |
| 505 | % o type: the alpha type (e.g. associate). |
| 506 | % |
| 507 | */ |
| 508 | MagickExport void SetQuantumAlphaType(QuantumInfo *quantum_info, |
| 509 | const QuantumAlphaType type) |
| 510 | { |
| 511 | assert(quantum_info != (QuantumInfo *) NULL); |
| 512 | assert(quantum_info->signature == MagickSignature); |
| 513 | quantum_info->alpha_type=type; |
| 514 | } |
| 515 | |
| 516 | /* |
| 517 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 518 | % % |
| 519 | % % |
| 520 | % % |
| 521 | % S e t Q u a n t u m D e p t h % |
| 522 | % % |
| 523 | % % |
| 524 | % % |
| 525 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 526 | % |
| 527 | % SetQuantumDepth() sets the quantum depth. |
| 528 | % |
| 529 | % The format of the SetQuantumDepth method is: |
| 530 | % |
| 531 | % MagickBooleanType SetQuantumDepth(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 532 | % QuantumInfo *quantum_info,const size_t depth) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 533 | % |
| 534 | % A description of each parameter follows: |
| 535 | % |
| 536 | % o image: the image. |
| 537 | % |
| 538 | % o quantum_info: the quantum info. |
| 539 | % |
| 540 | % o depth: the quantum depth. |
| 541 | % |
| 542 | */ |
| 543 | MagickExport MagickBooleanType SetQuantumDepth(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 544 | QuantumInfo *quantum_info,const size_t depth) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 545 | { |
| 546 | MagickBooleanType |
| 547 | status; |
| 548 | |
| 549 | /* |
| 550 | Allocate the quantum pixel buffer. |
| 551 | */ |
| 552 | assert(image != (Image *) NULL); |
| 553 | assert(image->signature == MagickSignature); |
| 554 | if (image->debug != MagickFalse) |
| 555 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 556 | assert(quantum_info != (QuantumInfo *) NULL); |
| 557 | assert(quantum_info->signature == MagickSignature); |
| 558 | quantum_info->depth=depth; |
| 559 | if (quantum_info->format == FloatingPointQuantumFormat) |
| 560 | { |
| 561 | if (quantum_info->depth > 32) |
| 562 | quantum_info->depth=64; |
| 563 | else |
cristy | c9672a9 | 2010-01-06 00:57:45 +0000 | [diff] [blame] | 564 | if (quantum_info->depth > 16) |
| 565 | quantum_info->depth=32; |
| 566 | else |
| 567 | quantum_info->depth=16; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 568 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 569 | if (quantum_info->pixels != (unsigned char **) NULL) |
| 570 | DestroyQuantumPixels(quantum_info); |
cristy | a327432 | 2010-05-14 23:22:12 +0000 | [diff] [blame] | 571 | status=AcquireQuantumPixels(quantum_info,(6+quantum_info->pad)*image->columns* |
cristy | 2dfdad3 | 2010-05-15 14:15:35 +0000 | [diff] [blame] | 572 | ((quantum_info->depth+7)/8)); /* allow for CMYKA + RLE byte + pad */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 573 | return(status); |
| 574 | } |
| 575 | |
| 576 | /* |
| 577 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 578 | % % |
| 579 | % % |
| 580 | % % |
| 581 | % S e t Q u a n t u m F o r m a t % |
| 582 | % % |
| 583 | % % |
| 584 | % % |
| 585 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 586 | % |
| 587 | % SetQuantumFormat() sets the quantum format. |
| 588 | % |
| 589 | % The format of the SetQuantumFormat method is: |
| 590 | % |
| 591 | % MagickBooleanType SetQuantumFormat(const Image *image, |
| 592 | % QuantumInfo *quantum_info,const QuantumFormatType format) |
| 593 | % |
| 594 | % A description of each parameter follows: |
| 595 | % |
| 596 | % o image: the image. |
| 597 | % |
| 598 | % o quantum_info: the quantum info. |
| 599 | % |
| 600 | % o format: the quantum format. |
| 601 | % |
| 602 | */ |
| 603 | MagickExport MagickBooleanType SetQuantumFormat(const Image *image, |
| 604 | QuantumInfo *quantum_info,const QuantumFormatType format) |
| 605 | { |
| 606 | assert(image != (Image *) NULL); |
| 607 | assert(image->signature == MagickSignature); |
| 608 | if (image->debug != MagickFalse) |
| 609 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 610 | assert(quantum_info != (QuantumInfo *) NULL); |
| 611 | assert(quantum_info->signature == MagickSignature); |
| 612 | quantum_info->format=format; |
| 613 | return(SetQuantumDepth(image,quantum_info,quantum_info->depth)); |
| 614 | } |
| 615 | |
| 616 | /* |
| 617 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 618 | % % |
| 619 | % % |
| 620 | % % |
| 621 | % S e t Q u a n t u m I m a g e T y p e % |
| 622 | % % |
| 623 | % % |
| 624 | % % |
| 625 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 626 | % |
| 627 | % SetQuantumImageType() sets the image type based on the quantum type. |
| 628 | % |
| 629 | % The format of the SetQuantumImageType method is: |
| 630 | % |
| 631 | % void ImageType SetQuantumImageType(Image *image, |
| 632 | % const QuantumType quantum_type) |
| 633 | % |
| 634 | % A description of each parameter follows: |
| 635 | % |
| 636 | % o image: the image. |
| 637 | % |
| 638 | % o quantum_type: Declare which pixel components to transfer (red, green, |
| 639 | % blue, opacity, RGB, or RGBA). |
| 640 | % |
| 641 | */ |
| 642 | MagickExport void SetQuantumImageType(Image *image, |
| 643 | const QuantumType quantum_type) |
| 644 | { |
| 645 | assert(image != (Image *) NULL); |
| 646 | assert(image->signature == MagickSignature); |
| 647 | if (image->debug != MagickFalse) |
| 648 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 649 | switch (quantum_type) |
| 650 | { |
| 651 | case IndexQuantum: |
| 652 | case IndexAlphaQuantum: |
| 653 | { |
| 654 | image->type=PaletteType; |
| 655 | break; |
| 656 | } |
| 657 | case GrayQuantum: |
| 658 | case GrayAlphaQuantum: |
| 659 | { |
| 660 | image->type=GrayscaleType; |
| 661 | if (image->depth == 1) |
| 662 | image->type=BilevelType; |
| 663 | break; |
| 664 | } |
| 665 | case CyanQuantum: |
| 666 | case MagentaQuantum: |
| 667 | case YellowQuantum: |
| 668 | case BlackQuantum: |
| 669 | case CMYKQuantum: |
| 670 | case CMYKAQuantum: |
| 671 | { |
| 672 | image->type=ColorSeparationType; |
| 673 | break; |
| 674 | } |
| 675 | default: |
| 676 | { |
| 677 | image->type=TrueColorType; |
| 678 | break; |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | /* |
| 684 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 685 | % % |
| 686 | % % |
| 687 | % % |
| 688 | % S e t Q u a n t u m P a c k % |
| 689 | % % |
| 690 | % % |
| 691 | % % |
| 692 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 693 | % |
| 694 | % SetQuantumPack() sets the quantum pack flag. |
| 695 | % |
| 696 | % The format of the SetQuantumPack method is: |
| 697 | % |
| 698 | % void SetQuantumPack(QuantumInfo *quantum_info, |
| 699 | % const MagickBooleanType pack) |
| 700 | % |
| 701 | % A description of each parameter follows: |
| 702 | % |
| 703 | % o quantum_info: the quantum info. |
| 704 | % |
| 705 | % o pack: the pack flag. |
| 706 | % |
| 707 | */ |
| 708 | MagickExport void SetQuantumPack(QuantumInfo *quantum_info, |
| 709 | const MagickBooleanType pack) |
| 710 | { |
| 711 | assert(quantum_info != (QuantumInfo *) NULL); |
| 712 | assert(quantum_info->signature == MagickSignature); |
| 713 | quantum_info->pack=pack; |
| 714 | } |
| 715 | |
| 716 | |
| 717 | /* |
| 718 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 719 | % % |
| 720 | % % |
| 721 | % % |
| 722 | % S e t Q u a n t u m P a d % |
| 723 | % % |
| 724 | % % |
| 725 | % % |
| 726 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 727 | % |
| 728 | % SetQuantumPad() sets the quantum pad. |
| 729 | % |
| 730 | % The format of the SetQuantumPad method is: |
| 731 | % |
| 732 | % MagickBooleanType SetQuantumPad(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 733 | % QuantumInfo *quantum_info,const size_t pad) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 734 | % |
| 735 | % A description of each parameter follows: |
| 736 | % |
| 737 | % o image: the image. |
| 738 | % |
| 739 | % o quantum_info: the quantum info. |
| 740 | % |
| 741 | % o pad: the quantum pad. |
| 742 | % |
| 743 | */ |
| 744 | MagickExport MagickBooleanType SetQuantumPad(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 745 | QuantumInfo *quantum_info,const size_t pad) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 746 | { |
| 747 | assert(image != (Image *) NULL); |
| 748 | assert(image->signature == MagickSignature); |
| 749 | if (image->debug != MagickFalse) |
| 750 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 751 | assert(quantum_info != (QuantumInfo *) NULL); |
| 752 | assert(quantum_info->signature == MagickSignature); |
| 753 | quantum_info->pad=pad; |
| 754 | return(SetQuantumDepth(image,quantum_info,quantum_info->depth)); |
| 755 | } |
| 756 | |
| 757 | /* |
| 758 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 759 | % % |
| 760 | % % |
| 761 | % % |
| 762 | % S e t Q u a n t u m M i n I s W h i t e % |
| 763 | % % |
| 764 | % % |
| 765 | % % |
| 766 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 767 | % |
| 768 | % SetQuantumMinIsWhite() sets the quantum min-is-white flag. |
| 769 | % |
| 770 | % The format of the SetQuantumMinIsWhite method is: |
| 771 | % |
| 772 | % void SetQuantumMinIsWhite(QuantumInfo *quantum_info, |
| 773 | % const MagickBooleanType min_is_white) |
| 774 | % |
| 775 | % A description of each parameter follows: |
| 776 | % |
| 777 | % o quantum_info: the quantum info. |
| 778 | % |
| 779 | % o min_is_white: the min-is-white flag. |
| 780 | % |
| 781 | */ |
| 782 | MagickExport void SetQuantumMinIsWhite(QuantumInfo *quantum_info, |
| 783 | const MagickBooleanType min_is_white) |
| 784 | { |
| 785 | assert(quantum_info != (QuantumInfo *) NULL); |
| 786 | assert(quantum_info->signature == MagickSignature); |
| 787 | quantum_info->min_is_white=min_is_white; |
| 788 | } |
| 789 | |
| 790 | /* |
| 791 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 792 | % % |
| 793 | % % |
| 794 | % % |
| 795 | % S e t Q u a n t u m Q u a n t u m % |
| 796 | % % |
| 797 | % % |
| 798 | % % |
| 799 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 800 | % |
| 801 | % SetQuantumQuantum() sets the quantum quantum. |
| 802 | % |
| 803 | % The format of the SetQuantumQuantum method is: |
| 804 | % |
| 805 | % void SetQuantumQuantum(QuantumInfo *quantum_info, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 806 | % const size_t quantum) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 807 | % |
| 808 | % A description of each parameter follows: |
| 809 | % |
| 810 | % o quantum_info: the quantum info. |
| 811 | % |
| 812 | % o quantum: the quantum quantum. |
| 813 | % |
| 814 | */ |
| 815 | MagickExport void SetQuantumQuantum(QuantumInfo *quantum_info, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 816 | const size_t quantum) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 817 | { |
| 818 | assert(quantum_info != (QuantumInfo *) NULL); |
| 819 | assert(quantum_info->signature == MagickSignature); |
| 820 | quantum_info->quantum=quantum; |
| 821 | } |
| 822 | |
| 823 | /* |
| 824 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 825 | % % |
| 826 | % % |
| 827 | % % |
| 828 | % S e t Q u a n t u m S c a l e % |
| 829 | % % |
| 830 | % % |
| 831 | % % |
| 832 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 833 | % |
| 834 | % SetQuantumScale() sets the quantum scale. |
| 835 | % |
| 836 | % The format of the SetQuantumScale method is: |
| 837 | % |
| 838 | % void SetQuantumScale(QuantumInfo *quantum_info,const double scale) |
| 839 | % |
| 840 | % A description of each parameter follows: |
| 841 | % |
| 842 | % o quantum_info: the quantum info. |
| 843 | % |
| 844 | % o scale: the quantum scale. |
| 845 | % |
| 846 | */ |
| 847 | MagickExport void SetQuantumScale(QuantumInfo *quantum_info,const double scale) |
| 848 | { |
| 849 | assert(quantum_info != (QuantumInfo *) NULL); |
| 850 | assert(quantum_info->signature == MagickSignature); |
| 851 | quantum_info->scale=scale; |
| 852 | } |