MagickCore 7.1.2-35
Convert, Edit, Or Compose Bitmap Images
Loading...
Searching...
No Matches
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% Cristy %
16% October 1998 %
17% %
18% %
19% Copyright @ 1999 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% https://imagemagick.org/license/ %
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␌
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/cache-private.h"
50#include "MagickCore/colorspace.h"
51#include "MagickCore/colorspace-private.h"
52#include "MagickCore/constitute.h"
53#include "MagickCore/delegate.h"
54#include "MagickCore/geometry.h"
55#include "MagickCore/list.h"
56#include "MagickCore/magick.h"
57#include "MagickCore/memory_.h"
58#include "MagickCore/memory-private.h"
59#include "MagickCore/monitor.h"
60#include "MagickCore/option.h"
61#include "MagickCore/pixel.h"
62#include "MagickCore/pixel-accessor.h"
63#include "MagickCore/property.h"
64#include "MagickCore/quantum.h"
65#include "MagickCore/quantum-private.h"
66#include "MagickCore/resource_.h"
67#include "MagickCore/semaphore.h"
68#include "MagickCore/statistic.h"
69#include "MagickCore/stream.h"
70#include "MagickCore/string_.h"
71#include "MagickCore/string-private.h"
72#include "MagickCore/thread-private.h"
73#include "MagickCore/utility.h"
74␌
75/*
76 Define declarations.
77*/
78#define QuantumSignature 0xab
79␌
80/*
81 Forward declarations.
82*/
83static void
84 DestroyQuantumPixels(QuantumInfo *);
85␌
86/*
87%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88% %
89% %
90% %
91% A c q u i r e Q u a n t u m I n f o %
92% %
93% %
94% %
95%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96%
97% AcquireQuantumInfo() allocates the QuantumInfo structure.
98%
99% The format of the AcquireQuantumInfo method is:
100%
101% QuantumInfo *AcquireQuantumInfo(const ImageInfo *image_info,Image *image)
102%
103% A description of each parameter follows:
104%
105% o image_info: the image info.
106%
107% o image: the image.
108%
109*/
110MagickExport QuantumInfo *AcquireQuantumInfo(const ImageInfo *image_info,
111 Image *image)
112{
113 MagickBooleanType
114 status;
115
116 QuantumInfo
117 *quantum_info;
118
119 quantum_info=(QuantumInfo *) AcquireCriticalMemory(sizeof(*quantum_info));
120 quantum_info->signature=MagickCoreSignature;
121 GetQuantumInfo(image_info,quantum_info);
122 if (image == (const Image *) NULL)
123 return(quantum_info);
124 status=SetQuantumDepth(image,quantum_info,image->depth);
125 quantum_info->endian=image->endian;
126 if (status == MagickFalse)
127 quantum_info=DestroyQuantumInfo(quantum_info);
128 return(quantum_info);
129}
130␌
131/*
132%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133% %
134% %
135% %
136+ A c q u i r e Q u a n t u m P i x e l s %
137% %
138% %
139% %
140%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141%
142% AcquireQuantumPixels() allocates the pixel staging areas.
143%
144% The format of the AcquireQuantumPixels method is:
145%
146% MagickBooleanType AcquireQuantumPixels(QuantumInfo *quantum_info,
147% const size_t extent)
148%
149% A description of each parameter follows:
150%
151% o quantum_info: the quantum info.
152%
153% o extent: the quantum info.
154%
155*/
156static MagickBooleanType AcquireQuantumPixels(QuantumInfo *quantum_info,
157 const size_t extent)
158{
159 ssize_t
160 i;
161
162 assert(quantum_info != (QuantumInfo *) NULL);
163 assert(quantum_info->signature == MagickCoreSignature);
164 quantum_info->number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
165 quantum_info->pixels=(MemoryInfo **) AcquireQuantumMemory(
166 quantum_info->number_threads,sizeof(*quantum_info->pixels));
167 if (quantum_info->pixels == (MemoryInfo **) NULL)
168 return(MagickFalse);
169 quantum_info->extent=extent;
170 (void) memset(quantum_info->pixels,0,quantum_info->number_threads*
171 sizeof(*quantum_info->pixels));
172 for (i=0; i < (ssize_t) quantum_info->number_threads; i++)
173 {
174 unsigned char
175 *pixels;
176
177 quantum_info->pixels[i]=AcquireVirtualMemory(extent+1,sizeof(*pixels));
178 if (quantum_info->pixels[i] == (MemoryInfo *) NULL)
179 {
180 DestroyQuantumPixels(quantum_info);
181 return(MagickFalse);
182 }
183 pixels=(unsigned char *) GetVirtualMemoryBlob(quantum_info->pixels[i]);
184 (void) memset(pixels,0,(extent+1)*sizeof(*pixels));
185 pixels[extent]=QuantumSignature;
186 }
187 return(MagickTrue);
188}
189␌
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*/
213MagickExport QuantumInfo *DestroyQuantumInfo(QuantumInfo *quantum_info)
214{
215 assert(quantum_info != (QuantumInfo *) NULL);
216 assert(quantum_info->signature == MagickCoreSignature);
217 if (quantum_info->pixels != (MemoryInfo **) NULL)
218 DestroyQuantumPixels(quantum_info);
219 if (quantum_info->semaphore != (SemaphoreInfo *) NULL)
220 RelinquishSemaphoreInfo(&quantum_info->semaphore);
221 quantum_info->signature=(~MagickCoreSignature);
222 quantum_info=(QuantumInfo *) RelinquishMagickMemory(quantum_info);
223 return(quantum_info);
224}
225␌
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*/
248static void DestroyQuantumPixels(QuantumInfo *quantum_info)
249{
250 ssize_t
251 i;
252
253 assert(quantum_info != (QuantumInfo *) NULL);
254 assert(quantum_info->signature == MagickCoreSignature);
255 assert(quantum_info->pixels != (MemoryInfo **) NULL);
256 for (i=0; i < (ssize_t) quantum_info->number_threads; i++)
257 if (quantum_info->pixels[i] != (MemoryInfo *) NULL)
258 {
259#ifndef NDEBUG
260 ssize_t
261 extent;
262
263 unsigned char
264 *pixels;
265
266 /*
267 Did we overrun our quantum buffer?
268 */
269 extent=(ssize_t) quantum_info->extent;
270 pixels=(unsigned char *) GetVirtualMemoryBlob(quantum_info->pixels[i]);
271 assert(pixels[extent] == QuantumSignature);
272#endif
273 quantum_info->pixels[i]=RelinquishVirtualMemory(
274 quantum_info->pixels[i]);
275 }
276 quantum_info->pixels=(MemoryInfo **) RelinquishMagickMemory(
277 quantum_info->pixels);
278}
279␌
280/*
281%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
282% %
283% %
284% %
285% G e t Q u a n t u m E x t e n t %
286% %
287% %
288% %
289%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
290%
291% GetQuantumExtent() returns the quantum pixel buffer extent.
292%
293% The format of the GetQuantumExtent method is:
294%
295% size_t GetQuantumExtent(Image *image,const QuantumInfo *quantum_info,
296% const QuantumType quantum_type)
297%
298% A description of each parameter follows:
299%
300% o image: the image.
301%
302% o quantum_info: the quantum info.
303%
304% o quantum_type: Declare which pixel components to transfer (red, green,
305% blue, opacity, RGB, or RGBA).
306%
307*/
308MagickExport size_t GetQuantumExtent(const Image *image,
309 const QuantumInfo *quantum_info,const QuantumType quantum_type)
310{
311 size_t
312 channels;
313
314 assert(quantum_info != (QuantumInfo *) NULL);
315 assert(quantum_info->signature == MagickCoreSignature);
316 channels=1;
317 switch (quantum_type)
318 {
319 case GrayAlphaQuantum: channels=2; break;
320 case IndexAlphaQuantum: channels=2; break;
321 case RGBQuantum: channels=3; break;
322 case BGRQuantum: channels=3; break;
323 case RGBAQuantum: channels=4; break;
324 case RGBOQuantum: channels=4; break;
325 case BGRAQuantum: channels=4; break;
326 case BGROQuantum: channels=4; break;
327 case CMYKQuantum: channels=4; break;
328 case CMYKAQuantum: channels=5; break;
329 case CMYKOQuantum: channels=5; break;
330 case MultispectralQuantum: channels=GetImageChannels(image); break;
331 case CbYCrAQuantum: channels=4; break;
332 case CbYCrQuantum: channels=3; break;
333 case CbYCrYQuantum: channels=4; break;
334 default: break;
335 }
336 if (quantum_info->pack == MagickFalse)
337 return((size_t) (channels*image->columns*((quantum_info->depth+7)/8))+
338 (quantum_info->pad*image->columns));
339 return((size_t) ((channels*image->columns*quantum_info->depth+7)/8)+
340 (quantum_info->pad*image->columns));
341}
342␌
343/*
344%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
345% %
346% %
347% %
348% G e t Q u a n t u m E n d i a n %
349% %
350% %
351% %
352%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
353%
354% GetQuantumEndian() returns the quantum endian of the image.
355%
356% The endian of the GetQuantumEndian method is:
357%
358% EndianType GetQuantumEndian(const QuantumInfo *quantum_info)
359%
360% A description of each parameter follows:
361%
362% o quantum_info: the quantum info.
363%
364*/
365MagickExport EndianType GetQuantumEndian(const QuantumInfo *quantum_info)
366{
367 assert(quantum_info != (QuantumInfo *) NULL);
368 assert(quantum_info->signature == MagickCoreSignature);
369 return(quantum_info->endian);
370}
371␌
372/*
373%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
374% %
375% %
376% %
377% G e t Q u a n t u m F o r m a t %
378% %
379% %
380% %
381%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
382%
383% GetQuantumFormat() returns the quantum format of the image.
384%
385% The format of the GetQuantumFormat method is:
386%
387% QuantumFormatType GetQuantumFormat(const QuantumInfo *quantum_info)
388%
389% A description of each parameter follows:
390%
391% o quantum_info: the quantum info.
392%
393*/
394MagickExport QuantumFormatType GetQuantumFormat(const QuantumInfo *quantum_info)
395{
396 assert(quantum_info != (QuantumInfo *) NULL);
397 assert(quantum_info->signature == MagickCoreSignature);
398 return(quantum_info->format);
399}
400␌
401/*
402%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
403% %
404% %
405% %
406% G e t Q u a n t u m I n f o %
407% %
408% %
409% %
410%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
411%
412% GetQuantumInfo() initializes the QuantumInfo structure to default values.
413%
414% The format of the GetQuantumInfo method is:
415%
416% GetQuantumInfo(const ImageInfo *image_info,QuantumInfo *quantum_info)
417%
418% A description of each parameter follows:
419%
420% o image_info: the image info.
421%
422% o quantum_info: the quantum info.
423%
424*/
425MagickExport void GetQuantumInfo(const ImageInfo *image_info,
426 QuantumInfo *quantum_info)
427{
428 const char
429 *option;
430
431 assert(quantum_info != (QuantumInfo *) NULL);
432 (void) memset(quantum_info,0,sizeof(*quantum_info));
433 quantum_info->quantum=8;
434 quantum_info->maximum=1.0;
435 quantum_info->scale=QuantumRange;
436 quantum_info->pack=MagickTrue;
437 quantum_info->semaphore=AcquireSemaphoreInfo();
438 quantum_info->signature=MagickCoreSignature;
439 if (image_info == (const ImageInfo *) NULL)
440 return;
441 option=GetImageOption(image_info,"quantum:format");
442 if (option != (char *) NULL)
443 quantum_info->format=(QuantumFormatType) ParseCommandOption(
444 MagickQuantumFormatOptions,MagickFalse,option);
445 option=GetImageOption(image_info,"quantum:minimum");
446 if (option != (char *) NULL)
447 quantum_info->minimum=StringToDouble(option,(char **) NULL);
448 option=GetImageOption(image_info,"quantum:maximum");
449 if (option != (char *) NULL)
450 quantum_info->maximum=StringToDouble(option,(char **) NULL);
451 if ((quantum_info->minimum == 0.0) && (quantum_info->maximum == 0.0))
452 quantum_info->scale=0.0;
453 else
454 if (quantum_info->minimum == quantum_info->maximum)
455 {
456 quantum_info->scale=(double) QuantumRange/quantum_info->minimum;
457 quantum_info->minimum=0.0;
458 }
459 else
460 quantum_info->scale=(double) QuantumRange/(quantum_info->maximum-
461 quantum_info->minimum);
462 option=GetImageOption(image_info,"quantum:scale");
463 if (option != (char *) NULL)
464 quantum_info->scale=StringToDouble(option,(char **) NULL);
465 option=GetImageOption(image_info,"quantum:polarity");
466 if (option != (char *) NULL)
467 quantum_info->min_is_white=LocaleCompare(option,"min-is-white") == 0 ?
468 MagickTrue : MagickFalse;
469 quantum_info->endian=image_info->endian;
470 ResetQuantumState(quantum_info);
471}
472␌
473/*
474%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
475% %
476% %
477% %
478% G e t Q u a n t u m P i x e l s %
479% %
480% %
481% %
482%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
483%
484% GetQuantumPixels() returns the quantum pixels.
485%
486% The format of the GetQuantumPixels method is:
487%
488% unsigned char *QuantumPixels GetQuantumPixels(
489% const QuantumInfo *quantum_info)
490%
491% A description of each parameter follows:
492%
493% o image: the image.
494%
495*/
496MagickExport unsigned char *GetQuantumPixels(const QuantumInfo *quantum_info)
497{
498 const int
499 id = GetOpenMPThreadId();
500
501 assert(quantum_info != (QuantumInfo *) NULL);
502 assert(quantum_info->signature == MagickCoreSignature);
503 return((unsigned char *) GetVirtualMemoryBlob(quantum_info->pixels[id]));
504}
505␌
506/*
507%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
508% %
509% %
510% %
511% G e t Q u a n t u m T y p e %
512% %
513% %
514% %
515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
516%
517% GetQuantumType() returns the quantum type of the image.
518%
519% The format of the GetQuantumType method is:
520%
521% QuantumType GetQuantumType(Image *image,ExceptionInfo *exception)
522%
523% A description of each parameter follows:
524%
525% o image: the image.
526%
527% o exception: return any errors or warnings in this structure.
528%
529*/
530MagickExport QuantumType GetQuantumType(Image *image,ExceptionInfo *exception)
531{
532 QuantumType
533 quantum_type;
534
535 assert(image != (Image *) NULL);
536 assert(image->signature == MagickCoreSignature);
537 if (IsEventLogging() != MagickFalse)
538 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
539 (void) exception;
540 quantum_type=RGBQuantum;
541 if (image->alpha_trait != UndefinedPixelTrait)
542 quantum_type=RGBAQuantum;
543 if (image->colorspace == CMYKColorspace)
544 {
545 quantum_type=CMYKQuantum;
546 if (image->alpha_trait != UndefinedPixelTrait)
547 quantum_type=CMYKAQuantum;
548 }
549 if (IsGrayColorspace(image->colorspace) != MagickFalse)
550 {
551 quantum_type=GrayQuantum;
552 if (image->alpha_trait != UndefinedPixelTrait)
553 quantum_type=GrayAlphaQuantum;
554 }
555 if (image->storage_class == PseudoClass)
556 {
557 quantum_type=IndexQuantum;
558 if (image->alpha_trait != UndefinedPixelTrait)
559 quantum_type=IndexAlphaQuantum;
560 }
561 if (image->number_meta_channels != 0)
562 quantum_type=MultispectralQuantum;
563 return(quantum_type);
564}
565␌
566/*
567%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
568% %
569% %
570% %
571+ R e s e t Q u a n t u m S t a t e %
572% %
573% %
574% %
575%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
576%
577% ResetQuantumState() resets the quantum state.
578%
579% The format of the ResetQuantumState method is:
580%
581% void ResetQuantumState(QuantumInfo *quantum_info)
582%
583% A description of each parameter follows:
584%
585% o quantum_info: the quantum info.
586%
587*/
588MagickPrivate void ResetQuantumState(QuantumInfo *quantum_info)
589{
590 static const unsigned int mask[32] =
591 {
592 0x00000000U, 0x00000001U, 0x00000003U, 0x00000007U, 0x0000000fU,
593 0x0000001fU, 0x0000003fU, 0x0000007fU, 0x000000ffU, 0x000001ffU,
594 0x000003ffU, 0x000007ffU, 0x00000fffU, 0x00001fffU, 0x00003fffU,
595 0x00007fffU, 0x0000ffffU, 0x0001ffffU, 0x0003ffffU, 0x0007ffffU,
596 0x000fffffU, 0x001fffffU, 0x003fffffU, 0x007fffffU, 0x00ffffffU,
597 0x01ffffffU, 0x03ffffffU, 0x07ffffffU, 0x0fffffffU, 0x1fffffffU,
598 0x3fffffffU, 0x7fffffffU
599 };
600
601 assert(quantum_info != (QuantumInfo *) NULL);
602 assert(quantum_info->signature == MagickCoreSignature);
603 quantum_info->state.inverse_scale=1.0;
604 if (fabs(quantum_info->scale) >= MagickEpsilon)
605 quantum_info->state.inverse_scale/=quantum_info->scale;
606 quantum_info->state.pixel=0U;
607 quantum_info->state.bits=0U;
608 quantum_info->state.mask=mask;
609}
610␌
611/*
612%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
613% %
614% %
615% %
616% S e t Q u a n t u m F o r m a t %
617% %
618% %
619% %
620%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
621%
622% SetQuantumAlphaType() sets the quantum format.
623%
624% The format of the SetQuantumAlphaType method is:
625%
626% void SetQuantumAlphaType(QuantumInfo *quantum_info,
627% const QuantumAlphaType type)
628%
629% A description of each parameter follows:
630%
631% o quantum_info: the quantum info.
632%
633% o type: the alpha type (e.g. associate).
634%
635*/
636MagickExport void SetQuantumAlphaType(QuantumInfo *quantum_info,
637 const QuantumAlphaType type)
638{
639 assert(quantum_info != (QuantumInfo *) NULL);
640 assert(quantum_info->signature == MagickCoreSignature);
641 quantum_info->alpha_type=type;
642}
643␌
644/*
645%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
646% %
647% %
648% %
649% S e t Q u a n t u m D e p t h %
650% %
651% %
652% %
653%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
654%
655% SetQuantumDepth() sets the quantum depth.
656%
657% The format of the SetQuantumDepth method is:
658%
659% MagickBooleanType SetQuantumDepth(const Image *image,
660% QuantumInfo *quantum_info,const size_t depth)
661%
662% A description of each parameter follows:
663%
664% o image: the image.
665%
666% o quantum_info: the quantum info.
667%
668% o depth: the quantum depth.
669%
670*/
671MagickExport MagickBooleanType SetQuantumDepth(const Image *image,
672 QuantumInfo *quantum_info,const size_t depth)
673{
674 /*
675 Allocate the quantum pixel buffer.
676 */
677 assert(image != (Image *) NULL);
678 assert(image->signature == MagickCoreSignature);
679 assert(quantum_info != (QuantumInfo *) NULL);
680 assert(quantum_info->signature == MagickCoreSignature);
681 if (IsEventLogging() != MagickFalse)
682 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
683 quantum_info->depth=MagickMin(depth,64);
684 if (quantum_info->format == FloatingPointQuantumFormat)
685 {
686 if (quantum_info->depth > 32)
687 quantum_info->depth=64;
688 else
689 if (quantum_info->depth > 24)
690 quantum_info->depth=32;
691 else
692 if (quantum_info->depth > 16)
693 quantum_info->depth=24;
694 else
695 quantum_info->depth=16;
696 }
697 return(SetQuantumExtent(image,quantum_info));
698}
699␌
700/*
701%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
702% %
703% %
704% %
705% S e t Q u a n t u m E n d i a n %
706% %
707% %
708% %
709%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
710%
711% SetQuantumEndian() sets the quantum endian.
712%
713% The endian of the SetQuantumEndian method is:
714%
715% MagickBooleanType SetQuantumEndian(const Image *image,
716% QuantumInfo *quantum_info,const EndianType endian)
717%
718% A description of each parameter follows:
719%
720% o image: the image.
721%
722% o quantum_info: the quantum info.
723%
724% o endian: the quantum endian.
725%
726*/
727MagickExport MagickBooleanType SetQuantumEndian(const Image *image,
728 QuantumInfo *quantum_info,const EndianType endian)
729{
730 assert(image != (Image *) NULL);
731 assert(image->signature == MagickCoreSignature);
732 assert(quantum_info != (QuantumInfo *) NULL);
733 assert(quantum_info->signature == MagickCoreSignature);
734 if (IsEventLogging() != MagickFalse)
735 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
736 quantum_info->endian=endian;
737 return(SetQuantumExtent(image,quantum_info));
738}
739␌
740/*
741%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
742% %
743% %
744% %
745% S e t Q u a n t u m E x t e n t %
746% %
747% %
748% %
749%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
750%
751% SetQuantumExtent() sets the quantum pixel buffer extent.
752%
753% The format of the SetQuantumExtent method is:
754%
755% MagickBooleanType SetQuantumExtent(Image *image,
756% QuantumInfo *quantum_info)
757%
758% A description of each parameter follows:
759%
760% o image: the image.
761%
762% o quantum_info: the quantum info.
763%
764*/
765MagickExport MagickBooleanType SetQuantumExtent(const Image *image,
766 QuantumInfo *quantum_info)
767{
768 size_t
769 extent,
770 quantum;
771
772 /*
773 Speculative allocation since we don't yet know the quantum type.
774 */
775 assert(image != (Image *) NULL);
776 assert(image->signature == MagickCoreSignature);
777 assert(quantum_info != (QuantumInfo *) NULL);
778 assert(quantum_info->signature == MagickCoreSignature);
779 quantum=(GetPixelChannels(image)+quantum_info->pad+3)*
780 ((quantum_info->depth+7)/8)*sizeof(double);
781 extent=MagickMax(image->columns,image->rows)*quantum;
782 if ((MagickMax(image->columns,image->rows) != 0) &&
783 (quantum != (extent/MagickMax(image->columns,image->rows))))
784 return(MagickFalse);
785 if (quantum_info->pixels != (MemoryInfo **) NULL)
786 {
787 if (extent <= quantum_info->extent)
788 return(MagickTrue);
789 DestroyQuantumPixels(quantum_info);
790 }
791 return(AcquireQuantumPixels(quantum_info,extent));
792}
793␌
794/*
795%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
796% %
797% %
798% %
799% S e t Q u a n t u m F o r m a t %
800% %
801% %
802% %
803%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
804%
805% SetQuantumFormat() sets the quantum format.
806%
807% The format of the SetQuantumFormat method is:
808%
809% MagickBooleanType SetQuantumFormat(const Image *image,
810% QuantumInfo *quantum_info,const QuantumFormatType format)
811%
812% A description of each parameter follows:
813%
814% o image: the image.
815%
816% o quantum_info: the quantum info.
817%
818% o format: the quantum format.
819%
820*/
821MagickExport MagickBooleanType SetQuantumFormat(const Image *image,
822 QuantumInfo *quantum_info,const QuantumFormatType format)
823{
824 assert(image != (Image *) NULL);
825 assert(image->signature == MagickCoreSignature);
826 assert(quantum_info != (QuantumInfo *) NULL);
827 assert(quantum_info->signature == MagickCoreSignature);
828 if (IsEventLogging() != MagickFalse)
829 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
830 quantum_info->format=format;
831 return(SetQuantumExtent(image,quantum_info));
832}
833␌
834/*
835%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
836% %
837% %
838% %
839% S e t Q u a n t u m I m a g e T y p e %
840% %
841% %
842% %
843%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
844%
845% SetQuantumImageType() sets the image type based on the quantum type.
846%
847% The format of the SetQuantumImageType method is:
848%
849% void ImageType SetQuantumImageType(Image *image,
850% const QuantumType quantum_type)
851%
852% A description of each parameter follows:
853%
854% o image: the image.
855%
856% o quantum_type: Declare which pixel components to transfer (red, green,
857% blue, opacity, RGB, or RGBA).
858%
859*/
860MagickExport void SetQuantumImageType(Image *image,
861 const QuantumType quantum_type)
862{
863 assert(image != (Image *) NULL);
864 assert(image->signature == MagickCoreSignature);
865 if (IsEventLogging() != MagickFalse)
866 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
867 switch (quantum_type)
868 {
869 case IndexQuantum:
870 case IndexAlphaQuantum:
871 {
872 image->type=PaletteType;
873 break;
874 }
875 case GrayQuantum:
876 case GrayAlphaQuantum:
877 {
878 image->type=GrayscaleType;
879 if (image->depth == 1)
880 image->type=BilevelType;
881 break;
882 }
883 case CyanQuantum:
884 case MagentaQuantum:
885 case YellowQuantum:
886 case BlackQuantum:
887 case CMYKQuantum:
888 case CMYKAQuantum:
889 case MultispectralQuantum:
890 {
891 image->type=ColorSeparationType;
892 break;
893 }
894 default:
895 {
896 image->type=TrueColorType;
897 break;
898 }
899 }
900}
901␌
902/*
903%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
904% %
905% %
906% %
907% S e t Q u a n t u m M e t a C h a n n e l %
908% %
909% %
910% %
911%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
912%
913% SetQuantumMetaChannel() sets the quantum meta-channel that will exported or
914% imported when the quantum type is MultispectralQuantum. To unset the
915% meta-channel, set the meta-channel to -1.
916%
917% The format of the SetQuantumMetaChannel method is:
918%
919% void SetQuantumMetaChannel(const Image *image,QuantumInfo *quantum_info,
920% const ssize_t meta_channel)
921%
922% A description of each parameter follows:
923%
924% o image: the image.
925%
926% o quantum_info: the quantum info.
927%
928% o meta_channel: the meta channel.
929%
930*/
931MagickExport MagickBooleanType SetQuantumMetaChannel(const Image *image,
932 QuantumInfo *quantum_info, const ssize_t meta_channel)
933{
934 assert(quantum_info != (QuantumInfo *) NULL);
935 assert(quantum_info->signature == MagickCoreSignature);
936 if ((meta_channel < -1) ||
937 (meta_channel >= (ssize_t) image->number_meta_channels))
938 return(MagickFalse);
939 quantum_info->meta_channel=meta_channel+1;
940 return(MagickTrue);
941}
942␌
943/*
944%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
945% %
946% %
947% %
948% S e t Q u a n t u m P a c k %
949% %
950% %
951% %
952%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
953%
954% SetQuantumPack() sets the quantum pack flag.
955%
956% The format of the SetQuantumPack method is:
957%
958% void SetQuantumPack(QuantumInfo *quantum_info,
959% const MagickBooleanType pack)
960%
961% A description of each parameter follows:
962%
963% o quantum_info: the quantum info.
964%
965% o pack: the pack flag.
966%
967*/
968MagickExport void SetQuantumPack(QuantumInfo *quantum_info,
969 const MagickBooleanType pack)
970{
971 assert(quantum_info != (QuantumInfo *) NULL);
972 assert(quantum_info->signature == MagickCoreSignature);
973 quantum_info->pack=pack;
974}
975␌
976/*
977%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
978% %
979% %
980% %
981% S e t Q u a n t u m P a d %
982% %
983% %
984% %
985%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
986%
987% SetQuantumPad() sets the quantum pad.
988%
989% The format of the SetQuantumPad method is:
990%
991% MagickBooleanType SetQuantumPad(const Image *image,
992% QuantumInfo *quantum_info,const size_t pad)
993%
994% A description of each parameter follows:
995%
996% o image: the image.
997%
998% o quantum_info: the quantum info.
999%
1000% o pad: the quantum pad.
1001%
1002*/
1003MagickExport MagickBooleanType SetQuantumPad(const Image *image,
1004 QuantumInfo *quantum_info,const size_t pad)
1005{
1006 assert(image != (Image *) NULL);
1007 assert(image->signature == MagickCoreSignature);
1008 assert(quantum_info != (QuantumInfo *) NULL);
1009 assert(quantum_info->signature == MagickCoreSignature);
1010 if (IsEventLogging() != MagickFalse)
1011 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1012 if (pad >= (MAGICK_SSIZE_MAX/GetImageChannels(image)))
1013 return(MagickFalse);
1014 quantum_info->pad=pad;
1015 return(SetQuantumExtent(image,quantum_info));
1016}
1017␌
1018/*
1019%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1020% %
1021% %
1022% %
1023% S e t Q u a n t u m M i n I s W h i t e %
1024% %
1025% %
1026% %
1027%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1028%
1029% SetQuantumMinIsWhite() sets the quantum min-is-white flag.
1030%
1031% The format of the SetQuantumMinIsWhite method is:
1032%
1033% void SetQuantumMinIsWhite(QuantumInfo *quantum_info,
1034% const MagickBooleanType min_is_white)
1035%
1036% A description of each parameter follows:
1037%
1038% o quantum_info: the quantum info.
1039%
1040% o min_is_white: the min-is-white flag.
1041%
1042*/
1043MagickExport void SetQuantumMinIsWhite(QuantumInfo *quantum_info,
1044 const MagickBooleanType min_is_white)
1045{
1046 assert(quantum_info != (QuantumInfo *) NULL);
1047 assert(quantum_info->signature == MagickCoreSignature);
1048 quantum_info->min_is_white=min_is_white;
1049}
1050␌
1051/*
1052%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1053% %
1054% %
1055% %
1056% S e t Q u a n t u m Q u a n t u m %
1057% %
1058% %
1059% %
1060%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1061%
1062% SetQuantumQuantum() sets the quantum quantum.
1063%
1064% The format of the SetQuantumQuantum method is:
1065%
1066% void SetQuantumQuantum(QuantumInfo *quantum_info,const size_t quantum)
1067%
1068% A description of each parameter follows:
1069%
1070% o quantum_info: the quantum info.
1071%
1072% o quantum: the quantum quantum.
1073%
1074*/
1075MagickExport void SetQuantumQuantum(QuantumInfo *quantum_info,
1076 const size_t quantum)
1077{
1078 assert(quantum_info != (QuantumInfo *) NULL);
1079 assert(quantum_info->signature == MagickCoreSignature);
1080 quantum_info->quantum=quantum;
1081}
1082␌
1083/*
1084%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1085% %
1086% %
1087% %
1088% S e t Q u a n t u m S c a l e %
1089% %
1090% %
1091% %
1092%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1093%
1094% SetQuantumScale() sets the quantum scale.
1095%
1096% The format of the SetQuantumScale method is:
1097%
1098% void SetQuantumScale(QuantumInfo *quantum_info,const double scale)
1099%
1100% A description of each parameter follows:
1101%
1102% o quantum_info: the quantum info.
1103%
1104% o scale: the quantum scale.
1105%
1106*/
1107MagickExport void SetQuantumScale(QuantumInfo *quantum_info,const double scale)
1108{
1109 assert(quantum_info != (QuantumInfo *) NULL);
1110 assert(quantum_info->signature == MagickCoreSignature);
1111 quantum_info->scale=scale;
1112}