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-2014 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 % http://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/draw.h"
48 #include "MagickCore/exception.h"
49 #include "MagickCore/exception-private.h"
50 #include "MagickCore/cache.h"
51 #include "MagickCore/constitute.h"
52 #include "MagickCore/delegate.h"
53 #include "MagickCore/geometry.h"
54 #include "MagickCore/image-private.h"
55 #include "MagickCore/list.h"
56 #include "MagickCore/magick.h"
57 #include "MagickCore/memory_.h"
58 #include "MagickCore/monitor.h"
59 #include "MagickCore/option.h"
60 #include "MagickCore/pixel.h"
61 #include "MagickCore/pixel-accessor.h"
62 #include "MagickCore/pixel-private.h"
63 #include "MagickCore/quantum.h"
64 #include "MagickCore/quantum-private.h"
65 #include "MagickCore/resource_.h"
66 #include "MagickCore/semaphore.h"
67 #include "MagickCore/statistic.h"
68 #include "MagickCore/stream.h"
69 #include "MagickCore/string_.h"
70 #include "MagickCore/transform.h"
71 #include "MagickCore/utility.h"
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 + A c q u i r e P i x e l C h a n n e l M a p %
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84 % AcquirePixelChannelMap() acquires a pixel component map.
86 % The format of the AcquirePixelChannelMap() method is:
88 % PixelChannelMap *AcquirePixelChannelMap(void)
91 MagickExport PixelChannelMap *AcquirePixelChannelMap(void)
99 channel_map=(PixelChannelMap *) AcquireQuantumMemory(MaxPixelChannels,
100 sizeof(*channel_map));
101 if (channel_map == (PixelChannelMap *) NULL)
102 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
103 (void) ResetMagickMemory(channel_map,0,MaxPixelChannels*sizeof(*channel_map));
104 for (i=0; i < MaxPixelChannels; i++)
105 channel_map[i].channel=(PixelChannel) i;
110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 + C l o n e P i x e l C h a n n e l M a p %
118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 % ClonePixelChannelMap() clones a pixel component map.
122 % The format of the ClonePixelChannelMap() method is:
124 % PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
126 % A description of each parameter follows:
128 % o channel_map: the pixel component map.
131 MagickExport PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
136 assert(channel_map != (PixelChannelMap *) NULL);
137 clone_map=AcquirePixelChannelMap();
138 if (clone_map == (PixelChannelMap *) NULL)
139 return((PixelChannelMap *) NULL);
140 (void) CopyMagickMemory(clone_map,channel_map,MaxPixelChannels*
141 sizeof(*channel_map));
146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150 + C l o n e P i x e l I n f o %
154 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156 % ClonePixelInfo() makes a duplicate of the given pixel info structure, or if
157 % pixel info is NULL, a new one.
159 % The format of the ClonePixelInfo method is:
161 % PixelInfo *ClonePixelInfo(const PixelInfo *pixel_info)
163 % A description of each parameter follows:
165 % o pixel_info: the pixel info.
168 MagickExport PixelInfo *ClonePixelInfo(const PixelInfo *pixel)
173 pixel_info=(PixelInfo *) AcquireQuantumMemory(1,sizeof(*pixel_info));
174 if (pixel_info == (PixelInfo *) NULL)
175 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
176 *pixel_info=(*pixel);
181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185 % D e c o d e P i x e l G a m m a %
189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191 % DecodePixelGamma() applies the expansive power-law nonlinearity to the pixel.
193 % The format of the DecodePixelGamma method is:
195 % double DecodePixelGamma(const MagickRealType pixel)
197 % A description of each parameter follows:
199 % o pixel: the pixel.
203 static inline double DecodeGamma(const double x)
215 static const double coefficient[] = /* terms for x^(7/5), x=1.5 */
217 1.7917488588043277509,
218 0.82045614371976854984,
219 0.027694100686325412819,
220 -0.00094244335181762134018,
221 0.000064355540911469709545,
222 -5.7224404636060757485e-06,
223 5.8767669437311184313e-07,
224 -6.6139920053589721168e-08,
225 7.9323242696227458163e-09
228 static const double powers_of_two[] = /* (2^x)^(7/5) */
231 2.6390158215457883983,
232 6.9644045063689921093,
233 1.8379173679952558018e+01,
234 4.8502930128332728543e+01
238 Compute x^2.4 == x*x^(7/5) == pow(x,2.4).
241 term[1]=4.0*frexp(x,&exponent)-3.0;
242 term[2]=2.0*term[1]*term[1]-term[0];
243 term[3]=2.0*term[1]*term[2]-term[1];
244 term[4]=2.0*term[1]*term[3]-term[2];
245 term[5]=2.0*term[1]*term[4]-term[3];
246 term[6]=2.0*term[1]*term[5]-term[4];
247 term[7]=2.0*term[1]*term[6]-term[5];
248 term[8]=2.0*term[1]*term[7]-term[6];
249 p=coefficient[0]*term[0]+coefficient[1]*term[1]+coefficient[2]*term[2]+
250 coefficient[3]*term[3]+coefficient[4]*term[4]+coefficient[5]*term[5]+
251 coefficient[6]*term[6]+coefficient[7]*term[7]+coefficient[8]*term[8];
252 quotient=div(exponent-1,5);
253 if (quotient.rem < 0)
258 return(x*ldexp(powers_of_two[quotient.rem]*p,7*quotient.quot));
261 MagickExport MagickRealType DecodePixelGamma(const MagickRealType pixel)
263 if (pixel <= (0.0404482362771076*QuantumRange))
264 return(pixel/12.92f);
265 return((MagickRealType) (QuantumRange*DecodeGamma((double) (QuantumScale*
266 pixel+0.055)/1.055)));
270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
274 + D e s t r o y P i x e l C h a n n e l M a p %
278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280 % DestroyPixelChannelMap() deallocates memory associated with the pixel
283 % The format of the DestroyPixelChannelMap() method is:
285 % PixelChannelMap *DestroyPixelChannelMap(PixelChannelMap *channel_map)
287 % A description of each parameter follows:
289 % o channel_map: the pixel component map.
292 MagickExport PixelChannelMap *DestroyPixelChannelMap(
293 PixelChannelMap *channel_map)
295 assert(channel_map != (PixelChannelMap *) NULL);
296 channel_map=(PixelChannelMap *) RelinquishMagickMemory(channel_map);
297 return((PixelChannelMap *) RelinquishMagickMemory(channel_map));
301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
305 + E n c o d e P i x e l G a m m a %
309 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
311 % EncodePixelGamma() cancels any nonlinearity in the pixel.
313 % The format of the EncodePixelGamma method is:
315 % MagickRealType EncodePixelGamma(const double MagickRealType)
317 % A description of each parameter follows:
319 % o pixel: the pixel.
323 static inline double EncodeGamma(const double x)
335 static const double coefficient[] = /* Chebychevi poly: x^(5/12), x=1.5 */
337 1.1758200232996901923,
338 0.16665763094889061230,
339 -0.0083154894939042125035,
340 0.00075187976780420279038,
341 -0.000083240178519391795367,
342 0.000010229209410070008679,
343 -1.3400466409860246e-06,
344 1.8333422241635376682e-07,
345 -2.5878596761348859722e-08
348 static const double powers_of_two[] = /* (2^N)^(5/12) */
351 1.3348398541700343678,
352 1.7817974362806785482,
353 2.3784142300054420538,
354 3.1748021039363991669,
355 4.2378523774371812394,
356 5.6568542494923805819,
357 7.5509945014535482244,
358 1.0079368399158985525e1,
359 1.3454342644059433809e1,
360 1.7959392772949968275e1,
361 2.3972913230026907883e1
365 Compute x^(1/2.4) == x^(5/12) == pow(x,1.0/2.4).
368 term[1]=4.0*frexp(x,&exponent)-3.0;
369 term[2]=2.0*term[1]*term[1]-term[0];
370 term[3]=2.0*term[1]*term[2]-term[1];
371 term[4]=2.0*term[1]*term[3]-term[2];
372 term[5]=2.0*term[1]*term[4]-term[3];
373 term[6]=2.0*term[1]*term[5]-term[4];
374 term[7]=2.0*term[1]*term[6]-term[5];
375 term[8]=2.0*term[1]*term[7]-term[6];
376 p=coefficient[0]*term[0]+coefficient[1]*term[1]+coefficient[2]*term[2]+
377 coefficient[3]*term[3]+coefficient[4]*term[4]+coefficient[5]*term[5]+
378 coefficient[6]*term[6]+coefficient[7]*term[7]+coefficient[8]*term[8];
379 quotient=div(exponent-1,12);
380 if (quotient.rem < 0)
385 return(ldexp(powers_of_two[quotient.rem]*p,5*quotient.quot));
388 MagickExport MagickRealType EncodePixelGamma(const MagickRealType pixel)
390 if (pixel <= (0.0031306684425005883*QuantumRange))
391 return(12.92f*pixel);
392 return((MagickRealType) QuantumRange*(1.055*EncodeGamma((double) QuantumScale*
397 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
401 % E x p o r t I m a g e P i x e l s %
405 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
407 % ExportImagePixels() extracts pixel data from an image and returns it to you.
408 % The method returns MagickTrue on success otherwise MagickFalse if an error is
409 % encountered. The data is returned as char, short int, Quantum, unsigned int,
410 % unsigned long long, float, or double in the order specified by map.
412 % Suppose you want to extract the first scanline of a 640x480 image as
413 % character data in red-green-blue order:
415 % ExportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels,exception);
417 % The format of the ExportImagePixels method is:
419 % MagickBooleanType ExportImagePixels(const Image *image,const ssize_t x,
420 % const ssize_t y,const size_t width,const size_t height,
421 % const char *map,const StorageType type,void *pixels,
422 % ExceptionInfo *exception)
424 % A description of each parameter follows:
426 % o image: the image.
428 % o x,y,width,height: These values define the perimeter
429 % of a region of pixels you want to extract.
431 % o map: This string reflects the expected ordering of the pixel array.
432 % It can be any combination or order of R = red, G = green, B = blue,
433 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
434 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
437 % o type: Define the data type of the pixels. Float and double types are
438 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
439 % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *),
440 % LongPixel (unsigned int *), LongLongPixel (unsigned long long *),
441 % QuantumPixel (Quantum *), or ShortPixel (unsigned short *).
443 % o pixels: This array of values contain the pixel components as defined by
444 % map and type. You must preallocate this array where the expected
445 % length varies depending on the values of width, height, map, and type.
447 % o exception: return any errors or warnings in this structure.
451 static void ExportCharPixel(Image *image,const RectangleInfo *roi,
452 const char *restrict map,const QuantumType *quantum_map,void *pixels,
453 ExceptionInfo *exception)
455 register const Quantum
461 register unsigned char
470 q=(unsigned char *) pixels;
471 if (LocaleCompare(map,"BGR") == 0)
473 for (y=0; y < (ssize_t) roi->height; y++)
475 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
476 if (p == (const Quantum *) NULL)
478 for (x=0; x < (ssize_t) roi->width; x++)
480 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
481 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
482 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
483 p+=GetPixelChannels(image);
488 if (LocaleCompare(map,"BGRA") == 0)
490 for (y=0; y < (ssize_t) roi->height; y++)
492 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
493 if (p == (const Quantum *) NULL)
495 for (x=0; x < (ssize_t) roi->width; x++)
497 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
498 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
499 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
500 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
501 p+=GetPixelChannels(image);
506 if (LocaleCompare(map,"BGRP") == 0)
508 for (y=0; y < (ssize_t) roi->height; y++)
510 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
511 if (p == (const Quantum *) NULL)
513 for (x=0; x < (ssize_t) roi->width; x++)
515 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
516 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
517 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
518 *q++=ScaleQuantumToChar((Quantum) 0);
519 p+=GetPixelChannels(image);
524 if (LocaleCompare(map,"I") == 0)
526 for (y=0; y < (ssize_t) roi->height; y++)
528 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
529 if (p == (const Quantum *) NULL)
531 for (x=0; x < (ssize_t) roi->width; x++)
533 *q++=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
534 p+=GetPixelChannels(image);
539 if (LocaleCompare(map,"RGB") == 0)
541 for (y=0; y < (ssize_t) roi->height; y++)
543 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
544 if (p == (const Quantum *) NULL)
546 for (x=0; x < (ssize_t) roi->width; x++)
548 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
549 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
550 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
551 p+=GetPixelChannels(image);
556 if (LocaleCompare(map,"RGBA") == 0)
558 for (y=0; y < (ssize_t) roi->height; y++)
560 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
561 if (p == (const Quantum *) NULL)
563 for (x=0; x < (ssize_t) roi->width; x++)
565 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
566 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
567 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
568 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
569 p+=GetPixelChannels(image);
574 if (LocaleCompare(map,"RGBP") == 0)
576 for (y=0; y < (ssize_t) roi->height; y++)
578 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
579 if (p == (const Quantum *) NULL)
581 for (x=0; x < (ssize_t) roi->width; x++)
583 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
584 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
585 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
586 *q++=ScaleQuantumToChar((Quantum) 0);
587 p+=GetPixelChannels(image);
593 for (y=0; y < (ssize_t) roi->height; y++)
595 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
596 if (p == (const Quantum *) NULL)
598 for (x=0; x < (ssize_t) roi->width; x++)
603 for (i=0; i < (ssize_t) length; i++)
606 switch (quantum_map[i])
611 *q=ScaleQuantumToChar(GetPixelRed(image,p));
617 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
623 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
628 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
633 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
638 if (image->colorspace == CMYKColorspace)
639 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
644 *q=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
652 p+=GetPixelChannels(image);
657 static void ExportDoublePixel(Image *image,const RectangleInfo *roi,
658 const char *restrict map,const QuantumType *quantum_map,void *pixels,
659 ExceptionInfo *exception)
661 register const Quantum
677 if (LocaleCompare(map,"BGR") == 0)
679 for (y=0; y < (ssize_t) roi->height; y++)
681 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
682 if (p == (const Quantum *) NULL)
684 for (x=0; x < (ssize_t) roi->width; x++)
686 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
687 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
688 *q++=(double) (QuantumScale*GetPixelRed(image,p));
689 p+=GetPixelChannels(image);
694 if (LocaleCompare(map,"BGRA") == 0)
696 for (y=0; y < (ssize_t) roi->height; y++)
698 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
699 if (p == (const Quantum *) NULL)
701 for (x=0; x < (ssize_t) roi->width; x++)
703 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
704 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
705 *q++=(double) (QuantumScale*GetPixelRed(image,p));
706 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
707 p+=GetPixelChannels(image);
712 if (LocaleCompare(map,"BGRP") == 0)
714 for (y=0; y < (ssize_t) roi->height; y++)
716 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
717 if (p == (const Quantum *) NULL)
719 for (x=0; x < (ssize_t) roi->width; x++)
721 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
722 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
723 *q++=(double) (QuantumScale*GetPixelRed(image,p));
725 p+=GetPixelChannels(image);
730 if (LocaleCompare(map,"I") == 0)
732 for (y=0; y < (ssize_t) roi->height; y++)
734 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
735 if (p == (const Quantum *) NULL)
737 for (x=0; x < (ssize_t) roi->width; x++)
739 *q++=(double) (QuantumScale*GetPixelIntensity(image,p));
740 p+=GetPixelChannels(image);
745 if (LocaleCompare(map,"RGB") == 0)
747 for (y=0; y < (ssize_t) roi->height; y++)
749 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
750 if (p == (const Quantum *) NULL)
752 for (x=0; x < (ssize_t) roi->width; x++)
754 *q++=(double) (QuantumScale*GetPixelRed(image,p));
755 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
756 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
757 p+=GetPixelChannels(image);
762 if (LocaleCompare(map,"RGBA") == 0)
764 for (y=0; y < (ssize_t) roi->height; y++)
766 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
767 if (p == (const Quantum *) NULL)
769 for (x=0; x < (ssize_t) roi->width; x++)
771 *q++=(double) (QuantumScale*GetPixelRed(image,p));
772 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
773 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
774 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
775 p+=GetPixelChannels(image);
780 if (LocaleCompare(map,"RGBP") == 0)
782 for (y=0; y < (ssize_t) roi->height; y++)
784 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
785 if (p == (const Quantum *) NULL)
787 for (x=0; x < (ssize_t) roi->width; x++)
789 *q++=(double) (QuantumScale*GetPixelRed(image,p));
790 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
791 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
793 p+=GetPixelChannels(image);
799 for (y=0; y < (ssize_t) roi->height; y++)
801 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
802 if (p == (const Quantum *) NULL)
804 for (x=0; x < (ssize_t) roi->width; x++)
809 for (i=0; i < (ssize_t) length; i++)
812 switch (quantum_map[i])
817 *q=(double) (QuantumScale*GetPixelRed(image,p));
823 *q=(double) (QuantumScale*GetPixelGreen(image,p));
829 *q=(double) (QuantumScale*GetPixelBlue(image,p));
834 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
839 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
844 if (image->colorspace == CMYKColorspace)
845 *q=(double) (QuantumScale*
846 GetPixelBlack(image,p));
851 *q=(double) (QuantumScale*GetPixelIntensity(image,p));
859 p+=GetPixelChannels(image);
864 static void ExportFloatPixel(Image *image,const RectangleInfo *roi,
865 const char *restrict map,const QuantumType *quantum_map,void *pixels,
866 ExceptionInfo *exception)
868 register const Quantum
884 if (LocaleCompare(map,"BGR") == 0)
886 for (y=0; y < (ssize_t) roi->height; y++)
888 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
889 if (p == (const Quantum *) NULL)
891 for (x=0; x < (ssize_t) roi->width; x++)
893 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
894 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
895 *q++=(float) (QuantumScale*GetPixelRed(image,p));
896 p+=GetPixelChannels(image);
901 if (LocaleCompare(map,"BGRA") == 0)
903 for (y=0; y < (ssize_t) roi->height; y++)
905 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
906 if (p == (const Quantum *) NULL)
908 for (x=0; x < (ssize_t) roi->width; x++)
910 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
911 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
912 *q++=(float) (QuantumScale*GetPixelRed(image,p));
913 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
914 p+=GetPixelChannels(image);
919 if (LocaleCompare(map,"BGRP") == 0)
921 for (y=0; y < (ssize_t) roi->height; y++)
923 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
924 if (p == (const Quantum *) NULL)
926 for (x=0; x < (ssize_t) roi->width; x++)
928 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
929 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
930 *q++=(float) (QuantumScale*GetPixelRed(image,p));
932 p+=GetPixelChannels(image);
937 if (LocaleCompare(map,"I") == 0)
939 for (y=0; y < (ssize_t) roi->height; y++)
941 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
942 if (p == (const Quantum *) NULL)
944 for (x=0; x < (ssize_t) roi->width; x++)
946 *q++=(float) (QuantumScale*GetPixelIntensity(image,p));
947 p+=GetPixelChannels(image);
952 if (LocaleCompare(map,"RGB") == 0)
954 for (y=0; y < (ssize_t) roi->height; y++)
956 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
957 if (p == (const Quantum *) NULL)
959 for (x=0; x < (ssize_t) roi->width; x++)
961 *q++=(float) (QuantumScale*GetPixelRed(image,p));
962 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
963 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
964 p+=GetPixelChannels(image);
969 if (LocaleCompare(map,"RGBA") == 0)
971 for (y=0; y < (ssize_t) roi->height; y++)
973 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
974 if (p == (const Quantum *) NULL)
976 for (x=0; x < (ssize_t) roi->width; x++)
978 *q++=(float) (QuantumScale*GetPixelRed(image,p));
979 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
980 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
981 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
982 p+=GetPixelChannels(image);
987 if (LocaleCompare(map,"RGBP") == 0)
989 for (y=0; y < (ssize_t) roi->height; y++)
991 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
992 if (p == (const Quantum *) NULL)
994 for (x=0; x < (ssize_t) roi->width; x++)
996 *q++=(float) (QuantumScale*GetPixelRed(image,p));
997 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
998 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
1000 p+=GetPixelChannels(image);
1006 for (y=0; y < (ssize_t) roi->height; y++)
1008 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1009 if (p == (const Quantum *) NULL)
1011 for (x=0; x < (ssize_t) roi->width; x++)
1016 for (i=0; i < (ssize_t) length; i++)
1019 switch (quantum_map[i])
1024 *q=(float) (QuantumScale*GetPixelRed(image,p));
1028 case MagentaQuantum:
1030 *q=(float) (QuantumScale*GetPixelGreen(image,p));
1036 *q=(float) (QuantumScale*GetPixelBlue(image,p));
1041 *q=(float) (QuantumScale*((Quantum) (GetPixelAlpha(image,p))));
1044 case OpacityQuantum:
1046 *q=(float) (QuantumScale*GetPixelAlpha(image,p));
1051 if (image->colorspace == CMYKColorspace)
1052 *q=(float) (QuantumScale* GetPixelBlack(image,p));
1057 *q=(float) (QuantumScale*GetPixelIntensity(image,p));
1065 p+=GetPixelChannels(image);
1070 static void ExportLongPixel(Image *image,const RectangleInfo *roi,
1071 const char *restrict map,const QuantumType *quantum_map,void *pixels,
1072 ExceptionInfo *exception)
1074 register const Quantum
1080 register unsigned int
1089 q=(unsigned int *) pixels;
1090 if (LocaleCompare(map,"BGR") == 0)
1092 for (y=0; y < (ssize_t) roi->height; y++)
1094 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1095 if (p == (const Quantum *) NULL)
1097 for (x=0; x < (ssize_t) roi->width; x++)
1099 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1100 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1101 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1102 p+=GetPixelChannels(image);
1107 if (LocaleCompare(map,"BGRA") == 0)
1109 for (y=0; y < (ssize_t) roi->height; y++)
1111 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1112 if (p == (const Quantum *) NULL)
1114 for (x=0; x < (ssize_t) roi->width; x++)
1116 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1117 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1118 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1119 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1120 p+=GetPixelChannels(image);
1125 if (LocaleCompare(map,"BGRP") == 0)
1127 for (y=0; y < (ssize_t) roi->height; y++)
1129 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1130 if (p == (const Quantum *) NULL)
1132 for (x=0; x < (ssize_t) roi->width; x++)
1134 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1135 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1136 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1138 p+=GetPixelChannels(image);
1143 if (LocaleCompare(map,"I") == 0)
1145 for (y=0; y < (ssize_t) roi->height; y++)
1147 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1148 if (p == (const Quantum *) NULL)
1150 for (x=0; x < (ssize_t) roi->width; x++)
1152 *q++=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
1153 p+=GetPixelChannels(image);
1158 if (LocaleCompare(map,"RGB") == 0)
1160 for (y=0; y < (ssize_t) roi->height; y++)
1162 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1163 if (p == (const Quantum *) NULL)
1165 for (x=0; x < (ssize_t) roi->width; x++)
1167 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1168 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1169 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1170 p+=GetPixelChannels(image);
1175 if (LocaleCompare(map,"RGBA") == 0)
1177 for (y=0; y < (ssize_t) roi->height; y++)
1179 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1180 if (p == (const Quantum *) NULL)
1182 for (x=0; x < (ssize_t) roi->width; x++)
1184 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1185 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1186 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1187 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1188 p+=GetPixelChannels(image);
1193 if (LocaleCompare(map,"RGBP") == 0)
1195 for (y=0; y < (ssize_t) roi->height; y++)
1197 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1198 if (p == (const Quantum *) NULL)
1200 for (x=0; x < (ssize_t) roi->width; x++)
1202 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1203 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1204 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1206 p+=GetPixelChannels(image);
1212 for (y=0; y < (ssize_t) roi->height; y++)
1214 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1215 if (p == (const Quantum *) NULL)
1217 for (x=0; x < (ssize_t) roi->width; x++)
1222 for (i=0; i < (ssize_t) length; i++)
1225 switch (quantum_map[i])
1230 *q=ScaleQuantumToLong(GetPixelRed(image,p));
1234 case MagentaQuantum:
1236 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
1242 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
1247 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1250 case OpacityQuantum:
1252 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1257 if (image->colorspace == CMYKColorspace)
1258 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
1263 *q=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
1271 p+=GetPixelChannels(image);
1276 static void ExportLongLongPixel(Image *image,const RectangleInfo *roi,
1277 const char *restrict map,const QuantumType *quantum_map,void *pixels,
1278 ExceptionInfo *exception)
1280 register const Quantum
1286 register MagickSizeType
1295 q=(MagickSizeType *) pixels;
1296 if (LocaleCompare(map,"BGR") == 0)
1298 for (y=0; y < (ssize_t) roi->height; y++)
1300 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1301 if (p == (const Quantum *) NULL)
1303 for (x=0; x < (ssize_t) roi->width; x++)
1305 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1306 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1307 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1308 p+=GetPixelChannels(image);
1313 if (LocaleCompare(map,"BGRA") == 0)
1315 for (y=0; y < (ssize_t) roi->height; y++)
1317 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1318 if (p == (const Quantum *) NULL)
1320 for (x=0; x < (ssize_t) roi->width; x++)
1322 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1323 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1324 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1325 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1326 p+=GetPixelChannels(image);
1331 if (LocaleCompare(map,"BGRP") == 0)
1333 for (y=0; y < (ssize_t) roi->height; y++)
1335 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1336 if (p == (const Quantum *) NULL)
1338 for (x=0; x < (ssize_t) roi->width; x++)
1340 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1341 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1342 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1344 p+=GetPixelChannels(image);
1349 if (LocaleCompare(map,"I") == 0)
1351 for (y=0; y < (ssize_t) roi->height; y++)
1353 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1354 if (p == (const Quantum *) NULL)
1356 for (x=0; x < (ssize_t) roi->width; x++)
1358 *q++=ScaleQuantumToLongLong(ClampToQuantum(GetPixelIntensity(image,p)));
1359 p+=GetPixelChannels(image);
1364 if (LocaleCompare(map,"RGB") == 0)
1366 for (y=0; y < (ssize_t) roi->height; y++)
1368 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1369 if (p == (const Quantum *) NULL)
1371 for (x=0; x < (ssize_t) roi->width; x++)
1373 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1374 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1375 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1376 p+=GetPixelChannels(image);
1381 if (LocaleCompare(map,"RGBA") == 0)
1383 for (y=0; y < (ssize_t) roi->height; y++)
1385 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1386 if (p == (const Quantum *) NULL)
1388 for (x=0; x < (ssize_t) roi->width; x++)
1390 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1391 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1392 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1393 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1394 p+=GetPixelChannels(image);
1399 if (LocaleCompare(map,"RGBP") == 0)
1401 for (y=0; y < (ssize_t) roi->height; y++)
1403 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1404 if (p == (const Quantum *) NULL)
1406 for (x=0; x < (ssize_t) roi->width; x++)
1408 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1409 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1410 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1412 p+=GetPixelChannels(image);
1418 for (y=0; y < (ssize_t) roi->height; y++)
1420 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1421 if (p == (const Quantum *) NULL)
1423 for (x=0; x < (ssize_t) roi->width; x++)
1428 for (i=0; i < (ssize_t) length; i++)
1431 switch (quantum_map[i])
1436 *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
1440 case MagentaQuantum:
1442 *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1448 *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1453 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1456 case OpacityQuantum:
1458 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1463 if (image->colorspace == CMYKColorspace)
1464 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
1469 *q=ScaleQuantumToLongLong(ClampToQuantum(
1470 GetPixelIntensity(image,p)));
1478 p+=GetPixelChannels(image);
1483 static void ExportQuantumPixel(Image *image,const RectangleInfo *roi,
1484 const char *restrict map,const QuantumType *quantum_map,void *pixels,
1485 ExceptionInfo *exception)
1487 register const Quantum
1502 q=(Quantum *) pixels;
1503 if (LocaleCompare(map,"BGR") == 0)
1505 for (y=0; y < (ssize_t) roi->height; y++)
1507 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1508 if (p == (const Quantum *) NULL)
1510 for (x=0; x < (ssize_t) roi->width; x++)
1512 *q++=GetPixelBlue(image,p);
1513 *q++=GetPixelGreen(image,p);
1514 *q++=GetPixelRed(image,p);
1515 p+=GetPixelChannels(image);
1520 if (LocaleCompare(map,"BGRA") == 0)
1522 for (y=0; y < (ssize_t) roi->height; y++)
1524 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1525 if (p == (const Quantum *) NULL)
1527 for (x=0; x < (ssize_t) roi->width; x++)
1529 *q++=GetPixelBlue(image,p);
1530 *q++=GetPixelGreen(image,p);
1531 *q++=GetPixelRed(image,p);
1532 *q++=(Quantum) (GetPixelAlpha(image,p));
1533 p+=GetPixelChannels(image);
1538 if (LocaleCompare(map,"BGRP") == 0)
1540 for (y=0; y < (ssize_t) roi->height; y++)
1542 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1543 if (p == (const Quantum *) NULL)
1545 for (x=0; x < (ssize_t) roi->width; x++)
1547 *q++=GetPixelBlue(image,p);
1548 *q++=GetPixelGreen(image,p);
1549 *q++=GetPixelRed(image,p);
1551 p+=GetPixelChannels(image);
1556 if (LocaleCompare(map,"I") == 0)
1558 for (y=0; y < (ssize_t) roi->height; y++)
1560 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1561 if (p == (const Quantum *) NULL)
1563 for (x=0; x < (ssize_t) roi->width; x++)
1565 *q++=ClampToQuantum(GetPixelIntensity(image,p));
1566 p+=GetPixelChannels(image);
1571 if (LocaleCompare(map,"RGB") == 0)
1573 for (y=0; y < (ssize_t) roi->height; y++)
1575 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1576 if (p == (const Quantum *) NULL)
1578 for (x=0; x < (ssize_t) roi->width; x++)
1580 *q++=GetPixelRed(image,p);
1581 *q++=GetPixelGreen(image,p);
1582 *q++=GetPixelBlue(image,p);
1583 p+=GetPixelChannels(image);
1588 if (LocaleCompare(map,"RGBA") == 0)
1590 for (y=0; y < (ssize_t) roi->height; y++)
1592 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1593 if (p == (const Quantum *) NULL)
1595 for (x=0; x < (ssize_t) roi->width; x++)
1597 *q++=GetPixelRed(image,p);
1598 *q++=GetPixelGreen(image,p);
1599 *q++=GetPixelBlue(image,p);
1600 *q++=(Quantum) (GetPixelAlpha(image,p));
1601 p+=GetPixelChannels(image);
1606 if (LocaleCompare(map,"RGBP") == 0)
1608 for (y=0; y < (ssize_t) roi->height; y++)
1610 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1611 if (p == (const Quantum *) NULL)
1613 for (x=0; x < (ssize_t) roi->width; x++)
1615 *q++=GetPixelRed(image,p);
1616 *q++=GetPixelGreen(image,p);
1617 *q++=GetPixelBlue(image,p);
1619 p+=GetPixelChannels(image);
1625 for (y=0; y < (ssize_t) roi->height; y++)
1627 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1628 if (p == (const Quantum *) NULL)
1630 for (x=0; x < (ssize_t) roi->width; x++)
1635 for (i=0; i < (ssize_t) length; i++)
1638 switch (quantum_map[i])
1643 *q=GetPixelRed(image,p);
1647 case MagentaQuantum:
1649 *q=GetPixelGreen(image,p);
1655 *q=GetPixelBlue(image,p);
1660 *q=GetPixelAlpha(image,p);
1663 case OpacityQuantum:
1665 *q=GetPixelAlpha(image,p);
1670 if (image->colorspace == CMYKColorspace)
1671 *q=GetPixelBlack(image,p);
1676 *q=ClampToQuantum(GetPixelIntensity(image,p));
1687 p+=GetPixelChannels(image);
1692 static void ExportShortPixel(Image *image,const RectangleInfo *roi,
1693 const char *restrict map,const QuantumType *quantum_map,void *pixels,
1694 ExceptionInfo *exception)
1696 register const Quantum
1702 register unsigned short
1711 q=(unsigned short *) pixels;
1712 if (LocaleCompare(map,"BGR") == 0)
1714 for (y=0; y < (ssize_t) roi->height; y++)
1716 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1717 if (p == (const Quantum *) NULL)
1719 for (x=0; x < (ssize_t) roi->width; x++)
1721 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1722 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1723 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1724 p+=GetPixelChannels(image);
1729 if (LocaleCompare(map,"BGRA") == 0)
1731 for (y=0; y < (ssize_t) roi->height; y++)
1733 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1734 if (p == (const Quantum *) NULL)
1736 for (x=0; x < (ssize_t) roi->width; x++)
1738 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1739 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1740 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1741 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1742 p+=GetPixelChannels(image);
1747 if (LocaleCompare(map,"BGRP") == 0)
1749 for (y=0; y < (ssize_t) roi->height; y++)
1751 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1752 if (p == (const Quantum *) NULL)
1754 for (x=0; x < (ssize_t) roi->width; x++)
1756 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1757 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1758 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1760 p+=GetPixelChannels(image);
1765 if (LocaleCompare(map,"I") == 0)
1767 for (y=0; y < (ssize_t) roi->height; y++)
1769 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1770 if (p == (const Quantum *) NULL)
1772 for (x=0; x < (ssize_t) roi->width; x++)
1774 *q++=ScaleQuantumToShort(ClampToQuantum(GetPixelIntensity(image,p)));
1775 p+=GetPixelChannels(image);
1780 if (LocaleCompare(map,"RGB") == 0)
1782 for (y=0; y < (ssize_t) roi->height; y++)
1784 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1785 if (p == (const Quantum *) NULL)
1787 for (x=0; x < (ssize_t) roi->width; x++)
1789 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1790 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1791 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1792 p+=GetPixelChannels(image);
1797 if (LocaleCompare(map,"RGBA") == 0)
1799 for (y=0; y < (ssize_t) roi->height; y++)
1801 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1802 if (p == (const Quantum *) NULL)
1804 for (x=0; x < (ssize_t) roi->width; x++)
1806 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1807 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1808 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1809 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1810 p+=GetPixelChannels(image);
1815 if (LocaleCompare(map,"RGBP") == 0)
1817 for (y=0; y < (ssize_t) roi->height; y++)
1819 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1820 if (p == (const Quantum *) NULL)
1822 for (x=0; x < (ssize_t) roi->width; x++)
1824 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1825 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1826 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1828 p+=GetPixelChannels(image);
1834 for (y=0; y < (ssize_t) roi->height; y++)
1836 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1837 if (p == (const Quantum *) NULL)
1839 for (x=0; x < (ssize_t) roi->width; x++)
1844 for (i=0; i < (ssize_t) length; i++)
1847 switch (quantum_map[i])
1852 *q=ScaleQuantumToShort(GetPixelRed(image,p));
1856 case MagentaQuantum:
1858 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
1864 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
1869 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1872 case OpacityQuantum:
1874 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1879 if (image->colorspace == CMYKColorspace)
1880 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
1885 *q=ScaleQuantumToShort(ClampToQuantum(GetPixelIntensity(image,p)));
1893 p+=GetPixelChannels(image);
1898 MagickExport MagickBooleanType ExportImagePixels(Image *image,const ssize_t x,
1899 const ssize_t y,const size_t width,const size_t height,const char *map,
1900 const StorageType type,void *pixels,ExceptionInfo *exception)
1914 assert(image != (Image *) NULL);
1915 assert(image->signature == MagickSignature);
1916 if (image->debug != MagickFalse)
1917 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1919 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1920 if (quantum_map == (QuantumType *) NULL)
1922 (void) ThrowMagickException(exception,GetMagickModule(),
1923 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1924 return(MagickFalse);
1926 for (i=0; i < (ssize_t) length; i++)
1933 quantum_map[i]=AlphaQuantum;
1939 quantum_map[i]=BlueQuantum;
1945 quantum_map[i]=CyanQuantum;
1946 if (image->colorspace == CMYKColorspace)
1948 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1949 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1950 "ColorSeparatedImageRequired","`%s'",map);
1951 return(MagickFalse);
1956 quantum_map[i]=GreenQuantum;
1962 quantum_map[i]=IndexQuantum;
1968 quantum_map[i]=BlackQuantum;
1969 if (image->colorspace == CMYKColorspace)
1971 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1972 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1973 "ColorSeparatedImageRequired","`%s'",map);
1974 return(MagickFalse);
1979 quantum_map[i]=MagentaQuantum;
1980 if (image->colorspace == CMYKColorspace)
1982 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1983 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1984 "ColorSeparatedImageRequired","`%s'",map);
1985 return(MagickFalse);
1990 quantum_map[i]=OpacityQuantum;
1996 quantum_map[i]=UndefinedQuantum;
2002 quantum_map[i]=RedQuantum;
2008 quantum_map[i]=YellowQuantum;
2009 if (image->colorspace == CMYKColorspace)
2011 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2012 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2013 "ColorSeparatedImageRequired","`%s'",map);
2014 return(MagickFalse);
2018 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2019 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2020 "UnrecognizedPixelMap","`%s'",map);
2021 return(MagickFalse);
2033 ExportCharPixel(image,&roi,map,quantum_map,pixels,exception);
2038 ExportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
2043 ExportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
2048 ExportLongPixel(image,&roi,map,quantum_map,pixels,exception);
2053 ExportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
2058 ExportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
2063 ExportShortPixel(image,&roi,map,quantum_map,pixels,exception);
2068 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2069 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2070 "UnrecognizedPixelMap","`%s'",map);
2074 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2079 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2083 % G e t P i x e l I n f o %
2087 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2089 % GetPixelInfo() initializes the PixelInfo structure.
2091 % The format of the GetPixelInfo method is:
2093 % GetPixelInfo(const Image *image,PixelInfo *pixel)
2095 % A description of each parameter follows:
2097 % o image: the image. (optional - may be NULL)
2099 % o pixel: Specifies a pointer to a PixelInfo structure.
2102 MagickExport void GetPixelInfo(const Image *image,PixelInfo *pixel)
2104 pixel->storage_class=DirectClass;
2105 pixel->colorspace=sRGBColorspace;
2106 pixel->alpha_trait=UndefinedPixelTrait;
2108 pixel->depth=MAGICKCORE_QUANTUM_DEPTH;
2113 pixel->alpha=(double) OpaqueAlpha;
2115 if (image == (const Image *) NULL)
2117 pixel->storage_class=image->storage_class;
2118 pixel->colorspace=image->colorspace;
2119 pixel->alpha_trait=image->alpha_trait;
2120 pixel->depth=image->depth;
2121 pixel->fuzz=image->fuzz;
2125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2129 % G e t P i x e l I n t e n s i t y %
2133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2135 % GetPixelIntensity() returns a single sample intensity value from the red,
2136 % green, and blue components of a pixel based on the selected method:
2138 % Rec601Luma 0.298839R' + 0.586811G' + 0.114350B'
2139 % Rec601Luminance 0.298839R + 0.586811G + 0.114350B
2140 % Rec709Luma 0.212656R' + 0.715158G' + 0.072186B'
2141 % Rec709Luminance 0.212656R + 0.715158G + 0.072186B
2142 % Brightness max(R', G', B')
2143 % Lightness (min(R', G', B') + max(R', G', B')) / 2.0
2145 % MS (R^2 + G^2 + B^2) / 3.0
2146 % RMS sqrt((R^2 + G^2 + B^2) / 3.0
2147 % Average (R + G + B') / 3.0
2149 % The format of the GetPixelIntensity method is:
2151 % MagickRealType GetPixelIntensity(const Image *image,
2152 % const Quantum *pixel)
2154 % A description of each parameter follows:
2156 % o image: the image.
2158 % o pixel: Specifies a pointer to a Quantum structure.
2162 static inline MagickRealType MagickMax(const MagickRealType x,
2163 const MagickRealType y)
2170 static inline MagickRealType MagickMin(const MagickRealType x,
2171 const MagickRealType y)
2178 MagickExport MagickRealType GetPixelIntensity(const Image *restrict image,
2179 const Quantum *restrict pixel)
2187 if (image->colorspace == GRAYColorspace)
2188 return((MagickRealType) GetPixelGray(image,pixel));
2189 red=(MagickRealType) GetPixelRed(image,pixel);
2190 green=(MagickRealType) GetPixelGreen(image,pixel);
2191 blue=(MagickRealType) GetPixelBlue(image,pixel);
2192 switch (image->intensity)
2194 case AveragePixelIntensityMethod:
2196 intensity=(red+green+blue)/3.0;
2199 case BrightnessPixelIntensityMethod:
2201 intensity=MagickMax(MagickMax(red,green),blue);
2204 case LightnessPixelIntensityMethod:
2206 intensity=(MagickMin(MagickMin(red,green),blue)+
2207 MagickMax(MagickMax(red,green),blue))/2.0;
2210 case MSPixelIntensityMethod:
2212 intensity=(MagickRealType) (((double) red*red+green*green+blue*blue)/
2213 (3.0*QuantumRange));
2216 case Rec601LumaPixelIntensityMethod:
2218 if (image->colorspace == RGBColorspace)
2220 red=EncodePixelGamma(red);
2221 green=EncodePixelGamma(green);
2222 blue=EncodePixelGamma(blue);
2224 intensity=0.298839*red+0.586811*green+0.114350*blue;
2227 case Rec601LuminancePixelIntensityMethod:
2229 if (image->colorspace == sRGBColorspace)
2231 red=DecodePixelGamma(red);
2232 green=DecodePixelGamma(green);
2233 blue=DecodePixelGamma(blue);
2235 intensity=0.298839*red+0.586811*green+0.114350*blue;
2238 case Rec709LumaPixelIntensityMethod:
2241 if (image->colorspace == RGBColorspace)
2243 red=EncodePixelGamma(red);
2244 green=EncodePixelGamma(green);
2245 blue=EncodePixelGamma(blue);
2247 intensity=0.212656*red+0.715158*green+0.072186*blue;
2250 case Rec709LuminancePixelIntensityMethod:
2252 if (image->colorspace == sRGBColorspace)
2254 red=DecodePixelGamma(red);
2255 green=DecodePixelGamma(green);
2256 blue=DecodePixelGamma(blue);
2258 intensity=0.212656*red+0.715158*green+0.072186*blue;
2261 case RMSPixelIntensityMethod:
2263 intensity=(MagickRealType) (sqrt((double) red*red+green*green+blue*blue)/
2272 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2276 % I m p o r t I m a g e P i x e l s %
2280 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2282 % ImportImagePixels() accepts pixel data and stores in the image at the
2283 % location you specify. The method returns MagickTrue on success otherwise
2284 % MagickFalse if an error is encountered. The pixel data can be either char,
2285 % Quantum, short int, unsigned int, unsigned long long, float, or double in
2286 % the order specified by map.
2288 % Suppose your want to upload the first scanline of a 640x480 image from
2289 % character data in red-green-blue order:
2291 % ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels);
2293 % The format of the ImportImagePixels method is:
2295 % MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
2296 % const ssize_t y,const size_t width,const size_t height,
2297 % const char *map,const StorageType type,const void *pixels,
2298 % ExceptionInfo *exception)
2300 % A description of each parameter follows:
2302 % o image: the image.
2304 % o x,y,width,height: These values define the perimeter
2305 % of a region of pixels you want to define.
2307 % o map: This string reflects the expected ordering of the pixel array.
2308 % It can be any combination or order of R = red, G = green, B = blue,
2309 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
2310 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
2313 % o type: Define the data type of the pixels. Float and double types are
2314 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
2315 % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *),
2316 % LongPixel (unsigned int *), LongLongPixel (unsigned long long *),
2317 % QuantumPixel (Quantum *), or ShortPixel (unsigned short *).
2319 % o pixels: This array of values contain the pixel components as defined by
2320 % map and type. You must preallocate this array where the expected
2321 % length varies depending on the values of width, height, map, and type.
2323 % o exception: return any errors or warnings in this structure.
2327 static void ImportCharPixel(Image *image,const RectangleInfo *roi,
2328 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2329 ExceptionInfo *exception)
2331 register const unsigned char
2346 p=(const unsigned char *) pixels;
2347 if (LocaleCompare(map,"BGR") == 0)
2349 for (y=0; y < (ssize_t) roi->height; y++)
2351 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2352 if (q == (Quantum *) NULL)
2354 for (x=0; x < (ssize_t) roi->width; x++)
2356 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2357 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2358 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2359 q+=GetPixelChannels(image);
2361 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2366 if (LocaleCompare(map,"BGRA") == 0)
2368 for (y=0; y < (ssize_t) roi->height; y++)
2370 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2371 if (q == (Quantum *) NULL)
2373 for (x=0; x < (ssize_t) roi->width; x++)
2375 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2376 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2377 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2378 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2379 q+=GetPixelChannels(image);
2381 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2386 if (LocaleCompare(map,"BGRO") == 0)
2388 for (y=0; y < (ssize_t) roi->height; y++)
2390 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2391 if (q == (Quantum *) NULL)
2393 for (x=0; x < (ssize_t) roi->width; x++)
2395 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2396 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2397 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2398 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2399 q+=GetPixelChannels(image);
2401 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2406 if (LocaleCompare(map,"BGRP") == 0)
2408 for (y=0; y < (ssize_t) roi->height; y++)
2410 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2411 if (q == (Quantum *) NULL)
2413 for (x=0; x < (ssize_t) roi->width; x++)
2415 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2416 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2417 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2419 q+=GetPixelChannels(image);
2421 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2426 if (LocaleCompare(map,"I") == 0)
2428 for (y=0; y < (ssize_t) roi->height; y++)
2430 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2431 if (q == (Quantum *) NULL)
2433 for (x=0; x < (ssize_t) roi->width; x++)
2435 SetPixelGray(image,ScaleCharToQuantum(*p++),q);
2436 q+=GetPixelChannels(image);
2438 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2443 if (LocaleCompare(map,"RGB") == 0)
2445 for (y=0; y < (ssize_t) roi->height; y++)
2447 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2448 if (q == (Quantum *) NULL)
2450 for (x=0; x < (ssize_t) roi->width; x++)
2452 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2453 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2454 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2455 q+=GetPixelChannels(image);
2457 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2462 if (LocaleCompare(map,"RGBA") == 0)
2464 for (y=0; y < (ssize_t) roi->height; y++)
2466 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2467 if (q == (Quantum *) NULL)
2469 for (x=0; x < (ssize_t) roi->width; x++)
2471 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2472 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2473 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2474 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2475 q+=GetPixelChannels(image);
2477 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2482 if (LocaleCompare(map,"RGBO") == 0)
2484 for (y=0; y < (ssize_t) roi->height; y++)
2486 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2487 if (q == (Quantum *) NULL)
2489 for (x=0; x < (ssize_t) roi->width; x++)
2491 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2492 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2493 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2494 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2495 q+=GetPixelChannels(image);
2497 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2502 if (LocaleCompare(map,"RGBP") == 0)
2504 for (y=0; y < (ssize_t) roi->height; y++)
2506 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2507 if (q == (Quantum *) NULL)
2509 for (x=0; x < (ssize_t) roi->width; x++)
2511 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2512 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2513 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2515 q+=GetPixelChannels(image);
2517 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2523 for (y=0; y < (ssize_t) roi->height; y++)
2525 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2526 if (q == (Quantum *) NULL)
2528 for (x=0; x < (ssize_t) roi->width; x++)
2533 for (i=0; i < (ssize_t) length; i++)
2535 switch (quantum_map[i])
2540 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2544 case MagentaQuantum:
2546 SetPixelGreen(image,ScaleCharToQuantum(*p),q);
2552 SetPixelBlue(image,ScaleCharToQuantum(*p),q);
2557 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2560 case OpacityQuantum:
2562 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2567 SetPixelBlack(image,ScaleCharToQuantum(*p),q);
2572 SetPixelGray(image,ScaleCharToQuantum(*p),q);
2580 q+=GetPixelChannels(image);
2582 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2587 static void ImportDoublePixel(Image *image,const RectangleInfo *roi,
2588 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2589 ExceptionInfo *exception)
2591 register const double
2606 p=(const double *) pixels;
2607 if (LocaleCompare(map,"BGR") == 0)
2609 for (y=0; y < (ssize_t) roi->height; y++)
2611 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2612 if (q == (Quantum *) NULL)
2614 for (x=0; x < (ssize_t) roi->width; x++)
2616 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2618 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2620 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2622 q+=GetPixelChannels(image);
2624 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2629 if (LocaleCompare(map,"BGRA") == 0)
2631 for (y=0; y < (ssize_t) roi->height; y++)
2633 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2634 if (q == (Quantum *) NULL)
2636 for (x=0; x < (ssize_t) roi->width; x++)
2638 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2640 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2642 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2644 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2646 q+=GetPixelChannels(image);
2648 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2653 if (LocaleCompare(map,"BGRP") == 0)
2655 for (y=0; y < (ssize_t) roi->height; y++)
2657 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2658 if (q == (Quantum *) NULL)
2660 for (x=0; x < (ssize_t) roi->width; x++)
2662 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2664 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2666 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2669 q+=GetPixelChannels(image);
2671 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2676 if (LocaleCompare(map,"I") == 0)
2678 for (y=0; y < (ssize_t) roi->height; y++)
2680 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2681 if (q == (Quantum *) NULL)
2683 for (x=0; x < (ssize_t) roi->width; x++)
2685 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2687 q+=GetPixelChannels(image);
2689 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2694 if (LocaleCompare(map,"RGB") == 0)
2696 for (y=0; y < (ssize_t) roi->height; y++)
2698 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2699 if (q == (Quantum *) NULL)
2701 for (x=0; x < (ssize_t) roi->width; x++)
2703 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2705 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2707 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2709 q+=GetPixelChannels(image);
2711 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2716 if (LocaleCompare(map,"RGBA") == 0)
2718 for (y=0; y < (ssize_t) roi->height; y++)
2720 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2721 if (q == (Quantum *) NULL)
2723 for (x=0; x < (ssize_t) roi->width; x++)
2725 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2727 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2729 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2731 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2733 q+=GetPixelChannels(image);
2735 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2740 if (LocaleCompare(map,"RGBP") == 0)
2742 for (y=0; y < (ssize_t) roi->height; y++)
2744 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2745 if (q == (Quantum *) NULL)
2747 for (x=0; x < (ssize_t) roi->width; x++)
2749 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2751 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2753 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2755 q+=GetPixelChannels(image);
2757 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2763 for (y=0; y < (ssize_t) roi->height; y++)
2765 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2766 if (q == (Quantum *) NULL)
2768 for (x=0; x < (ssize_t) roi->width; x++)
2773 for (i=0; i < (ssize_t) length; i++)
2775 switch (quantum_map[i])
2780 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2784 case MagentaQuantum:
2786 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2792 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2797 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2800 case OpacityQuantum:
2802 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2807 SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q);
2812 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2820 q+=GetPixelChannels(image);
2822 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2827 static void ImportFloatPixel(Image *image,const RectangleInfo *roi,
2828 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2829 ExceptionInfo *exception)
2831 register const float
2846 p=(const float *) pixels;
2847 if (LocaleCompare(map,"BGR") == 0)
2849 for (y=0; y < (ssize_t) roi->height; y++)
2851 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2852 if (q == (Quantum *) NULL)
2854 for (x=0; x < (ssize_t) roi->width; x++)
2856 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2858 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2860 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2862 q+=GetPixelChannels(image);
2864 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2869 if (LocaleCompare(map,"BGRA") == 0)
2871 for (y=0; y < (ssize_t) roi->height; y++)
2873 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2874 if (q == (Quantum *) NULL)
2876 for (x=0; x < (ssize_t) roi->width; x++)
2878 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2880 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2882 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2884 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2886 q+=GetPixelChannels(image);
2888 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2893 if (LocaleCompare(map,"BGRP") == 0)
2895 for (y=0; y < (ssize_t) roi->height; y++)
2897 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2898 if (q == (Quantum *) NULL)
2900 for (x=0; x < (ssize_t) roi->width; x++)
2902 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2904 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2906 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2909 q+=GetPixelChannels(image);
2911 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2916 if (LocaleCompare(map,"I") == 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 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2927 q+=GetPixelChannels(image);
2929 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2934 if (LocaleCompare(map,"RGB") == 0)
2936 for (y=0; y < (ssize_t) roi->height; y++)
2938 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2939 if (q == (Quantum *) NULL)
2941 for (x=0; x < (ssize_t) roi->width; x++)
2943 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2945 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2947 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2949 q+=GetPixelChannels(image);
2951 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2956 if (LocaleCompare(map,"RGBA") == 0)
2958 for (y=0; y < (ssize_t) roi->height; y++)
2960 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2961 if (q == (Quantum *) NULL)
2963 for (x=0; x < (ssize_t) roi->width; x++)
2965 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2967 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2969 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2971 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2973 q+=GetPixelChannels(image);
2975 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2980 if (LocaleCompare(map,"RGBP") == 0)
2982 for (y=0; y < (ssize_t) roi->height; y++)
2984 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2985 if (q == (Quantum *) NULL)
2987 for (x=0; x < (ssize_t) roi->width; x++)
2989 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2991 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2993 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2995 q+=GetPixelChannels(image);
2997 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3003 for (y=0; y < (ssize_t) roi->height; y++)
3005 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3006 if (q == (Quantum *) NULL)
3008 for (x=0; x < (ssize_t) roi->width; x++)
3013 for (i=0; i < (ssize_t) length; i++)
3015 switch (quantum_map[i])
3020 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3024 case MagentaQuantum:
3026 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3032 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3037 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
3040 case OpacityQuantum:
3042 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
3047 SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q);
3052 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
3060 q+=GetPixelChannels(image);
3062 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3067 static void ImportLongPixel(Image *image,const RectangleInfo *roi,
3068 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3069 ExceptionInfo *exception)
3071 register const unsigned int
3086 p=(const unsigned int *) pixels;
3087 if (LocaleCompare(map,"BGR") == 0)
3089 for (y=0; y < (ssize_t) roi->height; y++)
3091 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3092 if (q == (Quantum *) NULL)
3094 for (x=0; x < (ssize_t) roi->width; x++)
3096 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3097 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3098 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3099 q+=GetPixelChannels(image);
3101 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3106 if (LocaleCompare(map,"BGRA") == 0)
3108 for (y=0; y < (ssize_t) roi->height; y++)
3110 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3111 if (q == (Quantum *) NULL)
3113 for (x=0; x < (ssize_t) roi->width; x++)
3115 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3116 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3117 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3118 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3119 q+=GetPixelChannels(image);
3121 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3126 if (LocaleCompare(map,"BGRP") == 0)
3128 for (y=0; y < (ssize_t) roi->height; y++)
3130 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3131 if (q == (Quantum *) NULL)
3133 for (x=0; x < (ssize_t) roi->width; x++)
3135 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3136 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3137 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3139 q+=GetPixelChannels(image);
3141 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3146 if (LocaleCompare(map,"I") == 0)
3148 for (y=0; y < (ssize_t) roi->height; y++)
3150 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3151 if (q == (Quantum *) NULL)
3153 for (x=0; x < (ssize_t) roi->width; x++)
3155 SetPixelGray(image,ScaleLongToQuantum(*p++),q);
3156 q+=GetPixelChannels(image);
3158 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3163 if (LocaleCompare(map,"RGB") == 0)
3165 for (y=0; y < (ssize_t) roi->height; y++)
3167 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3168 if (q == (Quantum *) NULL)
3170 for (x=0; x < (ssize_t) roi->width; x++)
3172 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3173 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3174 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3175 q+=GetPixelChannels(image);
3177 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3182 if (LocaleCompare(map,"RGBA") == 0)
3184 for (y=0; y < (ssize_t) roi->height; y++)
3186 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3187 if (q == (Quantum *) NULL)
3189 for (x=0; x < (ssize_t) roi->width; x++)
3191 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3192 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3193 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3194 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3195 q+=GetPixelChannels(image);
3197 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3202 if (LocaleCompare(map,"RGBP") == 0)
3204 for (y=0; y < (ssize_t) roi->height; y++)
3206 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3207 if (q == (Quantum *) NULL)
3209 for (x=0; x < (ssize_t) roi->width; x++)
3211 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3212 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3213 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3215 q+=GetPixelChannels(image);
3217 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3223 for (y=0; y < (ssize_t) roi->height; y++)
3225 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3226 if (q == (Quantum *) NULL)
3228 for (x=0; x < (ssize_t) roi->width; x++)
3233 for (i=0; i < (ssize_t) length; i++)
3235 switch (quantum_map[i])
3240 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3244 case MagentaQuantum:
3246 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
3252 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
3257 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3260 case OpacityQuantum:
3262 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3267 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
3272 SetPixelGray(image,ScaleLongToQuantum(*p),q);
3280 q+=GetPixelChannels(image);
3282 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3287 static void ImportLongLongPixel(Image *image,const RectangleInfo *roi,
3288 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3289 ExceptionInfo *exception)
3291 register const MagickSizeType
3306 p=(const MagickSizeType *) pixels;
3307 if (LocaleCompare(map,"BGR") == 0)
3309 for (y=0; y < (ssize_t) roi->height; y++)
3311 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3312 if (q == (Quantum *) NULL)
3314 for (x=0; x < (ssize_t) roi->width; x++)
3316 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3317 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3318 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3319 q+=GetPixelChannels(image);
3321 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3326 if (LocaleCompare(map,"BGRA") == 0)
3328 for (y=0; y < (ssize_t) roi->height; y++)
3330 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3331 if (q == (Quantum *) NULL)
3333 for (x=0; x < (ssize_t) roi->width; x++)
3335 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3336 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3337 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3338 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3339 q+=GetPixelChannels(image);
3341 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3346 if (LocaleCompare(map,"BGRP") == 0)
3348 for (y=0; y < (ssize_t) roi->height; y++)
3350 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3351 if (q == (Quantum *) NULL)
3353 for (x=0; x < (ssize_t) roi->width; x++)
3355 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3356 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3357 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3359 q+=GetPixelChannels(image);
3361 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3366 if (LocaleCompare(map,"I") == 0)
3368 for (y=0; y < (ssize_t) roi->height; y++)
3370 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3371 if (q == (Quantum *) NULL)
3373 for (x=0; x < (ssize_t) roi->width; x++)
3375 SetPixelGray(image,ScaleLongLongToQuantum(*p++),q);
3376 q+=GetPixelChannels(image);
3378 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3383 if (LocaleCompare(map,"RGB") == 0)
3385 for (y=0; y < (ssize_t) roi->height; y++)
3387 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3388 if (q == (Quantum *) NULL)
3390 for (x=0; x < (ssize_t) roi->width; x++)
3392 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3393 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3394 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3395 q+=GetPixelChannels(image);
3397 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3402 if (LocaleCompare(map,"RGBA") == 0)
3404 for (y=0; y < (ssize_t) roi->height; y++)
3406 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3407 if (q == (Quantum *) NULL)
3409 for (x=0; x < (ssize_t) roi->width; x++)
3411 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3412 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3413 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3414 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3415 q+=GetPixelChannels(image);
3417 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3422 if (LocaleCompare(map,"RGBP") == 0)
3424 for (y=0; y < (ssize_t) roi->height; y++)
3426 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3427 if (q == (Quantum *) NULL)
3429 for (x=0; x < (ssize_t) roi->width; x++)
3431 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3432 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3433 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3435 q+=GetPixelChannels(image);
3437 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3443 for (y=0; y < (ssize_t) roi->height; y++)
3445 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3446 if (q == (Quantum *) NULL)
3448 for (x=0; x < (ssize_t) roi->width; x++)
3453 for (i=0; i < (ssize_t) length; i++)
3455 switch (quantum_map[i])
3460 SetPixelRed(image,ScaleLongLongToQuantum(*p),q);
3464 case MagentaQuantum:
3466 SetPixelGreen(image,ScaleLongLongToQuantum(*p),q);
3472 SetPixelBlue(image,ScaleLongLongToQuantum(*p),q);
3477 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3480 case OpacityQuantum:
3482 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3487 SetPixelBlack(image,ScaleLongLongToQuantum(*p),q);
3492 SetPixelGray(image,ScaleLongLongToQuantum(*p),q);
3500 q+=GetPixelChannels(image);
3502 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3507 static void ImportQuantumPixel(Image *image,const RectangleInfo *roi,
3508 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3509 ExceptionInfo *exception)
3511 register const Quantum
3526 p=(const Quantum *) pixels;
3527 if (LocaleCompare(map,"BGR") == 0)
3529 for (y=0; y < (ssize_t) roi->height; y++)
3531 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3532 if (q == (Quantum *) NULL)
3534 for (x=0; x < (ssize_t) roi->width; x++)
3536 SetPixelBlue(image,*p++,q);
3537 SetPixelGreen(image,*p++,q);
3538 SetPixelRed(image,*p++,q);
3539 q+=GetPixelChannels(image);
3541 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3546 if (LocaleCompare(map,"BGRA") == 0)
3548 for (y=0; y < (ssize_t) roi->height; y++)
3550 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3551 if (q == (Quantum *) NULL)
3553 for (x=0; x < (ssize_t) roi->width; x++)
3555 SetPixelBlue(image,*p++,q);
3556 SetPixelGreen(image,*p++,q);
3557 SetPixelRed(image,*p++,q);
3558 SetPixelAlpha(image,*p++,q);
3559 q+=GetPixelChannels(image);
3561 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3566 if (LocaleCompare(map,"BGRP") == 0)
3568 for (y=0; y < (ssize_t) roi->height; y++)
3570 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3571 if (q == (Quantum *) NULL)
3573 for (x=0; x < (ssize_t) roi->width; x++)
3575 SetPixelBlue(image,*p++,q);
3576 SetPixelGreen(image,*p++,q);
3577 SetPixelRed(image,*p++,q);
3579 q+=GetPixelChannels(image);
3581 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3586 if (LocaleCompare(map,"I") == 0)
3588 for (y=0; y < (ssize_t) roi->height; y++)
3590 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3591 if (q == (Quantum *) NULL)
3593 for (x=0; x < (ssize_t) roi->width; x++)
3595 SetPixelGray(image,*p++,q);
3596 q+=GetPixelChannels(image);
3598 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3603 if (LocaleCompare(map,"RGB") == 0)
3605 for (y=0; y < (ssize_t) roi->height; y++)
3607 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3608 if (q == (Quantum *) NULL)
3610 for (x=0; x < (ssize_t) roi->width; x++)
3612 SetPixelRed(image,*p++,q);
3613 SetPixelGreen(image,*p++,q);
3614 SetPixelBlue(image,*p++,q);
3615 q+=GetPixelChannels(image);
3617 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3622 if (LocaleCompare(map,"RGBA") == 0)
3624 for (y=0; y < (ssize_t) roi->height; y++)
3626 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3627 if (q == (Quantum *) NULL)
3629 for (x=0; x < (ssize_t) roi->width; x++)
3631 SetPixelRed(image,*p++,q);
3632 SetPixelGreen(image,*p++,q);
3633 SetPixelBlue(image,*p++,q);
3634 SetPixelAlpha(image,*p++,q);
3635 q+=GetPixelChannels(image);
3637 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3642 if (LocaleCompare(map,"RGBP") == 0)
3644 for (y=0; y < (ssize_t) roi->height; y++)
3646 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3647 if (q == (Quantum *) NULL)
3649 for (x=0; x < (ssize_t) roi->width; x++)
3651 SetPixelRed(image,*p++,q);
3652 SetPixelGreen(image,*p++,q);
3653 SetPixelBlue(image,*p++,q);
3655 q+=GetPixelChannels(image);
3657 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3663 for (y=0; y < (ssize_t) roi->height; y++)
3665 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3666 if (q == (Quantum *) NULL)
3668 for (x=0; x < (ssize_t) roi->width; x++)
3673 for (i=0; i < (ssize_t) length; i++)
3675 switch (quantum_map[i])
3680 SetPixelRed(image,*p,q);
3684 case MagentaQuantum:
3686 SetPixelGreen(image,*p,q);
3692 SetPixelBlue(image,*p,q);
3697 SetPixelAlpha(image,*p,q);
3700 case OpacityQuantum:
3702 SetPixelAlpha(image,*p,q);
3707 SetPixelBlack(image,*p,q);
3712 SetPixelGray(image,*p,q);
3720 q+=GetPixelChannels(image);
3722 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3727 static void ImportShortPixel(Image *image,const RectangleInfo *roi,
3728 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3729 ExceptionInfo *exception)
3731 register const unsigned short
3746 p=(const unsigned short *) pixels;
3747 if (LocaleCompare(map,"BGR") == 0)
3749 for (y=0; y < (ssize_t) roi->height; y++)
3751 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3752 if (q == (Quantum *) NULL)
3754 for (x=0; x < (ssize_t) roi->width; x++)
3756 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3757 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3758 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3759 q+=GetPixelChannels(image);
3761 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3766 if (LocaleCompare(map,"BGRA") == 0)
3768 for (y=0; y < (ssize_t) roi->height; y++)
3770 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3771 if (q == (Quantum *) NULL)
3773 for (x=0; x < (ssize_t) roi->width; x++)
3775 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3776 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3777 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3778 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3779 q+=GetPixelChannels(image);
3781 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3786 if (LocaleCompare(map,"BGRP") == 0)
3788 for (y=0; y < (ssize_t) roi->height; y++)
3790 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3791 if (q == (Quantum *) NULL)
3793 for (x=0; x < (ssize_t) roi->width; x++)
3795 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3796 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3797 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3799 q+=GetPixelChannels(image);
3801 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3806 if (LocaleCompare(map,"I") == 0)
3808 for (y=0; y < (ssize_t) roi->height; y++)
3810 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3811 if (q == (Quantum *) NULL)
3813 for (x=0; x < (ssize_t) roi->width; x++)
3815 SetPixelGray(image,ScaleShortToQuantum(*p++),q);
3816 q+=GetPixelChannels(image);
3818 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3823 if (LocaleCompare(map,"RGB") == 0)
3825 for (y=0; y < (ssize_t) roi->height; y++)
3827 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3828 if (q == (Quantum *) NULL)
3830 for (x=0; x < (ssize_t) roi->width; x++)
3832 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3833 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3834 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3835 q+=GetPixelChannels(image);
3837 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3842 if (LocaleCompare(map,"RGBA") == 0)
3844 for (y=0; y < (ssize_t) roi->height; y++)
3846 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3847 if (q == (Quantum *) NULL)
3849 for (x=0; x < (ssize_t) roi->width; x++)
3851 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3852 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3853 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3854 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3855 q+=GetPixelChannels(image);
3857 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3862 if (LocaleCompare(map,"RGBP") == 0)
3864 for (y=0; y < (ssize_t) roi->height; y++)
3866 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3867 if (q == (Quantum *) NULL)
3869 for (x=0; x < (ssize_t) roi->width; x++)
3871 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3872 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3873 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3875 q+=GetPixelChannels(image);
3877 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3883 for (y=0; y < (ssize_t) roi->height; y++)
3885 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3886 if (q == (Quantum *) NULL)
3888 for (x=0; x < (ssize_t) roi->width; x++)
3893 for (i=0; i < (ssize_t) length; i++)
3895 switch (quantum_map[i])
3900 SetPixelRed(image,ScaleShortToQuantum(*p),q);
3904 case MagentaQuantum:
3906 SetPixelGreen(image,ScaleShortToQuantum(*p),q);
3912 SetPixelBlue(image,ScaleShortToQuantum(*p),q);
3917 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3920 case OpacityQuantum:
3922 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3927 SetPixelBlack(image,ScaleShortToQuantum(*p),q);
3932 SetPixelGray(image,ScaleShortToQuantum(*p),q);
3940 q+=GetPixelChannels(image);
3942 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3947 MagickExport MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
3948 const ssize_t y,const size_t width,const size_t height,const char *map,
3949 const StorageType type,const void *pixels,ExceptionInfo *exception)
3964 Allocate image structure.
3966 assert(image != (Image *) NULL);
3967 assert(image->signature == MagickSignature);
3968 if (image->debug != MagickFalse)
3969 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3971 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
3972 if (quantum_map == (QuantumType *) NULL)
3973 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
3975 for (i=0; i < (ssize_t) length; i++)
3982 quantum_map[i]=AlphaQuantum;
3983 image->alpha_trait=BlendPixelTrait;
3989 quantum_map[i]=BlueQuantum;
3995 quantum_map[i]=CyanQuantum;
3996 (void) SetImageColorspace(image,CMYKColorspace,exception);
4002 quantum_map[i]=GreenQuantum;
4008 quantum_map[i]=BlackQuantum;
4009 (void) SetImageColorspace(image,CMYKColorspace,exception);
4015 quantum_map[i]=IndexQuantum;
4016 (void) SetImageColorspace(image,GRAYColorspace,exception);
4022 quantum_map[i]=MagentaQuantum;
4023 (void) SetImageColorspace(image,CMYKColorspace,exception);
4029 quantum_map[i]=OpacityQuantum;
4030 image->alpha_trait=BlendPixelTrait;
4036 quantum_map[i]=UndefinedQuantum;
4042 quantum_map[i]=RedQuantum;
4048 quantum_map[i]=YellowQuantum;
4049 (void) SetImageColorspace(image,CMYKColorspace,exception);
4054 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4055 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4056 "UnrecognizedPixelMap","`%s'",map);
4057 return(MagickFalse);
4061 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
4062 return(MagickFalse);
4064 Transfer the pixels from the pixel data to the image.
4074 ImportCharPixel(image,&roi,map,quantum_map,pixels,exception);
4079 ImportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
4084 ImportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
4089 ImportLongPixel(image,&roi,map,quantum_map,pixels,exception);
4094 ImportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
4099 ImportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
4104 ImportShortPixel(image,&roi,map,quantum_map,pixels,exception);
4109 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4110 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4111 "UnrecognizedStorageType","`%d'",type);
4115 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4124 + 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 %
4128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4130 % InitializePixelChannelMap() defines the standard pixel component map.
4132 % The format of the InitializePixelChannelMap() method is:
4134 % void InitializePixelChannelMap(Image *image)
4136 % A description of each parameter follows:
4138 % o image: the image.
4142 static void LogPixelChannels(const Image *image)
4147 (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%.20g]",
4148 image->filename,(double) image->number_channels);
4149 for (i=0; i < (ssize_t) image->number_channels; i++)
4152 traits[MaxTextExtent];
4160 switch (GetPixelChannelChannel(image,i))
4162 case RedPixelChannel:
4165 if (image->colorspace == CMYKColorspace)
4167 if (image->colorspace == GRAYColorspace)
4171 case GreenPixelChannel:
4174 if (image->colorspace == CMYKColorspace)
4178 case BluePixelChannel:
4181 if (image->colorspace == CMYKColorspace)
4185 case BlackPixelChannel:
4188 if (image->storage_class == PseudoClass)
4192 case IndexPixelChannel:
4197 case AlphaPixelChannel:
4202 case ReadMaskPixelChannel:
4207 case WriteMaskPixelChannel:
4212 case MetaPixelChannel:
4220 channel=GetPixelChannelChannel(image,i);
4222 if ((GetPixelChannelTraits(image,channel) & UpdatePixelTrait) != 0)
4223 (void) ConcatenateMagickString(traits,"update,",MaxTextExtent);
4224 if ((GetPixelChannelTraits(image,channel) & BlendPixelTrait) != 0)
4225 (void) ConcatenateMagickString(traits,"blend,",MaxTextExtent);
4226 if ((GetPixelChannelTraits(image,channel) & CopyPixelTrait) != 0)
4227 (void) ConcatenateMagickString(traits,"copy,",MaxTextExtent);
4228 if (*traits == '\0')
4229 (void) ConcatenateMagickString(traits,"undefined,",MaxTextExtent);
4230 traits[strlen(traits)-1]='\0';
4231 (void) LogMagickEvent(PixelEvent,GetMagickModule()," %.20g: %s (%s)",
4232 (double) i,name,traits);
4236 MagickExport void InitializePixelChannelMap(Image *image)
4247 assert(image != (Image *) NULL);
4248 assert(image->signature == MagickSignature);
4249 (void) ResetMagickMemory(image->channel_map,0,MaxPixelChannels*
4250 sizeof(*image->channel_map));
4251 trait=UpdatePixelTrait;
4252 if (image->alpha_trait == BlendPixelTrait)
4253 trait=(PixelTrait) (trait | BlendPixelTrait);
4255 if (image->colorspace == GRAYColorspace)
4257 SetPixelChannelAttributes(image,BluePixelChannel,trait,n);
4258 SetPixelChannelAttributes(image,GreenPixelChannel,trait,n);
4259 SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
4263 SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
4264 SetPixelChannelAttributes(image,GreenPixelChannel,trait,n++);
4265 SetPixelChannelAttributes(image,BluePixelChannel,trait,n++);
4267 if (image->colorspace == CMYKColorspace)
4268 SetPixelChannelAttributes(image,BlackPixelChannel,trait,n++);
4269 if (image->alpha_trait != UndefinedPixelTrait)
4270 SetPixelChannelAttributes(image,AlphaPixelChannel,CopyPixelTrait,n++);
4271 if (image->storage_class == PseudoClass)
4272 SetPixelChannelAttributes(image,IndexPixelChannel,CopyPixelTrait,n++);
4273 if (image->read_mask != MagickFalse)
4274 SetPixelChannelAttributes(image,ReadMaskPixelChannel,CopyPixelTrait,n++);
4275 if (image->write_mask != MagickFalse)
4276 SetPixelChannelAttributes(image,WriteMaskPixelChannel,CopyPixelTrait,n++);
4277 assert((n+image->number_meta_channels) < MaxPixelChannels);
4278 for (i=0; i < (ssize_t) image->number_meta_channels; i++)
4279 SetPixelChannelAttributes(image,(PixelChannel) (MetaPixelChannel+i),
4280 CopyPixelTrait,n++);
4281 image->number_channels=(size_t) n;
4282 if (image->debug != MagickFalse)
4283 LogPixelChannels(image);
4284 (void) SetImageChannelMask(image,image->channel_mask);
4288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4292 % I n t e r p o l a t e P i x e l C h a n n e l %
4296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4298 % InterpolatePixelChannel() applies a pixel interpolation method between a
4299 % floating point coordinate and the pixels surrounding that coordinate. No
4300 % pixel area resampling, or scaling of the result is performed.
4302 % Interpolation is restricted to just the specified channel.
4304 % The format of the InterpolatePixelChannel method is:
4306 % MagickBooleanType InterpolatePixelChannel(const Image *image,
4307 % const CacheView *image_view,const PixelChannel channel,
4308 % const PixelInterpolateMethod method,const double x,const double y,
4309 % double *pixel,ExceptionInfo *exception)
4311 % A description of each parameter follows:
4313 % o image: the image.
4315 % o image_view: the image view.
4317 % o channel: the pixel channel to interpolate.
4319 % o method: the pixel color interpolation method.
4321 % o x,y: A double representing the current (x,y) position of the pixel.
4323 % o pixel: return the interpolated pixel here.
4325 % o exception: return any errors or warnings in this structure.
4329 static inline void CatromWeights(const double x,double (*weights)[4])
4337 Nicolas Robidoux' 10 flops (4* + 5- + 1+) refactoring of the computation
4338 of the standard four 1D Catmull-Rom weights. The sampling location is
4339 assumed between the second and third input pixel locations, and x is the
4340 position relative to the second input pixel location. Formulas originally
4341 derived for the VIPS (Virtual Image Processing System) library.
4343 alpha=(double) 1.0-x;
4344 beta=(double) (-0.5)*x*alpha;
4345 (*weights)[0]=alpha*beta;
4346 (*weights)[3]=x*beta;
4348 The following computation of the inner weights from the outer ones work
4349 for all Keys cubics.
4351 gamma=(*weights)[3]-(*weights)[0];
4352 (*weights)[1]=alpha-(*weights)[0]+gamma;
4353 (*weights)[2]=x-(*weights)[3]-gamma;
4356 static inline void SplineWeights(const double x,double (*weights)[4])
4363 Nicolas Robidoux' 12 flops (6* + 5- + 1+) refactoring of the computation
4364 of the standard four 1D cubic B-spline smoothing weights. The sampling
4365 location is assumed between the second and third input pixel locations,
4366 and x is the position relative to the second input pixel location.
4368 alpha=(double) 1.0-x;
4369 (*weights)[3]=(double) (1.0/6.0)*x*x*x;
4370 (*weights)[0]=(double) (1.0/6.0)*alpha*alpha*alpha;
4371 beta=(*weights)[3]-(*weights)[0];
4372 (*weights)[1]=alpha-(*weights)[0]+beta;
4373 (*weights)[2]=x-(*weights)[3]-beta;
4376 static inline double MeshInterpolate(const PointInfo *delta,const double p,
4377 const double x,const double y)
4379 return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
4383 static inline ssize_t NearestNeighbor(const double x)
4386 return((ssize_t) (x+0.5));
4387 return((ssize_t) (x-0.5));
4391 MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
4392 const CacheView *image_view,const PixelChannel channel,
4393 const PixelInterpolateMethod method,const double x,const double y,
4394 double *pixel,ExceptionInfo *exception)
4404 PixelInterpolateMethod
4410 register const Quantum
4420 assert(image != (Image *) NULL);
4421 assert(image != (Image *) NULL);
4422 assert(image->signature == MagickSignature);
4423 assert(image_view != (CacheView *) NULL);
4426 traits=GetPixelChannelTraits(image,channel);
4427 x_offset=(ssize_t) floor(x);
4428 y_offset=(ssize_t) floor(y);
4429 interpolate = method;
4430 if ( interpolate == UndefinedInterpolatePixel )
4431 interpolate = image->interpolate;
4432 switch (interpolate)
4434 case AverageInterpolatePixel: /* nearest 4 neighbours */
4435 case Average9InterpolatePixel: /* nearest 9 neighbours */
4436 case Average16InterpolatePixel: /* nearest 16 neighbours */
4441 count=2; /* size of the area to average - default nearest 4 */
4442 if (interpolate == Average9InterpolatePixel)
4445 x_offset=(ssize_t) (floor(x+0.5)-1);
4446 y_offset=(ssize_t) (floor(y+0.5)-1);
4449 if (interpolate == Average16InterpolatePixel)
4455 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,(size_t) count,
4456 (size_t) count,exception);
4457 if (p == (const Quantum *) NULL)
4462 count*=count; /* Number of pixels to average */
4463 if ((traits & BlendPixelTrait) == 0)
4464 for (i=0; i < (ssize_t) count; i++)
4467 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4470 for (i=0; i < (ssize_t) count; i++)
4472 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4473 GetPixelChannels(image));
4474 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4476 for (i=0; i < (ssize_t) count; i++)
4478 gamma=PerceptibleReciprocal(alpha[i])/count;
4479 *pixel+=gamma*pixels[i];
4483 case BilinearInterpolatePixel:
4490 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4491 if (p == (const Quantum *) NULL)
4496 if ((traits & BlendPixelTrait) == 0)
4497 for (i=0; i < 4; i++)
4500 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4503 for (i=0; i < 4; i++)
4505 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4506 GetPixelChannels(image));
4507 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4511 epsilon.x=1.0-delta.x;
4512 epsilon.y=1.0-delta.y;
4513 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4514 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4515 gamma=PerceptibleReciprocal(gamma);
4516 *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
4517 (epsilon.x*pixels[2]+delta.x*pixels[3]));
4520 case BlendInterpolatePixel:
4522 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4523 if (p == (const Quantum *) NULL)
4528 if ((traits & BlendPixelTrait) == 0)
4529 for (i=0; i < 4; i++)
4532 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4535 for (i=0; i < 4; i++)
4537 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4538 GetPixelChannels(image));
4539 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4541 gamma=1.0; /* number of pixels blended together (its variable) */
4542 for (i=0; i <= 1L; i++) {
4543 if ((y-y_offset) >= 0.75)
4545 alpha[i]=alpha[i+2]; /* take right pixels */
4546 pixels[i]=pixels[i+2];
4549 if ((y-y_offset) > 0.25)
4551 gamma=2.0; /* blend both pixels in row */
4552 alpha[i]+=alpha[i+2]; /* add up alpha weights */
4553 pixels[i]+=pixels[i+2];
4556 if ((x-x_offset) >= 0.75)
4558 alpha[0]=alpha[1]; /* take bottom row blend */
4559 pixels[0]=pixels[1];
4562 if ((x-x_offset) > 0.25)
4564 gamma*=2.0; /* blend both rows */
4565 alpha[0]+=alpha[1]; /* add up alpha weights */
4566 pixels[0]+=pixels[1];
4568 if (channel != AlphaPixelChannel)
4569 gamma=PerceptibleReciprocal(alpha[0]); /* (color) 1/alpha_weights */
4571 gamma=PerceptibleReciprocal(gamma); /* (alpha) 1/number_of_pixels */
4572 *pixel=gamma*pixels[0];
4575 case CatromInterpolatePixel:
4581 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4583 if (p == (const Quantum *) NULL)
4588 if ((traits & BlendPixelTrait) == 0)
4589 for (i=0; i < 16; i++)
4592 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4595 for (i=0; i < 16; i++)
4597 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4598 GetPixelChannels(image));
4599 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4601 CatromWeights((double) (x-x_offset),&cx);
4602 CatromWeights((double) (y-y_offset),&cy);
4603 gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4604 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4605 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4606 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4607 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4608 cx[2]*alpha[14]+cx[3]*alpha[15])));
4609 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4610 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4611 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4612 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4613 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4616 case IntegerInterpolatePixel:
4618 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4619 if (p == (const Quantum *) NULL)
4624 *pixel=(double) GetPixelChannel(image,channel,p);
4627 case NearestInterpolatePixel:
4629 x_offset=(ssize_t) floor(x+0.5);
4630 y_offset=(ssize_t) floor(y+0.5);
4631 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4632 if (p == (const Quantum *) NULL)
4637 *pixel=(double) GetPixelChannel(image,channel,p);
4640 case MeshInterpolatePixel:
4646 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4647 if (p == (const Quantum *) NULL)
4652 if ((traits & BlendPixelTrait) == 0)
4653 for (i=0; i < 4; i++)
4656 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4659 for (i=0; i < 4; i++)
4661 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4662 GetPixelChannels(image));
4663 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4667 luminance.x=GetPixelLuma(image,p)-(double)
4668 GetPixelLuma(image,p+3*GetPixelChannels(image));
4669 luminance.y=GetPixelLuma(image,p+GetPixelChannels(image))-(double)
4670 GetPixelLuma(image,p+2*GetPixelChannels(image));
4671 if (fabs(luminance.x) < fabs(luminance.y))
4676 if (delta.x <= delta.y)
4679 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4681 delta.y=1.0-delta.y;
4682 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4683 gamma=PerceptibleReciprocal(gamma);
4684 *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
4690 Top-right triangle (pixel: 1, diagonal: 0-3).
4692 delta.x=1.0-delta.x;
4693 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4694 gamma=PerceptibleReciprocal(gamma);
4695 *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
4704 if (delta.x <= (1.0-delta.y))
4707 Top-left triangle (pixel: 0, diagonal: 1-2).
4709 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4710 gamma=PerceptibleReciprocal(gamma);
4711 *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
4717 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4719 delta.x=1.0-delta.x;
4720 delta.y=1.0-delta.y;
4721 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4722 gamma=PerceptibleReciprocal(gamma);
4723 *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
4729 case SplineInterpolatePixel:
4735 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4737 if (p == (const Quantum *) NULL)
4742 if ((traits & BlendPixelTrait) == 0)
4743 for (i=0; i < 16; i++)
4746 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4749 for (i=0; i < 16; i++)
4751 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4752 GetPixelChannels(image));
4753 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4755 SplineWeights((double) (x-x_offset),&cx);
4756 SplineWeights((double) (y-y_offset),&cy);
4757 gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4758 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4759 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4760 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4761 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4762 cx[2]*alpha[14]+cx[3]*alpha[15])));
4763 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4764 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4765 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4766 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4767 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4775 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4779 % I n t e r p o l a t e P i x e l C h a n n e l s %
4783 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4785 % InterpolatePixelChannels() applies a pixel interpolation method between a
4786 % floating point coordinate and the pixels surrounding that coordinate. No
4787 % pixel area resampling, or scaling of the result is performed.
4789 % Interpolation is restricted to just the current channel setting of the
4790 % destination image into which the color is to be stored
4792 % The format of the InterpolatePixelChannels method is:
4794 % MagickBooleanType InterpolatePixelChannels(const Image *source,
4795 % const CacheView *source_view,const Image *destination,
4796 % const PixelInterpolateMethod method,const double x,const double y,
4797 % Quantum *pixel,ExceptionInfo *exception)
4799 % A description of each parameter follows:
4801 % o source: the source.
4803 % o source_view: the source view.
4805 % o destination: the destination image, for the interpolated color
4807 % o method: the pixel color interpolation method.
4809 % o x,y: A double representing the current (x,y) position of the pixel.
4811 % o pixel: return the interpolated pixel here.
4813 % o exception: return any errors or warnings in this structure.
4816 MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
4817 const CacheView *source_view,const Image *destination,
4818 const PixelInterpolateMethod method,const double x,const double y,
4819 Quantum *pixel,ExceptionInfo *exception)
4829 register const Quantum
4839 PixelInterpolateMethod
4842 assert(source != (Image *) NULL);
4843 assert(source != (Image *) NULL);
4844 assert(source->signature == MagickSignature);
4845 assert(source_view != (CacheView *) NULL);
4847 x_offset=(ssize_t) floor(x);
4848 y_offset=(ssize_t) floor(y);
4849 interpolate = method;
4850 if ( interpolate == UndefinedInterpolatePixel )
4851 interpolate = source->interpolate;
4852 switch (interpolate)
4854 case AverageInterpolatePixel: /* nearest 4 neighbours */
4855 case Average9InterpolatePixel: /* nearest 9 neighbours */
4856 case Average16InterpolatePixel: /* nearest 16 neighbours */
4861 count=2; /* size of the area to average - default nearest 4 */
4862 if (interpolate == Average9InterpolatePixel)
4865 x_offset=(ssize_t) (floor(x+0.5)-1);
4866 y_offset=(ssize_t) (floor(y+0.5)-1);
4869 if (interpolate == Average16InterpolatePixel)
4875 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,(size_t) count,
4876 (size_t) count,exception);
4877 if (p == (const Quantum *) NULL)
4882 count*=count; /* Number of pixels to average */
4883 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4891 PixelChannel channel=GetPixelChannelChannel(source,i);
4892 PixelTrait traits=GetPixelChannelTraits(source,channel);
4893 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4895 if ((traits == UndefinedPixelTrait) ||
4896 (destination_traits == UndefinedPixelTrait))
4898 for (j=0; j < (ssize_t) count; j++)
4899 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
4901 if ((traits & BlendPixelTrait) == 0)
4903 for (j=0; j < (ssize_t) count; j++)
4906 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4909 for (j=0; j < (ssize_t) count; j++)
4911 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4912 GetPixelChannels(source));
4913 pixels[j]*=alpha[j];
4914 gamma=PerceptibleReciprocal(alpha[j]);
4915 sum+=gamma*pixels[j];
4918 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4922 case BilinearInterpolatePixel:
4925 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4926 if (p == (const Quantum *) NULL)
4931 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4937 PixelChannel channel=GetPixelChannelChannel(source,i);
4938 PixelTrait traits=GetPixelChannelTraits(source,channel);
4939 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4941 if ((traits == UndefinedPixelTrait) ||
4942 (destination_traits == UndefinedPixelTrait))
4946 epsilon.x=1.0-delta.x;
4947 epsilon.y=1.0-delta.y;
4948 pixels[0]=(double) p[i];
4949 pixels[1]=(double) p[GetPixelChannels(source)+i];
4950 pixels[2]=(double) p[2*GetPixelChannels(source)+i];
4951 pixels[3]=(double) p[3*GetPixelChannels(source)+i];
4952 if ((traits & BlendPixelTrait) == 0)
4954 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
4955 gamma=PerceptibleReciprocal(gamma);
4956 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4957 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*
4958 pixels[2]+delta.x*pixels[3]))),pixel);
4961 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4962 alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source));
4963 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4964 GetPixelChannels(source));
4965 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4966 GetPixelChannels(source));
4967 pixels[0]*=alpha[0];
4968 pixels[1]*=alpha[1];
4969 pixels[2]*=alpha[2];
4970 pixels[3]*=alpha[3];
4971 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4972 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4973 gamma=PerceptibleReciprocal(gamma);
4974 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4975 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+
4976 delta.x*pixels[3]))),pixel);
4980 case BlendInterpolatePixel:
4982 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4983 if (p == (const Quantum *) NULL)
4988 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4993 PixelChannel channel=GetPixelChannelChannel(source,i);
4994 PixelTrait traits=GetPixelChannelTraits(source,channel);
4995 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4997 if ((traits == UndefinedPixelTrait) ||
4998 (destination_traits == UndefinedPixelTrait))
5000 if ((traits & BlendPixelTrait) == 0)
5001 for (j=0; j < 4; j++)
5004 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+channel];
5007 for (j=0; j < 4; j++)
5009 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
5010 GetPixelChannels(source));
5011 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+channel];
5013 gamma=1.0; /* number of pixels blended together (its variable) */
5014 for (j=0; j <= 1L; j++)
5016 if ((y-y_offset) >= 0.75)
5018 alpha[j]=alpha[j+2]; /* take right pixels */
5019 pixels[j]=pixels[j+2];
5022 if ((y-y_offset) > 0.25)
5024 gamma=2.0; /* blend both pixels in row */
5025 alpha[j]+=alpha[j+2]; /* add up alpha weights */
5026 pixels[j]+=pixels[j+2];
5029 if ((x-x_offset) >= 0.75)
5031 alpha[0]=alpha[1]; /* take bottom row blend */
5032 pixels[0]=pixels[1];
5035 if ((x-x_offset) > 0.25)
5037 gamma*=2.0; /* blend both rows */
5038 alpha[0]+=alpha[1]; /* add up alpha weights */
5039 pixels[0]+=pixels[1];
5041 if ((traits & BlendPixelTrait) == 0)
5042 gamma=PerceptibleReciprocal(alpha[0]); /* (color) 1/alpha_weights */
5044 gamma=PerceptibleReciprocal(gamma); /* (alpha) 1/number_of_pixels */
5045 SetPixelChannel(destination,channel,ClampToQuantum(gamma*pixels[0]),
5050 case CatromInterpolatePixel:
5056 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
5058 if (p == (const Quantum *) NULL)
5063 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5068 PixelChannel channel=GetPixelChannelChannel(source,i);
5069 PixelTrait traits=GetPixelChannelTraits(source,channel);
5070 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5072 if ((traits == UndefinedPixelTrait) ||
5073 (destination_traits == UndefinedPixelTrait))
5075 if ((traits & BlendPixelTrait) == 0)
5076 for (j=0; j < 16; j++)
5079 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
5082 for (j=0; j < 16; j++)
5084 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
5085 GetPixelChannels(source));
5086 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
5088 CatromWeights((double) (x-x_offset),&cx);
5089 CatromWeights((double) (y-y_offset),&cy);
5090 gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
5091 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
5092 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
5093 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
5094 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
5095 cx[2]*alpha[14]+cx[3]*alpha[15])));
5096 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
5097 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
5098 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
5099 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
5100 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
5101 pixels[14]+cx[3]*pixels[15]))),pixel);
5105 case IntegerInterpolatePixel:
5107 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
5108 if (p == (const Quantum *) NULL)
5113 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5115 PixelChannel channel=GetPixelChannelChannel(source,i);
5116 PixelTrait traits=GetPixelChannelTraits(source,channel);
5117 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5119 if ((traits == UndefinedPixelTrait) ||
5120 (destination_traits == UndefinedPixelTrait))
5122 SetPixelChannel(destination,channel,p[i],pixel);
5126 case NearestInterpolatePixel:
5128 x_offset=(ssize_t) floor(x+0.5);
5129 y_offset=(ssize_t) floor(y+0.5);
5130 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
5131 if (p == (const Quantum *) NULL)
5136 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5138 PixelChannel channel=GetPixelChannelChannel(source,i);
5139 PixelTrait traits=GetPixelChannelTraits(source,channel);
5140 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5142 if ((traits == UndefinedPixelTrait) ||
5143 (destination_traits == UndefinedPixelTrait))
5145 SetPixelChannel(destination,channel,p[i],pixel);
5149 case MeshInterpolatePixel:
5151 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
5152 if (p == (const Quantum *) NULL)
5157 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5163 PixelChannel channel=GetPixelChannelChannel(source,i);
5164 PixelTrait traits=GetPixelChannelTraits(source,channel);
5165 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5167 if ((traits == UndefinedPixelTrait) ||
5168 (destination_traits == UndefinedPixelTrait))
5170 pixels[0]=(double) p[i];
5171 pixels[1]=(double) p[GetPixelChannels(source)+i];
5172 pixels[2]=(double) p[2*GetPixelChannels(source)+i];
5173 pixels[3]=(double) p[3*GetPixelChannels(source)+i];
5174 if ((traits & BlendPixelTrait) == 0)
5183 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
5184 alpha[1]=QuantumScale*GetPixelAlpha(source,p+
5185 GetPixelChannels(source));
5186 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
5187 GetPixelChannels(source));
5188 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
5189 GetPixelChannels(source));
5193 luminance.x=fabs((double) (GetPixelLuma(source,p)-
5194 GetPixelLuma(source,p+3*GetPixelChannels(source))));
5195 luminance.y=fabs((double) (GetPixelLuma(source,p+
5196 GetPixelChannels(source))-GetPixelLuma(source,p+2*
5197 GetPixelChannels(source))));
5198 if (luminance.x < luminance.y)
5203 if (delta.x <= delta.y)
5206 Bottom-left triangle (pixel: 2, diagonal: 0-3).
5208 delta.y=1.0-delta.y;
5209 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5210 gamma=PerceptibleReciprocal(gamma);
5211 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5212 MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel);
5217 Top-right triangle (pixel: 1, diagonal: 0-3).
5219 delta.x=1.0-delta.x;
5220 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5221 gamma=PerceptibleReciprocal(gamma);
5222 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5223 MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel);
5231 if (delta.x <= (1.0-delta.y))
5234 Top-left triangle (pixel: 0, diagonal: 1-2).
5236 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5237 gamma=PerceptibleReciprocal(gamma);
5238 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5239 MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel);
5244 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5246 delta.x=1.0-delta.x;
5247 delta.y=1.0-delta.y;
5248 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5249 gamma=PerceptibleReciprocal(gamma);
5250 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5251 MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel);
5257 case SplineInterpolatePixel:
5263 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
5265 if (p == (const Quantum *) NULL)
5270 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5275 PixelChannel channel=GetPixelChannelChannel(source,i);
5276 PixelTrait traits=GetPixelChannelTraits(source,channel);
5277 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5279 if ((traits == UndefinedPixelTrait) ||
5280 (destination_traits == UndefinedPixelTrait))
5282 if ((traits & BlendPixelTrait) == 0)
5283 for (j=0; j < 16; j++)
5286 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
5289 for (j=0; j < 16; j++)
5291 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
5292 GetPixelChannels(source));
5293 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
5295 SplineWeights((double) (x-x_offset),&cx);
5296 SplineWeights((double) (y-y_offset),&cy);
5297 gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
5298 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
5299 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
5300 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
5301 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
5302 cx[2]*alpha[14]+cx[3]*alpha[15])));
5303 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
5304 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
5305 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
5306 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
5307 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
5308 pixels[14]+cx[3]*pixels[15]))),pixel);
5317 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5321 % I n t e r p o l a t e P i x e l I n f o %
5325 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5327 % InterpolatePixelInfo() applies a pixel interpolation method between a
5328 % floating point coordinate and the pixels surrounding that coordinate. No
5329 % pixel area resampling, or scaling of the result is performed.
5331 % Interpolation is restricted to just RGBKA channels.
5333 % The format of the InterpolatePixelInfo method is:
5335 % MagickBooleanType InterpolatePixelInfo(const Image *image,
5336 % const CacheView *image_view,const PixelInterpolateMethod method,
5337 % const double x,const double y,PixelInfo *pixel,
5338 % ExceptionInfo *exception)
5340 % A description of each parameter follows:
5342 % o image: the image.
5344 % o image_view: the image view.
5346 % o method: the pixel color interpolation method.
5348 % o x,y: A double representing the current (x,y) position of the pixel.
5350 % o pixel: return the interpolated pixel here.
5352 % o exception: return any errors or warnings in this structure.
5356 static inline void AlphaBlendPixelInfo(const Image *image,
5357 const Quantum *pixel,PixelInfo *pixel_info,double *alpha)
5359 if (image->alpha_trait != BlendPixelTrait)
5362 pixel_info->red=(double) GetPixelRed(image,pixel);
5363 pixel_info->green=(double) GetPixelGreen(image,pixel);
5364 pixel_info->blue=(double) GetPixelBlue(image,pixel);
5365 pixel_info->black=0.0;
5366 if (image->colorspace == CMYKColorspace)
5367 pixel_info->black=(double) GetPixelBlack(image,pixel);
5368 pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5371 *alpha=QuantumScale*GetPixelAlpha(image,pixel);
5372 pixel_info->red=(*alpha*GetPixelRed(image,pixel));
5373 pixel_info->green=(*alpha*GetPixelGreen(image,pixel));
5374 pixel_info->blue=(*alpha*GetPixelBlue(image,pixel));
5375 pixel_info->black=0.0;
5376 if (image->colorspace == CMYKColorspace)
5377 pixel_info->black=(*alpha*GetPixelBlack(image,pixel));
5378 pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5381 MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
5382 const CacheView *image_view,const PixelInterpolateMethod method,
5383 const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception)
5395 register const Quantum
5405 PixelInterpolateMethod
5408 assert(image != (Image *) NULL);
5409 assert(image->signature == MagickSignature);
5410 assert(image_view != (CacheView *) NULL);
5412 x_offset=(ssize_t) floor(x);
5413 y_offset=(ssize_t) floor(y);
5414 interpolate = method;
5415 if ( interpolate == UndefinedInterpolatePixel )
5416 interpolate = image->interpolate;
5417 switch (interpolate)
5419 case AverageInterpolatePixel: /* nearest 4 neighbours */
5420 case Average9InterpolatePixel: /* nearest 9 neighbours */
5421 case Average16InterpolatePixel: /* nearest 16 neighbours */
5426 count=2; /* size of the area to average - default nearest 4 */
5427 if (interpolate == Average9InterpolatePixel)
5430 x_offset=(ssize_t) (floor(x+0.5)-1);
5431 y_offset=(ssize_t) (floor(y+0.5)-1);
5433 else if (interpolate == Average16InterpolatePixel)
5439 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,(size_t) count,
5440 (size_t) count,exception);
5441 if (p == (const Quantum *) NULL)
5451 count*=count; /* number of pixels - square of size */
5452 for (i=0; i < (ssize_t) count; i++)
5454 AlphaBlendPixelInfo(image,p,pixels,alpha);
5455 gamma=PerceptibleReciprocal(alpha[0]);
5456 pixel->red+=gamma*pixels[0].red;
5457 pixel->green+=gamma*pixels[0].green;
5458 pixel->blue+=gamma*pixels[0].blue;
5459 pixel->black+=gamma*pixels[0].black;
5460 pixel->alpha+=pixels[0].alpha;
5461 p += GetPixelChannels(image);
5463 gamma=1.0/count; /* average weighting of each pixel in area */
5465 pixel->green*=gamma;
5467 pixel->black*=gamma;
5468 pixel->alpha*=gamma;
5471 case BackgroundInterpolatePixel:
5473 *pixel=image->background_color; /* Copy PixelInfo Structure */
5476 case BilinearInterpolatePixel:
5483 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5484 if (p == (const Quantum *) NULL)
5489 for (i=0; i < 4L; i++)
5490 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5493 epsilon.x=1.0-delta.x;
5494 epsilon.y=1.0-delta.y;
5495 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5496 (epsilon.x*alpha[2]+delta.x*alpha[3])));
5497 gamma=PerceptibleReciprocal(gamma);
5498 pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
5499 pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red));
5500 pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x*
5501 pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x*
5503 pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x*
5504 pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x*
5506 if (image->colorspace == CMYKColorspace)
5507 pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x*
5508 pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x*
5510 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5511 gamma=PerceptibleReciprocal(gamma);
5512 pixel->alpha=(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x*
5513 pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x*
5517 case BlendInterpolatePixel:
5519 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5520 if (p == (const Quantum *) NULL)
5525 for (i=0; i < 4L; i++)
5526 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5527 gamma=1.0; /* number of pixels blended together (its variable) */
5528 for (i=0; i <= 1L; i++)
5530 if ((y-y_offset) >= 0.75)
5532 alpha[i]=alpha[i+2]; /* take right pixels */
5533 pixels[i]=pixels[i+2];
5536 if ((y-y_offset) > 0.25)
5538 gamma=2.0; /* blend both pixels in row */
5539 alpha[i]+=alpha[i+2]; /* add up alpha weights */
5540 pixels[i].red+=pixels[i+2].red;
5541 pixels[i].green+=pixels[i+2].green;
5542 pixels[i].blue+=pixels[i+2].blue;
5543 pixels[i].black+=pixels[i+2].black;
5544 pixels[i].alpha+=pixels[i+2].alpha;
5547 if ((x-x_offset) >= 0.75)
5550 pixels[0]=pixels[1];
5553 if ((x-x_offset) > 0.25)
5555 gamma*=2.0; /* blend both rows */
5556 alpha[0]+= alpha[1]; /* add up alpha weights */
5557 pixels[0].red+=pixels[1].red;
5558 pixels[0].green+=pixels[1].green;
5559 pixels[0].blue+=pixels[1].blue;
5560 pixels[0].black+=pixels[1].black;
5561 pixels[0].alpha+=pixels[1].alpha;
5564 alpha[0]=PerceptibleReciprocal(alpha[0]);
5565 pixel->red=alpha[0]*pixels[0].red;
5566 pixel->green=alpha[0]*pixels[0].green; /* divide by sum of alpha */
5567 pixel->blue=alpha[0]*pixels[0].blue;
5568 pixel->black=alpha[0]*pixels[0].black;
5569 pixel->alpha=gamma*pixels[0].alpha; /* divide by number of pixels */
5572 case CatromInterpolatePixel:
5578 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5580 if (p == (const Quantum *) NULL)
5585 for (i=0; i < 16L; i++)
5586 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5587 CatromWeights((double) (x-x_offset),&cx);
5588 CatromWeights((double) (y-y_offset),&cy);
5589 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]*
5590 pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5591 pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]*
5592 pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5593 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]*
5594 pixels[14].red+cx[3]*pixels[15].red));
5595 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]*
5596 pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+
5597 cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+
5598 cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]*
5599 pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]*
5600 pixels[12].green+cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]*
5602 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]*
5603 pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5604 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]*
5605 pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5606 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+
5607 cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5608 if (image->colorspace == CMYKColorspace)
5609 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]*
5610 pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+
5611 cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+
5612 cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]*
5613 pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]*
5614 pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]*
5616 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]*
5617 pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+
5618 cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+
5619 cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]*
5620 pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+
5621 cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5624 case IntegerInterpolatePixel:
5626 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5627 if (p == (const Quantum *) NULL)
5632 GetPixelInfoPixel(image,p,pixel);
5635 case MeshInterpolatePixel:
5641 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5642 if (p == (const Quantum *) NULL)
5649 luminance.x=GetPixelLuma(image,p)-(double)
5650 GetPixelLuma(image,p+3*GetPixelChannels(image));
5651 luminance.y=GetPixelLuma(image,p+GetPixelChannels(image))-(double)
5652 GetPixelLuma(image,p+2*GetPixelChannels(image));
5653 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5654 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5655 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5656 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5657 if (fabs(luminance.x) < fabs(luminance.y))
5662 if (delta.x <= delta.y)
5665 Bottom-left triangle (pixel: 2, diagonal: 0-3).
5667 delta.y=1.0-delta.y;
5668 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5669 gamma=PerceptibleReciprocal(gamma);
5670 pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red,
5671 pixels[3].red,pixels[0].red);
5672 pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green,
5673 pixels[3].green,pixels[0].green);
5674 pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
5675 pixels[3].blue,pixels[0].blue);
5676 if (image->colorspace == CMYKColorspace)
5677 pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black,
5678 pixels[3].black,pixels[0].black);
5679 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5680 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha,
5681 pixels[3].alpha,pixels[0].alpha);
5686 Top-right triangle (pixel:1 , diagonal: 0-3).
5688 delta.x=1.0-delta.x;
5689 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5690 gamma=PerceptibleReciprocal(gamma);
5691 pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red,
5692 pixels[0].red,pixels[3].red);
5693 pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green,
5694 pixels[0].green,pixels[3].green);
5695 pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
5696 pixels[0].blue,pixels[3].blue);
5697 if (image->colorspace == CMYKColorspace)
5698 pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black,
5699 pixels[0].black,pixels[3].black);
5700 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5701 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha,
5702 pixels[0].alpha,pixels[3].alpha);
5710 if (delta.x <= (1.0-delta.y))
5713 Top-left triangle (pixel: 0, diagonal: 1-2).
5715 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5716 gamma=PerceptibleReciprocal(gamma);
5717 pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red,
5718 pixels[1].red,pixels[2].red);
5719 pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green,
5720 pixels[1].green,pixels[2].green);
5721 pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
5722 pixels[1].blue,pixels[2].blue);
5723 if (image->colorspace == CMYKColorspace)
5724 pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black,
5725 pixels[1].black,pixels[2].black);
5726 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5727 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha,
5728 pixels[1].alpha,pixels[2].alpha);
5733 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5735 delta.x=1.0-delta.x;
5736 delta.y=1.0-delta.y;
5737 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5738 gamma=PerceptibleReciprocal(gamma);
5739 pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red,
5740 pixels[2].red,pixels[1].red);
5741 pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green,
5742 pixels[2].green,pixels[1].green);
5743 pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
5744 pixels[2].blue,pixels[1].blue);
5745 if (image->colorspace == CMYKColorspace)
5746 pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black,
5747 pixels[2].black,pixels[1].black);
5748 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5749 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha,
5750 pixels[2].alpha,pixels[1].alpha);
5755 case NearestInterpolatePixel:
5757 x_offset=(ssize_t) floor(x+0.5);
5758 y_offset=(ssize_t) floor(y+0.5);
5759 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5760 if (p == (const Quantum *) NULL)
5765 GetPixelInfoPixel(image,p,pixel);
5768 case SplineInterpolatePixel:
5774 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5776 if (p == (const Quantum *) NULL)
5781 for (i=0; i < 16L; i++)
5782 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5783 SplineWeights((double) (x-x_offset),&cx);
5784 SplineWeights((double) (y-y_offset),&cy);
5785 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]*
5786 pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5787 pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]*
5788 pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5789 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]*
5790 pixels[14].red+cx[3]*pixels[15].red));
5791 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]*
5792 pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+
5793 cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+
5794 cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]*
5795 pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]*pixels[12].green+
5796 cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]*pixels[15].green));
5797 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]*
5798 pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5799 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]*
5800 pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5801 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+
5802 cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5803 if (image->colorspace == CMYKColorspace)
5804 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]*
5805 pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+
5806 cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+
5807 cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]*
5808 pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]*
5809 pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]*
5811 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]*
5812 pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+
5813 cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+
5814 cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]*
5815 pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+
5816 cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5824 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5828 + I s F u z z y E q u i v a l e n c e P i x e l %
5832 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5834 % IsFuzzyEquivalencePixel() returns MagickTrue if the distance between two
5835 % pixels is less than the specified distance in a linear three (or four)u
5836 % dimensional color space.
5838 % The format of the IsFuzzyEquivalencePixel method is:
5840 % void IsFuzzyEquivalencePixel(const Image *source,const Quantum *p,
5841 % const Image *destination,const Quantum *q)
5843 % A description of each parameter follows:
5845 % o source: the source image.
5849 % o destination: the destination image.
5854 MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *source,
5855 const Quantum *p,const Image *destination,const Quantum *q)
5865 fuzz=(double) MagickMax(source->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(
5866 destination->fuzz,(MagickRealType) MagickSQ1_2);
5869 if (source->alpha_trait == BlendPixelTrait)
5872 Transparencies are involved - set alpha distance
5874 pixel=GetPixelAlpha(source,p)-(double) GetPixelAlpha(destination,q);
5875 distance=pixel*pixel;
5876 if (distance > fuzz)
5877 return(MagickFalse);
5879 Generate a alpha scaling factor to generate a 4D cone on colorspace
5880 Note that if one color is transparent, distance has no color component.
5882 scale=QuantumScale*GetPixelAlpha(source,p);
5883 scale*=QuantumScale*GetPixelAlpha(destination,q);
5884 if (scale <= MagickEpsilon)
5888 RGB or CMY color cube
5890 distance*=3.0; /* rescale appropriately */
5892 pixel=GetPixelRed(source,p)-(double) GetPixelRed(destination,q);
5893 if ((source->colorspace == HSLColorspace) ||
5894 (source->colorspace == HSBColorspace) ||
5895 (source->colorspace == HWBColorspace))
5898 Compute an arc distance for hue. It should be a vector angle of
5899 'S'/'W' length with 'L'/'B' forming appropriate cones.
5901 if (fabs((double) pixel) > (QuantumRange/2))
5902 pixel-=QuantumRange;
5905 distance+=scale*pixel*pixel;
5906 if (distance > fuzz)
5907 return(MagickFalse);
5908 pixel=GetPixelGreen(source,p)-(double) GetPixelGreen(destination,q);
5909 distance+=scale*pixel*pixel;
5910 if (distance > fuzz)
5911 return(MagickFalse);
5912 pixel=GetPixelBlue(source,p)-(double) GetPixelBlue(destination,q);
5913 distance+=scale*pixel*pixel;
5914 if (distance > fuzz)
5915 return(MagickFalse);
5920 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5924 + I s F u z z y E q u i v a l e n c e P i x e l I n f o %
5928 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5930 % IsFuzzyEquivalencePixelInfo() returns true if the distance between two
5931 % colors is less than the specified distance in a linear three (or four)
5932 % dimensional color space.
5934 % This implements the equivalent of:
5935 % fuzz < sqrt(color_distance^2 * u.a*v.a + alpha_distance^2)
5937 % Which produces a multi-dimensional cone for that colorspace along the
5938 % transparency vector.
5940 % For example for an RGB:
5941 % color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3
5943 % See http://www.imagemagick.org/Usage/bugs/fuzz_distance/
5945 % Hue colorspace distances need more work. Hue is not a distance, it is an
5948 % A check that q is in the same color space as p should be made and the
5949 % appropriate mapping made. -- Anthony Thyssen 8 December 2010
5951 % The format of the IsFuzzyEquivalencePixelInfo method is:
5953 % MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5954 % const PixelInfo *q)
5956 % A description of each parameter follows:
5963 MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5974 if ((p->fuzz == 0.0) && (q->fuzz == 0.0))
5975 return(IsPixelInfoEquivalent(p,q));
5977 fuzz=MagickMax(q->fuzz,(MagickRealType) MagickSQ1_2)*
5978 MagickMax(q->fuzz,(MagickRealType) MagickSQ1_2);
5979 else if (q->fuzz == 0.0)
5980 fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*
5981 MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2);
5983 fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*
5984 MagickMax(q->fuzz,(MagickRealType) MagickSQ1_2);
5987 if ((p->alpha_trait == BlendPixelTrait) ||
5988 (q->alpha_trait == BlendPixelTrait))
5991 Transparencies are involved - set alpha distance.
5993 pixel=(p->alpha_trait == BlendPixelTrait ? p->alpha : OpaqueAlpha)-
5994 (q->alpha_trait == BlendPixelTrait ? q->alpha : OpaqueAlpha);
5995 distance=pixel*pixel;
5996 if (distance > fuzz)
5997 return(MagickFalse);
5999 Generate a alpha scaling factor to generate a 4D cone on colorspace.
6000 If one color is transparent, distance has no color component.
6002 if (p->alpha_trait == BlendPixelTrait)
6003 scale=(QuantumScale*p->alpha);
6004 if (q->alpha_trait == BlendPixelTrait)
6005 scale*=(QuantumScale*q->alpha);
6006 if (scale <= MagickEpsilon )
6010 CMYK create a CMY cube with a multi-dimensional cone toward black.
6012 if (p->colorspace == CMYKColorspace)
6014 pixel=p->black-q->black;
6015 distance+=pixel*pixel*scale;
6016 if (distance > fuzz)
6017 return(MagickFalse);
6018 scale*=(double) (QuantumScale*(QuantumRange-p->black));
6019 scale*=(double) (QuantumScale*(QuantumRange-q->black));
6022 RGB or CMY color cube.
6024 distance*=3.0; /* rescale appropriately */
6026 pixel=p->red-q->red;
6027 if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) ||
6028 (p->colorspace == HWBColorspace))
6031 This calculates a arc distance for hue-- it should be a vector
6032 angle of 'S'/'W' length with 'L'/'B' forming appropriate cones.
6033 In other words this is a hack - Anthony.
6035 if (fabs((double) pixel) > (QuantumRange/2))
6036 pixel-=QuantumRange;
6039 distance+=pixel*pixel*scale;
6040 if (distance > fuzz)
6041 return(MagickFalse);
6042 pixel=p->green-q->green;
6043 distance+=pixel*pixel*scale;
6044 if (distance > fuzz)
6045 return(MagickFalse);
6046 pixel=p->blue-q->blue;
6047 distance+=pixel*pixel*scale;
6048 if (distance > fuzz)
6049 return(MagickFalse);
6054 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6058 % S e t P i x e l C h a n n e l M a s k %
6062 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6064 % SetPixelChannelMask() sets the pixel channel map from the specified channel
6067 % The format of the SetPixelChannelMask method is:
6069 % void SetPixelChannelMask(Image *image,const ChannelType channel_mask)
6071 % A description of each parameter follows:
6073 % o image: the image.
6075 % o channel_mask: the channel mask.
6078 MagickExport void SetPixelChannelMask(Image *image,
6079 const ChannelType channel_mask)
6081 #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
6086 if (image->debug != MagickFalse)
6087 (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%08x]", \
6088 image->filename,channel_mask); \
6089 image->channel_mask=channel_mask;
6090 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
6092 PixelChannel channel=GetPixelChannelChannel(image,i);
6093 SetPixelChannelTraits(image,channel,
6094 GetChannelBit(channel_mask,channel) == 0 ? CopyPixelTrait :
6095 image->alpha_trait != BlendPixelTrait || (channel == AlphaPixelChannel) ?
6096 UpdatePixelTrait : (PixelTrait) (UpdatePixelTrait | image->alpha_trait));
6098 if (image->storage_class == PseudoClass)
6099 SetPixelChannelTraits(image,IndexPixelChannel,CopyPixelTrait);
6100 if (image->read_mask != MagickFalse)
6101 SetPixelChannelTraits(image,ReadMaskPixelChannel,CopyPixelTrait);
6102 if (image->write_mask != MagickFalse)
6103 SetPixelChannelTraits(image,WriteMaskPixelChannel,CopyPixelTrait);
6104 if (image->debug != MagickFalse)
6105 LogPixelChannels(image);
6109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6113 % S e t P i x e l M e t a C h a n n e l s %
6117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6119 % SetPixelMetaChannels() sets the image meta channels.
6121 % The format of the SetPixelMetaChannels method is:
6123 % MagickBooleanType SetPixelMetaChannels(Image *image,
6124 % const size_t number_meta_channels,ExceptionInfo *exception)
6126 % A description of each parameter follows:
6128 % o image: the image.
6130 % o number_meta_channels: the number of meta channels.
6132 % o exception: return any errors or warnings in this structure.
6135 MagickExport MagickBooleanType SetPixelMetaChannels(Image *image,
6136 const size_t number_meta_channels,ExceptionInfo *exception)
6138 image->number_meta_channels=number_meta_channels;
6139 return(SyncImagePixelCache(image,exception));