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