MagickCore  7.0.7
Convert, Edit, Or Compose Bitmap Images
quantum.c
Go to the documentation of this file.
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % %
4 % %
5 % %
6 % QQQ U U AAA N N TTTTT U U M M %
7 % Q Q U U A A NN N T U U MM MM %
8 % Q Q U U AAAAA N N N T U U M M M %
9 % Q QQ U U A A N NN T U U M M %
10 % QQQQ UUU A A N N T UUU M M %
11 % %
12 % MagicCore Methods to Acquire / Destroy Quantum Pixels %
13 % %
14 % Software Design %
15 % Cristy %
16 % October 1998 %
17 % %
18 % %
19 % Copyright 1999-2018 ImageMagick Studio LLC, a non-profit organization %
20 % dedicated to making software imaging solutions freely available. %
21 % %
22 % You may not use this file except in compliance with the License. You may %
23 % obtain a copy of the License at %
24 % %
25 % https://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 */
41 #include "MagickCore/studio.h"
42 #include "MagickCore/attribute.h"
43 #include "MagickCore/blob.h"
46 #include "MagickCore/exception.h"
48 #include "MagickCore/cache.h"
50 #include "MagickCore/colorspace.h"
52 #include "MagickCore/constitute.h"
53 #include "MagickCore/delegate.h"
54 #include "MagickCore/geometry.h"
55 #include "MagickCore/list.h"
56 #include "MagickCore/magick.h"
57 #include "MagickCore/memory_.h"
59 #include "MagickCore/monitor.h"
60 #include "MagickCore/option.h"
61 #include "MagickCore/pixel.h"
63 #include "MagickCore/property.h"
64 #include "MagickCore/quantum.h"
66 #include "MagickCore/resource_.h"
67 #include "MagickCore/semaphore.h"
68 #include "MagickCore/statistic.h"
69 #include "MagickCore/stream.h"
70 #include "MagickCore/string_.h"
73 #include "MagickCore/utility.h"
74 
75 /*
76  Define declarations.
77 */
78 #define QuantumSignature 0xab
79 
80 /*
81  Forward declarations.
82 */
83 static void
85 
86 /*
87 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 % %
89 % %
90 % %
91 % A c q u i r e Q u a n t u m I n f o %
92 % %
93 % %
94 % %
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 %
97 % AcquireQuantumInfo() allocates the QuantumInfo structure.
98 %
99 % The format of the AcquireQuantumInfo method is:
100 %
101 % QuantumInfo *AcquireQuantumInfo(const ImageInfo *image_info,Image *image)
102 %
103 % A description of each parameter follows:
104 %
105 % o image_info: the image info.
106 %
107 % o image: the image.
108 %
109 */
111  Image *image)
112 {
114  status;
115 
117  *quantum_info;
118 
119  quantum_info=(QuantumInfo *) AcquireCriticalMemory(sizeof(*quantum_info));
120  quantum_info->signature=MagickCoreSignature;
121  GetQuantumInfo(image_info,quantum_info);
122  if (image == (const Image *) NULL)
123  return(quantum_info);
124  status=SetQuantumDepth(image,quantum_info,image->depth);
125  quantum_info->endian=image->endian;
126  if (status == MagickFalse)
127  quantum_info=DestroyQuantumInfo(quantum_info);
128  return(quantum_info);
129 }
130 
131 /*
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 % %
134 % %
135 % %
136 + A c q u i r e Q u a n t u m P i x e l s %
137 % %
138 % %
139 % %
140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 %
142 % AcquireQuantumPixels() allocates the pixel staging areas.
143 %
144 % The format of the AcquireQuantumPixels method is:
145 %
146 % MagickBooleanType AcquireQuantumPixels(QuantumInfo *quantum_info,
147 % const size_t extent)
148 %
149 % A description of each parameter follows:
150 %
151 % o quantum_info: the quantum info.
152 %
153 % o extent: the quantum info.
154 %
155 */
157  const size_t extent)
158 {
159  register ssize_t
160  i;
161 
162  assert(quantum_info != (QuantumInfo *) NULL);
163  assert(quantum_info->signature == MagickCoreSignature);
164  quantum_info->number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
165  quantum_info->pixels=(unsigned char **) AcquireQuantumMemory(
166  quantum_info->number_threads,sizeof(*quantum_info->pixels));
167  if (quantum_info->pixels == (unsigned char **) NULL)
168  return(MagickFalse);
169  quantum_info->extent=extent;
170  (void) ResetMagickMemory(quantum_info->pixels,0,quantum_info->number_threads*
171  sizeof(*quantum_info->pixels));
172  for (i=0; i < (ssize_t) quantum_info->number_threads; i++)
173  {
174  quantum_info->pixels[i]=(unsigned char *) AcquireQuantumMemory(extent+1,
175  sizeof(**quantum_info->pixels));
176  if (quantum_info->pixels[i] == (unsigned char *) NULL)
177  {
178  while (--i >= 0)
179  quantum_info->pixels[i]=(unsigned char *) RelinquishMagickMemory(
180  quantum_info->pixels[i]);
181  return(MagickFalse);
182  }
183  (void) ResetMagickMemory(quantum_info->pixels[i],0,(extent+1)*
184  sizeof(**quantum_info->pixels));
185  quantum_info->pixels[i][extent]=QuantumSignature;
186  }
187  return(MagickTrue);
188 }
189 
190 /*
191 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192 % %
193 % %
194 % %
195 % D e s t r o y Q u a n t u m I n f o %
196 % %
197 % %
198 % %
199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
200 %
201 % DestroyQuantumInfo() deallocates memory associated with the QuantumInfo
202 % structure.
203 %
204 % The format of the DestroyQuantumInfo method is:
205 %
206 % QuantumInfo *DestroyQuantumInfo(QuantumInfo *quantum_info)
207 %
208 % A description of each parameter follows:
209 %
210 % o quantum_info: the quantum info.
211 %
212 */
214 {
215  assert(quantum_info != (QuantumInfo *) NULL);
216  assert(quantum_info->signature == MagickCoreSignature);
217  if (quantum_info->pixels != (unsigned char **) NULL)
218  DestroyQuantumPixels(quantum_info);
219  if (quantum_info->semaphore != (SemaphoreInfo *) NULL)
220  RelinquishSemaphoreInfo(&quantum_info->semaphore);
221  quantum_info->signature=(~MagickCoreSignature);
222  quantum_info=(QuantumInfo *) RelinquishMagickMemory(quantum_info);
223  return(quantum_info);
224 }
225 
226 /*
227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228 % %
229 % %
230 % %
231 + D e s t r o y Q u a n t u m P i x e l s %
232 % %
233 % %
234 % %
235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
236 %
237 % DestroyQuantumPixels() destroys the quantum pixels.
238 %
239 % The format of the DestroyQuantumPixels() method is:
240 %
241 % void DestroyQuantumPixels(QuantumInfo *quantum_info)
242 %
243 % A description of each parameter follows:
244 %
245 % o quantum_info: the quantum info.
246 %
247 */
248 static void DestroyQuantumPixels(QuantumInfo *quantum_info)
249 {
250  register ssize_t
251  i;
252 
253  ssize_t
254  extent;
255 
256  assert(quantum_info != (QuantumInfo *) NULL);
257  assert(quantum_info->signature == MagickCoreSignature);
258  assert(quantum_info->pixels != (unsigned char **) NULL);
259  extent=(ssize_t) quantum_info->extent;
260  for (i=0; i < (ssize_t) quantum_info->number_threads; i++)
261  if (quantum_info->pixels[i] != (unsigned char *) NULL)
262  {
263  /*
264  Did we overrun our quantum buffer?
265  */
266  assert(quantum_info->pixels[i][extent] == QuantumSignature);
267  quantum_info->pixels[i]=(unsigned char *) RelinquishMagickMemory(
268  quantum_info->pixels[i]);
269  }
270  quantum_info->pixels=(unsigned char **) RelinquishMagickMemory(
271  quantum_info->pixels);
272 }
273 
274 /*
275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
276 % %
277 % %
278 % %
279 % G e t Q u a n t u m E x t e n t %
280 % %
281 % %
282 % %
283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
284 %
285 % GetQuantumExtent() returns the quantum pixel buffer extent.
286 %
287 % The format of the GetQuantumExtent method is:
288 %
289 % size_t GetQuantumExtent(Image *image,const QuantumInfo *quantum_info,
290 % const QuantumType quantum_type)
291 %
292 % A description of each parameter follows:
293 %
294 % o image: the image.
295 %
296 % o quantum_info: the quantum info.
297 %
298 % o quantum_type: Declare which pixel components to transfer (red, green,
299 % blue, opacity, RGB, or RGBA).
300 %
301 */
302 MagickExport size_t GetQuantumExtent(const Image *image,
303  const QuantumInfo *quantum_info,const QuantumType quantum_type)
304 {
305  size_t
306  packet_size;
307 
308  assert(quantum_info != (QuantumInfo *) NULL);
309  assert(quantum_info->signature == MagickCoreSignature);
310  packet_size=1;
311  switch (quantum_type)
312  {
313  case GrayAlphaQuantum: packet_size=2; break;
314  case IndexAlphaQuantum: packet_size=2; break;
315  case RGBQuantum: packet_size=3; break;
316  case BGRQuantum: packet_size=3; break;
317  case RGBAQuantum: packet_size=4; break;
318  case RGBOQuantum: packet_size=4; break;
319  case BGRAQuantum: packet_size=4; break;
320  case CMYKQuantum: packet_size=4; break;
321  case CMYKAQuantum: packet_size=5; break;
322  case CbYCrAQuantum: packet_size=4; break;
323  case CbYCrQuantum: packet_size=3; break;
324  case CbYCrYQuantum: packet_size=4; break;
325  default: break;
326  }
327  if (quantum_info->pack == MagickFalse)
328  return((size_t) (packet_size*image->columns*((quantum_info->depth+7)/8)));
329  return((size_t) ((packet_size*image->columns*quantum_info->depth+7)/8));
330 }
331 
332 /*
333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
334 % %
335 % %
336 % %
337 % G e t Q u a n t u m E n d i a n %
338 % %
339 % %
340 % %
341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
342 %
343 % GetQuantumEndian() returns the quantum endian of the image.
344 %
345 % The endian of the GetQuantumEndian method is:
346 %
347 % EndianType GetQuantumEndian(const QuantumInfo *quantum_info)
348 %
349 % A description of each parameter follows:
350 %
351 % o quantum_info: the quantum info.
352 %
353 */
355 {
356  assert(quantum_info != (QuantumInfo *) NULL);
357  assert(quantum_info->signature == MagickCoreSignature);
358  return(quantum_info->endian);
359 }
360 
361 /*
362 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
363 % %
364 % %
365 % %
366 % G e t Q u a n t u m F o r m a t %
367 % %
368 % %
369 % %
370 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
371 %
372 % GetQuantumFormat() returns the quantum format of the image.
373 %
374 % The format of the GetQuantumFormat method is:
375 %
376 % QuantumFormatType GetQuantumFormat(const QuantumInfo *quantum_info)
377 %
378 % A description of each parameter follows:
379 %
380 % o quantum_info: the quantum info.
381 %
382 */
384 {
385  assert(quantum_info != (QuantumInfo *) NULL);
386  assert(quantum_info->signature == MagickCoreSignature);
387  return(quantum_info->format);
388 }
389 
390 /*
391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
392 % %
393 % %
394 % %
395 % G e t Q u a n t u m I n f o %
396 % %
397 % %
398 % %
399 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
400 %
401 % GetQuantumInfo() initializes the QuantumInfo structure to default values.
402 %
403 % The format of the GetQuantumInfo method is:
404 %
405 % GetQuantumInfo(const ImageInfo *image_info,QuantumInfo *quantum_info)
406 %
407 % A description of each parameter follows:
408 %
409 % o image_info: the image info.
410 %
411 % o quantum_info: the quantum info.
412 %
413 */
414 MagickExport void GetQuantumInfo(const ImageInfo *image_info,
415  QuantumInfo *quantum_info)
416 {
417  const char
418  *option;
419 
420  assert(quantum_info != (QuantumInfo *) NULL);
421  (void) ResetMagickMemory(quantum_info,0,sizeof(*quantum_info));
422  quantum_info->quantum=8;
423  quantum_info->maximum=1.0;
424  quantum_info->scale=QuantumRange;
425  quantum_info->pack=MagickTrue;
426  quantum_info->semaphore=AcquireSemaphoreInfo();
427  quantum_info->signature=MagickCoreSignature;
428  if (image_info == (const ImageInfo *) NULL)
429  return;
430  option=GetImageOption(image_info,"quantum:format");
431  if (option != (char *) NULL)
434  option=GetImageOption(image_info,"quantum:minimum");
435  if (option != (char *) NULL)
436  quantum_info->minimum=StringToDouble(option,(char **) NULL);
437  option=GetImageOption(image_info,"quantum:maximum");
438  if (option != (char *) NULL)
439  quantum_info->maximum=StringToDouble(option,(char **) NULL);
440  if ((quantum_info->minimum == 0.0) && (quantum_info->maximum == 0.0))
441  quantum_info->scale=0.0;
442  else
443  if (quantum_info->minimum == quantum_info->maximum)
444  {
445  quantum_info->scale=(double) QuantumRange/quantum_info->minimum;
446  quantum_info->minimum=0.0;
447  }
448  else
449  quantum_info->scale=(double) QuantumRange/(quantum_info->maximum-
450  quantum_info->minimum);
451  option=GetImageOption(image_info,"quantum:scale");
452  if (option != (char *) NULL)
453  quantum_info->scale=StringToDouble(option,(char **) NULL);
454  option=GetImageOption(image_info,"quantum:polarity");
455  if (option != (char *) NULL)
456  quantum_info->min_is_white=LocaleCompare(option,"min-is-white") == 0 ?
458  quantum_info->endian=image_info->endian;
459  ResetQuantumState(quantum_info);
460 }
461 
462 /*
463 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
464 % %
465 % %
466 % %
467 % G e t Q u a n t u m P i x e l s %
468 % %
469 % %
470 % %
471 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
472 %
473 % GetQuantumPixels() returns the quantum pixels.
474 %
475 % The format of the GetQuantumPixels method is:
476 %
477 % unsigned char *QuantumPixels GetQuantumPixels(
478 % const QuantumInfo *quantum_info)
479 %
480 % A description of each parameter follows:
481 %
482 % o image: the image.
483 %
484 */
485 MagickExport unsigned char *GetQuantumPixels(const QuantumInfo *quantum_info)
486 {
487  const int
488  id = GetOpenMPThreadId();
489 
490  assert(quantum_info != (QuantumInfo *) NULL);
491  assert(quantum_info->signature == MagickCoreSignature);
492  return(quantum_info->pixels[id]);
493 }
494 
495 /*
496 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
497 % %
498 % %
499 % %
500 % G e t Q u a n t u m T y p e %
501 % %
502 % %
503 % %
504 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
505 %
506 % GetQuantumType() returns the quantum type of the image.
507 %
508 % The format of the GetQuantumType method is:
509 %
510 % QuantumType GetQuantumType(Image *image,ExceptionInfo *exception)
511 %
512 % A description of each parameter follows:
513 %
514 % o image: the image.
515 %
516 % o exception: return any errors or warnings in this structure.
517 %
518 */
520 {
522  quantum_type;
523 
524  assert(image != (Image *) NULL);
525  assert(image->signature == MagickCoreSignature);
526  if (image->debug != MagickFalse)
527  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
528  (void) exception;
529  quantum_type=RGBQuantum;
530  if (image->alpha_trait != UndefinedPixelTrait)
531  quantum_type=RGBAQuantum;
532  if (image->colorspace == CMYKColorspace)
533  {
534  quantum_type=CMYKQuantum;
535  if (image->alpha_trait != UndefinedPixelTrait)
536  quantum_type=CMYKAQuantum;
537  }
538  if (IsGrayColorspace(image->colorspace) != MagickFalse)
539  {
540  quantum_type=GrayQuantum;
541  if (image->alpha_trait != UndefinedPixelTrait)
542  quantum_type=GrayAlphaQuantum;
543  }
544  if (image->storage_class == PseudoClass)
545  {
546  quantum_type=IndexQuantum;
547  if (image->alpha_trait != UndefinedPixelTrait)
548  quantum_type=IndexAlphaQuantum;
549  }
550  return(quantum_type);
551 }
552 
553 /*
554 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
555 % %
556 % %
557 % %
558 + R e s e t Q u a n t u m S t a t e %
559 % %
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 */
576 {
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 == MagickCoreSignature);
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 % %
603 % 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 */
624  const QuantumAlphaType type)
625 {
626  assert(quantum_info != (QuantumInfo *) NULL);
627  assert(quantum_info->signature == MagickCoreSignature);
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,
647 % QuantumInfo *quantum_info,const size_t depth)
648 %
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 */
659  QuantumInfo *quantum_info,const size_t depth)
660 {
661  size_t
662  extent,
663  quantum;
664 
665  /*
666  Allocate the quantum pixel buffer.
667  */
668  assert(image != (Image *) NULL);
669  assert(image->signature == MagickCoreSignature);
670  if (image->debug != MagickFalse)
671  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
672  assert(quantum_info != (QuantumInfo *) NULL);
673  assert(quantum_info->signature == MagickCoreSignature);
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
680  if (quantum_info->depth > 16)
681  quantum_info->depth=32;
682  else
683  quantum_info->depth=16;
684  }
685  if (quantum_info->pixels != (unsigned char **) NULL)
686  DestroyQuantumPixels(quantum_info);
687  quantum=(quantum_info->pad+6)*(quantum_info->depth+7)/8;
688  extent=MagickMax(image->columns,image->rows)*quantum;
689  if ((MagickMax(image->columns,image->rows) != 0) &&
690  (quantum != (extent/MagickMax(image->columns,image->rows))))
691  return(MagickFalse);
692  return(AcquireQuantumPixels(quantum_info,extent));
693 }
694 
695 /*
696 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
697 % %
698 % %
699 % %
700 % S e t Q u a n t u m E n d i a n %
701 % %
702 % %
703 % %
704 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
705 %
706 % SetQuantumEndian() sets the quantum endian.
707 %
708 % The endian of the SetQuantumEndian method is:
709 %
710 % MagickBooleanType SetQuantumEndian(const Image *image,
711 % QuantumInfo *quantum_info,const EndianType endian)
712 %
713 % A description of each parameter follows:
714 %
715 % o image: the image.
716 %
717 % o quantum_info: the quantum info.
718 %
719 % o endian: the quantum endian.
720 %
721 */
723  QuantumInfo *quantum_info,const EndianType endian)
724 {
725  assert(image != (Image *) NULL);
726  assert(image->signature == MagickCoreSignature);
727  if (image->debug != MagickFalse)
728  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
729  assert(quantum_info != (QuantumInfo *) NULL);
730  assert(quantum_info->signature == MagickCoreSignature);
731  quantum_info->endian=endian;
732  return(SetQuantumDepth(image,quantum_info,quantum_info->depth));
733 }
734 
735 /*
736 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
737 % %
738 % %
739 % %
740 % S e t Q u a n t u m F o r m a t %
741 % %
742 % %
743 % %
744 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
745 %
746 % SetQuantumFormat() sets the quantum format.
747 %
748 % The format of the SetQuantumFormat method is:
749 %
750 % MagickBooleanType SetQuantumFormat(const Image *image,
751 % QuantumInfo *quantum_info,const QuantumFormatType format)
752 %
753 % A description of each parameter follows:
754 %
755 % o image: the image.
756 %
757 % o quantum_info: the quantum info.
758 %
759 % o format: the quantum format.
760 %
761 */
763  QuantumInfo *quantum_info,const QuantumFormatType format)
764 {
765  assert(image != (Image *) NULL);
766  assert(image->signature == MagickCoreSignature);
767  if (image->debug != MagickFalse)
768  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
769  assert(quantum_info != (QuantumInfo *) NULL);
770  assert(quantum_info->signature == MagickCoreSignature);
771  quantum_info->format=format;
772  return(SetQuantumDepth(image,quantum_info,quantum_info->depth));
773 }
774 
775 /*
776 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
777 % %
778 % %
779 % %
780 % S e t Q u a n t u m I m a g e T y p e %
781 % %
782 % %
783 % %
784 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
785 %
786 % SetQuantumImageType() sets the image type based on the quantum type.
787 %
788 % The format of the SetQuantumImageType method is:
789 %
790 % void ImageType SetQuantumImageType(Image *image,
791 % const QuantumType quantum_type)
792 %
793 % A description of each parameter follows:
794 %
795 % o image: the image.
796 %
797 % o quantum_type: Declare which pixel components to transfer (red, green,
798 % blue, opacity, RGB, or RGBA).
799 %
800 */
802  const QuantumType quantum_type)
803 {
804  assert(image != (Image *) NULL);
805  assert(image->signature == MagickCoreSignature);
806  if (image->debug != MagickFalse)
807  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
808  switch (quantum_type)
809  {
810  case IndexQuantum:
811  case IndexAlphaQuantum:
812  {
813  image->type=PaletteType;
814  break;
815  }
816  case GrayQuantum:
817  case GrayAlphaQuantum:
818  {
819  image->type=GrayscaleType;
820  if (image->depth == 1)
821  image->type=BilevelType;
822  break;
823  }
824  case CyanQuantum:
825  case MagentaQuantum:
826  case YellowQuantum:
827  case BlackQuantum:
828  case CMYKQuantum:
829  case CMYKAQuantum:
830  {
831  image->type=ColorSeparationType;
832  break;
833  }
834  default:
835  {
836  image->type=TrueColorType;
837  break;
838  }
839  }
840 }
841 
842 /*
843 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
844 % %
845 % %
846 % %
847 % S e t Q u a n t u m P a c k %
848 % %
849 % %
850 % %
851 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
852 %
853 % SetQuantumPack() sets the quantum pack flag.
854 %
855 % The format of the SetQuantumPack method is:
856 %
857 % void SetQuantumPack(QuantumInfo *quantum_info,
858 % const MagickBooleanType pack)
859 %
860 % A description of each parameter follows:
861 %
862 % o quantum_info: the quantum info.
863 %
864 % o pack: the pack flag.
865 %
866 */
868  const MagickBooleanType pack)
869 {
870  assert(quantum_info != (QuantumInfo *) NULL);
871  assert(quantum_info->signature == MagickCoreSignature);
872  quantum_info->pack=pack;
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,
891 % QuantumInfo *quantum_info,const size_t pad)
892 %
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 */
903  QuantumInfo *quantum_info,const size_t pad)
904 {
905  assert(image != (Image *) NULL);
906  assert(image->signature == MagickCoreSignature);
907  if (image->debug != MagickFalse)
908  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
909  assert(quantum_info != (QuantumInfo *) NULL);
910  assert(quantum_info->signature == MagickCoreSignature);
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 */
941  const MagickBooleanType min_is_white)
942 {
943  assert(quantum_info != (QuantumInfo *) NULL);
944  assert(quantum_info->signature == MagickCoreSignature);
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,
964 % const size_t quantum)
965 %
966 % A description of each parameter follows:
967 %
968 % o quantum_info: the quantum info.
969 %
970 % o quantum: the quantum quantum.
971 %
972 */
974  const size_t quantum)
975 {
976  assert(quantum_info != (QuantumInfo *) NULL);
977  assert(quantum_info->signature == MagickCoreSignature);
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 */
1005 MagickExport void SetQuantumScale(QuantumInfo *quantum_info,const double scale)
1006 {
1007  assert(quantum_info != (QuantumInfo *) NULL);
1008  assert(quantum_info->signature == MagickCoreSignature);
1009  quantum_info->scale=scale;
1010 }
size_t rows
Definition: image.h:172
static MagickBooleanType AcquireQuantumPixels(QuantumInfo *quantum_info, const size_t extent)
Definition: quantum.c:156
QuantumFormatType
Definition: quantum.h:42
MagickExport EndianType GetQuantumEndian(const QuantumInfo *quantum_info)
Definition: quantum.c:354
EndianType endian
Definition: image.h:395
QuantumFormatType format
MagickExport MagickBooleanType SetQuantumFormat(const Image *image, QuantumInfo *quantum_info, const QuantumFormatType format)
Definition: quantum.c:762
QuantumAlphaType alpha_type
ImageType type
Definition: image.h:264
#define QuantumSignature
Definition: quantum.c:78
MagickExport ssize_t ParseCommandOption(const CommandOption option, const MagickBooleanType list, const char *options)
Definition: option.c:2953
unsigned char ** pixels
EndianType endian
Definition: image.h:228
MagickExport SemaphoreInfo * AcquireSemaphoreInfo(void)
Definition: semaphore.c:192
static double StringToDouble(const char *magick_restrict string, char **magick_restrict sentinal)
static MagickBooleanType IsGrayColorspace(const ColorspaceType colorspace)
QuantumState state
MagickExport MagickBooleanType SetQuantumEndian(const Image *image, QuantumInfo *quantum_info, const EndianType endian)
Definition: quantum.c:722
MagickExport const char * GetImageOption(const ImageInfo *image_info, const char *option)
Definition: option.c:2288
#define MagickEpsilon
Definition: magick-type.h:110
ClassType storage_class
Definition: image.h:154
Definition: log.h:52
EndianType
Definition: quantum.h:28
Definition: image.h:151
EndianType endian
#define MagickCoreSignature
MagickBooleanType pack
MagickBooleanType
Definition: magick-type.h:156
MagickExport void * ResetMagickMemory(void *memory, int byte, const size_t size)
Definition: memory.c:1164
MagickExport MagickBooleanType SetQuantumDepth(const Image *image, QuantumInfo *quantum_info, const size_t depth)
Definition: quantum.c:658
MagickExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
Definition: memory.c:529
MagickExport MagickBooleanType SetQuantumPad(const Image *image, QuantumInfo *quantum_info, const size_t pad)
Definition: quantum.c:902
MagickExport void SetQuantumAlphaType(QuantumInfo *quantum_info, const QuantumAlphaType type)
Definition: quantum.c:623
static int GetOpenMPThreadId(void)
unsigned int pixel
MagickExport MagickBooleanType static void * AcquireCriticalMemory(const size_t size)
PixelTrait alpha_trait
Definition: image.h:280
MagickExport MagickBooleanType LogMagickEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
Definition: log.c:1397
SemaphoreInfo * semaphore
size_t signature
Definition: image.h:354
size_t columns
Definition: image.h:172
MagickExport MagickSizeType GetMagickResourceLimit(const ResourceType type)
Definition: resource.c:758
MagickExport void SetQuantumScale(QuantumInfo *quantum_info, const double scale)
Definition: quantum.c:1005
MagickExport unsigned char * GetQuantumPixels(const QuantumInfo *quantum_info)
Definition: quantum.c:485
MagickExport void SetQuantumMinIsWhite(QuantumInfo *quantum_info, const MagickBooleanType min_is_white)
Definition: quantum.c:940
static void DestroyQuantumPixels(QuantumInfo *)
Definition: quantum.c:248
MagickExport void SetQuantumImageType(Image *image, const QuantumType quantum_type)
Definition: quantum.c:801
#define MagickMax(x, y)
Definition: image-private.h:26
MagickExport int LocaleCompare(const char *p, const char *q)
Definition: locale.c:1409
char filename[MagickPathExtent]
Definition: image.h:319
#define GetMagickModule()
Definition: log.h:28
size_t number_threads
const unsigned int * mask
MagickExport QuantumFormatType GetQuantumFormat(const QuantumInfo *quantum_info)
Definition: quantum.c:383
MagickPrivate void ResetQuantumState(QuantumInfo *quantum_info)
Definition: quantum.c:575
MagickExport void SetQuantumQuantum(QuantumInfo *quantum_info, const size_t quantum)
Definition: quantum.c:973
double inverse_scale
QuantumType
Definition: quantum.h:50
MagickExport void * RelinquishMagickMemory(void *memory)
Definition: memory.c:1038
#define MagickPrivate
#define MagickExport
MagickBooleanType min_is_white
MagickExport void RelinquishSemaphoreInfo(SemaphoreInfo **semaphore_info)
Definition: semaphore.c:351
MagickExport void GetQuantumInfo(const ImageInfo *image_info, QuantumInfo *quantum_info)
Definition: quantum.c:414
MagickExport QuantumInfo * AcquireQuantumInfo(const ImageInfo *image_info, Image *image)
Definition: quantum.c:110
QuantumAlphaType
Definition: quantum.h:35
MagickExport void SetQuantumPack(QuantumInfo *quantum_info, const MagickBooleanType pack)
Definition: quantum.c:867
ColorspaceType colorspace
Definition: image.h:157
#define QuantumRange
Definition: magick-type.h:83
MagickExport QuantumInfo * DestroyQuantumInfo(QuantumInfo *quantum_info)
Definition: quantum.c:213
MagickBooleanType debug
Definition: image.h:334
MagickExport size_t GetQuantumExtent(const Image *image, const QuantumInfo *quantum_info, const QuantumType quantum_type)
Definition: quantum.c:302
MagickExport QuantumType GetQuantumType(Image *image, ExceptionInfo *exception)
Definition: quantum.c:519
size_t depth
Definition: image.h:172