blob: 5950dcb43e133d242ab3ee26a2144b1a3d2e6537 [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 %
15% John Cristy %
16% October 1998 %
17% %
18% %
19% Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization %
20% dedicated to making software imaging solutions freely available. %
21% %
22% You may not use this file except in compliance with the License. You may %
23% obtain a copy of the License at %
24% %
25% http://www.imagemagick.org/script/license.php %
26% %
27% Unless required by applicable law or agreed to in writing, software %
28% distributed under the License is distributed on an "AS IS" BASIS, %
29% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
30% See the License for the specific language governing permissions and %
31% limitations under the License. %
32% %
33%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34%
35%
36*/
37
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"
49#include "MagickCore/constitute.h"
50#include "MagickCore/delegate.h"
51#include "MagickCore/geometry.h"
52#include "MagickCore/list.h"
53#include "MagickCore/magick.h"
54#include "MagickCore/memory_.h"
55#include "MagickCore/monitor.h"
56#include "MagickCore/option.h"
57#include "MagickCore/pixel.h"
58#include "MagickCore/pixel-accessor.h"
59#include "MagickCore/property.h"
60#include "MagickCore/quantum.h"
61#include "MagickCore/quantum-private.h"
62#include "MagickCore/resource_.h"
63#include "MagickCore/semaphore.h"
64#include "MagickCore/statistic.h"
65#include "MagickCore/stream.h"
66#include "MagickCore/string_.h"
67#include "MagickCore/string-private.h"
68#include "MagickCore/thread-private.h"
69#include "MagickCore/utility.h"
cristy3ed852e2009-09-05 21:47:34 +000070
71/*
72 Define declarations.
73*/
74#define QuantumSignature 0xab
75
76/*
77 Forward declarations.
78*/
79static void
80 DestroyQuantumPixels(QuantumInfo *);
81
82/*
83%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84% %
85% %
86% %
87% A c q u i r e Q u a n t u m I n f o %
88% %
89% %
90% %
91%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92%
93% AcquireQuantumInfo() allocates the QuantumInfo structure.
94%
95% The format of the AcquireQuantumInfo method is:
96%
97% QuantumInfo *AcquireQuantumInfo(const ImageInfo *image_info,Image *image)
98%
99% A description of each parameter follows:
100%
101% o image_info: the image info.
102%
103% o image: the image.
104%
105*/
106
cristybb503372010-05-27 20:51:26 +0000107static inline size_t MagickMax(const size_t x,
108 const size_t y)
cristy3ed852e2009-09-05 21:47:34 +0000109{
110 if (x > y)
111 return(x);
112 return(y);
113}
114
115MagickExport QuantumInfo *AcquireQuantumInfo(const ImageInfo *image_info,
116 Image *image)
117{
118 MagickBooleanType
119 status;
120
121 QuantumInfo
122 *quantum_info;
123
cristy73bd4a52010-10-05 11:24:23 +0000124 quantum_info=(QuantumInfo *) AcquireMagickMemory(sizeof(*quantum_info));
cristy3ed852e2009-09-05 21:47:34 +0000125 if (quantum_info == (QuantumInfo *) NULL)
126 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
127 quantum_info->signature=MagickSignature;
128 GetQuantumInfo(image_info,quantum_info);
129 if (image == (const Image *) NULL)
130 return(quantum_info);
131 status=SetQuantumDepth(image,quantum_info,image->depth);
132 if (status == MagickFalse)
133 quantum_info=DestroyQuantumInfo(quantum_info);
134 return(quantum_info);
135}
136
137/*
138%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139% %
140% %
141% %
142+ A c q u i r e Q u a n t u m P i x e l s %
143% %
144% %
145% %
146%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147%
148% AcquireQuantumPixels() allocates the unsigned char structure.
149%
150% The format of the AcquireQuantumPixels method is:
151%
152% MagickBooleanType AcquireQuantumPixels(QuantumInfo *quantum_info,
153% const size_t extent)
154%
155% A description of each parameter follows:
156%
157% o quantum_info: the quantum info.
158%
159% o extent: the quantum info.
160%
161*/
162static MagickBooleanType AcquireQuantumPixels(QuantumInfo *quantum_info,
163 const size_t extent)
164{
cristybb503372010-05-27 20:51:26 +0000165 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000166 i;
167
168 assert(quantum_info != (QuantumInfo *) NULL);
169 assert(quantum_info->signature == MagickSignature);
170 quantum_info->number_threads=GetOpenMPMaximumThreads();
171 quantum_info->pixels=(unsigned char **) AcquireQuantumMemory(
172 quantum_info->number_threads,sizeof(*quantum_info->pixels));
173 if (quantum_info->pixels == (unsigned char **) NULL)
174 return(MagickFalse);
175 quantum_info->extent=extent;
176 (void) ResetMagickMemory(quantum_info->pixels,0,
cristyed6b55a2010-10-06 02:15:05 +0000177 quantum_info->number_threads*sizeof(*quantum_info->pixels));
cristybb503372010-05-27 20:51:26 +0000178 for (i=0; i < (ssize_t) quantum_info->number_threads; i++)
cristy3ed852e2009-09-05 21:47:34 +0000179 {
180 quantum_info->pixels[i]=(unsigned char *) AcquireQuantumMemory(extent+1,
181 sizeof(**quantum_info->pixels));
cristy84787932009-10-06 19:18:19 +0000182 if (quantum_info->pixels[i] == (unsigned char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000183 return(MagickFalse);
184 (void) ResetMagickMemory(quantum_info->pixels[i],0,(extent+1)*
185 sizeof(**quantum_info->pixels));
186 quantum_info->pixels[i][extent]=QuantumSignature;
187 }
188 return(MagickTrue);
189}
190
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)
221 DestroySemaphoreInfo(&quantum_info->semaphore);
222 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% %
cristye11d00a2011-12-06 18:03:25 +0000335% G e t Q u a n t u m F o r m a t %
336% %
337% %
338% %
339%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
340%
341% GetQuantumFormat() returns the quantum format of the image.
342%
343% The format of the GetQuantumFormat method is:
344%
345% QuantumFormatType GetQuantumFormat(const QuantumInfo *quantum_info)
346%
347% A description of each parameter follows:
348%
349% o quantum_info: the quantum info.
350%
351*/
352MagickExport QuantumFormatType GetQuantumFormat(const QuantumInfo *quantum_info)
353{
354 assert(quantum_info != (QuantumInfo *) NULL);
355 assert(quantum_info->signature == MagickSignature);
356 return(quantum_info->format);
357}
358
359/*
360%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
361% %
362% %
363% %
cristy3ed852e2009-09-05 21:47:34 +0000364% G e t Q u a n t u m I n f o %
365% %
366% %
367% %
368%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
369%
370% GetQuantumInfo() initializes the QuantumInfo structure to default values.
371%
372% The format of the GetQuantumInfo method is:
373%
374% GetQuantumInfo(const ImageInfo *image_info,QuantumInfo *quantum_info)
375%
376% A description of each parameter follows:
377%
378% o image_info: the image info.
379%
380% o quantum_info: the quantum info.
381%
382*/
383MagickExport void GetQuantumInfo(const ImageInfo *image_info,
384 QuantumInfo *quantum_info)
385{
386 const char
387 *option;
388
389 assert(quantum_info != (QuantumInfo *) NULL);
390 (void) ResetMagickMemory(quantum_info,0,sizeof(*quantum_info));
391 quantum_info->quantum=8;
392 quantum_info->maximum=1.0;
393 quantum_info->scale=QuantumRange;
394 quantum_info->pack=MagickTrue;
395 quantum_info->semaphore=AllocateSemaphoreInfo();
396 quantum_info->signature=MagickSignature;
397 if (image_info == (const ImageInfo *) NULL)
398 return;
399 option=GetImageOption(image_info,"quantum:format");
400 if (option != (char *) NULL)
cristy042ee782011-04-22 18:48:30 +0000401 quantum_info->format=(QuantumFormatType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +0000402 MagickQuantumFormatOptions,MagickFalse,option);
403 option=GetImageOption(image_info,"quantum:minimum");
404 if (option != (char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +0000405 quantum_info->minimum=StringToDouble(option,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000406 option=GetImageOption(image_info,"quantum:maximum");
407 if (option != (char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +0000408 quantum_info->maximum=StringToDouble(option,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000409 if ((quantum_info->minimum == 0.0) && (quantum_info->maximum == 0.0))
410 quantum_info->scale=0.0;
411 else
412 if (quantum_info->minimum == quantum_info->maximum)
413 {
414 quantum_info->scale=(MagickRealType) QuantumRange/quantum_info->minimum;
415 quantum_info->minimum=0.0;
416 }
417 else
418 quantum_info->scale=(MagickRealType) QuantumRange/(quantum_info->maximum-
419 quantum_info->minimum);
420 option=GetImageOption(image_info,"quantum:scale");
421 if (option != (char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +0000422 quantum_info->scale=StringToDouble(option,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000423 option=GetImageOption(image_info,"quantum:polarity");
424 if (option != (char *) NULL)
425 quantum_info->min_is_white=LocaleCompare(option,"min-is-white") == 0 ?
426 MagickTrue : MagickFalse;
cristy32c68432012-01-12 15:06:28 +0000427 quantum_info->endian=image_info->endian;
428 ResetQuantumState(quantum_info);
cristy3ed852e2009-09-05 21:47:34 +0000429}
430
431/*
432%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
433% %
434% %
435% %
436% G e t Q u a n t u m P i x e l s %
437% %
438% %
439% %
440%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
441%
442% GetQuantumPixels() returns the quantum pixels.
443%
444% The format of the GetQuantumPixels method is:
445%
446% unsigned char *QuantumPixels GetQuantumPixels(
447% const QuantumInfo *quantum_info)
448%
449% A description of each parameter follows:
450%
451% o image: the image.
452%
453*/
454MagickExport unsigned char *GetQuantumPixels(const QuantumInfo *quantum_info)
455{
cristy5c9e6f22010-09-17 17:31:01 +0000456 const int
457 id = GetOpenMPThreadId();
cristy3ed852e2009-09-05 21:47:34 +0000458
459 assert(quantum_info != (QuantumInfo *) NULL);
460 assert(quantum_info->signature == MagickSignature);
cristy3ed852e2009-09-05 21:47:34 +0000461 return(quantum_info->pixels[id]);
462}
463
464/*
465%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
466% %
467% %
468% %
469% G e t Q u a n t u m T y p e %
470% %
471% %
472% %
473%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
474%
475% GetQuantumType() returns the quantum type of the image.
476%
477% The format of the GetQuantumType method is:
478%
479% QuantumType GetQuantumType(Image *image,ExceptionInfo *exception)
480%
481% A description of each parameter follows:
482%
483% o image: the image.
484%
485*/
486MagickExport QuantumType GetQuantumType(Image *image,ExceptionInfo *exception)
487{
488 QuantumType
489 quantum_type;
490
491 assert(image != (Image *) NULL);
492 assert(image->signature == MagickSignature);
493 if (image->debug != MagickFalse)
494 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
495 quantum_type=RGBQuantum;
496 if (image->matte != MagickFalse)
497 quantum_type=RGBAQuantum;
498 if (image->colorspace == CMYKColorspace)
499 {
500 quantum_type=CMYKQuantum;
501 if (image->matte != MagickFalse)
502 quantum_type=CMYKAQuantum;
503 }
cristy4c08aed2011-07-01 19:47:50 +0000504 if (IsImageGray(image,exception) != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000505 {
506 quantum_type=GrayQuantum;
507 if (image->matte != MagickFalse)
508 quantum_type=GrayAlphaQuantum;
509 }
510 else
511 if (image->storage_class == PseudoClass)
512 {
513 quantum_type=IndexQuantum;
514 if (image->matte != MagickFalse)
515 quantum_type=IndexAlphaQuantum;
516 }
517 return(quantum_type);
518}
519
520/*
521%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
522% %
523% %
524% %
cristy79630222012-01-14 01:38:37 +0000525+ R e s e t Q u a n t u m S t a t e %
cristy32c68432012-01-12 15:06:28 +0000526% %
527% %
528% %
529%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
530%
531% ResetQuantumState() resets the quantum state.
532%
533% The format of the ResetQuantumState method is:
534%
535% void ResetQuantumState(QuantumInfo *quantum_info)
536%
537% A description of each parameter follows:
538%
539% o quantum_info: the quantum info.
540%
541*/
cristy79630222012-01-14 01:38:37 +0000542MagickPrivate void ResetQuantumState(QuantumInfo *quantum_info)
cristy32c68432012-01-12 15:06:28 +0000543{
544 static const unsigned int mask[32] =
545 {
546 0x00000000U, 0x00000001U, 0x00000003U, 0x00000007U, 0x0000000fU,
547 0x0000001fU, 0x0000003fU, 0x0000007fU, 0x000000ffU, 0x000001ffU,
548 0x000003ffU, 0x000007ffU, 0x00000fffU, 0x00001fffU, 0x00003fffU,
549 0x00007fffU, 0x0000ffffU, 0x0001ffffU, 0x0003ffffU, 0x0007ffffU,
550 0x000fffffU, 0x001fffffU, 0x003fffffU, 0x007fffffU, 0x00ffffffU,
551 0x01ffffffU, 0x03ffffffU, 0x07ffffffU, 0x0fffffffU, 0x1fffffffU,
552 0x3fffffffU, 0x7fffffffU
553 };
554
555 assert(quantum_info != (QuantumInfo *) NULL);
556 assert(quantum_info->signature == MagickSignature);
557 quantum_info->state.inverse_scale=1.0;
558 if (fabs(quantum_info->scale) >= MagickEpsilon)
559 quantum_info->state.inverse_scale/=quantum_info->scale;
560 quantum_info->state.pixel=0U;
561 quantum_info->state.bits=0U;
562 quantum_info->state.mask=mask;
563}
564
565/*
566%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
567% %
568% %
569% %
cristy3ed852e2009-09-05 21:47:34 +0000570% S e t Q u a n t u m F o r m a t %
571% %
572% %
573% %
574%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
575%
576% SetQuantumAlphaType() sets the quantum format.
577%
578% The format of the SetQuantumAlphaType method is:
579%
580% void SetQuantumAlphaType(QuantumInfo *quantum_info,
581% const QuantumAlphaType type)
582%
583% A description of each parameter follows:
584%
585% o quantum_info: the quantum info.
586%
587% o type: the alpha type (e.g. associate).
588%
589*/
590MagickExport void SetQuantumAlphaType(QuantumInfo *quantum_info,
591 const QuantumAlphaType type)
592{
593 assert(quantum_info != (QuantumInfo *) NULL);
594 assert(quantum_info->signature == MagickSignature);
595 quantum_info->alpha_type=type;
596}
597
598/*
599%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
600% %
601% %
602% %
603% S e t Q u a n t u m D e p t h %
604% %
605% %
606% %
607%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
608%
609% SetQuantumDepth() sets the quantum depth.
610%
611% The format of the SetQuantumDepth method is:
612%
613% MagickBooleanType SetQuantumDepth(const Image *image,
cristybb503372010-05-27 20:51:26 +0000614% QuantumInfo *quantum_info,const size_t depth)
cristy3ed852e2009-09-05 21:47:34 +0000615%
616% A description of each parameter follows:
617%
618% o image: the image.
619%
620% o quantum_info: the quantum info.
621%
622% o depth: the quantum depth.
623%
624*/
625MagickExport MagickBooleanType SetQuantumDepth(const Image *image,
cristybb503372010-05-27 20:51:26 +0000626 QuantumInfo *quantum_info,const size_t depth)
cristy3ed852e2009-09-05 21:47:34 +0000627{
628 MagickBooleanType
629 status;
630
631 /*
632 Allocate the quantum pixel buffer.
633 */
634 assert(image != (Image *) NULL);
635 assert(image->signature == MagickSignature);
636 if (image->debug != MagickFalse)
637 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
638 assert(quantum_info != (QuantumInfo *) NULL);
639 assert(quantum_info->signature == MagickSignature);
640 quantum_info->depth=depth;
641 if (quantum_info->format == FloatingPointQuantumFormat)
642 {
643 if (quantum_info->depth > 32)
644 quantum_info->depth=64;
645 else
cristyc9672a92010-01-06 00:57:45 +0000646 if (quantum_info->depth > 16)
647 quantum_info->depth=32;
648 else
649 quantum_info->depth=16;
cristy3ed852e2009-09-05 21:47:34 +0000650 }
cristy3ed852e2009-09-05 21:47:34 +0000651 if (quantum_info->pixels != (unsigned char **) NULL)
652 DestroyQuantumPixels(quantum_info);
cristya3274322010-05-14 23:22:12 +0000653 status=AcquireQuantumPixels(quantum_info,(6+quantum_info->pad)*image->columns*
cristy2dfdad32010-05-15 14:15:35 +0000654 ((quantum_info->depth+7)/8)); /* allow for CMYKA + RLE byte + pad */
cristy3ed852e2009-09-05 21:47:34 +0000655 return(status);
656}
657
658/*
659%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
660% %
661% %
662% %
663% S e t Q u a n t u m F o r m a t %
664% %
665% %
666% %
667%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
668%
669% SetQuantumFormat() sets the quantum format.
670%
671% The format of the SetQuantumFormat method is:
672%
673% MagickBooleanType SetQuantumFormat(const Image *image,
674% QuantumInfo *quantum_info,const QuantumFormatType format)
675%
676% A description of each parameter follows:
677%
678% o image: the image.
679%
680% o quantum_info: the quantum info.
681%
682% o format: the quantum format.
683%
684*/
685MagickExport MagickBooleanType SetQuantumFormat(const Image *image,
686 QuantumInfo *quantum_info,const QuantumFormatType format)
687{
688 assert(image != (Image *) NULL);
689 assert(image->signature == MagickSignature);
690 if (image->debug != MagickFalse)
691 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
692 assert(quantum_info != (QuantumInfo *) NULL);
693 assert(quantum_info->signature == MagickSignature);
694 quantum_info->format=format;
695 return(SetQuantumDepth(image,quantum_info,quantum_info->depth));
696}
697
698/*
699%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
700% %
701% %
702% %
703% S e t Q u a n t u m I m a g e T y p e %
704% %
705% %
706% %
707%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
708%
709% SetQuantumImageType() sets the image type based on the quantum type.
710%
711% The format of the SetQuantumImageType method is:
712%
713% void ImageType SetQuantumImageType(Image *image,
714% const QuantumType quantum_type)
715%
716% A description of each parameter follows:
717%
718% o image: the image.
719%
720% o quantum_type: Declare which pixel components to transfer (red, green,
721% blue, opacity, RGB, or RGBA).
722%
723*/
724MagickExport void SetQuantumImageType(Image *image,
725 const QuantumType quantum_type)
726{
727 assert(image != (Image *) NULL);
728 assert(image->signature == MagickSignature);
729 if (image->debug != MagickFalse)
730 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
731 switch (quantum_type)
732 {
733 case IndexQuantum:
734 case IndexAlphaQuantum:
735 {
736 image->type=PaletteType;
737 break;
738 }
739 case GrayQuantum:
740 case GrayAlphaQuantum:
741 {
742 image->type=GrayscaleType;
743 if (image->depth == 1)
744 image->type=BilevelType;
745 break;
746 }
747 case CyanQuantum:
748 case MagentaQuantum:
749 case YellowQuantum:
750 case BlackQuantum:
751 case CMYKQuantum:
752 case CMYKAQuantum:
753 {
754 image->type=ColorSeparationType;
755 break;
756 }
757 default:
758 {
759 image->type=TrueColorType;
760 break;
761 }
762 }
763}
764
765/*
766%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
767% %
768% %
769% %
770% S e t Q u a n t u m P a c k %
771% %
772% %
773% %
774%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
775%
776% SetQuantumPack() sets the quantum pack flag.
777%
778% The format of the SetQuantumPack method is:
779%
780% void SetQuantumPack(QuantumInfo *quantum_info,
781% const MagickBooleanType pack)
782%
783% A description of each parameter follows:
784%
785% o quantum_info: the quantum info.
786%
787% o pack: the pack flag.
788%
789*/
790MagickExport void SetQuantumPack(QuantumInfo *quantum_info,
791 const MagickBooleanType pack)
792{
793 assert(quantum_info != (QuantumInfo *) NULL);
794 assert(quantum_info->signature == MagickSignature);
795 quantum_info->pack=pack;
796}
797
798
799/*
800%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
801% %
802% %
803% %
804% S e t Q u a n t u m P a d %
805% %
806% %
807% %
808%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
809%
810% SetQuantumPad() sets the quantum pad.
811%
812% The format of the SetQuantumPad method is:
813%
814% MagickBooleanType SetQuantumPad(const Image *image,
cristybb503372010-05-27 20:51:26 +0000815% QuantumInfo *quantum_info,const size_t pad)
cristy3ed852e2009-09-05 21:47:34 +0000816%
817% A description of each parameter follows:
818%
819% o image: the image.
820%
821% o quantum_info: the quantum info.
822%
823% o pad: the quantum pad.
824%
825*/
826MagickExport MagickBooleanType SetQuantumPad(const Image *image,
cristybb503372010-05-27 20:51:26 +0000827 QuantumInfo *quantum_info,const size_t pad)
cristy3ed852e2009-09-05 21:47:34 +0000828{
829 assert(image != (Image *) NULL);
830 assert(image->signature == MagickSignature);
831 if (image->debug != MagickFalse)
832 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
833 assert(quantum_info != (QuantumInfo *) NULL);
834 assert(quantum_info->signature == MagickSignature);
835 quantum_info->pad=pad;
836 return(SetQuantumDepth(image,quantum_info,quantum_info->depth));
837}
838
839/*
840%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
841% %
842% %
843% %
844% S e t Q u a n t u m M i n I s W h i t e %
845% %
846% %
847% %
848%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
849%
850% SetQuantumMinIsWhite() sets the quantum min-is-white flag.
851%
852% The format of the SetQuantumMinIsWhite method is:
853%
854% void SetQuantumMinIsWhite(QuantumInfo *quantum_info,
855% const MagickBooleanType min_is_white)
856%
857% A description of each parameter follows:
858%
859% o quantum_info: the quantum info.
860%
861% o min_is_white: the min-is-white flag.
862%
863*/
864MagickExport void SetQuantumMinIsWhite(QuantumInfo *quantum_info,
865 const MagickBooleanType min_is_white)
866{
867 assert(quantum_info != (QuantumInfo *) NULL);
868 assert(quantum_info->signature == MagickSignature);
869 quantum_info->min_is_white=min_is_white;
870}
871
872/*
873%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
874% %
875% %
876% %
877% S e t Q u a n t u m Q u a n t u m %
878% %
879% %
880% %
881%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
882%
883% SetQuantumQuantum() sets the quantum quantum.
884%
885% The format of the SetQuantumQuantum method is:
886%
887% void SetQuantumQuantum(QuantumInfo *quantum_info,
cristybb503372010-05-27 20:51:26 +0000888% const size_t quantum)
cristy3ed852e2009-09-05 21:47:34 +0000889%
890% A description of each parameter follows:
891%
892% o quantum_info: the quantum info.
893%
894% o quantum: the quantum quantum.
895%
896*/
897MagickExport void SetQuantumQuantum(QuantumInfo *quantum_info,
cristybb503372010-05-27 20:51:26 +0000898 const size_t quantum)
cristy3ed852e2009-09-05 21:47:34 +0000899{
900 assert(quantum_info != (QuantumInfo *) NULL);
901 assert(quantum_info->signature == MagickSignature);
902 quantum_info->quantum=quantum;
903}
904
905/*
906%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
907% %
908% %
909% %
910% S e t Q u a n t u m S c a l e %
911% %
912% %
913% %
914%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
915%
916% SetQuantumScale() sets the quantum scale.
917%
918% The format of the SetQuantumScale method is:
919%
920% void SetQuantumScale(QuantumInfo *quantum_info,const double scale)
921%
922% A description of each parameter follows:
923%
924% o quantum_info: the quantum info.
925%
926% o scale: the quantum scale.
927%
928*/
929MagickExport void SetQuantumScale(QuantumInfo *quantum_info,const double scale)
930{
931 assert(quantum_info != (QuantumInfo *) NULL);
932 assert(quantum_info->signature == MagickSignature);
933 quantum_info->scale=scale;
934}