]> granicus.if.org Git - imagemagick/blob - magick/quantum.c
minor note
[imagemagick] / magick / quantum.c
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 \f
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"
66 #include "magick/string-private.h"
67 #include "magick/thread-private.h"
68 #include "magick/utility.h"
69 \f
70 /*
71   Define declarations.
72 */
73 #define QuantumSignature  0xab
74 \f
75 /*
76   Forward declarations.
77 */
78 static void
79   DestroyQuantumPixels(QuantumInfo *);
80 \f
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
106 static inline size_t MagickMax(const size_t x,
107   const size_t y)
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
123   quantum_info=(QuantumInfo *) AcquireMagickMemory(sizeof(*quantum_info));
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 \f
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 {
164   register ssize_t
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     quantum_info->number_threads*sizeof(*quantum_info->pixels));
177   for (i=0; i < (ssize_t) quantum_info->number_threads; i++)
178   {
179     quantum_info->pixels[i]=(unsigned char *) AcquireQuantumMemory(extent+1,
180       sizeof(**quantum_info->pixels));
181     if (quantum_info->pixels[i] == (unsigned char *) NULL)
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 \f
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 \f
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 {
250   register ssize_t
251     i;
252
253   ssize_t
254     extent;
255
256   assert(quantum_info != (QuantumInfo *) NULL);
257   assert(quantum_info->signature == MagickSignature);
258   assert(quantum_info->pixels != (unsigned char **) NULL);
259   extent=(ssize_t) quantum_info->extent;
260   for (i=0; i < (ssize_t) quantum_info->number_threads; i++)
261     if (quantum_info->pixels[i] != (unsigned char *) NULL)
262       {
263         /*
264           Did we overrun our quantum buffer?
265         */
266         assert(quantum_info->pixels[i][extent] == QuantumSignature);
267         quantum_info->pixels[i]=(unsigned char *) RelinquishMagickMemory(
268           quantum_info->pixels[i]);
269       }
270   quantum_info->pixels=(unsigned char **) RelinquishMagickMemory(
271     quantum_info->pixels);
272 }
273 \f
274 /*
275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
276 %                                                                             %
277 %                                                                             %
278 %                                                                             %
279 %   G e t Q u a n t u m E x t e n t                                           %
280 %                                                                             %
281 %                                                                             %
282 %                                                                             %
283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
284 %
285 %  GetQuantumExtent() returns the quantum pixel buffer extent.
286 %
287 %  The format of the GetQuantumExtent method is:
288 %
289 %      size_t GetQuantumExtent(Image *image,const QuantumInfo *quantum_info,
290 %        const QuantumType quantum_type)
291 %
292 %  A description of each parameter follows:
293 %
294 %    o image: the image.
295 %
296 %    o quantum_info: the quantum info.
297 %
298 %    o quantum_type: Declare which pixel components to transfer (red, green,
299 %      blue, opacity, RGB, or RGBA).
300 %
301 */
302 MagickExport size_t GetQuantumExtent(const Image *image,
303   const QuantumInfo *quantum_info,const QuantumType quantum_type)
304 {
305   size_t
306     packet_size;
307
308   assert(quantum_info != (QuantumInfo *) NULL);
309   assert(quantum_info->signature == MagickSignature);
310   packet_size=1;
311   switch (quantum_type)
312   {
313     case GrayAlphaQuantum: packet_size=2; break;
314     case IndexAlphaQuantum: packet_size=2; break;
315     case RGBQuantum: packet_size=3; break;
316     case BGRQuantum: packet_size=3; break;
317     case RGBAQuantum: packet_size=4; break;
318     case RGBOQuantum: packet_size=4; break;
319     case BGRAQuantum: packet_size=4; break;
320     case CMYKQuantum: packet_size=4; break;
321     case CMYKAQuantum: packet_size=5; break;
322     default: break;
323   }
324   if (quantum_info->pack == MagickFalse)
325     return((size_t) (packet_size*image->columns*((quantum_info->depth+7)/8)));
326   return((size_t) ((packet_size*image->columns*quantum_info->depth+7)/8));
327 }
328 \f
329 /*
330 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
331 %                                                                             %
332 %                                                                             %
333 %                                                                             %
334 %   G e t Q u a n t u m I n f o                                               %
335 %                                                                             %
336 %                                                                             %
337 %                                                                             %
338 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
339 %
340 %  GetQuantumInfo() initializes the QuantumInfo structure to default values.
341 %
342 %  The format of the GetQuantumInfo method is:
343 %
344 %      GetQuantumInfo(const ImageInfo *image_info,QuantumInfo *quantum_info)
345 %
346 %  A description of each parameter follows:
347 %
348 %    o image_info: the image info.
349 %
350 %    o quantum_info: the quantum info.
351 %
352 */
353 MagickExport void GetQuantumInfo(const ImageInfo *image_info,
354   QuantumInfo *quantum_info)
355 {
356   const char
357     *option;
358
359   assert(quantum_info != (QuantumInfo *) NULL);
360   (void) ResetMagickMemory(quantum_info,0,sizeof(*quantum_info));
361   quantum_info->quantum=8;
362   quantum_info->maximum=1.0;
363   quantum_info->scale=QuantumRange;
364   quantum_info->pack=MagickTrue;
365   quantum_info->semaphore=AllocateSemaphoreInfo();
366   quantum_info->signature=MagickSignature;
367   if (image_info == (const ImageInfo *) NULL)
368     return;
369   option=GetImageOption(image_info,"quantum:format");
370   if (option != (char *) NULL)
371     quantum_info->format=(QuantumFormatType) ParseMagickOption(
372       MagickQuantumFormatOptions,MagickFalse,option);
373   option=GetImageOption(image_info,"quantum:minimum");
374   if (option != (char *) NULL)
375     quantum_info->minimum=StringToDouble(option);
376   option=GetImageOption(image_info,"quantum:maximum");
377   if (option != (char *) NULL)
378     quantum_info->maximum=StringToDouble(option);
379   if ((quantum_info->minimum == 0.0) && (quantum_info->maximum == 0.0))
380     quantum_info->scale=0.0;
381   else
382     if (quantum_info->minimum == quantum_info->maximum)
383       {
384         quantum_info->scale=(MagickRealType) QuantumRange/quantum_info->minimum;
385         quantum_info->minimum=0.0;
386       }
387     else
388       quantum_info->scale=(MagickRealType) QuantumRange/(quantum_info->maximum-
389         quantum_info->minimum);
390   option=GetImageOption(image_info,"quantum:scale");
391   if (option != (char *) NULL)
392     quantum_info->scale=StringToDouble(option);
393   option=GetImageOption(image_info,"quantum:polarity");
394   if (option != (char *) NULL)
395     quantum_info->min_is_white=LocaleCompare(option,"min-is-white") == 0 ?
396       MagickTrue : MagickFalse;
397 }
398 \f
399 /*
400 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
401 %                                                                             %
402 %                                                                             %
403 %                                                                             %
404 %   G e t Q u a n t u m P i x e l s                                           %
405 %                                                                             %
406 %                                                                             %
407 %                                                                             %
408 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
409 %
410 %  GetQuantumPixels() returns the quantum pixels.
411 %
412 %  The format of the GetQuantumPixels method is:
413 %
414 %      unsigned char *QuantumPixels GetQuantumPixels(
415 %        const QuantumInfo *quantum_info)
416 %
417 %  A description of each parameter follows:
418 %
419 %    o image: the image.
420 %
421 */
422 MagickExport unsigned char *GetQuantumPixels(const QuantumInfo *quantum_info)
423 {
424   const int
425     id = GetOpenMPThreadId();
426
427   assert(quantum_info != (QuantumInfo *) NULL);
428   assert(quantum_info->signature == MagickSignature);
429   return(quantum_info->pixels[id]);
430 }
431 \f
432 /*
433 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
434 %                                                                             %
435 %                                                                             %
436 %                                                                             %
437 %   G e t Q u a n t u m T y p e                                               %
438 %                                                                             %
439 %                                                                             %
440 %                                                                             %
441 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
442 %
443 %  GetQuantumType() returns the quantum type of the image.
444 %
445 %  The format of the GetQuantumType method is:
446 %
447 %      QuantumType GetQuantumType(Image *image,ExceptionInfo *exception)
448 %
449 %  A description of each parameter follows:
450 %
451 %    o image: the image.
452 %
453 */
454 MagickExport QuantumType GetQuantumType(Image *image,ExceptionInfo *exception)
455 {
456   QuantumType
457     quantum_type;
458
459   assert(image != (Image *) NULL);
460   assert(image->signature == MagickSignature);
461   if (image->debug != MagickFalse)
462     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
463   quantum_type=RGBQuantum;
464   if (image->matte != MagickFalse)
465     quantum_type=RGBAQuantum;
466   if (image->colorspace == CMYKColorspace)
467     {
468       quantum_type=CMYKQuantum;
469       if (image->matte != MagickFalse)
470         quantum_type=CMYKAQuantum;
471     }
472   if (IsGrayImage(image,exception) != MagickFalse)
473     {
474       quantum_type=GrayQuantum;
475       if (image->matte != MagickFalse)
476         quantum_type=GrayAlphaQuantum;
477     }
478   else
479     if (image->storage_class == PseudoClass)
480       {
481         quantum_type=IndexQuantum;
482         if (image->matte != MagickFalse)
483           quantum_type=IndexAlphaQuantum;
484       }
485   return(quantum_type);
486 }
487 \f
488 /*
489 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
490 %                                                                             %
491 %                                                                             %
492 %                                                                             %
493 %   S e t Q u a n t u m F o r m a t                                           %
494 %                                                                             %
495 %                                                                             %
496 %                                                                             %
497 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
498 %
499 %  SetQuantumAlphaType() sets the quantum format.
500 %
501 %  The format of the SetQuantumAlphaType method is:
502 %
503 %      void SetQuantumAlphaType(QuantumInfo *quantum_info,
504 %        const QuantumAlphaType type)
505 %
506 %  A description of each parameter follows:
507 %
508 %    o quantum_info: the quantum info.
509 %
510 %    o type: the alpha type (e.g. associate).
511 %
512 */
513 MagickExport void SetQuantumAlphaType(QuantumInfo *quantum_info,
514   const QuantumAlphaType type)
515 {
516   assert(quantum_info != (QuantumInfo *) NULL);
517   assert(quantum_info->signature == MagickSignature);
518   quantum_info->alpha_type=type;
519 }
520 \f
521 /*
522 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
523 %                                                                             %
524 %                                                                             %
525 %                                                                             %
526 %   S e t Q u a n t u m D e p t h                                             %
527 %                                                                             %
528 %                                                                             %
529 %                                                                             %
530 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
531 %
532 %  SetQuantumDepth() sets the quantum depth.
533 %
534 %  The format of the SetQuantumDepth method is:
535 %
536 %      MagickBooleanType SetQuantumDepth(const Image *image,
537 %        QuantumInfo *quantum_info,const size_t depth)
538 %
539 %  A description of each parameter follows:
540 %
541 %    o image: the image.
542 %
543 %    o quantum_info: the quantum info.
544 %
545 %    o depth: the quantum depth.
546 %
547 */
548 MagickExport MagickBooleanType SetQuantumDepth(const Image *image,
549   QuantumInfo *quantum_info,const size_t depth)
550 {
551   MagickBooleanType
552     status;
553
554   /*
555     Allocate the quantum pixel buffer.
556   */
557   assert(image != (Image *) NULL);
558   assert(image->signature == MagickSignature);
559   if (image->debug != MagickFalse)
560     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
561   assert(quantum_info != (QuantumInfo *) NULL);
562   assert(quantum_info->signature == MagickSignature);
563   quantum_info->depth=depth;
564   if (quantum_info->format == FloatingPointQuantumFormat)
565     {
566       if (quantum_info->depth > 32)
567         quantum_info->depth=64;
568       else
569         if (quantum_info->depth > 16)
570           quantum_info->depth=32;
571         else
572           quantum_info->depth=16;
573     }
574   if (quantum_info->pixels != (unsigned char **) NULL)
575     DestroyQuantumPixels(quantum_info);
576   status=AcquireQuantumPixels(quantum_info,(6+quantum_info->pad)*image->columns*
577     ((quantum_info->depth+7)/8));  /* allow for CMYKA + RLE byte + pad */
578   return(status);
579 }
580 \f
581 /*
582 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
583 %                                                                             %
584 %                                                                             %
585 %                                                                             %
586 %   S e t Q u a n t u m F o r m a t                                           %
587 %                                                                             %
588 %                                                                             %
589 %                                                                             %
590 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
591 %
592 %  SetQuantumFormat() sets the quantum format.
593 %
594 %  The format of the SetQuantumFormat method is:
595 %
596 %      MagickBooleanType SetQuantumFormat(const Image *image,
597 %        QuantumInfo *quantum_info,const QuantumFormatType format)
598 %
599 %  A description of each parameter follows:
600 %
601 %    o image: the image.
602 %
603 %    o quantum_info: the quantum info.
604 %
605 %    o format: the quantum format.
606 %
607 */
608 MagickExport MagickBooleanType SetQuantumFormat(const Image *image,
609   QuantumInfo *quantum_info,const QuantumFormatType format)
610 {
611   assert(image != (Image *) NULL);
612   assert(image->signature == MagickSignature);
613   if (image->debug != MagickFalse)
614     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
615   assert(quantum_info != (QuantumInfo *) NULL);
616   assert(quantum_info->signature == MagickSignature);
617   quantum_info->format=format;
618   return(SetQuantumDepth(image,quantum_info,quantum_info->depth));
619 }
620 \f
621 /*
622 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
623 %                                                                             %
624 %                                                                             %
625 %                                                                             %
626 %   S e t Q u a n t u m I m a g e T y p e                                     %
627 %                                                                             %
628 %                                                                             %
629 %                                                                             %
630 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
631 %
632 %  SetQuantumImageType() sets the image type based on the quantum type.
633 %
634 %  The format of the SetQuantumImageType method is:
635 %
636 %      void ImageType SetQuantumImageType(Image *image,
637 %        const QuantumType quantum_type)
638 %
639 %  A description of each parameter follows:
640 %
641 %    o image: the image.
642 %
643 %    o quantum_type: Declare which pixel components to transfer (red, green,
644 %      blue, opacity, RGB, or RGBA).
645 %
646 */
647 MagickExport void SetQuantumImageType(Image *image,
648   const QuantumType quantum_type)
649 {
650   assert(image != (Image *) NULL);
651   assert(image->signature == MagickSignature);
652   if (image->debug != MagickFalse)
653     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
654   switch (quantum_type)
655   {
656     case IndexQuantum:
657     case IndexAlphaQuantum:
658     {
659       image->type=PaletteType;
660       break;
661     }
662     case GrayQuantum:
663     case GrayAlphaQuantum:
664     {
665       image->type=GrayscaleType;
666       if (image->depth == 1)
667         image->type=BilevelType;
668       break;
669     }
670     case CyanQuantum:
671     case MagentaQuantum:
672     case YellowQuantum:
673     case BlackQuantum:
674     case CMYKQuantum:
675     case CMYKAQuantum:
676     {
677       image->type=ColorSeparationType;
678       break;
679     }
680     default:
681     {
682       image->type=TrueColorType;
683       break;
684     }
685   }
686 }
687 \f
688 /*
689 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
690 %                                                                             %
691 %                                                                             %
692 %                                                                             %
693 %   S e t Q u a n t u m P a c k                                               %
694 %                                                                             %
695 %                                                                             %
696 %                                                                             %
697 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
698 %
699 %  SetQuantumPack() sets the quantum pack flag.
700 %
701 %  The format of the SetQuantumPack method is:
702 %
703 %      void SetQuantumPack(QuantumInfo *quantum_info,
704 %        const MagickBooleanType pack)
705 %
706 %  A description of each parameter follows:
707 %
708 %    o quantum_info: the quantum info.
709 %
710 %    o pack: the pack flag.
711 %
712 */
713 MagickExport void SetQuantumPack(QuantumInfo *quantum_info,
714   const MagickBooleanType pack)
715 {
716   assert(quantum_info != (QuantumInfo *) NULL);
717   assert(quantum_info->signature == MagickSignature);
718   quantum_info->pack=pack;
719 }
720 \f
721 \f
722 /*
723 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
724 %                                                                             %
725 %                                                                             %
726 %                                                                             %
727 %   S e t Q u a n t u m P a d                                                 %
728 %                                                                             %
729 %                                                                             %
730 %                                                                             %
731 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
732 %
733 %  SetQuantumPad() sets the quantum pad.
734 %
735 %  The format of the SetQuantumPad method is:
736 %
737 %      MagickBooleanType SetQuantumPad(const Image *image,
738 %        QuantumInfo *quantum_info,const size_t pad)
739 %
740 %  A description of each parameter follows:
741 %
742 %    o image: the image.
743 %
744 %    o quantum_info: the quantum info.
745 %
746 %    o pad: the quantum pad.
747 %
748 */
749 MagickExport MagickBooleanType SetQuantumPad(const Image *image,
750   QuantumInfo *quantum_info,const size_t pad)
751 {
752   assert(image != (Image *) NULL);
753   assert(image->signature == MagickSignature);
754   if (image->debug != MagickFalse)
755     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
756   assert(quantum_info != (QuantumInfo *) NULL);
757   assert(quantum_info->signature == MagickSignature);
758   quantum_info->pad=pad;
759   return(SetQuantumDepth(image,quantum_info,quantum_info->depth));
760 }
761 \f
762 /*
763 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
764 %                                                                             %
765 %                                                                             %
766 %                                                                             %
767 %   S e t Q u a n t u m M i n I s W h i t e                                   %
768 %                                                                             %
769 %                                                                             %
770 %                                                                             %
771 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
772 %
773 %  SetQuantumMinIsWhite() sets the quantum min-is-white flag.
774 %
775 %  The format of the SetQuantumMinIsWhite method is:
776 %
777 %      void SetQuantumMinIsWhite(QuantumInfo *quantum_info,
778 %        const MagickBooleanType min_is_white)
779 %
780 %  A description of each parameter follows:
781 %
782 %    o quantum_info: the quantum info.
783 %
784 %    o min_is_white: the min-is-white flag.
785 %
786 */
787 MagickExport void SetQuantumMinIsWhite(QuantumInfo *quantum_info,
788   const MagickBooleanType min_is_white)
789 {
790   assert(quantum_info != (QuantumInfo *) NULL);
791   assert(quantum_info->signature == MagickSignature);
792   quantum_info->min_is_white=min_is_white;
793 }
794 \f
795 /*
796 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
797 %                                                                             %
798 %                                                                             %
799 %                                                                             %
800 %   S e t Q u a n t u m Q u a n t u m                                         %
801 %                                                                             %
802 %                                                                             %
803 %                                                                             %
804 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
805 %
806 %  SetQuantumQuantum() sets the quantum quantum.
807 %
808 %  The format of the SetQuantumQuantum method is:
809 %
810 %      void SetQuantumQuantum(QuantumInfo *quantum_info,
811 %        const size_t quantum)
812 %
813 %  A description of each parameter follows:
814 %
815 %    o quantum_info: the quantum info.
816 %
817 %    o quantum: the quantum quantum.
818 %
819 */
820 MagickExport void SetQuantumQuantum(QuantumInfo *quantum_info,
821   const size_t quantum)
822 {
823   assert(quantum_info != (QuantumInfo *) NULL);
824   assert(quantum_info->signature == MagickSignature);
825   quantum_info->quantum=quantum;
826 }
827 \f
828 /*
829 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
830 %                                                                             %
831 %                                                                             %
832 %                                                                             %
833 %   S e t Q u a n t u m S c a l e                                             %
834 %                                                                             %
835 %                                                                             %
836 %                                                                             %
837 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838 %
839 %  SetQuantumScale() sets the quantum scale.
840 %
841 %  The format of the SetQuantumScale method is:
842 %
843 %      void SetQuantumScale(QuantumInfo *quantum_info,const double scale)
844 %
845 %  A description of each parameter follows:
846 %
847 %    o quantum_info: the quantum info.
848 %
849 %    o scale: the quantum scale.
850 %
851 */
852 MagickExport void SetQuantumScale(QuantumInfo *quantum_info,const double scale)
853 {
854   assert(quantum_info != (QuantumInfo *) NULL);
855   assert(quantum_info->signature == MagickSignature);
856   quantum_info->scale=scale;
857 }