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