blob: f0422f8293de5a27f21fde54a5fe8052de4c1ca6 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
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 %
cristyde984cd2013-12-01 14:49:27 +000015% Cristy %
cristy3ed852e2009-09-05 21:47:34 +000016% October 1998 %
17% %
18% %
cristyb56bb242014-11-25 17:12:48 +000019% Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000020% 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
38/*
39 Include declarations.
40*/
cristy4c08aed2011-07-01 19:47:50 +000041#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"
cristy16d9c1a2014-12-14 15:28:39 +000049#include "MagickCore/cache-private.h"
cristy291fa172015-03-29 17:42:05 +000050#include "MagickCore/colorspace.h"
51#include "MagickCore/colorspace-private.h"
cristy4c08aed2011-07-01 19:47:50 +000052#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/monitor.h"
59#include "MagickCore/option.h"
60#include "MagickCore/pixel.h"
61#include "MagickCore/pixel-accessor.h"
62#include "MagickCore/property.h"
63#include "MagickCore/quantum.h"
64#include "MagickCore/quantum-private.h"
65#include "MagickCore/resource_.h"
66#include "MagickCore/semaphore.h"
67#include "MagickCore/statistic.h"
68#include "MagickCore/stream.h"
69#include "MagickCore/string_.h"
70#include "MagickCore/string-private.h"
71#include "MagickCore/thread-private.h"
72#include "MagickCore/utility.h"
cristy3ed852e2009-09-05 21:47:34 +000073
74/*
75 Define declarations.
76*/
77#define QuantumSignature 0xab
78
79/*
80 Forward declarations.
81*/
82static void
83 DestroyQuantumPixels(QuantumInfo *);
84
85/*
86%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87% %
88% %
89% %
90% A c q u i r e Q u a n t u m I n f o %
91% %
92% %
93% %
94%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95%
96% AcquireQuantumInfo() allocates the QuantumInfo structure.
97%
98% The format of the AcquireQuantumInfo method is:
99%
cristy5f766ef2014-12-14 21:12:47 +0000100% QuantumInfo *AcquireQuantumInfo(const ImageInfo *image_info,Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000101%
102% A description of each parameter follows:
103%
104% o image_info: the image info.
105%
106% o image: the image.
107%
108*/
cristy3ed852e2009-09-05 21:47:34 +0000109MagickExport QuantumInfo *AcquireQuantumInfo(const ImageInfo *image_info,
cristy5f766ef2014-12-14 21:12:47 +0000110 Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000111{
112 MagickBooleanType
113 status;
114
115 QuantumInfo
116 *quantum_info;
117
cristy73bd4a52010-10-05 11:24:23 +0000118 quantum_info=(QuantumInfo *) AcquireMagickMemory(sizeof(*quantum_info));
cristy3ed852e2009-09-05 21:47:34 +0000119 if (quantum_info == (QuantumInfo *) NULL)
120 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
121 quantum_info->signature=MagickSignature;
122 GetQuantumInfo(image_info,quantum_info);
123 if (image == (const Image *) NULL)
124 return(quantum_info);
125 status=SetQuantumDepth(image,quantum_info,image->depth);
cristyc32a4022013-03-15 15:08:09 +0000126 quantum_info->endian=image->endian;
cristy3ed852e2009-09-05 21:47:34 +0000127 if (status == MagickFalse)
128 quantum_info=DestroyQuantumInfo(quantum_info);
129 return(quantum_info);
130}
131
132/*
133%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134% %
135% %
136% %
137+ A c q u i r e Q u a n t u m P i x e l s %
138% %
139% %
140% %
141%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142%
cristy16d9c1a2014-12-14 15:28:39 +0000143% AcquireQuantumPixels() allocates the pixel staging areas.
cristy3ed852e2009-09-05 21:47:34 +0000144%
145% The format of the AcquireQuantumPixels method is:
146%
147% MagickBooleanType AcquireQuantumPixels(QuantumInfo *quantum_info,
148% const size_t extent)
149%
150% A description of each parameter follows:
151%
152% o quantum_info: the quantum info.
153%
154% o extent: the quantum info.
155%
156*/
157static MagickBooleanType AcquireQuantumPixels(QuantumInfo *quantum_info,
158 const size_t extent)
159{
cristybb503372010-05-27 20:51:26 +0000160 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000161 i;
162
163 assert(quantum_info != (QuantumInfo *) NULL);
164 assert(quantum_info->signature == MagickSignature);
cristy9357bdd2012-07-30 12:28:34 +0000165 quantum_info->number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
cristy3ed852e2009-09-05 21:47:34 +0000166 quantum_info->pixels=(unsigned char **) AcquireQuantumMemory(
167 quantum_info->number_threads,sizeof(*quantum_info->pixels));
168 if (quantum_info->pixels == (unsigned char **) NULL)
169 return(MagickFalse);
170 quantum_info->extent=extent;
cristy5c6cd592012-04-23 00:57:38 +0000171 (void) ResetMagickMemory(quantum_info->pixels,0,quantum_info->number_threads*
172 sizeof(*quantum_info->pixels));
cristybb503372010-05-27 20:51:26 +0000173 for (i=0; i < (ssize_t) quantum_info->number_threads; i++)
cristy3ed852e2009-09-05 21:47:34 +0000174 {
175 quantum_info->pixels[i]=(unsigned char *) AcquireQuantumMemory(extent+1,
176 sizeof(**quantum_info->pixels));
cristy84787932009-10-06 19:18:19 +0000177 if (quantum_info->pixels[i] == (unsigned char *) NULL)
cristy16d9c1a2014-12-14 15:28:39 +0000178 {
179 while (--i >= 0)
180 quantum_info->pixels[i]=(unsigned char *) RelinquishMagickMemory(
181 quantum_info->pixels[i]);
182 return(MagickFalse);
183 }
cristy3ed852e2009-09-05 21:47:34 +0000184 (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
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*/
214MagickExport 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)
cristy3d162a92014-02-16 14:05:06 +0000221 RelinquishSemaphoreInfo(&quantum_info->semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000222 quantum_info->signature=(~MagickSignature);
223 quantum_info=(QuantumInfo *) RelinquishMagickMemory(quantum_info);
224 return(quantum_info);
225}
226
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*/
249static void DestroyQuantumPixels(QuantumInfo *quantum_info)
250{
cristybb503372010-05-27 20:51:26 +0000251 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000252 i;
253
cristy4362aac2010-10-06 18:52:08 +0000254 ssize_t
255 extent;
256
cristy3ed852e2009-09-05 21:47:34 +0000257 assert(quantum_info != (QuantumInfo *) NULL);
258 assert(quantum_info->signature == MagickSignature);
259 assert(quantum_info->pixels != (unsigned char **) NULL);
cristy55a91cd2010-12-01 00:57:40 +0000260 extent=(ssize_t) quantum_info->extent;
cristybb503372010-05-27 20:51:26 +0000261 for (i=0; i < (ssize_t) quantum_info->number_threads; i++)
cristyed6b55a2010-10-06 02:15:05 +0000262 if (quantum_info->pixels[i] != (unsigned char *) NULL)
263 {
264 /*
265 Did we overrun our quantum buffer?
266 */
cristy4362aac2010-10-06 18:52:08 +0000267 assert(quantum_info->pixels[i][extent] == QuantumSignature);
cristyed6b55a2010-10-06 02:15:05 +0000268 quantum_info->pixels[i]=(unsigned char *) RelinquishMagickMemory(
269 quantum_info->pixels[i]);
270 }
cristy3ed852e2009-09-05 21:47:34 +0000271 quantum_info->pixels=(unsigned char **) RelinquishMagickMemory(
272 quantum_info->pixels);
273}
274
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*/
303MagickExport 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;
cristy1f9852b2010-09-04 15:05:36 +0000317 case BGRQuantum: packet_size=3; break;
cristy3ed852e2009-09-05 21:47:34 +0000318 case RGBAQuantum: packet_size=4; break;
319 case RGBOQuantum: packet_size=4; break;
cristy1f9852b2010-09-04 15:05:36 +0000320 case BGRAQuantum: packet_size=4; break;
cristy3ed852e2009-09-05 21:47:34 +0000321 case CMYKQuantum: packet_size=4; break;
322 case CMYKAQuantum: packet_size=5; break;
323 default: break;
324 }
325 if (quantum_info->pack == MagickFalse)
cristyc9672a92010-01-06 00:57:45 +0000326 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));
cristy3ed852e2009-09-05 21:47:34 +0000328}
329
330/*
331%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
332% %
333% %
334% %
cristy9d4918b2012-11-14 20:18:32 +0000335% G e t Q u a n t u m E n d i a n %
336% %
337% %
338% %
339%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
340%
341% GetQuantumEndian() returns the quantum endian of the image.
342%
343% The endian of the GetQuantumEndian method is:
344%
345% EndianType GetQuantumEndian(const QuantumInfo *quantum_info)
346%
347% A description of each parameter follows:
348%
349% o quantum_info: the quantum info.
350%
351*/
352MagickExport EndianType GetQuantumEndian(const QuantumInfo *quantum_info)
353{
354 assert(quantum_info != (QuantumInfo *) NULL);
355 assert(quantum_info->signature == MagickSignature);
356 return(quantum_info->endian);
357}
358
359/*
360%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
361% %
362% %
363% %
cristye11d00a2011-12-06 18:03:25 +0000364% G e t Q u a n t u m F o r m a t %
365% %
366% %
367% %
368%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
369%
370% GetQuantumFormat() returns the quantum format of the image.
371%
372% The format of the GetQuantumFormat method is:
373%
374% QuantumFormatType GetQuantumFormat(const QuantumInfo *quantum_info)
375%
376% A description of each parameter follows:
377%
378% o quantum_info: the quantum info.
379%
380*/
381MagickExport QuantumFormatType GetQuantumFormat(const QuantumInfo *quantum_info)
382{
383 assert(quantum_info != (QuantumInfo *) NULL);
384 assert(quantum_info->signature == MagickSignature);
385 return(quantum_info->format);
386}
387
388/*
389%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
390% %
391% %
392% %
cristy3ed852e2009-09-05 21:47:34 +0000393% G e t Q u a n t u m I n f o %
394% %
395% %
396% %
397%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
398%
399% GetQuantumInfo() initializes the QuantumInfo structure to default values.
400%
401% The format of the GetQuantumInfo method is:
402%
403% GetQuantumInfo(const ImageInfo *image_info,QuantumInfo *quantum_info)
404%
405% A description of each parameter follows:
406%
407% o image_info: the image info.
408%
409% o quantum_info: the quantum info.
410%
411*/
412MagickExport void GetQuantumInfo(const ImageInfo *image_info,
413 QuantumInfo *quantum_info)
414{
415 const char
416 *option;
417
418 assert(quantum_info != (QuantumInfo *) NULL);
419 (void) ResetMagickMemory(quantum_info,0,sizeof(*quantum_info));
420 quantum_info->quantum=8;
421 quantum_info->maximum=1.0;
422 quantum_info->scale=QuantumRange;
423 quantum_info->pack=MagickTrue;
cristy3d162a92014-02-16 14:05:06 +0000424 quantum_info->semaphore=AcquireSemaphoreInfo();
cristy3ed852e2009-09-05 21:47:34 +0000425 quantum_info->signature=MagickSignature;
426 if (image_info == (const ImageInfo *) NULL)
427 return;
428 option=GetImageOption(image_info,"quantum:format");
429 if (option != (char *) NULL)
cristy042ee782011-04-22 18:48:30 +0000430 quantum_info->format=(QuantumFormatType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +0000431 MagickQuantumFormatOptions,MagickFalse,option);
432 option=GetImageOption(image_info,"quantum:minimum");
433 if (option != (char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +0000434 quantum_info->minimum=StringToDouble(option,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000435 option=GetImageOption(image_info,"quantum:maximum");
436 if (option != (char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +0000437 quantum_info->maximum=StringToDouble(option,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000438 if ((quantum_info->minimum == 0.0) && (quantum_info->maximum == 0.0))
439 quantum_info->scale=0.0;
440 else
441 if (quantum_info->minimum == quantum_info->maximum)
442 {
cristya19f1d72012-08-07 18:24:38 +0000443 quantum_info->scale=(double) QuantumRange/quantum_info->minimum;
cristy3ed852e2009-09-05 21:47:34 +0000444 quantum_info->minimum=0.0;
445 }
446 else
cristya19f1d72012-08-07 18:24:38 +0000447 quantum_info->scale=(double) QuantumRange/(quantum_info->maximum-
cristy3ed852e2009-09-05 21:47:34 +0000448 quantum_info->minimum);
449 option=GetImageOption(image_info,"quantum:scale");
450 if (option != (char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +0000451 quantum_info->scale=StringToDouble(option,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000452 option=GetImageOption(image_info,"quantum:polarity");
453 if (option != (char *) NULL)
454 quantum_info->min_is_white=LocaleCompare(option,"min-is-white") == 0 ?
455 MagickTrue : MagickFalse;
cristy32c68432012-01-12 15:06:28 +0000456 quantum_info->endian=image_info->endian;
457 ResetQuantumState(quantum_info);
cristy3ed852e2009-09-05 21:47:34 +0000458}
459
460/*
461%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
462% %
463% %
464% %
465% G e t Q u a n t u m P i x e l s %
466% %
467% %
468% %
469%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
470%
471% GetQuantumPixels() returns the quantum pixels.
472%
473% The format of the GetQuantumPixels method is:
474%
cristyb1253cd2015-05-31 01:06:54 +0000475% unsigned char *QuantumPixels GetQuantumPixels(
476% const QuantumInfo *quantum_info)
cristy3ed852e2009-09-05 21:47:34 +0000477%
478% A description of each parameter follows:
479%
480% o image: the image.
481%
482*/
cristyb1253cd2015-05-31 01:06:54 +0000483MagickExport unsigned char *GetQuantumPixels(const QuantumInfo *quantum_info)
cristy3ed852e2009-09-05 21:47:34 +0000484{
cristy5c9e6f22010-09-17 17:31:01 +0000485 const int
486 id = GetOpenMPThreadId();
cristy3ed852e2009-09-05 21:47:34 +0000487
488 assert(quantum_info != (QuantumInfo *) NULL);
489 assert(quantum_info->signature == MagickSignature);
cristy3ed852e2009-09-05 21:47:34 +0000490 return(quantum_info->pixels[id]);
491}
492
493/*
494%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
495% %
496% %
497% %
498% G e t Q u a n t u m T y p e %
499% %
500% %
501% %
502%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
503%
504% GetQuantumType() returns the quantum type of the image.
505%
506% The format of the GetQuantumType method is:
507%
508% QuantumType GetQuantumType(Image *image,ExceptionInfo *exception)
509%
510% A description of each parameter follows:
511%
512% o image: the image.
513%
cristy5b4868f2014-12-14 17:43:35 +0000514% o exception: return any errors or warnings in this structure.
515%
cristy3ed852e2009-09-05 21:47:34 +0000516*/
517MagickExport QuantumType GetQuantumType(Image *image,ExceptionInfo *exception)
518{
519 QuantumType
520 quantum_type;
521
522 assert(image != (Image *) NULL);
523 assert(image->signature == MagickSignature);
524 if (image->debug != MagickFalse)
525 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristyec5b7442015-03-29 17:50:11 +0000526 (void) exception;
cristy3ed852e2009-09-05 21:47:34 +0000527 quantum_type=RGBQuantum;
cristy9f36ba72014-12-07 22:55:01 +0000528 if (image->alpha_trait != UndefinedPixelTrait)
cristy3ed852e2009-09-05 21:47:34 +0000529 quantum_type=RGBAQuantum;
530 if (image->colorspace == CMYKColorspace)
531 {
532 quantum_type=CMYKQuantum;
cristy9f36ba72014-12-07 22:55:01 +0000533 if (image->alpha_trait != UndefinedPixelTrait)
cristy3ed852e2009-09-05 21:47:34 +0000534 quantum_type=CMYKAQuantum;
535 }
cristy291fa172015-03-29 17:42:05 +0000536 if (IsGrayColorspace(image->colorspace) != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000537 {
538 quantum_type=GrayQuantum;
cristy9f36ba72014-12-07 22:55:01 +0000539 if (image->alpha_trait != UndefinedPixelTrait)
cristy3ed852e2009-09-05 21:47:34 +0000540 quantum_type=GrayAlphaQuantum;
541 }
cristybdbf4b62012-05-13 22:22:59 +0000542 if (image->storage_class == PseudoClass)
543 {
544 quantum_type=IndexQuantum;
cristy9f36ba72014-12-07 22:55:01 +0000545 if (image->alpha_trait != UndefinedPixelTrait)
cristybdbf4b62012-05-13 22:22:59 +0000546 quantum_type=IndexAlphaQuantum;
547 }
cristy3ed852e2009-09-05 21:47:34 +0000548 return(quantum_type);
549}
550
551/*
552%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
553% %
554% %
555% %
cristy79630222012-01-14 01:38:37 +0000556+ R e s e t Q u a n t u m S t a t e %
cristy32c68432012-01-12 15:06:28 +0000557% %
558% %
559% %
560%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
561%
562% ResetQuantumState() resets the quantum state.
563%
564% The format of the ResetQuantumState method is:
565%
566% void ResetQuantumState(QuantumInfo *quantum_info)
567%
568% A description of each parameter follows:
569%
570% o quantum_info: the quantum info.
571%
572*/
cristy79630222012-01-14 01:38:37 +0000573MagickPrivate void ResetQuantumState(QuantumInfo *quantum_info)
cristy32c68432012-01-12 15:06:28 +0000574{
575 static const unsigned int mask[32] =
576 {
577 0x00000000U, 0x00000001U, 0x00000003U, 0x00000007U, 0x0000000fU,
578 0x0000001fU, 0x0000003fU, 0x0000007fU, 0x000000ffU, 0x000001ffU,
579 0x000003ffU, 0x000007ffU, 0x00000fffU, 0x00001fffU, 0x00003fffU,
580 0x00007fffU, 0x0000ffffU, 0x0001ffffU, 0x0003ffffU, 0x0007ffffU,
581 0x000fffffU, 0x001fffffU, 0x003fffffU, 0x007fffffU, 0x00ffffffU,
582 0x01ffffffU, 0x03ffffffU, 0x07ffffffU, 0x0fffffffU, 0x1fffffffU,
583 0x3fffffffU, 0x7fffffffU
584 };
585
586 assert(quantum_info != (QuantumInfo *) NULL);
587 assert(quantum_info->signature == MagickSignature);
588 quantum_info->state.inverse_scale=1.0;
589 if (fabs(quantum_info->scale) >= MagickEpsilon)
590 quantum_info->state.inverse_scale/=quantum_info->scale;
591 quantum_info->state.pixel=0U;
592 quantum_info->state.bits=0U;
593 quantum_info->state.mask=mask;
594}
595
596/*
597%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
598% %
599% %
600% %
cristy3ed852e2009-09-05 21:47:34 +0000601% S e t Q u a n t u m F o r m a t %
602% %
603% %
604% %
605%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
606%
607% SetQuantumAlphaType() sets the quantum format.
608%
609% The format of the SetQuantumAlphaType method is:
610%
611% void SetQuantumAlphaType(QuantumInfo *quantum_info,
612% const QuantumAlphaType type)
613%
614% A description of each parameter follows:
615%
616% o quantum_info: the quantum info.
617%
618% o type: the alpha type (e.g. associate).
619%
620*/
621MagickExport void SetQuantumAlphaType(QuantumInfo *quantum_info,
622 const QuantumAlphaType type)
623{
624 assert(quantum_info != (QuantumInfo *) NULL);
625 assert(quantum_info->signature == MagickSignature);
626 quantum_info->alpha_type=type;
627}
628
629/*
630%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
631% %
632% %
633% %
634% S e t Q u a n t u m D e p t h %
635% %
636% %
637% %
638%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
639%
640% SetQuantumDepth() sets the quantum depth.
641%
642% The format of the SetQuantumDepth method is:
643%
644% MagickBooleanType SetQuantumDepth(const Image *image,
cristybb503372010-05-27 20:51:26 +0000645% QuantumInfo *quantum_info,const size_t depth)
cristy3ed852e2009-09-05 21:47:34 +0000646%
647% A description of each parameter follows:
648%
649% o image: the image.
650%
651% o quantum_info: the quantum info.
652%
653% o depth: the quantum depth.
654%
655*/
656MagickExport MagickBooleanType SetQuantumDepth(const Image *image,
cristybb503372010-05-27 20:51:26 +0000657 QuantumInfo *quantum_info,const size_t depth)
cristy3ed852e2009-09-05 21:47:34 +0000658{
cristy56d88542014-12-01 01:13:30 +0000659 size_t
660 extent,
661 quantum;
cristy3ed852e2009-09-05 21:47:34 +0000662
663 /*
664 Allocate the quantum pixel buffer.
665 */
666 assert(image != (Image *) NULL);
667 assert(image->signature == MagickSignature);
668 if (image->debug != MagickFalse)
669 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
670 assert(quantum_info != (QuantumInfo *) NULL);
671 assert(quantum_info->signature == MagickSignature);
672 quantum_info->depth=depth;
673 if (quantum_info->format == FloatingPointQuantumFormat)
674 {
675 if (quantum_info->depth > 32)
676 quantum_info->depth=64;
677 else
cristyc9672a92010-01-06 00:57:45 +0000678 if (quantum_info->depth > 16)
679 quantum_info->depth=32;
680 else
681 quantum_info->depth=16;
cristy3ed852e2009-09-05 21:47:34 +0000682 }
cristy3ed852e2009-09-05 21:47:34 +0000683 if (quantum_info->pixels != (unsigned char **) NULL)
684 DestroyQuantumPixels(quantum_info);
cristy56d88542014-12-01 01:13:30 +0000685 quantum=(quantum_info->pad+6)*(quantum_info->depth+7)/8;
686 extent=image->columns*quantum;
687 if (quantum != (extent/image->columns))
688 return(MagickFalse);
689 return(AcquireQuantumPixels(quantum_info,extent));
cristy3ed852e2009-09-05 21:47:34 +0000690}
691
692/*
693%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
694% %
695% %
696% %
cristy9d4918b2012-11-14 20:18:32 +0000697% S e t Q u a n t u m E n d i a n %
698% %
699% %
700% %
701%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
702%
703% SetQuantumEndian() sets the quantum endian.
704%
705% The endian of the SetQuantumEndian method is:
706%
707% MagickBooleanType SetQuantumEndian(const Image *image,
708% QuantumInfo *quantum_info,const EndianType endian)
709%
710% A description of each parameter follows:
711%
712% o image: the image.
713%
714% o quantum_info: the quantum info.
715%
716% o endian: the quantum endian.
717%
718*/
719MagickExport MagickBooleanType SetQuantumEndian(const Image *image,
720 QuantumInfo *quantum_info,const EndianType endian)
721{
722 assert(image != (Image *) NULL);
723 assert(image->signature == MagickSignature);
724 if (image->debug != MagickFalse)
725 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
726 assert(quantum_info != (QuantumInfo *) NULL);
727 assert(quantum_info->signature == MagickSignature);
728 quantum_info->endian=endian;
729 return(SetQuantumDepth(image,quantum_info,quantum_info->depth));
730}
731
732/*
733%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
734% %
735% %
736% %
cristy3ed852e2009-09-05 21:47:34 +0000737% S e t Q u a n t u m F o r m a t %
738% %
739% %
740% %
741%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
742%
743% SetQuantumFormat() sets the quantum format.
744%
745% The format of the SetQuantumFormat method is:
746%
747% MagickBooleanType SetQuantumFormat(const Image *image,
748% QuantumInfo *quantum_info,const QuantumFormatType format)
749%
750% A description of each parameter follows:
751%
752% o image: the image.
753%
754% o quantum_info: the quantum info.
755%
756% o format: the quantum format.
757%
758*/
759MagickExport MagickBooleanType SetQuantumFormat(const Image *image,
760 QuantumInfo *quantum_info,const QuantumFormatType format)
761{
762 assert(image != (Image *) NULL);
763 assert(image->signature == MagickSignature);
764 if (image->debug != MagickFalse)
765 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
766 assert(quantum_info != (QuantumInfo *) NULL);
767 assert(quantum_info->signature == MagickSignature);
768 quantum_info->format=format;
769 return(SetQuantumDepth(image,quantum_info,quantum_info->depth));
770}
771
772/*
773%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
774% %
775% %
776% %
777% S e t Q u a n t u m I m a g e T y p e %
778% %
779% %
780% %
781%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
782%
783% SetQuantumImageType() sets the image type based on the quantum type.
784%
785% The format of the SetQuantumImageType method is:
786%
787% void ImageType SetQuantumImageType(Image *image,
788% const QuantumType quantum_type)
789%
790% A description of each parameter follows:
791%
792% o image: the image.
793%
794% o quantum_type: Declare which pixel components to transfer (red, green,
795% blue, opacity, RGB, or RGBA).
796%
797*/
798MagickExport void SetQuantumImageType(Image *image,
799 const QuantumType quantum_type)
800{
801 assert(image != (Image *) NULL);
802 assert(image->signature == MagickSignature);
803 if (image->debug != MagickFalse)
804 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
805 switch (quantum_type)
806 {
807 case IndexQuantum:
808 case IndexAlphaQuantum:
809 {
810 image->type=PaletteType;
811 break;
812 }
813 case GrayQuantum:
814 case GrayAlphaQuantum:
815 {
816 image->type=GrayscaleType;
817 if (image->depth == 1)
818 image->type=BilevelType;
819 break;
820 }
821 case CyanQuantum:
822 case MagentaQuantum:
823 case YellowQuantum:
824 case BlackQuantum:
825 case CMYKQuantum:
826 case CMYKAQuantum:
827 {
828 image->type=ColorSeparationType;
829 break;
830 }
831 default:
832 {
833 image->type=TrueColorType;
834 break;
835 }
836 }
837}
838
839/*
840%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
841% %
842% %
843% %
844% S e t Q u a n t u m P a c k %
845% %
846% %
847% %
848%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
849%
850% SetQuantumPack() sets the quantum pack flag.
851%
852% The format of the SetQuantumPack method is:
853%
854% void SetQuantumPack(QuantumInfo *quantum_info,
855% const MagickBooleanType pack)
856%
857% A description of each parameter follows:
858%
859% o quantum_info: the quantum info.
860%
861% o pack: the pack flag.
862%
863*/
864MagickExport void SetQuantumPack(QuantumInfo *quantum_info,
865 const MagickBooleanType pack)
866{
867 assert(quantum_info != (QuantumInfo *) NULL);
868 assert(quantum_info->signature == MagickSignature);
869 quantum_info->pack=pack;
870}
871
872
873/*
874%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
875% %
876% %
877% %
878% S e t Q u a n t u m P a d %
879% %
880% %
881% %
882%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
883%
884% SetQuantumPad() sets the quantum pad.
885%
886% The format of the SetQuantumPad method is:
887%
888% MagickBooleanType SetQuantumPad(const Image *image,
cristybb503372010-05-27 20:51:26 +0000889% QuantumInfo *quantum_info,const size_t pad)
cristy3ed852e2009-09-05 21:47:34 +0000890%
891% A description of each parameter follows:
892%
893% o image: the image.
894%
895% o quantum_info: the quantum info.
896%
897% o pad: the quantum pad.
898%
899*/
900MagickExport MagickBooleanType SetQuantumPad(const Image *image,
cristybb503372010-05-27 20:51:26 +0000901 QuantumInfo *quantum_info,const size_t pad)
cristy3ed852e2009-09-05 21:47:34 +0000902{
903 assert(image != (Image *) NULL);
904 assert(image->signature == MagickSignature);
905 if (image->debug != MagickFalse)
906 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
907 assert(quantum_info != (QuantumInfo *) NULL);
908 assert(quantum_info->signature == MagickSignature);
909 quantum_info->pad=pad;
910 return(SetQuantumDepth(image,quantum_info,quantum_info->depth));
911}
912
913/*
914%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
915% %
916% %
917% %
918% S e t Q u a n t u m M i n I s W h i t e %
919% %
920% %
921% %
922%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
923%
924% SetQuantumMinIsWhite() sets the quantum min-is-white flag.
925%
926% The format of the SetQuantumMinIsWhite method is:
927%
928% void SetQuantumMinIsWhite(QuantumInfo *quantum_info,
929% const MagickBooleanType min_is_white)
930%
931% A description of each parameter follows:
932%
933% o quantum_info: the quantum info.
934%
935% o min_is_white: the min-is-white flag.
936%
937*/
938MagickExport void SetQuantumMinIsWhite(QuantumInfo *quantum_info,
939 const MagickBooleanType min_is_white)
940{
941 assert(quantum_info != (QuantumInfo *) NULL);
942 assert(quantum_info->signature == MagickSignature);
943 quantum_info->min_is_white=min_is_white;
944}
945
946/*
947%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
948% %
949% %
950% %
951% S e t Q u a n t u m Q u a n t u m %
952% %
953% %
954% %
955%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
956%
957% SetQuantumQuantum() sets the quantum quantum.
958%
959% The format of the SetQuantumQuantum method is:
960%
961% void SetQuantumQuantum(QuantumInfo *quantum_info,
cristybb503372010-05-27 20:51:26 +0000962% const size_t quantum)
cristy3ed852e2009-09-05 21:47:34 +0000963%
964% A description of each parameter follows:
965%
966% o quantum_info: the quantum info.
967%
968% o quantum: the quantum quantum.
969%
970*/
971MagickExport void SetQuantumQuantum(QuantumInfo *quantum_info,
cristybb503372010-05-27 20:51:26 +0000972 const size_t quantum)
cristy3ed852e2009-09-05 21:47:34 +0000973{
974 assert(quantum_info != (QuantumInfo *) NULL);
975 assert(quantum_info->signature == MagickSignature);
976 quantum_info->quantum=quantum;
977}
978
979/*
980%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
981% %
982% %
983% %
984% S e t Q u a n t u m S c a l e %
985% %
986% %
987% %
988%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
989%
990% SetQuantumScale() sets the quantum scale.
991%
992% The format of the SetQuantumScale method is:
993%
994% void SetQuantumScale(QuantumInfo *quantum_info,const double scale)
995%
996% A description of each parameter follows:
997%
998% o quantum_info: the quantum info.
999%
1000% o scale: the quantum scale.
1001%
1002*/
1003MagickExport void SetQuantumScale(QuantumInfo *quantum_info,const double scale)
1004{
1005 assert(quantum_info != (QuantumInfo *) NULL);
1006 assert(quantum_info->signature == MagickSignature);
1007 quantum_info->scale=scale;
1008}