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