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