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  DestroyQuantumPixels(quantum_info);
179  return(MagickFalse);
180  }
181  (void) ResetMagickMemory(quantum_info->pixels[i],0,(extent+1)*
182  sizeof(**quantum_info->pixels));
183  quantum_info->pixels[i][extent]=QuantumSignature;
184  }
185  return(MagickTrue);
186 }
187 
188 /*
189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 % %
191 % %
192 % %
193 % D e s t r o y Q u a n t u m I n f o %
194 % %
195 % %
196 % %
197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
198 %
199 % DestroyQuantumInfo() deallocates memory associated with the QuantumInfo
200 % structure.
201 %
202 % The format of the DestroyQuantumInfo method is:
203 %
204 % QuantumInfo *DestroyQuantumInfo(QuantumInfo *quantum_info)
205 %
206 % A description of each parameter follows:
207 %
208 % o quantum_info: the quantum info.
209 %
210 */
212 {
213  assert(quantum_info != (QuantumInfo *) NULL);
214  assert(quantum_info->signature == MagickCoreSignature);
215  if (quantum_info->pixels != (unsigned char **) NULL)
216  DestroyQuantumPixels(quantum_info);
217  if (quantum_info->semaphore != (SemaphoreInfo *) NULL)
218  RelinquishSemaphoreInfo(&quantum_info->semaphore);
219  quantum_info->signature=(~MagickCoreSignature);
220  quantum_info=(QuantumInfo *) RelinquishMagickMemory(quantum_info);
221  return(quantum_info);
222 }
223 
224 /*
225 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226 % %
227 % %
228 % %
229 + D e s t r o y Q u a n t u m P i x e l s %
230 % %
231 % %
232 % %
233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234 %
235 % DestroyQuantumPixels() destroys the quantum pixels.
236 %
237 % The format of the DestroyQuantumPixels() method is:
238 %
239 % void DestroyQuantumPixels(QuantumInfo *quantum_info)
240 %
241 % A description of each parameter follows:
242 %
243 % o quantum_info: the quantum info.
244 %
245 */
246 static void DestroyQuantumPixels(QuantumInfo *quantum_info)
247 {
248  register ssize_t
249  i;
250 
251  ssize_t
252  extent;
253 
254  assert(quantum_info != (QuantumInfo *) NULL);
255  assert(quantum_info->signature == MagickCoreSignature);
256  assert(quantum_info->pixels != (unsigned char **) NULL);
257  extent=(ssize_t) quantum_info->extent;
258  for (i=0; i < (ssize_t) quantum_info->number_threads; i++)
259  if (quantum_info->pixels[i] != (unsigned char *) NULL)
260  {
261  /*
262  Did we overrun our quantum buffer?
263  */
264  assert(quantum_info->pixels[i][extent] == QuantumSignature);
265  quantum_info->pixels[i]=(unsigned char *) RelinquishMagickMemory(
266  quantum_info->pixels[i]);
267  }
268  quantum_info->pixels=(unsigned char **) RelinquishMagickMemory(
269  quantum_info->pixels);
270 }
271 
272 /*
273 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
274 % %
275 % %
276 % %
277 % G e t Q u a n t u m E x t e n t %
278 % %
279 % %
280 % %
281 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
282 %
283 % GetQuantumExtent() returns the quantum pixel buffer extent.
284 %
285 % The format of the GetQuantumExtent method is:
286 %
287 % size_t GetQuantumExtent(Image *image,const QuantumInfo *quantum_info,
288 % const QuantumType quantum_type)
289 %
290 % A description of each parameter follows:
291 %
292 % o image: the image.
293 %
294 % o quantum_info: the quantum info.
295 %
296 % o quantum_type: Declare which pixel components to transfer (red, green,
297 % blue, opacity, RGB, or RGBA).
298 %
299 */
300 MagickExport size_t GetQuantumExtent(const Image *image,
301  const QuantumInfo *quantum_info,const QuantumType quantum_type)
302 {
303  size_t
304  packet_size;
305 
306  assert(quantum_info != (QuantumInfo *) NULL);
307  assert(quantum_info->signature == MagickCoreSignature);
308  packet_size=1;
309  switch (quantum_type)
310  {
311  case GrayAlphaQuantum: packet_size=2; break;
312  case IndexAlphaQuantum: packet_size=2; break;
313  case RGBQuantum: packet_size=3; break;
314  case BGRQuantum: packet_size=3; break;
315  case RGBAQuantum: packet_size=4; break;
316  case RGBOQuantum: packet_size=4; break;
317  case BGRAQuantum: packet_size=4; break;
318  case CMYKQuantum: packet_size=4; break;
319  case CMYKAQuantum: packet_size=5; break;
320  case CbYCrAQuantum: packet_size=4; break;
321  case CbYCrQuantum: packet_size=3; break;
322  case CbYCrYQuantum: packet_size=4; break;
323  default: break;
324  }
325  if (quantum_info->pack == MagickFalse)
326  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));
328 }
329 
330 /*
331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
332 % %
333 % %
334 % %
335 % G e t Q u a n t u m E n d i a n %
336 % %
337 % %
338 % %
339 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
340 %
341 % GetQuantumEndian() returns the quantum endian of the image.
342 %
343 % The endian of the GetQuantumEndian method is:
344 %
345 % EndianType GetQuantumEndian(const QuantumInfo *quantum_info)
346 %
347 % A description of each parameter follows:
348 %
349 % o quantum_info: the quantum info.
350 %
351 */
353 {
354  assert(quantum_info != (QuantumInfo *) NULL);
355  assert(quantum_info->signature == MagickCoreSignature);
356  return(quantum_info->endian);
357 }
358 
359 /*
360 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
361 % %
362 % %
363 % %
364 % G e t Q u a n t u m F o r m a t %
365 % %
366 % %
367 % %
368 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
369 %
370 % GetQuantumFormat() returns the quantum format of the image.
371 %
372 % The format of the GetQuantumFormat method is:
373 %
374 % QuantumFormatType GetQuantumFormat(const QuantumInfo *quantum_info)
375 %
376 % A description of each parameter follows:
377 %
378 % o quantum_info: the quantum info.
379 %
380 */
382 {
383  assert(quantum_info != (QuantumInfo *) NULL);
384  assert(quantum_info->signature == MagickCoreSignature);
385  return(quantum_info->format);
386 }
387 
388 /*
389 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
390 % %
391 % %
392 % %
393 % G e t Q u a n t u m I n f o %
394 % %
395 % %
396 % %
397 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
398 %
399 % GetQuantumInfo() initializes the QuantumInfo structure to default values.
400 %
401 % The format of the GetQuantumInfo method is:
402 %
403 % GetQuantumInfo(const ImageInfo *image_info,QuantumInfo *quantum_info)
404 %
405 % A description of each parameter follows:
406 %
407 % o image_info: the image info.
408 %
409 % o quantum_info: the quantum info.
410 %
411 */
412 MagickExport void GetQuantumInfo(const ImageInfo *image_info,
413  QuantumInfo *quantum_info)
414 {
415  const char
416  *option;
417 
418  assert(quantum_info != (QuantumInfo *) NULL);
419  (void) ResetMagickMemory(quantum_info,0,sizeof(*quantum_info));
420  quantum_info->quantum=8;
421  quantum_info->maximum=1.0;
422  quantum_info->scale=QuantumRange;
423  quantum_info->pack=MagickTrue;
424  quantum_info->semaphore=AcquireSemaphoreInfo();
425  quantum_info->signature=MagickCoreSignature;
426  if (image_info == (const ImageInfo *) NULL)
427  return;
428  option=GetImageOption(image_info,"quantum:format");
429  if (option != (char *) NULL)
432  option=GetImageOption(image_info,"quantum:minimum");
433  if (option != (char *) NULL)
434  quantum_info->minimum=StringToDouble(option,(char **) NULL);
435  option=GetImageOption(image_info,"quantum:maximum");
436  if (option != (char *) NULL)
437  quantum_info->maximum=StringToDouble(option,(char **) NULL);
438  if ((quantum_info->minimum == 0.0) && (quantum_info->maximum == 0.0))
439  quantum_info->scale=0.0;
440  else
441  if (quantum_info->minimum == quantum_info->maximum)
442  {
443  quantum_info->scale=(double) QuantumRange/quantum_info->minimum;
444  quantum_info->minimum=0.0;
445  }
446  else
447  quantum_info->scale=(double) QuantumRange/(quantum_info->maximum-
448  quantum_info->minimum);
449  option=GetImageOption(image_info,"quantum:scale");
450  if (option != (char *) NULL)
451  quantum_info->scale=StringToDouble(option,(char **) NULL);
452  option=GetImageOption(image_info,"quantum:polarity");
453  if (option != (char *) NULL)
454  quantum_info->min_is_white=LocaleCompare(option,"min-is-white") == 0 ?
456  quantum_info->endian=image_info->endian;
457  ResetQuantumState(quantum_info);
458 }
459 
460 /*
461 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
462 % %
463 % %
464 % %
465 % G e t Q u a n t u m P i x e l s %
466 % %
467 % %
468 % %
469 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
470 %
471 % GetQuantumPixels() returns the quantum pixels.
472 %
473 % The format of the GetQuantumPixels method is:
474 %
475 % unsigned char *QuantumPixels GetQuantumPixels(
476 % const QuantumInfo *quantum_info)
477 %
478 % A description of each parameter follows:
479 %
480 % o image: the image.
481 %
482 */
483 MagickExport unsigned char *GetQuantumPixels(const QuantumInfo *quantum_info)
484 {
485  const int
486  id = GetOpenMPThreadId();
487 
488  assert(quantum_info != (QuantumInfo *) NULL);
489  assert(quantum_info->signature == MagickCoreSignature);
490  return(quantum_info->pixels[id]);
491 }
492 
493 /*
494 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
495 % %
496 % %
497 % %
498 % G e t Q u a n t u m T y p e %
499 % %
500 % %
501 % %
502 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
503 %
504 % GetQuantumType() returns the quantum type of the image.
505 %
506 % The format of the GetQuantumType method is:
507 %
508 % QuantumType GetQuantumType(Image *image,ExceptionInfo *exception)
509 %
510 % A description of each parameter follows:
511 %
512 % o image: the image.
513 %
514 % o exception: return any errors or warnings in this structure.
515 %
516 */
518 {
520  quantum_type;
521 
522  assert(image != (Image *) NULL);
523  assert(image->signature == MagickCoreSignature);
524  if (image->debug != MagickFalse)
525  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
526  (void) exception;
527  quantum_type=RGBQuantum;
528  if (image->alpha_trait != UndefinedPixelTrait)
529  quantum_type=RGBAQuantum;
530  if (image->colorspace == CMYKColorspace)
531  {
532  quantum_type=CMYKQuantum;
533  if (image->alpha_trait != UndefinedPixelTrait)
534  quantum_type=CMYKAQuantum;
535  }
536  if (IsGrayColorspace(image->colorspace) != MagickFalse)
537  {
538  quantum_type=GrayQuantum;
539  if (image->alpha_trait != UndefinedPixelTrait)
540  quantum_type=GrayAlphaQuantum;
541  }
542  if (image->storage_class == PseudoClass)
543  {
544  quantum_type=IndexQuantum;
545  if (image->alpha_trait != UndefinedPixelTrait)
546  quantum_type=IndexAlphaQuantum;
547  }
548  return(quantum_type);
549 }
550 
551 /*
552 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
553 % %
554 % %
555 % %
556 + R e s e t Q u a n t u m S t a t e %
557 % %
558 % %
559 % %
560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
561 %
562 % ResetQuantumState() resets the quantum state.
563 %
564 % The format of the ResetQuantumState method is:
565 %
566 % void ResetQuantumState(QuantumInfo *quantum_info)
567 %
568 % A description of each parameter follows:
569 %
570 % o quantum_info: the quantum info.
571 %
572 */
574 {
575  static const unsigned int mask[32] =
576  {
577  0x00000000U, 0x00000001U, 0x00000003U, 0x00000007U, 0x0000000fU,
578  0x0000001fU, 0x0000003fU, 0x0000007fU, 0x000000ffU, 0x000001ffU,
579  0x000003ffU, 0x000007ffU, 0x00000fffU, 0x00001fffU, 0x00003fffU,
580  0x00007fffU, 0x0000ffffU, 0x0001ffffU, 0x0003ffffU, 0x0007ffffU,
581  0x000fffffU, 0x001fffffU, 0x003fffffU, 0x007fffffU, 0x00ffffffU,
582  0x01ffffffU, 0x03ffffffU, 0x07ffffffU, 0x0fffffffU, 0x1fffffffU,
583  0x3fffffffU, 0x7fffffffU
584  };
585 
586  assert(quantum_info != (QuantumInfo *) NULL);
587  assert(quantum_info->signature == MagickCoreSignature);
588  quantum_info->state.inverse_scale=1.0;
589  if (fabs(quantum_info->scale) >= MagickEpsilon)
590  quantum_info->state.inverse_scale/=quantum_info->scale;
591  quantum_info->state.pixel=0U;
592  quantum_info->state.bits=0U;
593  quantum_info->state.mask=mask;
594 }
595 
596 /*
597 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
598 % %
599 % %
600 % %
601 % S e t Q u a n t u m F o r m a t %
602 % %
603 % %
604 % %
605 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
606 %
607 % SetQuantumAlphaType() sets the quantum format.
608 %
609 % The format of the SetQuantumAlphaType method is:
610 %
611 % void SetQuantumAlphaType(QuantumInfo *quantum_info,
612 % const QuantumAlphaType type)
613 %
614 % A description of each parameter follows:
615 %
616 % o quantum_info: the quantum info.
617 %
618 % o type: the alpha type (e.g. associate).
619 %
620 */
622  const QuantumAlphaType type)
623 {
624  assert(quantum_info != (QuantumInfo *) NULL);
625  assert(quantum_info->signature == MagickCoreSignature);
626  quantum_info->alpha_type=type;
627 }
628 
629 /*
630 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
631 % %
632 % %
633 % %
634 % S e t Q u a n t u m D e p t h %
635 % %
636 % %
637 % %
638 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
639 %
640 % SetQuantumDepth() sets the quantum depth.
641 %
642 % The format of the SetQuantumDepth method is:
643 %
644 % MagickBooleanType SetQuantumDepth(const Image *image,
645 % QuantumInfo *quantum_info,const size_t depth)
646 %
647 % A description of each parameter follows:
648 %
649 % o image: the image.
650 %
651 % o quantum_info: the quantum info.
652 %
653 % o depth: the quantum depth.
654 %
655 */
657  QuantumInfo *quantum_info,const size_t depth)
658 {
659  size_t
660  extent,
661  quantum;
662 
663  /*
664  Allocate the quantum pixel buffer.
665  */
666  assert(image != (Image *) NULL);
667  assert(image->signature == MagickCoreSignature);
668  if (image->debug != MagickFalse)
669  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
670  assert(quantum_info != (QuantumInfo *) NULL);
671  assert(quantum_info->signature == MagickCoreSignature);
672  quantum_info->depth=depth;
673  if (quantum_info->format == FloatingPointQuantumFormat)
674  {
675  if (quantum_info->depth > 32)
676  quantum_info->depth=64;
677  else
678  if (quantum_info->depth > 16)
679  quantum_info->depth=32;
680  else
681  quantum_info->depth=16;
682  }
683  if (quantum_info->pixels != (unsigned char **) NULL)
684  DestroyQuantumPixels(quantum_info);
685  quantum=(quantum_info->pad+MaxPixelChannels)*(quantum_info->depth+7)/8;
686  extent=MagickMax(image->columns,image->rows)*quantum;
687  if ((MagickMax(image->columns,image->rows) != 0) &&
688  (quantum != (extent/MagickMax(image->columns,image->rows))))
689  return(MagickFalse);
690  return(AcquireQuantumPixels(quantum_info,extent));
691 }
692 
693 /*
694 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
695 % %
696 % %
697 % %
698 % S e t Q u a n t u m E n d i a n %
699 % %
700 % %
701 % %
702 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
703 %
704 % SetQuantumEndian() sets the quantum endian.
705 %
706 % The endian of the SetQuantumEndian method is:
707 %
708 % MagickBooleanType SetQuantumEndian(const Image *image,
709 % QuantumInfo *quantum_info,const EndianType endian)
710 %
711 % A description of each parameter follows:
712 %
713 % o image: the image.
714 %
715 % o quantum_info: the quantum info.
716 %
717 % o endian: the quantum endian.
718 %
719 */
721  QuantumInfo *quantum_info,const EndianType endian)
722 {
723  assert(image != (Image *) NULL);
724  assert(image->signature == MagickCoreSignature);
725  if (image->debug != MagickFalse)
726  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
727  assert(quantum_info != (QuantumInfo *) NULL);
728  assert(quantum_info->signature == MagickCoreSignature);
729  quantum_info->endian=endian;
730  return(SetQuantumDepth(image,quantum_info,quantum_info->depth));
731 }
732 
733 /*
734 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
735 % %
736 % %
737 % %
738 % S e t Q u a n t u m F o r m a t %
739 % %
740 % %
741 % %
742 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
743 %
744 % SetQuantumFormat() sets the quantum format.
745 %
746 % The format of the SetQuantumFormat method is:
747 %
748 % MagickBooleanType SetQuantumFormat(const Image *image,
749 % QuantumInfo *quantum_info,const QuantumFormatType format)
750 %
751 % A description of each parameter follows:
752 %
753 % o image: the image.
754 %
755 % o quantum_info: the quantum info.
756 %
757 % o format: the quantum format.
758 %
759 */
761  QuantumInfo *quantum_info,const QuantumFormatType format)
762 {
763  assert(image != (Image *) NULL);
764  assert(image->signature == MagickCoreSignature);
765  if (image->debug != MagickFalse)
766  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
767  assert(quantum_info != (QuantumInfo *) NULL);
768  assert(quantum_info->signature == MagickCoreSignature);
769  quantum_info->format=format;
770  return(SetQuantumDepth(image,quantum_info,quantum_info->depth));
771 }
772 
773 /*
774 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
775 % %
776 % %
777 % %
778 % S e t Q u a n t u m I m a g e T y p e %
779 % %
780 % %
781 % %
782 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
783 %
784 % SetQuantumImageType() sets the image type based on the quantum type.
785 %
786 % The format of the SetQuantumImageType method is:
787 %
788 % void ImageType SetQuantumImageType(Image *image,
789 % const QuantumType quantum_type)
790 %
791 % A description of each parameter follows:
792 %
793 % o image: the image.
794 %
795 % o quantum_type: Declare which pixel components to transfer (red, green,
796 % blue, opacity, RGB, or RGBA).
797 %
798 */
800  const QuantumType quantum_type)
801 {
802  assert(image != (Image *) NULL);
803  assert(image->signature == MagickCoreSignature);
804  if (image->debug != MagickFalse)
805  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
806  switch (quantum_type)
807  {
808  case IndexQuantum:
809  case IndexAlphaQuantum:
810  {
811  image->type=PaletteType;
812  break;
813  }
814  case GrayQuantum:
815  case GrayAlphaQuantum:
816  {
817  image->type=GrayscaleType;
818  if (image->depth == 1)
819  image->type=BilevelType;
820  break;
821  }
822  case CyanQuantum:
823  case MagentaQuantum:
824  case YellowQuantum:
825  case BlackQuantum:
826  case CMYKQuantum:
827  case CMYKAQuantum:
828  {
829  image->type=ColorSeparationType;
830  break;
831  }
832  default:
833  {
834  image->type=TrueColorType;
835  break;
836  }
837  }
838 }
839 
840 /*
841 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
842 % %
843 % %
844 % %
845 % S e t Q u a n t u m P a c k %
846 % %
847 % %
848 % %
849 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
850 %
851 % SetQuantumPack() sets the quantum pack flag.
852 %
853 % The format of the SetQuantumPack method is:
854 %
855 % void SetQuantumPack(QuantumInfo *quantum_info,
856 % const MagickBooleanType pack)
857 %
858 % A description of each parameter follows:
859 %
860 % o quantum_info: the quantum info.
861 %
862 % o pack: the pack flag.
863 %
864 */
866  const MagickBooleanType pack)
867 {
868  assert(quantum_info != (QuantumInfo *) NULL);
869  assert(quantum_info->signature == MagickCoreSignature);
870  quantum_info->pack=pack;
871 }
872 
873 /*
874 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
875 % %
876 % %
877 % %
878 % S e t Q u a n t u m P a d %
879 % %
880 % %
881 % %
882 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
883 %
884 % SetQuantumPad() sets the quantum pad.
885 %
886 % The format of the SetQuantumPad method is:
887 %
888 % MagickBooleanType SetQuantumPad(const Image *image,
889 % QuantumInfo *quantum_info,const size_t pad)
890 %
891 % A description of each parameter follows:
892 %
893 % o image: the image.
894 %
895 % o quantum_info: the quantum info.
896 %
897 % o pad: the quantum pad.
898 %
899 */
901  QuantumInfo *quantum_info,const size_t pad)
902 {
903  assert(image != (Image *) NULL);
904  assert(image->signature == MagickCoreSignature);
905  if (image->debug != MagickFalse)
906  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
907  assert(quantum_info != (QuantumInfo *) NULL);
908  assert(quantum_info->signature == MagickCoreSignature);
909  quantum_info->pad=pad;
910  return(SetQuantumDepth(image,quantum_info,quantum_info->depth));
911 }
912 
913 /*
914 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
915 % %
916 % %
917 % %
918 % S e t Q u a n t u m M i n I s W h i t e %
919 % %
920 % %
921 % %
922 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
923 %
924 % SetQuantumMinIsWhite() sets the quantum min-is-white flag.
925 %
926 % The format of the SetQuantumMinIsWhite method is:
927 %
928 % void SetQuantumMinIsWhite(QuantumInfo *quantum_info,
929 % const MagickBooleanType min_is_white)
930 %
931 % A description of each parameter follows:
932 %
933 % o quantum_info: the quantum info.
934 %
935 % o min_is_white: the min-is-white flag.
936 %
937 */
939  const MagickBooleanType min_is_white)
940 {
941  assert(quantum_info != (QuantumInfo *) NULL);
942  assert(quantum_info->signature == MagickCoreSignature);
943  quantum_info->min_is_white=min_is_white;
944 }
945 
946 /*
947 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
948 % %
949 % %
950 % %
951 % S e t Q u a n t u m Q u a n t u m %
952 % %
953 % %
954 % %
955 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
956 %
957 % SetQuantumQuantum() sets the quantum quantum.
958 %
959 % The format of the SetQuantumQuantum method is:
960 %
961 % void SetQuantumQuantum(QuantumInfo *quantum_info,
962 % const size_t quantum)
963 %
964 % A description of each parameter follows:
965 %
966 % o quantum_info: the quantum info.
967 %
968 % o quantum: the quantum quantum.
969 %
970 */
972  const size_t quantum)
973 {
974  assert(quantum_info != (QuantumInfo *) NULL);
975  assert(quantum_info->signature == MagickCoreSignature);
976  quantum_info->quantum=quantum;
977 }
978 
979 /*
980 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
981 % %
982 % %
983 % %
984 % S e t Q u a n t u m S c a l e %
985 % %
986 % %
987 % %
988 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
989 %
990 % SetQuantumScale() sets the quantum scale.
991 %
992 % The format of the SetQuantumScale method is:
993 %
994 % void SetQuantumScale(QuantumInfo *quantum_info,const double scale)
995 %
996 % A description of each parameter follows:
997 %
998 % o quantum_info: the quantum info.
999 %
1000 % o scale: the quantum scale.
1001 %
1002 */
1003 MagickExport void SetQuantumScale(QuantumInfo *quantum_info,const double scale)
1004 {
1005  assert(quantum_info != (QuantumInfo *) NULL);
1006  assert(quantum_info->signature == MagickCoreSignature);
1007  quantum_info->scale=scale;
1008 }
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:352
EndianType endian
Definition: image.h:395
QuantumFormatType format
MagickExport MagickBooleanType SetQuantumFormat(const Image *image, QuantumInfo *quantum_info, const QuantumFormatType format)
Definition: quantum.c:760
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:2954
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:720
MagickExport const char * GetImageOption(const ImageInfo *image_info, const char *option)
Definition: option.c:2289
#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:656
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:900
MagickExport void SetQuantumAlphaType(QuantumInfo *quantum_info, const QuantumAlphaType type)
Definition: quantum.c:621
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:1003
MagickExport unsigned char * GetQuantumPixels(const QuantumInfo *quantum_info)
Definition: quantum.c:483
MagickExport void SetQuantumMinIsWhite(QuantumInfo *quantum_info, const MagickBooleanType min_is_white)
Definition: quantum.c:938
static void DestroyQuantumPixels(QuantumInfo *)
Definition: quantum.c:246
MagickExport void SetQuantumImageType(Image *image, const QuantumType quantum_type)
Definition: quantum.c:799
#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:381
MagickPrivate void ResetQuantumState(QuantumInfo *quantum_info)
Definition: quantum.c:573
MagickExport void SetQuantumQuantum(QuantumInfo *quantum_info, const size_t quantum)
Definition: quantum.c:971
double inverse_scale
QuantumType
Definition: quantum.h:50
MagickExport void * RelinquishMagickMemory(void *memory)
Definition: memory.c:1038
#define MaxPixelChannels
Definition: pixel.h:27
#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:412
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:865
ColorspaceType colorspace
Definition: image.h:157
#define QuantumRange
Definition: magick-type.h:83
MagickExport QuantumInfo * DestroyQuantumInfo(QuantumInfo *quantum_info)
Definition: quantum.c:211
MagickBooleanType debug
Definition: image.h:334
MagickExport size_t GetQuantumExtent(const Image *image, const QuantumInfo *quantum_info, const QuantumType quantum_type)
Definition: quantum.c:300
MagickExport QuantumType GetQuantumType(Image *image, ExceptionInfo *exception)
Definition: quantum.c:517
size_t depth
Definition: image.h:172