blob: 36909e175d8f55dd7ea04ddf5d83670a91160b7e [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"
cristy4c08aed2011-07-01 19:47:50 +000050#include "MagickCore/constitute.h"
51#include "MagickCore/delegate.h"
52#include "MagickCore/geometry.h"
53#include "MagickCore/list.h"
54#include "MagickCore/magick.h"
55#include "MagickCore/memory_.h"
56#include "MagickCore/monitor.h"
57#include "MagickCore/option.h"
58#include "MagickCore/pixel.h"
59#include "MagickCore/pixel-accessor.h"
60#include "MagickCore/property.h"
61#include "MagickCore/quantum.h"
62#include "MagickCore/quantum-private.h"
63#include "MagickCore/resource_.h"
64#include "MagickCore/semaphore.h"
65#include "MagickCore/statistic.h"
66#include "MagickCore/stream.h"
67#include "MagickCore/string_.h"
68#include "MagickCore/string-private.h"
69#include "MagickCore/thread-private.h"
70#include "MagickCore/utility.h"
cristy3ed852e2009-09-05 21:47:34 +000071
72/*
73 Define declarations.
74*/
75#define QuantumSignature 0xab
76
77/*
78 Forward declarations.
79*/
80static void
81 DestroyQuantumPixels(QuantumInfo *);
82
83/*
84%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85% %
86% %
87% %
88% A c q u i r e Q u a n t u m I n f o %
89% %
90% %
91% %
92%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93%
94% AcquireQuantumInfo() allocates the QuantumInfo structure.
95%
96% The format of the AcquireQuantumInfo method is:
97%
cristy5b4868f2014-12-14 17:43:35 +000098% QuantumInfo *AcquireQuantumInfo(const ImageInfo *image_info,Image *image,
99% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000100%
101% A description of each parameter follows:
102%
103% o image_info: the image info.
104%
105% o image: the image.
106%
cristy5b4868f2014-12-14 17:43:35 +0000107% o exception: return any errors or warnings in this structure.
108%
cristy3ed852e2009-09-05 21:47:34 +0000109*/
cristy3ed852e2009-09-05 21:47:34 +0000110MagickExport QuantumInfo *AcquireQuantumInfo(const ImageInfo *image_info,
cristy5b4868f2014-12-14 17:43:35 +0000111 Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000112{
113 MagickBooleanType
114 status;
115
116 QuantumInfo
117 *quantum_info;
118
cristy73bd4a52010-10-05 11:24:23 +0000119 quantum_info=(QuantumInfo *) AcquireMagickMemory(sizeof(*quantum_info));
cristy3ed852e2009-09-05 21:47:34 +0000120 if (quantum_info == (QuantumInfo *) NULL)
121 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
122 quantum_info->signature=MagickSignature;
123 GetQuantumInfo(image_info,quantum_info);
124 if (image == (const Image *) NULL)
125 return(quantum_info);
cristy5b4868f2014-12-14 17:43:35 +0000126 if (SyncImagePixelCache(image,exception) == MagickFalse)
127 return(DestroyQuantumInfo(quantum_info));
cristy3ed852e2009-09-05 21:47:34 +0000128 status=SetQuantumDepth(image,quantum_info,image->depth);
cristyc32a4022013-03-15 15:08:09 +0000129 quantum_info->endian=image->endian;
cristy3ed852e2009-09-05 21:47:34 +0000130 if (status == MagickFalse)
131 quantum_info=DestroyQuantumInfo(quantum_info);
132 return(quantum_info);
133}
134
135/*
136%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137% %
138% %
139% %
140+ A c q u i r e Q u a n t u m P i x e l s %
141% %
142% %
143% %
144%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145%
cristy16d9c1a2014-12-14 15:28:39 +0000146% AcquireQuantumPixels() allocates the pixel staging areas.
cristy3ed852e2009-09-05 21:47:34 +0000147%
148% The format of the AcquireQuantumPixels method is:
149%
150% MagickBooleanType AcquireQuantumPixels(QuantumInfo *quantum_info,
151% const size_t extent)
152%
153% A description of each parameter follows:
154%
155% o quantum_info: the quantum info.
156%
157% o extent: the quantum info.
158%
159*/
160static MagickBooleanType AcquireQuantumPixels(QuantumInfo *quantum_info,
161 const size_t extent)
162{
cristybb503372010-05-27 20:51:26 +0000163 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000164 i;
165
166 assert(quantum_info != (QuantumInfo *) NULL);
167 assert(quantum_info->signature == MagickSignature);
cristy9357bdd2012-07-30 12:28:34 +0000168 quantum_info->number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
cristy3ed852e2009-09-05 21:47:34 +0000169 quantum_info->pixels=(unsigned char **) AcquireQuantumMemory(
170 quantum_info->number_threads,sizeof(*quantum_info->pixels));
171 if (quantum_info->pixels == (unsigned char **) NULL)
172 return(MagickFalse);
173 quantum_info->extent=extent;
cristy5c6cd592012-04-23 00:57:38 +0000174 (void) ResetMagickMemory(quantum_info->pixels,0,quantum_info->number_threads*
175 sizeof(*quantum_info->pixels));
cristybb503372010-05-27 20:51:26 +0000176 for (i=0; i < (ssize_t) quantum_info->number_threads; i++)
cristy3ed852e2009-09-05 21:47:34 +0000177 {
178 quantum_info->pixels[i]=(unsigned char *) AcquireQuantumMemory(extent+1,
179 sizeof(**quantum_info->pixels));
cristy84787932009-10-06 19:18:19 +0000180 if (quantum_info->pixels[i] == (unsigned char *) NULL)
cristy16d9c1a2014-12-14 15:28:39 +0000181 {
182 while (--i >= 0)
183 quantum_info->pixels[i]=(unsigned char *) RelinquishMagickMemory(
184 quantum_info->pixels[i]);
185 return(MagickFalse);
186 }
cristy3ed852e2009-09-05 21:47:34 +0000187 (void) ResetMagickMemory(quantum_info->pixels[i],0,(extent+1)*
188 sizeof(**quantum_info->pixels));
189 quantum_info->pixels[i][extent]=QuantumSignature;
190 }
191 return(MagickTrue);
192}
193
194/*
195%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196% %
197% %
198% %
199% D e s t r o y Q u a n t u m I n f o %
200% %
201% %
202% %
203%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204%
205% DestroyQuantumInfo() deallocates memory associated with the QuantumInfo
206% structure.
207%
208% The format of the DestroyQuantumInfo method is:
209%
210% QuantumInfo *DestroyQuantumInfo(QuantumInfo *quantum_info)
211%
212% A description of each parameter follows:
213%
214% o quantum_info: the quantum info.
215%
216*/
217MagickExport QuantumInfo *DestroyQuantumInfo(QuantumInfo *quantum_info)
218{
219 assert(quantum_info != (QuantumInfo *) NULL);
220 assert(quantum_info->signature == MagickSignature);
221 if (quantum_info->pixels != (unsigned char **) NULL)
222 DestroyQuantumPixels(quantum_info);
223 if (quantum_info->semaphore != (SemaphoreInfo *) NULL)
cristy3d162a92014-02-16 14:05:06 +0000224 RelinquishSemaphoreInfo(&quantum_info->semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000225 quantum_info->signature=(~MagickSignature);
226 quantum_info=(QuantumInfo *) RelinquishMagickMemory(quantum_info);
227 return(quantum_info);
228}
229
230/*
231%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232% %
233% %
234% %
235+ D e s t r o y Q u a n t u m P i x e l s %
236% %
237% %
238% %
239%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240%
241% DestroyQuantumPixels() destroys the quantum pixels.
242%
243% The format of the DestroyQuantumPixels() method is:
244%
245% void DestroyQuantumPixels(QuantumInfo *quantum_info)
246%
247% A description of each parameter follows:
248%
249% o quantum_info: the quantum info.
250%
251*/
252static void DestroyQuantumPixels(QuantumInfo *quantum_info)
253{
cristybb503372010-05-27 20:51:26 +0000254 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000255 i;
256
cristy4362aac2010-10-06 18:52:08 +0000257 ssize_t
258 extent;
259
cristy3ed852e2009-09-05 21:47:34 +0000260 assert(quantum_info != (QuantumInfo *) NULL);
261 assert(quantum_info->signature == MagickSignature);
262 assert(quantum_info->pixels != (unsigned char **) NULL);
cristy55a91cd2010-12-01 00:57:40 +0000263 extent=(ssize_t) quantum_info->extent;
cristybb503372010-05-27 20:51:26 +0000264 for (i=0; i < (ssize_t) quantum_info->number_threads; i++)
cristyed6b55a2010-10-06 02:15:05 +0000265 if (quantum_info->pixels[i] != (unsigned char *) NULL)
266 {
267 /*
268 Did we overrun our quantum buffer?
269 */
cristy4362aac2010-10-06 18:52:08 +0000270 assert(quantum_info->pixels[i][extent] == QuantumSignature);
cristyed6b55a2010-10-06 02:15:05 +0000271 quantum_info->pixels[i]=(unsigned char *) RelinquishMagickMemory(
272 quantum_info->pixels[i]);
273 }
cristy3ed852e2009-09-05 21:47:34 +0000274 quantum_info->pixels=(unsigned char **) RelinquishMagickMemory(
275 quantum_info->pixels);
276}
277
278/*
279%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280% %
281% %
282% %
283% G e t Q u a n t u m E x t e n t %
284% %
285% %
286% %
287%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
288%
289% GetQuantumExtent() returns the quantum pixel buffer extent.
290%
291% The format of the GetQuantumExtent method is:
292%
293% size_t GetQuantumExtent(Image *image,const QuantumInfo *quantum_info,
294% const QuantumType quantum_type)
295%
296% A description of each parameter follows:
297%
298% o image: the image.
299%
300% o quantum_info: the quantum info.
301%
302% o quantum_type: Declare which pixel components to transfer (red, green,
303% blue, opacity, RGB, or RGBA).
304%
305*/
306MagickExport size_t GetQuantumExtent(const Image *image,
307 const QuantumInfo *quantum_info,const QuantumType quantum_type)
308{
309 size_t
310 packet_size;
311
312 assert(quantum_info != (QuantumInfo *) NULL);
313 assert(quantum_info->signature == MagickSignature);
314 packet_size=1;
315 switch (quantum_type)
316 {
317 case GrayAlphaQuantum: packet_size=2; break;
318 case IndexAlphaQuantum: packet_size=2; break;
319 case RGBQuantum: packet_size=3; break;
cristy1f9852b2010-09-04 15:05:36 +0000320 case BGRQuantum: packet_size=3; break;
cristy3ed852e2009-09-05 21:47:34 +0000321 case RGBAQuantum: packet_size=4; break;
322 case RGBOQuantum: packet_size=4; break;
cristy1f9852b2010-09-04 15:05:36 +0000323 case BGRAQuantum: packet_size=4; break;
cristy3ed852e2009-09-05 21:47:34 +0000324 case CMYKQuantum: packet_size=4; break;
325 case CMYKAQuantum: packet_size=5; break;
326 default: break;
327 }
328 if (quantum_info->pack == MagickFalse)
cristyc9672a92010-01-06 00:57:45 +0000329 return((size_t) (packet_size*image->columns*((quantum_info->depth+7)/8)));
330 return((size_t) ((packet_size*image->columns*quantum_info->depth+7)/8));
cristy3ed852e2009-09-05 21:47:34 +0000331}
332
333/*
334%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335% %
336% %
337% %
cristy9d4918b2012-11-14 20:18:32 +0000338% G e t Q u a n t u m E n d i a n %
339% %
340% %
341% %
342%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
343%
344% GetQuantumEndian() returns the quantum endian of the image.
345%
346% The endian of the GetQuantumEndian method is:
347%
348% EndianType GetQuantumEndian(const QuantumInfo *quantum_info)
349%
350% A description of each parameter follows:
351%
352% o quantum_info: the quantum info.
353%
354*/
355MagickExport EndianType GetQuantumEndian(const QuantumInfo *quantum_info)
356{
357 assert(quantum_info != (QuantumInfo *) NULL);
358 assert(quantum_info->signature == MagickSignature);
359 return(quantum_info->endian);
360}
361
362/*
363%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
364% %
365% %
366% %
cristye11d00a2011-12-06 18:03:25 +0000367% G e t Q u a n t u m F o r m a t %
368% %
369% %
370% %
371%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
372%
373% GetQuantumFormat() returns the quantum format of the image.
374%
375% The format of the GetQuantumFormat method is:
376%
377% QuantumFormatType GetQuantumFormat(const QuantumInfo *quantum_info)
378%
379% A description of each parameter follows:
380%
381% o quantum_info: the quantum info.
382%
383*/
384MagickExport QuantumFormatType GetQuantumFormat(const QuantumInfo *quantum_info)
385{
386 assert(quantum_info != (QuantumInfo *) NULL);
387 assert(quantum_info->signature == MagickSignature);
388 return(quantum_info->format);
389}
390
391/*
392%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
393% %
394% %
395% %
cristy3ed852e2009-09-05 21:47:34 +0000396% G e t Q u a n t u m I n f o %
397% %
398% %
399% %
400%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
401%
402% GetQuantumInfo() initializes the QuantumInfo structure to default values.
403%
404% The format of the GetQuantumInfo method is:
405%
406% GetQuantumInfo(const ImageInfo *image_info,QuantumInfo *quantum_info)
407%
408% A description of each parameter follows:
409%
410% o image_info: the image info.
411%
412% o quantum_info: the quantum info.
413%
414*/
415MagickExport void GetQuantumInfo(const ImageInfo *image_info,
416 QuantumInfo *quantum_info)
417{
418 const char
419 *option;
420
421 assert(quantum_info != (QuantumInfo *) NULL);
422 (void) ResetMagickMemory(quantum_info,0,sizeof(*quantum_info));
423 quantum_info->quantum=8;
424 quantum_info->maximum=1.0;
425 quantum_info->scale=QuantumRange;
426 quantum_info->pack=MagickTrue;
cristy3d162a92014-02-16 14:05:06 +0000427 quantum_info->semaphore=AcquireSemaphoreInfo();
cristy3ed852e2009-09-05 21:47:34 +0000428 quantum_info->signature=MagickSignature;
429 if (image_info == (const ImageInfo *) NULL)
430 return;
431 option=GetImageOption(image_info,"quantum:format");
432 if (option != (char *) NULL)
cristy042ee782011-04-22 18:48:30 +0000433 quantum_info->format=(QuantumFormatType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +0000434 MagickQuantumFormatOptions,MagickFalse,option);
435 option=GetImageOption(image_info,"quantum:minimum");
436 if (option != (char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +0000437 quantum_info->minimum=StringToDouble(option,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000438 option=GetImageOption(image_info,"quantum:maximum");
439 if (option != (char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +0000440 quantum_info->maximum=StringToDouble(option,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000441 if ((quantum_info->minimum == 0.0) && (quantum_info->maximum == 0.0))
442 quantum_info->scale=0.0;
443 else
444 if (quantum_info->minimum == quantum_info->maximum)
445 {
cristya19f1d72012-08-07 18:24:38 +0000446 quantum_info->scale=(double) QuantumRange/quantum_info->minimum;
cristy3ed852e2009-09-05 21:47:34 +0000447 quantum_info->minimum=0.0;
448 }
449 else
cristya19f1d72012-08-07 18:24:38 +0000450 quantum_info->scale=(double) QuantumRange/(quantum_info->maximum-
cristy3ed852e2009-09-05 21:47:34 +0000451 quantum_info->minimum);
452 option=GetImageOption(image_info,"quantum:scale");
453 if (option != (char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +0000454 quantum_info->scale=StringToDouble(option,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000455 option=GetImageOption(image_info,"quantum:polarity");
456 if (option != (char *) NULL)
457 quantum_info->min_is_white=LocaleCompare(option,"min-is-white") == 0 ?
458 MagickTrue : MagickFalse;
cristy32c68432012-01-12 15:06:28 +0000459 quantum_info->endian=image_info->endian;
460 ResetQuantumState(quantum_info);
cristy3ed852e2009-09-05 21:47:34 +0000461}
462
463/*
464%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
465% %
466% %
467% %
468% G e t Q u a n t u m P i x e l s %
469% %
470% %
471% %
472%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
473%
474% GetQuantumPixels() returns the quantum pixels.
475%
476% The format of the GetQuantumPixels method is:
477%
478% unsigned char *QuantumPixels GetQuantumPixels(
479% const QuantumInfo *quantum_info)
480%
481% A description of each parameter follows:
482%
483% o image: the image.
484%
485*/
486MagickExport unsigned char *GetQuantumPixels(const QuantumInfo *quantum_info)
487{
cristy5c9e6f22010-09-17 17:31:01 +0000488 const int
489 id = GetOpenMPThreadId();
cristy3ed852e2009-09-05 21:47:34 +0000490
491 assert(quantum_info != (QuantumInfo *) NULL);
492 assert(quantum_info->signature == MagickSignature);
cristy3ed852e2009-09-05 21:47:34 +0000493 return(quantum_info->pixels[id]);
494}
495
496/*
497%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
498% %
499% %
500% %
501% G e t Q u a n t u m T y p e %
502% %
503% %
504% %
505%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
506%
507% GetQuantumType() returns the quantum type of the image.
508%
509% The format of the GetQuantumType method is:
510%
511% QuantumType GetQuantumType(Image *image,ExceptionInfo *exception)
512%
513% A description of each parameter follows:
514%
515% o image: the image.
516%
cristy5b4868f2014-12-14 17:43:35 +0000517% o exception: return any errors or warnings in this structure.
518%
cristy3ed852e2009-09-05 21:47:34 +0000519*/
520MagickExport QuantumType GetQuantumType(Image *image,ExceptionInfo *exception)
521{
522 QuantumType
523 quantum_type;
524
525 assert(image != (Image *) NULL);
526 assert(image->signature == MagickSignature);
527 if (image->debug != MagickFalse)
528 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
529 quantum_type=RGBQuantum;
cristy9f36ba72014-12-07 22:55:01 +0000530 if (image->alpha_trait != UndefinedPixelTrait)
cristy3ed852e2009-09-05 21:47:34 +0000531 quantum_type=RGBAQuantum;
532 if (image->colorspace == CMYKColorspace)
533 {
534 quantum_type=CMYKQuantum;
cristy9f36ba72014-12-07 22:55:01 +0000535 if (image->alpha_trait != UndefinedPixelTrait)
cristy3ed852e2009-09-05 21:47:34 +0000536 quantum_type=CMYKAQuantum;
537 }
cristy4c08aed2011-07-01 19:47:50 +0000538 if (IsImageGray(image,exception) != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000539 {
540 quantum_type=GrayQuantum;
cristy9f36ba72014-12-07 22:55:01 +0000541 if (image->alpha_trait != UndefinedPixelTrait)
cristy3ed852e2009-09-05 21:47:34 +0000542 quantum_type=GrayAlphaQuantum;
543 }
cristybdbf4b62012-05-13 22:22:59 +0000544 if (image->storage_class == PseudoClass)
545 {
546 quantum_type=IndexQuantum;
cristy9f36ba72014-12-07 22:55:01 +0000547 if (image->alpha_trait != UndefinedPixelTrait)
cristybdbf4b62012-05-13 22:22:59 +0000548 quantum_type=IndexAlphaQuantum;
549 }
cristy3ed852e2009-09-05 21:47:34 +0000550 return(quantum_type);
551}
552
553/*
554%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
555% %
556% %
557% %
cristy79630222012-01-14 01:38:37 +0000558+ R e s e t Q u a n t u m S t a t e %
cristy32c68432012-01-12 15:06:28 +0000559% %
560% %
561% %
562%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
563%
564% ResetQuantumState() resets the quantum state.
565%
566% The format of the ResetQuantumState method is:
567%
568% void ResetQuantumState(QuantumInfo *quantum_info)
569%
570% A description of each parameter follows:
571%
572% o quantum_info: the quantum info.
573%
574*/
cristy79630222012-01-14 01:38:37 +0000575MagickPrivate void ResetQuantumState(QuantumInfo *quantum_info)
cristy32c68432012-01-12 15:06:28 +0000576{
577 static const unsigned int mask[32] =
578 {
579 0x00000000U, 0x00000001U, 0x00000003U, 0x00000007U, 0x0000000fU,
580 0x0000001fU, 0x0000003fU, 0x0000007fU, 0x000000ffU, 0x000001ffU,
581 0x000003ffU, 0x000007ffU, 0x00000fffU, 0x00001fffU, 0x00003fffU,
582 0x00007fffU, 0x0000ffffU, 0x0001ffffU, 0x0003ffffU, 0x0007ffffU,
583 0x000fffffU, 0x001fffffU, 0x003fffffU, 0x007fffffU, 0x00ffffffU,
584 0x01ffffffU, 0x03ffffffU, 0x07ffffffU, 0x0fffffffU, 0x1fffffffU,
585 0x3fffffffU, 0x7fffffffU
586 };
587
588 assert(quantum_info != (QuantumInfo *) NULL);
589 assert(quantum_info->signature == MagickSignature);
590 quantum_info->state.inverse_scale=1.0;
591 if (fabs(quantum_info->scale) >= MagickEpsilon)
592 quantum_info->state.inverse_scale/=quantum_info->scale;
593 quantum_info->state.pixel=0U;
594 quantum_info->state.bits=0U;
595 quantum_info->state.mask=mask;
596}
597
598/*
599%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
600% %
601% %
602% %
cristy3ed852e2009-09-05 21:47:34 +0000603% S e t Q u a n t u m F o r m a t %
604% %
605% %
606% %
607%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
608%
609% SetQuantumAlphaType() sets the quantum format.
610%
611% The format of the SetQuantumAlphaType method is:
612%
613% void SetQuantumAlphaType(QuantumInfo *quantum_info,
614% const QuantumAlphaType type)
615%
616% A description of each parameter follows:
617%
618% o quantum_info: the quantum info.
619%
620% o type: the alpha type (e.g. associate).
621%
622*/
623MagickExport void SetQuantumAlphaType(QuantumInfo *quantum_info,
624 const QuantumAlphaType type)
625{
626 assert(quantum_info != (QuantumInfo *) NULL);
627 assert(quantum_info->signature == MagickSignature);
628 quantum_info->alpha_type=type;
629}
630
631/*
632%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
633% %
634% %
635% %
636% S e t Q u a n t u m D e p t h %
637% %
638% %
639% %
640%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
641%
642% SetQuantumDepth() sets the quantum depth.
643%
644% The format of the SetQuantumDepth method is:
645%
646% MagickBooleanType SetQuantumDepth(const Image *image,
cristybb503372010-05-27 20:51:26 +0000647% QuantumInfo *quantum_info,const size_t depth)
cristy3ed852e2009-09-05 21:47:34 +0000648%
649% A description of each parameter follows:
650%
651% o image: the image.
652%
653% o quantum_info: the quantum info.
654%
655% o depth: the quantum depth.
656%
657*/
658MagickExport MagickBooleanType SetQuantumDepth(const Image *image,
cristybb503372010-05-27 20:51:26 +0000659 QuantumInfo *quantum_info,const size_t depth)
cristy3ed852e2009-09-05 21:47:34 +0000660{
cristy56d88542014-12-01 01:13:30 +0000661 size_t
662 extent,
663 quantum;
cristy3ed852e2009-09-05 21:47:34 +0000664
665 /*
666 Allocate the quantum pixel buffer.
667 */
668 assert(image != (Image *) NULL);
669 assert(image->signature == MagickSignature);
670 if (image->debug != MagickFalse)
671 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
672 assert(quantum_info != (QuantumInfo *) NULL);
673 assert(quantum_info->signature == MagickSignature);
674 quantum_info->depth=depth;
675 if (quantum_info->format == FloatingPointQuantumFormat)
676 {
677 if (quantum_info->depth > 32)
678 quantum_info->depth=64;
679 else
cristyc9672a92010-01-06 00:57:45 +0000680 if (quantum_info->depth > 16)
681 quantum_info->depth=32;
682 else
683 quantum_info->depth=16;
cristy3ed852e2009-09-05 21:47:34 +0000684 }
cristy3ed852e2009-09-05 21:47:34 +0000685 if (quantum_info->pixels != (unsigned char **) NULL)
686 DestroyQuantumPixels(quantum_info);
cristy56d88542014-12-01 01:13:30 +0000687 quantum=(quantum_info->pad+6)*(quantum_info->depth+7)/8;
688 extent=image->columns*quantum;
689 if (quantum != (extent/image->columns))
690 return(MagickFalse);
691 return(AcquireQuantumPixels(quantum_info,extent));
cristy3ed852e2009-09-05 21:47:34 +0000692}
693
694/*
695%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
696% %
697% %
698% %
cristy9d4918b2012-11-14 20:18:32 +0000699% S e t Q u a n t u m E n d i a n %
700% %
701% %
702% %
703%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
704%
705% SetQuantumEndian() sets the quantum endian.
706%
707% The endian of the SetQuantumEndian method is:
708%
709% MagickBooleanType SetQuantumEndian(const Image *image,
710% QuantumInfo *quantum_info,const EndianType endian)
711%
712% A description of each parameter follows:
713%
714% o image: the image.
715%
716% o quantum_info: the quantum info.
717%
718% o endian: the quantum endian.
719%
720*/
721MagickExport MagickBooleanType SetQuantumEndian(const Image *image,
722 QuantumInfo *quantum_info,const EndianType endian)
723{
724 assert(image != (Image *) NULL);
725 assert(image->signature == MagickSignature);
726 if (image->debug != MagickFalse)
727 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
728 assert(quantum_info != (QuantumInfo *) NULL);
729 assert(quantum_info->signature == MagickSignature);
730 quantum_info->endian=endian;
731 return(SetQuantumDepth(image,quantum_info,quantum_info->depth));
732}
733
734/*
735%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
736% %
737% %
738% %
cristy3ed852e2009-09-05 21:47:34 +0000739% S e t Q u a n t u m F o r m a t %
740% %
741% %
742% %
743%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
744%
745% SetQuantumFormat() sets the quantum format.
746%
747% The format of the SetQuantumFormat method is:
748%
749% MagickBooleanType SetQuantumFormat(const Image *image,
750% QuantumInfo *quantum_info,const QuantumFormatType format)
751%
752% A description of each parameter follows:
753%
754% o image: the image.
755%
756% o quantum_info: the quantum info.
757%
758% o format: the quantum format.
759%
760*/
761MagickExport MagickBooleanType SetQuantumFormat(const Image *image,
762 QuantumInfo *quantum_info,const QuantumFormatType format)
763{
764 assert(image != (Image *) NULL);
765 assert(image->signature == MagickSignature);
766 if (image->debug != MagickFalse)
767 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
768 assert(quantum_info != (QuantumInfo *) NULL);
769 assert(quantum_info->signature == MagickSignature);
770 quantum_info->format=format;
771 return(SetQuantumDepth(image,quantum_info,quantum_info->depth));
772}
773
774/*
775%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
776% %
777% %
778% %
779% S e t Q u a n t u m I m a g e T y p e %
780% %
781% %
782% %
783%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
784%
785% SetQuantumImageType() sets the image type based on the quantum type.
786%
787% The format of the SetQuantumImageType method is:
788%
789% void ImageType SetQuantumImageType(Image *image,
790% const QuantumType quantum_type)
791%
792% A description of each parameter follows:
793%
794% o image: the image.
795%
796% o quantum_type: Declare which pixel components to transfer (red, green,
797% blue, opacity, RGB, or RGBA).
798%
799*/
800MagickExport void SetQuantumImageType(Image *image,
801 const QuantumType quantum_type)
802{
803 assert(image != (Image *) NULL);
804 assert(image->signature == MagickSignature);
805 if (image->debug != MagickFalse)
806 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
807 switch (quantum_type)
808 {
809 case IndexQuantum:
810 case IndexAlphaQuantum:
811 {
812 image->type=PaletteType;
813 break;
814 }
815 case GrayQuantum:
816 case GrayAlphaQuantum:
817 {
818 image->type=GrayscaleType;
819 if (image->depth == 1)
820 image->type=BilevelType;
821 break;
822 }
823 case CyanQuantum:
824 case MagentaQuantum:
825 case YellowQuantum:
826 case BlackQuantum:
827 case CMYKQuantum:
828 case CMYKAQuantum:
829 {
830 image->type=ColorSeparationType;
831 break;
832 }
833 default:
834 {
835 image->type=TrueColorType;
836 break;
837 }
838 }
839}
840
841/*
842%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
843% %
844% %
845% %
846% S e t Q u a n t u m P a c k %
847% %
848% %
849% %
850%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
851%
852% SetQuantumPack() sets the quantum pack flag.
853%
854% The format of the SetQuantumPack method is:
855%
856% void SetQuantumPack(QuantumInfo *quantum_info,
857% const MagickBooleanType pack)
858%
859% A description of each parameter follows:
860%
861% o quantum_info: the quantum info.
862%
863% o pack: the pack flag.
864%
865*/
866MagickExport void SetQuantumPack(QuantumInfo *quantum_info,
867 const MagickBooleanType pack)
868{
869 assert(quantum_info != (QuantumInfo *) NULL);
870 assert(quantum_info->signature == MagickSignature);
871 quantum_info->pack=pack;
872}
873
874
875/*
876%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
877% %
878% %
879% %
880% S e t Q u a n t u m P a d %
881% %
882% %
883% %
884%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
885%
886% SetQuantumPad() sets the quantum pad.
887%
888% The format of the SetQuantumPad method is:
889%
890% MagickBooleanType SetQuantumPad(const Image *image,
cristybb503372010-05-27 20:51:26 +0000891% QuantumInfo *quantum_info,const size_t pad)
cristy3ed852e2009-09-05 21:47:34 +0000892%
893% A description of each parameter follows:
894%
895% o image: the image.
896%
897% o quantum_info: the quantum info.
898%
899% o pad: the quantum pad.
900%
901*/
902MagickExport MagickBooleanType SetQuantumPad(const Image *image,
cristybb503372010-05-27 20:51:26 +0000903 QuantumInfo *quantum_info,const size_t pad)
cristy3ed852e2009-09-05 21:47:34 +0000904{
905 assert(image != (Image *) NULL);
906 assert(image->signature == MagickSignature);
907 if (image->debug != MagickFalse)
908 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
909 assert(quantum_info != (QuantumInfo *) NULL);
910 assert(quantum_info->signature == MagickSignature);
911 quantum_info->pad=pad;
912 return(SetQuantumDepth(image,quantum_info,quantum_info->depth));
913}
914
915/*
916%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
917% %
918% %
919% %
920% S e t Q u a n t u m M i n I s W h i t e %
921% %
922% %
923% %
924%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
925%
926% SetQuantumMinIsWhite() sets the quantum min-is-white flag.
927%
928% The format of the SetQuantumMinIsWhite method is:
929%
930% void SetQuantumMinIsWhite(QuantumInfo *quantum_info,
931% const MagickBooleanType min_is_white)
932%
933% A description of each parameter follows:
934%
935% o quantum_info: the quantum info.
936%
937% o min_is_white: the min-is-white flag.
938%
939*/
940MagickExport void SetQuantumMinIsWhite(QuantumInfo *quantum_info,
941 const MagickBooleanType min_is_white)
942{
943 assert(quantum_info != (QuantumInfo *) NULL);
944 assert(quantum_info->signature == MagickSignature);
945 quantum_info->min_is_white=min_is_white;
946}
947
948/*
949%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
950% %
951% %
952% %
953% S e t Q u a n t u m Q u a n t u m %
954% %
955% %
956% %
957%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
958%
959% SetQuantumQuantum() sets the quantum quantum.
960%
961% The format of the SetQuantumQuantum method is:
962%
963% void SetQuantumQuantum(QuantumInfo *quantum_info,
cristybb503372010-05-27 20:51:26 +0000964% const size_t quantum)
cristy3ed852e2009-09-05 21:47:34 +0000965%
966% A description of each parameter follows:
967%
968% o quantum_info: the quantum info.
969%
970% o quantum: the quantum quantum.
971%
972*/
973MagickExport void SetQuantumQuantum(QuantumInfo *quantum_info,
cristybb503372010-05-27 20:51:26 +0000974 const size_t quantum)
cristy3ed852e2009-09-05 21:47:34 +0000975{
976 assert(quantum_info != (QuantumInfo *) NULL);
977 assert(quantum_info->signature == MagickSignature);
978 quantum_info->quantum=quantum;
979}
980
981/*
982%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
983% %
984% %
985% %
986% S e t Q u a n t u m S c a l e %
987% %
988% %
989% %
990%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
991%
992% SetQuantumScale() sets the quantum scale.
993%
994% The format of the SetQuantumScale method is:
995%
996% void SetQuantumScale(QuantumInfo *quantum_info,const double scale)
997%
998% A description of each parameter follows:
999%
1000% o quantum_info: the quantum info.
1001%
1002% o scale: the quantum scale.
1003%
1004*/
1005MagickExport void SetQuantumScale(QuantumInfo *quantum_info,const double scale)
1006{
1007 assert(quantum_info != (QuantumInfo *) NULL);
1008 assert(quantum_info->signature == MagickSignature);
1009 quantum_info->scale=scale;
1010}