MagickCore 7.1.2-37
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 (image->columns == 1)
337 {
338 if ((quantum_type == GrayQuantum) && (quantum_info->depth == 10) &&
339 (quantum_info->pack == MagickFalse))
340 return(4+quantum_info->pad);
341 if (quantum_type == CbYCrYQuantum)
342 channels=6;
343 }
344 if (quantum_info->pack == MagickFalse)
345 return((size_t) (channels*image->columns*((quantum_info->depth+7)/8))+
346 (quantum_info->pad*image->columns));
347 return((size_t) ((channels*image->columns*quantum_info->depth+7)/8)+
348 (quantum_info->pad*image->columns));
349}
350␌
351/*
352%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
353% %
354% %
355% %
356% G e t Q u a n t u m E n d i a n %
357% %
358% %
359% %
360%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
361%
362% GetQuantumEndian() returns the quantum endian of the image.
363%
364% The endian of the GetQuantumEndian method is:
365%
366% EndianType GetQuantumEndian(const QuantumInfo *quantum_info)
367%
368% A description of each parameter follows:
369%
370% o quantum_info: the quantum info.
371%
372*/
373MagickExport EndianType GetQuantumEndian(const QuantumInfo *quantum_info)
374{
375 assert(quantum_info != (QuantumInfo *) NULL);
376 assert(quantum_info->signature == MagickCoreSignature);
377 return(quantum_info->endian);
378}
379␌
380/*
381%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
382% %
383% %
384% %
385% G e t Q u a n t u m F o r m a t %
386% %
387% %
388% %
389%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
390%
391% GetQuantumFormat() returns the quantum format of the image.
392%
393% The format of the GetQuantumFormat method is:
394%
395% QuantumFormatType GetQuantumFormat(const QuantumInfo *quantum_info)
396%
397% A description of each parameter follows:
398%
399% o quantum_info: the quantum info.
400%
401*/
402MagickExport QuantumFormatType GetQuantumFormat(const QuantumInfo *quantum_info)
403{
404 assert(quantum_info != (QuantumInfo *) NULL);
405 assert(quantum_info->signature == MagickCoreSignature);
406 return(quantum_info->format);
407}
408␌
409/*
410%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
411% %
412% %
413% %
414% G e t Q u a n t u m I n f o %
415% %
416% %
417% %
418%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
419%
420% GetQuantumInfo() initializes the QuantumInfo structure to default values.
421%
422% The format of the GetQuantumInfo method is:
423%
424% GetQuantumInfo(const ImageInfo *image_info,QuantumInfo *quantum_info)
425%
426% A description of each parameter follows:
427%
428% o image_info: the image info.
429%
430% o quantum_info: the quantum info.
431%
432*/
433MagickExport void GetQuantumInfo(const ImageInfo *image_info,
434 QuantumInfo *quantum_info)
435{
436 const char
437 *option;
438
439 assert(quantum_info != (QuantumInfo *) NULL);
440 (void) memset(quantum_info,0,sizeof(*quantum_info));
441 quantum_info->quantum=8;
442 quantum_info->maximum=1.0;
443 quantum_info->scale=QuantumRange;
444 quantum_info->pack=MagickTrue;
445 quantum_info->semaphore=AcquireSemaphoreInfo();
446 quantum_info->signature=MagickCoreSignature;
447 if (image_info == (const ImageInfo *) NULL)
448 return;
449 option=GetImageOption(image_info,"quantum:format");
450 if (option != (char *) NULL)
451 quantum_info->format=(QuantumFormatType) ParseCommandOption(
452 MagickQuantumFormatOptions,MagickFalse,option);
453 option=GetImageOption(image_info,"quantum:minimum");
454 if (option != (char *) NULL)
455 quantum_info->minimum=StringToDouble(option,(char **) NULL);
456 option=GetImageOption(image_info,"quantum:maximum");
457 if (option != (char *) NULL)
458 quantum_info->maximum=StringToDouble(option,(char **) NULL);
459 if ((quantum_info->minimum == 0.0) && (quantum_info->maximum == 0.0))
460 quantum_info->scale=0.0;
461 else
462 if (quantum_info->minimum == quantum_info->maximum)
463 {
464 quantum_info->scale=(double) QuantumRange/quantum_info->minimum;
465 quantum_info->minimum=0.0;
466 }
467 else
468 quantum_info->scale=(double) QuantumRange/(quantum_info->maximum-
469 quantum_info->minimum);
470 option=GetImageOption(image_info,"quantum:scale");
471 if (option != (char *) NULL)
472 quantum_info->scale=StringToDouble(option,(char **) NULL);
473 option=GetImageOption(image_info,"quantum:polarity");
474 if (option != (char *) NULL)
475 quantum_info->min_is_white=LocaleCompare(option,"min-is-white") == 0 ?
476 MagickTrue : MagickFalse;
477 quantum_info->endian=image_info->endian;
478 ResetQuantumState(quantum_info);
479}
480␌
481/*
482%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
483% %
484% %
485% %
486% G e t Q u a n t u m P i x e l s %
487% %
488% %
489% %
490%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
491%
492% GetQuantumPixels() returns the quantum pixels.
493%
494% The format of the GetQuantumPixels method is:
495%
496% unsigned char *QuantumPixels GetQuantumPixels(
497% const QuantumInfo *quantum_info)
498%
499% A description of each parameter follows:
500%
501% o image: the image.
502%
503*/
504MagickExport unsigned char *GetQuantumPixels(const QuantumInfo *quantum_info)
505{
506 const int
507 id = GetOpenMPThreadId();
508
509 assert(quantum_info != (QuantumInfo *) NULL);
510 assert(quantum_info->signature == MagickCoreSignature);
511 return((unsigned char *) GetVirtualMemoryBlob(quantum_info->pixels[id]));
512}
513␌
514/*
515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
516% %
517% %
518% %
519% G e t Q u a n t u m T y p e %
520% %
521% %
522% %
523%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
524%
525% GetQuantumType() returns the quantum type of the image.
526%
527% The format of the GetQuantumType method is:
528%
529% QuantumType GetQuantumType(Image *image,ExceptionInfo *exception)
530%
531% A description of each parameter follows:
532%
533% o image: the image.
534%
535% o exception: return any errors or warnings in this structure.
536%
537*/
538MagickExport QuantumType GetQuantumType(Image *image,ExceptionInfo *exception)
539{
540 QuantumType
541 quantum_type;
542
543 assert(image != (Image *) NULL);
544 assert(image->signature == MagickCoreSignature);
545 if (IsEventLogging() != MagickFalse)
546 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
547 (void) exception;
548 quantum_type=RGBQuantum;
549 if (image->alpha_trait != UndefinedPixelTrait)
550 quantum_type=RGBAQuantum;
551 if (image->colorspace == CMYKColorspace)
552 {
553 quantum_type=CMYKQuantum;
554 if (image->alpha_trait != UndefinedPixelTrait)
555 quantum_type=CMYKAQuantum;
556 }
557 if (IsGrayColorspace(image->colorspace) != MagickFalse)
558 {
559 quantum_type=GrayQuantum;
560 if (image->alpha_trait != UndefinedPixelTrait)
561 quantum_type=GrayAlphaQuantum;
562 }
563 if (image->storage_class == PseudoClass)
564 {
565 quantum_type=IndexQuantum;
566 if (image->alpha_trait != UndefinedPixelTrait)
567 quantum_type=IndexAlphaQuantum;
568 }
569 if (image->number_meta_channels != 0)
570 quantum_type=MultispectralQuantum;
571 return(quantum_type);
572}
573␌
574/*
575%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
576% %
577% %
578% %
579+ R e s e t Q u a n t u m S t a t e %
580% %
581% %
582% %
583%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
584%
585% ResetQuantumState() resets the quantum state.
586%
587% The format of the ResetQuantumState method is:
588%
589% void ResetQuantumState(QuantumInfo *quantum_info)
590%
591% A description of each parameter follows:
592%
593% o quantum_info: the quantum info.
594%
595*/
596MagickPrivate void ResetQuantumState(QuantumInfo *quantum_info)
597{
598 static const unsigned int mask[32] =
599 {
600 0x00000000U, 0x00000001U, 0x00000003U, 0x00000007U, 0x0000000fU,
601 0x0000001fU, 0x0000003fU, 0x0000007fU, 0x000000ffU, 0x000001ffU,
602 0x000003ffU, 0x000007ffU, 0x00000fffU, 0x00001fffU, 0x00003fffU,
603 0x00007fffU, 0x0000ffffU, 0x0001ffffU, 0x0003ffffU, 0x0007ffffU,
604 0x000fffffU, 0x001fffffU, 0x003fffffU, 0x007fffffU, 0x00ffffffU,
605 0x01ffffffU, 0x03ffffffU, 0x07ffffffU, 0x0fffffffU, 0x1fffffffU,
606 0x3fffffffU, 0x7fffffffU
607 };
608
609 assert(quantum_info != (QuantumInfo *) NULL);
610 assert(quantum_info->signature == MagickCoreSignature);
611 quantum_info->state.inverse_scale=1.0;
612 if (fabs(quantum_info->scale) >= MagickEpsilon)
613 quantum_info->state.inverse_scale/=quantum_info->scale;
614 quantum_info->state.pixel=0U;
615 quantum_info->state.bits=0U;
616 quantum_info->state.mask=mask;
617}
618␌
619/*
620%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
621% %
622% %
623% %
624% S e t Q u a n t u m F o r m a t %
625% %
626% %
627% %
628%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
629%
630% SetQuantumAlphaType() sets the quantum format.
631%
632% The format of the SetQuantumAlphaType method is:
633%
634% void SetQuantumAlphaType(QuantumInfo *quantum_info,
635% const QuantumAlphaType type)
636%
637% A description of each parameter follows:
638%
639% o quantum_info: the quantum info.
640%
641% o type: the alpha type (e.g. associate).
642%
643*/
644MagickExport void SetQuantumAlphaType(QuantumInfo *quantum_info,
645 const QuantumAlphaType type)
646{
647 assert(quantum_info != (QuantumInfo *) NULL);
648 assert(quantum_info->signature == MagickCoreSignature);
649 quantum_info->alpha_type=type;
650}
651␌
652/*
653%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
654% %
655% %
656% %
657% S e t Q u a n t u m D e p t h %
658% %
659% %
660% %
661%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
662%
663% SetQuantumDepth() sets the quantum depth.
664%
665% The format of the SetQuantumDepth method is:
666%
667% MagickBooleanType SetQuantumDepth(const Image *image,
668% QuantumInfo *quantum_info,const size_t depth)
669%
670% A description of each parameter follows:
671%
672% o image: the image.
673%
674% o quantum_info: the quantum info.
675%
676% o depth: the quantum depth.
677%
678*/
679MagickExport MagickBooleanType SetQuantumDepth(const Image *image,
680 QuantumInfo *quantum_info,const size_t depth)
681{
682 /*
683 Allocate the quantum pixel buffer.
684 */
685 assert(image != (Image *) NULL);
686 assert(image->signature == MagickCoreSignature);
687 assert(quantum_info != (QuantumInfo *) NULL);
688 assert(quantum_info->signature == MagickCoreSignature);
689 if (IsEventLogging() != MagickFalse)
690 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
691 quantum_info->depth=MagickMin(depth,64);
692 if (quantum_info->format == FloatingPointQuantumFormat)
693 {
694 if (quantum_info->depth > 32)
695 quantum_info->depth=64;
696 else
697 if (quantum_info->depth > 24)
698 quantum_info->depth=32;
699 else
700 if (quantum_info->depth > 16)
701 quantum_info->depth=24;
702 else
703 quantum_info->depth=16;
704 }
705 return(SetQuantumExtent(image,quantum_info));
706}
707␌
708/*
709%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
710% %
711% %
712% %
713% S e t Q u a n t u m E n d i a n %
714% %
715% %
716% %
717%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
718%
719% SetQuantumEndian() sets the quantum endian.
720%
721% The endian of the SetQuantumEndian method is:
722%
723% MagickBooleanType SetQuantumEndian(const Image *image,
724% QuantumInfo *quantum_info,const EndianType endian)
725%
726% A description of each parameter follows:
727%
728% o image: the image.
729%
730% o quantum_info: the quantum info.
731%
732% o endian: the quantum endian.
733%
734*/
735MagickExport MagickBooleanType SetQuantumEndian(const Image *image,
736 QuantumInfo *quantum_info,const EndianType endian)
737{
738 assert(image != (Image *) NULL);
739 assert(image->signature == MagickCoreSignature);
740 assert(quantum_info != (QuantumInfo *) NULL);
741 assert(quantum_info->signature == MagickCoreSignature);
742 if (IsEventLogging() != MagickFalse)
743 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
744 quantum_info->endian=endian;
745 return(SetQuantumExtent(image,quantum_info));
746}
747␌
748/*
749%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
750% %
751% %
752% %
753% S e t Q u a n t u m E x t e n t %
754% %
755% %
756% %
757%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
758%
759% SetQuantumExtent() sets the quantum pixel buffer extent.
760%
761% The format of the SetQuantumExtent method is:
762%
763% MagickBooleanType SetQuantumExtent(Image *image,
764% QuantumInfo *quantum_info)
765%
766% A description of each parameter follows:
767%
768% o image: the image.
769%
770% o quantum_info: the quantum info.
771%
772*/
773MagickExport MagickBooleanType SetQuantumExtent(const Image *image,
774 QuantumInfo *quantum_info)
775{
776 size_t
777 extent,
778 quantum;
779
780 /*
781 Speculative allocation since we don't yet know the quantum type.
782 */
783 assert(image != (Image *) NULL);
784 assert(image->signature == MagickCoreSignature);
785 assert(quantum_info != (QuantumInfo *) NULL);
786 assert(quantum_info->signature == MagickCoreSignature);
787 quantum=(GetPixelChannels(image)+quantum_info->pad+3)*
788 ((quantum_info->depth+7)/8)*sizeof(double);
789 extent=MagickMax(image->columns,image->rows)*quantum;
790 if ((MagickMax(image->columns,image->rows) != 0) &&
791 (quantum != (extent/MagickMax(image->columns,image->rows))))
792 return(MagickFalse);
793 if (quantum_info->pixels != (MemoryInfo **) NULL)
794 {
795 if (extent <= quantum_info->extent)
796 return(MagickTrue);
797 DestroyQuantumPixels(quantum_info);
798 }
799 return(AcquireQuantumPixels(quantum_info,extent));
800}
801␌
802/*
803%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
804% %
805% %
806% %
807% S e t Q u a n t u m F o r m a t %
808% %
809% %
810% %
811%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
812%
813% SetQuantumFormat() sets the quantum format.
814%
815% The format of the SetQuantumFormat method is:
816%
817% MagickBooleanType SetQuantumFormat(const Image *image,
818% QuantumInfo *quantum_info,const QuantumFormatType format)
819%
820% A description of each parameter follows:
821%
822% o image: the image.
823%
824% o quantum_info: the quantum info.
825%
826% o format: the quantum format.
827%
828*/
829MagickExport MagickBooleanType SetQuantumFormat(const Image *image,
830 QuantumInfo *quantum_info,const QuantumFormatType format)
831{
832 assert(image != (Image *) NULL);
833 assert(image->signature == MagickCoreSignature);
834 assert(quantum_info != (QuantumInfo *) NULL);
835 assert(quantum_info->signature == MagickCoreSignature);
836 if (IsEventLogging() != MagickFalse)
837 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
838 quantum_info->format=format;
839 return(SetQuantumExtent(image,quantum_info));
840}
841␌
842/*
843%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
844% %
845% %
846% %
847% S e t Q u a n t u m I m a g e T y p e %
848% %
849% %
850% %
851%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
852%
853% SetQuantumImageType() sets the image type based on the quantum type.
854%
855% The format of the SetQuantumImageType method is:
856%
857% void ImageType SetQuantumImageType(Image *image,
858% const QuantumType quantum_type)
859%
860% A description of each parameter follows:
861%
862% o image: the image.
863%
864% o quantum_type: Declare which pixel components to transfer (red, green,
865% blue, opacity, RGB, or RGBA).
866%
867*/
868MagickExport void SetQuantumImageType(Image *image,
869 const QuantumType quantum_type)
870{
871 assert(image != (Image *) NULL);
872 assert(image->signature == MagickCoreSignature);
873 if (IsEventLogging() != MagickFalse)
874 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
875 switch (quantum_type)
876 {
877 case IndexQuantum:
878 case IndexAlphaQuantum:
879 {
880 image->type=PaletteType;
881 break;
882 }
883 case GrayQuantum:
884 case GrayAlphaQuantum:
885 {
886 image->type=GrayscaleType;
887 if (image->depth == 1)
888 image->type=BilevelType;
889 break;
890 }
891 case CyanQuantum:
892 case MagentaQuantum:
893 case YellowQuantum:
894 case BlackQuantum:
895 case CMYKQuantum:
896 case CMYKAQuantum:
897 case MultispectralQuantum:
898 {
899 image->type=ColorSeparationType;
900 break;
901 }
902 default:
903 {
904 image->type=TrueColorType;
905 break;
906 }
907 }
908}
909␌
910/*
911%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
912% %
913% %
914% %
915% S e t Q u a n t u m M e t a C h a n n e l %
916% %
917% %
918% %
919%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
920%
921% SetQuantumMetaChannel() sets the quantum meta-channel that will exported or
922% imported when the quantum type is MultispectralQuantum. To unset the
923% meta-channel, set the meta-channel to -1.
924%
925% The format of the SetQuantumMetaChannel method is:
926%
927% void SetQuantumMetaChannel(const Image *image,QuantumInfo *quantum_info,
928% const ssize_t meta_channel)
929%
930% A description of each parameter follows:
931%
932% o image: the image.
933%
934% o quantum_info: the quantum info.
935%
936% o meta_channel: the meta channel.
937%
938*/
939MagickExport MagickBooleanType SetQuantumMetaChannel(const Image *image,
940 QuantumInfo *quantum_info, const ssize_t meta_channel)
941{
942 assert(quantum_info != (QuantumInfo *) NULL);
943 assert(quantum_info->signature == MagickCoreSignature);
944 if ((meta_channel < -1) ||
945 (meta_channel >= (ssize_t) image->number_meta_channels))
946 return(MagickFalse);
947 quantum_info->meta_channel=meta_channel+1;
948 return(MagickTrue);
949}
950␌
951/*
952%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
953% %
954% %
955% %
956% S e t Q u a n t u m P a c k %
957% %
958% %
959% %
960%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
961%
962% SetQuantumPack() sets the quantum pack flag.
963%
964% The format of the SetQuantumPack method is:
965%
966% void SetQuantumPack(QuantumInfo *quantum_info,
967% const MagickBooleanType pack)
968%
969% A description of each parameter follows:
970%
971% o quantum_info: the quantum info.
972%
973% o pack: the pack flag.
974%
975*/
976MagickExport void SetQuantumPack(QuantumInfo *quantum_info,
977 const MagickBooleanType pack)
978{
979 assert(quantum_info != (QuantumInfo *) NULL);
980 assert(quantum_info->signature == MagickCoreSignature);
981 quantum_info->pack=pack;
982}
983␌
984/*
985%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
986% %
987% %
988% %
989% S e t Q u a n t u m P a d %
990% %
991% %
992% %
993%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
994%
995% SetQuantumPad() sets the quantum pad.
996%
997% The format of the SetQuantumPad method is:
998%
999% MagickBooleanType SetQuantumPad(const Image *image,
1000% QuantumInfo *quantum_info,const size_t pad)
1001%
1002% A description of each parameter follows:
1003%
1004% o image: the image.
1005%
1006% o quantum_info: the quantum info.
1007%
1008% o pad: the quantum pad.
1009%
1010*/
1011MagickExport MagickBooleanType SetQuantumPad(const Image *image,
1012 QuantumInfo *quantum_info,const size_t pad)
1013{
1014 assert(image != (Image *) NULL);
1015 assert(image->signature == MagickCoreSignature);
1016 assert(quantum_info != (QuantumInfo *) NULL);
1017 assert(quantum_info->signature == MagickCoreSignature);
1018 if (IsEventLogging() != MagickFalse)
1019 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1020 if (pad >= (MAGICK_SSIZE_MAX/GetImageChannels(image)))
1021 return(MagickFalse);
1022 quantum_info->pad=pad;
1023 return(SetQuantumExtent(image,quantum_info));
1024}
1025␌
1026/*
1027%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1028% %
1029% %
1030% %
1031% S e t Q u a n t u m M i n I s W h i t e %
1032% %
1033% %
1034% %
1035%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1036%
1037% SetQuantumMinIsWhite() sets the quantum min-is-white flag.
1038%
1039% The format of the SetQuantumMinIsWhite method is:
1040%
1041% void SetQuantumMinIsWhite(QuantumInfo *quantum_info,
1042% const MagickBooleanType min_is_white)
1043%
1044% A description of each parameter follows:
1045%
1046% o quantum_info: the quantum info.
1047%
1048% o min_is_white: the min-is-white flag.
1049%
1050*/
1051MagickExport void SetQuantumMinIsWhite(QuantumInfo *quantum_info,
1052 const MagickBooleanType min_is_white)
1053{
1054 assert(quantum_info != (QuantumInfo *) NULL);
1055 assert(quantum_info->signature == MagickCoreSignature);
1056 quantum_info->min_is_white=min_is_white;
1057}
1058␌
1059/*
1060%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1061% %
1062% %
1063% %
1064% S e t Q u a n t u m Q u a n t u m %
1065% %
1066% %
1067% %
1068%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1069%
1070% SetQuantumQuantum() sets the quantum quantum.
1071%
1072% The format of the SetQuantumQuantum method is:
1073%
1074% void SetQuantumQuantum(QuantumInfo *quantum_info,const size_t quantum)
1075%
1076% A description of each parameter follows:
1077%
1078% o quantum_info: the quantum info.
1079%
1080% o quantum: the quantum quantum.
1081%
1082*/
1083MagickExport void SetQuantumQuantum(QuantumInfo *quantum_info,
1084 const size_t quantum)
1085{
1086 assert(quantum_info != (QuantumInfo *) NULL);
1087 assert(quantum_info->signature == MagickCoreSignature);
1088 quantum_info->quantum=quantum;
1089}
1090␌
1091/*
1092%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1093% %
1094% %
1095% %
1096% S e t Q u a n t u m S c a l e %
1097% %
1098% %
1099% %
1100%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1101%
1102% SetQuantumScale() sets the quantum scale.
1103%
1104% The format of the SetQuantumScale method is:
1105%
1106% void SetQuantumScale(QuantumInfo *quantum_info,const double scale)
1107%
1108% A description of each parameter follows:
1109%
1110% o quantum_info: the quantum info.
1111%
1112% o scale: the quantum scale.
1113%
1114*/
1115MagickExport void SetQuantumScale(QuantumInfo *quantum_info,const double scale)
1116{
1117 assert(quantum_info != (QuantumInfo *) NULL);
1118 assert(quantum_info->signature == MagickCoreSignature);
1119 quantum_info->scale=scale;
1120}