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-2013 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"
73 #define LogPixelChannels(image) \
78 (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%.20g]", \
79 image->filename,(double) image->number_channels); \
80 for (i=0; i < (ssize_t) image->number_channels; i++) \
83 traits[MaxTextExtent]; \
91 switch (GetPixelChannelChannel(image,i)) \
93 case RedPixelChannel: \
96 if (image->colorspace == CMYKColorspace) \
98 if (image->colorspace == GRAYColorspace) \
102 case GreenPixelChannel: \
105 if (image->colorspace == CMYKColorspace) \
109 case BluePixelChannel: \
112 if (image->colorspace == CMYKColorspace) \
116 case BlackPixelChannel: \
119 if (image->storage_class == PseudoClass) \
123 case IndexPixelChannel: \
128 case AlphaPixelChannel: \
133 case MaskPixelChannel: \
138 case MetaPixelChannel: \
146 channel=GetPixelChannelChannel(image,i); \
148 if ((GetPixelChannelTraits(image,channel) & UpdatePixelTrait) != 0) \
149 (void) ConcatenateMagickString(traits,"update,",MaxTextExtent); \
150 if ((GetPixelChannelTraits(image,channel) & BlendPixelTrait) != 0) \
151 (void) ConcatenateMagickString(traits,"blend,",MaxTextExtent); \
152 if ((GetPixelChannelTraits(image,channel) & CopyPixelTrait) != 0) \
153 (void) ConcatenateMagickString(traits,"copy,",MaxTextExtent); \
154 if (*traits == '\0') \
155 (void) ConcatenateMagickString(traits,"undefined,",MaxTextExtent); \
156 traits[strlen(traits)-1]='\0'; \
157 (void) LogMagickEvent(PixelEvent,GetMagickModule()," %.20g: %s (%s)", \
158 (double) i,name,traits); \
163 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
167 + A c q u i r e P i x e l C h a n n e l M a p %
171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173 % AcquirePixelChannelMap() acquires a pixel component map.
175 % The format of the AcquirePixelChannelMap() method is:
177 % PixelChannelMap *AcquirePixelChannelMap(void)
180 MagickExport PixelChannelMap *AcquirePixelChannelMap(void)
188 channel_map=(PixelChannelMap *) AcquireQuantumMemory(MaxPixelChannels,
189 sizeof(*channel_map));
190 if (channel_map == (PixelChannelMap *) NULL)
191 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
192 (void) ResetMagickMemory(channel_map,0,MaxPixelChannels*sizeof(*channel_map));
193 for (i=0; i < MaxPixelChannels; i++)
194 channel_map[i].channel=(PixelChannel) i;
199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 + C l o n e P i x e l C h a n n e l M a p %
207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209 % ClonePixelChannelMap() clones a pixel component map.
211 % The format of the ClonePixelChannelMap() method is:
213 % PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
215 % A description of each parameter follows:
217 % o channel_map: the pixel component map.
220 MagickExport PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
225 assert(channel_map != (PixelChannelMap *) NULL);
226 clone_map=AcquirePixelChannelMap();
227 if (clone_map == (PixelChannelMap *) NULL)
228 return((PixelChannelMap *) NULL);
229 (void) CopyMagickMemory(clone_map,channel_map,MaxPixelChannels*
230 sizeof(*channel_map));
235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239 + C l o n e P i x e l I n f o %
243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
245 % ClonePixelInfo() makes a duplicate of the given pixel info structure, or if
246 % pixel info is NULL, a new one.
248 % The format of the ClonePixelInfo method is:
250 % PixelInfo *ClonePixelInfo(const PixelInfo *pixel_info)
252 % A description of each parameter follows:
254 % o pixel_info: the pixel info.
257 MagickExport PixelInfo *ClonePixelInfo(const PixelInfo *pixel)
262 pixel_info=(PixelInfo *) AcquireQuantumMemory(1,sizeof(*pixel_info));
263 if (pixel_info == (PixelInfo *) NULL)
264 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
265 *pixel_info=(*pixel);
270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
274 % D e c o d e P i x e l G a m m a %
278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280 % DecodePixelGamma() applies the expansive power-law nonlinearity to the pixel.
282 % The format of the DecodePixelGammaImage method is:
284 % double DecodePixelGamma(const MagickRealType pixel)
286 % A description of each parameter follows:
288 % o pixel: the pixel.
291 MagickExport MagickRealType DecodePixelGamma(const MagickRealType pixel)
293 if (pixel <= (0.0404482362771076*QuantumRange))
294 return(pixel/12.92f);
295 return((MagickRealType) (QuantumRange*pow((double) (QuantumScale*pixel+
300 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304 + D e s t r o y P i x e l C h a n n e l M a p %
308 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
310 % DestroyPixelChannelMap() deallocates memory associated with the pixel
313 % The format of the DestroyPixelChannelMap() method is:
315 % PixelChannelMap *DestroyPixelChannelMap(PixelChannelMap *channel_map)
317 % A description of each parameter follows:
319 % o channel_map: the pixel component map.
322 MagickExport PixelChannelMap *DestroyPixelChannelMap(
323 PixelChannelMap *channel_map)
325 assert(channel_map != (PixelChannelMap *) NULL);
326 channel_map=(PixelChannelMap *) RelinquishMagickMemory(channel_map);
327 return((PixelChannelMap *) RelinquishMagickMemory(channel_map));
331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335 + E n c o d e P i x e l G a m m a %
339 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
341 % EncodePixelGamma() cancels any nonlinearity in the pixel.
343 % The format of the EncodePixelGammaImage method is:
345 % MagickRealType EncodePixelGamma(const double MagickRealType)
347 % A description of each parameter follows:
349 % o pixel: the pixel.
352 MagickExport MagickRealType EncodePixelGamma(const MagickRealType pixel)
354 if (pixel <= (0.0031306684425005883*QuantumRange))
355 return(12.92f*pixel);
356 return((MagickRealType) QuantumRange*(1.055*pow((double) QuantumScale*pixel,
361 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
365 % E x p o r t I m a g e P i x e l s %
369 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
371 % ExportImagePixels() extracts pixel data from an image and returns it to you.
372 % The method returns MagickTrue on success otherwise MagickFalse if an error is
373 % encountered. The data is returned as char, short int, Quantum, unsigned int,
374 % unsigned long long, float, or double in the order specified by map.
376 % Suppose you want to extract the first scanline of a 640x480 image as
377 % character data in red-green-blue order:
379 % ExportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels,exception);
381 % The format of the ExportImagePixels method is:
383 % MagickBooleanType ExportImagePixels(const Image *image,const ssize_t x,
384 % const ssize_t y,const size_t width,const size_t height,
385 % const char *map,const StorageType type,void *pixels,
386 % ExceptionInfo *exception)
388 % A description of each parameter follows:
390 % o image: the image.
392 % o x,y,width,height: These values define the perimeter
393 % of a region of pixels you want to extract.
395 % o map: This string reflects the expected ordering of the pixel array.
396 % It can be any combination or order of R = red, G = green, B = blue,
397 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
398 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
401 % o type: Define the data type of the pixels. Float and double types are
402 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
403 % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *),
404 % LongPixel (unsigned int *), LongLongPixel (unsigned long long *),
405 % QuantumPixel (Quantum *), or ShortPixel (unsigned short *).
407 % o pixels: This array of values contain the pixel components as defined by
408 % map and type. You must preallocate this array where the expected
409 % length varies depending on the values of width, height, map, and type.
411 % o exception: return any errors or warnings in this structure.
415 static void ExportCharPixel(Image *image,const RectangleInfo *roi,
416 const char *restrict map,const QuantumType *quantum_map,void *pixels,
417 ExceptionInfo *exception)
419 register const Quantum
425 register unsigned char
434 q=(unsigned char *) pixels;
435 if (LocaleCompare(map,"BGR") == 0)
437 for (y=0; y < (ssize_t) roi->height; y++)
439 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
440 if (p == (const Quantum *) NULL)
442 for (x=0; x < (ssize_t) roi->width; x++)
444 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
445 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
446 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
447 p+=GetPixelChannels(image);
452 if (LocaleCompare(map,"BGRA") == 0)
454 for (y=0; y < (ssize_t) roi->height; y++)
456 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
457 if (p == (const Quantum *) NULL)
459 for (x=0; x < (ssize_t) roi->width; x++)
461 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
462 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
463 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
464 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
465 p+=GetPixelChannels(image);
470 if (LocaleCompare(map,"BGRP") == 0)
472 for (y=0; y < (ssize_t) roi->height; y++)
474 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
475 if (p == (const Quantum *) NULL)
477 for (x=0; x < (ssize_t) roi->width; x++)
479 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
480 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
481 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
482 *q++=ScaleQuantumToChar((Quantum) 0);
483 p+=GetPixelChannels(image);
488 if (LocaleCompare(map,"I") == 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(GetPixelIntensity(image,p));
498 p+=GetPixelChannels(image);
503 if (LocaleCompare(map,"RGB") == 0)
505 for (y=0; y < (ssize_t) roi->height; y++)
507 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
508 if (p == (const Quantum *) NULL)
510 for (x=0; x < (ssize_t) roi->width; x++)
512 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
513 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
514 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
515 p+=GetPixelChannels(image);
520 if (LocaleCompare(map,"RGBA") == 0)
522 for (y=0; y < (ssize_t) roi->height; y++)
524 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
525 if (p == (const Quantum *) NULL)
527 for (x=0; x < (ssize_t) roi->width; x++)
529 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
530 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
531 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
532 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
533 p+=GetPixelChannels(image);
538 if (LocaleCompare(map,"RGBP") == 0)
540 for (y=0; y < (ssize_t) roi->height; y++)
542 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
543 if (p == (const Quantum *) NULL)
545 for (x=0; x < (ssize_t) roi->width; x++)
547 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
548 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
549 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
550 *q++=ScaleQuantumToChar((Quantum) 0);
551 p+=GetPixelChannels(image);
557 for (y=0; y < (ssize_t) roi->height; y++)
559 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
560 if (p == (const Quantum *) NULL)
562 for (x=0; x < (ssize_t) roi->width; x++)
567 for (i=0; i < (ssize_t) length; i++)
570 switch (quantum_map[i])
575 *q=ScaleQuantumToChar(GetPixelRed(image,p));
581 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
587 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
592 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
597 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
602 if (image->colorspace == CMYKColorspace)
603 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
608 *q=ScaleQuantumToChar(GetPixelIntensity(image,p));
616 p+=GetPixelChannels(image);
621 static void ExportDoublePixel(Image *image,const RectangleInfo *roi,
622 const char *restrict map,const QuantumType *quantum_map,void *pixels,
623 ExceptionInfo *exception)
625 register const Quantum
641 if (LocaleCompare(map,"BGR") == 0)
643 for (y=0; y < (ssize_t) roi->height; y++)
645 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
646 if (p == (const Quantum *) NULL)
648 for (x=0; x < (ssize_t) roi->width; x++)
650 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
651 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
652 *q++=(double) (QuantumScale*GetPixelRed(image,p));
653 p+=GetPixelChannels(image);
658 if (LocaleCompare(map,"BGRA") == 0)
660 for (y=0; y < (ssize_t) roi->height; y++)
662 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
663 if (p == (const Quantum *) NULL)
665 for (x=0; x < (ssize_t) roi->width; x++)
667 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
668 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
669 *q++=(double) (QuantumScale*GetPixelRed(image,p));
670 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
671 p+=GetPixelChannels(image);
676 if (LocaleCompare(map,"BGRP") == 0)
678 for (y=0; y < (ssize_t) roi->height; y++)
680 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
681 if (p == (const Quantum *) NULL)
683 for (x=0; x < (ssize_t) roi->width; x++)
685 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
686 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
687 *q++=(double) (QuantumScale*GetPixelRed(image,p));
689 p+=GetPixelChannels(image);
694 if (LocaleCompare(map,"I") == 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*GetPixelIntensity(image,p));
704 p+=GetPixelChannels(image);
709 if (LocaleCompare(map,"RGB") == 0)
711 for (y=0; y < (ssize_t) roi->height; y++)
713 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
714 if (p == (const Quantum *) NULL)
716 for (x=0; x < (ssize_t) roi->width; x++)
718 *q++=(double) (QuantumScale*GetPixelRed(image,p));
719 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
720 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
721 p+=GetPixelChannels(image);
726 if (LocaleCompare(map,"RGBA") == 0)
728 for (y=0; y < (ssize_t) roi->height; y++)
730 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
731 if (p == (const Quantum *) NULL)
733 for (x=0; x < (ssize_t) roi->width; x++)
735 *q++=(double) (QuantumScale*GetPixelRed(image,p));
736 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
737 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
738 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
739 p+=GetPixelChannels(image);
744 if (LocaleCompare(map,"RGBP") == 0)
746 for (y=0; y < (ssize_t) roi->height; y++)
748 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
749 if (p == (const Quantum *) NULL)
751 for (x=0; x < (ssize_t) roi->width; x++)
753 *q++=(double) (QuantumScale*GetPixelRed(image,p));
754 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
755 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
757 p+=GetPixelChannels(image);
763 for (y=0; y < (ssize_t) roi->height; y++)
765 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
766 if (p == (const Quantum *) NULL)
768 for (x=0; x < (ssize_t) roi->width; x++)
773 for (i=0; i < (ssize_t) length; i++)
776 switch (quantum_map[i])
781 *q=(double) (QuantumScale*GetPixelRed(image,p));
787 *q=(double) (QuantumScale*GetPixelGreen(image,p));
793 *q=(double) (QuantumScale*GetPixelBlue(image,p));
798 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
803 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
808 if (image->colorspace == CMYKColorspace)
809 *q=(double) (QuantumScale*
810 GetPixelBlack(image,p));
815 *q=(double) (QuantumScale*GetPixelIntensity(image,p));
823 p+=GetPixelChannels(image);
828 static void ExportFloatPixel(Image *image,const RectangleInfo *roi,
829 const char *restrict map,const QuantumType *quantum_map,void *pixels,
830 ExceptionInfo *exception)
832 register const Quantum
848 if (LocaleCompare(map,"BGR") == 0)
850 for (y=0; y < (ssize_t) roi->height; y++)
852 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
853 if (p == (const Quantum *) NULL)
855 for (x=0; x < (ssize_t) roi->width; x++)
857 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
858 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
859 *q++=(float) (QuantumScale*GetPixelRed(image,p));
860 p+=GetPixelChannels(image);
865 if (LocaleCompare(map,"BGRA") == 0)
867 for (y=0; y < (ssize_t) roi->height; y++)
869 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
870 if (p == (const Quantum *) NULL)
872 for (x=0; x < (ssize_t) roi->width; x++)
874 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
875 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
876 *q++=(float) (QuantumScale*GetPixelRed(image,p));
877 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
878 p+=GetPixelChannels(image);
883 if (LocaleCompare(map,"BGRP") == 0)
885 for (y=0; y < (ssize_t) roi->height; y++)
887 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
888 if (p == (const Quantum *) NULL)
890 for (x=0; x < (ssize_t) roi->width; x++)
892 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
893 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
894 *q++=(float) (QuantumScale*GetPixelRed(image,p));
896 p+=GetPixelChannels(image);
901 if (LocaleCompare(map,"I") == 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*GetPixelIntensity(image,p));
911 p+=GetPixelChannels(image);
916 if (LocaleCompare(map,"RGB") == 0)
918 for (y=0; y < (ssize_t) roi->height; y++)
920 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
921 if (p == (const Quantum *) NULL)
923 for (x=0; x < (ssize_t) roi->width; x++)
925 *q++=(float) (QuantumScale*GetPixelRed(image,p));
926 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
927 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
928 p+=GetPixelChannels(image);
933 if (LocaleCompare(map,"RGBA") == 0)
935 for (y=0; y < (ssize_t) roi->height; y++)
937 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
938 if (p == (const Quantum *) NULL)
940 for (x=0; x < (ssize_t) roi->width; x++)
942 *q++=(float) (QuantumScale*GetPixelRed(image,p));
943 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
944 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
945 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
946 p+=GetPixelChannels(image);
951 if (LocaleCompare(map,"RGBP") == 0)
953 for (y=0; y < (ssize_t) roi->height; y++)
955 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
956 if (p == (const Quantum *) NULL)
958 for (x=0; x < (ssize_t) roi->width; x++)
960 *q++=(float) (QuantumScale*GetPixelRed(image,p));
961 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
962 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
964 p+=GetPixelChannels(image);
970 for (y=0; y < (ssize_t) roi->height; y++)
972 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
973 if (p == (const Quantum *) NULL)
975 for (x=0; x < (ssize_t) roi->width; x++)
980 for (i=0; i < (ssize_t) length; i++)
983 switch (quantum_map[i])
988 *q=(float) (QuantumScale*GetPixelRed(image,p));
994 *q=(float) (QuantumScale*GetPixelGreen(image,p));
1000 *q=(float) (QuantumScale*GetPixelBlue(image,p));
1005 *q=(float) (QuantumScale*((Quantum) (GetPixelAlpha(image,p))));
1008 case OpacityQuantum:
1010 *q=(float) (QuantumScale*GetPixelAlpha(image,p));
1015 if (image->colorspace == CMYKColorspace)
1016 *q=(float) (QuantumScale* GetPixelBlack(image,p));
1021 *q=(float) (QuantumScale*GetPixelIntensity(image,p));
1029 p+=GetPixelChannels(image);
1034 static void ExportLongPixel(Image *image,const RectangleInfo *roi,
1035 const char *restrict map,const QuantumType *quantum_map,void *pixels,
1036 ExceptionInfo *exception)
1038 register const Quantum
1044 register unsigned int
1053 q=(unsigned int *) pixels;
1054 if (LocaleCompare(map,"BGR") == 0)
1056 for (y=0; y < (ssize_t) roi->height; y++)
1058 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1059 if (p == (const Quantum *) NULL)
1061 for (x=0; x < (ssize_t) roi->width; x++)
1063 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1064 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1065 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1066 p+=GetPixelChannels(image);
1071 if (LocaleCompare(map,"BGRA") == 0)
1073 for (y=0; y < (ssize_t) roi->height; y++)
1075 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1076 if (p == (const Quantum *) NULL)
1078 for (x=0; x < (ssize_t) roi->width; x++)
1080 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1081 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1082 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1083 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1084 p+=GetPixelChannels(image);
1089 if (LocaleCompare(map,"BGRP") == 0)
1091 for (y=0; y < (ssize_t) roi->height; y++)
1093 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1094 if (p == (const Quantum *) NULL)
1096 for (x=0; x < (ssize_t) roi->width; x++)
1098 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1099 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1100 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1102 p+=GetPixelChannels(image);
1107 if (LocaleCompare(map,"I") == 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(GetPixelIntensity(image,p));
1117 p+=GetPixelChannels(image);
1122 if (LocaleCompare(map,"RGB") == 0)
1124 for (y=0; y < (ssize_t) roi->height; y++)
1126 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1127 if (p == (const Quantum *) NULL)
1129 for (x=0; x < (ssize_t) roi->width; x++)
1131 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1132 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1133 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1134 p+=GetPixelChannels(image);
1139 if (LocaleCompare(map,"RGBA") == 0)
1141 for (y=0; y < (ssize_t) roi->height; y++)
1143 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1144 if (p == (const Quantum *) NULL)
1146 for (x=0; x < (ssize_t) roi->width; x++)
1148 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1149 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1150 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1151 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1152 p+=GetPixelChannels(image);
1157 if (LocaleCompare(map,"RGBP") == 0)
1159 for (y=0; y < (ssize_t) roi->height; y++)
1161 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1162 if (p == (const Quantum *) NULL)
1164 for (x=0; x < (ssize_t) roi->width; x++)
1166 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1167 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1168 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1170 p+=GetPixelChannels(image);
1176 for (y=0; y < (ssize_t) roi->height; y++)
1178 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1179 if (p == (const Quantum *) NULL)
1181 for (x=0; x < (ssize_t) roi->width; x++)
1186 for (i=0; i < (ssize_t) length; i++)
1189 switch (quantum_map[i])
1194 *q=ScaleQuantumToLong(GetPixelRed(image,p));
1198 case MagentaQuantum:
1200 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
1206 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
1211 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1214 case OpacityQuantum:
1216 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1221 if (image->colorspace == CMYKColorspace)
1222 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
1227 *q=ScaleQuantumToLong(GetPixelIntensity(image,p));
1235 p+=GetPixelChannels(image);
1240 static void ExportLongLongPixel(Image *image,const RectangleInfo *roi,
1241 const char *restrict map,const QuantumType *quantum_map,void *pixels,
1242 ExceptionInfo *exception)
1244 register const Quantum
1250 register MagickSizeType
1259 q=(MagickSizeType *) pixels;
1260 if (LocaleCompare(map,"BGR") == 0)
1262 for (y=0; y < (ssize_t) roi->height; y++)
1264 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1265 if (p == (const Quantum *) NULL)
1267 for (x=0; x < (ssize_t) roi->width; x++)
1269 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1270 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1271 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1272 p+=GetPixelChannels(image);
1277 if (LocaleCompare(map,"BGRA") == 0)
1279 for (y=0; y < (ssize_t) roi->height; y++)
1281 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1282 if (p == (const Quantum *) NULL)
1284 for (x=0; x < (ssize_t) roi->width; x++)
1286 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1287 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1288 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1289 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1290 p+=GetPixelChannels(image);
1295 if (LocaleCompare(map,"BGRP") == 0)
1297 for (y=0; y < (ssize_t) roi->height; y++)
1299 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1300 if (p == (const Quantum *) NULL)
1302 for (x=0; x < (ssize_t) roi->width; x++)
1304 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1305 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1306 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1308 p+=GetPixelChannels(image);
1313 if (LocaleCompare(map,"I") == 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(GetPixelIntensity(image,p));
1323 p+=GetPixelChannels(image);
1328 if (LocaleCompare(map,"RGB") == 0)
1330 for (y=0; y < (ssize_t) roi->height; y++)
1332 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1333 if (p == (const Quantum *) NULL)
1335 for (x=0; x < (ssize_t) roi->width; x++)
1337 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1338 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1339 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1340 p+=GetPixelChannels(image);
1345 if (LocaleCompare(map,"RGBA") == 0)
1347 for (y=0; y < (ssize_t) roi->height; y++)
1349 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1350 if (p == (const Quantum *) NULL)
1352 for (x=0; x < (ssize_t) roi->width; x++)
1354 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1355 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1356 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1357 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1358 p+=GetPixelChannels(image);
1363 if (LocaleCompare(map,"RGBP") == 0)
1365 for (y=0; y < (ssize_t) roi->height; y++)
1367 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1368 if (p == (const Quantum *) NULL)
1370 for (x=0; x < (ssize_t) roi->width; x++)
1372 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1373 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1374 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1376 p+=GetPixelChannels(image);
1382 for (y=0; y < (ssize_t) roi->height; y++)
1384 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1385 if (p == (const Quantum *) NULL)
1387 for (x=0; x < (ssize_t) roi->width; x++)
1392 for (i=0; i < (ssize_t) length; i++)
1395 switch (quantum_map[i])
1400 *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
1404 case MagentaQuantum:
1406 *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1412 *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1417 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1420 case OpacityQuantum:
1422 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1427 if (image->colorspace == CMYKColorspace)
1428 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
1433 *q=ScaleQuantumToLongLong(GetPixelIntensity(image,p));
1441 p+=GetPixelChannels(image);
1446 static void ExportQuantumPixel(Image *image,const RectangleInfo *roi,
1447 const char *restrict map,const QuantumType *quantum_map,void *pixels,
1448 ExceptionInfo *exception)
1450 register const Quantum
1465 q=(Quantum *) pixels;
1466 if (LocaleCompare(map,"BGR") == 0)
1468 for (y=0; y < (ssize_t) roi->height; y++)
1470 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1471 if (p == (const Quantum *) NULL)
1473 for (x=0; x < (ssize_t) roi->width; x++)
1475 *q++=GetPixelBlue(image,p);
1476 *q++=GetPixelGreen(image,p);
1477 *q++=GetPixelRed(image,p);
1478 p+=GetPixelChannels(image);
1483 if (LocaleCompare(map,"BGRA") == 0)
1485 for (y=0; y < (ssize_t) roi->height; y++)
1487 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1488 if (p == (const Quantum *) NULL)
1490 for (x=0; x < (ssize_t) roi->width; x++)
1492 *q++=GetPixelBlue(image,p);
1493 *q++=GetPixelGreen(image,p);
1494 *q++=GetPixelRed(image,p);
1495 *q++=(Quantum) (GetPixelAlpha(image,p));
1496 p+=GetPixelChannels(image);
1501 if (LocaleCompare(map,"BGRP") == 0)
1503 for (y=0; y < (ssize_t) roi->height; y++)
1505 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1506 if (p == (const Quantum *) NULL)
1508 for (x=0; x < (ssize_t) roi->width; x++)
1510 *q++=GetPixelBlue(image,p);
1511 *q++=GetPixelGreen(image,p);
1512 *q++=GetPixelRed(image,p);
1514 p+=GetPixelChannels(image);
1519 if (LocaleCompare(map,"I") == 0)
1521 for (y=0; y < (ssize_t) roi->height; y++)
1523 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1524 if (p == (const Quantum *) NULL)
1526 for (x=0; x < (ssize_t) roi->width; x++)
1528 *q++=GetPixelIntensity(image,p);
1529 p+=GetPixelChannels(image);
1534 if (LocaleCompare(map,"RGB") == 0)
1536 for (y=0; y < (ssize_t) roi->height; y++)
1538 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1539 if (p == (const Quantum *) NULL)
1541 for (x=0; x < (ssize_t) roi->width; x++)
1543 *q++=GetPixelRed(image,p);
1544 *q++=GetPixelGreen(image,p);
1545 *q++=GetPixelBlue(image,p);
1546 p+=GetPixelChannels(image);
1551 if (LocaleCompare(map,"RGBA") == 0)
1553 for (y=0; y < (ssize_t) roi->height; y++)
1555 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1556 if (p == (const Quantum *) NULL)
1558 for (x=0; x < (ssize_t) roi->width; x++)
1560 *q++=GetPixelRed(image,p);
1561 *q++=GetPixelGreen(image,p);
1562 *q++=GetPixelBlue(image,p);
1563 *q++=(Quantum) (GetPixelAlpha(image,p));
1564 p+=GetPixelChannels(image);
1569 if (LocaleCompare(map,"RGBP") == 0)
1571 for (y=0; y < (ssize_t) roi->height; y++)
1573 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1574 if (p == (const Quantum *) NULL)
1576 for (x=0; x < (ssize_t) roi->width; x++)
1578 *q++=GetPixelRed(image,p);
1579 *q++=GetPixelGreen(image,p);
1580 *q++=GetPixelBlue(image,p);
1582 p+=GetPixelChannels(image);
1588 for (y=0; y < (ssize_t) roi->height; y++)
1590 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1591 if (p == (const Quantum *) NULL)
1593 for (x=0; x < (ssize_t) roi->width; x++)
1598 for (i=0; i < (ssize_t) length; i++)
1601 switch (quantum_map[i])
1606 *q=GetPixelRed(image,p);
1610 case MagentaQuantum:
1612 *q=GetPixelGreen(image,p);
1618 *q=GetPixelBlue(image,p);
1623 *q=GetPixelAlpha(image,p);
1626 case OpacityQuantum:
1628 *q=GetPixelAlpha(image,p);
1633 if (image->colorspace == CMYKColorspace)
1634 *q=GetPixelBlack(image,p);
1639 *q=(GetPixelIntensity(image,p));
1650 p+=GetPixelChannels(image);
1655 static void ExportShortPixel(Image *image,const RectangleInfo *roi,
1656 const char *restrict map,const QuantumType *quantum_map,void *pixels,
1657 ExceptionInfo *exception)
1659 register const Quantum
1665 register unsigned short
1674 q=(unsigned short *) pixels;
1675 if (LocaleCompare(map,"BGR") == 0)
1677 for (y=0; y < (ssize_t) roi->height; y++)
1679 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1680 if (p == (const Quantum *) NULL)
1682 for (x=0; x < (ssize_t) roi->width; x++)
1684 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1685 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1686 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1687 p+=GetPixelChannels(image);
1692 if (LocaleCompare(map,"BGRA") == 0)
1694 for (y=0; y < (ssize_t) roi->height; y++)
1696 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1697 if (p == (const Quantum *) NULL)
1699 for (x=0; x < (ssize_t) roi->width; x++)
1701 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1702 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1703 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1704 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1705 p+=GetPixelChannels(image);
1710 if (LocaleCompare(map,"BGRP") == 0)
1712 for (y=0; y < (ssize_t) roi->height; y++)
1714 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1715 if (p == (const Quantum *) NULL)
1717 for (x=0; x < (ssize_t) roi->width; x++)
1719 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1720 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1721 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1723 p+=GetPixelChannels(image);
1728 if (LocaleCompare(map,"I") == 0)
1730 for (y=0; y < (ssize_t) roi->height; y++)
1732 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1733 if (p == (const Quantum *) NULL)
1735 for (x=0; x < (ssize_t) roi->width; x++)
1737 *q++=ScaleQuantumToShort(GetPixelIntensity(image,p));
1738 p+=GetPixelChannels(image);
1743 if (LocaleCompare(map,"RGB") == 0)
1745 for (y=0; y < (ssize_t) roi->height; y++)
1747 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1748 if (p == (const Quantum *) NULL)
1750 for (x=0; x < (ssize_t) roi->width; x++)
1752 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1753 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1754 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1755 p+=GetPixelChannels(image);
1760 if (LocaleCompare(map,"RGBA") == 0)
1762 for (y=0; y < (ssize_t) roi->height; y++)
1764 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1765 if (p == (const Quantum *) NULL)
1767 for (x=0; x < (ssize_t) roi->width; x++)
1769 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1770 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1771 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1772 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1773 p+=GetPixelChannels(image);
1778 if (LocaleCompare(map,"RGBP") == 0)
1780 for (y=0; y < (ssize_t) roi->height; y++)
1782 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1783 if (p == (const Quantum *) NULL)
1785 for (x=0; x < (ssize_t) roi->width; x++)
1787 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1788 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1789 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1791 p+=GetPixelChannels(image);
1797 for (y=0; y < (ssize_t) roi->height; y++)
1799 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1800 if (p == (const Quantum *) NULL)
1802 for (x=0; x < (ssize_t) roi->width; x++)
1807 for (i=0; i < (ssize_t) length; i++)
1810 switch (quantum_map[i])
1815 *q=ScaleQuantumToShort(GetPixelRed(image,p));
1819 case MagentaQuantum:
1821 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
1827 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
1832 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1835 case OpacityQuantum:
1837 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1842 if (image->colorspace == CMYKColorspace)
1843 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
1848 *q=ScaleQuantumToShort(GetPixelIntensity(image,p));
1856 p+=GetPixelChannels(image);
1861 MagickExport MagickBooleanType ExportImagePixels(Image *image,
1862 const ssize_t x,const ssize_t y,const size_t width,const size_t height,
1863 const char *map,const StorageType type,void *pixels,ExceptionInfo *exception)
1877 assert(image != (Image *) NULL);
1878 assert(image->signature == MagickSignature);
1879 if (image->debug != MagickFalse)
1880 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1882 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1883 if (quantum_map == (QuantumType *) NULL)
1885 (void) ThrowMagickException(exception,GetMagickModule(),
1886 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1887 return(MagickFalse);
1889 for (i=0; i < (ssize_t) length; i++)
1896 quantum_map[i]=AlphaQuantum;
1902 quantum_map[i]=BlueQuantum;
1908 quantum_map[i]=CyanQuantum;
1909 if (image->colorspace == CMYKColorspace)
1911 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1912 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1913 "ColorSeparatedImageRequired","`%s'",map);
1914 return(MagickFalse);
1919 quantum_map[i]=GreenQuantum;
1925 quantum_map[i]=IndexQuantum;
1931 quantum_map[i]=BlackQuantum;
1932 if (image->colorspace == CMYKColorspace)
1934 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1935 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1936 "ColorSeparatedImageRequired","`%s'",map);
1937 return(MagickFalse);
1942 quantum_map[i]=MagentaQuantum;
1943 if (image->colorspace == CMYKColorspace)
1945 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1946 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1947 "ColorSeparatedImageRequired","`%s'",map);
1948 return(MagickFalse);
1953 quantum_map[i]=OpacityQuantum;
1959 quantum_map[i]=UndefinedQuantum;
1965 quantum_map[i]=RedQuantum;
1971 quantum_map[i]=YellowQuantum;
1972 if (image->colorspace == CMYKColorspace)
1974 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1975 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1976 "ColorSeparatedImageRequired","`%s'",map);
1977 return(MagickFalse);
1981 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1982 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1983 "UnrecognizedPixelMap","`%s'",map);
1984 return(MagickFalse);
1996 ExportCharPixel(image,&roi,map,quantum_map,pixels,exception);
2001 ExportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
2006 ExportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
2011 ExportLongPixel(image,&roi,map,quantum_map,pixels,exception);
2016 ExportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
2021 ExportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
2026 ExportShortPixel(image,&roi,map,quantum_map,pixels,exception);
2031 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2032 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2033 "UnrecognizedPixelMap","`%s'",map);
2037 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2046 % G e t P i x e l I n f o %
2050 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2052 % GetPixelInfo() initializes the PixelInfo structure.
2054 % The format of the GetPixelInfo method is:
2056 % GetPixelInfo(const Image *image,PixelInfo *pixel)
2058 % A description of each parameter follows:
2060 % o image: the image.
2062 % o pixel: Specifies a pointer to a PixelInfo structure.
2065 MagickExport void GetPixelInfo(const Image *image,PixelInfo *pixel)
2067 pixel->storage_class=DirectClass;
2068 pixel->colorspace=sRGBColorspace;
2069 pixel->alpha_trait=UndefinedPixelTrait;
2071 pixel->depth=MAGICKCORE_QUANTUM_DEPTH;
2076 pixel->alpha=(double) OpaqueAlpha;
2078 if (image == (const Image *) NULL)
2080 pixel->storage_class=image->storage_class;
2081 pixel->colorspace=image->colorspace;
2082 pixel->alpha_trait=image->alpha_trait;
2083 pixel->depth=image->depth;
2084 pixel->fuzz=image->fuzz;
2088 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2092 % I m p o r t I m a g e P i x e l s %
2096 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2098 % ImportImagePixels() accepts pixel data and stores in the image at the
2099 % location you specify. The method returns MagickTrue on success otherwise
2100 % MagickFalse if an error is encountered. The pixel data can be either char,
2101 % Quantum, short int, unsigned int, unsigned long long, float, or double in
2102 % the order specified by map.
2104 % Suppose your want to upload the first scanline of a 640x480 image from
2105 % character data in red-green-blue order:
2107 % ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels);
2109 % The format of the ImportImagePixels method is:
2111 % MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
2112 % const ssize_t y,const size_t width,const size_t height,
2113 % const char *map,const StorageType type,const void *pixels,
2114 % ExceptionInfo *exception)
2116 % A description of each parameter follows:
2118 % o image: the image.
2120 % o x,y,width,height: These values define the perimeter
2121 % of a region of pixels you want to define.
2123 % o map: This string reflects the expected ordering of the pixel array.
2124 % It can be any combination or order of R = red, G = green, B = blue,
2125 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
2126 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
2129 % o type: Define the data type of the pixels. Float and double types are
2130 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
2131 % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *),
2132 % LongPixel (unsigned int *), LongLongPixel (unsigned long long *),
2133 % QuantumPixel (Quantum *), or ShortPixel (unsigned short *).
2135 % o pixels: This array of values contain the pixel components as defined by
2136 % map and type. You must preallocate this array where the expected
2137 % length varies depending on the values of width, height, map, and type.
2139 % o exception: return any errors or warnings in this structure.
2143 static void ImportCharPixel(Image *image,const RectangleInfo *roi,
2144 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2145 ExceptionInfo *exception)
2147 register const unsigned char
2162 p=(const unsigned char *) pixels;
2163 if (LocaleCompare(map,"BGR") == 0)
2165 for (y=0; y < (ssize_t) roi->height; y++)
2167 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2168 if (q == (Quantum *) NULL)
2170 for (x=0; x < (ssize_t) roi->width; x++)
2172 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2173 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2174 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2175 q+=GetPixelChannels(image);
2177 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2182 if (LocaleCompare(map,"BGRA") == 0)
2184 for (y=0; y < (ssize_t) roi->height; y++)
2186 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2187 if (q == (Quantum *) NULL)
2189 for (x=0; x < (ssize_t) roi->width; x++)
2191 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2192 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2193 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2194 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2195 q+=GetPixelChannels(image);
2197 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2202 if (LocaleCompare(map,"BGRO") == 0)
2204 for (y=0; y < (ssize_t) roi->height; y++)
2206 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2207 if (q == (Quantum *) NULL)
2209 for (x=0; x < (ssize_t) roi->width; x++)
2211 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2212 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2213 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2214 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2215 q+=GetPixelChannels(image);
2217 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2222 if (LocaleCompare(map,"BGRP") == 0)
2224 for (y=0; y < (ssize_t) roi->height; y++)
2226 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2227 if (q == (Quantum *) NULL)
2229 for (x=0; x < (ssize_t) roi->width; x++)
2231 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2232 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2233 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2235 q+=GetPixelChannels(image);
2237 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2242 if (LocaleCompare(map,"I") == 0)
2244 for (y=0; y < (ssize_t) roi->height; y++)
2246 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2247 if (q == (Quantum *) NULL)
2249 for (x=0; x < (ssize_t) roi->width; x++)
2251 SetPixelGray(image,ScaleCharToQuantum(*p++),q);
2252 q+=GetPixelChannels(image);
2254 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2259 if (LocaleCompare(map,"RGB") == 0)
2261 for (y=0; y < (ssize_t) roi->height; y++)
2263 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2264 if (q == (Quantum *) NULL)
2266 for (x=0; x < (ssize_t) roi->width; x++)
2268 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2269 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2270 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2271 q+=GetPixelChannels(image);
2273 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2278 if (LocaleCompare(map,"RGBA") == 0)
2280 for (y=0; y < (ssize_t) roi->height; y++)
2282 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2283 if (q == (Quantum *) NULL)
2285 for (x=0; x < (ssize_t) roi->width; x++)
2287 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2288 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2289 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2290 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2291 q+=GetPixelChannels(image);
2293 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2298 if (LocaleCompare(map,"RGBO") == 0)
2300 for (y=0; y < (ssize_t) roi->height; y++)
2302 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2303 if (q == (Quantum *) NULL)
2305 for (x=0; x < (ssize_t) roi->width; x++)
2307 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2308 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2309 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2310 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2311 q+=GetPixelChannels(image);
2313 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2318 if (LocaleCompare(map,"RGBP") == 0)
2320 for (y=0; y < (ssize_t) roi->height; y++)
2322 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2323 if (q == (Quantum *) NULL)
2325 for (x=0; x < (ssize_t) roi->width; x++)
2327 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2328 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2329 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2331 q+=GetPixelChannels(image);
2333 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2339 for (y=0; y < (ssize_t) roi->height; y++)
2341 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2342 if (q == (Quantum *) NULL)
2344 for (x=0; x < (ssize_t) roi->width; x++)
2349 for (i=0; i < (ssize_t) length; i++)
2351 switch (quantum_map[i])
2356 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2360 case MagentaQuantum:
2362 SetPixelGreen(image,ScaleCharToQuantum(*p),q);
2368 SetPixelBlue(image,ScaleCharToQuantum(*p),q);
2373 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2376 case OpacityQuantum:
2378 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2383 SetPixelBlack(image,ScaleCharToQuantum(*p),q);
2388 SetPixelGray(image,ScaleCharToQuantum(*p),q);
2396 q+=GetPixelChannels(image);
2398 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2403 static void ImportDoublePixel(Image *image,const RectangleInfo *roi,
2404 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2405 ExceptionInfo *exception)
2407 register const double
2422 p=(const double *) pixels;
2423 if (LocaleCompare(map,"BGR") == 0)
2425 for (y=0; y < (ssize_t) roi->height; y++)
2427 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2428 if (q == (Quantum *) NULL)
2430 for (x=0; x < (ssize_t) roi->width; x++)
2432 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2434 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2436 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2438 q+=GetPixelChannels(image);
2440 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2445 if (LocaleCompare(map,"BGRA") == 0)
2447 for (y=0; y < (ssize_t) roi->height; y++)
2449 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2450 if (q == (Quantum *) NULL)
2452 for (x=0; x < (ssize_t) roi->width; x++)
2454 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2456 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2458 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2460 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2462 q+=GetPixelChannels(image);
2464 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2469 if (LocaleCompare(map,"BGRP") == 0)
2471 for (y=0; y < (ssize_t) roi->height; y++)
2473 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2474 if (q == (Quantum *) NULL)
2476 for (x=0; x < (ssize_t) roi->width; x++)
2478 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2480 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2482 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2485 q+=GetPixelChannels(image);
2487 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2492 if (LocaleCompare(map,"I") == 0)
2494 for (y=0; y < (ssize_t) roi->height; y++)
2496 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2497 if (q == (Quantum *) NULL)
2499 for (x=0; x < (ssize_t) roi->width; x++)
2501 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2503 q+=GetPixelChannels(image);
2505 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2510 if (LocaleCompare(map,"RGB") == 0)
2512 for (y=0; y < (ssize_t) roi->height; y++)
2514 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2515 if (q == (Quantum *) NULL)
2517 for (x=0; x < (ssize_t) roi->width; x++)
2519 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2521 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2523 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2525 q+=GetPixelChannels(image);
2527 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2532 if (LocaleCompare(map,"RGBA") == 0)
2534 for (y=0; y < (ssize_t) roi->height; y++)
2536 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2537 if (q == (Quantum *) NULL)
2539 for (x=0; x < (ssize_t) roi->width; x++)
2541 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2543 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2545 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2547 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2549 q+=GetPixelChannels(image);
2551 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2556 if (LocaleCompare(map,"RGBP") == 0)
2558 for (y=0; y < (ssize_t) roi->height; y++)
2560 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2561 if (q == (Quantum *) NULL)
2563 for (x=0; x < (ssize_t) roi->width; x++)
2565 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2567 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2569 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2571 q+=GetPixelChannels(image);
2573 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2579 for (y=0; y < (ssize_t) roi->height; y++)
2581 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2582 if (q == (Quantum *) NULL)
2584 for (x=0; x < (ssize_t) roi->width; x++)
2589 for (i=0; i < (ssize_t) length; i++)
2591 switch (quantum_map[i])
2596 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2600 case MagentaQuantum:
2602 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2608 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2613 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2616 case OpacityQuantum:
2618 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2623 SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q);
2628 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2636 q+=GetPixelChannels(image);
2638 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2643 static void ImportFloatPixel(Image *image,const RectangleInfo *roi,
2644 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2645 ExceptionInfo *exception)
2647 register const float
2662 p=(const float *) pixels;
2663 if (LocaleCompare(map,"BGR") == 0)
2665 for (y=0; y < (ssize_t) roi->height; y++)
2667 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2668 if (q == (Quantum *) NULL)
2670 for (x=0; x < (ssize_t) roi->width; x++)
2672 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2674 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2676 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2678 q+=GetPixelChannels(image);
2680 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2685 if (LocaleCompare(map,"BGRA") == 0)
2687 for (y=0; y < (ssize_t) roi->height; y++)
2689 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2690 if (q == (Quantum *) NULL)
2692 for (x=0; x < (ssize_t) roi->width; x++)
2694 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2696 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2698 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2700 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2702 q+=GetPixelChannels(image);
2704 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2709 if (LocaleCompare(map,"BGRP") == 0)
2711 for (y=0; y < (ssize_t) roi->height; y++)
2713 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2714 if (q == (Quantum *) NULL)
2716 for (x=0; x < (ssize_t) roi->width; x++)
2718 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2720 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2722 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2725 q+=GetPixelChannels(image);
2727 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2732 if (LocaleCompare(map,"I") == 0)
2734 for (y=0; y < (ssize_t) roi->height; y++)
2736 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2737 if (q == (Quantum *) NULL)
2739 for (x=0; x < (ssize_t) roi->width; x++)
2741 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2743 q+=GetPixelChannels(image);
2745 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2750 if (LocaleCompare(map,"RGB") == 0)
2752 for (y=0; y < (ssize_t) roi->height; y++)
2754 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2755 if (q == (Quantum *) NULL)
2757 for (x=0; x < (ssize_t) roi->width; x++)
2759 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2761 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2763 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2765 q+=GetPixelChannels(image);
2767 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2772 if (LocaleCompare(map,"RGBA") == 0)
2774 for (y=0; y < (ssize_t) roi->height; y++)
2776 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2777 if (q == (Quantum *) NULL)
2779 for (x=0; x < (ssize_t) roi->width; x++)
2781 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2783 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2785 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2787 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2789 q+=GetPixelChannels(image);
2791 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2796 if (LocaleCompare(map,"RGBP") == 0)
2798 for (y=0; y < (ssize_t) roi->height; y++)
2800 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2801 if (q == (Quantum *) NULL)
2803 for (x=0; x < (ssize_t) roi->width; x++)
2805 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2807 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2809 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2811 q+=GetPixelChannels(image);
2813 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2819 for (y=0; y < (ssize_t) roi->height; y++)
2821 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2822 if (q == (Quantum *) NULL)
2824 for (x=0; x < (ssize_t) roi->width; x++)
2829 for (i=0; i < (ssize_t) length; i++)
2831 switch (quantum_map[i])
2836 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2840 case MagentaQuantum:
2842 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2848 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2853 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2856 case OpacityQuantum:
2858 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2863 SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q);
2868 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2876 q+=GetPixelChannels(image);
2878 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2883 static void ImportLongPixel(Image *image,const RectangleInfo *roi,
2884 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2885 ExceptionInfo *exception)
2887 register const unsigned int
2902 p=(const unsigned int *) pixels;
2903 if (LocaleCompare(map,"BGR") == 0)
2905 for (y=0; y < (ssize_t) roi->height; y++)
2907 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2908 if (q == (Quantum *) NULL)
2910 for (x=0; x < (ssize_t) roi->width; x++)
2912 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2913 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2914 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2915 q+=GetPixelChannels(image);
2917 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2922 if (LocaleCompare(map,"BGRA") == 0)
2924 for (y=0; y < (ssize_t) roi->height; y++)
2926 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2927 if (q == (Quantum *) NULL)
2929 for (x=0; x < (ssize_t) roi->width; x++)
2931 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2932 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2933 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2934 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
2935 q+=GetPixelChannels(image);
2937 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2942 if (LocaleCompare(map,"BGRP") == 0)
2944 for (y=0; y < (ssize_t) roi->height; y++)
2946 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2947 if (q == (Quantum *) NULL)
2949 for (x=0; x < (ssize_t) roi->width; x++)
2951 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2952 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2953 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2955 q+=GetPixelChannels(image);
2957 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2962 if (LocaleCompare(map,"I") == 0)
2964 for (y=0; y < (ssize_t) roi->height; y++)
2966 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2967 if (q == (Quantum *) NULL)
2969 for (x=0; x < (ssize_t) roi->width; x++)
2971 SetPixelGray(image,ScaleLongToQuantum(*p++),q);
2972 q+=GetPixelChannels(image);
2974 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2979 if (LocaleCompare(map,"RGB") == 0)
2981 for (y=0; y < (ssize_t) roi->height; y++)
2983 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2984 if (q == (Quantum *) NULL)
2986 for (x=0; x < (ssize_t) roi->width; x++)
2988 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2989 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2990 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2991 q+=GetPixelChannels(image);
2993 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2998 if (LocaleCompare(map,"RGBA") == 0)
3000 for (y=0; y < (ssize_t) roi->height; y++)
3002 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3003 if (q == (Quantum *) NULL)
3005 for (x=0; x < (ssize_t) roi->width; x++)
3007 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3008 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3009 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3010 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3011 q+=GetPixelChannels(image);
3013 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3018 if (LocaleCompare(map,"RGBP") == 0)
3020 for (y=0; y < (ssize_t) roi->height; y++)
3022 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3023 if (q == (Quantum *) NULL)
3025 for (x=0; x < (ssize_t) roi->width; x++)
3027 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3028 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3029 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3031 q+=GetPixelChannels(image);
3033 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3039 for (y=0; y < (ssize_t) roi->height; y++)
3041 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3042 if (q == (Quantum *) NULL)
3044 for (x=0; x < (ssize_t) roi->width; x++)
3049 for (i=0; i < (ssize_t) length; i++)
3051 switch (quantum_map[i])
3056 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3060 case MagentaQuantum:
3062 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
3068 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
3073 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3076 case OpacityQuantum:
3078 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3083 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
3088 SetPixelGray(image,ScaleLongToQuantum(*p),q);
3096 q+=GetPixelChannels(image);
3098 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3103 static void ImportLongLongPixel(Image *image,const RectangleInfo *roi,
3104 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3105 ExceptionInfo *exception)
3107 register const MagickSizeType
3122 p=(const MagickSizeType *) pixels;
3123 if (LocaleCompare(map,"BGR") == 0)
3125 for (y=0; y < (ssize_t) roi->height; y++)
3127 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3128 if (q == (Quantum *) NULL)
3130 for (x=0; x < (ssize_t) roi->width; x++)
3132 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3133 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3134 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3135 q+=GetPixelChannels(image);
3137 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3142 if (LocaleCompare(map,"BGRA") == 0)
3144 for (y=0; y < (ssize_t) roi->height; y++)
3146 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3147 if (q == (Quantum *) NULL)
3149 for (x=0; x < (ssize_t) roi->width; x++)
3151 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3152 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3153 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3154 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3155 q+=GetPixelChannels(image);
3157 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3162 if (LocaleCompare(map,"BGRP") == 0)
3164 for (y=0; y < (ssize_t) roi->height; y++)
3166 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3167 if (q == (Quantum *) NULL)
3169 for (x=0; x < (ssize_t) roi->width; x++)
3171 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3172 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3173 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3175 q+=GetPixelChannels(image);
3177 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3182 if (LocaleCompare(map,"I") == 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 SetPixelGray(image,ScaleLongLongToQuantum(*p++),q);
3192 q+=GetPixelChannels(image);
3194 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3199 if (LocaleCompare(map,"RGB") == 0)
3201 for (y=0; y < (ssize_t) roi->height; y++)
3203 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3204 if (q == (Quantum *) NULL)
3206 for (x=0; x < (ssize_t) roi->width; x++)
3208 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3209 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3210 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3211 q+=GetPixelChannels(image);
3213 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3218 if (LocaleCompare(map,"RGBA") == 0)
3220 for (y=0; y < (ssize_t) roi->height; y++)
3222 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3223 if (q == (Quantum *) NULL)
3225 for (x=0; x < (ssize_t) roi->width; x++)
3227 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3228 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3229 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3230 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3231 q+=GetPixelChannels(image);
3233 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3238 if (LocaleCompare(map,"RGBP") == 0)
3240 for (y=0; y < (ssize_t) roi->height; y++)
3242 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3243 if (q == (Quantum *) NULL)
3245 for (x=0; x < (ssize_t) roi->width; x++)
3247 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3248 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3249 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3251 q+=GetPixelChannels(image);
3253 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3259 for (y=0; y < (ssize_t) roi->height; y++)
3261 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3262 if (q == (Quantum *) NULL)
3264 for (x=0; x < (ssize_t) roi->width; x++)
3269 for (i=0; i < (ssize_t) length; i++)
3271 switch (quantum_map[i])
3276 SetPixelRed(image,ScaleLongLongToQuantum(*p),q);
3280 case MagentaQuantum:
3282 SetPixelGreen(image,ScaleLongLongToQuantum(*p),q);
3288 SetPixelBlue(image,ScaleLongLongToQuantum(*p),q);
3293 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3296 case OpacityQuantum:
3298 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3303 SetPixelBlack(image,ScaleLongLongToQuantum(*p),q);
3308 SetPixelGray(image,ScaleLongLongToQuantum(*p),q);
3316 q+=GetPixelChannels(image);
3318 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3323 static void ImportQuantumPixel(Image *image,const RectangleInfo *roi,
3324 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3325 ExceptionInfo *exception)
3327 register const Quantum
3342 p=(const Quantum *) pixels;
3343 if (LocaleCompare(map,"BGR") == 0)
3345 for (y=0; y < (ssize_t) roi->height; y++)
3347 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3348 if (q == (Quantum *) NULL)
3350 for (x=0; x < (ssize_t) roi->width; x++)
3352 SetPixelBlue(image,*p++,q);
3353 SetPixelGreen(image,*p++,q);
3354 SetPixelRed(image,*p++,q);
3355 q+=GetPixelChannels(image);
3357 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3362 if (LocaleCompare(map,"BGRA") == 0)
3364 for (y=0; y < (ssize_t) roi->height; y++)
3366 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3367 if (q == (Quantum *) NULL)
3369 for (x=0; x < (ssize_t) roi->width; x++)
3371 SetPixelBlue(image,*p++,q);
3372 SetPixelGreen(image,*p++,q);
3373 SetPixelRed(image,*p++,q);
3374 SetPixelAlpha(image,*p++,q);
3375 q+=GetPixelChannels(image);
3377 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3382 if (LocaleCompare(map,"BGRP") == 0)
3384 for (y=0; y < (ssize_t) roi->height; y++)
3386 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3387 if (q == (Quantum *) NULL)
3389 for (x=0; x < (ssize_t) roi->width; x++)
3391 SetPixelBlue(image,*p++,q);
3392 SetPixelGreen(image,*p++,q);
3393 SetPixelRed(image,*p++,q);
3395 q+=GetPixelChannels(image);
3397 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3402 if (LocaleCompare(map,"I") == 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 SetPixelGray(image,*p++,q);
3412 q+=GetPixelChannels(image);
3414 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3419 if (LocaleCompare(map,"RGB") == 0)
3421 for (y=0; y < (ssize_t) roi->height; y++)
3423 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3424 if (q == (Quantum *) NULL)
3426 for (x=0; x < (ssize_t) roi->width; x++)
3428 SetPixelRed(image,*p++,q);
3429 SetPixelGreen(image,*p++,q);
3430 SetPixelBlue(image,*p++,q);
3431 q+=GetPixelChannels(image);
3433 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3438 if (LocaleCompare(map,"RGBA") == 0)
3440 for (y=0; y < (ssize_t) roi->height; y++)
3442 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3443 if (q == (Quantum *) NULL)
3445 for (x=0; x < (ssize_t) roi->width; x++)
3447 SetPixelRed(image,*p++,q);
3448 SetPixelGreen(image,*p++,q);
3449 SetPixelBlue(image,*p++,q);
3450 SetPixelAlpha(image,*p++,q);
3451 q+=GetPixelChannels(image);
3453 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3458 if (LocaleCompare(map,"RGBP") == 0)
3460 for (y=0; y < (ssize_t) roi->height; y++)
3462 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3463 if (q == (Quantum *) NULL)
3465 for (x=0; x < (ssize_t) roi->width; x++)
3467 SetPixelRed(image,*p++,q);
3468 SetPixelGreen(image,*p++,q);
3469 SetPixelBlue(image,*p++,q);
3471 q+=GetPixelChannels(image);
3473 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3479 for (y=0; y < (ssize_t) roi->height; y++)
3481 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3482 if (q == (Quantum *) NULL)
3484 for (x=0; x < (ssize_t) roi->width; x++)
3489 for (i=0; i < (ssize_t) length; i++)
3491 switch (quantum_map[i])
3496 SetPixelRed(image,*p,q);
3500 case MagentaQuantum:
3502 SetPixelGreen(image,*p,q);
3508 SetPixelBlue(image,*p,q);
3513 SetPixelAlpha(image,*p,q);
3516 case OpacityQuantum:
3518 SetPixelAlpha(image,*p,q);
3523 SetPixelBlack(image,*p,q);
3528 SetPixelGray(image,*p,q);
3536 q+=GetPixelChannels(image);
3538 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3543 static void ImportShortPixel(Image *image,const RectangleInfo *roi,
3544 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3545 ExceptionInfo *exception)
3547 register const unsigned short
3562 p=(const unsigned short *) pixels;
3563 if (LocaleCompare(map,"BGR") == 0)
3565 for (y=0; y < (ssize_t) roi->height; y++)
3567 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3568 if (q == (Quantum *) NULL)
3570 for (x=0; x < (ssize_t) roi->width; x++)
3572 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3573 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3574 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3575 q+=GetPixelChannels(image);
3577 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3582 if (LocaleCompare(map,"BGRA") == 0)
3584 for (y=0; y < (ssize_t) roi->height; y++)
3586 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3587 if (q == (Quantum *) NULL)
3589 for (x=0; x < (ssize_t) roi->width; x++)
3591 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3592 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3593 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3594 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3595 q+=GetPixelChannels(image);
3597 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3602 if (LocaleCompare(map,"BGRP") == 0)
3604 for (y=0; y < (ssize_t) roi->height; y++)
3606 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3607 if (q == (Quantum *) NULL)
3609 for (x=0; x < (ssize_t) roi->width; x++)
3611 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3612 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3613 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3615 q+=GetPixelChannels(image);
3617 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3622 if (LocaleCompare(map,"I") == 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 SetPixelGray(image,ScaleShortToQuantum(*p++),q);
3632 q+=GetPixelChannels(image);
3634 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3639 if (LocaleCompare(map,"RGB") == 0)
3641 for (y=0; y < (ssize_t) roi->height; y++)
3643 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3644 if (q == (Quantum *) NULL)
3646 for (x=0; x < (ssize_t) roi->width; x++)
3648 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3649 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3650 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3651 q+=GetPixelChannels(image);
3653 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3658 if (LocaleCompare(map,"RGBA") == 0)
3660 for (y=0; y < (ssize_t) roi->height; y++)
3662 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3663 if (q == (Quantum *) NULL)
3665 for (x=0; x < (ssize_t) roi->width; x++)
3667 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3668 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3669 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3670 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3671 q+=GetPixelChannels(image);
3673 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3678 if (LocaleCompare(map,"RGBP") == 0)
3680 for (y=0; y < (ssize_t) roi->height; y++)
3682 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3683 if (q == (Quantum *) NULL)
3685 for (x=0; x < (ssize_t) roi->width; x++)
3687 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3688 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3689 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3691 q+=GetPixelChannels(image);
3693 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3699 for (y=0; y < (ssize_t) roi->height; y++)
3701 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3702 if (q == (Quantum *) NULL)
3704 for (x=0; x < (ssize_t) roi->width; x++)
3709 for (i=0; i < (ssize_t) length; i++)
3711 switch (quantum_map[i])
3716 SetPixelRed(image,ScaleShortToQuantum(*p),q);
3720 case MagentaQuantum:
3722 SetPixelGreen(image,ScaleShortToQuantum(*p),q);
3728 SetPixelBlue(image,ScaleShortToQuantum(*p),q);
3733 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3736 case OpacityQuantum:
3738 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3743 SetPixelBlack(image,ScaleShortToQuantum(*p),q);
3748 SetPixelGray(image,ScaleShortToQuantum(*p),q);
3756 q+=GetPixelChannels(image);
3758 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3763 MagickExport MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
3764 const ssize_t y,const size_t width,const size_t height,const char *map,
3765 const StorageType type,const void *pixels,ExceptionInfo *exception)
3780 Allocate image structure.
3782 assert(image != (Image *) NULL);
3783 assert(image->signature == MagickSignature);
3784 if (image->debug != MagickFalse)
3785 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3787 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
3788 if (quantum_map == (QuantumType *) NULL)
3789 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
3791 for (i=0; i < (ssize_t) length; i++)
3798 quantum_map[i]=AlphaQuantum;
3799 image->alpha_trait=BlendPixelTrait;
3805 quantum_map[i]=BlueQuantum;
3811 quantum_map[i]=CyanQuantum;
3812 (void) SetImageColorspace(image,CMYKColorspace,exception);
3818 quantum_map[i]=GreenQuantum;
3824 quantum_map[i]=BlackQuantum;
3825 (void) SetImageColorspace(image,CMYKColorspace,exception);
3831 quantum_map[i]=IndexQuantum;
3832 (void) SetImageColorspace(image,GRAYColorspace,exception);
3838 quantum_map[i]=MagentaQuantum;
3839 (void) SetImageColorspace(image,CMYKColorspace,exception);
3845 quantum_map[i]=OpacityQuantum;
3846 image->alpha_trait=BlendPixelTrait;
3852 quantum_map[i]=UndefinedQuantum;
3858 quantum_map[i]=RedQuantum;
3864 quantum_map[i]=YellowQuantum;
3865 (void) SetImageColorspace(image,CMYKColorspace,exception);
3870 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3871 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3872 "UnrecognizedPixelMap","`%s'",map);
3873 return(MagickFalse);
3877 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
3878 return(MagickFalse);
3880 Transfer the pixels from the pixel data to the image.
3890 ImportCharPixel(image,&roi,map,quantum_map,pixels,exception);
3895 ImportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
3900 ImportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
3905 ImportLongPixel(image,&roi,map,quantum_map,pixels,exception);
3910 ImportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
3915 ImportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
3920 ImportShortPixel(image,&roi,map,quantum_map,pixels,exception);
3925 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3926 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3927 "UnrecognizedPixelMap","`%s'",map);
3931 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3936 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3940 + 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 %
3944 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3946 % InitializePixelChannelMap() defines the standard pixel component map.
3948 % The format of the InitializePixelChannelMap() method is:
3950 % void InitializePixelChannelMap(Image *image)
3952 % A description of each parameter follows:
3954 % o image: the image.
3957 MagickExport void InitializePixelChannelMap(Image *image)
3968 assert(image != (Image *) NULL);
3969 assert(image->signature == MagickSignature);
3970 (void) ResetMagickMemory(image->channel_map,0,MaxPixelChannels*
3971 sizeof(*image->channel_map));
3972 trait=UpdatePixelTrait;
3973 if (image->alpha_trait == BlendPixelTrait)
3974 trait=(PixelTrait) (trait | BlendPixelTrait);
3976 if (image->colorspace == GRAYColorspace)
3978 SetPixelChannelAttributes(image,BluePixelChannel,trait,n);
3979 SetPixelChannelAttributes(image,GreenPixelChannel,trait,n);
3980 SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
3984 SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
3985 SetPixelChannelAttributes(image,GreenPixelChannel,trait,n++);
3986 SetPixelChannelAttributes(image,BluePixelChannel,trait,n++);
3988 if (image->colorspace == CMYKColorspace)
3989 SetPixelChannelAttributes(image,BlackPixelChannel,trait,n++);
3990 if (image->alpha_trait != UndefinedPixelTrait)
3991 SetPixelChannelAttributes(image,AlphaPixelChannel,CopyPixelTrait,n++);
3992 if (image->storage_class == PseudoClass)
3993 SetPixelChannelAttributes(image,IndexPixelChannel,CopyPixelTrait,n++);
3994 if (image->mask != MagickFalse)
3995 SetPixelChannelAttributes(image,MaskPixelChannel,CopyPixelTrait,n++);
3996 assert((n+image->number_meta_channels) < MaxPixelChannels);
3997 for (i=0; i < (ssize_t) image->number_meta_channels; i++)
3998 SetPixelChannelAttributes(image,(PixelChannel) (MetaPixelChannel+i),
3999 CopyPixelTrait,n++);
4000 image->number_channels=(size_t) n;
4001 if (image->debug != MagickFalse)
4002 LogPixelChannels(image);
4003 (void) SetImageChannelMask(image,image->channel_mask);
4007 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4011 % I n t e r p o l a t e P i x e l C h a n n e l %
4015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4017 % InterpolatePixelChannel() applies a pixel interpolation method between a
4018 % floating point coordinate and the pixels surrounding that coordinate. No
4019 % pixel area resampling, or scaling of the result is performed.
4021 % Interpolation is restricted to just the specified channel.
4023 % The format of the InterpolatePixelChannel method is:
4025 % MagickBooleanType InterpolatePixelChannel(const Image *image,
4026 % const CacheView *image_view,const PixelChannel channel,
4027 % const PixelInterpolateMethod method,const double x,const double y,
4028 % double *pixel,ExceptionInfo *exception)
4030 % A description of each parameter follows:
4032 % o image: the image.
4034 % o image_view: the image view.
4036 % o channel: the pixel channel to interpolate.
4038 % o method: the pixel color interpolation method.
4040 % o x,y: A double representing the current (x,y) position of the pixel.
4042 % o pixel: return the interpolated pixel here.
4044 % o exception: return any errors or warnings in this structure.
4048 static inline double MagickMax(const double x,const double y)
4055 static inline void CatromWeights(const double x,double (*weights)[4])
4063 Nicolas Robidoux' 10 flops (4* + 5- + 1+) refactoring of the computation
4064 of the standard four 1D Catmull-Rom weights. The sampling location is
4065 assumed between the second and third input pixel locations, and x is the
4066 position relative to the second input pixel location. Formulas originally
4067 derived for the VIPS (Virtual Image Processing System) library.
4069 alpha=(double) 1.0-x;
4070 beta=(double) (-0.5)*x*alpha;
4071 (*weights)[0]=alpha*beta;
4072 (*weights)[3]=x*beta;
4074 The following computation of the inner weights from the outer ones work
4075 for all Keys cubics.
4077 gamma=(*weights)[3]-(*weights)[0];
4078 (*weights)[1]=alpha-(*weights)[0]+gamma;
4079 (*weights)[2]=x-(*weights)[3]-gamma;
4082 static inline void SplineWeights(const double x,double (*weights)[4])
4089 Nicolas Robidoux' 12 flops (6* + 5- + 1+) refactoring of the
4090 computation of the standard four 1D cubic B-spline smoothing
4091 weights. The sampling location is assumed between the second and
4092 third input pixel locations, and x is the position relative to the
4093 second input pixel location.
4095 alpha=(double) 1.0-x;
4096 (*weights)[3]=(double) (1.0/6.0)*x*x*x;
4097 (*weights)[0]=(double) (1.0/6.0)*alpha*alpha*alpha;
4098 beta=(*weights)[3]-(*weights)[0];
4099 (*weights)[1]=alpha-(*weights)[0]+beta;
4100 (*weights)[2]=x-(*weights)[3]-beta;
4103 static inline double MeshInterpolate(const PointInfo *delta,const double p,
4104 const double x,const double y)
4106 return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
4110 static inline ssize_t NearestNeighbor(const double x)
4113 return((ssize_t) (x+0.5));
4114 return((ssize_t) (x-0.5));
4118 MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
4119 const CacheView *image_view,const PixelChannel channel,
4120 const PixelInterpolateMethod method,const double x,const double y,
4121 double *pixel,ExceptionInfo *exception)
4134 register const Quantum
4144 PixelInterpolateMethod
4147 assert(image != (Image *) NULL);
4148 assert(image != (Image *) NULL);
4149 assert(image->signature == MagickSignature);
4150 assert(image_view != (CacheView *) NULL);
4153 traits=GetPixelChannelTraits(image,channel);
4154 x_offset=(ssize_t) floor(x);
4155 y_offset=(ssize_t) floor(y);
4156 interpolate = method;
4157 if ( interpolate == UndefinedInterpolatePixel )
4158 interpolate = image->interpolate;
4159 switch (interpolate)
4161 case AverageInterpolatePixel: /* nearest 4 neighbours */
4162 case Average9InterpolatePixel: /* nearest 9 neighbours */
4163 case Average16InterpolatePixel: /* nearest 16 neighbours */
4168 count=2; /* size of the area to average - default nearest 4 */
4169 if (interpolate == Average9InterpolatePixel)
4172 x_offset=(ssize_t) (floor(x+0.5)-1);
4173 y_offset=(ssize_t) (floor(y+0.5)-1);
4176 if (interpolate == Average16InterpolatePixel)
4182 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,count,count,
4184 if (p == (const Quantum *) NULL)
4189 count*=count; /* Number of pixels to Average */
4190 if ((traits & BlendPixelTrait) == 0)
4191 for (i=0; i < (ssize_t) count; i++)
4194 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4197 for (i=0; i < (ssize_t) count; i++)
4199 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4200 GetPixelChannels(image));
4201 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4203 for (i=0; i < (ssize_t) count; i++)
4205 gamma=PerceptibleReciprocal(alpha[i])/count;
4206 *pixel+=gamma*pixels[i];
4210 case BilinearInterpolatePixel:
4217 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4218 if (p == (const Quantum *) NULL)
4223 if ((traits & BlendPixelTrait) == 0)
4224 for (i=0; i < 4; i++)
4227 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4230 for (i=0; i < 4; i++)
4232 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4233 GetPixelChannels(image));
4234 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4238 epsilon.x=1.0-delta.x;
4239 epsilon.y=1.0-delta.y;
4240 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4241 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4242 gamma=PerceptibleReciprocal(gamma);
4243 *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
4244 (epsilon.x*pixels[2]+delta.x*pixels[3]));
4247 case BlendInterpolatePixel:
4249 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4250 if (p == (const Quantum *) NULL)
4255 if ((traits & BlendPixelTrait) == 0)
4256 for (i=0; i < 4; i++)
4259 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4262 for (i=0; i < 4; i++)
4264 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4265 GetPixelChannels(image));
4266 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4268 gamma=1.0; /* number of pixels blended together (its variable) */
4269 for (i=0; i <= 1L; i++) {
4270 if ((y-y_offset) >= 0.75)
4272 alpha[i]=alpha[i+2]; /* take right pixels */
4273 pixels[i]=pixels[i+2];
4276 if ((y-y_offset) > 0.25)
4278 gamma=2.0; /* blend both pixels in row */
4279 alpha[i]+=alpha[i+2]; /* add up alpha weights */
4280 pixels[i]+=pixels[i+2];
4283 if ((x-x_offset) >= 0.75)
4285 alpha[0]=alpha[1]; /* take bottom row blend */
4286 pixels[0]=pixels[1];
4289 if ((x-x_offset) > 0.25)
4291 gamma*=2.0; /* blend both rows */
4292 alpha[0]+=alpha[1]; /* add up alpha weights */
4293 pixels[0]+=pixels[1];
4295 if (channel != AlphaPixelChannel)
4296 gamma=PerceptibleReciprocal(alpha[0]); /* (color) 1/alpha_weights */
4298 gamma=PerceptibleReciprocal(gamma); /* (alpha) 1/number_of_pixels */
4299 *pixel=gamma*pixels[0];
4302 case CatromInterpolatePixel:
4308 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4310 if (p == (const Quantum *) NULL)
4315 if ((traits & BlendPixelTrait) == 0)
4316 for (i=0; i < 16; i++)
4319 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4322 for (i=0; i < 16; i++)
4324 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4325 GetPixelChannels(image));
4326 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4328 CatromWeights((double) (x-x_offset),&cx);
4329 CatromWeights((double) (y-y_offset),&cy);
4330 gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4331 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4332 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4333 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4334 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4335 cx[2]*alpha[14]+cx[3]*alpha[15])));
4336 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4337 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4338 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4339 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4340 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4344 /* deprecated useless and very slow interpolator */
4345 case FilterInterpolatePixel:
4359 geometry.x=x_offset-1;
4360 geometry.y=y_offset-1;
4361 excerpt_image=ExcerptImage(image,&geometry,exception);
4362 if (excerpt_image == (Image *) NULL)
4367 filter_image=ResizeImage(excerpt_image,1,1,image->filter,exception);
4368 excerpt_image=DestroyImage(excerpt_image);
4369 if (filter_image == (Image *) NULL)
4371 filter_view=AcquireVirtualCacheView(filter_image,exception);
4372 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4373 if (p == (const Quantum *) NULL)
4376 *pixel=(double) GetPixelChannel(image,channel,p);
4377 filter_view=DestroyCacheView(filter_view);
4378 filter_image=DestroyImage(filter_image);
4382 case IntegerInterpolatePixel:
4384 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4385 if (p == (const Quantum *) NULL)
4390 *pixel=(double) GetPixelChannel(image,channel,p);
4393 case NearestInterpolatePixel:
4395 x_offset=(ssize_t) floor(x+0.5);
4396 y_offset=(ssize_t) floor(y+0.5);
4397 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4398 if (p == (const Quantum *) NULL)
4403 *pixel=(double) GetPixelChannel(image,channel,p);
4406 case MeshInterpolatePixel:
4412 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4413 if (p == (const Quantum *) NULL)
4418 if ((traits & BlendPixelTrait) == 0)
4419 for (i=0; i < 4; i++)
4422 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4425 for (i=0; i < 4; i++)
4427 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4428 GetPixelChannels(image));
4429 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4433 luminance.x=GetPixelLuminance(image,p)-(double)
4434 GetPixelLuminance(image,p+3*GetPixelChannels(image));
4435 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
4436 GetPixelLuminance(image,p+2*GetPixelChannels(image));
4437 if (fabs(luminance.x) < fabs(luminance.y))
4442 if (delta.x <= delta.y)
4445 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4447 delta.y=1.0-delta.y;
4448 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4449 gamma=PerceptibleReciprocal(gamma);
4450 *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
4456 Top-right triangle (pixel: 1, diagonal: 0-3).
4458 delta.x=1.0-delta.x;
4459 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4460 gamma=PerceptibleReciprocal(gamma);
4461 *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
4470 if (delta.x <= (1.0-delta.y))
4473 Top-left triangle (pixel: 0, diagonal: 1-2).
4475 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4476 gamma=PerceptibleReciprocal(gamma);
4477 *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
4483 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4485 delta.x=1.0-delta.x;
4486 delta.y=1.0-delta.y;
4487 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4488 gamma=PerceptibleReciprocal(gamma);
4489 *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
4495 case SplineInterpolatePixel:
4501 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4503 if (p == (const Quantum *) NULL)
4508 if ((traits & BlendPixelTrait) == 0)
4509 for (i=0; i < 16; i++)
4512 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4515 for (i=0; i < 16; i++)
4517 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4518 GetPixelChannels(image));
4519 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4521 SplineWeights((double) (x-x_offset),&cx);
4522 SplineWeights((double) (y-y_offset),&cy);
4523 gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4524 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4525 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4526 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4527 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4528 cx[2]*alpha[14]+cx[3]*alpha[15])));
4529 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4530 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4531 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4532 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4533 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4541 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4545 % I n t e r p o l a t e P i x e l C h a n n e l s %
4549 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4551 % InterpolatePixelChannels() applies a pixel interpolation method between a
4552 % floating point coordinate and the pixels surrounding that coordinate. No
4553 % pixel area resampling, or scaling of the result is performed.
4555 % Interpolation is restricted to just the current channel setting of the
4556 % destination image into which the color is to be stored
4558 % The format of the InterpolatePixelChannels method is:
4560 % MagickBooleanType InterpolatePixelChannels(const Image *source,
4561 % const CacheView *source_view,const Image *destination,
4562 % const PixelInterpolateMethod method,const double x,const double y,
4563 % Quantum *pixel,ExceptionInfo *exception)
4565 % A description of each parameter follows:
4567 % o source: the source.
4569 % o source_view: the source view.
4571 % o destination: the destination image, for the interpolated color
4573 % o method: the pixel color interpolation method.
4575 % o x,y: A double representing the current (x,y) position of the pixel.
4577 % o pixel: return the interpolated pixel here.
4579 % o exception: return any errors or warnings in this structure.
4582 MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
4583 const CacheView *source_view,const Image *destination,
4584 const PixelInterpolateMethod method,const double x,const double y,
4585 Quantum *pixel,ExceptionInfo *exception)
4595 register const Quantum
4605 PixelInterpolateMethod
4608 assert(source != (Image *) NULL);
4609 assert(source != (Image *) NULL);
4610 assert(source->signature == MagickSignature);
4611 assert(source_view != (CacheView *) NULL);
4613 x_offset=(ssize_t) floor(x);
4614 y_offset=(ssize_t) floor(y);
4615 interpolate = method;
4616 if ( interpolate == UndefinedInterpolatePixel )
4617 interpolate = source->interpolate;
4618 switch (interpolate)
4620 case AverageInterpolatePixel: /* nearest 4 neighbours */
4621 case Average9InterpolatePixel: /* nearest 9 neighbours */
4622 case Average16InterpolatePixel: /* nearest 16 neighbours */
4627 count=2; /* size of the area to average - default nearest 4 */
4628 if (interpolate == Average9InterpolatePixel)
4631 x_offset=(ssize_t) (floor(x+0.5)-1);
4632 y_offset=(ssize_t) (floor(y+0.5)-1);
4635 if (interpolate == Average16InterpolatePixel)
4641 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,count,count,
4643 if (p == (const Quantum *) NULL)
4648 count*=count; /* Number of pixels to Average */
4649 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4657 PixelChannel channel=GetPixelChannelChannel(source,i);
4658 PixelTrait traits=GetPixelChannelTraits(source,channel);
4659 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4661 if ((traits == UndefinedPixelTrait) ||
4662 (destination_traits == UndefinedPixelTrait))
4664 for (j=0; j < (ssize_t) count; j++)
4665 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
4667 if ((traits & BlendPixelTrait) == 0)
4669 for (j=0; j < (ssize_t) count; j++)
4672 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4675 for (j=0; j < (ssize_t) count; j++)
4677 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4678 GetPixelChannels(source));
4679 pixels[j]*=alpha[j];
4680 gamma=PerceptibleReciprocal(alpha[j]);
4681 sum+=gamma*pixels[j];
4684 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4688 case BilinearInterpolatePixel:
4691 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4692 if (p == (const Quantum *) NULL)
4697 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4703 PixelChannel channel=GetPixelChannelChannel(source,i);
4704 PixelTrait traits=GetPixelChannelTraits(source,channel);
4705 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4707 if ((traits == UndefinedPixelTrait) ||
4708 (destination_traits == UndefinedPixelTrait))
4712 epsilon.x=1.0-delta.x;
4713 epsilon.y=1.0-delta.y;
4714 pixels[0]=(double) p[i];
4715 pixels[1]=(double) p[GetPixelChannels(source)+i];
4716 pixels[2]=(double) p[2*GetPixelChannels(source)+i];
4717 pixels[3]=(double) p[3*GetPixelChannels(source)+i];
4718 if ((traits & BlendPixelTrait) == 0)
4720 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
4721 gamma=PerceptibleReciprocal(gamma);
4722 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4723 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*
4724 pixels[2]+delta.x*pixels[3]))),pixel);
4727 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4728 alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source));
4729 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4730 GetPixelChannels(source));
4731 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4732 GetPixelChannels(source));
4733 pixels[0]*=alpha[0];
4734 pixels[1]*=alpha[1];
4735 pixels[2]*=alpha[2];
4736 pixels[3]*=alpha[3];
4737 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4738 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4739 gamma=PerceptibleReciprocal(gamma);
4740 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4741 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+
4742 delta.x*pixels[3]))),pixel);
4746 case BlendInterpolatePixel:
4748 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4749 if (p == (const Quantum *) NULL)
4754 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4759 PixelChannel channel=GetPixelChannelChannel(source,i);
4760 PixelTrait traits=GetPixelChannelTraits(source,channel);
4761 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4763 if ((traits == UndefinedPixelTrait) ||
4764 (destination_traits == UndefinedPixelTrait))
4766 if ((traits & BlendPixelTrait) == 0)
4767 for (j=0; j < 4; j++)
4770 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+channel];
4773 for (j=0; j < 4; j++)
4775 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4776 GetPixelChannels(source));
4777 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+channel];
4779 gamma=1.0; /* number of pixels blended together (its variable) */
4780 for (j=0; j <= 1L; j++)
4782 if ((y-y_offset) >= 0.75)
4784 alpha[j]=alpha[j+2]; /* take right pixels */
4785 pixels[j]=pixels[j+2];
4788 if ((y-y_offset) > 0.25)
4790 gamma=2.0; /* blend both pixels in row */
4791 alpha[j]+=alpha[j+2]; /* add up alpha weights */
4792 pixels[j]+=pixels[j+2];
4795 if ((x-x_offset) >= 0.75)
4797 alpha[0]=alpha[1]; /* take bottom row blend */
4798 pixels[0]=pixels[1];
4801 if ((x-x_offset) > 0.25)
4803 gamma*=2.0; /* blend both rows */
4804 alpha[0]+=alpha[1]; /* add up alpha weights */
4805 pixels[0]+=pixels[1];
4807 if ((traits & BlendPixelTrait) == 0)
4808 gamma=PerceptibleReciprocal(alpha[0]); /* (color) 1/alpha_weights */
4810 gamma=PerceptibleReciprocal(gamma); /* (alpha) 1/number_of_pixels */
4811 SetPixelChannel(destination,channel,ClampToQuantum(gamma*pixels[0]),
4816 case CatromInterpolatePixel:
4822 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4824 if (p == (const Quantum *) NULL)
4829 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4834 PixelChannel channel=GetPixelChannelChannel(source,i);
4835 PixelTrait traits=GetPixelChannelTraits(source,channel);
4836 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4838 if ((traits == UndefinedPixelTrait) ||
4839 (destination_traits == UndefinedPixelTrait))
4841 if ((traits & BlendPixelTrait) == 0)
4842 for (j=0; j < 16; j++)
4845 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
4848 for (j=0; j < 16; j++)
4850 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4851 GetPixelChannels(source));
4852 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4854 CatromWeights((double) (x-x_offset),&cx);
4855 CatromWeights((double) (y-y_offset),&cy);
4856 gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
4857 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4858 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4859 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4860 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4861 cx[2]*alpha[14]+cx[3]*alpha[15])));
4862 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
4863 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
4864 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
4865 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
4866 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
4867 pixels[14]+cx[3]*pixels[15]))),pixel);
4872 /* deprecated useless and very slow interpolator */
4873 case FilterInterpolatePixel:
4875 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4887 PixelChannel channel=GetPixelChannelChannel(source,i);
4888 PixelTrait traits=GetPixelChannelTraits(source,channel);
4889 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4891 if ((traits == UndefinedPixelTrait) ||
4892 (destination_traits == UndefinedPixelTrait))
4896 geometry.x=x_offset-1;
4897 geometry.y=y_offset-1;
4898 excerpt_source=ExcerptImage(source,&geometry,exception);
4899 if (excerpt_source == (Image *) NULL)
4904 filter_source=ResizeImage(excerpt_source,1,1,source->filter,exception);
4905 excerpt_source=DestroyImage(excerpt_source);
4906 if (filter_source == (Image *) NULL)
4908 filter_view=AcquireVirtualCacheView(filter_source,exception);
4909 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4910 if (p == (const Quantum *) NULL)
4914 SetPixelChannel(destination,channel,p[i],pixel);
4916 filter_view=DestroyCacheView(filter_view);
4917 filter_source=DestroyImage(filter_source);
4922 case IntegerInterpolatePixel:
4924 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
4925 if (p == (const Quantum *) NULL)
4930 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4932 PixelChannel channel=GetPixelChannelChannel(source,i);
4933 PixelTrait traits=GetPixelChannelTraits(source,channel);
4934 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4936 if ((traits == UndefinedPixelTrait) ||
4937 (destination_traits == UndefinedPixelTrait))
4939 SetPixelChannel(destination,channel,p[i],pixel);
4943 case NearestInterpolatePixel:
4945 x_offset=(ssize_t) floor(x+0.5);
4946 y_offset=(ssize_t) floor(y+0.5);
4947 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
4948 if (p == (const Quantum *) NULL)
4953 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4955 PixelChannel channel=GetPixelChannelChannel(source,i);
4956 PixelTrait traits=GetPixelChannelTraits(source,channel);
4957 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4959 if ((traits == UndefinedPixelTrait) ||
4960 (destination_traits == UndefinedPixelTrait))
4962 SetPixelChannel(destination,channel,p[i],pixel);
4966 case MeshInterpolatePixel:
4968 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4969 if (p == (const Quantum *) NULL)
4974 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4980 PixelChannel channel=GetPixelChannelChannel(source,i);
4981 PixelTrait traits=GetPixelChannelTraits(source,channel);
4982 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4984 if ((traits == UndefinedPixelTrait) ||
4985 (destination_traits == UndefinedPixelTrait))
4987 pixels[0]=(double) p[i];
4988 pixels[1]=(double) p[GetPixelChannels(source)+i];
4989 pixels[2]=(double) p[2*GetPixelChannels(source)+i];
4990 pixels[3]=(double) p[3*GetPixelChannels(source)+i];
4991 if ((traits & BlendPixelTrait) == 0)
5000 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
5001 alpha[1]=QuantumScale*GetPixelAlpha(source,p+
5002 GetPixelChannels(source));
5003 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
5004 GetPixelChannels(source));
5005 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
5006 GetPixelChannels(source));
5010 luminance.x=fabs((double) (GetPixelLuminance(source,p)-
5011 GetPixelLuminance(source,p+3*GetPixelChannels(source))));
5012 luminance.y=fabs((double) (GetPixelLuminance(source,p+
5013 GetPixelChannels(source))-GetPixelLuminance(source,p+2*
5014 GetPixelChannels(source))));
5015 if (luminance.x < luminance.y)
5020 if (delta.x <= delta.y)
5023 Bottom-left triangle (pixel: 2, diagonal: 0-3).
5025 delta.y=1.0-delta.y;
5026 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5027 gamma=PerceptibleReciprocal(gamma);
5028 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5029 MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel);
5034 Top-right triangle (pixel: 1, diagonal: 0-3).
5036 delta.x=1.0-delta.x;
5037 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5038 gamma=PerceptibleReciprocal(gamma);
5039 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5040 MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel);
5048 if (delta.x <= (1.0-delta.y))
5051 Top-left triangle (pixel: 0, diagonal: 1-2).
5053 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5054 gamma=PerceptibleReciprocal(gamma);
5055 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5056 MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel);
5061 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5063 delta.x=1.0-delta.x;
5064 delta.y=1.0-delta.y;
5065 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5066 gamma=PerceptibleReciprocal(gamma);
5067 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5068 MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel);
5074 case SplineInterpolatePixel:
5080 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
5082 if (p == (const Quantum *) NULL)
5087 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5092 PixelChannel channel=GetPixelChannelChannel(source,i);
5093 PixelTrait traits=GetPixelChannelTraits(source,channel);
5094 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5096 if ((traits == UndefinedPixelTrait) ||
5097 (destination_traits == UndefinedPixelTrait))
5099 if ((traits & BlendPixelTrait) == 0)
5100 for (j=0; j < 16; j++)
5103 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
5106 for (j=0; j < 16; j++)
5108 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
5109 GetPixelChannels(source));
5110 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
5112 SplineWeights((double) (x-x_offset),&cx);
5113 SplineWeights((double) (y-y_offset),&cy);
5114 gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
5115 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
5116 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
5117 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
5118 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
5119 cx[2]*alpha[14]+cx[3]*alpha[15])));
5120 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
5121 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
5122 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
5123 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
5124 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
5125 pixels[14]+cx[3]*pixels[15]))),pixel);
5134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5138 % I n t e r p o l a t e P i x e l I n f o %
5142 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5144 % InterpolatePixelInfo() applies a pixel interpolation method between a
5145 % floating point coordinate and the pixels surrounding that coordinate. No
5146 % pixel area resampling, or scaling of the result is performed.
5148 % Interpolation is restricted to just RGBKA channels.
5150 % The format of the InterpolatePixelInfo method is:
5152 % MagickBooleanType InterpolatePixelInfo(const Image *image,
5153 % const CacheView *image_view,const PixelInterpolateMethod method,
5154 % const double x,const double y,PixelInfo *pixel,
5155 % ExceptionInfo *exception)
5157 % A description of each parameter follows:
5159 % o image: the image.
5161 % o image_view: the image view.
5163 % o method: the pixel color interpolation method.
5165 % o x,y: A double representing the current (x,y) position of the pixel.
5167 % o pixel: return the interpolated pixel here.
5169 % o exception: return any errors or warnings in this structure.
5173 static inline void AlphaBlendPixelInfo(const Image *image,
5174 const Quantum *pixel,PixelInfo *pixel_info,double *alpha)
5176 if (image->alpha_trait != BlendPixelTrait)
5179 pixel_info->red=(double) GetPixelRed(image,pixel);
5180 pixel_info->green=(double) GetPixelGreen(image,pixel);
5181 pixel_info->blue=(double) GetPixelBlue(image,pixel);
5182 pixel_info->black=0.0;
5183 if (image->colorspace == CMYKColorspace)
5184 pixel_info->black=(double) GetPixelBlack(image,pixel);
5185 pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5188 *alpha=QuantumScale*GetPixelAlpha(image,pixel);
5189 pixel_info->red=(*alpha*GetPixelRed(image,pixel));
5190 pixel_info->green=(*alpha*GetPixelGreen(image,pixel));
5191 pixel_info->blue=(*alpha*GetPixelBlue(image,pixel));
5192 pixel_info->black=0.0;
5193 if (image->colorspace == CMYKColorspace)
5194 pixel_info->black=(*alpha*GetPixelBlack(image,pixel));
5195 pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5198 MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
5199 const CacheView *image_view,const PixelInterpolateMethod method,
5200 const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception)
5212 register const Quantum
5222 PixelInterpolateMethod
5225 assert(image != (Image *) NULL);
5226 assert(image->signature == MagickSignature);
5227 assert(image_view != (CacheView *) NULL);
5229 x_offset=(ssize_t) floor(x);
5230 y_offset=(ssize_t) floor(y);
5231 interpolate = method;
5232 if ( interpolate == UndefinedInterpolatePixel )
5233 interpolate = image->interpolate;
5234 switch (interpolate)
5236 case AverageInterpolatePixel: /* nearest 4 neighbours */
5237 case Average9InterpolatePixel: /* nearest 9 neighbours */
5238 case Average16InterpolatePixel: /* nearest 16 neighbours */
5243 count=2; /* size of the area to average - default nearest 4 */
5244 if (interpolate == Average9InterpolatePixel)
5247 x_offset=(ssize_t) (floor(x+0.5)-1);
5248 y_offset=(ssize_t) (floor(y+0.5)-1);
5250 else if (interpolate == Average16InterpolatePixel)
5256 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,count,count,
5258 if (p == (const Quantum *) NULL)
5268 count*=count; /* number of pixels - square of size */
5269 for (i=0; i < (ssize_t) count; i++)
5271 AlphaBlendPixelInfo(image,p,pixels,alpha);
5272 gamma=PerceptibleReciprocal(alpha[0]);
5273 pixel->red+=gamma*pixels[0].red;
5274 pixel->green+=gamma*pixels[0].green;
5275 pixel->blue+=gamma*pixels[0].blue;
5276 pixel->black+=gamma*pixels[0].black;
5277 pixel->alpha+=pixels[0].alpha;
5278 p += GetPixelChannels(image);
5280 gamma=1.0/count; /* average weighting of each pixel in area */
5282 pixel->green*=gamma;
5284 pixel->black*=gamma;
5285 pixel->alpha*=gamma;
5288 case BackgroundInterpolatePixel:
5290 *pixel=image->background_color; /* Copy PixelInfo Structure */
5293 case BilinearInterpolatePixel:
5300 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5301 if (p == (const Quantum *) NULL)
5306 for (i=0; i < 4L; i++)
5307 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5310 epsilon.x=1.0-delta.x;
5311 epsilon.y=1.0-delta.y;
5312 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5313 (epsilon.x*alpha[2]+delta.x*alpha[3])));
5314 gamma=PerceptibleReciprocal(gamma);
5315 pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
5316 pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red));
5317 pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x*
5318 pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x*
5320 pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x*
5321 pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x*
5323 if (image->colorspace == CMYKColorspace)
5324 pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x*
5325 pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x*
5327 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5328 gamma=PerceptibleReciprocal(gamma);
5329 pixel->alpha=(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x*
5330 pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x*
5334 case BlendInterpolatePixel:
5336 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5337 if (p == (const Quantum *) NULL)
5342 for (i=0; i < 4L; i++)
5343 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5344 gamma=1.0; /* number of pixels blended together (its variable) */
5345 for (i=0; i <= 1L; i++)
5347 if ((y-y_offset) >= 0.75)
5349 alpha[i]=alpha[i+2]; /* take right pixels */
5350 pixels[i]=pixels[i+2];
5353 if ((y-y_offset) > 0.25)
5355 gamma=2.0; /* blend both pixels in row */
5356 alpha[i]+=alpha[i+2]; /* add up alpha weights */
5357 pixels[i].red+=pixels[i+2].red;
5358 pixels[i].green+=pixels[i+2].green;
5359 pixels[i].blue+=pixels[i+2].blue;
5360 pixels[i].black+=pixels[i+2].black;
5361 pixels[i].alpha+=pixels[i+2].alpha;
5364 if ((x-x_offset) >= 0.75)
5367 pixels[0]=pixels[1];
5370 if ((x-x_offset) > 0.25)
5372 gamma*=2.0; /* blend both rows */
5373 alpha[0]+= alpha[1]; /* add up alpha weights */
5374 pixels[0].red+=pixels[1].red;
5375 pixels[0].green+=pixels[1].green;
5376 pixels[0].blue+=pixels[1].blue;
5377 pixels[0].black+=pixels[1].black;
5378 pixels[0].alpha+=pixels[1].alpha;
5381 alpha[0]=PerceptibleReciprocal(alpha[0]);
5382 pixel->red=alpha[0]*pixels[0].red;
5383 pixel->green=alpha[0]*pixels[0].green; /* divide by sum of alpha */
5384 pixel->blue=alpha[0]*pixels[0].blue;
5385 pixel->black=alpha[0]*pixels[0].black;
5386 pixel->alpha=gamma*pixels[0].alpha; /* divide by number of pixels */
5389 case CatromInterpolatePixel:
5395 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5397 if (p == (const Quantum *) NULL)
5402 for (i=0; i < 16L; i++)
5403 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5404 CatromWeights((double) (x-x_offset),&cx);
5405 CatromWeights((double) (y-y_offset),&cy);
5406 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]*
5407 pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5408 pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]*
5409 pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5410 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]*
5411 pixels[14].red+cx[3]*pixels[15].red));
5412 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]*
5413 pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+
5414 cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+
5415 cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]*
5416 pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]*
5417 pixels[12].green+cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]*
5419 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]*
5420 pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5421 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]*
5422 pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5423 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+
5424 cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5425 if (image->colorspace == CMYKColorspace)
5426 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]*
5427 pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+
5428 cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+
5429 cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]*
5430 pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]*
5431 pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]*
5433 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]*
5434 pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+
5435 cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+
5436 cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]*
5437 pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+
5438 cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5442 /* deprecated useless and very slow interpolator */
5443 case FilterInterpolatePixel:
5457 geometry.x=x_offset-1;
5458 geometry.y=y_offset-1;
5459 excerpt_image=ExcerptImage(image,&geometry,exception);
5460 if (excerpt_image == (Image *) NULL)
5465 filter_image=ResizeImage(excerpt_image,1,1,image->filter,exception);
5466 excerpt_image=DestroyImage(excerpt_image);
5467 if (filter_image == (Image *) NULL)
5469 filter_view=AcquireVirtualCacheView(filter_image,exception);
5470 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
5471 if (p != (const Quantum *) NULL)
5472 GetPixelInfoPixel(image,p,pixel);
5473 filter_view=DestroyCacheView(filter_view);
5474 filter_image=DestroyImage(filter_image);
5478 case IntegerInterpolatePixel:
5480 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5481 if (p == (const Quantum *) NULL)
5486 GetPixelInfoPixel(image,p,pixel);
5489 case MeshInterpolatePixel:
5495 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5496 if (p == (const Quantum *) NULL)
5503 luminance.x=GetPixelLuminance(image,p)-(double)
5504 GetPixelLuminance(image,p+3*GetPixelChannels(image));
5505 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
5506 GetPixelLuminance(image,p+2*GetPixelChannels(image));
5507 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5508 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5509 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5510 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5511 if (fabs(luminance.x) < fabs(luminance.y))
5516 if (delta.x <= delta.y)
5519 Bottom-left triangle (pixel: 2, diagonal: 0-3).
5521 delta.y=1.0-delta.y;
5522 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5523 gamma=PerceptibleReciprocal(gamma);
5524 pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red,
5525 pixels[3].red,pixels[0].red);
5526 pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green,
5527 pixels[3].green,pixels[0].green);
5528 pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
5529 pixels[3].blue,pixels[0].blue);
5530 if (image->colorspace == CMYKColorspace)
5531 pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black,
5532 pixels[3].black,pixels[0].black);
5533 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5534 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha,
5535 pixels[3].alpha,pixels[0].alpha);
5540 Top-right triangle (pixel:1 , diagonal: 0-3).
5542 delta.x=1.0-delta.x;
5543 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5544 gamma=PerceptibleReciprocal(gamma);
5545 pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red,
5546 pixels[0].red,pixels[3].red);
5547 pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green,
5548 pixels[0].green,pixels[3].green);
5549 pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
5550 pixels[0].blue,pixels[3].blue);
5551 if (image->colorspace == CMYKColorspace)
5552 pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black,
5553 pixels[0].black,pixels[3].black);
5554 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5555 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha,
5556 pixels[0].alpha,pixels[3].alpha);
5564 if (delta.x <= (1.0-delta.y))
5567 Top-left triangle (pixel: 0, diagonal: 1-2).
5569 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5570 gamma=PerceptibleReciprocal(gamma);
5571 pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red,
5572 pixels[1].red,pixels[2].red);
5573 pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green,
5574 pixels[1].green,pixels[2].green);
5575 pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
5576 pixels[1].blue,pixels[2].blue);
5577 if (image->colorspace == CMYKColorspace)
5578 pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black,
5579 pixels[1].black,pixels[2].black);
5580 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5581 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha,
5582 pixels[1].alpha,pixels[2].alpha);
5587 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5589 delta.x=1.0-delta.x;
5590 delta.y=1.0-delta.y;
5591 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5592 gamma=PerceptibleReciprocal(gamma);
5593 pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red,
5594 pixels[2].red,pixels[1].red);
5595 pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green,
5596 pixels[2].green,pixels[1].green);
5597 pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
5598 pixels[2].blue,pixels[1].blue);
5599 if (image->colorspace == CMYKColorspace)
5600 pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black,
5601 pixels[2].black,pixels[1].black);
5602 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5603 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha,
5604 pixels[2].alpha,pixels[1].alpha);
5609 case NearestInterpolatePixel:
5611 x_offset=(ssize_t) floor(x+0.5);
5612 y_offset=(ssize_t) floor(y+0.5);
5613 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5614 if (p == (const Quantum *) NULL)
5619 GetPixelInfoPixel(image,p,pixel);
5622 case SplineInterpolatePixel:
5628 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5630 if (p == (const Quantum *) NULL)
5635 for (i=0; i < 16L; i++)
5636 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5637 SplineWeights((double) (x-x_offset),&cx);
5638 SplineWeights((double) (y-y_offset),&cy);
5639 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]*
5640 pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5641 pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]*
5642 pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5643 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]*
5644 pixels[14].red+cx[3]*pixels[15].red));
5645 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]*
5646 pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+
5647 cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+
5648 cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]*
5649 pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]*pixels[12].green+
5650 cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]*pixels[15].green));
5651 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]*
5652 pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5653 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]*
5654 pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5655 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+
5656 cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5657 if (image->colorspace == CMYKColorspace)
5658 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]*
5659 pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+
5660 cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+
5661 cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]*
5662 pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]*
5663 pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]*
5665 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]*
5666 pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+
5667 cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+
5668 cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]*
5669 pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+
5670 cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5678 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5682 + I s F u z z y E q u i v a l e n c e P i x e l %
5686 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5688 % IsFuzzyEquivalencePixel() returns MagickTrue if the distance between two
5689 % pixels is less than the specified distance in a linear three (or four)u
5690 % dimensional color space.
5692 % The format of the IsFuzzyEquivalencePixel method is:
5694 % void IsFuzzyEquivalencePixel(const Image *source,const Quantum *p,
5695 % const Image *destination,const Quantum *q)
5697 % A description of each parameter follows:
5699 % o source: the source image.
5703 % o destination: the destination image.
5708 MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *source,
5709 const Quantum *p,const Image *destination,const Quantum *q)
5719 fuzz=MagickMax(source->fuzz,(double) MagickSQ1_2)*MagickMax(
5720 destination->fuzz,(double) MagickSQ1_2);
5723 if (source->alpha_trait == BlendPixelTrait)
5726 Transparencies are involved - set alpha distance
5728 pixel=GetPixelAlpha(source,p)-(double)
5729 GetPixelAlpha(destination,q);
5730 distance=pixel*pixel;
5731 if (distance > fuzz)
5732 return(MagickFalse);
5734 Generate a alpha scaling factor to generate a 4D cone on colorspace
5735 Note that if one color is transparent, distance has no color component.
5737 scale=QuantumScale*GetPixelAlpha(source,p);
5738 scale*=QuantumScale*GetPixelAlpha(destination,q);
5739 if (scale <= MagickEpsilon)
5743 RGB or CMY color cube
5745 distance*=3.0; /* rescale appropriately */
5747 pixel=GetPixelRed(source,p)-(double) GetPixelRed(destination,q);
5748 if ((source->colorspace == HSLColorspace) ||
5749 (source->colorspace == HSBColorspace) ||
5750 (source->colorspace == HWBColorspace))
5753 Compute an arc distance for hue. It should be a vector angle of
5754 'S'/'W' length with 'L'/'B' forming appropriate cones.
5756 if (fabs((double) pixel) > (QuantumRange/2))
5757 pixel-=QuantumRange;
5760 distance+=scale*pixel*pixel;
5761 if (distance > fuzz)
5762 return(MagickFalse);
5763 pixel=GetPixelGreen(source,p)-(double) GetPixelGreen(destination,q);
5764 distance+=scale*pixel*pixel;
5765 if (distance > fuzz)
5766 return(MagickFalse);
5767 pixel=GetPixelBlue(source,p)-(double) GetPixelBlue(destination,q);
5768 distance+=scale*pixel*pixel;
5769 if (distance > fuzz)
5770 return(MagickFalse);
5775 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5779 + 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 %
5783 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5785 % IsFuzzyEquivalencePixelInfo() returns true if the distance between two
5786 % colors is less than the specified distance in a linear three (or four)
5787 % dimensional color space.
5789 % This implements the equivalent of:
5790 % fuzz < sqrt(color_distance^2 * u.a*v.a + alpha_distance^2)
5792 % Which produces a multi-dimensional cone for that colorspace along the
5793 % transparency vector.
5795 % For example for an RGB:
5796 % color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3
5798 % See http://www.imagemagick.org/Usage/bugs/fuzz_distance/
5800 % Hue colorspace distances need more work. Hue is not a distance, it is an
5803 % A check that q is in the same color space as p should be made and the
5804 % appropriate mapping made. -- Anthony Thyssen 8 December 2010
5806 % The format of the IsFuzzyEquivalencePixelInfo method is:
5808 % MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5809 % const PixelInfo *q)
5811 % A description of each parameter follows:
5818 MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5829 if ((p->fuzz == 0.0) && (q->fuzz == 0.0))
5830 return(IsPixelInfoEquivalent(p,q));
5832 fuzz=MagickMax(q->fuzz,(double) MagickSQ1_2)*MagickMax(q->fuzz,
5833 (double) MagickSQ1_2);
5834 else if (q->fuzz == 0.0)
5835 fuzz=MagickMax(p->fuzz,(double) MagickSQ1_2)*MagickMax(p->fuzz,
5836 (double) MagickSQ1_2);
5838 fuzz=MagickMax(p->fuzz,(double) MagickSQ1_2)*MagickMax(q->fuzz,
5839 (double) MagickSQ1_2);
5842 if ((p->alpha_trait == BlendPixelTrait) || (q->alpha_trait == BlendPixelTrait))
5845 Transparencies are involved - set alpha distance.
5847 pixel=(p->alpha_trait == BlendPixelTrait ? p->alpha : OpaqueAlpha)-
5848 (q->alpha_trait == BlendPixelTrait ? q->alpha : OpaqueAlpha);
5849 distance=pixel*pixel;
5850 if (distance > fuzz)
5851 return(MagickFalse);
5853 Generate a alpha scaling factor to generate a 4D cone on colorspace.
5854 If one color is transparent, distance has no color component.
5856 if (p->alpha_trait == BlendPixelTrait)
5857 scale=(QuantumScale*p->alpha);
5858 if (q->alpha_trait == BlendPixelTrait)
5859 scale*=(QuantumScale*q->alpha);
5860 if (scale <= MagickEpsilon )
5864 CMYK create a CMY cube with a multi-dimensional cone toward black.
5866 if (p->colorspace == CMYKColorspace)
5868 pixel=p->black-q->black;
5869 distance+=pixel*pixel*scale;
5870 if (distance > fuzz)
5871 return(MagickFalse);
5872 scale*=(double) (QuantumScale*(QuantumRange-p->black));
5873 scale*=(double) (QuantumScale*(QuantumRange-q->black));
5876 RGB or CMY color cube.
5878 distance*=3.0; /* rescale appropriately */
5880 pixel=p->red-q->red;
5881 if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) ||
5882 (p->colorspace == HWBColorspace))
5885 This calculates a arc distance for hue-- it should be a vector angle
5886 of 'S'/'W' length with 'L'/'B' forming appropriate cones. In other
5887 words this is a hack - Anthony.
5889 if (fabs((double) pixel) > (QuantumRange/2))
5890 pixel-=QuantumRange;
5893 distance+=pixel*pixel*scale;
5894 if (distance > fuzz)
5895 return(MagickFalse);
5896 pixel=p->green-q->green;
5897 distance+=pixel*pixel*scale;
5898 if (distance > fuzz)
5899 return(MagickFalse);
5900 pixel=p->blue-q->blue;
5901 distance+=pixel*pixel*scale;
5902 if (distance > fuzz)
5903 return(MagickFalse);
5908 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5912 % S e t P i x e l C h a n n e l M a p M a s k %
5916 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5918 % SetPixelChannelMask() sets the pixel channel map from the specified
5921 % The format of the SetPixelChannelMask method is:
5923 % void SetPixelChannelMask(Image *image,const ChannelType channel_mask)
5925 % A description of each parameter follows:
5927 % o image: the image.
5929 % o channel_mask: the channel mask.
5932 MagickExport void SetPixelChannelMask(Image *image,
5933 const ChannelType channel_mask)
5935 #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
5940 if (image->debug != MagickFalse)
5941 (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%08x]", \
5942 image->filename,channel_mask); \
5943 image->channel_mask=channel_mask;
5944 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5946 PixelChannel channel=GetPixelChannelChannel(image,i);
5947 SetPixelChannelTraits(image,channel,
5948 GetChannelBit(channel_mask,channel) == 0 ? CopyPixelTrait :
5949 image->alpha_trait != BlendPixelTrait || (channel == AlphaPixelChannel) ?
5950 UpdatePixelTrait : (PixelTrait) (UpdatePixelTrait | image->alpha_trait));
5952 if (image->storage_class == PseudoClass)
5953 SetPixelChannelTraits(image,IndexPixelChannel,CopyPixelTrait);
5954 if (image->mask != MagickFalse)
5955 SetPixelChannelTraits(image,MaskPixelChannel,CopyPixelTrait);
5956 if (image->debug != MagickFalse)
5957 LogPixelChannels(image);
5961 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5965 % S e t P i x e l M e t a C h a n n e l s %
5969 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5971 % SetPixelMetaChannels() sets the image meta channels.
5973 % The format of the SetPixelMetaChannels method is:
5975 % MagickBooleanType SetPixelMetaChannels(Image *image,
5976 % const size_t number_meta_channels,ExceptionInfo *exception)
5978 % A description of each parameter follows:
5980 % o image: the image.
5982 % o number_meta_channels: the number of meta channels.
5984 % o exception: return any errors or warnings in this structure.
5987 MagickExport MagickBooleanType SetPixelMetaChannels(Image *image,
5988 const size_t number_meta_channels,ExceptionInfo *exception)
5990 image->number_meta_channels=number_meta_channels;
5991 return(SyncImagePixelCache(image,exception));