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