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