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(ClampToQuantum(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(ClampToQuantum(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(ClampToQuantum(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(ClampToQuantum(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(ClampToQuantum(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(ClampToQuantum(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++=ClampToQuantum(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=ClampToQuantum(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(ClampToQuantum(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(ClampToQuantum(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 % G e t P i x e l I n t e n s i t y %
2096 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2098 % GetPixelIntensity() returns a single sample intensity value from the red,
2099 % green, and blue components of a pixel based on the selected method:
2101 % Rec601Luma 0.298839R' + 0.586811G' + 0.114350B'
2102 % Rec601Luminance 0.298839R + 0.586811G + 0.114350B
2103 % Rec709Luma 0.21260R' + 0.71520G' + 0.07220B'
2104 % Rec709Luminance 0.21260R + 0.71520G + 0.07220B
2105 % Brightness max(R, G, B)
2106 % Lightness (min(R, G, B) + max(R, G, B)) / 2.0
2107 % RMS (R'^2 + G'^2 + B'^2) / 3.0
2108 % Average (R' + G' + B') / 3.0
2110 % The format of the GetPixelIntensity method is:
2112 % MagickRealType GetPixelIntensity(const Image *image,
2113 % const Quantum *pixel)
2115 % A description of each parameter follows:
2117 % o image: the image.
2119 % o pixel: Specifies a pointer to a Quantum structure.
2123 static inline MagickRealType MagickMax(const MagickRealType x,
2124 const MagickRealType y)
2131 static inline MagickRealType MagickMin(const MagickRealType x,
2132 const MagickRealType y)
2139 MagickExport MagickRealType GetPixelIntensity(const Image *restrict image,
2140 const Quantum *restrict pixel)
2148 if (image->colorspace == GRAYColorspace)
2149 return((MagickRealType) pixel[image->channel_map[GrayPixelChannel].offset]);
2150 red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
2151 green=(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
2152 blue=(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
2153 switch (image->intensity)
2155 case AveragePixelIntensityMethod:
2157 intensity=(red+green+blue)/3.0;
2160 case BrightnessPixelIntensityMethod:
2162 intensity=MagickMax(MagickMax(red,green),blue);
2165 case LightnessPixelIntensityMethod:
2167 intensity=MagickMin(MagickMin(red,green),blue);
2170 case Rec601LumaPixelIntensityMethod:
2172 intensity=0.298839f*red+0.586811f*green+0.114350f*blue;
2175 case Rec601LuminancePixelIntensityMethod:
2177 if (image->colorspace == sRGBColorspace)
2179 red=DecodePixelGamma(red);
2180 green=DecodePixelGamma(green);
2181 blue=DecodePixelGamma(blue);
2183 intensity=0.298839f*red+0.586811f*green+0.114350f*blue;
2186 case Rec709LumaPixelIntensityMethod:
2189 intensity=0.21260f*red+0.71520f*green+0.07220f*blue;
2192 case Rec709LuminancePixelIntensityMethod:
2194 if (image->colorspace == sRGBColorspace)
2196 red=DecodePixelGamma(red);
2197 green=DecodePixelGamma(green);
2198 blue=DecodePixelGamma(blue);
2200 intensity=0.21260f*red+0.71520f*green+0.07220f*blue;
2203 case RMSPixelIntensityMethod:
2205 intensity=(MagickRealType) sqrt((double) red*red+green*green+blue*blue);
2213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2217 % I m p o r t I m a g e P i x e l s %
2221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2223 % ImportImagePixels() accepts pixel data and stores in the image at the
2224 % location you specify. The method returns MagickTrue on success otherwise
2225 % MagickFalse if an error is encountered. The pixel data can be either char,
2226 % Quantum, short int, unsigned int, unsigned long long, float, or double in
2227 % the order specified by map.
2229 % Suppose your want to upload the first scanline of a 640x480 image from
2230 % character data in red-green-blue order:
2232 % ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels);
2234 % The format of the ImportImagePixels method is:
2236 % MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
2237 % const ssize_t y,const size_t width,const size_t height,
2238 % const char *map,const StorageType type,const void *pixels,
2239 % ExceptionInfo *exception)
2241 % A description of each parameter follows:
2243 % o image: the image.
2245 % o x,y,width,height: These values define the perimeter
2246 % of a region of pixels you want to define.
2248 % o map: This string reflects the expected ordering of the pixel array.
2249 % It can be any combination or order of R = red, G = green, B = blue,
2250 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
2251 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
2254 % o type: Define the data type of the pixels. Float and double types are
2255 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
2256 % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *),
2257 % LongPixel (unsigned int *), LongLongPixel (unsigned long long *),
2258 % QuantumPixel (Quantum *), or ShortPixel (unsigned short *).
2260 % o pixels: This array of values contain the pixel components as defined by
2261 % map and type. You must preallocate this array where the expected
2262 % length varies depending on the values of width, height, map, and type.
2264 % o exception: return any errors or warnings in this structure.
2268 static void ImportCharPixel(Image *image,const RectangleInfo *roi,
2269 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2270 ExceptionInfo *exception)
2272 register const unsigned char
2287 p=(const unsigned char *) pixels;
2288 if (LocaleCompare(map,"BGR") == 0)
2290 for (y=0; y < (ssize_t) roi->height; y++)
2292 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2293 if (q == (Quantum *) NULL)
2295 for (x=0; x < (ssize_t) roi->width; x++)
2297 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2298 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2299 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2300 q+=GetPixelChannels(image);
2302 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2307 if (LocaleCompare(map,"BGRA") == 0)
2309 for (y=0; y < (ssize_t) roi->height; y++)
2311 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2312 if (q == (Quantum *) NULL)
2314 for (x=0; x < (ssize_t) roi->width; x++)
2316 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2317 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2318 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2319 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2320 q+=GetPixelChannels(image);
2322 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2327 if (LocaleCompare(map,"BGRO") == 0)
2329 for (y=0; y < (ssize_t) roi->height; y++)
2331 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2332 if (q == (Quantum *) NULL)
2334 for (x=0; x < (ssize_t) roi->width; x++)
2336 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2337 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2338 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2339 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2340 q+=GetPixelChannels(image);
2342 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2347 if (LocaleCompare(map,"BGRP") == 0)
2349 for (y=0; y < (ssize_t) roi->height; y++)
2351 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2352 if (q == (Quantum *) NULL)
2354 for (x=0; x < (ssize_t) roi->width; x++)
2356 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2357 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2358 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2360 q+=GetPixelChannels(image);
2362 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2367 if (LocaleCompare(map,"I") == 0)
2369 for (y=0; y < (ssize_t) roi->height; y++)
2371 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2372 if (q == (Quantum *) NULL)
2374 for (x=0; x < (ssize_t) roi->width; x++)
2376 SetPixelGray(image,ScaleCharToQuantum(*p++),q);
2377 q+=GetPixelChannels(image);
2379 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2384 if (LocaleCompare(map,"RGB") == 0)
2386 for (y=0; y < (ssize_t) roi->height; y++)
2388 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2389 if (q == (Quantum *) NULL)
2391 for (x=0; x < (ssize_t) roi->width; x++)
2393 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2394 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2395 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2396 q+=GetPixelChannels(image);
2398 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2403 if (LocaleCompare(map,"RGBA") == 0)
2405 for (y=0; y < (ssize_t) roi->height; y++)
2407 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2408 if (q == (Quantum *) NULL)
2410 for (x=0; x < (ssize_t) roi->width; x++)
2412 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2413 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2414 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2415 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2416 q+=GetPixelChannels(image);
2418 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2423 if (LocaleCompare(map,"RGBO") == 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 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2433 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2434 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2435 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2436 q+=GetPixelChannels(image);
2438 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2443 if (LocaleCompare(map,"RGBP") == 0)
2445 for (y=0; y < (ssize_t) roi->height; y++)
2447 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2448 if (q == (Quantum *) NULL)
2450 for (x=0; x < (ssize_t) roi->width; x++)
2452 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2453 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2454 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2456 q+=GetPixelChannels(image);
2458 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2464 for (y=0; y < (ssize_t) roi->height; y++)
2466 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2467 if (q == (Quantum *) NULL)
2469 for (x=0; x < (ssize_t) roi->width; x++)
2474 for (i=0; i < (ssize_t) length; i++)
2476 switch (quantum_map[i])
2481 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2485 case MagentaQuantum:
2487 SetPixelGreen(image,ScaleCharToQuantum(*p),q);
2493 SetPixelBlue(image,ScaleCharToQuantum(*p),q);
2498 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2501 case OpacityQuantum:
2503 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2508 SetPixelBlack(image,ScaleCharToQuantum(*p),q);
2513 SetPixelGray(image,ScaleCharToQuantum(*p),q);
2521 q+=GetPixelChannels(image);
2523 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2528 static void ImportDoublePixel(Image *image,const RectangleInfo *roi,
2529 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2530 ExceptionInfo *exception)
2532 register const double
2547 p=(const double *) pixels;
2548 if (LocaleCompare(map,"BGR") == 0)
2550 for (y=0; y < (ssize_t) roi->height; y++)
2552 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2553 if (q == (Quantum *) NULL)
2555 for (x=0; x < (ssize_t) roi->width; x++)
2557 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2559 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2561 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2563 q+=GetPixelChannels(image);
2565 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2570 if (LocaleCompare(map,"BGRA") == 0)
2572 for (y=0; y < (ssize_t) roi->height; y++)
2574 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2575 if (q == (Quantum *) NULL)
2577 for (x=0; x < (ssize_t) roi->width; x++)
2579 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2581 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2583 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2585 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2587 q+=GetPixelChannels(image);
2589 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2594 if (LocaleCompare(map,"BGRP") == 0)
2596 for (y=0; y < (ssize_t) roi->height; y++)
2598 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2599 if (q == (Quantum *) NULL)
2601 for (x=0; x < (ssize_t) roi->width; x++)
2603 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2605 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2607 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2610 q+=GetPixelChannels(image);
2612 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2617 if (LocaleCompare(map,"I") == 0)
2619 for (y=0; y < (ssize_t) roi->height; y++)
2621 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2622 if (q == (Quantum *) NULL)
2624 for (x=0; x < (ssize_t) roi->width; x++)
2626 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2628 q+=GetPixelChannels(image);
2630 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2635 if (LocaleCompare(map,"RGB") == 0)
2637 for (y=0; y < (ssize_t) roi->height; y++)
2639 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2640 if (q == (Quantum *) NULL)
2642 for (x=0; x < (ssize_t) roi->width; x++)
2644 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2646 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2648 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2650 q+=GetPixelChannels(image);
2652 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2657 if (LocaleCompare(map,"RGBA") == 0)
2659 for (y=0; y < (ssize_t) roi->height; y++)
2661 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2662 if (q == (Quantum *) NULL)
2664 for (x=0; x < (ssize_t) roi->width; x++)
2666 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2668 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2670 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2672 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2674 q+=GetPixelChannels(image);
2676 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2681 if (LocaleCompare(map,"RGBP") == 0)
2683 for (y=0; y < (ssize_t) roi->height; y++)
2685 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2686 if (q == (Quantum *) NULL)
2688 for (x=0; x < (ssize_t) roi->width; x++)
2690 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2692 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2694 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2696 q+=GetPixelChannels(image);
2698 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2704 for (y=0; y < (ssize_t) roi->height; y++)
2706 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2707 if (q == (Quantum *) NULL)
2709 for (x=0; x < (ssize_t) roi->width; x++)
2714 for (i=0; i < (ssize_t) length; i++)
2716 switch (quantum_map[i])
2721 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2725 case MagentaQuantum:
2727 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2733 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2738 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2741 case OpacityQuantum:
2743 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2748 SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q);
2753 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2761 q+=GetPixelChannels(image);
2763 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2768 static void ImportFloatPixel(Image *image,const RectangleInfo *roi,
2769 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2770 ExceptionInfo *exception)
2772 register const float
2787 p=(const float *) pixels;
2788 if (LocaleCompare(map,"BGR") == 0)
2790 for (y=0; y < (ssize_t) roi->height; y++)
2792 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2793 if (q == (Quantum *) NULL)
2795 for (x=0; x < (ssize_t) roi->width; x++)
2797 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2799 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2801 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2803 q+=GetPixelChannels(image);
2805 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2810 if (LocaleCompare(map,"BGRA") == 0)
2812 for (y=0; y < (ssize_t) roi->height; y++)
2814 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2815 if (q == (Quantum *) NULL)
2817 for (x=0; x < (ssize_t) roi->width; x++)
2819 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2821 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2823 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2825 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2827 q+=GetPixelChannels(image);
2829 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2834 if (LocaleCompare(map,"BGRP") == 0)
2836 for (y=0; y < (ssize_t) roi->height; y++)
2838 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2839 if (q == (Quantum *) NULL)
2841 for (x=0; x < (ssize_t) roi->width; x++)
2843 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2845 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2847 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2850 q+=GetPixelChannels(image);
2852 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2857 if (LocaleCompare(map,"I") == 0)
2859 for (y=0; y < (ssize_t) roi->height; y++)
2861 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2862 if (q == (Quantum *) NULL)
2864 for (x=0; x < (ssize_t) roi->width; x++)
2866 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2868 q+=GetPixelChannels(image);
2870 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2875 if (LocaleCompare(map,"RGB") == 0)
2877 for (y=0; y < (ssize_t) roi->height; y++)
2879 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2880 if (q == (Quantum *) NULL)
2882 for (x=0; x < (ssize_t) roi->width; x++)
2884 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2886 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2888 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2890 q+=GetPixelChannels(image);
2892 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2897 if (LocaleCompare(map,"RGBA") == 0)
2899 for (y=0; y < (ssize_t) roi->height; y++)
2901 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2902 if (q == (Quantum *) NULL)
2904 for (x=0; x < (ssize_t) roi->width; x++)
2906 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2908 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2910 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2912 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2914 q+=GetPixelChannels(image);
2916 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2921 if (LocaleCompare(map,"RGBP") == 0)
2923 for (y=0; y < (ssize_t) roi->height; y++)
2925 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2926 if (q == (Quantum *) NULL)
2928 for (x=0; x < (ssize_t) roi->width; x++)
2930 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2932 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2934 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2936 q+=GetPixelChannels(image);
2938 if (SyncAuthenticPixels(image,exception) == MagickFalse)
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++)
2954 for (i=0; i < (ssize_t) length; i++)
2956 switch (quantum_map[i])
2961 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2965 case MagentaQuantum:
2967 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2973 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2978 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2981 case OpacityQuantum:
2983 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2988 SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q);
2993 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
3001 q+=GetPixelChannels(image);
3003 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3008 static void ImportLongPixel(Image *image,const RectangleInfo *roi,
3009 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3010 ExceptionInfo *exception)
3012 register const unsigned int
3027 p=(const unsigned int *) pixels;
3028 if (LocaleCompare(map,"BGR") == 0)
3030 for (y=0; y < (ssize_t) roi->height; y++)
3032 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3033 if (q == (Quantum *) NULL)
3035 for (x=0; x < (ssize_t) roi->width; x++)
3037 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3038 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3039 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3040 q+=GetPixelChannels(image);
3042 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3047 if (LocaleCompare(map,"BGRA") == 0)
3049 for (y=0; y < (ssize_t) roi->height; y++)
3051 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3052 if (q == (Quantum *) NULL)
3054 for (x=0; x < (ssize_t) roi->width; x++)
3056 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3057 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3058 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3059 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3060 q+=GetPixelChannels(image);
3062 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3067 if (LocaleCompare(map,"BGRP") == 0)
3069 for (y=0; y < (ssize_t) roi->height; y++)
3071 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3072 if (q == (Quantum *) NULL)
3074 for (x=0; x < (ssize_t) roi->width; x++)
3076 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3077 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3078 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3080 q+=GetPixelChannels(image);
3082 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3087 if (LocaleCompare(map,"I") == 0)
3089 for (y=0; y < (ssize_t) roi->height; y++)
3091 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3092 if (q == (Quantum *) NULL)
3094 for (x=0; x < (ssize_t) roi->width; x++)
3096 SetPixelGray(image,ScaleLongToQuantum(*p++),q);
3097 q+=GetPixelChannels(image);
3099 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3104 if (LocaleCompare(map,"RGB") == 0)
3106 for (y=0; y < (ssize_t) roi->height; y++)
3108 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3109 if (q == (Quantum *) NULL)
3111 for (x=0; x < (ssize_t) roi->width; x++)
3113 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3114 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3115 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3116 q+=GetPixelChannels(image);
3118 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3123 if (LocaleCompare(map,"RGBA") == 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 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3133 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3134 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3135 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3136 q+=GetPixelChannels(image);
3138 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3143 if (LocaleCompare(map,"RGBP") == 0)
3145 for (y=0; y < (ssize_t) roi->height; y++)
3147 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3148 if (q == (Quantum *) NULL)
3150 for (x=0; x < (ssize_t) roi->width; x++)
3152 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3153 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3154 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3156 q+=GetPixelChannels(image);
3158 if (SyncAuthenticPixels(image,exception) == MagickFalse)
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++)
3174 for (i=0; i < (ssize_t) length; i++)
3176 switch (quantum_map[i])
3181 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3185 case MagentaQuantum:
3187 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
3193 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
3198 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3201 case OpacityQuantum:
3203 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3208 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
3213 SetPixelGray(image,ScaleLongToQuantum(*p),q);
3221 q+=GetPixelChannels(image);
3223 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3228 static void ImportLongLongPixel(Image *image,const RectangleInfo *roi,
3229 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3230 ExceptionInfo *exception)
3232 register const MagickSizeType
3247 p=(const MagickSizeType *) pixels;
3248 if (LocaleCompare(map,"BGR") == 0)
3250 for (y=0; y < (ssize_t) roi->height; y++)
3252 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3253 if (q == (Quantum *) NULL)
3255 for (x=0; x < (ssize_t) roi->width; x++)
3257 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3258 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3259 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3260 q+=GetPixelChannels(image);
3262 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3267 if (LocaleCompare(map,"BGRA") == 0)
3269 for (y=0; y < (ssize_t) roi->height; y++)
3271 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3272 if (q == (Quantum *) NULL)
3274 for (x=0; x < (ssize_t) roi->width; x++)
3276 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3277 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3278 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3279 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3280 q+=GetPixelChannels(image);
3282 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3287 if (LocaleCompare(map,"BGRP") == 0)
3289 for (y=0; y < (ssize_t) roi->height; y++)
3291 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3292 if (q == (Quantum *) NULL)
3294 for (x=0; x < (ssize_t) roi->width; x++)
3296 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3297 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3298 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3300 q+=GetPixelChannels(image);
3302 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3307 if (LocaleCompare(map,"I") == 0)
3309 for (y=0; y < (ssize_t) roi->height; y++)
3311 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3312 if (q == (Quantum *) NULL)
3314 for (x=0; x < (ssize_t) roi->width; x++)
3316 SetPixelGray(image,ScaleLongLongToQuantum(*p++),q);
3317 q+=GetPixelChannels(image);
3319 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3324 if (LocaleCompare(map,"RGB") == 0)
3326 for (y=0; y < (ssize_t) roi->height; y++)
3328 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3329 if (q == (Quantum *) NULL)
3331 for (x=0; x < (ssize_t) roi->width; x++)
3333 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3334 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3335 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3336 q+=GetPixelChannels(image);
3338 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3343 if (LocaleCompare(map,"RGBA") == 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 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3353 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3354 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3355 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3356 q+=GetPixelChannels(image);
3358 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3363 if (LocaleCompare(map,"RGBP") == 0)
3365 for (y=0; y < (ssize_t) roi->height; y++)
3367 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3368 if (q == (Quantum *) NULL)
3370 for (x=0; x < (ssize_t) roi->width; x++)
3372 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3373 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3374 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3376 q+=GetPixelChannels(image);
3378 if (SyncAuthenticPixels(image,exception) == MagickFalse)
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++)
3394 for (i=0; i < (ssize_t) length; i++)
3396 switch (quantum_map[i])
3401 SetPixelRed(image,ScaleLongLongToQuantum(*p),q);
3405 case MagentaQuantum:
3407 SetPixelGreen(image,ScaleLongLongToQuantum(*p),q);
3413 SetPixelBlue(image,ScaleLongLongToQuantum(*p),q);
3418 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3421 case OpacityQuantum:
3423 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3428 SetPixelBlack(image,ScaleLongLongToQuantum(*p),q);
3433 SetPixelGray(image,ScaleLongLongToQuantum(*p),q);
3441 q+=GetPixelChannels(image);
3443 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3448 static void ImportQuantumPixel(Image *image,const RectangleInfo *roi,
3449 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3450 ExceptionInfo *exception)
3452 register const Quantum
3467 p=(const Quantum *) pixels;
3468 if (LocaleCompare(map,"BGR") == 0)
3470 for (y=0; y < (ssize_t) roi->height; y++)
3472 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3473 if (q == (Quantum *) NULL)
3475 for (x=0; x < (ssize_t) roi->width; x++)
3477 SetPixelBlue(image,*p++,q);
3478 SetPixelGreen(image,*p++,q);
3479 SetPixelRed(image,*p++,q);
3480 q+=GetPixelChannels(image);
3482 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3487 if (LocaleCompare(map,"BGRA") == 0)
3489 for (y=0; y < (ssize_t) roi->height; y++)
3491 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3492 if (q == (Quantum *) NULL)
3494 for (x=0; x < (ssize_t) roi->width; x++)
3496 SetPixelBlue(image,*p++,q);
3497 SetPixelGreen(image,*p++,q);
3498 SetPixelRed(image,*p++,q);
3499 SetPixelAlpha(image,*p++,q);
3500 q+=GetPixelChannels(image);
3502 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3507 if (LocaleCompare(map,"BGRP") == 0)
3509 for (y=0; y < (ssize_t) roi->height; y++)
3511 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3512 if (q == (Quantum *) NULL)
3514 for (x=0; x < (ssize_t) roi->width; x++)
3516 SetPixelBlue(image,*p++,q);
3517 SetPixelGreen(image,*p++,q);
3518 SetPixelRed(image,*p++,q);
3520 q+=GetPixelChannels(image);
3522 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3527 if (LocaleCompare(map,"I") == 0)
3529 for (y=0; y < (ssize_t) roi->height; y++)
3531 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3532 if (q == (Quantum *) NULL)
3534 for (x=0; x < (ssize_t) roi->width; x++)
3536 SetPixelGray(image,*p++,q);
3537 q+=GetPixelChannels(image);
3539 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3544 if (LocaleCompare(map,"RGB") == 0)
3546 for (y=0; y < (ssize_t) roi->height; y++)
3548 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3549 if (q == (Quantum *) NULL)
3551 for (x=0; x < (ssize_t) roi->width; x++)
3553 SetPixelRed(image,*p++,q);
3554 SetPixelGreen(image,*p++,q);
3555 SetPixelBlue(image,*p++,q);
3556 q+=GetPixelChannels(image);
3558 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3563 if (LocaleCompare(map,"RGBA") == 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 SetPixelRed(image,*p++,q);
3573 SetPixelGreen(image,*p++,q);
3574 SetPixelBlue(image,*p++,q);
3575 SetPixelAlpha(image,*p++,q);
3576 q+=GetPixelChannels(image);
3578 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3583 if (LocaleCompare(map,"RGBP") == 0)
3585 for (y=0; y < (ssize_t) roi->height; y++)
3587 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3588 if (q == (Quantum *) NULL)
3590 for (x=0; x < (ssize_t) roi->width; x++)
3592 SetPixelRed(image,*p++,q);
3593 SetPixelGreen(image,*p++,q);
3594 SetPixelBlue(image,*p++,q);
3596 q+=GetPixelChannels(image);
3598 if (SyncAuthenticPixels(image,exception) == MagickFalse)
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++)
3614 for (i=0; i < (ssize_t) length; i++)
3616 switch (quantum_map[i])
3621 SetPixelRed(image,*p,q);
3625 case MagentaQuantum:
3627 SetPixelGreen(image,*p,q);
3633 SetPixelBlue(image,*p,q);
3638 SetPixelAlpha(image,*p,q);
3641 case OpacityQuantum:
3643 SetPixelAlpha(image,*p,q);
3648 SetPixelBlack(image,*p,q);
3653 SetPixelGray(image,*p,q);
3661 q+=GetPixelChannels(image);
3663 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3668 static void ImportShortPixel(Image *image,const RectangleInfo *roi,
3669 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3670 ExceptionInfo *exception)
3672 register const unsigned short
3687 p=(const unsigned short *) pixels;
3688 if (LocaleCompare(map,"BGR") == 0)
3690 for (y=0; y < (ssize_t) roi->height; y++)
3692 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3693 if (q == (Quantum *) NULL)
3695 for (x=0; x < (ssize_t) roi->width; x++)
3697 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3698 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3699 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3700 q+=GetPixelChannels(image);
3702 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3707 if (LocaleCompare(map,"BGRA") == 0)
3709 for (y=0; y < (ssize_t) roi->height; y++)
3711 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3712 if (q == (Quantum *) NULL)
3714 for (x=0; x < (ssize_t) roi->width; x++)
3716 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3717 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3718 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3719 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3720 q+=GetPixelChannels(image);
3722 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3727 if (LocaleCompare(map,"BGRP") == 0)
3729 for (y=0; y < (ssize_t) roi->height; y++)
3731 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3732 if (q == (Quantum *) NULL)
3734 for (x=0; x < (ssize_t) roi->width; x++)
3736 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3737 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3738 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3740 q+=GetPixelChannels(image);
3742 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3747 if (LocaleCompare(map,"I") == 0)
3749 for (y=0; y < (ssize_t) roi->height; y++)
3751 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3752 if (q == (Quantum *) NULL)
3754 for (x=0; x < (ssize_t) roi->width; x++)
3756 SetPixelGray(image,ScaleShortToQuantum(*p++),q);
3757 q+=GetPixelChannels(image);
3759 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3764 if (LocaleCompare(map,"RGB") == 0)
3766 for (y=0; y < (ssize_t) roi->height; y++)
3768 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3769 if (q == (Quantum *) NULL)
3771 for (x=0; x < (ssize_t) roi->width; x++)
3773 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3774 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3775 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3776 q+=GetPixelChannels(image);
3778 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3783 if (LocaleCompare(map,"RGBA") == 0)
3785 for (y=0; y < (ssize_t) roi->height; y++)
3787 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3788 if (q == (Quantum *) NULL)
3790 for (x=0; x < (ssize_t) roi->width; x++)
3792 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3793 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3794 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3795 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3796 q+=GetPixelChannels(image);
3798 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3803 if (LocaleCompare(map,"RGBP") == 0)
3805 for (y=0; y < (ssize_t) roi->height; y++)
3807 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3808 if (q == (Quantum *) NULL)
3810 for (x=0; x < (ssize_t) roi->width; x++)
3812 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3813 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3814 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3816 q+=GetPixelChannels(image);
3818 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3824 for (y=0; y < (ssize_t) roi->height; y++)
3826 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3827 if (q == (Quantum *) NULL)
3829 for (x=0; x < (ssize_t) roi->width; x++)
3834 for (i=0; i < (ssize_t) length; i++)
3836 switch (quantum_map[i])
3841 SetPixelRed(image,ScaleShortToQuantum(*p),q);
3845 case MagentaQuantum:
3847 SetPixelGreen(image,ScaleShortToQuantum(*p),q);
3853 SetPixelBlue(image,ScaleShortToQuantum(*p),q);
3858 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3861 case OpacityQuantum:
3863 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3868 SetPixelBlack(image,ScaleShortToQuantum(*p),q);
3873 SetPixelGray(image,ScaleShortToQuantum(*p),q);
3881 q+=GetPixelChannels(image);
3883 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3888 MagickExport MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
3889 const ssize_t y,const size_t width,const size_t height,const char *map,
3890 const StorageType type,const void *pixels,ExceptionInfo *exception)
3905 Allocate image structure.
3907 assert(image != (Image *) NULL);
3908 assert(image->signature == MagickSignature);
3909 if (image->debug != MagickFalse)
3910 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3912 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
3913 if (quantum_map == (QuantumType *) NULL)
3914 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
3916 for (i=0; i < (ssize_t) length; i++)
3923 quantum_map[i]=AlphaQuantum;
3924 image->alpha_trait=BlendPixelTrait;
3930 quantum_map[i]=BlueQuantum;
3936 quantum_map[i]=CyanQuantum;
3937 (void) SetImageColorspace(image,CMYKColorspace,exception);
3943 quantum_map[i]=GreenQuantum;
3949 quantum_map[i]=BlackQuantum;
3950 (void) SetImageColorspace(image,CMYKColorspace,exception);
3956 quantum_map[i]=IndexQuantum;
3957 (void) SetImageColorspace(image,GRAYColorspace,exception);
3963 quantum_map[i]=MagentaQuantum;
3964 (void) SetImageColorspace(image,CMYKColorspace,exception);
3970 quantum_map[i]=OpacityQuantum;
3971 image->alpha_trait=BlendPixelTrait;
3977 quantum_map[i]=UndefinedQuantum;
3983 quantum_map[i]=RedQuantum;
3989 quantum_map[i]=YellowQuantum;
3990 (void) SetImageColorspace(image,CMYKColorspace,exception);
3995 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3996 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3997 "UnrecognizedPixelMap","`%s'",map);
3998 return(MagickFalse);
4002 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
4003 return(MagickFalse);
4005 Transfer the pixels from the pixel data to the image.
4015 ImportCharPixel(image,&roi,map,quantum_map,pixels,exception);
4020 ImportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
4025 ImportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
4030 ImportLongPixel(image,&roi,map,quantum_map,pixels,exception);
4035 ImportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
4040 ImportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
4045 ImportShortPixel(image,&roi,map,quantum_map,pixels,exception);
4050 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4051 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4052 "UnrecognizedPixelMap","`%s'",map);
4056 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4061 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4065 + 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 %
4069 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4071 % InitializePixelChannelMap() defines the standard pixel component map.
4073 % The format of the InitializePixelChannelMap() method is:
4075 % void InitializePixelChannelMap(Image *image)
4077 % A description of each parameter follows:
4079 % o image: the image.
4082 MagickExport void InitializePixelChannelMap(Image *image)
4093 assert(image != (Image *) NULL);
4094 assert(image->signature == MagickSignature);
4095 (void) ResetMagickMemory(image->channel_map,0,MaxPixelChannels*
4096 sizeof(*image->channel_map));
4097 trait=UpdatePixelTrait;
4098 if (image->alpha_trait == BlendPixelTrait)
4099 trait=(PixelTrait) (trait | BlendPixelTrait);
4101 if (image->colorspace == GRAYColorspace)
4103 SetPixelChannelAttributes(image,BluePixelChannel,trait,n);
4104 SetPixelChannelAttributes(image,GreenPixelChannel,trait,n);
4105 SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
4109 SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
4110 SetPixelChannelAttributes(image,GreenPixelChannel,trait,n++);
4111 SetPixelChannelAttributes(image,BluePixelChannel,trait,n++);
4113 if (image->colorspace == CMYKColorspace)
4114 SetPixelChannelAttributes(image,BlackPixelChannel,trait,n++);
4115 if (image->alpha_trait != UndefinedPixelTrait)
4116 SetPixelChannelAttributes(image,AlphaPixelChannel,CopyPixelTrait,n++);
4117 if (image->storage_class == PseudoClass)
4118 SetPixelChannelAttributes(image,IndexPixelChannel,CopyPixelTrait,n++);
4119 if (image->mask != MagickFalse)
4120 SetPixelChannelAttributes(image,MaskPixelChannel,CopyPixelTrait,n++);
4121 assert((n+image->number_meta_channels) < MaxPixelChannels);
4122 for (i=0; i < (ssize_t) image->number_meta_channels; i++)
4123 SetPixelChannelAttributes(image,(PixelChannel) (MetaPixelChannel+i),
4124 CopyPixelTrait,n++);
4125 image->number_channels=(size_t) n;
4126 if (image->debug != MagickFalse)
4127 LogPixelChannels(image);
4128 (void) SetImageChannelMask(image,image->channel_mask);
4132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4136 % I n t e r p o l a t e P i x e l C h a n n e l %
4140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4142 % InterpolatePixelChannel() applies a pixel interpolation method between a
4143 % floating point coordinate and the pixels surrounding that coordinate. No
4144 % pixel area resampling, or scaling of the result is performed.
4146 % Interpolation is restricted to just the specified channel.
4148 % The format of the InterpolatePixelChannel method is:
4150 % MagickBooleanType InterpolatePixelChannel(const Image *image,
4151 % const CacheView *image_view,const PixelChannel channel,
4152 % const PixelInterpolateMethod method,const double x,const double y,
4153 % double *pixel,ExceptionInfo *exception)
4155 % A description of each parameter follows:
4157 % o image: the image.
4159 % o image_view: the image view.
4161 % o channel: the pixel channel to interpolate.
4163 % o method: the pixel color interpolation method.
4165 % o x,y: A double representing the current (x,y) position of the pixel.
4167 % o pixel: return the interpolated pixel here.
4169 % o exception: return any errors or warnings in this structure.
4173 static inline void CatromWeights(const double x,double (*weights)[4])
4181 Nicolas Robidoux' 10 flops (4* + 5- + 1+) refactoring of the computation
4182 of the standard four 1D Catmull-Rom weights. The sampling location is
4183 assumed between the second and third input pixel locations, and x is the
4184 position relative to the second input pixel location. Formulas originally
4185 derived for the VIPS (Virtual Image Processing System) library.
4187 alpha=(double) 1.0-x;
4188 beta=(double) (-0.5)*x*alpha;
4189 (*weights)[0]=alpha*beta;
4190 (*weights)[3]=x*beta;
4192 The following computation of the inner weights from the outer ones work
4193 for all Keys cubics.
4195 gamma=(*weights)[3]-(*weights)[0];
4196 (*weights)[1]=alpha-(*weights)[0]+gamma;
4197 (*weights)[2]=x-(*weights)[3]-gamma;
4200 static inline void SplineWeights(const double x,double (*weights)[4])
4207 Nicolas Robidoux' 12 flops (6* + 5- + 1+) refactoring of the
4208 computation of the standard four 1D cubic B-spline smoothing
4209 weights. The sampling location is assumed between the second and
4210 third input pixel locations, and x is the position relative to the
4211 second input pixel location.
4213 alpha=(double) 1.0-x;
4214 (*weights)[3]=(double) (1.0/6.0)*x*x*x;
4215 (*weights)[0]=(double) (1.0/6.0)*alpha*alpha*alpha;
4216 beta=(*weights)[3]-(*weights)[0];
4217 (*weights)[1]=alpha-(*weights)[0]+beta;
4218 (*weights)[2]=x-(*weights)[3]-beta;
4221 static inline double MeshInterpolate(const PointInfo *delta,const double p,
4222 const double x,const double y)
4224 return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
4228 static inline ssize_t NearestNeighbor(const double x)
4231 return((ssize_t) (x+0.5));
4232 return((ssize_t) (x-0.5));
4236 MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
4237 const CacheView *image_view,const PixelChannel channel,
4238 const PixelInterpolateMethod method,const double x,const double y,
4239 double *pixel,ExceptionInfo *exception)
4252 register const Quantum
4262 PixelInterpolateMethod
4265 assert(image != (Image *) NULL);
4266 assert(image != (Image *) NULL);
4267 assert(image->signature == MagickSignature);
4268 assert(image_view != (CacheView *) NULL);
4271 traits=GetPixelChannelTraits(image,channel);
4272 x_offset=(ssize_t) floor(x);
4273 y_offset=(ssize_t) floor(y);
4274 interpolate = method;
4275 if ( interpolate == UndefinedInterpolatePixel )
4276 interpolate = image->interpolate;
4277 switch (interpolate)
4279 case AverageInterpolatePixel: /* nearest 4 neighbours */
4280 case Average9InterpolatePixel: /* nearest 9 neighbours */
4281 case Average16InterpolatePixel: /* nearest 16 neighbours */
4286 count=2; /* size of the area to average - default nearest 4 */
4287 if (interpolate == Average9InterpolatePixel)
4290 x_offset=(ssize_t) (floor(x+0.5)-1);
4291 y_offset=(ssize_t) (floor(y+0.5)-1);
4294 if (interpolate == Average16InterpolatePixel)
4300 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,(size_t) count,(size_t)
4302 if (p == (const Quantum *) NULL)
4307 count*=count; /* Number of pixels to Average */
4308 if ((traits & BlendPixelTrait) == 0)
4309 for (i=0; i < (ssize_t) count; i++)
4312 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4315 for (i=0; i < (ssize_t) count; i++)
4317 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4318 GetPixelChannels(image));
4319 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4321 for (i=0; i < (ssize_t) count; i++)
4323 gamma=PerceptibleReciprocal(alpha[i])/count;
4324 *pixel+=gamma*pixels[i];
4328 case BilinearInterpolatePixel:
4335 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4336 if (p == (const Quantum *) NULL)
4341 if ((traits & BlendPixelTrait) == 0)
4342 for (i=0; i < 4; i++)
4345 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4348 for (i=0; i < 4; i++)
4350 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4351 GetPixelChannels(image));
4352 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4356 epsilon.x=1.0-delta.x;
4357 epsilon.y=1.0-delta.y;
4358 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4359 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4360 gamma=PerceptibleReciprocal(gamma);
4361 *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
4362 (epsilon.x*pixels[2]+delta.x*pixels[3]));
4365 case BlendInterpolatePixel:
4367 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4368 if (p == (const Quantum *) NULL)
4373 if ((traits & BlendPixelTrait) == 0)
4374 for (i=0; i < 4; i++)
4377 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4380 for (i=0; i < 4; i++)
4382 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4383 GetPixelChannels(image));
4384 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4386 gamma=1.0; /* number of pixels blended together (its variable) */
4387 for (i=0; i <= 1L; i++) {
4388 if ((y-y_offset) >= 0.75)
4390 alpha[i]=alpha[i+2]; /* take right pixels */
4391 pixels[i]=pixels[i+2];
4394 if ((y-y_offset) > 0.25)
4396 gamma=2.0; /* blend both pixels in row */
4397 alpha[i]+=alpha[i+2]; /* add up alpha weights */
4398 pixels[i]+=pixels[i+2];
4401 if ((x-x_offset) >= 0.75)
4403 alpha[0]=alpha[1]; /* take bottom row blend */
4404 pixels[0]=pixels[1];
4407 if ((x-x_offset) > 0.25)
4409 gamma*=2.0; /* blend both rows */
4410 alpha[0]+=alpha[1]; /* add up alpha weights */
4411 pixels[0]+=pixels[1];
4413 if (channel != AlphaPixelChannel)
4414 gamma=PerceptibleReciprocal(alpha[0]); /* (color) 1/alpha_weights */
4416 gamma=PerceptibleReciprocal(gamma); /* (alpha) 1/number_of_pixels */
4417 *pixel=gamma*pixels[0];
4420 case CatromInterpolatePixel:
4426 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4428 if (p == (const Quantum *) NULL)
4433 if ((traits & BlendPixelTrait) == 0)
4434 for (i=0; i < 16; i++)
4437 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4440 for (i=0; i < 16; i++)
4442 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4443 GetPixelChannels(image));
4444 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4446 CatromWeights((double) (x-x_offset),&cx);
4447 CatromWeights((double) (y-y_offset),&cy);
4448 gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4449 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4450 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4451 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4452 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4453 cx[2]*alpha[14]+cx[3]*alpha[15])));
4454 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4455 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4456 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4457 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4458 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4462 /* deprecated useless and very slow interpolator */
4463 case FilterInterpolatePixel:
4477 geometry.x=x_offset-1;
4478 geometry.y=y_offset-1;
4479 excerpt_image=ExcerptImage(image,&geometry,exception);
4480 if (excerpt_image == (Image *) NULL)
4485 filter_image=ResizeImage(excerpt_image,1,1,image->filter,exception);
4486 excerpt_image=DestroyImage(excerpt_image);
4487 if (filter_image == (Image *) NULL)
4489 filter_view=AcquireVirtualCacheView(filter_image,exception);
4490 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4491 if (p == (const Quantum *) NULL)
4494 *pixel=(double) GetPixelChannel(image,channel,p);
4495 filter_view=DestroyCacheView(filter_view);
4496 filter_image=DestroyImage(filter_image);
4500 case IntegerInterpolatePixel:
4502 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4503 if (p == (const Quantum *) NULL)
4508 *pixel=(double) GetPixelChannel(image,channel,p);
4511 case NearestInterpolatePixel:
4513 x_offset=(ssize_t) floor(x+0.5);
4514 y_offset=(ssize_t) floor(y+0.5);
4515 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4516 if (p == (const Quantum *) NULL)
4521 *pixel=(double) GetPixelChannel(image,channel,p);
4524 case MeshInterpolatePixel:
4530 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4531 if (p == (const Quantum *) NULL)
4536 if ((traits & BlendPixelTrait) == 0)
4537 for (i=0; i < 4; i++)
4540 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4543 for (i=0; i < 4; i++)
4545 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4546 GetPixelChannels(image));
4547 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4551 luminance.x=GetPixelLuminance(image,p)-(double)
4552 GetPixelLuminance(image,p+3*GetPixelChannels(image));
4553 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
4554 GetPixelLuminance(image,p+2*GetPixelChannels(image));
4555 if (fabs(luminance.x) < fabs(luminance.y))
4560 if (delta.x <= delta.y)
4563 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4565 delta.y=1.0-delta.y;
4566 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4567 gamma=PerceptibleReciprocal(gamma);
4568 *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
4574 Top-right triangle (pixel: 1, diagonal: 0-3).
4576 delta.x=1.0-delta.x;
4577 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4578 gamma=PerceptibleReciprocal(gamma);
4579 *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
4588 if (delta.x <= (1.0-delta.y))
4591 Top-left triangle (pixel: 0, diagonal: 1-2).
4593 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4594 gamma=PerceptibleReciprocal(gamma);
4595 *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
4601 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4603 delta.x=1.0-delta.x;
4604 delta.y=1.0-delta.y;
4605 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4606 gamma=PerceptibleReciprocal(gamma);
4607 *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
4613 case SplineInterpolatePixel:
4619 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4621 if (p == (const Quantum *) NULL)
4626 if ((traits & BlendPixelTrait) == 0)
4627 for (i=0; i < 16; i++)
4630 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4633 for (i=0; i < 16; i++)
4635 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4636 GetPixelChannels(image));
4637 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4639 SplineWeights((double) (x-x_offset),&cx);
4640 SplineWeights((double) (y-y_offset),&cy);
4641 gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4642 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4643 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4644 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4645 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4646 cx[2]*alpha[14]+cx[3]*alpha[15])));
4647 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4648 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4649 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4650 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4651 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4663 % I n t e r p o l a t e P i x e l C h a n n e l s %
4667 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4669 % InterpolatePixelChannels() applies a pixel interpolation method between a
4670 % floating point coordinate and the pixels surrounding that coordinate. No
4671 % pixel area resampling, or scaling of the result is performed.
4673 % Interpolation is restricted to just the current channel setting of the
4674 % destination image into which the color is to be stored
4676 % The format of the InterpolatePixelChannels method is:
4678 % MagickBooleanType InterpolatePixelChannels(const Image *source,
4679 % const CacheView *source_view,const Image *destination,
4680 % const PixelInterpolateMethod method,const double x,const double y,
4681 % Quantum *pixel,ExceptionInfo *exception)
4683 % A description of each parameter follows:
4685 % o source: the source.
4687 % o source_view: the source view.
4689 % o destination: the destination image, for the interpolated color
4691 % o method: the pixel color interpolation method.
4693 % o x,y: A double representing the current (x,y) position of the pixel.
4695 % o pixel: return the interpolated pixel here.
4697 % o exception: return any errors or warnings in this structure.
4700 MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
4701 const CacheView *source_view,const Image *destination,
4702 const PixelInterpolateMethod method,const double x,const double y,
4703 Quantum *pixel,ExceptionInfo *exception)
4713 register const Quantum
4723 PixelInterpolateMethod
4726 assert(source != (Image *) NULL);
4727 assert(source != (Image *) NULL);
4728 assert(source->signature == MagickSignature);
4729 assert(source_view != (CacheView *) NULL);
4731 x_offset=(ssize_t) floor(x);
4732 y_offset=(ssize_t) floor(y);
4733 interpolate = method;
4734 if ( interpolate == UndefinedInterpolatePixel )
4735 interpolate = source->interpolate;
4736 switch (interpolate)
4738 case AverageInterpolatePixel: /* nearest 4 neighbours */
4739 case Average9InterpolatePixel: /* nearest 9 neighbours */
4740 case Average16InterpolatePixel: /* nearest 16 neighbours */
4745 count=2; /* size of the area to average - default nearest 4 */
4746 if (interpolate == Average9InterpolatePixel)
4749 x_offset=(ssize_t) (floor(x+0.5)-1);
4750 y_offset=(ssize_t) (floor(y+0.5)-1);
4753 if (interpolate == Average16InterpolatePixel)
4759 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,(size_t) count,(size_t)
4761 if (p == (const Quantum *) NULL)
4766 count*=count; /* Number of pixels to Average */
4767 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4775 PixelChannel channel=GetPixelChannelChannel(source,i);
4776 PixelTrait traits=GetPixelChannelTraits(source,channel);
4777 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4779 if ((traits == UndefinedPixelTrait) ||
4780 (destination_traits == UndefinedPixelTrait))
4782 for (j=0; j < (ssize_t) count; j++)
4783 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
4785 if ((traits & BlendPixelTrait) == 0)
4787 for (j=0; j < (ssize_t) count; j++)
4790 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4793 for (j=0; j < (ssize_t) count; j++)
4795 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4796 GetPixelChannels(source));
4797 pixels[j]*=alpha[j];
4798 gamma=PerceptibleReciprocal(alpha[j]);
4799 sum+=gamma*pixels[j];
4802 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4806 case BilinearInterpolatePixel:
4809 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4810 if (p == (const Quantum *) NULL)
4815 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4821 PixelChannel channel=GetPixelChannelChannel(source,i);
4822 PixelTrait traits=GetPixelChannelTraits(source,channel);
4823 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4825 if ((traits == UndefinedPixelTrait) ||
4826 (destination_traits == UndefinedPixelTrait))
4830 epsilon.x=1.0-delta.x;
4831 epsilon.y=1.0-delta.y;
4832 pixels[0]=(double) p[i];
4833 pixels[1]=(double) p[GetPixelChannels(source)+i];
4834 pixels[2]=(double) p[2*GetPixelChannels(source)+i];
4835 pixels[3]=(double) p[3*GetPixelChannels(source)+i];
4836 if ((traits & BlendPixelTrait) == 0)
4838 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
4839 gamma=PerceptibleReciprocal(gamma);
4840 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4841 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*
4842 pixels[2]+delta.x*pixels[3]))),pixel);
4845 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4846 alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source));
4847 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4848 GetPixelChannels(source));
4849 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4850 GetPixelChannels(source));
4851 pixels[0]*=alpha[0];
4852 pixels[1]*=alpha[1];
4853 pixels[2]*=alpha[2];
4854 pixels[3]*=alpha[3];
4855 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4856 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4857 gamma=PerceptibleReciprocal(gamma);
4858 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4859 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+
4860 delta.x*pixels[3]))),pixel);
4864 case BlendInterpolatePixel:
4866 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4867 if (p == (const Quantum *) NULL)
4872 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4877 PixelChannel channel=GetPixelChannelChannel(source,i);
4878 PixelTrait traits=GetPixelChannelTraits(source,channel);
4879 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4881 if ((traits == UndefinedPixelTrait) ||
4882 (destination_traits == UndefinedPixelTrait))
4884 if ((traits & BlendPixelTrait) == 0)
4885 for (j=0; j < 4; j++)
4888 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+channel];
4891 for (j=0; j < 4; j++)
4893 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4894 GetPixelChannels(source));
4895 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+channel];
4897 gamma=1.0; /* number of pixels blended together (its variable) */
4898 for (j=0; j <= 1L; j++)
4900 if ((y-y_offset) >= 0.75)
4902 alpha[j]=alpha[j+2]; /* take right pixels */
4903 pixels[j]=pixels[j+2];
4906 if ((y-y_offset) > 0.25)
4908 gamma=2.0; /* blend both pixels in row */
4909 alpha[j]+=alpha[j+2]; /* add up alpha weights */
4910 pixels[j]+=pixels[j+2];
4913 if ((x-x_offset) >= 0.75)
4915 alpha[0]=alpha[1]; /* take bottom row blend */
4916 pixels[0]=pixels[1];
4919 if ((x-x_offset) > 0.25)
4921 gamma*=2.0; /* blend both rows */
4922 alpha[0]+=alpha[1]; /* add up alpha weights */
4923 pixels[0]+=pixels[1];
4925 if ((traits & BlendPixelTrait) == 0)
4926 gamma=PerceptibleReciprocal(alpha[0]); /* (color) 1/alpha_weights */
4928 gamma=PerceptibleReciprocal(gamma); /* (alpha) 1/number_of_pixels */
4929 SetPixelChannel(destination,channel,ClampToQuantum(gamma*pixels[0]),
4934 case CatromInterpolatePixel:
4940 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4942 if (p == (const Quantum *) NULL)
4947 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4952 PixelChannel channel=GetPixelChannelChannel(source,i);
4953 PixelTrait traits=GetPixelChannelTraits(source,channel);
4954 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4956 if ((traits == UndefinedPixelTrait) ||
4957 (destination_traits == UndefinedPixelTrait))
4959 if ((traits & BlendPixelTrait) == 0)
4960 for (j=0; j < 16; j++)
4963 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
4966 for (j=0; j < 16; j++)
4968 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4969 GetPixelChannels(source));
4970 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4972 CatromWeights((double) (x-x_offset),&cx);
4973 CatromWeights((double) (y-y_offset),&cy);
4974 gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
4975 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4976 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4977 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4978 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4979 cx[2]*alpha[14]+cx[3]*alpha[15])));
4980 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
4981 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
4982 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
4983 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
4984 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
4985 pixels[14]+cx[3]*pixels[15]))),pixel);
4990 /* deprecated useless and very slow interpolator */
4991 case FilterInterpolatePixel:
4993 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5005 PixelChannel channel=GetPixelChannelChannel(source,i);
5006 PixelTrait traits=GetPixelChannelTraits(source,channel);
5007 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5009 if ((traits == UndefinedPixelTrait) ||
5010 (destination_traits == UndefinedPixelTrait))
5014 geometry.x=x_offset-1;
5015 geometry.y=y_offset-1;
5016 excerpt_source=ExcerptImage(source,&geometry,exception);
5017 if (excerpt_source == (Image *) NULL)
5022 filter_source=ResizeImage(excerpt_source,1,1,source->filter,exception);
5023 excerpt_source=DestroyImage(excerpt_source);
5024 if (filter_source == (Image *) NULL)
5026 filter_view=AcquireVirtualCacheView(filter_source,exception);
5027 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
5028 if (p == (const Quantum *) NULL)
5032 SetPixelChannel(destination,channel,p[i],pixel);
5034 filter_view=DestroyCacheView(filter_view);
5035 filter_source=DestroyImage(filter_source);
5040 case IntegerInterpolatePixel:
5042 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
5043 if (p == (const Quantum *) NULL)
5048 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5050 PixelChannel channel=GetPixelChannelChannel(source,i);
5051 PixelTrait traits=GetPixelChannelTraits(source,channel);
5052 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5054 if ((traits == UndefinedPixelTrait) ||
5055 (destination_traits == UndefinedPixelTrait))
5057 SetPixelChannel(destination,channel,p[i],pixel);
5061 case NearestInterpolatePixel:
5063 x_offset=(ssize_t) floor(x+0.5);
5064 y_offset=(ssize_t) floor(y+0.5);
5065 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
5066 if (p == (const Quantum *) NULL)
5071 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5073 PixelChannel channel=GetPixelChannelChannel(source,i);
5074 PixelTrait traits=GetPixelChannelTraits(source,channel);
5075 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5077 if ((traits == UndefinedPixelTrait) ||
5078 (destination_traits == UndefinedPixelTrait))
5080 SetPixelChannel(destination,channel,p[i],pixel);
5084 case MeshInterpolatePixel:
5086 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
5087 if (p == (const Quantum *) NULL)
5092 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5098 PixelChannel channel=GetPixelChannelChannel(source,i);
5099 PixelTrait traits=GetPixelChannelTraits(source,channel);
5100 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5102 if ((traits == UndefinedPixelTrait) ||
5103 (destination_traits == UndefinedPixelTrait))
5105 pixels[0]=(double) p[i];
5106 pixels[1]=(double) p[GetPixelChannels(source)+i];
5107 pixels[2]=(double) p[2*GetPixelChannels(source)+i];
5108 pixels[3]=(double) p[3*GetPixelChannels(source)+i];
5109 if ((traits & BlendPixelTrait) == 0)
5118 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
5119 alpha[1]=QuantumScale*GetPixelAlpha(source,p+
5120 GetPixelChannels(source));
5121 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
5122 GetPixelChannels(source));
5123 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
5124 GetPixelChannels(source));
5128 luminance.x=fabs((double) (GetPixelLuminance(source,p)-
5129 GetPixelLuminance(source,p+3*GetPixelChannels(source))));
5130 luminance.y=fabs((double) (GetPixelLuminance(source,p+
5131 GetPixelChannels(source))-GetPixelLuminance(source,p+2*
5132 GetPixelChannels(source))));
5133 if (luminance.x < luminance.y)
5138 if (delta.x <= delta.y)
5141 Bottom-left triangle (pixel: 2, diagonal: 0-3).
5143 delta.y=1.0-delta.y;
5144 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5145 gamma=PerceptibleReciprocal(gamma);
5146 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5147 MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel);
5152 Top-right triangle (pixel: 1, diagonal: 0-3).
5154 delta.x=1.0-delta.x;
5155 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5156 gamma=PerceptibleReciprocal(gamma);
5157 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5158 MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel);
5166 if (delta.x <= (1.0-delta.y))
5169 Top-left triangle (pixel: 0, diagonal: 1-2).
5171 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5172 gamma=PerceptibleReciprocal(gamma);
5173 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5174 MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel);
5179 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5181 delta.x=1.0-delta.x;
5182 delta.y=1.0-delta.y;
5183 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5184 gamma=PerceptibleReciprocal(gamma);
5185 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5186 MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel);
5192 case SplineInterpolatePixel:
5198 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
5200 if (p == (const Quantum *) NULL)
5205 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5210 PixelChannel channel=GetPixelChannelChannel(source,i);
5211 PixelTrait traits=GetPixelChannelTraits(source,channel);
5212 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5214 if ((traits == UndefinedPixelTrait) ||
5215 (destination_traits == UndefinedPixelTrait))
5217 if ((traits & BlendPixelTrait) == 0)
5218 for (j=0; j < 16; j++)
5221 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
5224 for (j=0; j < 16; j++)
5226 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
5227 GetPixelChannels(source));
5228 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
5230 SplineWeights((double) (x-x_offset),&cx);
5231 SplineWeights((double) (y-y_offset),&cy);
5232 gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
5233 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
5234 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
5235 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
5236 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
5237 cx[2]*alpha[14]+cx[3]*alpha[15])));
5238 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
5239 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
5240 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
5241 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
5242 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
5243 pixels[14]+cx[3]*pixels[15]))),pixel);
5252 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5256 % I n t e r p o l a t e P i x e l I n f o %
5260 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5262 % InterpolatePixelInfo() applies a pixel interpolation method between a
5263 % floating point coordinate and the pixels surrounding that coordinate. No
5264 % pixel area resampling, or scaling of the result is performed.
5266 % Interpolation is restricted to just RGBKA channels.
5268 % The format of the InterpolatePixelInfo method is:
5270 % MagickBooleanType InterpolatePixelInfo(const Image *image,
5271 % const CacheView *image_view,const PixelInterpolateMethod method,
5272 % const double x,const double y,PixelInfo *pixel,
5273 % ExceptionInfo *exception)
5275 % A description of each parameter follows:
5277 % o image: the image.
5279 % o image_view: the image view.
5281 % o method: the pixel color interpolation method.
5283 % o x,y: A double representing the current (x,y) position of the pixel.
5285 % o pixel: return the interpolated pixel here.
5287 % o exception: return any errors or warnings in this structure.
5291 static inline void AlphaBlendPixelInfo(const Image *image,
5292 const Quantum *pixel,PixelInfo *pixel_info,double *alpha)
5294 if (image->alpha_trait != BlendPixelTrait)
5297 pixel_info->red=(double) GetPixelRed(image,pixel);
5298 pixel_info->green=(double) GetPixelGreen(image,pixel);
5299 pixel_info->blue=(double) GetPixelBlue(image,pixel);
5300 pixel_info->black=0.0;
5301 if (image->colorspace == CMYKColorspace)
5302 pixel_info->black=(double) GetPixelBlack(image,pixel);
5303 pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5306 *alpha=QuantumScale*GetPixelAlpha(image,pixel);
5307 pixel_info->red=(*alpha*GetPixelRed(image,pixel));
5308 pixel_info->green=(*alpha*GetPixelGreen(image,pixel));
5309 pixel_info->blue=(*alpha*GetPixelBlue(image,pixel));
5310 pixel_info->black=0.0;
5311 if (image->colorspace == CMYKColorspace)
5312 pixel_info->black=(*alpha*GetPixelBlack(image,pixel));
5313 pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5316 MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
5317 const CacheView *image_view,const PixelInterpolateMethod method,
5318 const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception)
5330 register const Quantum
5340 PixelInterpolateMethod
5343 assert(image != (Image *) NULL);
5344 assert(image->signature == MagickSignature);
5345 assert(image_view != (CacheView *) NULL);
5347 x_offset=(ssize_t) floor(x);
5348 y_offset=(ssize_t) floor(y);
5349 interpolate = method;
5350 if ( interpolate == UndefinedInterpolatePixel )
5351 interpolate = image->interpolate;
5352 switch (interpolate)
5354 case AverageInterpolatePixel: /* nearest 4 neighbours */
5355 case Average9InterpolatePixel: /* nearest 9 neighbours */
5356 case Average16InterpolatePixel: /* nearest 16 neighbours */
5361 count=2; /* size of the area to average - default nearest 4 */
5362 if (interpolate == Average9InterpolatePixel)
5365 x_offset=(ssize_t) (floor(x+0.5)-1);
5366 y_offset=(ssize_t) (floor(y+0.5)-1);
5368 else if (interpolate == Average16InterpolatePixel)
5374 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,(size_t) count,(size_t)
5376 if (p == (const Quantum *) NULL)
5386 count*=count; /* number of pixels - square of size */
5387 for (i=0; i < (ssize_t) count; i++)
5389 AlphaBlendPixelInfo(image,p,pixels,alpha);
5390 gamma=PerceptibleReciprocal(alpha[0]);
5391 pixel->red+=gamma*pixels[0].red;
5392 pixel->green+=gamma*pixels[0].green;
5393 pixel->blue+=gamma*pixels[0].blue;
5394 pixel->black+=gamma*pixels[0].black;
5395 pixel->alpha+=pixels[0].alpha;
5396 p += GetPixelChannels(image);
5398 gamma=1.0/count; /* average weighting of each pixel in area */
5400 pixel->green*=gamma;
5402 pixel->black*=gamma;
5403 pixel->alpha*=gamma;
5406 case BackgroundInterpolatePixel:
5408 *pixel=image->background_color; /* Copy PixelInfo Structure */
5411 case BilinearInterpolatePixel:
5418 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5419 if (p == (const Quantum *) NULL)
5424 for (i=0; i < 4L; i++)
5425 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5428 epsilon.x=1.0-delta.x;
5429 epsilon.y=1.0-delta.y;
5430 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5431 (epsilon.x*alpha[2]+delta.x*alpha[3])));
5432 gamma=PerceptibleReciprocal(gamma);
5433 pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
5434 pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red));
5435 pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x*
5436 pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x*
5438 pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x*
5439 pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x*
5441 if (image->colorspace == CMYKColorspace)
5442 pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x*
5443 pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x*
5445 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5446 gamma=PerceptibleReciprocal(gamma);
5447 pixel->alpha=(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x*
5448 pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x*
5452 case BlendInterpolatePixel:
5454 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5455 if (p == (const Quantum *) NULL)
5460 for (i=0; i < 4L; i++)
5461 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5462 gamma=1.0; /* number of pixels blended together (its variable) */
5463 for (i=0; i <= 1L; i++)
5465 if ((y-y_offset) >= 0.75)
5467 alpha[i]=alpha[i+2]; /* take right pixels */
5468 pixels[i]=pixels[i+2];
5471 if ((y-y_offset) > 0.25)
5473 gamma=2.0; /* blend both pixels in row */
5474 alpha[i]+=alpha[i+2]; /* add up alpha weights */
5475 pixels[i].red+=pixels[i+2].red;
5476 pixels[i].green+=pixels[i+2].green;
5477 pixels[i].blue+=pixels[i+2].blue;
5478 pixels[i].black+=pixels[i+2].black;
5479 pixels[i].alpha+=pixels[i+2].alpha;
5482 if ((x-x_offset) >= 0.75)
5485 pixels[0]=pixels[1];
5488 if ((x-x_offset) > 0.25)
5490 gamma*=2.0; /* blend both rows */
5491 alpha[0]+= alpha[1]; /* add up alpha weights */
5492 pixels[0].red+=pixels[1].red;
5493 pixels[0].green+=pixels[1].green;
5494 pixels[0].blue+=pixels[1].blue;
5495 pixels[0].black+=pixels[1].black;
5496 pixels[0].alpha+=pixels[1].alpha;
5499 alpha[0]=PerceptibleReciprocal(alpha[0]);
5500 pixel->red=alpha[0]*pixels[0].red;
5501 pixel->green=alpha[0]*pixels[0].green; /* divide by sum of alpha */
5502 pixel->blue=alpha[0]*pixels[0].blue;
5503 pixel->black=alpha[0]*pixels[0].black;
5504 pixel->alpha=gamma*pixels[0].alpha; /* divide by number of pixels */
5507 case CatromInterpolatePixel:
5513 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5515 if (p == (const Quantum *) NULL)
5520 for (i=0; i < 16L; i++)
5521 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5522 CatromWeights((double) (x-x_offset),&cx);
5523 CatromWeights((double) (y-y_offset),&cy);
5524 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]*
5525 pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5526 pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]*
5527 pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5528 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]*
5529 pixels[14].red+cx[3]*pixels[15].red));
5530 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]*
5531 pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+
5532 cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+
5533 cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]*
5534 pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]*
5535 pixels[12].green+cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]*
5537 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]*
5538 pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5539 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]*
5540 pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5541 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+
5542 cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5543 if (image->colorspace == CMYKColorspace)
5544 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]*
5545 pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+
5546 cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+
5547 cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]*
5548 pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]*
5549 pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]*
5551 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]*
5552 pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+
5553 cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+
5554 cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]*
5555 pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+
5556 cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5560 /* deprecated useless and very slow interpolator */
5561 case FilterInterpolatePixel:
5575 geometry.x=x_offset-1;
5576 geometry.y=y_offset-1;
5577 excerpt_image=ExcerptImage(image,&geometry,exception);
5578 if (excerpt_image == (Image *) NULL)
5583 filter_image=ResizeImage(excerpt_image,1,1,image->filter,exception);
5584 excerpt_image=DestroyImage(excerpt_image);
5585 if (filter_image == (Image *) NULL)
5587 filter_view=AcquireVirtualCacheView(filter_image,exception);
5588 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
5589 if (p != (const Quantum *) NULL)
5590 GetPixelInfoPixel(image,p,pixel);
5591 filter_view=DestroyCacheView(filter_view);
5592 filter_image=DestroyImage(filter_image);
5596 case IntegerInterpolatePixel:
5598 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5599 if (p == (const Quantum *) NULL)
5604 GetPixelInfoPixel(image,p,pixel);
5607 case MeshInterpolatePixel:
5613 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5614 if (p == (const Quantum *) NULL)
5621 luminance.x=GetPixelLuminance(image,p)-(double)
5622 GetPixelLuminance(image,p+3*GetPixelChannels(image));
5623 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
5624 GetPixelLuminance(image,p+2*GetPixelChannels(image));
5625 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5626 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5627 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5628 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5629 if (fabs(luminance.x) < fabs(luminance.y))
5634 if (delta.x <= delta.y)
5637 Bottom-left triangle (pixel: 2, diagonal: 0-3).
5639 delta.y=1.0-delta.y;
5640 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5641 gamma=PerceptibleReciprocal(gamma);
5642 pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red,
5643 pixels[3].red,pixels[0].red);
5644 pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green,
5645 pixels[3].green,pixels[0].green);
5646 pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
5647 pixels[3].blue,pixels[0].blue);
5648 if (image->colorspace == CMYKColorspace)
5649 pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black,
5650 pixels[3].black,pixels[0].black);
5651 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5652 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha,
5653 pixels[3].alpha,pixels[0].alpha);
5658 Top-right triangle (pixel:1 , diagonal: 0-3).
5660 delta.x=1.0-delta.x;
5661 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5662 gamma=PerceptibleReciprocal(gamma);
5663 pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red,
5664 pixels[0].red,pixels[3].red);
5665 pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green,
5666 pixels[0].green,pixels[3].green);
5667 pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
5668 pixels[0].blue,pixels[3].blue);
5669 if (image->colorspace == CMYKColorspace)
5670 pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black,
5671 pixels[0].black,pixels[3].black);
5672 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5673 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha,
5674 pixels[0].alpha,pixels[3].alpha);
5682 if (delta.x <= (1.0-delta.y))
5685 Top-left triangle (pixel: 0, diagonal: 1-2).
5687 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5688 gamma=PerceptibleReciprocal(gamma);
5689 pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red,
5690 pixels[1].red,pixels[2].red);
5691 pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green,
5692 pixels[1].green,pixels[2].green);
5693 pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
5694 pixels[1].blue,pixels[2].blue);
5695 if (image->colorspace == CMYKColorspace)
5696 pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black,
5697 pixels[1].black,pixels[2].black);
5698 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5699 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha,
5700 pixels[1].alpha,pixels[2].alpha);
5705 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5707 delta.x=1.0-delta.x;
5708 delta.y=1.0-delta.y;
5709 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5710 gamma=PerceptibleReciprocal(gamma);
5711 pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red,
5712 pixels[2].red,pixels[1].red);
5713 pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green,
5714 pixels[2].green,pixels[1].green);
5715 pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
5716 pixels[2].blue,pixels[1].blue);
5717 if (image->colorspace == CMYKColorspace)
5718 pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black,
5719 pixels[2].black,pixels[1].black);
5720 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5721 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha,
5722 pixels[2].alpha,pixels[1].alpha);
5727 case NearestInterpolatePixel:
5729 x_offset=(ssize_t) floor(x+0.5);
5730 y_offset=(ssize_t) floor(y+0.5);
5731 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5732 if (p == (const Quantum *) NULL)
5737 GetPixelInfoPixel(image,p,pixel);
5740 case SplineInterpolatePixel:
5746 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5748 if (p == (const Quantum *) NULL)
5753 for (i=0; i < 16L; i++)
5754 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5755 SplineWeights((double) (x-x_offset),&cx);
5756 SplineWeights((double) (y-y_offset),&cy);
5757 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]*
5758 pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5759 pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]*
5760 pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5761 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]*
5762 pixels[14].red+cx[3]*pixels[15].red));
5763 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]*
5764 pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+
5765 cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+
5766 cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]*
5767 pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]*pixels[12].green+
5768 cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]*pixels[15].green));
5769 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]*
5770 pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5771 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]*
5772 pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5773 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+
5774 cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5775 if (image->colorspace == CMYKColorspace)
5776 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]*
5777 pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+
5778 cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+
5779 cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]*
5780 pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]*
5781 pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]*
5783 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]*
5784 pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+
5785 cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+
5786 cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]*
5787 pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+
5788 cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5796 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5800 + I s F u z z y E q u i v a l e n c e P i x e l %
5804 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5806 % IsFuzzyEquivalencePixel() returns MagickTrue if the distance between two
5807 % pixels is less than the specified distance in a linear three (or four)u
5808 % dimensional color space.
5810 % The format of the IsFuzzyEquivalencePixel method is:
5812 % void IsFuzzyEquivalencePixel(const Image *source,const Quantum *p,
5813 % const Image *destination,const Quantum *q)
5815 % A description of each parameter follows:
5817 % o source: the source image.
5821 % o destination: the destination image.
5826 MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *source,
5827 const Quantum *p,const Image *destination,const Quantum *q)
5837 fuzz=MagickMax(source->fuzz,(double) MagickSQ1_2)*MagickMax(
5838 destination->fuzz,(double) MagickSQ1_2);
5841 if (source->alpha_trait == BlendPixelTrait)
5844 Transparencies are involved - set alpha distance
5846 pixel=GetPixelAlpha(source,p)-(double) GetPixelAlpha(destination,q);
5847 distance=pixel*pixel;
5848 if (distance > fuzz)
5849 return(MagickFalse);
5851 Generate a alpha scaling factor to generate a 4D cone on colorspace
5852 Note that if one color is transparent, distance has no color component.
5854 scale=QuantumScale*GetPixelAlpha(source,p);
5855 scale*=QuantumScale*GetPixelAlpha(destination,q);
5856 if (scale <= MagickEpsilon)
5860 RGB or CMY color cube
5862 distance*=3.0; /* rescale appropriately */
5864 pixel=GetPixelRed(source,p)-(double) GetPixelRed(destination,q);
5865 if ((source->colorspace == HSLColorspace) ||
5866 (source->colorspace == HSBColorspace) ||
5867 (source->colorspace == HWBColorspace))
5870 Compute an arc distance for hue. It should be a vector angle of
5871 'S'/'W' length with 'L'/'B' forming appropriate cones.
5873 if (fabs((double) pixel) > (QuantumRange/2))
5874 pixel-=QuantumRange;
5877 distance+=scale*pixel*pixel;
5878 if (distance > fuzz)
5879 return(MagickFalse);
5880 pixel=GetPixelGreen(source,p)-(double) GetPixelGreen(destination,q);
5881 distance+=scale*pixel*pixel;
5882 if (distance > fuzz)
5883 return(MagickFalse);
5884 pixel=GetPixelBlue(source,p)-(double) GetPixelBlue(destination,q);
5885 distance+=scale*pixel*pixel;
5886 if (distance > fuzz)
5887 return(MagickFalse);
5892 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5896 + 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 %
5900 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5902 % IsFuzzyEquivalencePixelInfo() returns true if the distance between two
5903 % colors is less than the specified distance in a linear three (or four)
5904 % dimensional color space.
5906 % This implements the equivalent of:
5907 % fuzz < sqrt(color_distance^2 * u.a*v.a + alpha_distance^2)
5909 % Which produces a multi-dimensional cone for that colorspace along the
5910 % transparency vector.
5912 % For example for an RGB:
5913 % color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3
5915 % See http://www.imagemagick.org/Usage/bugs/fuzz_distance/
5917 % Hue colorspace distances need more work. Hue is not a distance, it is an
5920 % A check that q is in the same color space as p should be made and the
5921 % appropriate mapping made. -- Anthony Thyssen 8 December 2010
5923 % The format of the IsFuzzyEquivalencePixelInfo method is:
5925 % MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5926 % const PixelInfo *q)
5928 % A description of each parameter follows:
5935 MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5946 if ((p->fuzz == 0.0) && (q->fuzz == 0.0))
5947 return(IsPixelInfoEquivalent(p,q));
5949 fuzz=MagickMax(q->fuzz,(double) MagickSQ1_2)*MagickMax(q->fuzz,
5950 (double) MagickSQ1_2);
5951 else if (q->fuzz == 0.0)
5952 fuzz=MagickMax(p->fuzz,(double) MagickSQ1_2)*MagickMax(p->fuzz,
5953 (double) MagickSQ1_2);
5955 fuzz=MagickMax(p->fuzz,(double) MagickSQ1_2)*MagickMax(q->fuzz,
5956 (double) MagickSQ1_2);
5959 if ((p->alpha_trait == BlendPixelTrait) || (q->alpha_trait == BlendPixelTrait))
5962 Transparencies are involved - set alpha distance.
5964 pixel=(p->alpha_trait == BlendPixelTrait ? p->alpha : OpaqueAlpha)-
5965 (q->alpha_trait == BlendPixelTrait ? q->alpha : OpaqueAlpha);
5966 distance=pixel*pixel;
5967 if (distance > fuzz)
5968 return(MagickFalse);
5970 Generate a alpha scaling factor to generate a 4D cone on colorspace.
5971 If one color is transparent, distance has no color component.
5973 if (p->alpha_trait == BlendPixelTrait)
5974 scale=(QuantumScale*p->alpha);
5975 if (q->alpha_trait == BlendPixelTrait)
5976 scale*=(QuantumScale*q->alpha);
5977 if (scale <= MagickEpsilon )
5981 CMYK create a CMY cube with a multi-dimensional cone toward black.
5983 if (p->colorspace == CMYKColorspace)
5985 pixel=p->black-q->black;
5986 distance+=pixel*pixel*scale;
5987 if (distance > fuzz)
5988 return(MagickFalse);
5989 scale*=(double) (QuantumScale*(QuantumRange-p->black));
5990 scale*=(double) (QuantumScale*(QuantumRange-q->black));
5993 RGB or CMY color cube.
5995 distance*=3.0; /* rescale appropriately */
5997 pixel=p->red-q->red;
5998 if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) ||
5999 (p->colorspace == HWBColorspace))
6002 This calculates a arc distance for hue-- it should be a vector angle
6003 of 'S'/'W' length with 'L'/'B' forming appropriate cones. In other
6004 words this is a hack - Anthony.
6006 if (fabs((double) pixel) > (QuantumRange/2))
6007 pixel-=QuantumRange;
6010 distance+=pixel*pixel*scale;
6011 if (distance > fuzz)
6012 return(MagickFalse);
6013 pixel=p->green-q->green;
6014 distance+=pixel*pixel*scale;
6015 if (distance > fuzz)
6016 return(MagickFalse);
6017 pixel=p->blue-q->blue;
6018 distance+=pixel*pixel*scale;
6019 if (distance > fuzz)
6020 return(MagickFalse);
6025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6029 % S e t P i x e l C h a n n e l M a p M a s k %
6033 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6035 % SetPixelChannelMask() sets the pixel channel map from the specified
6038 % The format of the SetPixelChannelMask method is:
6040 % void SetPixelChannelMask(Image *image,const ChannelType channel_mask)
6042 % A description of each parameter follows:
6044 % o image: the image.
6046 % o channel_mask: the channel mask.
6049 MagickExport void SetPixelChannelMask(Image *image,
6050 const ChannelType channel_mask)
6052 #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
6057 if (image->debug != MagickFalse)
6058 (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%08x]", \
6059 image->filename,channel_mask); \
6060 image->channel_mask=channel_mask;
6061 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
6063 PixelChannel channel=GetPixelChannelChannel(image,i);
6064 SetPixelChannelTraits(image,channel,
6065 GetChannelBit(channel_mask,channel) == 0 ? CopyPixelTrait :
6066 image->alpha_trait != BlendPixelTrait || (channel == AlphaPixelChannel) ?
6067 UpdatePixelTrait : (PixelTrait) (UpdatePixelTrait | image->alpha_trait));
6069 if (image->storage_class == PseudoClass)
6070 SetPixelChannelTraits(image,IndexPixelChannel,CopyPixelTrait);
6071 if (image->mask != MagickFalse)
6072 SetPixelChannelTraits(image,MaskPixelChannel,CopyPixelTrait);
6073 if (image->debug != MagickFalse)
6074 LogPixelChannels(image);
6078 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6082 % S e t P i x e l M e t a C h a n n e l s %
6086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6088 % SetPixelMetaChannels() sets the image meta channels.
6090 % The format of the SetPixelMetaChannels method is:
6092 % MagickBooleanType SetPixelMetaChannels(Image *image,
6093 % const size_t number_meta_channels,ExceptionInfo *exception)
6095 % A description of each parameter follows:
6097 % o image: the image.
6099 % o number_meta_channels: the number of meta channels.
6101 % o exception: return any errors or warnings in this structure.
6104 MagickExport MagickBooleanType SetPixelMetaChannels(Image *image,
6105 const size_t number_meta_channels,ExceptionInfo *exception)
6107 image->number_meta_channels=number_meta_channels;
6108 return(SyncImagePixelCache(image,exception));