2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % PPPP IIIII X X EEEEE L %
10 % P IIIII X X EEEEE LLLLL %
12 % MagickCore Methods to Import/Export Pixels %
19 % Copyright 1999-2019 ImageMagick Studio LLC, a non-profit organization %
20 % dedicated to making software imaging solutions freely available. %
22 % You may not use this file except in compliance with the License. You may %
23 % obtain a copy of the License at %
25 % https://imagemagick.org/script/license.php %
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. %
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 #include "MagickCore/studio.h"
42 #include "MagickCore/property.h"
43 #include "MagickCore/blob.h"
44 #include "MagickCore/blob-private.h"
45 #include "MagickCore/cache-private.h"
46 #include "MagickCore/color-private.h"
47 #include "MagickCore/colorspace-private.h"
48 #include "MagickCore/draw.h"
49 #include "MagickCore/exception.h"
50 #include "MagickCore/exception-private.h"
51 #include "MagickCore/cache.h"
52 #include "MagickCore/constitute.h"
53 #include "MagickCore/delegate.h"
54 #include "MagickCore/geometry.h"
55 #include "MagickCore/image-private.h"
56 #include "MagickCore/list.h"
57 #include "MagickCore/magick.h"
58 #include "MagickCore/memory_.h"
59 #include "MagickCore/memory-private.h"
60 #include "MagickCore/monitor.h"
61 #include "MagickCore/option.h"
62 #include "MagickCore/pixel.h"
63 #include "MagickCore/pixel-accessor.h"
64 #include "MagickCore/pixel-private.h"
65 #include "MagickCore/quantum.h"
66 #include "MagickCore/quantum-private.h"
67 #include "MagickCore/resource_.h"
68 #include "MagickCore/semaphore.h"
69 #include "MagickCore/statistic.h"
70 #include "MagickCore/stream.h"
71 #include "MagickCore/string_.h"
72 #include "MagickCore/transform.h"
73 #include "MagickCore/utility.h"
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 + A c q u i r e P i x e l C h a n n e l M a p %
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 % AcquirePixelChannelMap() acquires a pixel component map.
88 % The format of the AcquirePixelChannelMap() method is:
90 % PixelChannelMap *AcquirePixelChannelMap(void)
93 MagickExport PixelChannelMap *AcquirePixelChannelMap(void)
101 channel_map=(PixelChannelMap *) AcquireQuantumMemory(MaxPixelChannels,
102 sizeof(*channel_map));
103 if (channel_map == (PixelChannelMap *) NULL)
104 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
105 (void) memset(channel_map,0,MaxPixelChannels*sizeof(*channel_map));
106 for (i=0; i < MaxPixelChannels; i++)
107 channel_map[i].channel=(PixelChannel) i;
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116 + C l o n e P i x e l C h a n n e l M a p %
120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122 % ClonePixelChannelMap() clones a pixel component map.
124 % The format of the ClonePixelChannelMap() method is:
126 % PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
128 % A description of each parameter follows:
130 % o channel_map: the pixel component map.
133 MagickExport PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
138 assert(channel_map != (PixelChannelMap *) NULL);
139 clone_map=AcquirePixelChannelMap();
140 if (clone_map == (PixelChannelMap *) NULL)
141 return((PixelChannelMap *) NULL);
142 (void) memcpy(clone_map,channel_map,MaxPixelChannels*
143 sizeof(*channel_map));
148 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152 + C l o n e P i x e l I n f o %
156 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158 % ClonePixelInfo() makes a duplicate of the given pixel info structure, or if
159 % pixel info is NULL, a new one.
161 % The format of the ClonePixelInfo method is:
163 % PixelInfo *ClonePixelInfo(const PixelInfo *pixel)
165 % A description of each parameter follows:
167 % o pixel: the pixel info.
170 MagickExport PixelInfo *ClonePixelInfo(const PixelInfo *pixel)
175 pixel_info=(PixelInfo *) AcquireQuantumMemory(1,sizeof(*pixel_info));
176 if (pixel_info == (PixelInfo *) NULL)
177 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
178 *pixel_info=(*pixel);
183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
187 + C o n f o r m P i x e l I n f o %
191 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
193 % ConformPixelInfo() ensures the pixel conforms with the colorspace and alpha
194 % attribute of the image.
196 % The format of the ConformPixelInfo method is:
198 % void *ConformPixelInfo((Image *image,const PixelInfo *source,
199 % PixelInfo *destination,ExceptionInfo *exception)
201 % A description of each parameter follows:
203 % o image: the image.
205 % o source: the source pixel info.
207 % o destination: the destination pixel info.
209 % o exception: return any errors or warnings in this structure.
212 MagickExport void ConformPixelInfo(Image *image,const PixelInfo *source,
213 PixelInfo *destination,ExceptionInfo *exception)
215 assert(image != (Image *) NULL);
216 assert(image->signature == MagickCoreSignature);
217 assert(destination != (const PixelInfo *) NULL);
218 *destination=(*source);
219 if (image->colorspace == CMYKColorspace)
221 if (IssRGBCompatibleColorspace(destination->colorspace))
222 ConvertRGBToCMYK(destination);
225 if (destination->colorspace == CMYKColorspace)
227 if (IssRGBCompatibleColorspace(image->colorspace))
228 ConvertCMYKToRGB(destination);
230 if ((IsPixelInfoGray(&image->background_color) == MagickFalse) &&
231 (IsGrayColorspace(image->colorspace) != MagickFalse))
232 (void) TransformImageColorspace(image,sRGBColorspace,exception);
233 if ((destination->alpha_trait != UndefinedPixelTrait) &&
234 (image->alpha_trait == UndefinedPixelTrait))
235 (void) SetImageAlpha(image,OpaqueAlpha,exception);
239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243 % D e c o d e P i x e l G a m m a %
247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249 % DecodePixelGamma() applies the expansive power-law nonlinearity to the pixel.
251 % The format of the DecodePixelGamma method is:
253 % double DecodePixelGamma(const MagickRealType pixel)
255 % A description of each parameter follows:
257 % o pixel: the pixel.
261 static inline double DecodeGamma(const double x)
273 static const double coefficient[] = /* terms for x^(7/5), x=1.5 */
275 1.7917488588043277509,
276 0.82045614371976854984,
277 0.027694100686325412819,
278 -0.00094244335181762134018,
279 0.000064355540911469709545,
280 -5.7224404636060757485e-06,
281 5.8767669437311184313e-07,
282 -6.6139920053589721168e-08,
283 7.9323242696227458163e-09
286 static const double powers_of_two[] = /* (2^x)^(7/5) */
289 2.6390158215457883983,
290 6.9644045063689921093,
291 1.8379173679952558018e+01,
292 4.8502930128332728543e+01
296 Compute x^2.4 == x*x^(7/5) == pow(x,2.4).
299 term[1]=4.0*frexp(x,&exponent)-3.0;
300 term[2]=2.0*term[1]*term[1]-term[0];
301 term[3]=2.0*term[1]*term[2]-term[1];
302 term[4]=2.0*term[1]*term[3]-term[2];
303 term[5]=2.0*term[1]*term[4]-term[3];
304 term[6]=2.0*term[1]*term[5]-term[4];
305 term[7]=2.0*term[1]*term[6]-term[5];
306 term[8]=2.0*term[1]*term[7]-term[6];
307 p=coefficient[0]*term[0]+coefficient[1]*term[1]+coefficient[2]*term[2]+
308 coefficient[3]*term[3]+coefficient[4]*term[4]+coefficient[5]*term[5]+
309 coefficient[6]*term[6]+coefficient[7]*term[7]+coefficient[8]*term[8];
310 quotient=div(exponent-1,5);
311 if (quotient.rem < 0)
316 return(x*ldexp(powers_of_two[quotient.rem]*p,7*quotient.quot));
319 MagickExport MagickRealType DecodePixelGamma(const MagickRealType pixel)
321 if (pixel <= (0.0404482362771076*QuantumRange))
322 return(pixel/12.92f);
323 return((MagickRealType) (QuantumRange*DecodeGamma((double) (QuantumScale*
324 pixel+0.055)/1.055)));
328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
332 + D e s t r o y P i x e l C h a n n e l M a p %
336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
338 % DestroyPixelChannelMap() deallocates memory associated with the pixel
341 % The format of the DestroyPixelChannelMap() method is:
343 % PixelChannelMap *DestroyPixelChannelMap(PixelChannelMap *channel_map)
345 % A description of each parameter follows:
347 % o channel_map: the pixel component map.
350 MagickExport PixelChannelMap *DestroyPixelChannelMap(
351 PixelChannelMap *channel_map)
353 assert(channel_map != (PixelChannelMap *) NULL);
354 channel_map=(PixelChannelMap *) RelinquishMagickMemory(channel_map);
355 return((PixelChannelMap *) RelinquishMagickMemory(channel_map));
359 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
363 + E n c o d e P i x e l G a m m a %
367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
369 % EncodePixelGamma() cancels any nonlinearity in the pixel.
371 % The format of the EncodePixelGamma method is:
373 % MagickRealType EncodePixelGamma(const double MagickRealType)
375 % A description of each parameter follows:
377 % o pixel: the pixel.
381 static inline double EncodeGamma(const double x)
393 static const double coefficient[] = /* Chebychevi poly: x^(5/12), x=1.5 */
395 1.1758200232996901923,
396 0.16665763094889061230,
397 -0.0083154894939042125035,
398 0.00075187976780420279038,
399 -0.000083240178519391795367,
400 0.000010229209410070008679,
401 -1.3400466409860246e-06,
402 1.8333422241635376682e-07,
403 -2.5878596761348859722e-08
406 static const double powers_of_two[] = /* (2^N)^(5/12) */
409 1.3348398541700343678,
410 1.7817974362806785482,
411 2.3784142300054420538,
412 3.1748021039363991669,
413 4.2378523774371812394,
414 5.6568542494923805819,
415 7.5509945014535482244,
416 1.0079368399158985525e1,
417 1.3454342644059433809e1,
418 1.7959392772949968275e1,
419 2.3972913230026907883e1
423 Compute x^(1/2.4) == x^(5/12) == pow(x,1.0/2.4).
426 term[1]=4.0*frexp(x,&exponent)-3.0;
427 term[2]=2.0*term[1]*term[1]-term[0];
428 term[3]=2.0*term[1]*term[2]-term[1];
429 term[4]=2.0*term[1]*term[3]-term[2];
430 term[5]=2.0*term[1]*term[4]-term[3];
431 term[6]=2.0*term[1]*term[5]-term[4];
432 term[7]=2.0*term[1]*term[6]-term[5];
433 term[8]=2.0*term[1]*term[7]-term[6];
434 p=coefficient[0]*term[0]+coefficient[1]*term[1]+coefficient[2]*term[2]+
435 coefficient[3]*term[3]+coefficient[4]*term[4]+coefficient[5]*term[5]+
436 coefficient[6]*term[6]+coefficient[7]*term[7]+coefficient[8]*term[8];
437 quotient=div(exponent-1,12);
438 if (quotient.rem < 0)
443 return(ldexp(powers_of_two[quotient.rem]*p,5*quotient.quot));
446 MagickExport MagickRealType EncodePixelGamma(const MagickRealType pixel)
448 if (pixel <= (0.0031306684425005883*QuantumRange))
449 return(12.92f*pixel);
450 return((MagickRealType) QuantumRange*(1.055*EncodeGamma((double) QuantumScale*
455 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
459 % E x p o r t I m a g e P i x e l s %
463 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
465 % ExportImagePixels() extracts pixel data from an image and returns it to you.
466 % The method returns MagickTrue on success otherwise MagickFalse if an error is
467 % encountered. The data is returned as char, short int, Quantum, unsigned int,
468 % unsigned long long, float, or double in the order specified by map.
470 % Suppose you want to extract the first scanline of a 640x480 image as
471 % character data in red-green-blue order:
473 % ExportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels,exception);
475 % The format of the ExportImagePixels method is:
477 % MagickBooleanType ExportImagePixels(const Image *image,const ssize_t x,
478 % const ssize_t y,const size_t width,const size_t height,
479 % const char *map,const StorageType type,void *pixels,
480 % ExceptionInfo *exception)
482 % A description of each parameter follows:
484 % o image: the image.
486 % o x,y,width,height: These values define the perimeter
487 % of a region of pixels you want to extract.
489 % o map: This string reflects the expected ordering of the pixel array.
490 % It can be any combination or order of R = red, G = green, B = blue,
491 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
492 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
495 % o type: Define the data type of the pixels. Float and double types are
496 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
497 % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *),
498 % LongPixel (unsigned int *), LongLongPixel (unsigned long long *),
499 % QuantumPixel (Quantum *), or ShortPixel (unsigned short *).
501 % o pixels: This array of values contain the pixel components as defined by
502 % map and type. You must preallocate this array where the expected
503 % length varies depending on the values of width, height, map, and type.
505 % o exception: return any errors or warnings in this structure.
509 static MagickBooleanType ExportCharPixel(const Image *image,
510 const RectangleInfo *roi,const char *magick_restrict map,
511 const QuantumType *quantum_map,void *pixels,ExceptionInfo *exception)
513 register const Quantum
519 register unsigned char
528 q=(unsigned char *) pixels;
529 if (LocaleCompare(map,"BGR") == 0)
531 for (y=0; y < (ssize_t) roi->height; y++)
533 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
534 if (p == (const Quantum *) NULL)
536 for (x=0; x < (ssize_t) roi->width; x++)
538 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
539 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
540 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
541 p+=GetPixelChannels(image);
544 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
546 if (LocaleCompare(map,"BGRA") == 0)
548 for (y=0; y < (ssize_t) roi->height; y++)
550 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
551 if (p == (const Quantum *) NULL)
553 for (x=0; x < (ssize_t) roi->width; x++)
555 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
556 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
557 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
558 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
559 p+=GetPixelChannels(image);
562 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
564 if (LocaleCompare(map,"BGRP") == 0)
566 for (y=0; y < (ssize_t) roi->height; y++)
568 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
569 if (p == (const Quantum *) NULL)
571 for (x=0; x < (ssize_t) roi->width; x++)
573 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
574 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
575 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
576 *q++=ScaleQuantumToChar((Quantum) 0);
577 p+=GetPixelChannels(image);
580 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
582 if (LocaleCompare(map,"I") == 0)
584 for (y=0; y < (ssize_t) roi->height; y++)
586 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
587 if (p == (const Quantum *) NULL)
589 for (x=0; x < (ssize_t) roi->width; x++)
591 *q++=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
592 p+=GetPixelChannels(image);
595 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
597 if (LocaleCompare(map,"RGB") == 0)
599 for (y=0; y < (ssize_t) roi->height; y++)
601 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
602 if (p == (const Quantum *) NULL)
604 for (x=0; x < (ssize_t) roi->width; x++)
606 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
607 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
608 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
609 p+=GetPixelChannels(image);
612 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
614 if (LocaleCompare(map,"RGBA") == 0)
616 for (y=0; y < (ssize_t) roi->height; y++)
618 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
619 if (p == (const Quantum *) NULL)
621 for (x=0; x < (ssize_t) roi->width; x++)
623 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
624 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
625 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
626 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
627 p+=GetPixelChannels(image);
630 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
632 if (LocaleCompare(map,"RGBP") == 0)
634 for (y=0; y < (ssize_t) roi->height; y++)
636 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
637 if (p == (const Quantum *) NULL)
639 for (x=0; x < (ssize_t) roi->width; x++)
641 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
642 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
643 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
644 *q++=ScaleQuantumToChar((Quantum) 0);
645 p+=GetPixelChannels(image);
648 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
651 for (y=0; y < (ssize_t) roi->height; y++)
653 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
654 if (p == (const Quantum *) NULL)
656 for (x=0; x < (ssize_t) roi->width; x++)
661 for (i=0; i < (ssize_t) length; i++)
664 switch (quantum_map[i])
669 *q=ScaleQuantumToChar(GetPixelRed(image,p));
675 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
681 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
686 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
691 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
696 if (image->colorspace == CMYKColorspace)
697 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
702 *q=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
710 p+=GetPixelChannels(image);
713 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
716 static MagickBooleanType ExportDoublePixel(const Image *image,
717 const RectangleInfo *roi,const char *magick_restrict map,
718 const QuantumType *quantum_map,void *pixels,ExceptionInfo *exception)
720 register const Quantum
736 if (LocaleCompare(map,"BGR") == 0)
738 for (y=0; y < (ssize_t) roi->height; y++)
740 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
741 if (p == (const Quantum *) NULL)
743 for (x=0; x < (ssize_t) roi->width; x++)
745 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
746 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
747 *q++=(double) (QuantumScale*GetPixelRed(image,p));
748 p+=GetPixelChannels(image);
751 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
753 if (LocaleCompare(map,"BGRA") == 0)
755 for (y=0; y < (ssize_t) roi->height; y++)
757 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
758 if (p == (const Quantum *) NULL)
760 for (x=0; x < (ssize_t) roi->width; x++)
762 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
763 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
764 *q++=(double) (QuantumScale*GetPixelRed(image,p));
765 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
766 p+=GetPixelChannels(image);
769 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
771 if (LocaleCompare(map,"BGRP") == 0)
773 for (y=0; y < (ssize_t) roi->height; y++)
775 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
776 if (p == (const Quantum *) NULL)
778 for (x=0; x < (ssize_t) roi->width; x++)
780 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
781 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
782 *q++=(double) (QuantumScale*GetPixelRed(image,p));
784 p+=GetPixelChannels(image);
787 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
789 if (LocaleCompare(map,"I") == 0)
791 for (y=0; y < (ssize_t) roi->height; y++)
793 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
794 if (p == (const Quantum *) NULL)
796 for (x=0; x < (ssize_t) roi->width; x++)
798 *q++=(double) (QuantumScale*GetPixelIntensity(image,p));
799 p+=GetPixelChannels(image);
802 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
804 if (LocaleCompare(map,"RGB") == 0)
806 for (y=0; y < (ssize_t) roi->height; y++)
808 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
809 if (p == (const Quantum *) NULL)
811 for (x=0; x < (ssize_t) roi->width; x++)
813 *q++=(double) (QuantumScale*GetPixelRed(image,p));
814 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
815 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
816 p+=GetPixelChannels(image);
819 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
821 if (LocaleCompare(map,"RGBA") == 0)
823 for (y=0; y < (ssize_t) roi->height; y++)
825 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
826 if (p == (const Quantum *) NULL)
828 for (x=0; x < (ssize_t) roi->width; x++)
830 *q++=(double) (QuantumScale*GetPixelRed(image,p));
831 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
832 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
833 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
834 p+=GetPixelChannels(image);
837 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
839 if (LocaleCompare(map,"RGBP") == 0)
841 for (y=0; y < (ssize_t) roi->height; y++)
843 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
844 if (p == (const Quantum *) NULL)
846 for (x=0; x < (ssize_t) roi->width; x++)
848 *q++=(double) (QuantumScale*GetPixelRed(image,p));
849 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
850 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
852 p+=GetPixelChannels(image);
855 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
858 for (y=0; y < (ssize_t) roi->height; y++)
860 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
861 if (p == (const Quantum *) NULL)
863 for (x=0; x < (ssize_t) roi->width; x++)
868 for (i=0; i < (ssize_t) length; i++)
871 switch (quantum_map[i])
876 *q=(double) (QuantumScale*GetPixelRed(image,p));
882 *q=(double) (QuantumScale*GetPixelGreen(image,p));
888 *q=(double) (QuantumScale*GetPixelBlue(image,p));
893 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
898 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
903 if (image->colorspace == CMYKColorspace)
904 *q=(double) (QuantumScale*
905 GetPixelBlack(image,p));
910 *q=(double) (QuantumScale*GetPixelIntensity(image,p));
918 p+=GetPixelChannels(image);
921 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
924 static MagickBooleanType ExportFloatPixel(const Image *image,
925 const RectangleInfo *roi,const char *magick_restrict map,
926 const QuantumType *quantum_map,void *pixels,ExceptionInfo *exception)
928 register const Quantum
944 if (LocaleCompare(map,"BGR") == 0)
946 for (y=0; y < (ssize_t) roi->height; y++)
948 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
949 if (p == (const Quantum *) NULL)
951 for (x=0; x < (ssize_t) roi->width; x++)
953 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
954 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
955 *q++=(float) (QuantumScale*GetPixelRed(image,p));
956 p+=GetPixelChannels(image);
959 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
961 if (LocaleCompare(map,"BGRA") == 0)
963 for (y=0; y < (ssize_t) roi->height; y++)
965 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
966 if (p == (const Quantum *) NULL)
968 for (x=0; x < (ssize_t) roi->width; x++)
970 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
971 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
972 *q++=(float) (QuantumScale*GetPixelRed(image,p));
973 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
974 p+=GetPixelChannels(image);
977 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
979 if (LocaleCompare(map,"BGRP") == 0)
981 for (y=0; y < (ssize_t) roi->height; y++)
983 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
984 if (p == (const Quantum *) NULL)
986 for (x=0; x < (ssize_t) roi->width; x++)
988 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
989 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
990 *q++=(float) (QuantumScale*GetPixelRed(image,p));
992 p+=GetPixelChannels(image);
995 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
997 if (LocaleCompare(map,"I") == 0)
999 for (y=0; y < (ssize_t) roi->height; y++)
1001 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1002 if (p == (const Quantum *) NULL)
1004 for (x=0; x < (ssize_t) roi->width; x++)
1006 *q++=(float) (QuantumScale*GetPixelIntensity(image,p));
1007 p+=GetPixelChannels(image);
1010 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1012 if (LocaleCompare(map,"RGB") == 0)
1014 for (y=0; y < (ssize_t) roi->height; y++)
1016 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1017 if (p == (const Quantum *) NULL)
1019 for (x=0; x < (ssize_t) roi->width; x++)
1021 *q++=(float) (QuantumScale*GetPixelRed(image,p));
1022 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
1023 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
1024 p+=GetPixelChannels(image);
1027 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1029 if (LocaleCompare(map,"RGBA") == 0)
1031 for (y=0; y < (ssize_t) roi->height; y++)
1033 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1034 if (p == (const Quantum *) NULL)
1036 for (x=0; x < (ssize_t) roi->width; x++)
1038 *q++=(float) (QuantumScale*GetPixelRed(image,p));
1039 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
1040 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
1041 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
1042 p+=GetPixelChannels(image);
1045 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1047 if (LocaleCompare(map,"RGBP") == 0)
1049 for (y=0; y < (ssize_t) roi->height; y++)
1051 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1052 if (p == (const Quantum *) NULL)
1054 for (x=0; x < (ssize_t) roi->width; x++)
1056 *q++=(float) (QuantumScale*GetPixelRed(image,p));
1057 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
1058 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
1060 p+=GetPixelChannels(image);
1063 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1066 for (y=0; y < (ssize_t) roi->height; y++)
1068 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1069 if (p == (const Quantum *) NULL)
1071 for (x=0; x < (ssize_t) roi->width; x++)
1076 for (i=0; i < (ssize_t) length; i++)
1079 switch (quantum_map[i])
1084 *q=(float) (QuantumScale*GetPixelRed(image,p));
1088 case MagentaQuantum:
1090 *q=(float) (QuantumScale*GetPixelGreen(image,p));
1096 *q=(float) (QuantumScale*GetPixelBlue(image,p));
1101 *q=(float) (QuantumScale*((Quantum) (GetPixelAlpha(image,p))));
1104 case OpacityQuantum:
1106 *q=(float) (QuantumScale*GetPixelAlpha(image,p));
1111 if (image->colorspace == CMYKColorspace)
1112 *q=(float) (QuantumScale* GetPixelBlack(image,p));
1117 *q=(float) (QuantumScale*GetPixelIntensity(image,p));
1125 p+=GetPixelChannels(image);
1128 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1131 static MagickBooleanType ExportLongPixel(const Image *image,
1132 const RectangleInfo *roi,const char *magick_restrict map,
1133 const QuantumType *quantum_map,void *pixels,ExceptionInfo *exception)
1135 register const Quantum
1141 register unsigned int
1150 q=(unsigned int *) pixels;
1151 if (LocaleCompare(map,"BGR") == 0)
1153 for (y=0; y < (ssize_t) roi->height; y++)
1155 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1156 if (p == (const Quantum *) NULL)
1158 for (x=0; x < (ssize_t) roi->width; x++)
1160 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1161 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1162 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1163 p+=GetPixelChannels(image);
1166 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1168 if (LocaleCompare(map,"BGRA") == 0)
1170 for (y=0; y < (ssize_t) roi->height; y++)
1172 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1173 if (p == (const Quantum *) NULL)
1175 for (x=0; x < (ssize_t) roi->width; x++)
1177 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1178 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1179 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1180 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1181 p+=GetPixelChannels(image);
1184 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1186 if (LocaleCompare(map,"BGRP") == 0)
1188 for (y=0; y < (ssize_t) roi->height; y++)
1190 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1191 if (p == (const Quantum *) NULL)
1193 for (x=0; x < (ssize_t) roi->width; x++)
1195 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1196 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1197 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1199 p+=GetPixelChannels(image);
1202 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1204 if (LocaleCompare(map,"I") == 0)
1206 for (y=0; y < (ssize_t) roi->height; y++)
1208 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1209 if (p == (const Quantum *) NULL)
1211 for (x=0; x < (ssize_t) roi->width; x++)
1213 *q++=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
1214 p+=GetPixelChannels(image);
1217 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1219 if (LocaleCompare(map,"RGB") == 0)
1221 for (y=0; y < (ssize_t) roi->height; y++)
1223 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1224 if (p == (const Quantum *) NULL)
1226 for (x=0; x < (ssize_t) roi->width; x++)
1228 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1229 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1230 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1231 p+=GetPixelChannels(image);
1234 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1236 if (LocaleCompare(map,"RGBA") == 0)
1238 for (y=0; y < (ssize_t) roi->height; y++)
1240 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1241 if (p == (const Quantum *) NULL)
1243 for (x=0; x < (ssize_t) roi->width; x++)
1245 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1246 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1247 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1248 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1249 p+=GetPixelChannels(image);
1252 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1254 if (LocaleCompare(map,"RGBP") == 0)
1256 for (y=0; y < (ssize_t) roi->height; y++)
1258 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1259 if (p == (const Quantum *) NULL)
1261 for (x=0; x < (ssize_t) roi->width; x++)
1263 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1264 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1265 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1267 p+=GetPixelChannels(image);
1270 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1273 for (y=0; y < (ssize_t) roi->height; y++)
1275 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1276 if (p == (const Quantum *) NULL)
1278 for (x=0; x < (ssize_t) roi->width; x++)
1283 for (i=0; i < (ssize_t) length; i++)
1286 switch (quantum_map[i])
1291 *q=ScaleQuantumToLong(GetPixelRed(image,p));
1295 case MagentaQuantum:
1297 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
1303 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
1308 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1311 case OpacityQuantum:
1313 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1318 if (image->colorspace == CMYKColorspace)
1319 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
1324 *q=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
1332 p+=GetPixelChannels(image);
1335 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1338 static MagickBooleanType ExportLongLongPixel(const Image *image,
1339 const RectangleInfo *roi,const char *magick_restrict map,
1340 const QuantumType *quantum_map,void *pixels,ExceptionInfo *exception)
1342 register const Quantum
1348 register MagickSizeType
1357 q=(MagickSizeType *) pixels;
1358 if (LocaleCompare(map,"BGR") == 0)
1360 for (y=0; y < (ssize_t) roi->height; y++)
1362 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1363 if (p == (const Quantum *) NULL)
1365 for (x=0; x < (ssize_t) roi->width; x++)
1367 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1368 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1369 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1370 p+=GetPixelChannels(image);
1373 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1375 if (LocaleCompare(map,"BGRA") == 0)
1377 for (y=0; y < (ssize_t) roi->height; y++)
1379 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1380 if (p == (const Quantum *) NULL)
1382 for (x=0; x < (ssize_t) roi->width; x++)
1384 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1385 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1386 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1387 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1388 p+=GetPixelChannels(image);
1391 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1393 if (LocaleCompare(map,"BGRP") == 0)
1395 for (y=0; y < (ssize_t) roi->height; y++)
1397 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1398 if (p == (const Quantum *) NULL)
1400 for (x=0; x < (ssize_t) roi->width; x++)
1402 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1403 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1404 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1406 p+=GetPixelChannels(image);
1409 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1411 if (LocaleCompare(map,"I") == 0)
1413 for (y=0; y < (ssize_t) roi->height; y++)
1415 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1416 if (p == (const Quantum *) NULL)
1418 for (x=0; x < (ssize_t) roi->width; x++)
1420 *q++=ScaleQuantumToLongLong(ClampToQuantum(
1421 GetPixelIntensity(image,p)));
1422 p+=GetPixelChannels(image);
1425 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1427 if (LocaleCompare(map,"RGB") == 0)
1429 for (y=0; y < (ssize_t) roi->height; y++)
1431 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1432 if (p == (const Quantum *) NULL)
1434 for (x=0; x < (ssize_t) roi->width; x++)
1436 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1437 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1438 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1439 p+=GetPixelChannels(image);
1442 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1444 if (LocaleCompare(map,"RGBA") == 0)
1446 for (y=0; y < (ssize_t) roi->height; y++)
1448 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1449 if (p == (const Quantum *) NULL)
1451 for (x=0; x < (ssize_t) roi->width; x++)
1453 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1454 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1455 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1456 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1457 p+=GetPixelChannels(image);
1460 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1462 if (LocaleCompare(map,"RGBP") == 0)
1464 for (y=0; y < (ssize_t) roi->height; y++)
1466 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1467 if (p == (const Quantum *) NULL)
1469 for (x=0; x < (ssize_t) roi->width; x++)
1471 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1472 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1473 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1475 p+=GetPixelChannels(image);
1478 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1481 for (y=0; y < (ssize_t) roi->height; y++)
1483 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1484 if (p == (const Quantum *) NULL)
1486 for (x=0; x < (ssize_t) roi->width; x++)
1491 for (i=0; i < (ssize_t) length; i++)
1494 switch (quantum_map[i])
1499 *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
1503 case MagentaQuantum:
1505 *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1511 *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1516 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1519 case OpacityQuantum:
1521 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1526 if (image->colorspace == CMYKColorspace)
1527 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
1532 *q=ScaleQuantumToLongLong(ClampToQuantum(
1533 GetPixelIntensity(image,p)));
1541 p+=GetPixelChannels(image);
1544 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1547 static MagickBooleanType ExportQuantumPixel(const Image *image,
1548 const RectangleInfo *roi,const char *magick_restrict map,
1549 const QuantumType *quantum_map,void *pixels,ExceptionInfo *exception)
1551 register const Quantum
1566 q=(Quantum *) pixels;
1567 if (LocaleCompare(map,"BGR") == 0)
1569 for (y=0; y < (ssize_t) roi->height; y++)
1571 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1572 if (p == (const Quantum *) NULL)
1574 for (x=0; x < (ssize_t) roi->width; x++)
1576 *q++=GetPixelBlue(image,p);
1577 *q++=GetPixelGreen(image,p);
1578 *q++=GetPixelRed(image,p);
1579 p+=GetPixelChannels(image);
1582 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1584 if (LocaleCompare(map,"BGRA") == 0)
1586 for (y=0; y < (ssize_t) roi->height; y++)
1588 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1589 if (p == (const Quantum *) NULL)
1591 for (x=0; x < (ssize_t) roi->width; x++)
1593 *q++=GetPixelBlue(image,p);
1594 *q++=GetPixelGreen(image,p);
1595 *q++=GetPixelRed(image,p);
1596 *q++=(Quantum) (GetPixelAlpha(image,p));
1597 p+=GetPixelChannels(image);
1600 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1602 if (LocaleCompare(map,"BGRP") == 0)
1604 for (y=0; y < (ssize_t) roi->height; y++)
1606 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1607 if (p == (const Quantum *) NULL)
1609 for (x=0; x < (ssize_t) roi->width; x++)
1611 *q++=GetPixelBlue(image,p);
1612 *q++=GetPixelGreen(image,p);
1613 *q++=GetPixelRed(image,p);
1615 p+=GetPixelChannels(image);
1618 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1620 if (LocaleCompare(map,"I") == 0)
1622 for (y=0; y < (ssize_t) roi->height; y++)
1624 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1625 if (p == (const Quantum *) NULL)
1627 for (x=0; x < (ssize_t) roi->width; x++)
1629 *q++=ClampToQuantum(GetPixelIntensity(image,p));
1630 p+=GetPixelChannels(image);
1633 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1635 if (LocaleCompare(map,"RGB") == 0)
1637 for (y=0; y < (ssize_t) roi->height; y++)
1639 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1640 if (p == (const Quantum *) NULL)
1642 for (x=0; x < (ssize_t) roi->width; x++)
1644 *q++=GetPixelRed(image,p);
1645 *q++=GetPixelGreen(image,p);
1646 *q++=GetPixelBlue(image,p);
1647 p+=GetPixelChannels(image);
1650 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1652 if (LocaleCompare(map,"RGBA") == 0)
1654 for (y=0; y < (ssize_t) roi->height; y++)
1656 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1657 if (p == (const Quantum *) NULL)
1659 for (x=0; x < (ssize_t) roi->width; x++)
1661 *q++=GetPixelRed(image,p);
1662 *q++=GetPixelGreen(image,p);
1663 *q++=GetPixelBlue(image,p);
1664 *q++=(Quantum) (GetPixelAlpha(image,p));
1665 p+=GetPixelChannels(image);
1668 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1670 if (LocaleCompare(map,"RGBP") == 0)
1672 for (y=0; y < (ssize_t) roi->height; y++)
1674 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1675 if (p == (const Quantum *) NULL)
1677 for (x=0; x < (ssize_t) roi->width; x++)
1679 *q++=GetPixelRed(image,p);
1680 *q++=GetPixelGreen(image,p);
1681 *q++=GetPixelBlue(image,p);
1683 p+=GetPixelChannels(image);
1686 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1689 for (y=0; y < (ssize_t) roi->height; y++)
1691 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1692 if (p == (const Quantum *) NULL)
1694 for (x=0; x < (ssize_t) roi->width; x++)
1699 for (i=0; i < (ssize_t) length; i++)
1702 switch (quantum_map[i])
1707 *q=GetPixelRed(image,p);
1711 case MagentaQuantum:
1713 *q=GetPixelGreen(image,p);
1719 *q=GetPixelBlue(image,p);
1724 *q=GetPixelAlpha(image,p);
1727 case OpacityQuantum:
1729 *q=GetPixelAlpha(image,p);
1734 if (image->colorspace == CMYKColorspace)
1735 *q=GetPixelBlack(image,p);
1740 *q=ClampToQuantum(GetPixelIntensity(image,p));
1751 p+=GetPixelChannels(image);
1754 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1757 static MagickBooleanType ExportShortPixel(const Image *image,
1758 const RectangleInfo *roi,const char *magick_restrict map,
1759 const QuantumType *quantum_map,void *pixels,ExceptionInfo *exception)
1761 register const Quantum
1767 register unsigned short
1776 q=(unsigned short *) pixels;
1777 if (LocaleCompare(map,"BGR") == 0)
1779 for (y=0; y < (ssize_t) roi->height; y++)
1781 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1782 if (p == (const Quantum *) NULL)
1784 for (x=0; x < (ssize_t) roi->width; x++)
1786 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1787 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1788 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1789 p+=GetPixelChannels(image);
1792 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1794 if (LocaleCompare(map,"BGRA") == 0)
1796 for (y=0; y < (ssize_t) roi->height; y++)
1798 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1799 if (p == (const Quantum *) NULL)
1801 for (x=0; x < (ssize_t) roi->width; x++)
1803 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1804 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1805 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1806 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1807 p+=GetPixelChannels(image);
1810 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1812 if (LocaleCompare(map,"BGRP") == 0)
1814 for (y=0; y < (ssize_t) roi->height; y++)
1816 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1817 if (p == (const Quantum *) NULL)
1819 for (x=0; x < (ssize_t) roi->width; x++)
1821 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1822 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1823 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1825 p+=GetPixelChannels(image);
1828 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1830 if (LocaleCompare(map,"I") == 0)
1832 for (y=0; y < (ssize_t) roi->height; y++)
1834 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1835 if (p == (const Quantum *) NULL)
1837 for (x=0; x < (ssize_t) roi->width; x++)
1839 *q++=ScaleQuantumToShort(ClampToQuantum(GetPixelIntensity(image,p)));
1840 p+=GetPixelChannels(image);
1843 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1845 if (LocaleCompare(map,"RGB") == 0)
1847 for (y=0; y < (ssize_t) roi->height; y++)
1849 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1850 if (p == (const Quantum *) NULL)
1852 for (x=0; x < (ssize_t) roi->width; x++)
1854 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1855 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1856 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1857 p+=GetPixelChannels(image);
1860 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1862 if (LocaleCompare(map,"RGBA") == 0)
1864 for (y=0; y < (ssize_t) roi->height; y++)
1866 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1867 if (p == (const Quantum *) NULL)
1869 for (x=0; x < (ssize_t) roi->width; x++)
1871 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1872 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1873 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1874 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1875 p+=GetPixelChannels(image);
1878 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1880 if (LocaleCompare(map,"RGBP") == 0)
1882 for (y=0; y < (ssize_t) roi->height; y++)
1884 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1885 if (p == (const Quantum *) NULL)
1887 for (x=0; x < (ssize_t) roi->width; x++)
1889 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1890 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1891 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1893 p+=GetPixelChannels(image);
1896 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1899 for (y=0; y < (ssize_t) roi->height; y++)
1901 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1902 if (p == (const Quantum *) NULL)
1904 for (x=0; x < (ssize_t) roi->width; x++)
1909 for (i=0; i < (ssize_t) length; i++)
1912 switch (quantum_map[i])
1917 *q=ScaleQuantumToShort(GetPixelRed(image,p));
1921 case MagentaQuantum:
1923 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
1929 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
1934 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1937 case OpacityQuantum:
1939 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1944 if (image->colorspace == CMYKColorspace)
1945 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
1950 *q=ScaleQuantumToShort(ClampToQuantum(GetPixelIntensity(image,p)));
1958 p+=GetPixelChannels(image);
1961 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1964 MagickExport MagickBooleanType ExportImagePixels(const Image *image,
1965 const ssize_t x,const ssize_t y,const size_t width,const size_t height,
1966 const char *map,const StorageType type,void *pixels,ExceptionInfo *exception)
1983 assert(image != (Image *) NULL);
1984 assert(image->signature == MagickCoreSignature);
1985 if (image->debug != MagickFalse)
1986 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1988 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1989 if (quantum_map == (QuantumType *) NULL)
1991 (void) ThrowMagickException(exception,GetMagickModule(),
1992 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1993 return(MagickFalse);
1995 for (i=0; i < (ssize_t) length; i++)
2002 quantum_map[i]=AlphaQuantum;
2008 quantum_map[i]=BlueQuantum;
2014 quantum_map[i]=CyanQuantum;
2015 if (image->colorspace == CMYKColorspace)
2017 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2018 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2019 "ColorSeparatedImageRequired","`%s'",map);
2020 return(MagickFalse);
2025 quantum_map[i]=GreenQuantum;
2031 quantum_map[i]=IndexQuantum;
2037 quantum_map[i]=BlackQuantum;
2038 if (image->colorspace == CMYKColorspace)
2040 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2041 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2042 "ColorSeparatedImageRequired","`%s'",map);
2043 return(MagickFalse);
2048 quantum_map[i]=MagentaQuantum;
2049 if (image->colorspace == CMYKColorspace)
2051 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2052 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2053 "ColorSeparatedImageRequired","`%s'",map);
2054 return(MagickFalse);
2059 quantum_map[i]=OpacityQuantum;
2065 quantum_map[i]=UndefinedQuantum;
2071 quantum_map[i]=RedQuantum;
2077 quantum_map[i]=YellowQuantum;
2078 if (image->colorspace == CMYKColorspace)
2080 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2081 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2082 "ColorSeparatedImageRequired","`%s'",map);
2083 return(MagickFalse);
2087 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2088 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2089 "UnrecognizedPixelMap","`%s'",map);
2090 return(MagickFalse);
2102 status=ExportCharPixel(image,&roi,map,quantum_map,pixels,exception);
2107 status=ExportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
2112 status=ExportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
2117 status=ExportLongPixel(image,&roi,map,quantum_map,pixels,exception);
2122 status=ExportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
2127 status=ExportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
2132 status=ExportShortPixel(image,&roi,map,quantum_map,pixels,exception);
2137 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2138 "UnrecognizedPixelMap","`%s'",map);
2142 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2151 % G e t P i x e l I n f o %
2155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2157 % GetPixelInfo() initializes the PixelInfo structure.
2159 % The format of the GetPixelInfo method is:
2161 % GetPixelInfo(const Image *image,PixelInfo *pixel)
2163 % A description of each parameter follows:
2165 % o image: the image. (optional - may be NULL)
2167 % o pixel: Specifies a pointer to a PixelInfo structure.
2170 MagickExport void GetPixelInfo(const Image *image,PixelInfo *pixel)
2172 (void) memset(pixel,0,sizeof(*pixel));
2173 pixel->storage_class=DirectClass;
2174 pixel->colorspace=sRGBColorspace;
2175 pixel->depth=MAGICKCORE_QUANTUM_DEPTH;
2176 pixel->alpha_trait=UndefinedPixelTrait;
2177 pixel->alpha=(double) OpaqueAlpha;
2178 if (image == (const Image *) NULL)
2180 pixel->storage_class=image->storage_class;
2181 pixel->colorspace=image->colorspace;
2182 pixel->alpha_trait=image->alpha_trait;
2183 pixel->depth=image->depth;
2184 pixel->fuzz=image->fuzz;
2188 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2192 % G e t P i x e l I n d o I n t e n s i t y %
2196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2198 % GetPixelInfoIntensity() returns a single sample intensity value from the red,
2199 % green, and blue components of a pixel based on the selected method:
2201 % Rec601Luma 0.298839R' + 0.586811G' + 0.114350B'
2202 % Rec601Luminance 0.298839R + 0.586811G + 0.114350B
2203 % Rec709Luma 0.212656R' + 0.715158G' + 0.072186B'
2204 % Rec709Luminance 0.212656R + 0.715158G + 0.072186B
2205 % Brightness max(R', G', B')
2206 % Lightness (min(R', G', B') + max(R', G', B')) / 2.0
2208 % MS (R^2 + G^2 + B^2) / 3.0
2209 % RMS sqrt((R^2 + G^2 + B^2) / 3.0
2210 % Average (R + G + B') / 3.0
2212 % The format of the GetPixelInfoIntensity method is:
2214 % MagickRealType GetPixelInfoIntensity(const Image *image,
2215 % const Quantum *pixel)
2217 % A description of each parameter follows:
2219 % o image: the image.
2221 % o pixel: Specifies a pointer to a Quantum structure.
2224 MagickExport MagickRealType GetPixelInfoIntensity(
2225 const Image *magick_restrict image,const PixelInfo *magick_restrict pixel)
2233 PixelIntensityMethod
2236 method=Rec709LumaPixelIntensityMethod;
2237 if (image != (const Image *) NULL)
2238 method=image->intensity;
2244 case AveragePixelIntensityMethod:
2246 intensity=(red+green+blue)/3.0;
2249 case BrightnessPixelIntensityMethod:
2251 intensity=MagickMax(MagickMax(red,green),blue);
2254 case LightnessPixelIntensityMethod:
2256 intensity=(MagickMin(MagickMin(red,green),blue)+
2257 MagickMax(MagickMax(red,green),blue))/2.0;
2260 case MSPixelIntensityMethod:
2262 intensity=(MagickRealType) (((double) red*red+green*green+blue*blue)/
2263 (3.0*QuantumRange));
2266 case Rec601LumaPixelIntensityMethod:
2268 if (pixel->colorspace == RGBColorspace)
2270 red=EncodePixelGamma(red);
2271 green=EncodePixelGamma(green);
2272 blue=EncodePixelGamma(blue);
2274 intensity=0.298839*red+0.586811*green+0.114350*blue;
2277 case Rec601LuminancePixelIntensityMethod:
2279 if (pixel->colorspace == sRGBColorspace)
2281 red=DecodePixelGamma(red);
2282 green=DecodePixelGamma(green);
2283 blue=DecodePixelGamma(blue);
2285 intensity=0.298839*red+0.586811*green+0.114350*blue;
2288 case Rec709LumaPixelIntensityMethod:
2291 if (pixel->colorspace == RGBColorspace)
2293 red=EncodePixelGamma(red);
2294 green=EncodePixelGamma(green);
2295 blue=EncodePixelGamma(blue);
2297 intensity=0.212656*red+0.715158*green+0.072186*blue;
2300 case Rec709LuminancePixelIntensityMethod:
2302 if (pixel->colorspace == sRGBColorspace)
2304 red=DecodePixelGamma(red);
2305 green=DecodePixelGamma(green);
2306 blue=DecodePixelGamma(blue);
2308 intensity=0.212656*red+0.715158*green+0.072186*blue;
2311 case RMSPixelIntensityMethod:
2313 intensity=(MagickRealType) (sqrt((double) red*red+green*green+blue*blue)/
2322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2326 % G e t P i x e l I n t e n s i t y %
2330 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2332 % GetPixelIntensity() returns a single sample intensity value from the red,
2333 % green, and blue components of a pixel based on the selected method:
2335 % Rec601Luma 0.298839R' + 0.586811G' + 0.114350B'
2336 % Rec601Luminance 0.298839R + 0.586811G + 0.114350B
2337 % Rec709Luma 0.212656R' + 0.715158G' + 0.072186B'
2338 % Rec709Luminance 0.212656R + 0.715158G + 0.072186B
2339 % Brightness max(R', G', B')
2340 % Lightness (min(R', G', B') + max(R', G', B')) / 2.0
2342 % MS (R^2 + G^2 + B^2) / 3.0
2343 % RMS sqrt((R^2 + G^2 + B^2) / 3.0
2344 % Average (R + G + B') / 3.0
2346 % The format of the GetPixelIntensity method is:
2348 % MagickRealType GetPixelIntensity(const Image *image,
2349 % const Quantum *pixel)
2351 % A description of each parameter follows:
2353 % o image: the image.
2355 % o pixel: Specifies a pointer to a Quantum structure.
2358 MagickExport MagickRealType GetPixelIntensity(
2359 const Image *magick_restrict image,const Quantum *magick_restrict pixel)
2367 red=(MagickRealType) GetPixelRed(image,pixel);
2368 green=(MagickRealType) GetPixelGreen(image,pixel);
2369 blue=(MagickRealType) GetPixelBlue(image,pixel);
2370 switch (image->intensity)
2372 case AveragePixelIntensityMethod:
2374 intensity=(red+green+blue)/3.0;
2377 case BrightnessPixelIntensityMethod:
2379 intensity=MagickMax(MagickMax(red,green),blue);
2382 case LightnessPixelIntensityMethod:
2384 intensity=(MagickMin(MagickMin(red,green),blue)+
2385 MagickMax(MagickMax(red,green),blue))/2.0;
2388 case MSPixelIntensityMethod:
2390 intensity=(MagickRealType) (((double) red*red+green*green+blue*blue)/
2391 (3.0*QuantumRange));
2394 case Rec601LumaPixelIntensityMethod:
2396 if (image->colorspace == RGBColorspace)
2398 red=EncodePixelGamma(red);
2399 green=EncodePixelGamma(green);
2400 blue=EncodePixelGamma(blue);
2402 intensity=0.298839*red+0.586811*green+0.114350*blue;
2405 case Rec601LuminancePixelIntensityMethod:
2407 if (image->colorspace == sRGBColorspace)
2409 red=DecodePixelGamma(red);
2410 green=DecodePixelGamma(green);
2411 blue=DecodePixelGamma(blue);
2413 intensity=0.298839*red+0.586811*green+0.114350*blue;
2416 case Rec709LumaPixelIntensityMethod:
2419 if (image->colorspace == RGBColorspace)
2421 red=EncodePixelGamma(red);
2422 green=EncodePixelGamma(green);
2423 blue=EncodePixelGamma(blue);
2425 intensity=0.212656*red+0.715158*green+0.072186*blue;
2428 case Rec709LuminancePixelIntensityMethod:
2430 if (image->colorspace == sRGBColorspace)
2432 red=DecodePixelGamma(red);
2433 green=DecodePixelGamma(green);
2434 blue=DecodePixelGamma(blue);
2436 intensity=0.212656*red+0.715158*green+0.072186*blue;
2439 case RMSPixelIntensityMethod:
2441 intensity=(MagickRealType) (sqrt((double) red*red+green*green+blue*blue)/
2450 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2454 % I m p o r t I m a g e P i x e l s %
2458 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2460 % ImportImagePixels() accepts pixel data and stores in the image at the
2461 % location you specify. The method returns MagickTrue on success otherwise
2462 % MagickFalse if an error is encountered. The pixel data can be either char,
2463 % Quantum, short int, unsigned int, unsigned long long, float, or double in
2464 % the order specified by map.
2466 % Suppose your want to upload the first scanline of a 640x480 image from
2467 % character data in red-green-blue order:
2469 % ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels);
2471 % The format of the ImportImagePixels method is:
2473 % MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
2474 % const ssize_t y,const size_t width,const size_t height,
2475 % const char *map,const StorageType type,const void *pixels,
2476 % ExceptionInfo *exception)
2478 % A description of each parameter follows:
2480 % o image: the image.
2482 % o x,y,width,height: These values define the perimeter
2483 % of a region of pixels you want to define.
2485 % o map: This string reflects the expected ordering of the pixel array.
2486 % It can be any combination or order of R = red, G = green, B = blue,
2487 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
2488 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
2491 % o type: Define the data type of the pixels. Float and double types are
2492 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
2493 % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *),
2494 % LongPixel (unsigned int *), LongLongPixel (unsigned long long *),
2495 % QuantumPixel (Quantum *), or ShortPixel (unsigned short *).
2497 % o pixels: This array of values contain the pixel components as defined by
2498 % map and type. You must preallocate this array where the expected
2499 % length varies depending on the values of width, height, map, and type.
2501 % o exception: return any errors or warnings in this structure.
2505 static MagickBooleanType ImportCharPixel(Image *image,const RectangleInfo *roi,
2506 const char *magick_restrict map,const QuantumType *quantum_map,
2507 const void *pixels,ExceptionInfo *exception)
2509 register const unsigned char
2524 p=(const unsigned char *) pixels;
2525 if (LocaleCompare(map,"BGR") == 0)
2527 for (y=0; y < (ssize_t) roi->height; y++)
2529 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2530 if (q == (Quantum *) NULL)
2532 for (x=0; x < (ssize_t) roi->width; x++)
2534 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2535 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2536 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2537 q+=GetPixelChannels(image);
2539 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2542 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2544 if (LocaleCompare(map,"BGRA") == 0)
2546 for (y=0; y < (ssize_t) roi->height; y++)
2548 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2549 if (q == (Quantum *) NULL)
2551 for (x=0; x < (ssize_t) roi->width; x++)
2553 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2554 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2555 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2556 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2557 q+=GetPixelChannels(image);
2559 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2562 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2564 if (LocaleCompare(map,"BGRO") == 0)
2566 for (y=0; y < (ssize_t) roi->height; y++)
2568 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2569 if (q == (Quantum *) NULL)
2571 for (x=0; x < (ssize_t) roi->width; x++)
2573 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2574 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2575 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2576 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2577 q+=GetPixelChannels(image);
2579 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2582 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2584 if (LocaleCompare(map,"BGRP") == 0)
2586 for (y=0; y < (ssize_t) roi->height; y++)
2588 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2589 if (q == (Quantum *) NULL)
2591 for (x=0; x < (ssize_t) roi->width; x++)
2593 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2594 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2595 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2597 q+=GetPixelChannels(image);
2599 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2602 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2604 if (LocaleCompare(map,"I") == 0)
2606 for (y=0; y < (ssize_t) roi->height; y++)
2608 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2609 if (q == (Quantum *) NULL)
2611 for (x=0; x < (ssize_t) roi->width; x++)
2613 SetPixelGray(image,ScaleCharToQuantum(*p++),q);
2614 q+=GetPixelChannels(image);
2616 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2619 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2621 if (LocaleCompare(map,"RGB") == 0)
2623 for (y=0; y < (ssize_t) roi->height; y++)
2625 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2626 if (q == (Quantum *) NULL)
2628 for (x=0; x < (ssize_t) roi->width; x++)
2630 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2631 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2632 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2633 q+=GetPixelChannels(image);
2635 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2638 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2640 if (LocaleCompare(map,"RGBA") == 0)
2642 for (y=0; y < (ssize_t) roi->height; y++)
2644 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2645 if (q == (Quantum *) NULL)
2647 for (x=0; x < (ssize_t) roi->width; x++)
2649 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2650 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2651 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2652 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2653 q+=GetPixelChannels(image);
2655 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2658 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2660 if (LocaleCompare(map,"RGBO") == 0)
2662 for (y=0; y < (ssize_t) roi->height; y++)
2664 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2665 if (q == (Quantum *) NULL)
2667 for (x=0; x < (ssize_t) roi->width; x++)
2669 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2670 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2671 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2672 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2673 q+=GetPixelChannels(image);
2675 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2678 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2680 if (LocaleCompare(map,"RGBP") == 0)
2682 for (y=0; y < (ssize_t) roi->height; y++)
2684 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2685 if (q == (Quantum *) NULL)
2687 for (x=0; x < (ssize_t) roi->width; x++)
2689 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2690 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2691 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2693 q+=GetPixelChannels(image);
2695 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2698 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2701 for (y=0; y < (ssize_t) roi->height; y++)
2703 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2704 if (q == (Quantum *) NULL)
2706 for (x=0; x < (ssize_t) roi->width; x++)
2711 for (i=0; i < (ssize_t) length; i++)
2713 switch (quantum_map[i])
2718 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2722 case MagentaQuantum:
2724 SetPixelGreen(image,ScaleCharToQuantum(*p),q);
2730 SetPixelBlue(image,ScaleCharToQuantum(*p),q);
2735 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2738 case OpacityQuantum:
2740 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2745 SetPixelBlack(image,ScaleCharToQuantum(*p),q);
2750 SetPixelGray(image,ScaleCharToQuantum(*p),q);
2758 q+=GetPixelChannels(image);
2760 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2763 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2766 static MagickBooleanType ImportDoublePixel(Image *image,
2767 const RectangleInfo *roi,const char *magick_restrict map,
2768 const QuantumType *quantum_map,const void *pixels,ExceptionInfo *exception)
2770 register const double
2785 p=(const double *) pixels;
2786 if (LocaleCompare(map,"BGR") == 0)
2788 for (y=0; y < (ssize_t) roi->height; y++)
2790 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2791 if (q == (Quantum *) NULL)
2793 for (x=0; x < (ssize_t) roi->width; x++)
2795 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2797 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2799 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2801 q+=GetPixelChannels(image);
2803 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2806 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2808 if (LocaleCompare(map,"BGRA") == 0)
2810 for (y=0; y < (ssize_t) roi->height; y++)
2812 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2813 if (q == (Quantum *) NULL)
2815 for (x=0; x < (ssize_t) roi->width; x++)
2817 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2819 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2821 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2823 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2825 q+=GetPixelChannels(image);
2827 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2830 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2832 if (LocaleCompare(map,"BGRP") == 0)
2834 for (y=0; y < (ssize_t) roi->height; y++)
2836 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2837 if (q == (Quantum *) NULL)
2839 for (x=0; x < (ssize_t) roi->width; x++)
2841 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2843 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2845 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2848 q+=GetPixelChannels(image);
2850 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2853 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2855 if (LocaleCompare(map,"I") == 0)
2857 for (y=0; y < (ssize_t) roi->height; y++)
2859 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2860 if (q == (Quantum *) NULL)
2862 for (x=0; x < (ssize_t) roi->width; x++)
2864 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2866 q+=GetPixelChannels(image);
2868 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2871 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2873 if (LocaleCompare(map,"RGB") == 0)
2875 for (y=0; y < (ssize_t) roi->height; y++)
2877 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2878 if (q == (Quantum *) NULL)
2880 for (x=0; x < (ssize_t) roi->width; x++)
2882 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2884 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2886 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2888 q+=GetPixelChannels(image);
2890 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2893 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2895 if (LocaleCompare(map,"RGBA") == 0)
2897 for (y=0; y < (ssize_t) roi->height; y++)
2899 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2900 if (q == (Quantum *) NULL)
2902 for (x=0; x < (ssize_t) roi->width; x++)
2904 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2906 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2908 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2910 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2912 q+=GetPixelChannels(image);
2914 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2917 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2919 if (LocaleCompare(map,"RGBP") == 0)
2921 for (y=0; y < (ssize_t) roi->height; y++)
2923 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2924 if (q == (Quantum *) NULL)
2926 for (x=0; x < (ssize_t) roi->width; x++)
2928 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2930 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2932 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2934 q+=GetPixelChannels(image);
2936 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2939 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2942 for (y=0; y < (ssize_t) roi->height; y++)
2944 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2945 if (q == (Quantum *) NULL)
2947 for (x=0; x < (ssize_t) roi->width; x++)
2952 for (i=0; i < (ssize_t) length; i++)
2954 switch (quantum_map[i])
2959 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2963 case MagentaQuantum:
2965 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2971 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2976 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2979 case OpacityQuantum:
2981 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2986 SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q);
2991 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2999 q+=GetPixelChannels(image);
3001 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3004 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3007 static MagickBooleanType ImportFloatPixel(Image *image,const RectangleInfo *roi,
3008 const char *magick_restrict map,const QuantumType *quantum_map,
3009 const void *pixels,ExceptionInfo *exception)
3011 register const float
3026 p=(const float *) pixels;
3027 if (LocaleCompare(map,"BGR") == 0)
3029 for (y=0; y < (ssize_t) roi->height; y++)
3031 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3032 if (q == (Quantum *) NULL)
3034 for (x=0; x < (ssize_t) roi->width; x++)
3036 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3038 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3040 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3042 q+=GetPixelChannels(image);
3044 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3047 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3049 if (LocaleCompare(map,"BGRA") == 0)
3051 for (y=0; y < (ssize_t) roi->height; y++)
3053 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3054 if (q == (Quantum *) NULL)
3056 for (x=0; x < (ssize_t) roi->width; x++)
3058 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3060 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3062 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3064 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
3066 q+=GetPixelChannels(image);
3068 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3071 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3073 if (LocaleCompare(map,"BGRP") == 0)
3075 for (y=0; y < (ssize_t) roi->height; y++)
3077 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3078 if (q == (Quantum *) NULL)
3080 for (x=0; x < (ssize_t) roi->width; x++)
3082 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3084 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3086 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3089 q+=GetPixelChannels(image);
3091 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3094 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3096 if (LocaleCompare(map,"I") == 0)
3098 for (y=0; y < (ssize_t) roi->height; y++)
3100 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3101 if (q == (Quantum *) NULL)
3103 for (x=0; x < (ssize_t) roi->width; x++)
3105 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
3107 q+=GetPixelChannels(image);
3109 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3112 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3114 if (LocaleCompare(map,"RGB") == 0)
3116 for (y=0; y < (ssize_t) roi->height; y++)
3118 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3119 if (q == (Quantum *) NULL)
3121 for (x=0; x < (ssize_t) roi->width; x++)
3123 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3125 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3127 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3129 q+=GetPixelChannels(image);
3131 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3134 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3136 if (LocaleCompare(map,"RGBA") == 0)
3138 for (y=0; y < (ssize_t) roi->height; y++)
3140 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3141 if (q == (Quantum *) NULL)
3143 for (x=0; x < (ssize_t) roi->width; x++)
3145 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3147 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3149 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3151 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
3153 q+=GetPixelChannels(image);
3155 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3158 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3160 if (LocaleCompare(map,"RGBP") == 0)
3162 for (y=0; y < (ssize_t) roi->height; y++)
3164 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3165 if (q == (Quantum *) NULL)
3167 for (x=0; x < (ssize_t) roi->width; x++)
3169 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3171 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3173 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3175 q+=GetPixelChannels(image);
3177 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3180 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3183 for (y=0; y < (ssize_t) roi->height; y++)
3185 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3186 if (q == (Quantum *) NULL)
3188 for (x=0; x < (ssize_t) roi->width; x++)
3193 for (i=0; i < (ssize_t) length; i++)
3195 switch (quantum_map[i])
3200 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3204 case MagentaQuantum:
3206 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3212 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3217 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
3220 case OpacityQuantum:
3222 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
3227 SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q);
3232 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
3240 q+=GetPixelChannels(image);
3242 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3245 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3248 static MagickBooleanType ImportLongPixel(Image *image,const RectangleInfo *roi,
3249 const char *magick_restrict map,const QuantumType *quantum_map,
3250 const void *pixels,ExceptionInfo *exception)
3252 register const unsigned int
3267 p=(const unsigned int *) pixels;
3268 if (LocaleCompare(map,"BGR") == 0)
3270 for (y=0; y < (ssize_t) roi->height; y++)
3272 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3273 if (q == (Quantum *) NULL)
3275 for (x=0; x < (ssize_t) roi->width; x++)
3277 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3278 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3279 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3280 q+=GetPixelChannels(image);
3282 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3285 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3287 if (LocaleCompare(map,"BGRA") == 0)
3289 for (y=0; y < (ssize_t) roi->height; y++)
3291 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3292 if (q == (Quantum *) NULL)
3294 for (x=0; x < (ssize_t) roi->width; x++)
3296 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3297 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3298 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3299 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3300 q+=GetPixelChannels(image);
3302 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3305 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3307 if (LocaleCompare(map,"BGRP") == 0)
3309 for (y=0; y < (ssize_t) roi->height; y++)
3311 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3312 if (q == (Quantum *) NULL)
3314 for (x=0; x < (ssize_t) roi->width; x++)
3316 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3317 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3318 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3320 q+=GetPixelChannels(image);
3322 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3325 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3327 if (LocaleCompare(map,"I") == 0)
3329 for (y=0; y < (ssize_t) roi->height; y++)
3331 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3332 if (q == (Quantum *) NULL)
3334 for (x=0; x < (ssize_t) roi->width; x++)
3336 SetPixelGray(image,ScaleLongToQuantum(*p++),q);
3337 q+=GetPixelChannels(image);
3339 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3342 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3344 if (LocaleCompare(map,"RGB") == 0)
3346 for (y=0; y < (ssize_t) roi->height; y++)
3348 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3349 if (q == (Quantum *) NULL)
3351 for (x=0; x < (ssize_t) roi->width; x++)
3353 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3354 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3355 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3356 q+=GetPixelChannels(image);
3358 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3361 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3363 if (LocaleCompare(map,"RGBA") == 0)
3365 for (y=0; y < (ssize_t) roi->height; y++)
3367 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3368 if (q == (Quantum *) NULL)
3370 for (x=0; x < (ssize_t) roi->width; x++)
3372 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3373 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3374 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3375 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3376 q+=GetPixelChannels(image);
3378 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3381 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3383 if (LocaleCompare(map,"RGBP") == 0)
3385 for (y=0; y < (ssize_t) roi->height; y++)
3387 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3388 if (q == (Quantum *) NULL)
3390 for (x=0; x < (ssize_t) roi->width; x++)
3392 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3393 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3394 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3396 q+=GetPixelChannels(image);
3398 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3401 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3404 for (y=0; y < (ssize_t) roi->height; y++)
3406 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3407 if (q == (Quantum *) NULL)
3409 for (x=0; x < (ssize_t) roi->width; x++)
3414 for (i=0; i < (ssize_t) length; i++)
3416 switch (quantum_map[i])
3421 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3425 case MagentaQuantum:
3427 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
3433 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
3438 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3441 case OpacityQuantum:
3443 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3448 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
3453 SetPixelGray(image,ScaleLongToQuantum(*p),q);
3461 q+=GetPixelChannels(image);
3463 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3466 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3469 static MagickBooleanType ImportLongLongPixel(Image *image,
3470 const RectangleInfo *roi,const char *magick_restrict map,
3471 const QuantumType *quantum_map,const void *pixels,ExceptionInfo *exception)
3473 register const MagickSizeType
3488 p=(const MagickSizeType *) pixels;
3489 if (LocaleCompare(map,"BGR") == 0)
3491 for (y=0; y < (ssize_t) roi->height; y++)
3493 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3494 if (q == (Quantum *) NULL)
3496 for (x=0; x < (ssize_t) roi->width; x++)
3498 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3499 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3500 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3501 q+=GetPixelChannels(image);
3503 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3506 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3508 if (LocaleCompare(map,"BGRA") == 0)
3510 for (y=0; y < (ssize_t) roi->height; y++)
3512 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3513 if (q == (Quantum *) NULL)
3515 for (x=0; x < (ssize_t) roi->width; x++)
3517 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3518 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3519 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3520 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3521 q+=GetPixelChannels(image);
3523 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3526 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3528 if (LocaleCompare(map,"BGRP") == 0)
3530 for (y=0; y < (ssize_t) roi->height; y++)
3532 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3533 if (q == (Quantum *) NULL)
3535 for (x=0; x < (ssize_t) roi->width; x++)
3537 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3538 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3539 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3541 q+=GetPixelChannels(image);
3543 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3546 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3548 if (LocaleCompare(map,"I") == 0)
3550 for (y=0; y < (ssize_t) roi->height; y++)
3552 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3553 if (q == (Quantum *) NULL)
3555 for (x=0; x < (ssize_t) roi->width; x++)
3557 SetPixelGray(image,ScaleLongLongToQuantum(*p++),q);
3558 q+=GetPixelChannels(image);
3560 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3563 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3565 if (LocaleCompare(map,"RGB") == 0)
3567 for (y=0; y < (ssize_t) roi->height; y++)
3569 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3570 if (q == (Quantum *) NULL)
3572 for (x=0; x < (ssize_t) roi->width; x++)
3574 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3575 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3576 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3577 q+=GetPixelChannels(image);
3579 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3582 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3584 if (LocaleCompare(map,"RGBA") == 0)
3586 for (y=0; y < (ssize_t) roi->height; y++)
3588 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3589 if (q == (Quantum *) NULL)
3591 for (x=0; x < (ssize_t) roi->width; x++)
3593 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3594 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3595 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3596 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3597 q+=GetPixelChannels(image);
3599 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3602 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3604 if (LocaleCompare(map,"RGBP") == 0)
3606 for (y=0; y < (ssize_t) roi->height; y++)
3608 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3609 if (q == (Quantum *) NULL)
3611 for (x=0; x < (ssize_t) roi->width; x++)
3613 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3614 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3615 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3617 q+=GetPixelChannels(image);
3619 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3622 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3625 for (y=0; y < (ssize_t) roi->height; y++)
3627 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3628 if (q == (Quantum *) NULL)
3630 for (x=0; x < (ssize_t) roi->width; x++)
3635 for (i=0; i < (ssize_t) length; i++)
3637 switch (quantum_map[i])
3642 SetPixelRed(image,ScaleLongLongToQuantum(*p),q);
3646 case MagentaQuantum:
3648 SetPixelGreen(image,ScaleLongLongToQuantum(*p),q);
3654 SetPixelBlue(image,ScaleLongLongToQuantum(*p),q);
3659 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3662 case OpacityQuantum:
3664 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3669 SetPixelBlack(image,ScaleLongLongToQuantum(*p),q);
3674 SetPixelGray(image,ScaleLongLongToQuantum(*p),q);
3682 q+=GetPixelChannels(image);
3684 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3687 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3690 static MagickBooleanType ImportQuantumPixel(Image *image,
3691 const RectangleInfo *roi,const char *magick_restrict map,
3692 const QuantumType *quantum_map,const void *pixels,ExceptionInfo *exception)
3694 register const Quantum
3709 p=(const Quantum *) pixels;
3710 if (LocaleCompare(map,"BGR") == 0)
3712 for (y=0; y < (ssize_t) roi->height; y++)
3714 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3715 if (q == (Quantum *) NULL)
3717 for (x=0; x < (ssize_t) roi->width; x++)
3719 SetPixelBlue(image,*p++,q);
3720 SetPixelGreen(image,*p++,q);
3721 SetPixelRed(image,*p++,q);
3722 q+=GetPixelChannels(image);
3724 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3727 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3729 if (LocaleCompare(map,"BGRA") == 0)
3731 for (y=0; y < (ssize_t) roi->height; y++)
3733 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3734 if (q == (Quantum *) NULL)
3736 for (x=0; x < (ssize_t) roi->width; x++)
3738 SetPixelBlue(image,*p++,q);
3739 SetPixelGreen(image,*p++,q);
3740 SetPixelRed(image,*p++,q);
3741 SetPixelAlpha(image,*p++,q);
3742 q+=GetPixelChannels(image);
3744 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3747 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3749 if (LocaleCompare(map,"BGRP") == 0)
3751 for (y=0; y < (ssize_t) roi->height; y++)
3753 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3754 if (q == (Quantum *) NULL)
3756 for (x=0; x < (ssize_t) roi->width; x++)
3758 SetPixelBlue(image,*p++,q);
3759 SetPixelGreen(image,*p++,q);
3760 SetPixelRed(image,*p++,q);
3762 q+=GetPixelChannels(image);
3764 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3767 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3769 if (LocaleCompare(map,"I") == 0)
3771 for (y=0; y < (ssize_t) roi->height; y++)
3773 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3774 if (q == (Quantum *) NULL)
3776 for (x=0; x < (ssize_t) roi->width; x++)
3778 SetPixelGray(image,*p++,q);
3779 q+=GetPixelChannels(image);
3781 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3784 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3786 if (LocaleCompare(map,"RGB") == 0)
3788 for (y=0; y < (ssize_t) roi->height; y++)
3790 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3791 if (q == (Quantum *) NULL)
3793 for (x=0; x < (ssize_t) roi->width; x++)
3795 SetPixelRed(image,*p++,q);
3796 SetPixelGreen(image,*p++,q);
3797 SetPixelBlue(image,*p++,q);
3798 q+=GetPixelChannels(image);
3800 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3803 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3805 if (LocaleCompare(map,"RGBA") == 0)
3807 for (y=0; y < (ssize_t) roi->height; y++)
3809 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3810 if (q == (Quantum *) NULL)
3812 for (x=0; x < (ssize_t) roi->width; x++)
3814 SetPixelRed(image,*p++,q);
3815 SetPixelGreen(image,*p++,q);
3816 SetPixelBlue(image,*p++,q);
3817 SetPixelAlpha(image,*p++,q);
3818 q+=GetPixelChannels(image);
3820 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3823 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3825 if (LocaleCompare(map,"RGBP") == 0)
3827 for (y=0; y < (ssize_t) roi->height; y++)
3829 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3830 if (q == (Quantum *) NULL)
3832 for (x=0; x < (ssize_t) roi->width; x++)
3834 SetPixelRed(image,*p++,q);
3835 SetPixelGreen(image,*p++,q);
3836 SetPixelBlue(image,*p++,q);
3838 q+=GetPixelChannels(image);
3840 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3843 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3846 for (y=0; y < (ssize_t) roi->height; y++)
3848 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3849 if (q == (Quantum *) NULL)
3851 for (x=0; x < (ssize_t) roi->width; x++)
3856 for (i=0; i < (ssize_t) length; i++)
3858 switch (quantum_map[i])
3863 SetPixelRed(image,*p,q);
3867 case MagentaQuantum:
3869 SetPixelGreen(image,*p,q);
3875 SetPixelBlue(image,*p,q);
3880 SetPixelAlpha(image,*p,q);
3883 case OpacityQuantum:
3885 SetPixelAlpha(image,*p,q);
3890 SetPixelBlack(image,*p,q);
3895 SetPixelGray(image,*p,q);
3903 q+=GetPixelChannels(image);
3905 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3908 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3911 static MagickBooleanType ImportShortPixel(Image *image,const RectangleInfo *roi,
3912 const char *magick_restrict map,const QuantumType *quantum_map,
3913 const void *pixels,ExceptionInfo *exception)
3915 register const unsigned short
3930 p=(const unsigned short *) pixels;
3931 if (LocaleCompare(map,"BGR") == 0)
3933 for (y=0; y < (ssize_t) roi->height; y++)
3935 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3936 if (q == (Quantum *) NULL)
3938 for (x=0; x < (ssize_t) roi->width; x++)
3940 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3941 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3942 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3943 q+=GetPixelChannels(image);
3945 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3948 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3950 if (LocaleCompare(map,"BGRA") == 0)
3952 for (y=0; y < (ssize_t) roi->height; y++)
3954 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3955 if (q == (Quantum *) NULL)
3957 for (x=0; x < (ssize_t) roi->width; x++)
3959 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3960 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3961 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3962 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3963 q+=GetPixelChannels(image);
3965 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3968 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3970 if (LocaleCompare(map,"BGRP") == 0)
3972 for (y=0; y < (ssize_t) roi->height; y++)
3974 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3975 if (q == (Quantum *) NULL)
3977 for (x=0; x < (ssize_t) roi->width; x++)
3979 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3980 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3981 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3983 q+=GetPixelChannels(image);
3985 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3988 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3990 if (LocaleCompare(map,"I") == 0)
3992 for (y=0; y < (ssize_t) roi->height; y++)
3994 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3995 if (q == (Quantum *) NULL)
3997 for (x=0; x < (ssize_t) roi->width; x++)
3999 SetPixelGray(image,ScaleShortToQuantum(*p++),q);
4000 q+=GetPixelChannels(image);
4002 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4005 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4007 if (LocaleCompare(map,"RGB") == 0)
4009 for (y=0; y < (ssize_t) roi->height; y++)
4011 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4012 if (q == (Quantum *) NULL)
4014 for (x=0; x < (ssize_t) roi->width; x++)
4016 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4017 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4018 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4019 q+=GetPixelChannels(image);
4021 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4024 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4026 if (LocaleCompare(map,"RGBA") == 0)
4028 for (y=0; y < (ssize_t) roi->height; y++)
4030 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4031 if (q == (Quantum *) NULL)
4033 for (x=0; x < (ssize_t) roi->width; x++)
4035 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4036 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4037 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4038 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
4039 q+=GetPixelChannels(image);
4041 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4044 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4046 if (LocaleCompare(map,"RGBP") == 0)
4048 for (y=0; y < (ssize_t) roi->height; y++)
4050 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4051 if (q == (Quantum *) NULL)
4053 for (x=0; x < (ssize_t) roi->width; x++)
4055 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4056 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4057 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4059 q+=GetPixelChannels(image);
4061 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4064 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4067 for (y=0; y < (ssize_t) roi->height; y++)
4069 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4070 if (q == (Quantum *) NULL)
4072 for (x=0; x < (ssize_t) roi->width; x++)
4077 for (i=0; i < (ssize_t) length; i++)
4079 switch (quantum_map[i])
4084 SetPixelRed(image,ScaleShortToQuantum(*p),q);
4088 case MagentaQuantum:
4090 SetPixelGreen(image,ScaleShortToQuantum(*p),q);
4096 SetPixelBlue(image,ScaleShortToQuantum(*p),q);
4101 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
4104 case OpacityQuantum:
4106 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
4111 SetPixelBlack(image,ScaleShortToQuantum(*p),q);
4116 SetPixelGray(image,ScaleShortToQuantum(*p),q);
4124 q+=GetPixelChannels(image);
4126 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4129 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4132 MagickExport MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
4133 const ssize_t y,const size_t width,const size_t height,const char *map,
4134 const StorageType type,const void *pixels,ExceptionInfo *exception)
4152 Allocate image structure.
4154 assert(image != (Image *) NULL);
4155 assert(image->signature == MagickCoreSignature);
4156 if (image->debug != MagickFalse)
4157 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4159 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
4160 if (quantum_map == (QuantumType *) NULL)
4161 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
4163 for (i=0; i < (ssize_t) length; i++)
4170 quantum_map[i]=AlphaQuantum;
4171 image->alpha_trait=BlendPixelTrait;
4177 quantum_map[i]=BlueQuantum;
4183 quantum_map[i]=CyanQuantum;
4184 (void) SetImageColorspace(image,CMYKColorspace,exception);
4190 quantum_map[i]=GreenQuantum;
4196 quantum_map[i]=BlackQuantum;
4197 (void) SetImageColorspace(image,CMYKColorspace,exception);
4203 quantum_map[i]=IndexQuantum;
4204 (void) SetImageColorspace(image,GRAYColorspace,exception);
4210 quantum_map[i]=MagentaQuantum;
4211 (void) SetImageColorspace(image,CMYKColorspace,exception);
4217 quantum_map[i]=OpacityQuantum;
4218 image->alpha_trait=BlendPixelTrait;
4224 quantum_map[i]=UndefinedQuantum;
4230 quantum_map[i]=RedQuantum;
4236 quantum_map[i]=YellowQuantum;
4237 (void) SetImageColorspace(image,CMYKColorspace,exception);
4242 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4243 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4244 "UnrecognizedPixelMap","`%s'",map);
4245 return(MagickFalse);
4249 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
4250 return(MagickFalse);
4252 Transfer the pixels from the pixel data to the image.
4262 status=ImportCharPixel(image,&roi,map,quantum_map,pixels,exception);
4267 status=ImportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
4272 status=ImportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
4277 status=ImportLongPixel(image,&roi,map,quantum_map,pixels,exception);
4282 status=ImportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
4287 status=ImportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
4292 status=ImportShortPixel(image,&roi,map,quantum_map,pixels,exception);
4297 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4298 "UnrecognizedStorageType","`%d'",type);
4302 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4307 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4311 + I n i t i a l i z e P i x e l C h a n n e l M a p %
4315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4317 % InitializePixelChannelMap() defines the standard pixel component map.
4319 % The format of the InitializePixelChannelMap() method is:
4321 % void InitializePixelChannelMap(Image *image)
4323 % A description of each parameter follows:
4325 % o image: the image.
4328 MagickExport void InitializePixelChannelMap(Image *image)
4339 assert(image != (Image *) NULL);
4340 assert(image->signature == MagickCoreSignature);
4341 (void) memset(image->channel_map,0,MaxPixelChannels*
4342 sizeof(*image->channel_map));
4343 trait=UpdatePixelTrait;
4344 if (image->alpha_trait != UndefinedPixelTrait)
4345 trait=(PixelTrait) (trait | BlendPixelTrait);
4347 if ((image->colorspace == LinearGRAYColorspace) ||
4348 (image->colorspace == GRAYColorspace))
4350 SetPixelChannelAttributes(image,BluePixelChannel,trait,n);
4351 SetPixelChannelAttributes(image,GreenPixelChannel,trait,n);
4352 SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
4356 SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
4357 SetPixelChannelAttributes(image,GreenPixelChannel,trait,n++);
4358 SetPixelChannelAttributes(image,BluePixelChannel,trait,n++);
4360 if (image->colorspace == CMYKColorspace)
4361 SetPixelChannelAttributes(image,BlackPixelChannel,trait,n++);
4362 for (i=0; i < (ssize_t) image->number_meta_channels; i++)
4364 SetPixelChannelAttributes(image,(PixelChannel) n,UpdatePixelTrait,n);
4367 if (image->alpha_trait != UndefinedPixelTrait)
4368 SetPixelChannelAttributes(image,AlphaPixelChannel,CopyPixelTrait,n++);
4369 if (image->storage_class == PseudoClass)
4370 SetPixelChannelAttributes(image,IndexPixelChannel,CopyPixelTrait,n++);
4371 if ((image->channels & ReadMaskChannel) != 0)
4372 SetPixelChannelAttributes(image,ReadMaskPixelChannel,CopyPixelTrait,n++);
4373 if ((image->channels & WriteMaskChannel) != 0)
4374 SetPixelChannelAttributes(image,WriteMaskPixelChannel,CopyPixelTrait,n++);
4375 if ((image->channels & CompositeMaskChannel) != 0)
4376 SetPixelChannelAttributes(image,CompositeMaskPixelChannel,CopyPixelTrait,
4378 image->number_channels=(size_t) n;
4379 (void) SetPixelChannelMask(image,image->channel_mask);
4383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4387 % I n t e r p o l a t e P i x e l C h a n n e l %
4391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4393 % InterpolatePixelChannel() applies a pixel interpolation method between a
4394 % floating point coordinate and the pixels surrounding that coordinate. No
4395 % pixel area resampling, or scaling of the result is performed.
4397 % Interpolation is restricted to just the specified channel.
4399 % The format of the InterpolatePixelChannel method is:
4401 % MagickBooleanType InterpolatePixelChannel(
4402 % const Image *magick_restrict image,const CacheView *image_view,
4403 % const PixelChannel channel,const PixelInterpolateMethod method,
4404 % const double x,const double y,double *pixel,ExceptionInfo *exception)
4406 % A description of each parameter follows:
4408 % o image: the image.
4410 % o image_view: the image view.
4412 % o channel: the pixel channel to interpolate.
4414 % o method: the pixel color interpolation method.
4416 % o x,y: A double representing the current (x,y) position of the pixel.
4418 % o pixel: return the interpolated pixel here.
4420 % o exception: return any errors or warnings in this structure.
4424 static inline void CatromWeights(const double x,double (*weights)[4])
4432 Nicolas Robidoux' 10 flops (4* + 5- + 1+) refactoring of the computation
4433 of the standard four 1D Catmull-Rom weights. The sampling location is
4434 assumed between the second and third input pixel locations, and x is the
4435 position relative to the second input pixel location. Formulas originally
4436 derived for the VIPS (Virtual Image Processing System) library.
4438 alpha=(double) 1.0-x;
4439 beta=(double) (-0.5)*x*alpha;
4440 (*weights)[0]=alpha*beta;
4441 (*weights)[3]=x*beta;
4443 The following computation of the inner weights from the outer ones work
4444 for all Keys cubics.
4446 gamma=(*weights)[3]-(*weights)[0];
4447 (*weights)[1]=alpha-(*weights)[0]+gamma;
4448 (*weights)[2]=x-(*weights)[3]-gamma;
4451 static inline void SplineWeights(const double x,double (*weights)[4])
4458 Nicolas Robidoux' 12 flops (6* + 5- + 1+) refactoring of the computation
4459 of the standard four 1D cubic B-spline smoothing weights. The sampling
4460 location is assumed between the second and third input pixel locations,
4461 and x is the position relative to the second input pixel location.
4463 alpha=(double) 1.0-x;
4464 (*weights)[3]=(double) (1.0/6.0)*x*x*x;
4465 (*weights)[0]=(double) (1.0/6.0)*alpha*alpha*alpha;
4466 beta=(*weights)[3]-(*weights)[0];
4467 (*weights)[1]=alpha-(*weights)[0]+beta;
4468 (*weights)[2]=x-(*weights)[3]-beta;
4471 static inline double MeshInterpolate(const PointInfo *delta,const double p,
4472 const double x,const double y)
4474 return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
4478 static inline ssize_t NearestNeighbor(const double x)
4481 return((ssize_t) (x+0.5));
4482 return((ssize_t) (x-0.5));
4486 MagickExport MagickBooleanType InterpolatePixelChannel(
4487 const Image *magick_restrict image,const CacheView_ *image_view,
4488 const PixelChannel channel,const PixelInterpolateMethod method,
4489 const double x,const double y,double *pixel,ExceptionInfo *exception)
4499 PixelInterpolateMethod
4505 register const Quantum
4515 assert(image != (Image *) NULL);
4516 assert(image->signature == MagickCoreSignature);
4517 assert(image_view != (CacheView *) NULL);
4520 traits=GetPixelChannelTraits(image,channel);
4521 x_offset=(ssize_t) floor(x);
4522 y_offset=(ssize_t) floor(y);
4524 if (interpolate == UndefinedInterpolatePixel)
4525 interpolate=image->interpolate;
4526 switch (interpolate)
4528 case AverageInterpolatePixel: /* nearest 4 neighbours */
4529 case Average9InterpolatePixel: /* nearest 9 neighbours */
4530 case Average16InterpolatePixel: /* nearest 16 neighbours */
4535 count=2; /* size of the area to average - default nearest 4 */
4536 if (interpolate == Average9InterpolatePixel)
4539 x_offset=(ssize_t) (floor(x+0.5)-1);
4540 y_offset=(ssize_t) (floor(y+0.5)-1);
4543 if (interpolate == Average16InterpolatePixel)
4549 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,(size_t) count,
4550 (size_t) count,exception);
4551 if (p == (const Quantum *) NULL)
4556 count*=count; /* Number of pixels to average */
4557 if ((traits & BlendPixelTrait) == 0)
4558 for (i=0; i < (ssize_t) count; i++)
4561 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4564 for (i=0; i < (ssize_t) count; i++)
4566 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4567 GetPixelChannels(image));
4568 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4570 for (i=0; i < (ssize_t) count; i++)
4572 gamma=PerceptibleReciprocal(alpha[i])/count;
4573 *pixel+=gamma*pixels[i];
4577 case BilinearInterpolatePixel:
4584 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4585 if (p == (const Quantum *) NULL)
4590 if ((traits & BlendPixelTrait) == 0)
4591 for (i=0; i < 4; i++)
4594 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4597 for (i=0; i < 4; i++)
4599 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4600 GetPixelChannels(image));
4601 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4605 epsilon.x=1.0-delta.x;
4606 epsilon.y=1.0-delta.y;
4607 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4608 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4609 gamma=PerceptibleReciprocal(gamma);
4610 *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
4611 (epsilon.x*pixels[2]+delta.x*pixels[3]));
4614 case BlendInterpolatePixel:
4616 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4617 if (p == (const Quantum *) NULL)
4622 if ((traits & BlendPixelTrait) == 0)
4623 for (i=0; i < 4; i++)
4626 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4629 for (i=0; i < 4; i++)
4631 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4632 GetPixelChannels(image));
4633 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4635 gamma=1.0; /* number of pixels blended together (its variable) */
4636 for (i=0; i <= 1L; i++) {
4637 if ((y-y_offset) >= 0.75)
4639 alpha[i]=alpha[i+2]; /* take right pixels */
4640 pixels[i]=pixels[i+2];
4643 if ((y-y_offset) > 0.25)
4645 gamma=2.0; /* blend both pixels in row */
4646 alpha[i]+=alpha[i+2]; /* add up alpha weights */
4647 pixels[i]+=pixels[i+2];
4650 if ((x-x_offset) >= 0.75)
4652 alpha[0]=alpha[1]; /* take bottom row blend */
4653 pixels[0]=pixels[1];
4656 if ((x-x_offset) > 0.25)
4658 gamma*=2.0; /* blend both rows */
4659 alpha[0]+=alpha[1]; /* add up alpha weights */
4660 pixels[0]+=pixels[1];
4662 if (channel != AlphaPixelChannel)
4663 gamma=PerceptibleReciprocal(alpha[0]); /* (color) 1/alpha_weights */
4665 gamma=PerceptibleReciprocal(gamma); /* (alpha) 1/number_of_pixels */
4666 *pixel=gamma*pixels[0];
4669 case CatromInterpolatePixel:
4675 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4677 if (p == (const Quantum *) NULL)
4682 if ((traits & BlendPixelTrait) == 0)
4683 for (i=0; i < 16; i++)
4686 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4689 for (i=0; i < 16; i++)
4691 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4692 GetPixelChannels(image));
4693 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4695 CatromWeights((double) (x-x_offset),&cx);
4696 CatromWeights((double) (y-y_offset),&cy);
4697 gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4698 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4699 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4700 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4701 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4702 cx[2]*alpha[14]+cx[3]*alpha[15])));
4703 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4704 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4705 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4706 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4707 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4710 case IntegerInterpolatePixel:
4712 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4713 if (p == (const Quantum *) NULL)
4718 *pixel=(double) GetPixelChannel(image,channel,p);
4721 case NearestInterpolatePixel:
4723 x_offset=(ssize_t) floor(x+0.5);
4724 y_offset=(ssize_t) floor(y+0.5);
4725 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4726 if (p == (const Quantum *) NULL)
4731 *pixel=(double) GetPixelChannel(image,channel,p);
4734 case MeshInterpolatePixel:
4740 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4741 if (p == (const Quantum *) NULL)
4746 if ((traits & BlendPixelTrait) == 0)
4747 for (i=0; i < 4; i++)
4750 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4753 for (i=0; i < 4; i++)
4755 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4756 GetPixelChannels(image));
4757 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4761 luminance.x=GetPixelLuma(image,p)-(double)
4762 GetPixelLuma(image,p+3*GetPixelChannels(image));
4763 luminance.y=GetPixelLuma(image,p+GetPixelChannels(image))-(double)
4764 GetPixelLuma(image,p+2*GetPixelChannels(image));
4765 if (fabs(luminance.x) < fabs(luminance.y))
4770 if (delta.x <= delta.y)
4773 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4775 delta.y=1.0-delta.y;
4776 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4777 gamma=PerceptibleReciprocal(gamma);
4778 *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
4784 Top-right triangle (pixel: 1, diagonal: 0-3).
4786 delta.x=1.0-delta.x;
4787 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4788 gamma=PerceptibleReciprocal(gamma);
4789 *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
4798 if (delta.x <= (1.0-delta.y))
4801 Top-left triangle (pixel: 0, diagonal: 1-2).
4803 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4804 gamma=PerceptibleReciprocal(gamma);
4805 *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
4811 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4813 delta.x=1.0-delta.x;
4814 delta.y=1.0-delta.y;
4815 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4816 gamma=PerceptibleReciprocal(gamma);
4817 *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
4823 case SplineInterpolatePixel:
4829 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4831 if (p == (const Quantum *) NULL)
4836 if ((traits & BlendPixelTrait) == 0)
4837 for (i=0; i < 16; i++)
4840 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4843 for (i=0; i < 16; i++)
4845 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4846 GetPixelChannels(image));
4847 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4849 SplineWeights((double) (x-x_offset),&cx);
4850 SplineWeights((double) (y-y_offset),&cy);
4851 gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4852 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4853 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4854 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4855 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4856 cx[2]*alpha[14]+cx[3]*alpha[15])));
4857 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4858 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4859 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4860 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4861 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4869 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4873 % I n t e r p o l a t e P i x e l C h a n n e l s %
4877 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4879 % InterpolatePixelChannels() applies a pixel interpolation method between a
4880 % floating point coordinate and the pixels surrounding that coordinate. No
4881 % pixel area resampling, or scaling of the result is performed.
4883 % Interpolation is restricted to just the current channel setting of the
4884 % destination image into which the color is to be stored
4886 % The format of the InterpolatePixelChannels method is:
4888 % MagickBooleanType InterpolatePixelChannels(
4889 % const Image *magick_restrict source,const CacheView *source_view,
4890 % const Image *magick_restrict destination,
4891 % const PixelInterpolateMethod method,const double x,const double y,
4892 % Quantum *pixel,ExceptionInfo *exception)
4894 % A description of each parameter follows:
4896 % o source: the source.
4898 % o source_view: the source view.
4900 % o destination: the destination image, for the interpolated color
4902 % o method: the pixel color interpolation method.
4904 % o x,y: A double representing the current (x,y) position of the pixel.
4906 % o pixel: return the interpolated pixel here.
4908 % o exception: return any errors or warnings in this structure.
4911 MagickExport MagickBooleanType InterpolatePixelChannels(
4912 const Image *magick_restrict source,const CacheView_ *source_view,
4913 const Image *magick_restrict destination,const PixelInterpolateMethod method,
4914 const double x,const double y,Quantum *pixel,ExceptionInfo *exception)
4924 register const Quantum
4934 PixelInterpolateMethod
4937 assert(source != (Image *) NULL);
4938 assert(source->signature == MagickCoreSignature);
4939 assert(source_view != (CacheView *) NULL);
4941 x_offset=(ssize_t) floor(x);
4942 y_offset=(ssize_t) floor(y);
4944 if (interpolate == UndefinedInterpolatePixel)
4945 interpolate=source->interpolate;
4946 switch (interpolate)
4948 case AverageInterpolatePixel: /* nearest 4 neighbours */
4949 case Average9InterpolatePixel: /* nearest 9 neighbours */
4950 case Average16InterpolatePixel: /* nearest 16 neighbours */
4955 count=2; /* size of the area to average - default nearest 4 */
4956 if (interpolate == Average9InterpolatePixel)
4959 x_offset=(ssize_t) (floor(x+0.5)-1);
4960 y_offset=(ssize_t) (floor(y+0.5)-1);
4963 if (interpolate == Average16InterpolatePixel)
4969 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,(size_t) count,
4970 (size_t) count,exception);
4971 if (p == (const Quantum *) NULL)
4976 count*=count; /* Number of pixels to average */
4977 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4985 PixelChannel channel = GetPixelChannelChannel(source,i);
4986 PixelTrait traits = GetPixelChannelTraits(source,channel);
4987 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4989 if ((traits == UndefinedPixelTrait) ||
4990 (destination_traits == UndefinedPixelTrait))
4992 for (j=0; j < (ssize_t) count; j++)
4993 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
4995 if ((traits & BlendPixelTrait) == 0)
4997 for (j=0; j < (ssize_t) count; j++)
5000 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
5003 for (j=0; j < (ssize_t) count; j++)
5005 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
5006 GetPixelChannels(source));
5007 pixels[j]*=alpha[j];
5008 gamma=PerceptibleReciprocal(alpha[j]);
5009 sum+=gamma*pixels[j];
5012 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
5016 case BilinearInterpolatePixel:
5019 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
5020 if (p == (const Quantum *) NULL)
5025 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5031 PixelChannel channel = GetPixelChannelChannel(source,i);
5032 PixelTrait traits = GetPixelChannelTraits(source,channel);
5033 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5035 if ((traits == UndefinedPixelTrait) ||
5036 (destination_traits == UndefinedPixelTrait))
5040 epsilon.x=1.0-delta.x;
5041 epsilon.y=1.0-delta.y;
5042 pixels[0]=(double) p[i];
5043 pixels[1]=(double) p[GetPixelChannels(source)+i];
5044 pixels[2]=(double) p[2*GetPixelChannels(source)+i];
5045 pixels[3]=(double) p[3*GetPixelChannels(source)+i];
5046 if ((traits & BlendPixelTrait) == 0)
5048 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5049 gamma=PerceptibleReciprocal(gamma);
5050 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
5051 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*
5052 pixels[2]+delta.x*pixels[3]))),pixel);
5055 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
5056 alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source));
5057 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
5058 GetPixelChannels(source));
5059 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
5060 GetPixelChannels(source));
5061 pixels[0]*=alpha[0];
5062 pixels[1]*=alpha[1];
5063 pixels[2]*=alpha[2];
5064 pixels[3]*=alpha[3];
5065 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5066 (epsilon.x*alpha[2]+delta.x*alpha[3])));
5067 gamma=PerceptibleReciprocal(gamma);
5068 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
5069 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+
5070 delta.x*pixels[3]))),pixel);
5074 case BlendInterpolatePixel:
5076 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
5077 if (p == (const Quantum *) NULL)
5082 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5087 PixelChannel channel = GetPixelChannelChannel(source,i);
5088 PixelTrait traits = GetPixelChannelTraits(source,channel);
5089 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5091 if ((traits == UndefinedPixelTrait) ||
5092 (destination_traits == UndefinedPixelTrait))
5094 if (source->alpha_trait != BlendPixelTrait)
5095 for (j=0; j < 4; j++)
5098 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
5101 for (j=0; j < 4; j++)
5103 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
5104 GetPixelChannels(source));
5105 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
5106 if (channel != AlphaPixelChannel)
5107 pixels[j]*=alpha[j];
5109 gamma=1.0; /* number of pixels blended together (its variable) */
5110 for (j=0; j <= 1L; j++)
5112 if ((y-y_offset) >= 0.75)
5114 alpha[j]=alpha[j+2]; /* take right pixels */
5115 pixels[j]=pixels[j+2];
5118 if ((y-y_offset) > 0.25)
5120 gamma=2.0; /* blend both pixels in row */
5121 alpha[j]+=alpha[j+2]; /* add up alpha weights */
5122 pixels[j]+=pixels[j+2];
5125 if ((x-x_offset) >= 0.75)
5127 alpha[0]=alpha[1]; /* take bottom row blend */
5128 pixels[0]=pixels[1];
5131 if ((x-x_offset) > 0.25)
5133 gamma*=2.0; /* blend both rows */
5134 alpha[0]+=alpha[1]; /* add up alpha weights */
5135 pixels[0]+=pixels[1];
5137 if (channel != AlphaPixelChannel)
5138 gamma=PerceptibleReciprocal(alpha[0]); /* (color) 1/alpha_weights */
5140 gamma=PerceptibleReciprocal(gamma); /* (alpha) 1/number_of_pixels */
5141 SetPixelChannel(destination,channel,ClampToQuantum(gamma*pixels[0]),
5146 case CatromInterpolatePixel:
5152 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
5154 if (p == (const Quantum *) NULL)
5159 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5164 PixelChannel channel = GetPixelChannelChannel(source,i);
5165 PixelTrait traits = GetPixelChannelTraits(source,channel);
5166 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5168 if ((traits == UndefinedPixelTrait) ||
5169 (destination_traits == UndefinedPixelTrait))
5171 if ((traits & BlendPixelTrait) == 0)
5172 for (j=0; j < 16; j++)
5175 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
5178 for (j=0; j < 16; j++)
5180 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
5181 GetPixelChannels(source));
5182 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
5184 CatromWeights((double) (x-x_offset),&cx);
5185 CatromWeights((double) (y-y_offset),&cy);
5186 gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
5187 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
5188 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
5189 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
5190 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
5191 cx[2]*alpha[14]+cx[3]*alpha[15])));
5192 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
5193 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
5194 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
5195 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
5196 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
5197 pixels[14]+cx[3]*pixels[15]))),pixel);
5201 case IntegerInterpolatePixel:
5203 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
5204 if (p == (const Quantum *) NULL)
5209 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5211 PixelChannel channel = GetPixelChannelChannel(source,i);
5212 PixelTrait traits = GetPixelChannelTraits(source,channel);
5213 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5215 if ((traits == UndefinedPixelTrait) ||
5216 (destination_traits == UndefinedPixelTrait))
5218 SetPixelChannel(destination,channel,p[i],pixel);
5222 case NearestInterpolatePixel:
5224 x_offset=(ssize_t) floor(x+0.5);
5225 y_offset=(ssize_t) floor(y+0.5);
5226 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
5227 if (p == (const Quantum *) NULL)
5232 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5234 PixelChannel channel = GetPixelChannelChannel(source,i);
5235 PixelTrait traits = GetPixelChannelTraits(source,channel);
5236 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5238 if ((traits == UndefinedPixelTrait) ||
5239 (destination_traits == UndefinedPixelTrait))
5241 SetPixelChannel(destination,channel,p[i],pixel);
5245 case MeshInterpolatePixel:
5247 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
5248 if (p == (const Quantum *) NULL)
5253 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5259 PixelChannel channel = GetPixelChannelChannel(source,i);
5260 PixelTrait traits = GetPixelChannelTraits(source,channel);
5261 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5263 if ((traits == UndefinedPixelTrait) ||
5264 (destination_traits == UndefinedPixelTrait))
5266 pixels[0]=(double) p[i];
5267 pixels[1]=(double) p[GetPixelChannels(source)+i];
5268 pixels[2]=(double) p[2*GetPixelChannels(source)+i];
5269 pixels[3]=(double) p[3*GetPixelChannels(source)+i];
5270 if ((traits & BlendPixelTrait) == 0)
5279 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
5280 alpha[1]=QuantumScale*GetPixelAlpha(source,p+
5281 GetPixelChannels(source));
5282 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
5283 GetPixelChannels(source));
5284 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
5285 GetPixelChannels(source));
5289 luminance.x=fabs((double) (GetPixelLuma(source,p)-
5290 GetPixelLuma(source,p+3*GetPixelChannels(source))));
5291 luminance.y=fabs((double) (GetPixelLuma(source,p+
5292 GetPixelChannels(source))-GetPixelLuma(source,p+2*
5293 GetPixelChannels(source))));
5294 if (luminance.x < luminance.y)
5299 if (delta.x <= delta.y)
5302 Bottom-left triangle (pixel: 2, diagonal: 0-3).
5304 delta.y=1.0-delta.y;
5305 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5306 gamma=PerceptibleReciprocal(gamma);
5307 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5308 MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel);
5313 Top-right triangle (pixel: 1, diagonal: 0-3).
5315 delta.x=1.0-delta.x;
5316 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5317 gamma=PerceptibleReciprocal(gamma);
5318 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5319 MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel);
5327 if (delta.x <= (1.0-delta.y))
5330 Top-left triangle (pixel: 0, diagonal: 1-2).
5332 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5333 gamma=PerceptibleReciprocal(gamma);
5334 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5335 MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel);
5340 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5342 delta.x=1.0-delta.x;
5343 delta.y=1.0-delta.y;
5344 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5345 gamma=PerceptibleReciprocal(gamma);
5346 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5347 MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel);
5353 case SplineInterpolatePixel:
5359 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
5361 if (p == (const Quantum *) NULL)
5366 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5371 PixelChannel channel = GetPixelChannelChannel(source,i);
5372 PixelTrait traits = GetPixelChannelTraits(source,channel);
5373 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5375 if ((traits == UndefinedPixelTrait) ||
5376 (destination_traits == UndefinedPixelTrait))
5378 if ((traits & BlendPixelTrait) == 0)
5379 for (j=0; j < 16; j++)
5382 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
5385 for (j=0; j < 16; j++)
5387 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
5388 GetPixelChannels(source));
5389 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
5391 SplineWeights((double) (x-x_offset),&cx);
5392 SplineWeights((double) (y-y_offset),&cy);
5393 gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
5394 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
5395 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
5396 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
5397 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
5398 cx[2]*alpha[14]+cx[3]*alpha[15])));
5399 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
5400 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
5401 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
5402 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
5403 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
5404 pixels[14]+cx[3]*pixels[15]))),pixel);
5413 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5417 % I n t e r p o l a t e P i x e l I n f o %
5421 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5423 % InterpolatePixelInfo() applies a pixel interpolation method between a
5424 % floating point coordinate and the pixels surrounding that coordinate. No
5425 % pixel area resampling, or scaling of the result is performed.
5427 % Interpolation is restricted to just RGBKA channels.
5429 % The format of the InterpolatePixelInfo method is:
5431 % MagickBooleanType InterpolatePixelInfo(const Image *image,
5432 % const CacheView *image_view,const PixelInterpolateMethod method,
5433 % const double x,const double y,PixelInfo *pixel,
5434 % ExceptionInfo *exception)
5436 % A description of each parameter follows:
5438 % o image: the image.
5440 % o image_view: the image view.
5442 % o method: the pixel color interpolation method.
5444 % o x,y: A double representing the current (x,y) position of the pixel.
5446 % o pixel: return the interpolated pixel here.
5448 % o exception: return any errors or warnings in this structure.
5452 static inline void AlphaBlendPixelInfo(const Image *image,
5453 const Quantum *pixel,PixelInfo *pixel_info,double *alpha)
5455 if (image->alpha_trait == UndefinedPixelTrait)
5458 pixel_info->red=(double) GetPixelRed(image,pixel);
5459 pixel_info->green=(double) GetPixelGreen(image,pixel);
5460 pixel_info->blue=(double) GetPixelBlue(image,pixel);
5461 pixel_info->black=0.0;
5462 if (image->colorspace == CMYKColorspace)
5463 pixel_info->black=(double) GetPixelBlack(image,pixel);
5464 pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5467 *alpha=QuantumScale*GetPixelAlpha(image,pixel);
5468 pixel_info->red=(*alpha*GetPixelRed(image,pixel));
5469 pixel_info->green=(*alpha*GetPixelGreen(image,pixel));
5470 pixel_info->blue=(*alpha*GetPixelBlue(image,pixel));
5471 pixel_info->black=0.0;
5472 if (image->colorspace == CMYKColorspace)
5473 pixel_info->black=(*alpha*GetPixelBlack(image,pixel));
5474 pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5477 MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
5478 const CacheView_ *image_view,const PixelInterpolateMethod method,
5479 const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception)
5491 register const Quantum
5501 PixelInterpolateMethod
5504 assert(image != (Image *) NULL);
5505 assert(image->signature == MagickCoreSignature);
5506 assert(image_view != (CacheView *) NULL);
5508 x_offset=(ssize_t) floor(x);
5509 y_offset=(ssize_t) floor(y);
5511 if (interpolate == UndefinedInterpolatePixel)
5512 interpolate=image->interpolate;
5513 GetPixelInfoPixel(image,(const Quantum *) NULL,pixel);
5514 (void) memset(&pixels,0,sizeof(pixels));
5515 switch (interpolate)
5517 case AverageInterpolatePixel: /* nearest 4 neighbours */
5518 case Average9InterpolatePixel: /* nearest 9 neighbours */
5519 case Average16InterpolatePixel: /* nearest 16 neighbours */
5524 count=2; /* size of the area to average - default nearest 4 */
5525 if (interpolate == Average9InterpolatePixel)
5528 x_offset=(ssize_t) (floor(x+0.5)-1);
5529 y_offset=(ssize_t) (floor(y+0.5)-1);
5531 else if (interpolate == Average16InterpolatePixel)
5537 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,(size_t) count,
5538 (size_t) count,exception);
5539 if (p == (const Quantum *) NULL)
5544 count*=count; /* number of pixels - square of size */
5545 for (i=0; i < (ssize_t) count; i++)
5547 AlphaBlendPixelInfo(image,p,pixels,alpha);
5548 gamma=PerceptibleReciprocal(alpha[0]);
5549 pixel->red+=gamma*pixels[0].red;
5550 pixel->green+=gamma*pixels[0].green;
5551 pixel->blue+=gamma*pixels[0].blue;
5552 pixel->black+=gamma*pixels[0].black;
5553 pixel->alpha+=pixels[0].alpha;
5554 p += GetPixelChannels(image);
5556 gamma=1.0/count; /* average weighting of each pixel in area */
5558 pixel->green*=gamma;
5560 pixel->black*=gamma;
5561 pixel->alpha*=gamma;
5564 case BackgroundInterpolatePixel:
5566 *pixel=image->background_color; /* Copy PixelInfo Structure */
5569 case BilinearInterpolatePixel:
5576 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5577 if (p == (const Quantum *) NULL)
5582 for (i=0; i < 4L; i++)
5583 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5586 epsilon.x=1.0-delta.x;
5587 epsilon.y=1.0-delta.y;
5588 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5589 (epsilon.x*alpha[2]+delta.x*alpha[3])));
5590 gamma=PerceptibleReciprocal(gamma);
5591 pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
5592 pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red));
5593 pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x*
5594 pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x*
5596 pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x*
5597 pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x*
5599 if (image->colorspace == CMYKColorspace)
5600 pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x*
5601 pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x*
5603 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5604 gamma=PerceptibleReciprocal(gamma);
5605 pixel->alpha=gamma*(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x*
5606 pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x*
5610 case BlendInterpolatePixel:
5612 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5613 if (p == (const Quantum *) NULL)
5618 for (i=0; i < 4L; i++)
5620 GetPixelInfoPixel(image,p+i*GetPixelChannels(image),pixels+i);
5621 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5623 gamma=1.0; /* number of pixels blended together (its variable) */
5624 for (i=0; i <= 1L; i++)
5626 if ((y-y_offset) >= 0.75)
5628 alpha[i]=alpha[i+2]; /* take right pixels */
5629 pixels[i]=pixels[i+2];
5632 if ((y-y_offset) > 0.25)
5634 gamma=2.0; /* blend both pixels in row */
5635 alpha[i]+=alpha[i+2]; /* add up alpha weights */
5636 pixels[i].red+=pixels[i+2].red;
5637 pixels[i].green+=pixels[i+2].green;
5638 pixels[i].blue+=pixels[i+2].blue;
5639 pixels[i].black+=pixels[i+2].black;
5640 pixels[i].alpha+=pixels[i+2].alpha;
5643 if ((x-x_offset) >= 0.75)
5646 pixels[0]=pixels[1];
5649 if ((x-x_offset) > 0.25)
5651 gamma*=2.0; /* blend both rows */
5652 alpha[0]+= alpha[1]; /* add up alpha weights */
5653 pixels[0].red+=pixels[1].red;
5654 pixels[0].green+=pixels[1].green;
5655 pixels[0].blue+=pixels[1].blue;
5656 pixels[0].black+=pixels[1].black;
5657 pixels[0].alpha+=pixels[1].alpha;
5660 alpha[0]=PerceptibleReciprocal(alpha[0]);
5661 pixel->red=alpha[0]*pixels[0].red;
5662 pixel->green=alpha[0]*pixels[0].green; /* divide by sum of alpha */
5663 pixel->blue=alpha[0]*pixels[0].blue;
5664 pixel->black=alpha[0]*pixels[0].black;
5665 pixel->alpha=gamma*pixels[0].alpha; /* divide by number of pixels */
5668 case CatromInterpolatePixel:
5674 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5676 if (p == (const Quantum *) NULL)
5681 for (i=0; i < 16L; i++)
5682 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5683 CatromWeights((double) (x-x_offset),&cx);
5684 CatromWeights((double) (y-y_offset),&cy);
5685 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]*
5686 pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5687 pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]*
5688 pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5689 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]*
5690 pixels[14].red+cx[3]*pixels[15].red));
5691 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]*
5692 pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+
5693 cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+
5694 cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]*
5695 pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]*
5696 pixels[12].green+cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]*
5698 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]*
5699 pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5700 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]*
5701 pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5702 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+
5703 cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5704 if (image->colorspace == CMYKColorspace)
5705 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]*
5706 pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+
5707 cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+
5708 cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]*
5709 pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]*
5710 pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]*
5712 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]*
5713 pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+
5714 cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+
5715 cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]*
5716 pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+
5717 cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5720 case IntegerInterpolatePixel:
5722 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5723 if (p == (const Quantum *) NULL)
5728 GetPixelInfoPixel(image,p,pixel);
5731 case MeshInterpolatePixel:
5737 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5738 if (p == (const Quantum *) NULL)
5745 luminance.x=GetPixelLuma(image,p)-(double)
5746 GetPixelLuma(image,p+3*GetPixelChannels(image));
5747 luminance.y=GetPixelLuma(image,p+GetPixelChannels(image))-(double)
5748 GetPixelLuma(image,p+2*GetPixelChannels(image));
5749 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5750 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5751 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5752 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5753 if (fabs(luminance.x) < fabs(luminance.y))
5758 if (delta.x <= delta.y)
5761 Bottom-left triangle (pixel: 2, diagonal: 0-3).
5763 delta.y=1.0-delta.y;
5764 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5765 gamma=PerceptibleReciprocal(gamma);
5766 pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red,
5767 pixels[3].red,pixels[0].red);
5768 pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green,
5769 pixels[3].green,pixels[0].green);
5770 pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
5771 pixels[3].blue,pixels[0].blue);
5772 if (image->colorspace == CMYKColorspace)
5773 pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black,
5774 pixels[3].black,pixels[0].black);
5775 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5776 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha,
5777 pixels[3].alpha,pixels[0].alpha);
5782 Top-right triangle (pixel:1 , diagonal: 0-3).
5784 delta.x=1.0-delta.x;
5785 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5786 gamma=PerceptibleReciprocal(gamma);
5787 pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red,
5788 pixels[0].red,pixels[3].red);
5789 pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green,
5790 pixels[0].green,pixels[3].green);
5791 pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
5792 pixels[0].blue,pixels[3].blue);
5793 if (image->colorspace == CMYKColorspace)
5794 pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black,
5795 pixels[0].black,pixels[3].black);
5796 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5797 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha,
5798 pixels[0].alpha,pixels[3].alpha);
5806 if (delta.x <= (1.0-delta.y))
5809 Top-left triangle (pixel: 0, diagonal: 1-2).
5811 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5812 gamma=PerceptibleReciprocal(gamma);
5813 pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red,
5814 pixels[1].red,pixels[2].red);
5815 pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green,
5816 pixels[1].green,pixels[2].green);
5817 pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
5818 pixels[1].blue,pixels[2].blue);
5819 if (image->colorspace == CMYKColorspace)
5820 pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black,
5821 pixels[1].black,pixels[2].black);
5822 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5823 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha,
5824 pixels[1].alpha,pixels[2].alpha);
5829 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5831 delta.x=1.0-delta.x;
5832 delta.y=1.0-delta.y;
5833 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5834 gamma=PerceptibleReciprocal(gamma);
5835 pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red,
5836 pixels[2].red,pixels[1].red);
5837 pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green,
5838 pixels[2].green,pixels[1].green);
5839 pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
5840 pixels[2].blue,pixels[1].blue);
5841 if (image->colorspace == CMYKColorspace)
5842 pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black,
5843 pixels[2].black,pixels[1].black);
5844 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5845 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha,
5846 pixels[2].alpha,pixels[1].alpha);
5851 case NearestInterpolatePixel:
5853 x_offset=(ssize_t) floor(x+0.5);
5854 y_offset=(ssize_t) floor(y+0.5);
5855 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5856 if (p == (const Quantum *) NULL)
5861 GetPixelInfoPixel(image,p,pixel);
5864 case SplineInterpolatePixel:
5870 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5872 if (p == (const Quantum *) NULL)
5877 for (i=0; i < 16L; i++)
5878 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5879 SplineWeights((double) (x-x_offset),&cx);
5880 SplineWeights((double) (y-y_offset),&cy);
5881 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]*
5882 pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5883 pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]*
5884 pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5885 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]*
5886 pixels[14].red+cx[3]*pixels[15].red));
5887 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]*
5888 pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+
5889 cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+
5890 cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]*
5891 pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]*pixels[12].green+
5892 cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]*pixels[15].green));
5893 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]*
5894 pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5895 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]*
5896 pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5897 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+
5898 cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5899 if (image->colorspace == CMYKColorspace)
5900 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]*
5901 pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+
5902 cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+
5903 cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]*
5904 pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]*
5905 pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]*
5907 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]*
5908 pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+
5909 cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+
5910 cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]*
5911 pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+
5912 cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5920 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5924 + I s F u z z y E q u i v a l e n c e P i x e l %
5928 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5930 % IsFuzzyEquivalencePixel() returns MagickTrue if the distance between two
5931 % pixels is less than the specified distance in a linear three (or four)
5932 % dimensional color space.
5934 % The format of the IsFuzzyEquivalencePixel method is:
5936 % void IsFuzzyEquivalencePixel(const Image *source,const Quantum *p,
5937 % const Image *destination,const Quantum *q)
5939 % A description of each parameter follows:
5941 % o source: the source image.
5945 % o destination: the destination image.
5950 MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *source,
5951 const Quantum *p,const Image *destination,const Quantum *q)
5961 fuzz=GetFuzzyColorDistance(source,destination);
5964 if (source->alpha_trait != UndefinedPixelTrait ||
5965 destination->alpha_trait != UndefinedPixelTrait)
5968 Transparencies are involved - set alpha distance
5970 pixel=GetPixelAlpha(source,p)-(double) GetPixelAlpha(destination,q);
5971 distance=pixel*pixel;
5972 if (distance > fuzz)
5973 return(MagickFalse);
5975 Generate a alpha scaling factor to generate a 4D cone on colorspace
5976 Note that if one color is transparent, distance has no color component.
5978 if (source->alpha_trait != UndefinedPixelTrait)
5979 scale=QuantumScale*GetPixelAlpha(source,p);
5980 if (destination->alpha_trait != UndefinedPixelTrait)
5981 scale*=QuantumScale*GetPixelAlpha(destination,q);
5982 if (scale <= MagickEpsilon)
5986 RGB or CMY color cube
5988 distance*=3.0; /* rescale appropriately */
5990 pixel=GetPixelRed(source,p)-(double) GetPixelRed(destination,q);
5991 if ((source->colorspace == HSLColorspace) ||
5992 (source->colorspace == HSBColorspace) ||
5993 (source->colorspace == HWBColorspace))
5996 Compute an arc distance for hue. It should be a vector angle of
5997 'S'/'W' length with 'L'/'B' forming appropriate cones.
5999 if (fabs((double) pixel) > (QuantumRange/2))
6000 pixel-=QuantumRange;
6003 distance+=scale*pixel*pixel;
6004 if (distance > fuzz)
6005 return(MagickFalse);
6006 pixel=GetPixelGreen(source,p)-(double) GetPixelGreen(destination,q);
6007 distance+=scale*pixel*pixel;
6008 if (distance > fuzz)
6009 return(MagickFalse);
6010 pixel=GetPixelBlue(source,p)-(double) GetPixelBlue(destination,q);
6011 distance+=scale*pixel*pixel;
6012 if (distance > fuzz)
6013 return(MagickFalse);
6018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6022 + I s F u z z y E q u i v a l e n c e P i x e l I n f o %
6026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6028 % IsFuzzyEquivalencePixelInfo() returns true if the distance between two
6029 % colors is less than the specified distance in a linear three (or four)
6030 % dimensional color space.
6032 % This implements the equivalent of:
6033 % fuzz < sqrt(color_distance^2 * u.a*v.a + alpha_distance^2)
6035 % Which produces a multi-dimensional cone for that colorspace along the
6036 % transparency vector.
6038 % For example for an RGB:
6039 % color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3
6041 % See http://imagemagick.org/Usage/bugs/fuzz_distance/
6043 % Hue colorspace distances need more work. Hue is not a distance, it is an
6046 % A check that q is in the same color space as p should be made and the
6047 % appropriate mapping made. -- Anthony Thyssen 8 December 2010
6049 % The format of the IsFuzzyEquivalencePixelInfo method is:
6051 % MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
6052 % const PixelInfo *q)
6054 % A description of each parameter follows:
6061 MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
6072 fuzz=(double) MagickMax(MagickMax(p->fuzz,q->fuzz),(MagickRealType)
6077 if ((p->alpha_trait != UndefinedPixelTrait) ||
6078 (q->alpha_trait != UndefinedPixelTrait))
6081 Transparencies are involved - set alpha distance.
6083 pixel=(p->alpha_trait != UndefinedPixelTrait ? p->alpha : OpaqueAlpha)-
6084 (q->alpha_trait != UndefinedPixelTrait ? q->alpha : OpaqueAlpha);
6085 distance=pixel*pixel;
6086 if (distance > fuzz)
6087 return(MagickFalse);
6089 Generate a alpha scaling factor to generate a 4D cone on colorspace.
6090 If one color is transparent, distance has no color component.
6092 if (p->alpha_trait != UndefinedPixelTrait)
6093 scale=(QuantumScale*p->alpha);
6094 if (q->alpha_trait != UndefinedPixelTrait)
6095 scale*=(QuantumScale*q->alpha);
6096 if (scale <= MagickEpsilon )
6100 CMYK create a CMY cube with a multi-dimensional cone toward black.
6102 if (p->colorspace == CMYKColorspace)
6104 pixel=p->black-q->black;
6105 distance+=pixel*pixel*scale;
6106 if (distance > fuzz)
6107 return(MagickFalse);
6108 scale*=(double) (QuantumScale*(QuantumRange-p->black));
6109 scale*=(double) (QuantumScale*(QuantumRange-q->black));
6112 RGB or CMY color cube.
6114 distance*=3.0; /* rescale appropriately */
6116 pixel=p->red-q->red;
6117 if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) ||
6118 (p->colorspace == HWBColorspace))
6121 This calculates a arc distance for hue-- it should be a vector
6122 angle of 'S'/'W' length with 'L'/'B' forming appropriate cones.
6123 In other words this is a hack - Anthony.
6125 if (fabs((double) pixel) > (QuantumRange/2))
6126 pixel-=QuantumRange;
6129 distance+=pixel*pixel*scale;
6130 if (distance > fuzz)
6131 return(MagickFalse);
6132 pixel=p->green-q->green;
6133 distance+=pixel*pixel*scale;
6134 if (distance > fuzz)
6135 return(MagickFalse);
6136 pixel=p->blue-q->blue;
6137 distance+=pixel*pixel*scale;
6138 if (distance > fuzz)
6139 return(MagickFalse);
6144 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6148 % S e t P i x e l C h a n n e l M a s k %
6152 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6154 % SetPixelChannelMask() sets the pixel channel map from the specified channel
6157 % The format of the SetPixelChannelMask method is:
6159 % ChannelType SetPixelChannelMask(Image *image,
6160 % const ChannelType channel_mask)
6162 % A description of each parameter follows:
6164 % o image: the image.
6166 % o channel_mask: the channel mask.
6170 static void LogPixelChannels(const Image *image)
6175 (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%08x]",
6176 image->filename,image->channel_mask);
6177 for (i=0; i < (ssize_t) image->number_channels; i++)
6180 channel_name[MagickPathExtent],
6181 traits[MagickPathExtent];
6189 channel=GetPixelChannelChannel(image,i);
6192 case RedPixelChannel:
6195 if (image->colorspace == CMYKColorspace)
6197 if ((image->colorspace == LinearGRAYColorspace) ||
6198 (image->colorspace == GRAYColorspace))
6202 case GreenPixelChannel:
6205 if (image->colorspace == CMYKColorspace)
6209 case BluePixelChannel:
6212 if (image->colorspace == CMYKColorspace)
6216 case BlackPixelChannel:
6219 if (image->storage_class == PseudoClass)
6223 case IndexPixelChannel:
6228 case AlphaPixelChannel:
6233 case ReadMaskPixelChannel:
6238 case WriteMaskPixelChannel:
6243 case CompositeMaskPixelChannel:
6245 name="composite-mask";
6248 case MetaPixelChannel:
6256 if (image->colorspace == UndefinedColorspace)
6258 (void) FormatLocaleString(channel_name,MagickPathExtent,"%.20g",
6260 name=(const char *) channel_name;
6263 if ((GetPixelChannelTraits(image,channel) & UpdatePixelTrait) != 0)
6264 (void) ConcatenateMagickString(traits,"update,",MagickPathExtent);
6265 if ((GetPixelChannelTraits(image,channel) & BlendPixelTrait) != 0)
6266 (void) ConcatenateMagickString(traits,"blend,",MagickPathExtent);
6267 if ((GetPixelChannelTraits(image,channel) & CopyPixelTrait) != 0)
6268 (void) ConcatenateMagickString(traits,"copy,",MagickPathExtent);
6269 if (*traits == '\0')
6270 (void) ConcatenateMagickString(traits,"undefined,",MagickPathExtent);
6271 traits[strlen(traits)-1]='\0';
6272 (void) LogMagickEvent(PixelEvent,GetMagickModule()," %.20g: %s (%s)",
6273 (double) i,name,traits);
6277 MagickExport ChannelType SetPixelChannelMask(Image *image,
6278 const ChannelType channel_mask)
6280 #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
6288 assert(image != (Image *) NULL);
6289 assert(image->signature == MagickCoreSignature);
6290 if (image->debug != MagickFalse)
6291 (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%08x]",
6292 image->filename,channel_mask);
6293 mask=image->channel_mask;
6294 image->channel_mask=channel_mask;
6295 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
6297 PixelChannel channel = GetPixelChannelChannel(image,i);
6298 if (GetChannelBit(channel_mask,channel) == 0)
6300 SetPixelChannelTraits(image,channel,CopyPixelTrait);
6303 if (channel == AlphaPixelChannel)
6305 if ((image->alpha_trait & CopyPixelTrait) != 0)
6307 SetPixelChannelTraits(image,channel,CopyPixelTrait);
6310 SetPixelChannelTraits(image,channel,UpdatePixelTrait);
6313 if (image->alpha_trait != UndefinedPixelTrait)
6315 SetPixelChannelTraits(image,channel,(const PixelTrait)
6316 (UpdatePixelTrait | BlendPixelTrait));
6319 SetPixelChannelTraits(image,channel,UpdatePixelTrait);
6321 if (image->storage_class == PseudoClass)
6322 SetPixelChannelTraits(image,IndexPixelChannel,CopyPixelTrait);
6323 if ((image->channels & ReadMaskChannel) != 0)
6324 SetPixelChannelTraits(image,ReadMaskPixelChannel,CopyPixelTrait);
6325 if ((image->channels & WriteMaskChannel) != 0)
6326 SetPixelChannelTraits(image,WriteMaskPixelChannel,CopyPixelTrait);
6327 if ((image->channels & CompositeMaskChannel) != 0)
6328 SetPixelChannelTraits(image,CompositeMaskPixelChannel,CopyPixelTrait);
6329 if (image->debug != MagickFalse)
6330 LogPixelChannels(image);
6335 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6339 % S e t P i x e l M e t a C h a n n e l s %
6343 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6345 % SetPixelMetaChannels() sets the image meta channels.
6347 % The format of the SetPixelMetaChannels method is:
6349 % MagickBooleanType SetPixelMetaChannels(Image *image,
6350 % const size_t number_meta_channels,ExceptionInfo *exception)
6352 % A description of each parameter follows:
6354 % o image: the image.
6356 % o number_meta_channels: the number of meta channels.
6358 % o exception: return any errors or warnings in this structure.
6361 MagickExport MagickBooleanType SetPixelMetaChannels(Image *image,
6362 const size_t number_meta_channels,ExceptionInfo *exception)
6364 image->number_meta_channels=number_meta_channels;
6365 InitializePixelChannelMap(image);
6366 return(SyncImagePixelCache(image,exception));