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-2017 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://www.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) ResetMagickMemory(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) CopyMagickMemory(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 void ExportCharPixel(const Image *image,const RectangleInfo *roi,
510 const char *magick_restrict map,const QuantumType *quantum_map,void *pixels,
511 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);
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);
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);
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);
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);
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);
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);
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);
715 static void ExportDoublePixel(const Image *image,const RectangleInfo *roi,
716 const char *magick_restrict map,const QuantumType *quantum_map,void *pixels,
717 ExceptionInfo *exception)
719 register const Quantum
735 if (LocaleCompare(map,"BGR") == 0)
737 for (y=0; y < (ssize_t) roi->height; y++)
739 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
740 if (p == (const Quantum *) NULL)
742 for (x=0; x < (ssize_t) roi->width; x++)
744 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
745 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
746 *q++=(double) (QuantumScale*GetPixelRed(image,p));
747 p+=GetPixelChannels(image);
752 if (LocaleCompare(map,"BGRA") == 0)
754 for (y=0; y < (ssize_t) roi->height; y++)
756 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
757 if (p == (const Quantum *) NULL)
759 for (x=0; x < (ssize_t) roi->width; x++)
761 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
762 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
763 *q++=(double) (QuantumScale*GetPixelRed(image,p));
764 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
765 p+=GetPixelChannels(image);
770 if (LocaleCompare(map,"BGRP") == 0)
772 for (y=0; y < (ssize_t) roi->height; y++)
774 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
775 if (p == (const Quantum *) NULL)
777 for (x=0; x < (ssize_t) roi->width; x++)
779 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
780 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
781 *q++=(double) (QuantumScale*GetPixelRed(image,p));
783 p+=GetPixelChannels(image);
788 if (LocaleCompare(map,"I") == 0)
790 for (y=0; y < (ssize_t) roi->height; y++)
792 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
793 if (p == (const Quantum *) NULL)
795 for (x=0; x < (ssize_t) roi->width; x++)
797 *q++=(double) (QuantumScale*GetPixelIntensity(image,p));
798 p+=GetPixelChannels(image);
803 if (LocaleCompare(map,"RGB") == 0)
805 for (y=0; y < (ssize_t) roi->height; y++)
807 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
808 if (p == (const Quantum *) NULL)
810 for (x=0; x < (ssize_t) roi->width; x++)
812 *q++=(double) (QuantumScale*GetPixelRed(image,p));
813 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
814 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
815 p+=GetPixelChannels(image);
820 if (LocaleCompare(map,"RGBA") == 0)
822 for (y=0; y < (ssize_t) roi->height; y++)
824 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
825 if (p == (const Quantum *) NULL)
827 for (x=0; x < (ssize_t) roi->width; x++)
829 *q++=(double) (QuantumScale*GetPixelRed(image,p));
830 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
831 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
832 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
833 p+=GetPixelChannels(image);
838 if (LocaleCompare(map,"RGBP") == 0)
840 for (y=0; y < (ssize_t) roi->height; y++)
842 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
843 if (p == (const Quantum *) NULL)
845 for (x=0; x < (ssize_t) roi->width; x++)
847 *q++=(double) (QuantumScale*GetPixelRed(image,p));
848 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
849 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
851 p+=GetPixelChannels(image);
857 for (y=0; y < (ssize_t) roi->height; y++)
859 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
860 if (p == (const Quantum *) NULL)
862 for (x=0; x < (ssize_t) roi->width; x++)
867 for (i=0; i < (ssize_t) length; i++)
870 switch (quantum_map[i])
875 *q=(double) (QuantumScale*GetPixelRed(image,p));
881 *q=(double) (QuantumScale*GetPixelGreen(image,p));
887 *q=(double) (QuantumScale*GetPixelBlue(image,p));
892 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
897 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
902 if (image->colorspace == CMYKColorspace)
903 *q=(double) (QuantumScale*
904 GetPixelBlack(image,p));
909 *q=(double) (QuantumScale*GetPixelIntensity(image,p));
917 p+=GetPixelChannels(image);
922 static void ExportFloatPixel(const Image *image,const RectangleInfo *roi,
923 const char *magick_restrict map,const QuantumType *quantum_map,void *pixels,
924 ExceptionInfo *exception)
926 register const Quantum
942 if (LocaleCompare(map,"BGR") == 0)
944 for (y=0; y < (ssize_t) roi->height; y++)
946 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
947 if (p == (const Quantum *) NULL)
949 for (x=0; x < (ssize_t) roi->width; x++)
951 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
952 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
953 *q++=(float) (QuantumScale*GetPixelRed(image,p));
954 p+=GetPixelChannels(image);
959 if (LocaleCompare(map,"BGRA") == 0)
961 for (y=0; y < (ssize_t) roi->height; y++)
963 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
964 if (p == (const Quantum *) NULL)
966 for (x=0; x < (ssize_t) roi->width; x++)
968 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
969 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
970 *q++=(float) (QuantumScale*GetPixelRed(image,p));
971 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
972 p+=GetPixelChannels(image);
977 if (LocaleCompare(map,"BGRP") == 0)
979 for (y=0; y < (ssize_t) roi->height; y++)
981 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
982 if (p == (const Quantum *) NULL)
984 for (x=0; x < (ssize_t) roi->width; x++)
986 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
987 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
988 *q++=(float) (QuantumScale*GetPixelRed(image,p));
990 p+=GetPixelChannels(image);
995 if (LocaleCompare(map,"I") == 0)
997 for (y=0; y < (ssize_t) roi->height; y++)
999 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1000 if (p == (const Quantum *) NULL)
1002 for (x=0; x < (ssize_t) roi->width; x++)
1004 *q++=(float) (QuantumScale*GetPixelIntensity(image,p));
1005 p+=GetPixelChannels(image);
1010 if (LocaleCompare(map,"RGB") == 0)
1012 for (y=0; y < (ssize_t) roi->height; y++)
1014 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1015 if (p == (const Quantum *) NULL)
1017 for (x=0; x < (ssize_t) roi->width; x++)
1019 *q++=(float) (QuantumScale*GetPixelRed(image,p));
1020 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
1021 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
1022 p+=GetPixelChannels(image);
1027 if (LocaleCompare(map,"RGBA") == 0)
1029 for (y=0; y < (ssize_t) roi->height; y++)
1031 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1032 if (p == (const Quantum *) NULL)
1034 for (x=0; x < (ssize_t) roi->width; x++)
1036 *q++=(float) (QuantumScale*GetPixelRed(image,p));
1037 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
1038 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
1039 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
1040 p+=GetPixelChannels(image);
1045 if (LocaleCompare(map,"RGBP") == 0)
1047 for (y=0; y < (ssize_t) roi->height; y++)
1049 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1050 if (p == (const Quantum *) NULL)
1052 for (x=0; x < (ssize_t) roi->width; x++)
1054 *q++=(float) (QuantumScale*GetPixelRed(image,p));
1055 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
1056 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
1058 p+=GetPixelChannels(image);
1064 for (y=0; y < (ssize_t) roi->height; y++)
1066 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1067 if (p == (const Quantum *) NULL)
1069 for (x=0; x < (ssize_t) roi->width; x++)
1074 for (i=0; i < (ssize_t) length; i++)
1077 switch (quantum_map[i])
1082 *q=(float) (QuantumScale*GetPixelRed(image,p));
1086 case MagentaQuantum:
1088 *q=(float) (QuantumScale*GetPixelGreen(image,p));
1094 *q=(float) (QuantumScale*GetPixelBlue(image,p));
1099 *q=(float) (QuantumScale*((Quantum) (GetPixelAlpha(image,p))));
1102 case OpacityQuantum:
1104 *q=(float) (QuantumScale*GetPixelAlpha(image,p));
1109 if (image->colorspace == CMYKColorspace)
1110 *q=(float) (QuantumScale* GetPixelBlack(image,p));
1115 *q=(float) (QuantumScale*GetPixelIntensity(image,p));
1123 p+=GetPixelChannels(image);
1128 static void ExportLongPixel(const Image *image,const RectangleInfo *roi,
1129 const char *magick_restrict map,const QuantumType *quantum_map,void *pixels,
1130 ExceptionInfo *exception)
1132 register const Quantum
1138 register unsigned int
1147 q=(unsigned int *) pixels;
1148 if (LocaleCompare(map,"BGR") == 0)
1150 for (y=0; y < (ssize_t) roi->height; y++)
1152 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1153 if (p == (const Quantum *) NULL)
1155 for (x=0; x < (ssize_t) roi->width; x++)
1157 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1158 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1159 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1160 p+=GetPixelChannels(image);
1165 if (LocaleCompare(map,"BGRA") == 0)
1167 for (y=0; y < (ssize_t) roi->height; y++)
1169 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1170 if (p == (const Quantum *) NULL)
1172 for (x=0; x < (ssize_t) roi->width; x++)
1174 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1175 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1176 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1177 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1178 p+=GetPixelChannels(image);
1183 if (LocaleCompare(map,"BGRP") == 0)
1185 for (y=0; y < (ssize_t) roi->height; y++)
1187 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1188 if (p == (const Quantum *) NULL)
1190 for (x=0; x < (ssize_t) roi->width; x++)
1192 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1193 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1194 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1196 p+=GetPixelChannels(image);
1201 if (LocaleCompare(map,"I") == 0)
1203 for (y=0; y < (ssize_t) roi->height; y++)
1205 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1206 if (p == (const Quantum *) NULL)
1208 for (x=0; x < (ssize_t) roi->width; x++)
1210 *q++=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
1211 p+=GetPixelChannels(image);
1216 if (LocaleCompare(map,"RGB") == 0)
1218 for (y=0; y < (ssize_t) roi->height; y++)
1220 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1221 if (p == (const Quantum *) NULL)
1223 for (x=0; x < (ssize_t) roi->width; x++)
1225 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1226 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1227 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1228 p+=GetPixelChannels(image);
1233 if (LocaleCompare(map,"RGBA") == 0)
1235 for (y=0; y < (ssize_t) roi->height; y++)
1237 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1238 if (p == (const Quantum *) NULL)
1240 for (x=0; x < (ssize_t) roi->width; x++)
1242 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1243 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1244 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1245 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1246 p+=GetPixelChannels(image);
1251 if (LocaleCompare(map,"RGBP") == 0)
1253 for (y=0; y < (ssize_t) roi->height; y++)
1255 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1256 if (p == (const Quantum *) NULL)
1258 for (x=0; x < (ssize_t) roi->width; x++)
1260 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1261 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1262 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1264 p+=GetPixelChannels(image);
1270 for (y=0; y < (ssize_t) roi->height; y++)
1272 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1273 if (p == (const Quantum *) NULL)
1275 for (x=0; x < (ssize_t) roi->width; x++)
1280 for (i=0; i < (ssize_t) length; i++)
1283 switch (quantum_map[i])
1288 *q=ScaleQuantumToLong(GetPixelRed(image,p));
1292 case MagentaQuantum:
1294 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
1300 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
1305 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1308 case OpacityQuantum:
1310 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1315 if (image->colorspace == CMYKColorspace)
1316 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
1321 *q=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
1329 p+=GetPixelChannels(image);
1334 static void ExportLongLongPixel(const Image *image,const RectangleInfo *roi,
1335 const char *magick_restrict map,const QuantumType *quantum_map,void *pixels,
1336 ExceptionInfo *exception)
1338 register const Quantum
1344 register MagickSizeType
1353 q=(MagickSizeType *) pixels;
1354 if (LocaleCompare(map,"BGR") == 0)
1356 for (y=0; y < (ssize_t) roi->height; y++)
1358 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1359 if (p == (const Quantum *) NULL)
1361 for (x=0; x < (ssize_t) roi->width; x++)
1363 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1364 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1365 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1366 p+=GetPixelChannels(image);
1371 if (LocaleCompare(map,"BGRA") == 0)
1373 for (y=0; y < (ssize_t) roi->height; y++)
1375 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1376 if (p == (const Quantum *) NULL)
1378 for (x=0; x < (ssize_t) roi->width; x++)
1380 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1381 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1382 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1383 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1384 p+=GetPixelChannels(image);
1389 if (LocaleCompare(map,"BGRP") == 0)
1391 for (y=0; y < (ssize_t) roi->height; y++)
1393 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1394 if (p == (const Quantum *) NULL)
1396 for (x=0; x < (ssize_t) roi->width; x++)
1398 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1399 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1400 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1402 p+=GetPixelChannels(image);
1407 if (LocaleCompare(map,"I") == 0)
1409 for (y=0; y < (ssize_t) roi->height; y++)
1411 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1412 if (p == (const Quantum *) NULL)
1414 for (x=0; x < (ssize_t) roi->width; x++)
1416 *q++=ScaleQuantumToLongLong(ClampToQuantum(
1417 GetPixelIntensity(image,p)));
1418 p+=GetPixelChannels(image);
1423 if (LocaleCompare(map,"RGB") == 0)
1425 for (y=0; y < (ssize_t) roi->height; y++)
1427 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1428 if (p == (const Quantum *) NULL)
1430 for (x=0; x < (ssize_t) roi->width; x++)
1432 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1433 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1434 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1435 p+=GetPixelChannels(image);
1440 if (LocaleCompare(map,"RGBA") == 0)
1442 for (y=0; y < (ssize_t) roi->height; y++)
1444 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1445 if (p == (const Quantum *) NULL)
1447 for (x=0; x < (ssize_t) roi->width; x++)
1449 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1450 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1451 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1452 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1453 p+=GetPixelChannels(image);
1458 if (LocaleCompare(map,"RGBP") == 0)
1460 for (y=0; y < (ssize_t) roi->height; y++)
1462 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1463 if (p == (const Quantum *) NULL)
1465 for (x=0; x < (ssize_t) roi->width; x++)
1467 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1468 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1469 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1471 p+=GetPixelChannels(image);
1477 for (y=0; y < (ssize_t) roi->height; y++)
1479 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1480 if (p == (const Quantum *) NULL)
1482 for (x=0; x < (ssize_t) roi->width; x++)
1487 for (i=0; i < (ssize_t) length; i++)
1490 switch (quantum_map[i])
1495 *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
1499 case MagentaQuantum:
1501 *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1507 *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1512 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1515 case OpacityQuantum:
1517 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1522 if (image->colorspace == CMYKColorspace)
1523 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
1528 *q=ScaleQuantumToLongLong(ClampToQuantum(
1529 GetPixelIntensity(image,p)));
1537 p+=GetPixelChannels(image);
1542 static void ExportQuantumPixel(const Image *image,const RectangleInfo *roi,
1543 const char *magick_restrict map,const QuantumType *quantum_map,void *pixels,
1544 ExceptionInfo *exception)
1546 register const Quantum
1561 q=(Quantum *) pixels;
1562 if (LocaleCompare(map,"BGR") == 0)
1564 for (y=0; y < (ssize_t) roi->height; y++)
1566 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1567 if (p == (const Quantum *) NULL)
1569 for (x=0; x < (ssize_t) roi->width; x++)
1571 *q++=GetPixelBlue(image,p);
1572 *q++=GetPixelGreen(image,p);
1573 *q++=GetPixelRed(image,p);
1574 p+=GetPixelChannels(image);
1579 if (LocaleCompare(map,"BGRA") == 0)
1581 for (y=0; y < (ssize_t) roi->height; y++)
1583 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1584 if (p == (const Quantum *) NULL)
1586 for (x=0; x < (ssize_t) roi->width; x++)
1588 *q++=GetPixelBlue(image,p);
1589 *q++=GetPixelGreen(image,p);
1590 *q++=GetPixelRed(image,p);
1591 *q++=(Quantum) (GetPixelAlpha(image,p));
1592 p+=GetPixelChannels(image);
1597 if (LocaleCompare(map,"BGRP") == 0)
1599 for (y=0; y < (ssize_t) roi->height; y++)
1601 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1602 if (p == (const Quantum *) NULL)
1604 for (x=0; x < (ssize_t) roi->width; x++)
1606 *q++=GetPixelBlue(image,p);
1607 *q++=GetPixelGreen(image,p);
1608 *q++=GetPixelRed(image,p);
1610 p+=GetPixelChannels(image);
1615 if (LocaleCompare(map,"I") == 0)
1617 for (y=0; y < (ssize_t) roi->height; y++)
1619 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1620 if (p == (const Quantum *) NULL)
1622 for (x=0; x < (ssize_t) roi->width; x++)
1624 *q++=ClampToQuantum(GetPixelIntensity(image,p));
1625 p+=GetPixelChannels(image);
1630 if (LocaleCompare(map,"RGB") == 0)
1632 for (y=0; y < (ssize_t) roi->height; y++)
1634 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1635 if (p == (const Quantum *) NULL)
1637 for (x=0; x < (ssize_t) roi->width; x++)
1639 *q++=GetPixelRed(image,p);
1640 *q++=GetPixelGreen(image,p);
1641 *q++=GetPixelBlue(image,p);
1642 p+=GetPixelChannels(image);
1647 if (LocaleCompare(map,"RGBA") == 0)
1649 for (y=0; y < (ssize_t) roi->height; y++)
1651 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1652 if (p == (const Quantum *) NULL)
1654 for (x=0; x < (ssize_t) roi->width; x++)
1656 *q++=GetPixelRed(image,p);
1657 *q++=GetPixelGreen(image,p);
1658 *q++=GetPixelBlue(image,p);
1659 *q++=(Quantum) (GetPixelAlpha(image,p));
1660 p+=GetPixelChannels(image);
1665 if (LocaleCompare(map,"RGBP") == 0)
1667 for (y=0; y < (ssize_t) roi->height; y++)
1669 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1670 if (p == (const Quantum *) NULL)
1672 for (x=0; x < (ssize_t) roi->width; x++)
1674 *q++=GetPixelRed(image,p);
1675 *q++=GetPixelGreen(image,p);
1676 *q++=GetPixelBlue(image,p);
1678 p+=GetPixelChannels(image);
1684 for (y=0; y < (ssize_t) roi->height; y++)
1686 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1687 if (p == (const Quantum *) NULL)
1689 for (x=0; x < (ssize_t) roi->width; x++)
1694 for (i=0; i < (ssize_t) length; i++)
1697 switch (quantum_map[i])
1702 *q=GetPixelRed(image,p);
1706 case MagentaQuantum:
1708 *q=GetPixelGreen(image,p);
1714 *q=GetPixelBlue(image,p);
1719 *q=GetPixelAlpha(image,p);
1722 case OpacityQuantum:
1724 *q=GetPixelAlpha(image,p);
1729 if (image->colorspace == CMYKColorspace)
1730 *q=GetPixelBlack(image,p);
1735 *q=ClampToQuantum(GetPixelIntensity(image,p));
1746 p+=GetPixelChannels(image);
1751 static void ExportShortPixel(const Image *image,const RectangleInfo *roi,
1752 const char *magick_restrict map,const QuantumType *quantum_map,void *pixels,
1753 ExceptionInfo *exception)
1755 register const Quantum
1761 register unsigned short
1770 q=(unsigned short *) pixels;
1771 if (LocaleCompare(map,"BGR") == 0)
1773 for (y=0; y < (ssize_t) roi->height; y++)
1775 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1776 if (p == (const Quantum *) NULL)
1778 for (x=0; x < (ssize_t) roi->width; x++)
1780 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1781 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1782 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1783 p+=GetPixelChannels(image);
1788 if (LocaleCompare(map,"BGRA") == 0)
1790 for (y=0; y < (ssize_t) roi->height; y++)
1792 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1793 if (p == (const Quantum *) NULL)
1795 for (x=0; x < (ssize_t) roi->width; x++)
1797 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1798 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1799 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1800 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1801 p+=GetPixelChannels(image);
1806 if (LocaleCompare(map,"BGRP") == 0)
1808 for (y=0; y < (ssize_t) roi->height; y++)
1810 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1811 if (p == (const Quantum *) NULL)
1813 for (x=0; x < (ssize_t) roi->width; x++)
1815 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1816 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1817 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1819 p+=GetPixelChannels(image);
1824 if (LocaleCompare(map,"I") == 0)
1826 for (y=0; y < (ssize_t) roi->height; y++)
1828 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1829 if (p == (const Quantum *) NULL)
1831 for (x=0; x < (ssize_t) roi->width; x++)
1833 *q++=ScaleQuantumToShort(ClampToQuantum(GetPixelIntensity(image,p)));
1834 p+=GetPixelChannels(image);
1839 if (LocaleCompare(map,"RGB") == 0)
1841 for (y=0; y < (ssize_t) roi->height; y++)
1843 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1844 if (p == (const Quantum *) NULL)
1846 for (x=0; x < (ssize_t) roi->width; x++)
1848 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1849 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1850 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1851 p+=GetPixelChannels(image);
1856 if (LocaleCompare(map,"RGBA") == 0)
1858 for (y=0; y < (ssize_t) roi->height; y++)
1860 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1861 if (p == (const Quantum *) NULL)
1863 for (x=0; x < (ssize_t) roi->width; x++)
1865 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1866 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1867 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1868 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1869 p+=GetPixelChannels(image);
1874 if (LocaleCompare(map,"RGBP") == 0)
1876 for (y=0; y < (ssize_t) roi->height; y++)
1878 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1879 if (p == (const Quantum *) NULL)
1881 for (x=0; x < (ssize_t) roi->width; x++)
1883 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1884 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1885 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1887 p+=GetPixelChannels(image);
1893 for (y=0; y < (ssize_t) roi->height; y++)
1895 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1896 if (p == (const Quantum *) NULL)
1898 for (x=0; x < (ssize_t) roi->width; x++)
1903 for (i=0; i < (ssize_t) length; i++)
1906 switch (quantum_map[i])
1911 *q=ScaleQuantumToShort(GetPixelRed(image,p));
1915 case MagentaQuantum:
1917 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
1923 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
1928 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1931 case OpacityQuantum:
1933 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1938 if (image->colorspace == CMYKColorspace)
1939 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
1944 *q=ScaleQuantumToShort(ClampToQuantum(GetPixelIntensity(image,p)));
1952 p+=GetPixelChannels(image);
1957 MagickExport MagickBooleanType ExportImagePixels(const Image *image,const ssize_t x,
1958 const ssize_t y,const size_t width,const size_t height,const char *map,
1959 const StorageType type,void *pixels,ExceptionInfo *exception)
1973 assert(image != (Image *) NULL);
1974 assert(image->signature == MagickCoreSignature);
1975 if (image->debug != MagickFalse)
1976 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1978 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1979 if (quantum_map == (QuantumType *) NULL)
1981 (void) ThrowMagickException(exception,GetMagickModule(),
1982 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1983 return(MagickFalse);
1985 for (i=0; i < (ssize_t) length; i++)
1992 quantum_map[i]=AlphaQuantum;
1998 quantum_map[i]=BlueQuantum;
2004 quantum_map[i]=CyanQuantum;
2005 if (image->colorspace == CMYKColorspace)
2007 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2008 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2009 "ColorSeparatedImageRequired","`%s'",map);
2010 return(MagickFalse);
2015 quantum_map[i]=GreenQuantum;
2021 quantum_map[i]=IndexQuantum;
2027 quantum_map[i]=BlackQuantum;
2028 if (image->colorspace == CMYKColorspace)
2030 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2031 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2032 "ColorSeparatedImageRequired","`%s'",map);
2033 return(MagickFalse);
2038 quantum_map[i]=MagentaQuantum;
2039 if (image->colorspace == CMYKColorspace)
2041 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2042 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2043 "ColorSeparatedImageRequired","`%s'",map);
2044 return(MagickFalse);
2049 quantum_map[i]=OpacityQuantum;
2055 quantum_map[i]=UndefinedQuantum;
2061 quantum_map[i]=RedQuantum;
2067 quantum_map[i]=YellowQuantum;
2068 if (image->colorspace == CMYKColorspace)
2070 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2071 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2072 "ColorSeparatedImageRequired","`%s'",map);
2073 return(MagickFalse);
2077 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2078 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2079 "UnrecognizedPixelMap","`%s'",map);
2080 return(MagickFalse);
2092 ExportCharPixel(image,&roi,map,quantum_map,pixels,exception);
2097 ExportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
2102 ExportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
2107 ExportLongPixel(image,&roi,map,quantum_map,pixels,exception);
2112 ExportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
2117 ExportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
2122 ExportShortPixel(image,&roi,map,quantum_map,pixels,exception);
2127 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2128 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2129 "UnrecognizedPixelMap","`%s'",map);
2133 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2142 % G e t P i x e l I n f o %
2146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2148 % GetPixelInfo() initializes the PixelInfo structure.
2150 % The format of the GetPixelInfo method is:
2152 % GetPixelInfo(const Image *image,PixelInfo *pixel)
2154 % A description of each parameter follows:
2156 % o image: the image. (optional - may be NULL)
2158 % o pixel: Specifies a pointer to a PixelInfo structure.
2161 MagickExport void GetPixelInfo(const Image *image,PixelInfo *pixel)
2163 pixel->storage_class=DirectClass;
2164 pixel->colorspace=sRGBColorspace;
2165 pixel->alpha_trait=UndefinedPixelTrait;
2167 pixel->depth=MAGICKCORE_QUANTUM_DEPTH;
2172 pixel->alpha=(double) OpaqueAlpha;
2176 if (image == (const Image *) NULL)
2178 pixel->storage_class=image->storage_class;
2179 pixel->colorspace=image->colorspace;
2180 pixel->alpha_trait=image->alpha_trait;
2181 pixel->depth=image->depth;
2182 pixel->fuzz=image->fuzz;
2186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2190 % G e t P i x e l I n d o I n t e n s i t y %
2194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2196 % GetPixelInfoIntensity() returns a single sample intensity value from the red,
2197 % green, and blue components of a pixel based on the selected method:
2199 % Rec601Luma 0.298839R' + 0.586811G' + 0.114350B'
2200 % Rec601Luminance 0.298839R + 0.586811G + 0.114350B
2201 % Rec709Luma 0.212656R' + 0.715158G' + 0.072186B'
2202 % Rec709Luminance 0.212656R + 0.715158G + 0.072186B
2203 % Brightness max(R', G', B')
2204 % Lightness (min(R', G', B') + max(R', G', B')) / 2.0
2206 % MS (R^2 + G^2 + B^2) / 3.0
2207 % RMS sqrt((R^2 + G^2 + B^2) / 3.0
2208 % Average (R + G + B') / 3.0
2210 % The format of the GetPixelInfoIntensity method is:
2212 % MagickRealType GetPixelInfoIntensity(const Image *image,
2213 % const Quantum *pixel)
2215 % A description of each parameter follows:
2217 % o image: the image.
2219 % o pixel: Specifies a pointer to a Quantum structure.
2222 MagickExport MagickRealType GetPixelInfoIntensity(
2223 const Image *magick_restrict image,const PixelInfo *magick_restrict pixel)
2231 PixelIntensityMethod
2234 method=Rec709LumaPixelIntensityMethod;
2235 if (image != (const Image *) NULL)
2236 method=image->intensity;
2242 case AveragePixelIntensityMethod:
2244 intensity=(red+green+blue)/3.0;
2247 case BrightnessPixelIntensityMethod:
2249 intensity=MagickMax(MagickMax(red,green),blue);
2252 case LightnessPixelIntensityMethod:
2254 intensity=(MagickMin(MagickMin(red,green),blue)+
2255 MagickMax(MagickMax(red,green),blue))/2.0;
2258 case MSPixelIntensityMethod:
2260 intensity=(MagickRealType) (((double) red*red+green*green+blue*blue)/
2261 (3.0*QuantumRange));
2264 case Rec601LumaPixelIntensityMethod:
2266 if (pixel->colorspace == RGBColorspace)
2268 red=EncodePixelGamma(red);
2269 green=EncodePixelGamma(green);
2270 blue=EncodePixelGamma(blue);
2272 intensity=0.298839*red+0.586811*green+0.114350*blue;
2275 case Rec601LuminancePixelIntensityMethod:
2277 if (pixel->colorspace == sRGBColorspace)
2279 red=DecodePixelGamma(red);
2280 green=DecodePixelGamma(green);
2281 blue=DecodePixelGamma(blue);
2283 intensity=0.298839*red+0.586811*green+0.114350*blue;
2286 case Rec709LumaPixelIntensityMethod:
2289 if (pixel->colorspace == RGBColorspace)
2291 red=EncodePixelGamma(red);
2292 green=EncodePixelGamma(green);
2293 blue=EncodePixelGamma(blue);
2295 intensity=0.212656*red+0.715158*green+0.072186*blue;
2298 case Rec709LuminancePixelIntensityMethod:
2300 if (pixel->colorspace == sRGBColorspace)
2302 red=DecodePixelGamma(red);
2303 green=DecodePixelGamma(green);
2304 blue=DecodePixelGamma(blue);
2306 intensity=0.212656*red+0.715158*green+0.072186*blue;
2309 case RMSPixelIntensityMethod:
2311 intensity=(MagickRealType) (sqrt((double) red*red+green*green+blue*blue)/
2320 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2324 % G e t P i x e l I n t e n s i t y %
2328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2330 % GetPixelIntensity() returns a single sample intensity value from the red,
2331 % green, and blue components of a pixel based on the selected method:
2333 % Rec601Luma 0.298839R' + 0.586811G' + 0.114350B'
2334 % Rec601Luminance 0.298839R + 0.586811G + 0.114350B
2335 % Rec709Luma 0.212656R' + 0.715158G' + 0.072186B'
2336 % Rec709Luminance 0.212656R + 0.715158G + 0.072186B
2337 % Brightness max(R', G', B')
2338 % Lightness (min(R', G', B') + max(R', G', B')) / 2.0
2340 % MS (R^2 + G^2 + B^2) / 3.0
2341 % RMS sqrt((R^2 + G^2 + B^2) / 3.0
2342 % Average (R + G + B') / 3.0
2344 % The format of the GetPixelIntensity method is:
2346 % MagickRealType GetPixelIntensity(const Image *image,
2347 % const Quantum *pixel)
2349 % A description of each parameter follows:
2351 % o image: the image.
2353 % o pixel: Specifies a pointer to a Quantum structure.
2356 MagickExport MagickRealType GetPixelIntensity(
2357 const Image *magick_restrict image,const Quantum *magick_restrict pixel)
2365 red=(MagickRealType) GetPixelRed(image,pixel);
2366 green=(MagickRealType) GetPixelGreen(image,pixel);
2367 blue=(MagickRealType) GetPixelBlue(image,pixel);
2368 switch (image->intensity)
2370 case AveragePixelIntensityMethod:
2372 intensity=(red+green+blue)/3.0;
2375 case BrightnessPixelIntensityMethod:
2377 intensity=MagickMax(MagickMax(red,green),blue);
2380 case LightnessPixelIntensityMethod:
2382 intensity=(MagickMin(MagickMin(red,green),blue)+
2383 MagickMax(MagickMax(red,green),blue))/2.0;
2386 case MSPixelIntensityMethod:
2388 intensity=(MagickRealType) (((double) red*red+green*green+blue*blue)/
2389 (3.0*QuantumRange));
2392 case Rec601LumaPixelIntensityMethod:
2394 if (image->colorspace == RGBColorspace)
2396 red=EncodePixelGamma(red);
2397 green=EncodePixelGamma(green);
2398 blue=EncodePixelGamma(blue);
2400 intensity=0.298839*red+0.586811*green+0.114350*blue;
2403 case Rec601LuminancePixelIntensityMethod:
2405 if (image->colorspace == sRGBColorspace)
2407 red=DecodePixelGamma(red);
2408 green=DecodePixelGamma(green);
2409 blue=DecodePixelGamma(blue);
2411 intensity=0.298839*red+0.586811*green+0.114350*blue;
2414 case Rec709LumaPixelIntensityMethod:
2417 if (image->colorspace == RGBColorspace)
2419 red=EncodePixelGamma(red);
2420 green=EncodePixelGamma(green);
2421 blue=EncodePixelGamma(blue);
2423 intensity=0.212656*red+0.715158*green+0.072186*blue;
2426 case Rec709LuminancePixelIntensityMethod:
2428 if (image->colorspace == sRGBColorspace)
2430 red=DecodePixelGamma(red);
2431 green=DecodePixelGamma(green);
2432 blue=DecodePixelGamma(blue);
2434 intensity=0.212656*red+0.715158*green+0.072186*blue;
2437 case RMSPixelIntensityMethod:
2439 intensity=(MagickRealType) (sqrt((double) red*red+green*green+blue*blue)/
2448 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2452 % I m p o r t I m a g e P i x e l s %
2456 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2458 % ImportImagePixels() accepts pixel data and stores in the image at the
2459 % location you specify. The method returns MagickTrue on success otherwise
2460 % MagickFalse if an error is encountered. The pixel data can be either char,
2461 % Quantum, short int, unsigned int, unsigned long long, float, or double in
2462 % the order specified by map.
2464 % Suppose your want to upload the first scanline of a 640x480 image from
2465 % character data in red-green-blue order:
2467 % ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels);
2469 % The format of the ImportImagePixels method is:
2471 % MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
2472 % const ssize_t y,const size_t width,const size_t height,
2473 % const char *map,const StorageType type,const void *pixels,
2474 % ExceptionInfo *exception)
2476 % A description of each parameter follows:
2478 % o image: the image.
2480 % o x,y,width,height: These values define the perimeter
2481 % of a region of pixels you want to define.
2483 % o map: This string reflects the expected ordering of the pixel array.
2484 % It can be any combination or order of R = red, G = green, B = blue,
2485 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
2486 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
2489 % o type: Define the data type of the pixels. Float and double types are
2490 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
2491 % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *),
2492 % LongPixel (unsigned int *), LongLongPixel (unsigned long long *),
2493 % QuantumPixel (Quantum *), or ShortPixel (unsigned short *).
2495 % o pixels: This array of values contain the pixel components as defined by
2496 % map and type. You must preallocate this array where the expected
2497 % length varies depending on the values of width, height, map, and type.
2499 % o exception: return any errors or warnings in this structure.
2503 static void ImportCharPixel(Image *image,const RectangleInfo *roi,
2504 const char *magick_restrict map,const QuantumType *quantum_map,
2505 const void *pixels,ExceptionInfo *exception)
2507 register const unsigned char
2522 p=(const unsigned char *) pixels;
2523 if (LocaleCompare(map,"BGR") == 0)
2525 for (y=0; y < (ssize_t) roi->height; y++)
2527 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2528 if (q == (Quantum *) NULL)
2530 for (x=0; x < (ssize_t) roi->width; x++)
2532 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2533 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2534 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2535 q+=GetPixelChannels(image);
2537 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2542 if (LocaleCompare(map,"BGRA") == 0)
2544 for (y=0; y < (ssize_t) roi->height; y++)
2546 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2547 if (q == (Quantum *) NULL)
2549 for (x=0; x < (ssize_t) roi->width; x++)
2551 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2552 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2553 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2554 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2555 q+=GetPixelChannels(image);
2557 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2562 if (LocaleCompare(map,"BGRO") == 0)
2564 for (y=0; y < (ssize_t) roi->height; y++)
2566 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2567 if (q == (Quantum *) NULL)
2569 for (x=0; x < (ssize_t) roi->width; x++)
2571 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2572 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2573 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2574 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2575 q+=GetPixelChannels(image);
2577 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2582 if (LocaleCompare(map,"BGRP") == 0)
2584 for (y=0; y < (ssize_t) roi->height; y++)
2586 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2587 if (q == (Quantum *) NULL)
2589 for (x=0; x < (ssize_t) roi->width; x++)
2591 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2592 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2593 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2595 q+=GetPixelChannels(image);
2597 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2602 if (LocaleCompare(map,"I") == 0)
2604 for (y=0; y < (ssize_t) roi->height; y++)
2606 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2607 if (q == (Quantum *) NULL)
2609 for (x=0; x < (ssize_t) roi->width; x++)
2611 SetPixelGray(image,ScaleCharToQuantum(*p++),q);
2612 q+=GetPixelChannels(image);
2614 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2619 if (LocaleCompare(map,"RGB") == 0)
2621 for (y=0; y < (ssize_t) roi->height; y++)
2623 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2624 if (q == (Quantum *) NULL)
2626 for (x=0; x < (ssize_t) roi->width; x++)
2628 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2629 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2630 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2631 q+=GetPixelChannels(image);
2633 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2638 if (LocaleCompare(map,"RGBA") == 0)
2640 for (y=0; y < (ssize_t) roi->height; y++)
2642 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2643 if (q == (Quantum *) NULL)
2645 for (x=0; x < (ssize_t) roi->width; x++)
2647 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2648 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2649 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2650 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2651 q+=GetPixelChannels(image);
2653 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2658 if (LocaleCompare(map,"RGBO") == 0)
2660 for (y=0; y < (ssize_t) roi->height; y++)
2662 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2663 if (q == (Quantum *) NULL)
2665 for (x=0; x < (ssize_t) roi->width; x++)
2667 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2668 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2669 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2670 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2671 q+=GetPixelChannels(image);
2673 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2678 if (LocaleCompare(map,"RGBP") == 0)
2680 for (y=0; y < (ssize_t) roi->height; y++)
2682 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2683 if (q == (Quantum *) NULL)
2685 for (x=0; x < (ssize_t) roi->width; x++)
2687 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2688 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2689 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2691 q+=GetPixelChannels(image);
2693 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2699 for (y=0; y < (ssize_t) roi->height; y++)
2701 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2702 if (q == (Quantum *) NULL)
2704 for (x=0; x < (ssize_t) roi->width; x++)
2709 for (i=0; i < (ssize_t) length; i++)
2711 switch (quantum_map[i])
2716 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2720 case MagentaQuantum:
2722 SetPixelGreen(image,ScaleCharToQuantum(*p),q);
2728 SetPixelBlue(image,ScaleCharToQuantum(*p),q);
2733 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2736 case OpacityQuantum:
2738 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2743 SetPixelBlack(image,ScaleCharToQuantum(*p),q);
2748 SetPixelGray(image,ScaleCharToQuantum(*p),q);
2756 q+=GetPixelChannels(image);
2758 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2763 static void ImportDoublePixel(Image *image,const RectangleInfo *roi,
2764 const char *magick_restrict map,const QuantumType *quantum_map,
2765 const void *pixels,ExceptionInfo *exception)
2767 register const double
2782 p=(const double *) pixels;
2783 if (LocaleCompare(map,"BGR") == 0)
2785 for (y=0; y < (ssize_t) roi->height; y++)
2787 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2788 if (q == (Quantum *) NULL)
2790 for (x=0; x < (ssize_t) roi->width; x++)
2792 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2794 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2796 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2798 q+=GetPixelChannels(image);
2800 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2805 if (LocaleCompare(map,"BGRA") == 0)
2807 for (y=0; y < (ssize_t) roi->height; y++)
2809 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2810 if (q == (Quantum *) NULL)
2812 for (x=0; x < (ssize_t) roi->width; x++)
2814 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2816 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2818 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2820 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2822 q+=GetPixelChannels(image);
2824 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2829 if (LocaleCompare(map,"BGRP") == 0)
2831 for (y=0; y < (ssize_t) roi->height; y++)
2833 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2834 if (q == (Quantum *) NULL)
2836 for (x=0; x < (ssize_t) roi->width; x++)
2838 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2840 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2842 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2845 q+=GetPixelChannels(image);
2847 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2852 if (LocaleCompare(map,"I") == 0)
2854 for (y=0; y < (ssize_t) roi->height; y++)
2856 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2857 if (q == (Quantum *) NULL)
2859 for (x=0; x < (ssize_t) roi->width; x++)
2861 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2863 q+=GetPixelChannels(image);
2865 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2870 if (LocaleCompare(map,"RGB") == 0)
2872 for (y=0; y < (ssize_t) roi->height; y++)
2874 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2875 if (q == (Quantum *) NULL)
2877 for (x=0; x < (ssize_t) roi->width; x++)
2879 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2881 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2883 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2885 q+=GetPixelChannels(image);
2887 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2892 if (LocaleCompare(map,"RGBA") == 0)
2894 for (y=0; y < (ssize_t) roi->height; y++)
2896 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2897 if (q == (Quantum *) NULL)
2899 for (x=0; x < (ssize_t) roi->width; x++)
2901 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2903 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2905 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2907 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2909 q+=GetPixelChannels(image);
2911 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2916 if (LocaleCompare(map,"RGBP") == 0)
2918 for (y=0; y < (ssize_t) roi->height; y++)
2920 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2921 if (q == (Quantum *) NULL)
2923 for (x=0; x < (ssize_t) roi->width; x++)
2925 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2927 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2929 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2931 q+=GetPixelChannels(image);
2933 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2939 for (y=0; y < (ssize_t) roi->height; y++)
2941 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2942 if (q == (Quantum *) NULL)
2944 for (x=0; x < (ssize_t) roi->width; x++)
2949 for (i=0; i < (ssize_t) length; i++)
2951 switch (quantum_map[i])
2956 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2960 case MagentaQuantum:
2962 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2968 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2973 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2976 case OpacityQuantum:
2978 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2983 SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q);
2988 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2996 q+=GetPixelChannels(image);
2998 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3003 static void ImportFloatPixel(Image *image,const RectangleInfo *roi,
3004 const char *magick_restrict map,const QuantumType *quantum_map,
3005 const void *pixels,ExceptionInfo *exception)
3007 register const float
3022 p=(const float *) pixels;
3023 if (LocaleCompare(map,"BGR") == 0)
3025 for (y=0; y < (ssize_t) roi->height; y++)
3027 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3028 if (q == (Quantum *) NULL)
3030 for (x=0; x < (ssize_t) roi->width; x++)
3032 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3034 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3036 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3038 q+=GetPixelChannels(image);
3040 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3045 if (LocaleCompare(map,"BGRA") == 0)
3047 for (y=0; y < (ssize_t) roi->height; y++)
3049 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3050 if (q == (Quantum *) NULL)
3052 for (x=0; x < (ssize_t) roi->width; x++)
3054 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3056 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3058 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3060 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
3062 q+=GetPixelChannels(image);
3064 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3069 if (LocaleCompare(map,"BGRP") == 0)
3071 for (y=0; y < (ssize_t) roi->height; y++)
3073 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3074 if (q == (Quantum *) NULL)
3076 for (x=0; x < (ssize_t) roi->width; x++)
3078 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3080 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3082 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3085 q+=GetPixelChannels(image);
3087 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3092 if (LocaleCompare(map,"I") == 0)
3094 for (y=0; y < (ssize_t) roi->height; y++)
3096 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3097 if (q == (Quantum *) NULL)
3099 for (x=0; x < (ssize_t) roi->width; x++)
3101 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
3103 q+=GetPixelChannels(image);
3105 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3110 if (LocaleCompare(map,"RGB") == 0)
3112 for (y=0; y < (ssize_t) roi->height; y++)
3114 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3115 if (q == (Quantum *) NULL)
3117 for (x=0; x < (ssize_t) roi->width; x++)
3119 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3121 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3123 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3125 q+=GetPixelChannels(image);
3127 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3132 if (LocaleCompare(map,"RGBA") == 0)
3134 for (y=0; y < (ssize_t) roi->height; y++)
3136 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3137 if (q == (Quantum *) NULL)
3139 for (x=0; x < (ssize_t) roi->width; x++)
3141 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3143 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3145 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3147 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
3149 q+=GetPixelChannels(image);
3151 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3156 if (LocaleCompare(map,"RGBP") == 0)
3158 for (y=0; y < (ssize_t) roi->height; y++)
3160 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3161 if (q == (Quantum *) NULL)
3163 for (x=0; x < (ssize_t) roi->width; x++)
3165 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3167 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3169 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3171 q+=GetPixelChannels(image);
3173 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3179 for (y=0; y < (ssize_t) roi->height; y++)
3181 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3182 if (q == (Quantum *) NULL)
3184 for (x=0; x < (ssize_t) roi->width; x++)
3189 for (i=0; i < (ssize_t) length; i++)
3191 switch (quantum_map[i])
3196 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3200 case MagentaQuantum:
3202 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3208 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3213 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
3216 case OpacityQuantum:
3218 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
3223 SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q);
3228 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
3236 q+=GetPixelChannels(image);
3238 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3243 static void ImportLongPixel(Image *image,const RectangleInfo *roi,
3244 const char *magick_restrict map,const QuantumType *quantum_map,
3245 const void *pixels,ExceptionInfo *exception)
3247 register const unsigned int
3262 p=(const unsigned int *) pixels;
3263 if (LocaleCompare(map,"BGR") == 0)
3265 for (y=0; y < (ssize_t) roi->height; y++)
3267 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3268 if (q == (Quantum *) NULL)
3270 for (x=0; x < (ssize_t) roi->width; x++)
3272 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3273 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3274 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3275 q+=GetPixelChannels(image);
3277 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3282 if (LocaleCompare(map,"BGRA") == 0)
3284 for (y=0; y < (ssize_t) roi->height; y++)
3286 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3287 if (q == (Quantum *) NULL)
3289 for (x=0; x < (ssize_t) roi->width; x++)
3291 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3292 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3293 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3294 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3295 q+=GetPixelChannels(image);
3297 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3302 if (LocaleCompare(map,"BGRP") == 0)
3304 for (y=0; y < (ssize_t) roi->height; y++)
3306 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3307 if (q == (Quantum *) NULL)
3309 for (x=0; x < (ssize_t) roi->width; x++)
3311 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3312 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3313 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3315 q+=GetPixelChannels(image);
3317 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3322 if (LocaleCompare(map,"I") == 0)
3324 for (y=0; y < (ssize_t) roi->height; y++)
3326 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3327 if (q == (Quantum *) NULL)
3329 for (x=0; x < (ssize_t) roi->width; x++)
3331 SetPixelGray(image,ScaleLongToQuantum(*p++),q);
3332 q+=GetPixelChannels(image);
3334 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3339 if (LocaleCompare(map,"RGB") == 0)
3341 for (y=0; y < (ssize_t) roi->height; y++)
3343 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3344 if (q == (Quantum *) NULL)
3346 for (x=0; x < (ssize_t) roi->width; x++)
3348 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3349 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3350 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3351 q+=GetPixelChannels(image);
3353 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3358 if (LocaleCompare(map,"RGBA") == 0)
3360 for (y=0; y < (ssize_t) roi->height; y++)
3362 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3363 if (q == (Quantum *) NULL)
3365 for (x=0; x < (ssize_t) roi->width; x++)
3367 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3368 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3369 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3370 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3371 q+=GetPixelChannels(image);
3373 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3378 if (LocaleCompare(map,"RGBP") == 0)
3380 for (y=0; y < (ssize_t) roi->height; y++)
3382 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3383 if (q == (Quantum *) NULL)
3385 for (x=0; x < (ssize_t) roi->width; x++)
3387 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3388 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3389 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3391 q+=GetPixelChannels(image);
3393 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3399 for (y=0; y < (ssize_t) roi->height; y++)
3401 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3402 if (q == (Quantum *) NULL)
3404 for (x=0; x < (ssize_t) roi->width; x++)
3409 for (i=0; i < (ssize_t) length; i++)
3411 switch (quantum_map[i])
3416 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3420 case MagentaQuantum:
3422 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
3428 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
3433 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3436 case OpacityQuantum:
3438 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3443 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
3448 SetPixelGray(image,ScaleLongToQuantum(*p),q);
3456 q+=GetPixelChannels(image);
3458 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3463 static void ImportLongLongPixel(Image *image,const RectangleInfo *roi,
3464 const char *magick_restrict map,const QuantumType *quantum_map,
3465 const void *pixels,ExceptionInfo *exception)
3467 register const MagickSizeType
3482 p=(const MagickSizeType *) pixels;
3483 if (LocaleCompare(map,"BGR") == 0)
3485 for (y=0; y < (ssize_t) roi->height; y++)
3487 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3488 if (q == (Quantum *) NULL)
3490 for (x=0; x < (ssize_t) roi->width; x++)
3492 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3493 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3494 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3495 q+=GetPixelChannels(image);
3497 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3502 if (LocaleCompare(map,"BGRA") == 0)
3504 for (y=0; y < (ssize_t) roi->height; y++)
3506 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3507 if (q == (Quantum *) NULL)
3509 for (x=0; x < (ssize_t) roi->width; x++)
3511 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3512 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3513 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3514 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3515 q+=GetPixelChannels(image);
3517 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3522 if (LocaleCompare(map,"BGRP") == 0)
3524 for (y=0; y < (ssize_t) roi->height; y++)
3526 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3527 if (q == (Quantum *) NULL)
3529 for (x=0; x < (ssize_t) roi->width; x++)
3531 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3532 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3533 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3535 q+=GetPixelChannels(image);
3537 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3542 if (LocaleCompare(map,"I") == 0)
3544 for (y=0; y < (ssize_t) roi->height; y++)
3546 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3547 if (q == (Quantum *) NULL)
3549 for (x=0; x < (ssize_t) roi->width; x++)
3551 SetPixelGray(image,ScaleLongLongToQuantum(*p++),q);
3552 q+=GetPixelChannels(image);
3554 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3559 if (LocaleCompare(map,"RGB") == 0)
3561 for (y=0; y < (ssize_t) roi->height; y++)
3563 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3564 if (q == (Quantum *) NULL)
3566 for (x=0; x < (ssize_t) roi->width; x++)
3568 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3569 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3570 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3571 q+=GetPixelChannels(image);
3573 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3578 if (LocaleCompare(map,"RGBA") == 0)
3580 for (y=0; y < (ssize_t) roi->height; y++)
3582 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3583 if (q == (Quantum *) NULL)
3585 for (x=0; x < (ssize_t) roi->width; x++)
3587 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3588 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3589 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3590 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3591 q+=GetPixelChannels(image);
3593 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3598 if (LocaleCompare(map,"RGBP") == 0)
3600 for (y=0; y < (ssize_t) roi->height; y++)
3602 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3603 if (q == (Quantum *) NULL)
3605 for (x=0; x < (ssize_t) roi->width; x++)
3607 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3608 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3609 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3611 q+=GetPixelChannels(image);
3613 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3619 for (y=0; y < (ssize_t) roi->height; y++)
3621 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3622 if (q == (Quantum *) NULL)
3624 for (x=0; x < (ssize_t) roi->width; x++)
3629 for (i=0; i < (ssize_t) length; i++)
3631 switch (quantum_map[i])
3636 SetPixelRed(image,ScaleLongLongToQuantum(*p),q);
3640 case MagentaQuantum:
3642 SetPixelGreen(image,ScaleLongLongToQuantum(*p),q);
3648 SetPixelBlue(image,ScaleLongLongToQuantum(*p),q);
3653 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3656 case OpacityQuantum:
3658 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3663 SetPixelBlack(image,ScaleLongLongToQuantum(*p),q);
3668 SetPixelGray(image,ScaleLongLongToQuantum(*p),q);
3676 q+=GetPixelChannels(image);
3678 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3683 static void ImportQuantumPixel(Image *image,const RectangleInfo *roi,
3684 const char *magick_restrict map,const QuantumType *quantum_map,
3685 const void *pixels,ExceptionInfo *exception)
3687 register const Quantum
3702 p=(const Quantum *) pixels;
3703 if (LocaleCompare(map,"BGR") == 0)
3705 for (y=0; y < (ssize_t) roi->height; y++)
3707 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3708 if (q == (Quantum *) NULL)
3710 for (x=0; x < (ssize_t) roi->width; x++)
3712 SetPixelBlue(image,*p++,q);
3713 SetPixelGreen(image,*p++,q);
3714 SetPixelRed(image,*p++,q);
3715 q+=GetPixelChannels(image);
3717 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3722 if (LocaleCompare(map,"BGRA") == 0)
3724 for (y=0; y < (ssize_t) roi->height; y++)
3726 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3727 if (q == (Quantum *) NULL)
3729 for (x=0; x < (ssize_t) roi->width; x++)
3731 SetPixelBlue(image,*p++,q);
3732 SetPixelGreen(image,*p++,q);
3733 SetPixelRed(image,*p++,q);
3734 SetPixelAlpha(image,*p++,q);
3735 q+=GetPixelChannels(image);
3737 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3742 if (LocaleCompare(map,"BGRP") == 0)
3744 for (y=0; y < (ssize_t) roi->height; y++)
3746 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3747 if (q == (Quantum *) NULL)
3749 for (x=0; x < (ssize_t) roi->width; x++)
3751 SetPixelBlue(image,*p++,q);
3752 SetPixelGreen(image,*p++,q);
3753 SetPixelRed(image,*p++,q);
3755 q+=GetPixelChannels(image);
3757 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3762 if (LocaleCompare(map,"I") == 0)
3764 for (y=0; y < (ssize_t) roi->height; y++)
3766 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3767 if (q == (Quantum *) NULL)
3769 for (x=0; x < (ssize_t) roi->width; x++)
3771 SetPixelGray(image,*p++,q);
3772 q+=GetPixelChannels(image);
3774 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3779 if (LocaleCompare(map,"RGB") == 0)
3781 for (y=0; y < (ssize_t) roi->height; y++)
3783 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3784 if (q == (Quantum *) NULL)
3786 for (x=0; x < (ssize_t) roi->width; x++)
3788 SetPixelRed(image,*p++,q);
3789 SetPixelGreen(image,*p++,q);
3790 SetPixelBlue(image,*p++,q);
3791 q+=GetPixelChannels(image);
3793 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3798 if (LocaleCompare(map,"RGBA") == 0)
3800 for (y=0; y < (ssize_t) roi->height; y++)
3802 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3803 if (q == (Quantum *) NULL)
3805 for (x=0; x < (ssize_t) roi->width; x++)
3807 SetPixelRed(image,*p++,q);
3808 SetPixelGreen(image,*p++,q);
3809 SetPixelBlue(image,*p++,q);
3810 SetPixelAlpha(image,*p++,q);
3811 q+=GetPixelChannels(image);
3813 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3818 if (LocaleCompare(map,"RGBP") == 0)
3820 for (y=0; y < (ssize_t) roi->height; y++)
3822 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3823 if (q == (Quantum *) NULL)
3825 for (x=0; x < (ssize_t) roi->width; x++)
3827 SetPixelRed(image,*p++,q);
3828 SetPixelGreen(image,*p++,q);
3829 SetPixelBlue(image,*p++,q);
3831 q+=GetPixelChannels(image);
3833 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3839 for (y=0; y < (ssize_t) roi->height; y++)
3841 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3842 if (q == (Quantum *) NULL)
3844 for (x=0; x < (ssize_t) roi->width; x++)
3849 for (i=0; i < (ssize_t) length; i++)
3851 switch (quantum_map[i])
3856 SetPixelRed(image,*p,q);
3860 case MagentaQuantum:
3862 SetPixelGreen(image,*p,q);
3868 SetPixelBlue(image,*p,q);
3873 SetPixelAlpha(image,*p,q);
3876 case OpacityQuantum:
3878 SetPixelAlpha(image,*p,q);
3883 SetPixelBlack(image,*p,q);
3888 SetPixelGray(image,*p,q);
3896 q+=GetPixelChannels(image);
3898 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3903 static void ImportShortPixel(Image *image,const RectangleInfo *roi,
3904 const char *magick_restrict map,const QuantumType *quantum_map,
3905 const void *pixels,ExceptionInfo *exception)
3907 register const unsigned short
3922 p=(const unsigned short *) pixels;
3923 if (LocaleCompare(map,"BGR") == 0)
3925 for (y=0; y < (ssize_t) roi->height; y++)
3927 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3928 if (q == (Quantum *) NULL)
3930 for (x=0; x < (ssize_t) roi->width; x++)
3932 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3933 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3934 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3935 q+=GetPixelChannels(image);
3937 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3942 if (LocaleCompare(map,"BGRA") == 0)
3944 for (y=0; y < (ssize_t) roi->height; y++)
3946 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3947 if (q == (Quantum *) NULL)
3949 for (x=0; x < (ssize_t) roi->width; x++)
3951 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3952 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3953 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3954 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3955 q+=GetPixelChannels(image);
3957 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3962 if (LocaleCompare(map,"BGRP") == 0)
3964 for (y=0; y < (ssize_t) roi->height; y++)
3966 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3967 if (q == (Quantum *) NULL)
3969 for (x=0; x < (ssize_t) roi->width; x++)
3971 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3972 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3973 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3975 q+=GetPixelChannels(image);
3977 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3982 if (LocaleCompare(map,"I") == 0)
3984 for (y=0; y < (ssize_t) roi->height; y++)
3986 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3987 if (q == (Quantum *) NULL)
3989 for (x=0; x < (ssize_t) roi->width; x++)
3991 SetPixelGray(image,ScaleShortToQuantum(*p++),q);
3992 q+=GetPixelChannels(image);
3994 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3999 if (LocaleCompare(map,"RGB") == 0)
4001 for (y=0; y < (ssize_t) roi->height; y++)
4003 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4004 if (q == (Quantum *) NULL)
4006 for (x=0; x < (ssize_t) roi->width; x++)
4008 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4009 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4010 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4011 q+=GetPixelChannels(image);
4013 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4018 if (LocaleCompare(map,"RGBA") == 0)
4020 for (y=0; y < (ssize_t) roi->height; y++)
4022 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4023 if (q == (Quantum *) NULL)
4025 for (x=0; x < (ssize_t) roi->width; x++)
4027 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4028 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4029 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4030 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
4031 q+=GetPixelChannels(image);
4033 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4038 if (LocaleCompare(map,"RGBP") == 0)
4040 for (y=0; y < (ssize_t) roi->height; y++)
4042 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4043 if (q == (Quantum *) NULL)
4045 for (x=0; x < (ssize_t) roi->width; x++)
4047 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4048 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4049 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4051 q+=GetPixelChannels(image);
4053 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4059 for (y=0; y < (ssize_t) roi->height; y++)
4061 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4062 if (q == (Quantum *) NULL)
4064 for (x=0; x < (ssize_t) roi->width; x++)
4069 for (i=0; i < (ssize_t) length; i++)
4071 switch (quantum_map[i])
4076 SetPixelRed(image,ScaleShortToQuantum(*p),q);
4080 case MagentaQuantum:
4082 SetPixelGreen(image,ScaleShortToQuantum(*p),q);
4088 SetPixelBlue(image,ScaleShortToQuantum(*p),q);
4093 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
4096 case OpacityQuantum:
4098 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
4103 SetPixelBlack(image,ScaleShortToQuantum(*p),q);
4108 SetPixelGray(image,ScaleShortToQuantum(*p),q);
4116 q+=GetPixelChannels(image);
4118 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4123 MagickExport MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
4124 const ssize_t y,const size_t width,const size_t height,const char *map,
4125 const StorageType type,const void *pixels,ExceptionInfo *exception)
4140 Allocate image structure.
4142 assert(image != (Image *) NULL);
4143 assert(image->signature == MagickCoreSignature);
4144 if (image->debug != MagickFalse)
4145 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4147 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
4148 if (quantum_map == (QuantumType *) NULL)
4149 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
4151 for (i=0; i < (ssize_t) length; i++)
4158 quantum_map[i]=AlphaQuantum;
4159 image->alpha_trait=BlendPixelTrait;
4165 quantum_map[i]=BlueQuantum;
4171 quantum_map[i]=CyanQuantum;
4172 (void) SetImageColorspace(image,CMYKColorspace,exception);
4178 quantum_map[i]=GreenQuantum;
4184 quantum_map[i]=BlackQuantum;
4185 (void) SetImageColorspace(image,CMYKColorspace,exception);
4191 quantum_map[i]=IndexQuantum;
4192 (void) SetImageColorspace(image,GRAYColorspace,exception);
4198 quantum_map[i]=MagentaQuantum;
4199 (void) SetImageColorspace(image,CMYKColorspace,exception);
4205 quantum_map[i]=OpacityQuantum;
4206 image->alpha_trait=BlendPixelTrait;
4212 quantum_map[i]=UndefinedQuantum;
4218 quantum_map[i]=RedQuantum;
4224 quantum_map[i]=YellowQuantum;
4225 (void) SetImageColorspace(image,CMYKColorspace,exception);
4230 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4231 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4232 "UnrecognizedPixelMap","`%s'",map);
4233 return(MagickFalse);
4237 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
4238 return(MagickFalse);
4240 Transfer the pixels from the pixel data to the image.
4250 ImportCharPixel(image,&roi,map,quantum_map,pixels,exception);
4255 ImportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
4260 ImportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
4265 ImportLongPixel(image,&roi,map,quantum_map,pixels,exception);
4270 ImportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
4275 ImportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
4280 ImportShortPixel(image,&roi,map,quantum_map,pixels,exception);
4285 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4286 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4287 "UnrecognizedStorageType","`%d'",type);
4291 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4300 + 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 %
4304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4306 % InitializePixelChannelMap() defines the standard pixel component map.
4308 % The format of the InitializePixelChannelMap() method is:
4310 % void InitializePixelChannelMap(Image *image)
4312 % A description of each parameter follows:
4314 % o image: the image.
4317 MagickExport void InitializePixelChannelMap(Image *image)
4328 assert(image != (Image *) NULL);
4329 assert(image->signature == MagickCoreSignature);
4330 (void) ResetMagickMemory(image->channel_map,0,MaxPixelChannels*
4331 sizeof(*image->channel_map));
4332 trait=UpdatePixelTrait;
4333 if (image->alpha_trait != UndefinedPixelTrait)
4334 trait=(PixelTrait) (trait | BlendPixelTrait);
4336 if (image->colorspace == GRAYColorspace)
4338 SetPixelChannelAttributes(image,BluePixelChannel,trait,n);
4339 SetPixelChannelAttributes(image,GreenPixelChannel,trait,n);
4340 SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
4344 SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
4345 SetPixelChannelAttributes(image,GreenPixelChannel,trait,n++);
4346 SetPixelChannelAttributes(image,BluePixelChannel,trait,n++);
4348 if (image->colorspace == CMYKColorspace)
4349 SetPixelChannelAttributes(image,BlackPixelChannel,trait,n++);
4350 for (i=0; i < (ssize_t) image->number_meta_channels; i++)
4352 SetPixelChannelAttributes(image,(PixelChannel) n,UpdatePixelTrait,n);
4355 if (image->alpha_trait != UndefinedPixelTrait)
4356 SetPixelChannelAttributes(image,AlphaPixelChannel,CopyPixelTrait,n++);
4357 if (image->storage_class == PseudoClass)
4358 SetPixelChannelAttributes(image,IndexPixelChannel,CopyPixelTrait,n++);
4359 if (image->read_mask != MagickFalse)
4360 SetPixelChannelAttributes(image,ReadMaskPixelChannel,CopyPixelTrait,n++);
4361 if (image->write_mask != MagickFalse)
4362 SetPixelChannelAttributes(image,WriteMaskPixelChannel,CopyPixelTrait,n++);
4363 image->number_channels=(size_t) n;
4364 (void) SetPixelChannelMask(image,image->channel_mask);
4368 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4372 % I n t e r p o l a t e P i x e l C h a n n e l %
4376 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4378 % InterpolatePixelChannel() applies a pixel interpolation method between a
4379 % floating point coordinate and the pixels surrounding that coordinate. No
4380 % pixel area resampling, or scaling of the result is performed.
4382 % Interpolation is restricted to just the specified channel.
4384 % The format of the InterpolatePixelChannel method is:
4386 % MagickBooleanType InterpolatePixelChannel(const Image *image,
4387 % const CacheView *image_view,const PixelChannel channel,
4388 % const PixelInterpolateMethod method,const double x,const double y,
4389 % double *pixel,ExceptionInfo *exception)
4391 % A description of each parameter follows:
4393 % o image: the image.
4395 % o image_view: the image view.
4397 % o channel: the pixel channel to interpolate.
4399 % o method: the pixel color interpolation method.
4401 % o x,y: A double representing the current (x,y) position of the pixel.
4403 % o pixel: return the interpolated pixel here.
4405 % o exception: return any errors or warnings in this structure.
4409 static inline void CatromWeights(const double x,double (*weights)[4])
4417 Nicolas Robidoux' 10 flops (4* + 5- + 1+) refactoring of the computation
4418 of the standard four 1D Catmull-Rom weights. The sampling location is
4419 assumed between the second and third input pixel locations, and x is the
4420 position relative to the second input pixel location. Formulas originally
4421 derived for the VIPS (Virtual Image Processing System) library.
4423 alpha=(double) 1.0-x;
4424 beta=(double) (-0.5)*x*alpha;
4425 (*weights)[0]=alpha*beta;
4426 (*weights)[3]=x*beta;
4428 The following computation of the inner weights from the outer ones work
4429 for all Keys cubics.
4431 gamma=(*weights)[3]-(*weights)[0];
4432 (*weights)[1]=alpha-(*weights)[0]+gamma;
4433 (*weights)[2]=x-(*weights)[3]-gamma;
4436 static inline void SplineWeights(const double x,double (*weights)[4])
4443 Nicolas Robidoux' 12 flops (6* + 5- + 1+) refactoring of the computation
4444 of the standard four 1D cubic B-spline smoothing weights. The sampling
4445 location is assumed between the second and third input pixel locations,
4446 and x is the position relative to the second input pixel location.
4448 alpha=(double) 1.0-x;
4449 (*weights)[3]=(double) (1.0/6.0)*x*x*x;
4450 (*weights)[0]=(double) (1.0/6.0)*alpha*alpha*alpha;
4451 beta=(*weights)[3]-(*weights)[0];
4452 (*weights)[1]=alpha-(*weights)[0]+beta;
4453 (*weights)[2]=x-(*weights)[3]-beta;
4456 static inline double MeshInterpolate(const PointInfo *delta,const double p,
4457 const double x,const double y)
4459 return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
4463 static inline ssize_t NearestNeighbor(const double x)
4466 return((ssize_t) (x+0.5));
4467 return((ssize_t) (x-0.5));
4471 MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
4472 const CacheView_ *image_view,const PixelChannel channel,
4473 const PixelInterpolateMethod method,const double x,const double y,
4474 double *pixel,ExceptionInfo *exception)
4484 PixelInterpolateMethod
4490 register const Quantum
4500 assert(image != (Image *) NULL);
4501 assert(image->signature == MagickCoreSignature);
4502 assert(image_view != (CacheView *) NULL);
4505 traits=GetPixelChannelTraits(image,channel);
4506 x_offset=(ssize_t) floor(x);
4507 y_offset=(ssize_t) floor(y);
4509 if (interpolate == UndefinedInterpolatePixel)
4510 interpolate=image->interpolate;
4511 switch (interpolate)
4513 case AverageInterpolatePixel: /* nearest 4 neighbours */
4514 case Average9InterpolatePixel: /* nearest 9 neighbours */
4515 case Average16InterpolatePixel: /* nearest 16 neighbours */
4520 count=2; /* size of the area to average - default nearest 4 */
4521 if (interpolate == Average9InterpolatePixel)
4524 x_offset=(ssize_t) (floor(x+0.5)-1);
4525 y_offset=(ssize_t) (floor(y+0.5)-1);
4528 if (interpolate == Average16InterpolatePixel)
4534 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,(size_t) count,
4535 (size_t) count,exception);
4536 if (p == (const Quantum *) NULL)
4541 count*=count; /* Number of pixels to average */
4542 if ((traits & BlendPixelTrait) == 0)
4543 for (i=0; i < (ssize_t) count; i++)
4546 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4549 for (i=0; i < (ssize_t) count; i++)
4551 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4552 GetPixelChannels(image));
4553 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4555 for (i=0; i < (ssize_t) count; i++)
4557 gamma=PerceptibleReciprocal(alpha[i])/count;
4558 *pixel+=gamma*pixels[i];
4562 case BilinearInterpolatePixel:
4569 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4570 if (p == (const Quantum *) NULL)
4575 if ((traits & BlendPixelTrait) == 0)
4576 for (i=0; i < 4; i++)
4579 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4582 for (i=0; i < 4; i++)
4584 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4585 GetPixelChannels(image));
4586 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4590 epsilon.x=1.0-delta.x;
4591 epsilon.y=1.0-delta.y;
4592 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4593 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4594 gamma=PerceptibleReciprocal(gamma);
4595 *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
4596 (epsilon.x*pixels[2]+delta.x*pixels[3]));
4599 case BlendInterpolatePixel:
4601 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4602 if (p == (const Quantum *) NULL)
4607 if ((traits & BlendPixelTrait) == 0)
4608 for (i=0; i < 4; i++)
4611 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4614 for (i=0; i < 4; i++)
4616 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4617 GetPixelChannels(image));
4618 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4620 gamma=1.0; /* number of pixels blended together (its variable) */
4621 for (i=0; i <= 1L; i++) {
4622 if ((y-y_offset) >= 0.75)
4624 alpha[i]=alpha[i+2]; /* take right pixels */
4625 pixels[i]=pixels[i+2];
4628 if ((y-y_offset) > 0.25)
4630 gamma=2.0; /* blend both pixels in row */
4631 alpha[i]+=alpha[i+2]; /* add up alpha weights */
4632 pixels[i]+=pixels[i+2];
4635 if ((x-x_offset) >= 0.75)
4637 alpha[0]=alpha[1]; /* take bottom row blend */
4638 pixels[0]=pixels[1];
4641 if ((x-x_offset) > 0.25)
4643 gamma*=2.0; /* blend both rows */
4644 alpha[0]+=alpha[1]; /* add up alpha weights */
4645 pixels[0]+=pixels[1];
4647 if (channel != AlphaPixelChannel)
4648 gamma=PerceptibleReciprocal(alpha[0]); /* (color) 1/alpha_weights */
4650 gamma=PerceptibleReciprocal(gamma); /* (alpha) 1/number_of_pixels */
4651 *pixel=gamma*pixels[0];
4654 case CatromInterpolatePixel:
4660 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4662 if (p == (const Quantum *) NULL)
4667 if ((traits & BlendPixelTrait) == 0)
4668 for (i=0; i < 16; i++)
4671 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4674 for (i=0; i < 16; i++)
4676 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4677 GetPixelChannels(image));
4678 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4680 CatromWeights((double) (x-x_offset),&cx);
4681 CatromWeights((double) (y-y_offset),&cy);
4682 gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4683 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4684 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4685 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4686 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4687 cx[2]*alpha[14]+cx[3]*alpha[15])));
4688 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4689 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4690 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4691 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4692 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4695 case IntegerInterpolatePixel:
4697 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4698 if (p == (const Quantum *) NULL)
4703 *pixel=(double) GetPixelChannel(image,channel,p);
4706 case NearestInterpolatePixel:
4708 x_offset=(ssize_t) floor(x+0.5);
4709 y_offset=(ssize_t) floor(y+0.5);
4710 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4711 if (p == (const Quantum *) NULL)
4716 *pixel=(double) GetPixelChannel(image,channel,p);
4719 case MeshInterpolatePixel:
4725 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4726 if (p == (const Quantum *) NULL)
4731 if ((traits & BlendPixelTrait) == 0)
4732 for (i=0; i < 4; i++)
4735 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4738 for (i=0; i < 4; i++)
4740 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4741 GetPixelChannels(image));
4742 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4746 luminance.x=GetPixelLuma(image,p)-(double)
4747 GetPixelLuma(image,p+3*GetPixelChannels(image));
4748 luminance.y=GetPixelLuma(image,p+GetPixelChannels(image))-(double)
4749 GetPixelLuma(image,p+2*GetPixelChannels(image));
4750 if (fabs(luminance.x) < fabs(luminance.y))
4755 if (delta.x <= delta.y)
4758 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4760 delta.y=1.0-delta.y;
4761 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4762 gamma=PerceptibleReciprocal(gamma);
4763 *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
4769 Top-right triangle (pixel: 1, diagonal: 0-3).
4771 delta.x=1.0-delta.x;
4772 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4773 gamma=PerceptibleReciprocal(gamma);
4774 *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
4783 if (delta.x <= (1.0-delta.y))
4786 Top-left triangle (pixel: 0, diagonal: 1-2).
4788 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4789 gamma=PerceptibleReciprocal(gamma);
4790 *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
4796 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4798 delta.x=1.0-delta.x;
4799 delta.y=1.0-delta.y;
4800 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4801 gamma=PerceptibleReciprocal(gamma);
4802 *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
4808 case SplineInterpolatePixel:
4814 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4816 if (p == (const Quantum *) NULL)
4821 if ((traits & BlendPixelTrait) == 0)
4822 for (i=0; i < 16; i++)
4825 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4828 for (i=0; i < 16; i++)
4830 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4831 GetPixelChannels(image));
4832 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4834 SplineWeights((double) (x-x_offset),&cx);
4835 SplineWeights((double) (y-y_offset),&cy);
4836 gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4837 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4838 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4839 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4840 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4841 cx[2]*alpha[14]+cx[3]*alpha[15])));
4842 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4843 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4844 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4845 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4846 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4854 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4858 % I n t e r p o l a t e P i x e l C h a n n e l s %
4862 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4864 % InterpolatePixelChannels() applies a pixel interpolation method between a
4865 % floating point coordinate and the pixels surrounding that coordinate. No
4866 % pixel area resampling, or scaling of the result is performed.
4868 % Interpolation is restricted to just the current channel setting of the
4869 % destination image into which the color is to be stored
4871 % The format of the InterpolatePixelChannels method is:
4873 % MagickBooleanType InterpolatePixelChannels(const Image *source,
4874 % const CacheView *source_view,const Image *destination,
4875 % const PixelInterpolateMethod method,const double x,const double y,
4876 % Quantum *pixel,ExceptionInfo *exception)
4878 % A description of each parameter follows:
4880 % o source: the source.
4882 % o source_view: the source view.
4884 % o destination: the destination image, for the interpolated color
4886 % o method: the pixel color interpolation method.
4888 % o x,y: A double representing the current (x,y) position of the pixel.
4890 % o pixel: return the interpolated pixel here.
4892 % o exception: return any errors or warnings in this structure.
4895 MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
4896 const CacheView_ *source_view,const Image *destination,
4897 const PixelInterpolateMethod method,const double x,const double y,
4898 Quantum *pixel,ExceptionInfo *exception)
4908 register const Quantum
4918 PixelInterpolateMethod
4921 assert(source != (Image *) NULL);
4922 assert(source->signature == MagickCoreSignature);
4923 assert(source_view != (CacheView *) NULL);
4925 x_offset=(ssize_t) floor(x);
4926 y_offset=(ssize_t) floor(y);
4928 if (interpolate == UndefinedInterpolatePixel)
4929 interpolate=source->interpolate;
4930 switch (interpolate)
4932 case AverageInterpolatePixel: /* nearest 4 neighbours */
4933 case Average9InterpolatePixel: /* nearest 9 neighbours */
4934 case Average16InterpolatePixel: /* nearest 16 neighbours */
4939 count=2; /* size of the area to average - default nearest 4 */
4940 if (interpolate == Average9InterpolatePixel)
4943 x_offset=(ssize_t) (floor(x+0.5)-1);
4944 y_offset=(ssize_t) (floor(y+0.5)-1);
4947 if (interpolate == Average16InterpolatePixel)
4953 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,(size_t) count,
4954 (size_t) count,exception);
4955 if (p == (const Quantum *) NULL)
4960 count*=count; /* Number of pixels to average */
4961 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4969 PixelChannel channel = GetPixelChannelChannel(source,i);
4970 PixelTrait traits = GetPixelChannelTraits(source,channel);
4971 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4973 if ((traits == UndefinedPixelTrait) ||
4974 (destination_traits == UndefinedPixelTrait))
4976 for (j=0; j < (ssize_t) count; j++)
4977 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
4979 if ((traits & BlendPixelTrait) == 0)
4981 for (j=0; j < (ssize_t) count; j++)
4984 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4987 for (j=0; j < (ssize_t) count; j++)
4989 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4990 GetPixelChannels(source));
4991 pixels[j]*=alpha[j];
4992 gamma=PerceptibleReciprocal(alpha[j]);
4993 sum+=gamma*pixels[j];
4996 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
5000 case BilinearInterpolatePixel:
5003 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
5004 if (p == (const Quantum *) NULL)
5009 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5015 PixelChannel channel = GetPixelChannelChannel(source,i);
5016 PixelTrait traits = GetPixelChannelTraits(source,channel);
5017 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5019 if ((traits == UndefinedPixelTrait) ||
5020 (destination_traits == UndefinedPixelTrait))
5024 epsilon.x=1.0-delta.x;
5025 epsilon.y=1.0-delta.y;
5026 pixels[0]=(double) p[i];
5027 pixels[1]=(double) p[GetPixelChannels(source)+i];
5028 pixels[2]=(double) p[2*GetPixelChannels(source)+i];
5029 pixels[3]=(double) p[3*GetPixelChannels(source)+i];
5030 if ((traits & BlendPixelTrait) == 0)
5032 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5033 gamma=PerceptibleReciprocal(gamma);
5034 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
5035 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*
5036 pixels[2]+delta.x*pixels[3]))),pixel);
5039 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
5040 alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source));
5041 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
5042 GetPixelChannels(source));
5043 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
5044 GetPixelChannels(source));
5045 pixels[0]*=alpha[0];
5046 pixels[1]*=alpha[1];
5047 pixels[2]*=alpha[2];
5048 pixels[3]*=alpha[3];
5049 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5050 (epsilon.x*alpha[2]+delta.x*alpha[3])));
5051 gamma=PerceptibleReciprocal(gamma);
5052 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
5053 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+
5054 delta.x*pixels[3]))),pixel);
5058 case BlendInterpolatePixel:
5060 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
5061 if (p == (const Quantum *) NULL)
5066 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5071 PixelChannel channel = GetPixelChannelChannel(source,i);
5072 PixelTrait traits = GetPixelChannelTraits(source,channel);
5073 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5075 if ((traits == UndefinedPixelTrait) ||
5076 (destination_traits == UndefinedPixelTrait))
5078 if (source->alpha_trait != BlendPixelTrait)
5079 for (j=0; j < 4; j++)
5082 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
5085 for (j=0; j < 4; j++)
5087 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
5088 GetPixelChannels(source));
5089 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
5090 if (channel != AlphaPixelChannel)
5091 pixels[j]*=alpha[j];
5093 gamma=1.0; /* number of pixels blended together (its variable) */
5094 for (j=0; j <= 1L; j++)
5096 if ((y-y_offset) >= 0.75)
5098 alpha[j]=alpha[j+2]; /* take right pixels */
5099 pixels[j]=pixels[j+2];
5102 if ((y-y_offset) > 0.25)
5104 gamma=2.0; /* blend both pixels in row */
5105 alpha[j]+=alpha[j+2]; /* add up alpha weights */
5106 pixels[j]+=pixels[j+2];
5109 if ((x-x_offset) >= 0.75)
5111 alpha[0]=alpha[1]; /* take bottom row blend */
5112 pixels[0]=pixels[1];
5115 if ((x-x_offset) > 0.25)
5117 gamma*=2.0; /* blend both rows */
5118 alpha[0]+=alpha[1]; /* add up alpha weights */
5119 pixels[0]+=pixels[1];
5121 if (channel != AlphaPixelChannel)
5122 gamma=PerceptibleReciprocal(alpha[0]); /* (color) 1/alpha_weights */
5124 gamma=PerceptibleReciprocal(gamma); /* (alpha) 1/number_of_pixels */
5125 SetPixelChannel(destination,channel,ClampToQuantum(gamma*pixels[0]),
5130 case CatromInterpolatePixel:
5136 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
5138 if (p == (const Quantum *) NULL)
5143 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5148 PixelChannel channel = GetPixelChannelChannel(source,i);
5149 PixelTrait traits = GetPixelChannelTraits(source,channel);
5150 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5152 if ((traits == UndefinedPixelTrait) ||
5153 (destination_traits == UndefinedPixelTrait))
5155 if ((traits & BlendPixelTrait) == 0)
5156 for (j=0; j < 16; j++)
5159 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
5162 for (j=0; j < 16; j++)
5164 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
5165 GetPixelChannels(source));
5166 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
5168 CatromWeights((double) (x-x_offset),&cx);
5169 CatromWeights((double) (y-y_offset),&cy);
5170 gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
5171 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
5172 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
5173 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
5174 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
5175 cx[2]*alpha[14]+cx[3]*alpha[15])));
5176 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
5177 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
5178 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
5179 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
5180 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
5181 pixels[14]+cx[3]*pixels[15]))),pixel);
5185 case IntegerInterpolatePixel:
5187 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
5188 if (p == (const Quantum *) NULL)
5193 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5195 PixelChannel channel = GetPixelChannelChannel(source,i);
5196 PixelTrait traits = GetPixelChannelTraits(source,channel);
5197 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5199 if ((traits == UndefinedPixelTrait) ||
5200 (destination_traits == UndefinedPixelTrait))
5202 SetPixelChannel(destination,channel,p[i],pixel);
5206 case NearestInterpolatePixel:
5208 x_offset=(ssize_t) floor(x+0.5);
5209 y_offset=(ssize_t) floor(y+0.5);
5210 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
5211 if (p == (const Quantum *) NULL)
5216 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5218 PixelChannel channel = GetPixelChannelChannel(source,i);
5219 PixelTrait traits = GetPixelChannelTraits(source,channel);
5220 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5222 if ((traits == UndefinedPixelTrait) ||
5223 (destination_traits == UndefinedPixelTrait))
5225 SetPixelChannel(destination,channel,p[i],pixel);
5229 case MeshInterpolatePixel:
5231 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
5232 if (p == (const Quantum *) NULL)
5237 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5243 PixelChannel channel = GetPixelChannelChannel(source,i);
5244 PixelTrait traits = GetPixelChannelTraits(source,channel);
5245 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5247 if ((traits == UndefinedPixelTrait) ||
5248 (destination_traits == UndefinedPixelTrait))
5250 pixels[0]=(double) p[i];
5251 pixels[1]=(double) p[GetPixelChannels(source)+i];
5252 pixels[2]=(double) p[2*GetPixelChannels(source)+i];
5253 pixels[3]=(double) p[3*GetPixelChannels(source)+i];
5254 if ((traits & BlendPixelTrait) == 0)
5263 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
5264 alpha[1]=QuantumScale*GetPixelAlpha(source,p+
5265 GetPixelChannels(source));
5266 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
5267 GetPixelChannels(source));
5268 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
5269 GetPixelChannels(source));
5273 luminance.x=fabs((double) (GetPixelLuma(source,p)-
5274 GetPixelLuma(source,p+3*GetPixelChannels(source))));
5275 luminance.y=fabs((double) (GetPixelLuma(source,p+
5276 GetPixelChannels(source))-GetPixelLuma(source,p+2*
5277 GetPixelChannels(source))));
5278 if (luminance.x < luminance.y)
5283 if (delta.x <= delta.y)
5286 Bottom-left triangle (pixel: 2, diagonal: 0-3).
5288 delta.y=1.0-delta.y;
5289 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5290 gamma=PerceptibleReciprocal(gamma);
5291 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5292 MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel);
5297 Top-right triangle (pixel: 1, diagonal: 0-3).
5299 delta.x=1.0-delta.x;
5300 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5301 gamma=PerceptibleReciprocal(gamma);
5302 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5303 MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel);
5311 if (delta.x <= (1.0-delta.y))
5314 Top-left triangle (pixel: 0, diagonal: 1-2).
5316 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5317 gamma=PerceptibleReciprocal(gamma);
5318 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5319 MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel);
5324 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5326 delta.x=1.0-delta.x;
5327 delta.y=1.0-delta.y;
5328 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5329 gamma=PerceptibleReciprocal(gamma);
5330 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5331 MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel);
5337 case SplineInterpolatePixel:
5343 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
5345 if (p == (const Quantum *) NULL)
5350 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5355 PixelChannel channel = GetPixelChannelChannel(source,i);
5356 PixelTrait traits = GetPixelChannelTraits(source,channel);
5357 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5359 if ((traits == UndefinedPixelTrait) ||
5360 (destination_traits == UndefinedPixelTrait))
5362 if ((traits & BlendPixelTrait) == 0)
5363 for (j=0; j < 16; j++)
5366 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
5369 for (j=0; j < 16; j++)
5371 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
5372 GetPixelChannels(source));
5373 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
5375 SplineWeights((double) (x-x_offset),&cx);
5376 SplineWeights((double) (y-y_offset),&cy);
5377 gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
5378 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
5379 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
5380 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
5381 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
5382 cx[2]*alpha[14]+cx[3]*alpha[15])));
5383 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
5384 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
5385 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
5386 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
5387 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
5388 pixels[14]+cx[3]*pixels[15]))),pixel);
5397 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5401 % I n t e r p o l a t e P i x e l I n f o %
5405 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5407 % InterpolatePixelInfo() applies a pixel interpolation method between a
5408 % floating point coordinate and the pixels surrounding that coordinate. No
5409 % pixel area resampling, or scaling of the result is performed.
5411 % Interpolation is restricted to just RGBKA channels.
5413 % The format of the InterpolatePixelInfo method is:
5415 % MagickBooleanType InterpolatePixelInfo(const Image *image,
5416 % const CacheView *image_view,const PixelInterpolateMethod method,
5417 % const double x,const double y,PixelInfo *pixel,
5418 % ExceptionInfo *exception)
5420 % A description of each parameter follows:
5422 % o image: the image.
5424 % o image_view: the image view.
5426 % o method: the pixel color interpolation method.
5428 % o x,y: A double representing the current (x,y) position of the pixel.
5430 % o pixel: return the interpolated pixel here.
5432 % o exception: return any errors or warnings in this structure.
5436 static inline void AlphaBlendPixelInfo(const Image *image,
5437 const Quantum *pixel,PixelInfo *pixel_info,double *alpha)
5439 if (image->alpha_trait == UndefinedPixelTrait)
5442 pixel_info->red=(double) GetPixelRed(image,pixel);
5443 pixel_info->green=(double) GetPixelGreen(image,pixel);
5444 pixel_info->blue=(double) GetPixelBlue(image,pixel);
5445 pixel_info->black=0.0;
5446 if (image->colorspace == CMYKColorspace)
5447 pixel_info->black=(double) GetPixelBlack(image,pixel);
5448 pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5451 *alpha=QuantumScale*GetPixelAlpha(image,pixel);
5452 pixel_info->red=(*alpha*GetPixelRed(image,pixel));
5453 pixel_info->green=(*alpha*GetPixelGreen(image,pixel));
5454 pixel_info->blue=(*alpha*GetPixelBlue(image,pixel));
5455 pixel_info->black=0.0;
5456 if (image->colorspace == CMYKColorspace)
5457 pixel_info->black=(*alpha*GetPixelBlack(image,pixel));
5458 pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5461 MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
5462 const CacheView_ *image_view,const PixelInterpolateMethod method,
5463 const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception)
5475 register const Quantum
5485 PixelInterpolateMethod
5488 assert(image != (Image *) NULL);
5489 assert(image->signature == MagickCoreSignature);
5490 assert(image_view != (CacheView *) NULL);
5492 x_offset=(ssize_t) floor(x);
5493 y_offset=(ssize_t) floor(y);
5495 if (interpolate == UndefinedInterpolatePixel)
5496 interpolate=image->interpolate;
5497 (void) ResetMagickMemory(&pixels,0,sizeof(pixels));
5498 switch (interpolate)
5500 case AverageInterpolatePixel: /* nearest 4 neighbours */
5501 case Average9InterpolatePixel: /* nearest 9 neighbours */
5502 case Average16InterpolatePixel: /* nearest 16 neighbours */
5507 count=2; /* size of the area to average - default nearest 4 */
5508 if (interpolate == Average9InterpolatePixel)
5511 x_offset=(ssize_t) (floor(x+0.5)-1);
5512 y_offset=(ssize_t) (floor(y+0.5)-1);
5514 else if (interpolate == Average16InterpolatePixel)
5520 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,(size_t) count,
5521 (size_t) count,exception);
5522 if (p == (const Quantum *) NULL)
5532 count*=count; /* number of pixels - square of size */
5533 for (i=0; i < (ssize_t) count; i++)
5535 AlphaBlendPixelInfo(image,p,pixels,alpha);
5536 gamma=PerceptibleReciprocal(alpha[0]);
5537 pixel->red+=gamma*pixels[0].red;
5538 pixel->green+=gamma*pixels[0].green;
5539 pixel->blue+=gamma*pixels[0].blue;
5540 pixel->black+=gamma*pixels[0].black;
5541 pixel->alpha+=pixels[0].alpha;
5542 p += GetPixelChannels(image);
5544 gamma=1.0/count; /* average weighting of each pixel in area */
5546 pixel->green*=gamma;
5548 pixel->black*=gamma;
5549 pixel->alpha*=gamma;
5552 case BackgroundInterpolatePixel:
5554 *pixel=image->background_color; /* Copy PixelInfo Structure */
5557 case BilinearInterpolatePixel:
5564 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5565 if (p == (const Quantum *) NULL)
5570 for (i=0; i < 4L; i++)
5571 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5574 epsilon.x=1.0-delta.x;
5575 epsilon.y=1.0-delta.y;
5576 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5577 (epsilon.x*alpha[2]+delta.x*alpha[3])));
5578 gamma=PerceptibleReciprocal(gamma);
5579 pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
5580 pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red));
5581 pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x*
5582 pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x*
5584 pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x*
5585 pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x*
5587 if (image->colorspace == CMYKColorspace)
5588 pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x*
5589 pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x*
5591 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5592 gamma=PerceptibleReciprocal(gamma);
5593 pixel->alpha=gamma*(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x*
5594 pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x*
5598 case BlendInterpolatePixel:
5600 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5601 if (p == (const Quantum *) NULL)
5606 for (i=0; i < 4L; i++)
5608 GetPixelInfoPixel(image,p+i*GetPixelChannels(image),pixels+i);
5609 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5611 gamma=1.0; /* number of pixels blended together (its variable) */
5612 for (i=0; i <= 1L; i++)
5614 if ((y-y_offset) >= 0.75)
5616 alpha[i]=alpha[i+2]; /* take right pixels */
5617 pixels[i]=pixels[i+2];
5620 if ((y-y_offset) > 0.25)
5622 gamma=2.0; /* blend both pixels in row */
5623 alpha[i]+=alpha[i+2]; /* add up alpha weights */
5624 pixels[i].red+=pixels[i+2].red;
5625 pixels[i].green+=pixels[i+2].green;
5626 pixels[i].blue+=pixels[i+2].blue;
5627 pixels[i].black+=pixels[i+2].black;
5628 pixels[i].alpha+=pixels[i+2].alpha;
5631 if ((x-x_offset) >= 0.75)
5634 pixels[0]=pixels[1];
5637 if ((x-x_offset) > 0.25)
5639 gamma*=2.0; /* blend both rows */
5640 alpha[0]+= alpha[1]; /* add up alpha weights */
5641 pixels[0].red+=pixels[1].red;
5642 pixels[0].green+=pixels[1].green;
5643 pixels[0].blue+=pixels[1].blue;
5644 pixels[0].black+=pixels[1].black;
5645 pixels[0].alpha+=pixels[1].alpha;
5648 alpha[0]=PerceptibleReciprocal(alpha[0]);
5649 pixel->red=alpha[0]*pixels[0].red;
5650 pixel->green=alpha[0]*pixels[0].green; /* divide by sum of alpha */
5651 pixel->blue=alpha[0]*pixels[0].blue;
5652 pixel->black=alpha[0]*pixels[0].black;
5653 pixel->alpha=gamma*pixels[0].alpha; /* divide by number of pixels */
5656 case CatromInterpolatePixel:
5662 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5664 if (p == (const Quantum *) NULL)
5669 for (i=0; i < 16L; i++)
5670 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5671 CatromWeights((double) (x-x_offset),&cx);
5672 CatromWeights((double) (y-y_offset),&cy);
5673 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]*
5674 pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5675 pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]*
5676 pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5677 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]*
5678 pixels[14].red+cx[3]*pixels[15].red));
5679 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]*
5680 pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+
5681 cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+
5682 cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]*
5683 pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]*
5684 pixels[12].green+cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]*
5686 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]*
5687 pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5688 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]*
5689 pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5690 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+
5691 cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5692 if (image->colorspace == CMYKColorspace)
5693 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]*
5694 pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+
5695 cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+
5696 cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]*
5697 pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]*
5698 pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]*
5700 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]*
5701 pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+
5702 cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+
5703 cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]*
5704 pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+
5705 cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5708 case IntegerInterpolatePixel:
5710 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5711 if (p == (const Quantum *) NULL)
5716 GetPixelInfoPixel(image,p,pixel);
5719 case MeshInterpolatePixel:
5725 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5726 if (p == (const Quantum *) NULL)
5733 luminance.x=GetPixelLuma(image,p)-(double)
5734 GetPixelLuma(image,p+3*GetPixelChannels(image));
5735 luminance.y=GetPixelLuma(image,p+GetPixelChannels(image))-(double)
5736 GetPixelLuma(image,p+2*GetPixelChannels(image));
5737 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5738 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5739 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5740 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5741 if (fabs(luminance.x) < fabs(luminance.y))
5746 if (delta.x <= delta.y)
5749 Bottom-left triangle (pixel: 2, diagonal: 0-3).
5751 delta.y=1.0-delta.y;
5752 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5753 gamma=PerceptibleReciprocal(gamma);
5754 pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red,
5755 pixels[3].red,pixels[0].red);
5756 pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green,
5757 pixels[3].green,pixels[0].green);
5758 pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
5759 pixels[3].blue,pixels[0].blue);
5760 if (image->colorspace == CMYKColorspace)
5761 pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black,
5762 pixels[3].black,pixels[0].black);
5763 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5764 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha,
5765 pixels[3].alpha,pixels[0].alpha);
5770 Top-right triangle (pixel:1 , diagonal: 0-3).
5772 delta.x=1.0-delta.x;
5773 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5774 gamma=PerceptibleReciprocal(gamma);
5775 pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red,
5776 pixels[0].red,pixels[3].red);
5777 pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green,
5778 pixels[0].green,pixels[3].green);
5779 pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
5780 pixels[0].blue,pixels[3].blue);
5781 if (image->colorspace == CMYKColorspace)
5782 pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black,
5783 pixels[0].black,pixels[3].black);
5784 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5785 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha,
5786 pixels[0].alpha,pixels[3].alpha);
5794 if (delta.x <= (1.0-delta.y))
5797 Top-left triangle (pixel: 0, diagonal: 1-2).
5799 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5800 gamma=PerceptibleReciprocal(gamma);
5801 pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red,
5802 pixels[1].red,pixels[2].red);
5803 pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green,
5804 pixels[1].green,pixels[2].green);
5805 pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
5806 pixels[1].blue,pixels[2].blue);
5807 if (image->colorspace == CMYKColorspace)
5808 pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black,
5809 pixels[1].black,pixels[2].black);
5810 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5811 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha,
5812 pixels[1].alpha,pixels[2].alpha);
5817 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5819 delta.x=1.0-delta.x;
5820 delta.y=1.0-delta.y;
5821 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5822 gamma=PerceptibleReciprocal(gamma);
5823 pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red,
5824 pixels[2].red,pixels[1].red);
5825 pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green,
5826 pixels[2].green,pixels[1].green);
5827 pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
5828 pixels[2].blue,pixels[1].blue);
5829 if (image->colorspace == CMYKColorspace)
5830 pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black,
5831 pixels[2].black,pixels[1].black);
5832 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5833 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha,
5834 pixels[2].alpha,pixels[1].alpha);
5839 case NearestInterpolatePixel:
5841 x_offset=(ssize_t) floor(x+0.5);
5842 y_offset=(ssize_t) floor(y+0.5);
5843 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5844 if (p == (const Quantum *) NULL)
5849 GetPixelInfoPixel(image,p,pixel);
5852 case SplineInterpolatePixel:
5858 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5860 if (p == (const Quantum *) NULL)
5865 for (i=0; i < 16L; i++)
5866 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5867 SplineWeights((double) (x-x_offset),&cx);
5868 SplineWeights((double) (y-y_offset),&cy);
5869 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]*
5870 pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5871 pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]*
5872 pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5873 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]*
5874 pixels[14].red+cx[3]*pixels[15].red));
5875 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]*
5876 pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+
5877 cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+
5878 cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]*
5879 pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]*pixels[12].green+
5880 cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]*pixels[15].green));
5881 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]*
5882 pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5883 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]*
5884 pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5885 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+
5886 cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5887 if (image->colorspace == CMYKColorspace)
5888 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]*
5889 pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+
5890 cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+
5891 cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]*
5892 pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]*
5893 pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]*
5895 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]*
5896 pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+
5897 cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+
5898 cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]*
5899 pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+
5900 cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5908 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5912 + I s F u z z y E q u i v a l e n c e P i x e l %
5916 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5918 % IsFuzzyEquivalencePixel() returns MagickTrue if the distance between two
5919 % pixels is less than the specified distance in a linear three (or four)
5920 % dimensional color space.
5922 % The format of the IsFuzzyEquivalencePixel method is:
5924 % void IsFuzzyEquivalencePixel(const Image *source,const Quantum *p,
5925 % const Image *destination,const Quantum *q)
5927 % A description of each parameter follows:
5929 % o source: the source image.
5933 % o destination: the destination image.
5938 MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *source,
5939 const Quantum *p,const Image *destination,const Quantum *q)
5949 fuzz=GetFuzzyColorDistance(source,destination);
5952 if (source->alpha_trait != UndefinedPixelTrait ||
5953 destination->alpha_trait != UndefinedPixelTrait)
5956 Transparencies are involved - set alpha distance
5958 pixel=GetPixelAlpha(source,p)-(double) GetPixelAlpha(destination,q);
5959 distance=pixel*pixel;
5960 if (distance > fuzz)
5961 return(MagickFalse);
5963 Generate a alpha scaling factor to generate a 4D cone on colorspace
5964 Note that if one color is transparent, distance has no color component.
5966 if (source->alpha_trait != UndefinedPixelTrait)
5967 scale=QuantumScale*GetPixelAlpha(source,p);
5968 if (destination->alpha_trait != UndefinedPixelTrait)
5969 scale*=QuantumScale*GetPixelAlpha(destination,q);
5970 if (scale <= MagickEpsilon)
5974 RGB or CMY color cube
5976 distance*=3.0; /* rescale appropriately */
5978 pixel=GetPixelRed(source,p)-(double) GetPixelRed(destination,q);
5979 if ((source->colorspace == HSLColorspace) ||
5980 (source->colorspace == HSBColorspace) ||
5981 (source->colorspace == HWBColorspace))
5984 Compute an arc distance for hue. It should be a vector angle of
5985 'S'/'W' length with 'L'/'B' forming appropriate cones.
5987 if (fabs((double) pixel) > (QuantumRange/2))
5988 pixel-=QuantumRange;
5991 distance+=scale*pixel*pixel;
5992 if (distance > fuzz)
5993 return(MagickFalse);
5994 pixel=GetPixelGreen(source,p)-(double) GetPixelGreen(destination,q);
5995 distance+=scale*pixel*pixel;
5996 if (distance > fuzz)
5997 return(MagickFalse);
5998 pixel=GetPixelBlue(source,p)-(double) GetPixelBlue(destination,q);
5999 distance+=scale*pixel*pixel;
6000 if (distance > fuzz)
6001 return(MagickFalse);
6006 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6010 + 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 %
6014 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6016 % IsFuzzyEquivalencePixelInfo() returns true if the distance between two
6017 % colors is less than the specified distance in a linear three (or four)
6018 % dimensional color space.
6020 % This implements the equivalent of:
6021 % fuzz < sqrt(color_distance^2 * u.a*v.a + alpha_distance^2)
6023 % Which produces a multi-dimensional cone for that colorspace along the
6024 % transparency vector.
6026 % For example for an RGB:
6027 % color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3
6029 % See http://www.imagemagick.org/Usage/bugs/fuzz_distance/
6031 % Hue colorspace distances need more work. Hue is not a distance, it is an
6034 % A check that q is in the same color space as p should be made and the
6035 % appropriate mapping made. -- Anthony Thyssen 8 December 2010
6037 % The format of the IsFuzzyEquivalencePixelInfo method is:
6039 % MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
6040 % const PixelInfo *q)
6042 % A description of each parameter follows:
6049 MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
6060 fuzz=(double) MagickMax(MagickMax(p->fuzz,q->fuzz),(MagickRealType)
6065 if ((p->alpha_trait != UndefinedPixelTrait) ||
6066 (q->alpha_trait != UndefinedPixelTrait))
6069 Transparencies are involved - set alpha distance.
6071 pixel=(p->alpha_trait != UndefinedPixelTrait ? p->alpha : OpaqueAlpha)-
6072 (q->alpha_trait != UndefinedPixelTrait ? q->alpha : OpaqueAlpha);
6073 distance=pixel*pixel;
6074 if (distance > fuzz)
6075 return(MagickFalse);
6077 Generate a alpha scaling factor to generate a 4D cone on colorspace.
6078 If one color is transparent, distance has no color component.
6080 if (p->alpha_trait != UndefinedPixelTrait)
6081 scale=(QuantumScale*p->alpha);
6082 if (q->alpha_trait != UndefinedPixelTrait)
6083 scale*=(QuantumScale*q->alpha);
6084 if (scale <= MagickEpsilon )
6088 CMYK create a CMY cube with a multi-dimensional cone toward black.
6090 if (p->colorspace == CMYKColorspace)
6092 pixel=p->black-q->black;
6093 distance+=pixel*pixel*scale;
6094 if (distance > fuzz)
6095 return(MagickFalse);
6096 scale*=(double) (QuantumScale*(QuantumRange-p->black));
6097 scale*=(double) (QuantumScale*(QuantumRange-q->black));
6100 RGB or CMY color cube.
6102 distance*=3.0; /* rescale appropriately */
6104 pixel=p->red-q->red;
6105 if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) ||
6106 (p->colorspace == HWBColorspace))
6109 This calculates a arc distance for hue-- it should be a vector
6110 angle of 'S'/'W' length with 'L'/'B' forming appropriate cones.
6111 In other words this is a hack - Anthony.
6113 if (fabs((double) pixel) > (QuantumRange/2))
6114 pixel-=QuantumRange;
6117 distance+=pixel*pixel*scale;
6118 if (distance > fuzz)
6119 return(MagickFalse);
6120 pixel=p->green-q->green;
6121 distance+=pixel*pixel*scale;
6122 if (distance > fuzz)
6123 return(MagickFalse);
6124 pixel=p->blue-q->blue;
6125 distance+=pixel*pixel*scale;
6126 if (distance > fuzz)
6127 return(MagickFalse);
6132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6136 % S e t P i x e l C h a n n e l M a s k %
6140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6142 % SetPixelChannelMask() sets the pixel channel map from the specified channel
6145 % The format of the SetPixelChannelMask method is:
6147 % ChannelType SetPixelChannelMask(Image *image,
6148 % const ChannelType channel_mask)
6150 % A description of each parameter follows:
6152 % o image: the image.
6154 % o channel_mask: the channel mask.
6158 static void LogPixelChannels(const Image *image)
6163 (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%08x]",
6164 image->filename,image->channel_mask);
6165 for (i=0; i < (ssize_t) image->number_channels; i++)
6168 channel_name[MagickPathExtent],
6169 traits[MagickPathExtent];
6177 channel=GetPixelChannelChannel(image,i);
6180 case RedPixelChannel:
6183 if (image->colorspace == CMYKColorspace)
6185 if (image->colorspace == GRAYColorspace)
6189 case GreenPixelChannel:
6192 if (image->colorspace == CMYKColorspace)
6196 case BluePixelChannel:
6199 if (image->colorspace == CMYKColorspace)
6203 case BlackPixelChannel:
6206 if (image->storage_class == PseudoClass)
6210 case IndexPixelChannel:
6215 case AlphaPixelChannel:
6220 case ReadMaskPixelChannel:
6225 case WriteMaskPixelChannel:
6230 case MetaPixelChannel:
6238 if (image->colorspace == UndefinedColorspace)
6240 (void) FormatLocaleString(channel_name,MagickPathExtent,"%.20g",
6242 name=(const char *) channel_name;
6245 if ((GetPixelChannelTraits(image,channel) & UpdatePixelTrait) != 0)
6246 (void) ConcatenateMagickString(traits,"update,",MagickPathExtent);
6247 if ((GetPixelChannelTraits(image,channel) & BlendPixelTrait) != 0)
6248 (void) ConcatenateMagickString(traits,"blend,",MagickPathExtent);
6249 if ((GetPixelChannelTraits(image,channel) & CopyPixelTrait) != 0)
6250 (void) ConcatenateMagickString(traits,"copy,",MagickPathExtent);
6251 if (*traits == '\0')
6252 (void) ConcatenateMagickString(traits,"undefined,",MagickPathExtent);
6253 traits[strlen(traits)-1]='\0';
6254 (void) LogMagickEvent(PixelEvent,GetMagickModule()," %.20g: %s (%s)",
6255 (double) i,name,traits);
6259 MagickExport ChannelType SetPixelChannelMask(Image *image,
6260 const ChannelType channel_mask)
6262 #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
6270 assert(image != (Image *) NULL);
6271 assert(image->signature == MagickCoreSignature);
6272 if (image->debug != MagickFalse)
6273 (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%08x]",
6274 image->filename,channel_mask);
6275 mask=image->channel_mask;
6276 image->channel_mask=channel_mask;
6277 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
6279 PixelChannel channel = GetPixelChannelChannel(image,i);
6280 if (GetChannelBit(channel_mask,channel) == 0)
6282 SetPixelChannelTraits(image,channel,CopyPixelTrait);
6285 if (channel == AlphaPixelChannel)
6287 if ((image->alpha_trait & CopyPixelTrait) != 0)
6289 SetPixelChannelTraits(image,channel,CopyPixelTrait);
6292 SetPixelChannelTraits(image,channel,UpdatePixelTrait);
6295 if (image->alpha_trait != UndefinedPixelTrait)
6297 SetPixelChannelTraits(image,channel,(const PixelTrait)
6298 (UpdatePixelTrait | BlendPixelTrait));
6301 SetPixelChannelTraits(image,channel,UpdatePixelTrait);
6303 if (image->storage_class == PseudoClass)
6304 SetPixelChannelTraits(image,IndexPixelChannel,CopyPixelTrait);
6305 if (image->read_mask != MagickFalse)
6306 SetPixelChannelTraits(image,ReadMaskPixelChannel,CopyPixelTrait);
6307 if (image->write_mask != MagickFalse)
6308 SetPixelChannelTraits(image,WriteMaskPixelChannel,CopyPixelTrait);
6309 if (image->debug != MagickFalse)
6310 LogPixelChannels(image);
6315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6319 % S e t P i x e l M e t a C h a n n e l s %
6323 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6325 % SetPixelMetaChannels() sets the image meta channels.
6327 % The format of the SetPixelMetaChannels method is:
6329 % MagickBooleanType SetPixelMetaChannels(Image *image,
6330 % const size_t number_meta_channels,ExceptionInfo *exception)
6332 % A description of each parameter follows:
6334 % o image: the image.
6336 % o number_meta_channels: the number of meta channels.
6338 % o exception: return any errors or warnings in this structure.
6341 MagickExport MagickBooleanType SetPixelMetaChannels(Image *image,
6342 const size_t number_meta_channels,ExceptionInfo *exception)
6344 image->number_meta_channels=number_meta_channels;
6345 InitializePixelChannelMap(image);
6346 return(SyncImagePixelCache(image,exception));