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 % Rec709Luma 0.21260R + 0.71520G + 0.07220B
2103 % Brightness max(R, G, B)
2104 % Lightness (min(R, G, B) + max(R, G, B)) / 2.0
2105 % RMS (R^2 + G^2 + B^2) / 3.0
2106 % Average (R + G + B) / 3.0
2108 % The format of the GetPixelIntensity method is:
2110 % GetPixelIntensity(const Image *image,const Quantum *pixel)
2112 % A description of each parameter follows:
2114 % o image: the image.
2116 % o pixel: Specifies a pointer to a Quantum structure.
2120 static inline MagickRealType MagickMax(const MagickRealType x,
2121 const MagickRealType y)
2128 static inline MagickRealType MagickMin(const MagickRealType x,
2129 const MagickRealType y)
2136 MagickExport MagickRealType GetPixelIntensity(const Image *restrict image,
2137 const Quantum *restrict pixel)
2145 if (image->colorspace == GRAYColorspace)
2146 return((MagickRealType) pixel[image->channel_map[GrayPixelChannel].offset]);
2147 red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
2148 green=(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
2149 blue=(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
2150 switch (image->intensity)
2152 case Rec601LumaPixelIntensityMethod:
2155 if (image->colorspace == sRGBColorspace)
2157 red=DecodePixelGamma(red);
2158 green=DecodePixelGamma(green);
2159 blue=DecodePixelGamma(blue);
2161 intensity=0.298839f*red+0.586811f*green+0.114350f*blue;
2164 case Rec709LumaPixelIntensityMethod:
2166 if (image->colorspace == sRGBColorspace)
2168 red=DecodePixelGamma(red);
2169 green=DecodePixelGamma(green);
2170 blue=DecodePixelGamma(blue);
2172 intensity=0.21260f*red+0.71520f*green+0.07220f*blue;
2175 case BrightnessPixelIntensityMethod:
2177 if (image->colorspace == sRGBColorspace)
2179 red=DecodePixelGamma(red);
2180 green=DecodePixelGamma(green);
2181 blue=DecodePixelGamma(blue);
2183 intensity=MagickMax(MagickMax(red,green),blue);
2186 case LightnessPixelIntensityMethod:
2188 if (image->colorspace == sRGBColorspace)
2190 red=DecodePixelGamma(red);
2191 green=DecodePixelGamma(green);
2192 blue=DecodePixelGamma(blue);
2194 intensity=MagickMin(MagickMin(red,green),blue);
2197 case RMSPixelIntensityMethod:
2199 intensity=(MagickRealType) sqrt((double) red*red+green*green+blue*blue);
2202 case AveragePixelIntensityMethod:
2204 intensity=(red+green+blue)/3.0;
2212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2216 % I m p o r t I m a g e P i x e l s %
2220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2222 % ImportImagePixels() accepts pixel data and stores in the image at the
2223 % location you specify. The method returns MagickTrue on success otherwise
2224 % MagickFalse if an error is encountered. The pixel data can be either char,
2225 % Quantum, short int, unsigned int, unsigned long long, float, or double in
2226 % the order specified by map.
2228 % Suppose your want to upload the first scanline of a 640x480 image from
2229 % character data in red-green-blue order:
2231 % ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels);
2233 % The format of the ImportImagePixels method is:
2235 % MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
2236 % const ssize_t y,const size_t width,const size_t height,
2237 % const char *map,const StorageType type,const void *pixels,
2238 % ExceptionInfo *exception)
2240 % A description of each parameter follows:
2242 % o image: the image.
2244 % o x,y,width,height: These values define the perimeter
2245 % of a region of pixels you want to define.
2247 % o map: This string reflects the expected ordering of the pixel array.
2248 % It can be any combination or order of R = red, G = green, B = blue,
2249 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
2250 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
2253 % o type: Define the data type of the pixels. Float and double types are
2254 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
2255 % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *),
2256 % LongPixel (unsigned int *), LongLongPixel (unsigned long long *),
2257 % QuantumPixel (Quantum *), or ShortPixel (unsigned short *).
2259 % o pixels: This array of values contain the pixel components as defined by
2260 % map and type. You must preallocate this array where the expected
2261 % length varies depending on the values of width, height, map, and type.
2263 % o exception: return any errors or warnings in this structure.
2267 static void ImportCharPixel(Image *image,const RectangleInfo *roi,
2268 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2269 ExceptionInfo *exception)
2271 register const unsigned char
2286 p=(const unsigned char *) pixels;
2287 if (LocaleCompare(map,"BGR") == 0)
2289 for (y=0; y < (ssize_t) roi->height; y++)
2291 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2292 if (q == (Quantum *) NULL)
2294 for (x=0; x < (ssize_t) roi->width; x++)
2296 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2297 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2298 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2299 q+=GetPixelChannels(image);
2301 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2306 if (LocaleCompare(map,"BGRA") == 0)
2308 for (y=0; y < (ssize_t) roi->height; y++)
2310 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2311 if (q == (Quantum *) NULL)
2313 for (x=0; x < (ssize_t) roi->width; x++)
2315 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2316 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2317 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2318 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2319 q+=GetPixelChannels(image);
2321 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2326 if (LocaleCompare(map,"BGRO") == 0)
2328 for (y=0; y < (ssize_t) roi->height; y++)
2330 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2331 if (q == (Quantum *) NULL)
2333 for (x=0; x < (ssize_t) roi->width; x++)
2335 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2336 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2337 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2338 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2339 q+=GetPixelChannels(image);
2341 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2346 if (LocaleCompare(map,"BGRP") == 0)
2348 for (y=0; y < (ssize_t) roi->height; y++)
2350 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2351 if (q == (Quantum *) NULL)
2353 for (x=0; x < (ssize_t) roi->width; x++)
2355 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2356 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2357 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2359 q+=GetPixelChannels(image);
2361 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2366 if (LocaleCompare(map,"I") == 0)
2368 for (y=0; y < (ssize_t) roi->height; y++)
2370 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2371 if (q == (Quantum *) NULL)
2373 for (x=0; x < (ssize_t) roi->width; x++)
2375 SetPixelGray(image,ScaleCharToQuantum(*p++),q);
2376 q+=GetPixelChannels(image);
2378 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2383 if (LocaleCompare(map,"RGB") == 0)
2385 for (y=0; y < (ssize_t) roi->height; y++)
2387 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2388 if (q == (Quantum *) NULL)
2390 for (x=0; x < (ssize_t) roi->width; x++)
2392 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2393 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2394 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2395 q+=GetPixelChannels(image);
2397 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2402 if (LocaleCompare(map,"RGBA") == 0)
2404 for (y=0; y < (ssize_t) roi->height; y++)
2406 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2407 if (q == (Quantum *) NULL)
2409 for (x=0; x < (ssize_t) roi->width; x++)
2411 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2412 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2413 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2414 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2415 q+=GetPixelChannels(image);
2417 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2422 if (LocaleCompare(map,"RGBO") == 0)
2424 for (y=0; y < (ssize_t) roi->height; y++)
2426 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2427 if (q == (Quantum *) NULL)
2429 for (x=0; x < (ssize_t) roi->width; x++)
2431 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2432 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2433 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2434 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2435 q+=GetPixelChannels(image);
2437 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2442 if (LocaleCompare(map,"RGBP") == 0)
2444 for (y=0; y < (ssize_t) roi->height; y++)
2446 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2447 if (q == (Quantum *) NULL)
2449 for (x=0; x < (ssize_t) roi->width; x++)
2451 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2452 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2453 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2455 q+=GetPixelChannels(image);
2457 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2463 for (y=0; y < (ssize_t) roi->height; y++)
2465 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2466 if (q == (Quantum *) NULL)
2468 for (x=0; x < (ssize_t) roi->width; x++)
2473 for (i=0; i < (ssize_t) length; i++)
2475 switch (quantum_map[i])
2480 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2484 case MagentaQuantum:
2486 SetPixelGreen(image,ScaleCharToQuantum(*p),q);
2492 SetPixelBlue(image,ScaleCharToQuantum(*p),q);
2497 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2500 case OpacityQuantum:
2502 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2507 SetPixelBlack(image,ScaleCharToQuantum(*p),q);
2512 SetPixelGray(image,ScaleCharToQuantum(*p),q);
2520 q+=GetPixelChannels(image);
2522 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2527 static void ImportDoublePixel(Image *image,const RectangleInfo *roi,
2528 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2529 ExceptionInfo *exception)
2531 register const double
2546 p=(const double *) pixels;
2547 if (LocaleCompare(map,"BGR") == 0)
2549 for (y=0; y < (ssize_t) roi->height; y++)
2551 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2552 if (q == (Quantum *) NULL)
2554 for (x=0; x < (ssize_t) roi->width; x++)
2556 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2558 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2560 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2562 q+=GetPixelChannels(image);
2564 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2569 if (LocaleCompare(map,"BGRA") == 0)
2571 for (y=0; y < (ssize_t) roi->height; y++)
2573 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2574 if (q == (Quantum *) NULL)
2576 for (x=0; x < (ssize_t) roi->width; x++)
2578 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2580 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2582 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2584 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2586 q+=GetPixelChannels(image);
2588 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2593 if (LocaleCompare(map,"BGRP") == 0)
2595 for (y=0; y < (ssize_t) roi->height; y++)
2597 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2598 if (q == (Quantum *) NULL)
2600 for (x=0; x < (ssize_t) roi->width; x++)
2602 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2604 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2606 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2609 q+=GetPixelChannels(image);
2611 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2616 if (LocaleCompare(map,"I") == 0)
2618 for (y=0; y < (ssize_t) roi->height; y++)
2620 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2621 if (q == (Quantum *) NULL)
2623 for (x=0; x < (ssize_t) roi->width; x++)
2625 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2627 q+=GetPixelChannels(image);
2629 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2634 if (LocaleCompare(map,"RGB") == 0)
2636 for (y=0; y < (ssize_t) roi->height; y++)
2638 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2639 if (q == (Quantum *) NULL)
2641 for (x=0; x < (ssize_t) roi->width; x++)
2643 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2645 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2647 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2649 q+=GetPixelChannels(image);
2651 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2656 if (LocaleCompare(map,"RGBA") == 0)
2658 for (y=0; y < (ssize_t) roi->height; y++)
2660 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2661 if (q == (Quantum *) NULL)
2663 for (x=0; x < (ssize_t) roi->width; x++)
2665 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2667 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2669 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2671 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2673 q+=GetPixelChannels(image);
2675 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2680 if (LocaleCompare(map,"RGBP") == 0)
2682 for (y=0; y < (ssize_t) roi->height; y++)
2684 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2685 if (q == (Quantum *) NULL)
2687 for (x=0; x < (ssize_t) roi->width; x++)
2689 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2691 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2693 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2695 q+=GetPixelChannels(image);
2697 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2703 for (y=0; y < (ssize_t) roi->height; y++)
2705 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2706 if (q == (Quantum *) NULL)
2708 for (x=0; x < (ssize_t) roi->width; x++)
2713 for (i=0; i < (ssize_t) length; i++)
2715 switch (quantum_map[i])
2720 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2724 case MagentaQuantum:
2726 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2732 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2737 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2740 case OpacityQuantum:
2742 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2747 SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q);
2752 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2760 q+=GetPixelChannels(image);
2762 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2767 static void ImportFloatPixel(Image *image,const RectangleInfo *roi,
2768 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2769 ExceptionInfo *exception)
2771 register const float
2786 p=(const float *) pixels;
2787 if (LocaleCompare(map,"BGR") == 0)
2789 for (y=0; y < (ssize_t) roi->height; y++)
2791 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2792 if (q == (Quantum *) NULL)
2794 for (x=0; x < (ssize_t) roi->width; x++)
2796 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2798 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2800 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2802 q+=GetPixelChannels(image);
2804 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2809 if (LocaleCompare(map,"BGRA") == 0)
2811 for (y=0; y < (ssize_t) roi->height; y++)
2813 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2814 if (q == (Quantum *) NULL)
2816 for (x=0; x < (ssize_t) roi->width; x++)
2818 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2820 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2822 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2824 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2826 q+=GetPixelChannels(image);
2828 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2833 if (LocaleCompare(map,"BGRP") == 0)
2835 for (y=0; y < (ssize_t) roi->height; y++)
2837 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2838 if (q == (Quantum *) NULL)
2840 for (x=0; x < (ssize_t) roi->width; x++)
2842 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2844 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2846 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2849 q+=GetPixelChannels(image);
2851 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2856 if (LocaleCompare(map,"I") == 0)
2858 for (y=0; y < (ssize_t) roi->height; y++)
2860 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2861 if (q == (Quantum *) NULL)
2863 for (x=0; x < (ssize_t) roi->width; x++)
2865 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2867 q+=GetPixelChannels(image);
2869 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2874 if (LocaleCompare(map,"RGB") == 0)
2876 for (y=0; y < (ssize_t) roi->height; y++)
2878 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2879 if (q == (Quantum *) NULL)
2881 for (x=0; x < (ssize_t) roi->width; x++)
2883 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2885 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2887 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2889 q+=GetPixelChannels(image);
2891 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2896 if (LocaleCompare(map,"RGBA") == 0)
2898 for (y=0; y < (ssize_t) roi->height; y++)
2900 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2901 if (q == (Quantum *) NULL)
2903 for (x=0; x < (ssize_t) roi->width; x++)
2905 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2907 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2909 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2911 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2913 q+=GetPixelChannels(image);
2915 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2920 if (LocaleCompare(map,"RGBP") == 0)
2922 for (y=0; y < (ssize_t) roi->height; y++)
2924 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2925 if (q == (Quantum *) NULL)
2927 for (x=0; x < (ssize_t) roi->width; x++)
2929 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2931 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2933 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2935 q+=GetPixelChannels(image);
2937 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2943 for (y=0; y < (ssize_t) roi->height; y++)
2945 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2946 if (q == (Quantum *) NULL)
2948 for (x=0; x < (ssize_t) roi->width; x++)
2953 for (i=0; i < (ssize_t) length; i++)
2955 switch (quantum_map[i])
2960 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2964 case MagentaQuantum:
2966 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2972 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2977 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2980 case OpacityQuantum:
2982 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2987 SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q);
2992 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
3000 q+=GetPixelChannels(image);
3002 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3007 static void ImportLongPixel(Image *image,const RectangleInfo *roi,
3008 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3009 ExceptionInfo *exception)
3011 register const unsigned int
3026 p=(const unsigned int *) pixels;
3027 if (LocaleCompare(map,"BGR") == 0)
3029 for (y=0; y < (ssize_t) roi->height; y++)
3031 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3032 if (q == (Quantum *) NULL)
3034 for (x=0; x < (ssize_t) roi->width; x++)
3036 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3037 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3038 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3039 q+=GetPixelChannels(image);
3041 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3046 if (LocaleCompare(map,"BGRA") == 0)
3048 for (y=0; y < (ssize_t) roi->height; y++)
3050 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3051 if (q == (Quantum *) NULL)
3053 for (x=0; x < (ssize_t) roi->width; x++)
3055 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3056 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3057 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3058 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3059 q+=GetPixelChannels(image);
3061 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3066 if (LocaleCompare(map,"BGRP") == 0)
3068 for (y=0; y < (ssize_t) roi->height; y++)
3070 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3071 if (q == (Quantum *) NULL)
3073 for (x=0; x < (ssize_t) roi->width; x++)
3075 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3076 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3077 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3079 q+=GetPixelChannels(image);
3081 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3086 if (LocaleCompare(map,"I") == 0)
3088 for (y=0; y < (ssize_t) roi->height; y++)
3090 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3091 if (q == (Quantum *) NULL)
3093 for (x=0; x < (ssize_t) roi->width; x++)
3095 SetPixelGray(image,ScaleLongToQuantum(*p++),q);
3096 q+=GetPixelChannels(image);
3098 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3103 if (LocaleCompare(map,"RGB") == 0)
3105 for (y=0; y < (ssize_t) roi->height; y++)
3107 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3108 if (q == (Quantum *) NULL)
3110 for (x=0; x < (ssize_t) roi->width; x++)
3112 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3113 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3114 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3115 q+=GetPixelChannels(image);
3117 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3122 if (LocaleCompare(map,"RGBA") == 0)
3124 for (y=0; y < (ssize_t) roi->height; y++)
3126 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3127 if (q == (Quantum *) NULL)
3129 for (x=0; x < (ssize_t) roi->width; x++)
3131 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3132 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3133 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3134 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3135 q+=GetPixelChannels(image);
3137 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3142 if (LocaleCompare(map,"RGBP") == 0)
3144 for (y=0; y < (ssize_t) roi->height; y++)
3146 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3147 if (q == (Quantum *) NULL)
3149 for (x=0; x < (ssize_t) roi->width; x++)
3151 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3152 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3153 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3155 q+=GetPixelChannels(image);
3157 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3163 for (y=0; y < (ssize_t) roi->height; y++)
3165 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3166 if (q == (Quantum *) NULL)
3168 for (x=0; x < (ssize_t) roi->width; x++)
3173 for (i=0; i < (ssize_t) length; i++)
3175 switch (quantum_map[i])
3180 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3184 case MagentaQuantum:
3186 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
3192 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
3197 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3200 case OpacityQuantum:
3202 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3207 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
3212 SetPixelGray(image,ScaleLongToQuantum(*p),q);
3220 q+=GetPixelChannels(image);
3222 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3227 static void ImportLongLongPixel(Image *image,const RectangleInfo *roi,
3228 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3229 ExceptionInfo *exception)
3231 register const MagickSizeType
3246 p=(const MagickSizeType *) pixels;
3247 if (LocaleCompare(map,"BGR") == 0)
3249 for (y=0; y < (ssize_t) roi->height; y++)
3251 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3252 if (q == (Quantum *) NULL)
3254 for (x=0; x < (ssize_t) roi->width; x++)
3256 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3257 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3258 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3259 q+=GetPixelChannels(image);
3261 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3266 if (LocaleCompare(map,"BGRA") == 0)
3268 for (y=0; y < (ssize_t) roi->height; y++)
3270 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3271 if (q == (Quantum *) NULL)
3273 for (x=0; x < (ssize_t) roi->width; x++)
3275 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3276 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3277 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3278 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3279 q+=GetPixelChannels(image);
3281 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3286 if (LocaleCompare(map,"BGRP") == 0)
3288 for (y=0; y < (ssize_t) roi->height; y++)
3290 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3291 if (q == (Quantum *) NULL)
3293 for (x=0; x < (ssize_t) roi->width; x++)
3295 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3296 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3297 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3299 q+=GetPixelChannels(image);
3301 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3306 if (LocaleCompare(map,"I") == 0)
3308 for (y=0; y < (ssize_t) roi->height; y++)
3310 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3311 if (q == (Quantum *) NULL)
3313 for (x=0; x < (ssize_t) roi->width; x++)
3315 SetPixelGray(image,ScaleLongLongToQuantum(*p++),q);
3316 q+=GetPixelChannels(image);
3318 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3323 if (LocaleCompare(map,"RGB") == 0)
3325 for (y=0; y < (ssize_t) roi->height; y++)
3327 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3328 if (q == (Quantum *) NULL)
3330 for (x=0; x < (ssize_t) roi->width; x++)
3332 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3333 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3334 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3335 q+=GetPixelChannels(image);
3337 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3342 if (LocaleCompare(map,"RGBA") == 0)
3344 for (y=0; y < (ssize_t) roi->height; y++)
3346 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3347 if (q == (Quantum *) NULL)
3349 for (x=0; x < (ssize_t) roi->width; x++)
3351 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3352 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3353 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3354 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3355 q+=GetPixelChannels(image);
3357 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3362 if (LocaleCompare(map,"RGBP") == 0)
3364 for (y=0; y < (ssize_t) roi->height; y++)
3366 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3367 if (q == (Quantum *) NULL)
3369 for (x=0; x < (ssize_t) roi->width; x++)
3371 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3372 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3373 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3375 q+=GetPixelChannels(image);
3377 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3383 for (y=0; y < (ssize_t) roi->height; y++)
3385 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3386 if (q == (Quantum *) NULL)
3388 for (x=0; x < (ssize_t) roi->width; x++)
3393 for (i=0; i < (ssize_t) length; i++)
3395 switch (quantum_map[i])
3400 SetPixelRed(image,ScaleLongLongToQuantum(*p),q);
3404 case MagentaQuantum:
3406 SetPixelGreen(image,ScaleLongLongToQuantum(*p),q);
3412 SetPixelBlue(image,ScaleLongLongToQuantum(*p),q);
3417 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3420 case OpacityQuantum:
3422 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3427 SetPixelBlack(image,ScaleLongLongToQuantum(*p),q);
3432 SetPixelGray(image,ScaleLongLongToQuantum(*p),q);
3440 q+=GetPixelChannels(image);
3442 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3447 static void ImportQuantumPixel(Image *image,const RectangleInfo *roi,
3448 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3449 ExceptionInfo *exception)
3451 register const Quantum
3466 p=(const Quantum *) pixels;
3467 if (LocaleCompare(map,"BGR") == 0)
3469 for (y=0; y < (ssize_t) roi->height; y++)
3471 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3472 if (q == (Quantum *) NULL)
3474 for (x=0; x < (ssize_t) roi->width; x++)
3476 SetPixelBlue(image,*p++,q);
3477 SetPixelGreen(image,*p++,q);
3478 SetPixelRed(image,*p++,q);
3479 q+=GetPixelChannels(image);
3481 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3486 if (LocaleCompare(map,"BGRA") == 0)
3488 for (y=0; y < (ssize_t) roi->height; y++)
3490 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3491 if (q == (Quantum *) NULL)
3493 for (x=0; x < (ssize_t) roi->width; x++)
3495 SetPixelBlue(image,*p++,q);
3496 SetPixelGreen(image,*p++,q);
3497 SetPixelRed(image,*p++,q);
3498 SetPixelAlpha(image,*p++,q);
3499 q+=GetPixelChannels(image);
3501 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3506 if (LocaleCompare(map,"BGRP") == 0)
3508 for (y=0; y < (ssize_t) roi->height; y++)
3510 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3511 if (q == (Quantum *) NULL)
3513 for (x=0; x < (ssize_t) roi->width; x++)
3515 SetPixelBlue(image,*p++,q);
3516 SetPixelGreen(image,*p++,q);
3517 SetPixelRed(image,*p++,q);
3519 q+=GetPixelChannels(image);
3521 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3526 if (LocaleCompare(map,"I") == 0)
3528 for (y=0; y < (ssize_t) roi->height; y++)
3530 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3531 if (q == (Quantum *) NULL)
3533 for (x=0; x < (ssize_t) roi->width; x++)
3535 SetPixelGray(image,*p++,q);
3536 q+=GetPixelChannels(image);
3538 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3543 if (LocaleCompare(map,"RGB") == 0)
3545 for (y=0; y < (ssize_t) roi->height; y++)
3547 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3548 if (q == (Quantum *) NULL)
3550 for (x=0; x < (ssize_t) roi->width; x++)
3552 SetPixelRed(image,*p++,q);
3553 SetPixelGreen(image,*p++,q);
3554 SetPixelBlue(image,*p++,q);
3555 q+=GetPixelChannels(image);
3557 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3562 if (LocaleCompare(map,"RGBA") == 0)
3564 for (y=0; y < (ssize_t) roi->height; y++)
3566 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3567 if (q == (Quantum *) NULL)
3569 for (x=0; x < (ssize_t) roi->width; x++)
3571 SetPixelRed(image,*p++,q);
3572 SetPixelGreen(image,*p++,q);
3573 SetPixelBlue(image,*p++,q);
3574 SetPixelAlpha(image,*p++,q);
3575 q+=GetPixelChannels(image);
3577 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3582 if (LocaleCompare(map,"RGBP") == 0)
3584 for (y=0; y < (ssize_t) roi->height; y++)
3586 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3587 if (q == (Quantum *) NULL)
3589 for (x=0; x < (ssize_t) roi->width; x++)
3591 SetPixelRed(image,*p++,q);
3592 SetPixelGreen(image,*p++,q);
3593 SetPixelBlue(image,*p++,q);
3595 q+=GetPixelChannels(image);
3597 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3603 for (y=0; y < (ssize_t) roi->height; y++)
3605 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3606 if (q == (Quantum *) NULL)
3608 for (x=0; x < (ssize_t) roi->width; x++)
3613 for (i=0; i < (ssize_t) length; i++)
3615 switch (quantum_map[i])
3620 SetPixelRed(image,*p,q);
3624 case MagentaQuantum:
3626 SetPixelGreen(image,*p,q);
3632 SetPixelBlue(image,*p,q);
3637 SetPixelAlpha(image,*p,q);
3640 case OpacityQuantum:
3642 SetPixelAlpha(image,*p,q);
3647 SetPixelBlack(image,*p,q);
3652 SetPixelGray(image,*p,q);
3660 q+=GetPixelChannels(image);
3662 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3667 static void ImportShortPixel(Image *image,const RectangleInfo *roi,
3668 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3669 ExceptionInfo *exception)
3671 register const unsigned short
3686 p=(const unsigned short *) pixels;
3687 if (LocaleCompare(map,"BGR") == 0)
3689 for (y=0; y < (ssize_t) roi->height; y++)
3691 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3692 if (q == (Quantum *) NULL)
3694 for (x=0; x < (ssize_t) roi->width; x++)
3696 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3697 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3698 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3699 q+=GetPixelChannels(image);
3701 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3706 if (LocaleCompare(map,"BGRA") == 0)
3708 for (y=0; y < (ssize_t) roi->height; y++)
3710 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3711 if (q == (Quantum *) NULL)
3713 for (x=0; x < (ssize_t) roi->width; x++)
3715 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3716 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3717 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3718 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3719 q+=GetPixelChannels(image);
3721 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3726 if (LocaleCompare(map,"BGRP") == 0)
3728 for (y=0; y < (ssize_t) roi->height; y++)
3730 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3731 if (q == (Quantum *) NULL)
3733 for (x=0; x < (ssize_t) roi->width; x++)
3735 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3736 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3737 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3739 q+=GetPixelChannels(image);
3741 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3746 if (LocaleCompare(map,"I") == 0)
3748 for (y=0; y < (ssize_t) roi->height; y++)
3750 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3751 if (q == (Quantum *) NULL)
3753 for (x=0; x < (ssize_t) roi->width; x++)
3755 SetPixelGray(image,ScaleShortToQuantum(*p++),q);
3756 q+=GetPixelChannels(image);
3758 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3763 if (LocaleCompare(map,"RGB") == 0)
3765 for (y=0; y < (ssize_t) roi->height; y++)
3767 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3768 if (q == (Quantum *) NULL)
3770 for (x=0; x < (ssize_t) roi->width; x++)
3772 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3773 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3774 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3775 q+=GetPixelChannels(image);
3777 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3782 if (LocaleCompare(map,"RGBA") == 0)
3784 for (y=0; y < (ssize_t) roi->height; y++)
3786 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3787 if (q == (Quantum *) NULL)
3789 for (x=0; x < (ssize_t) roi->width; x++)
3791 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3792 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3793 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3794 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3795 q+=GetPixelChannels(image);
3797 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3802 if (LocaleCompare(map,"RGBP") == 0)
3804 for (y=0; y < (ssize_t) roi->height; y++)
3806 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3807 if (q == (Quantum *) NULL)
3809 for (x=0; x < (ssize_t) roi->width; x++)
3811 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3812 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3813 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3815 q+=GetPixelChannels(image);
3817 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3823 for (y=0; y < (ssize_t) roi->height; y++)
3825 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3826 if (q == (Quantum *) NULL)
3828 for (x=0; x < (ssize_t) roi->width; x++)
3833 for (i=0; i < (ssize_t) length; i++)
3835 switch (quantum_map[i])
3840 SetPixelRed(image,ScaleShortToQuantum(*p),q);
3844 case MagentaQuantum:
3846 SetPixelGreen(image,ScaleShortToQuantum(*p),q);
3852 SetPixelBlue(image,ScaleShortToQuantum(*p),q);
3857 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3860 case OpacityQuantum:
3862 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3867 SetPixelBlack(image,ScaleShortToQuantum(*p),q);
3872 SetPixelGray(image,ScaleShortToQuantum(*p),q);
3880 q+=GetPixelChannels(image);
3882 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3887 MagickExport MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
3888 const ssize_t y,const size_t width,const size_t height,const char *map,
3889 const StorageType type,const void *pixels,ExceptionInfo *exception)
3904 Allocate image structure.
3906 assert(image != (Image *) NULL);
3907 assert(image->signature == MagickSignature);
3908 if (image->debug != MagickFalse)
3909 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3911 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
3912 if (quantum_map == (QuantumType *) NULL)
3913 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
3915 for (i=0; i < (ssize_t) length; i++)
3922 quantum_map[i]=AlphaQuantum;
3923 image->alpha_trait=BlendPixelTrait;
3929 quantum_map[i]=BlueQuantum;
3935 quantum_map[i]=CyanQuantum;
3936 (void) SetImageColorspace(image,CMYKColorspace,exception);
3942 quantum_map[i]=GreenQuantum;
3948 quantum_map[i]=BlackQuantum;
3949 (void) SetImageColorspace(image,CMYKColorspace,exception);
3955 quantum_map[i]=IndexQuantum;
3956 (void) SetImageColorspace(image,GRAYColorspace,exception);
3962 quantum_map[i]=MagentaQuantum;
3963 (void) SetImageColorspace(image,CMYKColorspace,exception);
3969 quantum_map[i]=OpacityQuantum;
3970 image->alpha_trait=BlendPixelTrait;
3976 quantum_map[i]=UndefinedQuantum;
3982 quantum_map[i]=RedQuantum;
3988 quantum_map[i]=YellowQuantum;
3989 (void) SetImageColorspace(image,CMYKColorspace,exception);
3994 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3995 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3996 "UnrecognizedPixelMap","`%s'",map);
3997 return(MagickFalse);
4001 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
4002 return(MagickFalse);
4004 Transfer the pixels from the pixel data to the image.
4014 ImportCharPixel(image,&roi,map,quantum_map,pixels,exception);
4019 ImportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
4024 ImportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
4029 ImportLongPixel(image,&roi,map,quantum_map,pixels,exception);
4034 ImportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
4039 ImportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
4044 ImportShortPixel(image,&roi,map,quantum_map,pixels,exception);
4049 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4050 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4051 "UnrecognizedPixelMap","`%s'",map);
4055 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4060 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4064 + 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 %
4068 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4070 % InitializePixelChannelMap() defines the standard pixel component map.
4072 % The format of the InitializePixelChannelMap() method is:
4074 % void InitializePixelChannelMap(Image *image)
4076 % A description of each parameter follows:
4078 % o image: the image.
4081 MagickExport void InitializePixelChannelMap(Image *image)
4092 assert(image != (Image *) NULL);
4093 assert(image->signature == MagickSignature);
4094 (void) ResetMagickMemory(image->channel_map,0,MaxPixelChannels*
4095 sizeof(*image->channel_map));
4096 trait=UpdatePixelTrait;
4097 if (image->alpha_trait == BlendPixelTrait)
4098 trait=(PixelTrait) (trait | BlendPixelTrait);
4100 if (image->colorspace == GRAYColorspace)
4102 SetPixelChannelAttributes(image,BluePixelChannel,trait,n);
4103 SetPixelChannelAttributes(image,GreenPixelChannel,trait,n);
4104 SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
4108 SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
4109 SetPixelChannelAttributes(image,GreenPixelChannel,trait,n++);
4110 SetPixelChannelAttributes(image,BluePixelChannel,trait,n++);
4112 if (image->colorspace == CMYKColorspace)
4113 SetPixelChannelAttributes(image,BlackPixelChannel,trait,n++);
4114 if (image->alpha_trait != UndefinedPixelTrait)
4115 SetPixelChannelAttributes(image,AlphaPixelChannel,CopyPixelTrait,n++);
4116 if (image->storage_class == PseudoClass)
4117 SetPixelChannelAttributes(image,IndexPixelChannel,CopyPixelTrait,n++);
4118 if (image->mask != MagickFalse)
4119 SetPixelChannelAttributes(image,MaskPixelChannel,CopyPixelTrait,n++);
4120 assert((n+image->number_meta_channels) < MaxPixelChannels);
4121 for (i=0; i < (ssize_t) image->number_meta_channels; i++)
4122 SetPixelChannelAttributes(image,(PixelChannel) (MetaPixelChannel+i),
4123 CopyPixelTrait,n++);
4124 image->number_channels=(size_t) n;
4125 if (image->debug != MagickFalse)
4126 LogPixelChannels(image);
4127 (void) SetImageChannelMask(image,image->channel_mask);
4131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4135 % I n t e r p o l a t e P i x e l C h a n n e l %
4139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4141 % InterpolatePixelChannel() applies a pixel interpolation method between a
4142 % floating point coordinate and the pixels surrounding that coordinate. No
4143 % pixel area resampling, or scaling of the result is performed.
4145 % Interpolation is restricted to just the specified channel.
4147 % The format of the InterpolatePixelChannel method is:
4149 % MagickBooleanType InterpolatePixelChannel(const Image *image,
4150 % const CacheView *image_view,const PixelChannel channel,
4151 % const PixelInterpolateMethod method,const double x,const double y,
4152 % double *pixel,ExceptionInfo *exception)
4154 % A description of each parameter follows:
4156 % o image: the image.
4158 % o image_view: the image view.
4160 % o channel: the pixel channel to interpolate.
4162 % o method: the pixel color interpolation method.
4164 % o x,y: A double representing the current (x,y) position of the pixel.
4166 % o pixel: return the interpolated pixel here.
4168 % o exception: return any errors or warnings in this structure.
4172 static inline void CatromWeights(const double x,double (*weights)[4])
4180 Nicolas Robidoux' 10 flops (4* + 5- + 1+) refactoring of the computation
4181 of the standard four 1D Catmull-Rom weights. The sampling location is
4182 assumed between the second and third input pixel locations, and x is the
4183 position relative to the second input pixel location. Formulas originally
4184 derived for the VIPS (Virtual Image Processing System) library.
4186 alpha=(double) 1.0-x;
4187 beta=(double) (-0.5)*x*alpha;
4188 (*weights)[0]=alpha*beta;
4189 (*weights)[3]=x*beta;
4191 The following computation of the inner weights from the outer ones work
4192 for all Keys cubics.
4194 gamma=(*weights)[3]-(*weights)[0];
4195 (*weights)[1]=alpha-(*weights)[0]+gamma;
4196 (*weights)[2]=x-(*weights)[3]-gamma;
4199 static inline void SplineWeights(const double x,double (*weights)[4])
4206 Nicolas Robidoux' 12 flops (6* + 5- + 1+) refactoring of the
4207 computation of the standard four 1D cubic B-spline smoothing
4208 weights. The sampling location is assumed between the second and
4209 third input pixel locations, and x is the position relative to the
4210 second input pixel location.
4212 alpha=(double) 1.0-x;
4213 (*weights)[3]=(double) (1.0/6.0)*x*x*x;
4214 (*weights)[0]=(double) (1.0/6.0)*alpha*alpha*alpha;
4215 beta=(*weights)[3]-(*weights)[0];
4216 (*weights)[1]=alpha-(*weights)[0]+beta;
4217 (*weights)[2]=x-(*weights)[3]-beta;
4220 static inline double MeshInterpolate(const PointInfo *delta,const double p,
4221 const double x,const double y)
4223 return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
4227 static inline ssize_t NearestNeighbor(const double x)
4230 return((ssize_t) (x+0.5));
4231 return((ssize_t) (x-0.5));
4235 MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
4236 const CacheView *image_view,const PixelChannel channel,
4237 const PixelInterpolateMethod method,const double x,const double y,
4238 double *pixel,ExceptionInfo *exception)
4251 register const Quantum
4261 PixelInterpolateMethod
4264 assert(image != (Image *) NULL);
4265 assert(image != (Image *) NULL);
4266 assert(image->signature == MagickSignature);
4267 assert(image_view != (CacheView *) NULL);
4270 traits=GetPixelChannelTraits(image,channel);
4271 x_offset=(ssize_t) floor(x);
4272 y_offset=(ssize_t) floor(y);
4273 interpolate = method;
4274 if ( interpolate == UndefinedInterpolatePixel )
4275 interpolate = image->interpolate;
4276 switch (interpolate)
4278 case AverageInterpolatePixel: /* nearest 4 neighbours */
4279 case Average9InterpolatePixel: /* nearest 9 neighbours */
4280 case Average16InterpolatePixel: /* nearest 16 neighbours */
4285 count=2; /* size of the area to average - default nearest 4 */
4286 if (interpolate == Average9InterpolatePixel)
4289 x_offset=(ssize_t) (floor(x+0.5)-1);
4290 y_offset=(ssize_t) (floor(y+0.5)-1);
4293 if (interpolate == Average16InterpolatePixel)
4299 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,(size_t) count,(size_t)
4301 if (p == (const Quantum *) NULL)
4306 count*=count; /* Number of pixels to Average */
4307 if ((traits & BlendPixelTrait) == 0)
4308 for (i=0; i < (ssize_t) count; i++)
4311 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4314 for (i=0; i < (ssize_t) count; i++)
4316 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4317 GetPixelChannels(image));
4318 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4320 for (i=0; i < (ssize_t) count; i++)
4322 gamma=PerceptibleReciprocal(alpha[i])/count;
4323 *pixel+=gamma*pixels[i];
4327 case BilinearInterpolatePixel:
4334 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4335 if (p == (const Quantum *) NULL)
4340 if ((traits & BlendPixelTrait) == 0)
4341 for (i=0; i < 4; i++)
4344 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4347 for (i=0; i < 4; i++)
4349 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4350 GetPixelChannels(image));
4351 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4355 epsilon.x=1.0-delta.x;
4356 epsilon.y=1.0-delta.y;
4357 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4358 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4359 gamma=PerceptibleReciprocal(gamma);
4360 *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
4361 (epsilon.x*pixels[2]+delta.x*pixels[3]));
4364 case BlendInterpolatePixel:
4366 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4367 if (p == (const Quantum *) NULL)
4372 if ((traits & BlendPixelTrait) == 0)
4373 for (i=0; i < 4; i++)
4376 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4379 for (i=0; i < 4; i++)
4381 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4382 GetPixelChannels(image));
4383 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4385 gamma=1.0; /* number of pixels blended together (its variable) */
4386 for (i=0; i <= 1L; i++) {
4387 if ((y-y_offset) >= 0.75)
4389 alpha[i]=alpha[i+2]; /* take right pixels */
4390 pixels[i]=pixels[i+2];
4393 if ((y-y_offset) > 0.25)
4395 gamma=2.0; /* blend both pixels in row */
4396 alpha[i]+=alpha[i+2]; /* add up alpha weights */
4397 pixels[i]+=pixels[i+2];
4400 if ((x-x_offset) >= 0.75)
4402 alpha[0]=alpha[1]; /* take bottom row blend */
4403 pixels[0]=pixels[1];
4406 if ((x-x_offset) > 0.25)
4408 gamma*=2.0; /* blend both rows */
4409 alpha[0]+=alpha[1]; /* add up alpha weights */
4410 pixels[0]+=pixels[1];
4412 if (channel != AlphaPixelChannel)
4413 gamma=PerceptibleReciprocal(alpha[0]); /* (color) 1/alpha_weights */
4415 gamma=PerceptibleReciprocal(gamma); /* (alpha) 1/number_of_pixels */
4416 *pixel=gamma*pixels[0];
4419 case CatromInterpolatePixel:
4425 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4427 if (p == (const Quantum *) NULL)
4432 if ((traits & BlendPixelTrait) == 0)
4433 for (i=0; i < 16; i++)
4436 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4439 for (i=0; i < 16; i++)
4441 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4442 GetPixelChannels(image));
4443 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4445 CatromWeights((double) (x-x_offset),&cx);
4446 CatromWeights((double) (y-y_offset),&cy);
4447 gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4448 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4449 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4450 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4451 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4452 cx[2]*alpha[14]+cx[3]*alpha[15])));
4453 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4454 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4455 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4456 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4457 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4461 /* deprecated useless and very slow interpolator */
4462 case FilterInterpolatePixel:
4476 geometry.x=x_offset-1;
4477 geometry.y=y_offset-1;
4478 excerpt_image=ExcerptImage(image,&geometry,exception);
4479 if (excerpt_image == (Image *) NULL)
4484 filter_image=ResizeImage(excerpt_image,1,1,image->filter,exception);
4485 excerpt_image=DestroyImage(excerpt_image);
4486 if (filter_image == (Image *) NULL)
4488 filter_view=AcquireVirtualCacheView(filter_image,exception);
4489 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4490 if (p == (const Quantum *) NULL)
4493 *pixel=(double) GetPixelChannel(image,channel,p);
4494 filter_view=DestroyCacheView(filter_view);
4495 filter_image=DestroyImage(filter_image);
4499 case IntegerInterpolatePixel:
4501 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4502 if (p == (const Quantum *) NULL)
4507 *pixel=(double) GetPixelChannel(image,channel,p);
4510 case NearestInterpolatePixel:
4512 x_offset=(ssize_t) floor(x+0.5);
4513 y_offset=(ssize_t) floor(y+0.5);
4514 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4515 if (p == (const Quantum *) NULL)
4520 *pixel=(double) GetPixelChannel(image,channel,p);
4523 case MeshInterpolatePixel:
4529 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4530 if (p == (const Quantum *) NULL)
4535 if ((traits & BlendPixelTrait) == 0)
4536 for (i=0; i < 4; i++)
4539 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4542 for (i=0; i < 4; i++)
4544 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4545 GetPixelChannels(image));
4546 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4550 luminance.x=GetPixelLuminance(image,p)-(double)
4551 GetPixelLuminance(image,p+3*GetPixelChannels(image));
4552 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
4553 GetPixelLuminance(image,p+2*GetPixelChannels(image));
4554 if (fabs(luminance.x) < fabs(luminance.y))
4559 if (delta.x <= delta.y)
4562 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4564 delta.y=1.0-delta.y;
4565 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4566 gamma=PerceptibleReciprocal(gamma);
4567 *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
4573 Top-right triangle (pixel: 1, diagonal: 0-3).
4575 delta.x=1.0-delta.x;
4576 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4577 gamma=PerceptibleReciprocal(gamma);
4578 *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
4587 if (delta.x <= (1.0-delta.y))
4590 Top-left triangle (pixel: 0, diagonal: 1-2).
4592 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4593 gamma=PerceptibleReciprocal(gamma);
4594 *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
4600 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4602 delta.x=1.0-delta.x;
4603 delta.y=1.0-delta.y;
4604 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4605 gamma=PerceptibleReciprocal(gamma);
4606 *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
4612 case SplineInterpolatePixel:
4618 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4620 if (p == (const Quantum *) NULL)
4625 if ((traits & BlendPixelTrait) == 0)
4626 for (i=0; i < 16; i++)
4629 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4632 for (i=0; i < 16; i++)
4634 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4635 GetPixelChannels(image));
4636 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4638 SplineWeights((double) (x-x_offset),&cx);
4639 SplineWeights((double) (y-y_offset),&cy);
4640 gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4641 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4642 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4643 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4644 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4645 cx[2]*alpha[14]+cx[3]*alpha[15])));
4646 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4647 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4648 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4649 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4650 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4658 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4662 % I n t e r p o l a t e P i x e l C h a n n e l s %
4666 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4668 % InterpolatePixelChannels() applies a pixel interpolation method between a
4669 % floating point coordinate and the pixels surrounding that coordinate. No
4670 % pixel area resampling, or scaling of the result is performed.
4672 % Interpolation is restricted to just the current channel setting of the
4673 % destination image into which the color is to be stored
4675 % The format of the InterpolatePixelChannels method is:
4677 % MagickBooleanType InterpolatePixelChannels(const Image *source,
4678 % const CacheView *source_view,const Image *destination,
4679 % const PixelInterpolateMethod method,const double x,const double y,
4680 % Quantum *pixel,ExceptionInfo *exception)
4682 % A description of each parameter follows:
4684 % o source: the source.
4686 % o source_view: the source view.
4688 % o destination: the destination image, for the interpolated color
4690 % o method: the pixel color interpolation method.
4692 % o x,y: A double representing the current (x,y) position of the pixel.
4694 % o pixel: return the interpolated pixel here.
4696 % o exception: return any errors or warnings in this structure.
4699 MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
4700 const CacheView *source_view,const Image *destination,
4701 const PixelInterpolateMethod method,const double x,const double y,
4702 Quantum *pixel,ExceptionInfo *exception)
4712 register const Quantum
4722 PixelInterpolateMethod
4725 assert(source != (Image *) NULL);
4726 assert(source != (Image *) NULL);
4727 assert(source->signature == MagickSignature);
4728 assert(source_view != (CacheView *) NULL);
4730 x_offset=(ssize_t) floor(x);
4731 y_offset=(ssize_t) floor(y);
4732 interpolate = method;
4733 if ( interpolate == UndefinedInterpolatePixel )
4734 interpolate = source->interpolate;
4735 switch (interpolate)
4737 case AverageInterpolatePixel: /* nearest 4 neighbours */
4738 case Average9InterpolatePixel: /* nearest 9 neighbours */
4739 case Average16InterpolatePixel: /* nearest 16 neighbours */
4744 count=2; /* size of the area to average - default nearest 4 */
4745 if (interpolate == Average9InterpolatePixel)
4748 x_offset=(ssize_t) (floor(x+0.5)-1);
4749 y_offset=(ssize_t) (floor(y+0.5)-1);
4752 if (interpolate == Average16InterpolatePixel)
4758 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,(size_t) count,(size_t)
4760 if (p == (const Quantum *) NULL)
4765 count*=count; /* Number of pixels to Average */
4766 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4774 PixelChannel channel=GetPixelChannelChannel(source,i);
4775 PixelTrait traits=GetPixelChannelTraits(source,channel);
4776 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4778 if ((traits == UndefinedPixelTrait) ||
4779 (destination_traits == UndefinedPixelTrait))
4781 for (j=0; j < (ssize_t) count; j++)
4782 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
4784 if ((traits & BlendPixelTrait) == 0)
4786 for (j=0; j < (ssize_t) count; j++)
4789 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4792 for (j=0; j < (ssize_t) count; j++)
4794 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4795 GetPixelChannels(source));
4796 pixels[j]*=alpha[j];
4797 gamma=PerceptibleReciprocal(alpha[j]);
4798 sum+=gamma*pixels[j];
4801 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4805 case BilinearInterpolatePixel:
4808 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4809 if (p == (const Quantum *) NULL)
4814 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4820 PixelChannel channel=GetPixelChannelChannel(source,i);
4821 PixelTrait traits=GetPixelChannelTraits(source,channel);
4822 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4824 if ((traits == UndefinedPixelTrait) ||
4825 (destination_traits == UndefinedPixelTrait))
4829 epsilon.x=1.0-delta.x;
4830 epsilon.y=1.0-delta.y;
4831 pixels[0]=(double) p[i];
4832 pixels[1]=(double) p[GetPixelChannels(source)+i];
4833 pixels[2]=(double) p[2*GetPixelChannels(source)+i];
4834 pixels[3]=(double) p[3*GetPixelChannels(source)+i];
4835 if ((traits & BlendPixelTrait) == 0)
4837 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
4838 gamma=PerceptibleReciprocal(gamma);
4839 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4840 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*
4841 pixels[2]+delta.x*pixels[3]))),pixel);
4844 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4845 alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source));
4846 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4847 GetPixelChannels(source));
4848 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4849 GetPixelChannels(source));
4850 pixels[0]*=alpha[0];
4851 pixels[1]*=alpha[1];
4852 pixels[2]*=alpha[2];
4853 pixels[3]*=alpha[3];
4854 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4855 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4856 gamma=PerceptibleReciprocal(gamma);
4857 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4858 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+
4859 delta.x*pixels[3]))),pixel);
4863 case BlendInterpolatePixel:
4865 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4866 if (p == (const Quantum *) NULL)
4871 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4876 PixelChannel channel=GetPixelChannelChannel(source,i);
4877 PixelTrait traits=GetPixelChannelTraits(source,channel);
4878 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4880 if ((traits == UndefinedPixelTrait) ||
4881 (destination_traits == UndefinedPixelTrait))
4883 if ((traits & BlendPixelTrait) == 0)
4884 for (j=0; j < 4; j++)
4887 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+channel];
4890 for (j=0; j < 4; j++)
4892 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4893 GetPixelChannels(source));
4894 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+channel];
4896 gamma=1.0; /* number of pixels blended together (its variable) */
4897 for (j=0; j <= 1L; j++)
4899 if ((y-y_offset) >= 0.75)
4901 alpha[j]=alpha[j+2]; /* take right pixels */
4902 pixels[j]=pixels[j+2];
4905 if ((y-y_offset) > 0.25)
4907 gamma=2.0; /* blend both pixels in row */
4908 alpha[j]+=alpha[j+2]; /* add up alpha weights */
4909 pixels[j]+=pixels[j+2];
4912 if ((x-x_offset) >= 0.75)
4914 alpha[0]=alpha[1]; /* take bottom row blend */
4915 pixels[0]=pixels[1];
4918 if ((x-x_offset) > 0.25)
4920 gamma*=2.0; /* blend both rows */
4921 alpha[0]+=alpha[1]; /* add up alpha weights */
4922 pixels[0]+=pixels[1];
4924 if ((traits & BlendPixelTrait) == 0)
4925 gamma=PerceptibleReciprocal(alpha[0]); /* (color) 1/alpha_weights */
4927 gamma=PerceptibleReciprocal(gamma); /* (alpha) 1/number_of_pixels */
4928 SetPixelChannel(destination,channel,ClampToQuantum(gamma*pixels[0]),
4933 case CatromInterpolatePixel:
4939 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4941 if (p == (const Quantum *) NULL)
4946 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4951 PixelChannel channel=GetPixelChannelChannel(source,i);
4952 PixelTrait traits=GetPixelChannelTraits(source,channel);
4953 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4955 if ((traits == UndefinedPixelTrait) ||
4956 (destination_traits == UndefinedPixelTrait))
4958 if ((traits & BlendPixelTrait) == 0)
4959 for (j=0; j < 16; j++)
4962 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
4965 for (j=0; j < 16; j++)
4967 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4968 GetPixelChannels(source));
4969 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4971 CatromWeights((double) (x-x_offset),&cx);
4972 CatromWeights((double) (y-y_offset),&cy);
4973 gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
4974 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4975 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4976 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4977 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4978 cx[2]*alpha[14]+cx[3]*alpha[15])));
4979 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
4980 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
4981 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
4982 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
4983 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
4984 pixels[14]+cx[3]*pixels[15]))),pixel);
4989 /* deprecated useless and very slow interpolator */
4990 case FilterInterpolatePixel:
4992 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5004 PixelChannel channel=GetPixelChannelChannel(source,i);
5005 PixelTrait traits=GetPixelChannelTraits(source,channel);
5006 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5008 if ((traits == UndefinedPixelTrait) ||
5009 (destination_traits == UndefinedPixelTrait))
5013 geometry.x=x_offset-1;
5014 geometry.y=y_offset-1;
5015 excerpt_source=ExcerptImage(source,&geometry,exception);
5016 if (excerpt_source == (Image *) NULL)
5021 filter_source=ResizeImage(excerpt_source,1,1,source->filter,exception);
5022 excerpt_source=DestroyImage(excerpt_source);
5023 if (filter_source == (Image *) NULL)
5025 filter_view=AcquireVirtualCacheView(filter_source,exception);
5026 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
5027 if (p == (const Quantum *) NULL)
5031 SetPixelChannel(destination,channel,p[i],pixel);
5033 filter_view=DestroyCacheView(filter_view);
5034 filter_source=DestroyImage(filter_source);
5039 case IntegerInterpolatePixel:
5041 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
5042 if (p == (const Quantum *) NULL)
5047 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5049 PixelChannel channel=GetPixelChannelChannel(source,i);
5050 PixelTrait traits=GetPixelChannelTraits(source,channel);
5051 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5053 if ((traits == UndefinedPixelTrait) ||
5054 (destination_traits == UndefinedPixelTrait))
5056 SetPixelChannel(destination,channel,p[i],pixel);
5060 case NearestInterpolatePixel:
5062 x_offset=(ssize_t) floor(x+0.5);
5063 y_offset=(ssize_t) floor(y+0.5);
5064 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
5065 if (p == (const Quantum *) NULL)
5070 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5072 PixelChannel channel=GetPixelChannelChannel(source,i);
5073 PixelTrait traits=GetPixelChannelTraits(source,channel);
5074 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5076 if ((traits == UndefinedPixelTrait) ||
5077 (destination_traits == UndefinedPixelTrait))
5079 SetPixelChannel(destination,channel,p[i],pixel);
5083 case MeshInterpolatePixel:
5085 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
5086 if (p == (const Quantum *) NULL)
5091 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5097 PixelChannel channel=GetPixelChannelChannel(source,i);
5098 PixelTrait traits=GetPixelChannelTraits(source,channel);
5099 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5101 if ((traits == UndefinedPixelTrait) ||
5102 (destination_traits == UndefinedPixelTrait))
5104 pixels[0]=(double) p[i];
5105 pixels[1]=(double) p[GetPixelChannels(source)+i];
5106 pixels[2]=(double) p[2*GetPixelChannels(source)+i];
5107 pixels[3]=(double) p[3*GetPixelChannels(source)+i];
5108 if ((traits & BlendPixelTrait) == 0)
5117 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
5118 alpha[1]=QuantumScale*GetPixelAlpha(source,p+
5119 GetPixelChannels(source));
5120 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
5121 GetPixelChannels(source));
5122 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
5123 GetPixelChannels(source));
5127 luminance.x=fabs((double) (GetPixelLuminance(source,p)-
5128 GetPixelLuminance(source,p+3*GetPixelChannels(source))));
5129 luminance.y=fabs((double) (GetPixelLuminance(source,p+
5130 GetPixelChannels(source))-GetPixelLuminance(source,p+2*
5131 GetPixelChannels(source))));
5132 if (luminance.x < luminance.y)
5137 if (delta.x <= delta.y)
5140 Bottom-left triangle (pixel: 2, diagonal: 0-3).
5142 delta.y=1.0-delta.y;
5143 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5144 gamma=PerceptibleReciprocal(gamma);
5145 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5146 MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel);
5151 Top-right triangle (pixel: 1, diagonal: 0-3).
5153 delta.x=1.0-delta.x;
5154 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5155 gamma=PerceptibleReciprocal(gamma);
5156 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5157 MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel);
5165 if (delta.x <= (1.0-delta.y))
5168 Top-left triangle (pixel: 0, diagonal: 1-2).
5170 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5171 gamma=PerceptibleReciprocal(gamma);
5172 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5173 MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel);
5178 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5180 delta.x=1.0-delta.x;
5181 delta.y=1.0-delta.y;
5182 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5183 gamma=PerceptibleReciprocal(gamma);
5184 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5185 MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel);
5191 case SplineInterpolatePixel:
5197 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
5199 if (p == (const Quantum *) NULL)
5204 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5209 PixelChannel channel=GetPixelChannelChannel(source,i);
5210 PixelTrait traits=GetPixelChannelTraits(source,channel);
5211 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5213 if ((traits == UndefinedPixelTrait) ||
5214 (destination_traits == UndefinedPixelTrait))
5216 if ((traits & BlendPixelTrait) == 0)
5217 for (j=0; j < 16; j++)
5220 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
5223 for (j=0; j < 16; j++)
5225 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
5226 GetPixelChannels(source));
5227 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
5229 SplineWeights((double) (x-x_offset),&cx);
5230 SplineWeights((double) (y-y_offset),&cy);
5231 gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
5232 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
5233 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
5234 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
5235 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
5236 cx[2]*alpha[14]+cx[3]*alpha[15])));
5237 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
5238 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
5239 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
5240 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
5241 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
5242 pixels[14]+cx[3]*pixels[15]))),pixel);
5251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5255 % I n t e r p o l a t e P i x e l I n f o %
5259 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5261 % InterpolatePixelInfo() applies a pixel interpolation method between a
5262 % floating point coordinate and the pixels surrounding that coordinate. No
5263 % pixel area resampling, or scaling of the result is performed.
5265 % Interpolation is restricted to just RGBKA channels.
5267 % The format of the InterpolatePixelInfo method is:
5269 % MagickBooleanType InterpolatePixelInfo(const Image *image,
5270 % const CacheView *image_view,const PixelInterpolateMethod method,
5271 % const double x,const double y,PixelInfo *pixel,
5272 % ExceptionInfo *exception)
5274 % A description of each parameter follows:
5276 % o image: the image.
5278 % o image_view: the image view.
5280 % o method: the pixel color interpolation method.
5282 % o x,y: A double representing the current (x,y) position of the pixel.
5284 % o pixel: return the interpolated pixel here.
5286 % o exception: return any errors or warnings in this structure.
5290 static inline void AlphaBlendPixelInfo(const Image *image,
5291 const Quantum *pixel,PixelInfo *pixel_info,double *alpha)
5293 if (image->alpha_trait != BlendPixelTrait)
5296 pixel_info->red=(double) GetPixelRed(image,pixel);
5297 pixel_info->green=(double) GetPixelGreen(image,pixel);
5298 pixel_info->blue=(double) GetPixelBlue(image,pixel);
5299 pixel_info->black=0.0;
5300 if (image->colorspace == CMYKColorspace)
5301 pixel_info->black=(double) GetPixelBlack(image,pixel);
5302 pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5305 *alpha=QuantumScale*GetPixelAlpha(image,pixel);
5306 pixel_info->red=(*alpha*GetPixelRed(image,pixel));
5307 pixel_info->green=(*alpha*GetPixelGreen(image,pixel));
5308 pixel_info->blue=(*alpha*GetPixelBlue(image,pixel));
5309 pixel_info->black=0.0;
5310 if (image->colorspace == CMYKColorspace)
5311 pixel_info->black=(*alpha*GetPixelBlack(image,pixel));
5312 pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5315 MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
5316 const CacheView *image_view,const PixelInterpolateMethod method,
5317 const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception)
5329 register const Quantum
5339 PixelInterpolateMethod
5342 assert(image != (Image *) NULL);
5343 assert(image->signature == MagickSignature);
5344 assert(image_view != (CacheView *) NULL);
5346 x_offset=(ssize_t) floor(x);
5347 y_offset=(ssize_t) floor(y);
5348 interpolate = method;
5349 if ( interpolate == UndefinedInterpolatePixel )
5350 interpolate = image->interpolate;
5351 switch (interpolate)
5353 case AverageInterpolatePixel: /* nearest 4 neighbours */
5354 case Average9InterpolatePixel: /* nearest 9 neighbours */
5355 case Average16InterpolatePixel: /* nearest 16 neighbours */
5360 count=2; /* size of the area to average - default nearest 4 */
5361 if (interpolate == Average9InterpolatePixel)
5364 x_offset=(ssize_t) (floor(x+0.5)-1);
5365 y_offset=(ssize_t) (floor(y+0.5)-1);
5367 else if (interpolate == Average16InterpolatePixel)
5373 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,(size_t) count,(size_t)
5375 if (p == (const Quantum *) NULL)
5385 count*=count; /* number of pixels - square of size */
5386 for (i=0; i < (ssize_t) count; i++)
5388 AlphaBlendPixelInfo(image,p,pixels,alpha);
5389 gamma=PerceptibleReciprocal(alpha[0]);
5390 pixel->red+=gamma*pixels[0].red;
5391 pixel->green+=gamma*pixels[0].green;
5392 pixel->blue+=gamma*pixels[0].blue;
5393 pixel->black+=gamma*pixels[0].black;
5394 pixel->alpha+=pixels[0].alpha;
5395 p += GetPixelChannels(image);
5397 gamma=1.0/count; /* average weighting of each pixel in area */
5399 pixel->green*=gamma;
5401 pixel->black*=gamma;
5402 pixel->alpha*=gamma;
5405 case BackgroundInterpolatePixel:
5407 *pixel=image->background_color; /* Copy PixelInfo Structure */
5410 case BilinearInterpolatePixel:
5417 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5418 if (p == (const Quantum *) NULL)
5423 for (i=0; i < 4L; i++)
5424 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5427 epsilon.x=1.0-delta.x;
5428 epsilon.y=1.0-delta.y;
5429 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5430 (epsilon.x*alpha[2]+delta.x*alpha[3])));
5431 gamma=PerceptibleReciprocal(gamma);
5432 pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
5433 pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red));
5434 pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x*
5435 pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x*
5437 pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x*
5438 pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x*
5440 if (image->colorspace == CMYKColorspace)
5441 pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x*
5442 pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x*
5444 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5445 gamma=PerceptibleReciprocal(gamma);
5446 pixel->alpha=(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x*
5447 pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x*
5451 case BlendInterpolatePixel:
5453 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5454 if (p == (const Quantum *) NULL)
5459 for (i=0; i < 4L; i++)
5460 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5461 gamma=1.0; /* number of pixels blended together (its variable) */
5462 for (i=0; i <= 1L; i++)
5464 if ((y-y_offset) >= 0.75)
5466 alpha[i]=alpha[i+2]; /* take right pixels */
5467 pixels[i]=pixels[i+2];
5470 if ((y-y_offset) > 0.25)
5472 gamma=2.0; /* blend both pixels in row */
5473 alpha[i]+=alpha[i+2]; /* add up alpha weights */
5474 pixels[i].red+=pixels[i+2].red;
5475 pixels[i].green+=pixels[i+2].green;
5476 pixels[i].blue+=pixels[i+2].blue;
5477 pixels[i].black+=pixels[i+2].black;
5478 pixels[i].alpha+=pixels[i+2].alpha;
5481 if ((x-x_offset) >= 0.75)
5484 pixels[0]=pixels[1];
5487 if ((x-x_offset) > 0.25)
5489 gamma*=2.0; /* blend both rows */
5490 alpha[0]+= alpha[1]; /* add up alpha weights */
5491 pixels[0].red+=pixels[1].red;
5492 pixels[0].green+=pixels[1].green;
5493 pixels[0].blue+=pixels[1].blue;
5494 pixels[0].black+=pixels[1].black;
5495 pixels[0].alpha+=pixels[1].alpha;
5498 alpha[0]=PerceptibleReciprocal(alpha[0]);
5499 pixel->red=alpha[0]*pixels[0].red;
5500 pixel->green=alpha[0]*pixels[0].green; /* divide by sum of alpha */
5501 pixel->blue=alpha[0]*pixels[0].blue;
5502 pixel->black=alpha[0]*pixels[0].black;
5503 pixel->alpha=gamma*pixels[0].alpha; /* divide by number of pixels */
5506 case CatromInterpolatePixel:
5512 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5514 if (p == (const Quantum *) NULL)
5519 for (i=0; i < 16L; i++)
5520 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5521 CatromWeights((double) (x-x_offset),&cx);
5522 CatromWeights((double) (y-y_offset),&cy);
5523 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]*
5524 pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5525 pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]*
5526 pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5527 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]*
5528 pixels[14].red+cx[3]*pixels[15].red));
5529 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]*
5530 pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+
5531 cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+
5532 cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]*
5533 pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]*
5534 pixels[12].green+cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]*
5536 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]*
5537 pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5538 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]*
5539 pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5540 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+
5541 cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5542 if (image->colorspace == CMYKColorspace)
5543 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]*
5544 pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+
5545 cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+
5546 cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]*
5547 pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]*
5548 pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]*
5550 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]*
5551 pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+
5552 cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+
5553 cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]*
5554 pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+
5555 cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5559 /* deprecated useless and very slow interpolator */
5560 case FilterInterpolatePixel:
5574 geometry.x=x_offset-1;
5575 geometry.y=y_offset-1;
5576 excerpt_image=ExcerptImage(image,&geometry,exception);
5577 if (excerpt_image == (Image *) NULL)
5582 filter_image=ResizeImage(excerpt_image,1,1,image->filter,exception);
5583 excerpt_image=DestroyImage(excerpt_image);
5584 if (filter_image == (Image *) NULL)
5586 filter_view=AcquireVirtualCacheView(filter_image,exception);
5587 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
5588 if (p != (const Quantum *) NULL)
5589 GetPixelInfoPixel(image,p,pixel);
5590 filter_view=DestroyCacheView(filter_view);
5591 filter_image=DestroyImage(filter_image);
5595 case IntegerInterpolatePixel:
5597 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5598 if (p == (const Quantum *) NULL)
5603 GetPixelInfoPixel(image,p,pixel);
5606 case MeshInterpolatePixel:
5612 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5613 if (p == (const Quantum *) NULL)
5620 luminance.x=GetPixelLuminance(image,p)-(double)
5621 GetPixelLuminance(image,p+3*GetPixelChannels(image));
5622 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
5623 GetPixelLuminance(image,p+2*GetPixelChannels(image));
5624 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5625 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5626 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5627 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5628 if (fabs(luminance.x) < fabs(luminance.y))
5633 if (delta.x <= delta.y)
5636 Bottom-left triangle (pixel: 2, diagonal: 0-3).
5638 delta.y=1.0-delta.y;
5639 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5640 gamma=PerceptibleReciprocal(gamma);
5641 pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red,
5642 pixels[3].red,pixels[0].red);
5643 pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green,
5644 pixels[3].green,pixels[0].green);
5645 pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
5646 pixels[3].blue,pixels[0].blue);
5647 if (image->colorspace == CMYKColorspace)
5648 pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black,
5649 pixels[3].black,pixels[0].black);
5650 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5651 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha,
5652 pixels[3].alpha,pixels[0].alpha);
5657 Top-right triangle (pixel:1 , diagonal: 0-3).
5659 delta.x=1.0-delta.x;
5660 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5661 gamma=PerceptibleReciprocal(gamma);
5662 pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red,
5663 pixels[0].red,pixels[3].red);
5664 pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green,
5665 pixels[0].green,pixels[3].green);
5666 pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
5667 pixels[0].blue,pixels[3].blue);
5668 if (image->colorspace == CMYKColorspace)
5669 pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black,
5670 pixels[0].black,pixels[3].black);
5671 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5672 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha,
5673 pixels[0].alpha,pixels[3].alpha);
5681 if (delta.x <= (1.0-delta.y))
5684 Top-left triangle (pixel: 0, diagonal: 1-2).
5686 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5687 gamma=PerceptibleReciprocal(gamma);
5688 pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red,
5689 pixels[1].red,pixels[2].red);
5690 pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green,
5691 pixels[1].green,pixels[2].green);
5692 pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
5693 pixels[1].blue,pixels[2].blue);
5694 if (image->colorspace == CMYKColorspace)
5695 pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black,
5696 pixels[1].black,pixels[2].black);
5697 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5698 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha,
5699 pixels[1].alpha,pixels[2].alpha);
5704 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5706 delta.x=1.0-delta.x;
5707 delta.y=1.0-delta.y;
5708 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5709 gamma=PerceptibleReciprocal(gamma);
5710 pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red,
5711 pixels[2].red,pixels[1].red);
5712 pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green,
5713 pixels[2].green,pixels[1].green);
5714 pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
5715 pixels[2].blue,pixels[1].blue);
5716 if (image->colorspace == CMYKColorspace)
5717 pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black,
5718 pixels[2].black,pixels[1].black);
5719 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5720 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha,
5721 pixels[2].alpha,pixels[1].alpha);
5726 case NearestInterpolatePixel:
5728 x_offset=(ssize_t) floor(x+0.5);
5729 y_offset=(ssize_t) floor(y+0.5);
5730 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5731 if (p == (const Quantum *) NULL)
5736 GetPixelInfoPixel(image,p,pixel);
5739 case SplineInterpolatePixel:
5745 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5747 if (p == (const Quantum *) NULL)
5752 for (i=0; i < 16L; i++)
5753 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5754 SplineWeights((double) (x-x_offset),&cx);
5755 SplineWeights((double) (y-y_offset),&cy);
5756 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]*
5757 pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5758 pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]*
5759 pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5760 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]*
5761 pixels[14].red+cx[3]*pixels[15].red));
5762 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]*
5763 pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+
5764 cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+
5765 cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]*
5766 pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]*pixels[12].green+
5767 cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]*pixels[15].green));
5768 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]*
5769 pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5770 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]*
5771 pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5772 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+
5773 cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5774 if (image->colorspace == CMYKColorspace)
5775 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]*
5776 pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+
5777 cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+
5778 cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]*
5779 pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]*
5780 pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]*
5782 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]*
5783 pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+
5784 cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+
5785 cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]*
5786 pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+
5787 cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5795 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5799 + I s F u z z y E q u i v a l e n c e P i x e l %
5803 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5805 % IsFuzzyEquivalencePixel() returns MagickTrue if the distance between two
5806 % pixels is less than the specified distance in a linear three (or four)u
5807 % dimensional color space.
5809 % The format of the IsFuzzyEquivalencePixel method is:
5811 % void IsFuzzyEquivalencePixel(const Image *source,const Quantum *p,
5812 % const Image *destination,const Quantum *q)
5814 % A description of each parameter follows:
5816 % o source: the source image.
5820 % o destination: the destination image.
5825 MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *source,
5826 const Quantum *p,const Image *destination,const Quantum *q)
5836 fuzz=MagickMax(source->fuzz,(double) MagickSQ1_2)*MagickMax(
5837 destination->fuzz,(double) MagickSQ1_2);
5840 if (source->alpha_trait == BlendPixelTrait)
5843 Transparencies are involved - set alpha distance
5845 pixel=GetPixelAlpha(source,p)-(double) GetPixelAlpha(destination,q);
5846 distance=pixel*pixel;
5847 if (distance > fuzz)
5848 return(MagickFalse);
5850 Generate a alpha scaling factor to generate a 4D cone on colorspace
5851 Note that if one color is transparent, distance has no color component.
5853 scale=QuantumScale*GetPixelAlpha(source,p);
5854 scale*=QuantumScale*GetPixelAlpha(destination,q);
5855 if (scale <= MagickEpsilon)
5859 RGB or CMY color cube
5861 distance*=3.0; /* rescale appropriately */
5863 pixel=GetPixelRed(source,p)-(double) GetPixelRed(destination,q);
5864 if ((source->colorspace == HSLColorspace) ||
5865 (source->colorspace == HSBColorspace) ||
5866 (source->colorspace == HWBColorspace))
5869 Compute an arc distance for hue. It should be a vector angle of
5870 'S'/'W' length with 'L'/'B' forming appropriate cones.
5872 if (fabs((double) pixel) > (QuantumRange/2))
5873 pixel-=QuantumRange;
5876 distance+=scale*pixel*pixel;
5877 if (distance > fuzz)
5878 return(MagickFalse);
5879 pixel=GetPixelGreen(source,p)-(double) GetPixelGreen(destination,q);
5880 distance+=scale*pixel*pixel;
5881 if (distance > fuzz)
5882 return(MagickFalse);
5883 pixel=GetPixelBlue(source,p)-(double) GetPixelBlue(destination,q);
5884 distance+=scale*pixel*pixel;
5885 if (distance > fuzz)
5886 return(MagickFalse);
5891 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5895 + 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 %
5899 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5901 % IsFuzzyEquivalencePixelInfo() returns true if the distance between two
5902 % colors is less than the specified distance in a linear three (or four)
5903 % dimensional color space.
5905 % This implements the equivalent of:
5906 % fuzz < sqrt(color_distance^2 * u.a*v.a + alpha_distance^2)
5908 % Which produces a multi-dimensional cone for that colorspace along the
5909 % transparency vector.
5911 % For example for an RGB:
5912 % color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3
5914 % See http://www.imagemagick.org/Usage/bugs/fuzz_distance/
5916 % Hue colorspace distances need more work. Hue is not a distance, it is an
5919 % A check that q is in the same color space as p should be made and the
5920 % appropriate mapping made. -- Anthony Thyssen 8 December 2010
5922 % The format of the IsFuzzyEquivalencePixelInfo method is:
5924 % MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5925 % const PixelInfo *q)
5927 % A description of each parameter follows:
5934 MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5945 if ((p->fuzz == 0.0) && (q->fuzz == 0.0))
5946 return(IsPixelInfoEquivalent(p,q));
5948 fuzz=MagickMax(q->fuzz,(double) MagickSQ1_2)*MagickMax(q->fuzz,
5949 (double) MagickSQ1_2);
5950 else if (q->fuzz == 0.0)
5951 fuzz=MagickMax(p->fuzz,(double) MagickSQ1_2)*MagickMax(p->fuzz,
5952 (double) MagickSQ1_2);
5954 fuzz=MagickMax(p->fuzz,(double) MagickSQ1_2)*MagickMax(q->fuzz,
5955 (double) MagickSQ1_2);
5958 if ((p->alpha_trait == BlendPixelTrait) || (q->alpha_trait == BlendPixelTrait))
5961 Transparencies are involved - set alpha distance.
5963 pixel=(p->alpha_trait == BlendPixelTrait ? p->alpha : OpaqueAlpha)-
5964 (q->alpha_trait == BlendPixelTrait ? q->alpha : OpaqueAlpha);
5965 distance=pixel*pixel;
5966 if (distance > fuzz)
5967 return(MagickFalse);
5969 Generate a alpha scaling factor to generate a 4D cone on colorspace.
5970 If one color is transparent, distance has no color component.
5972 if (p->alpha_trait == BlendPixelTrait)
5973 scale=(QuantumScale*p->alpha);
5974 if (q->alpha_trait == BlendPixelTrait)
5975 scale*=(QuantumScale*q->alpha);
5976 if (scale <= MagickEpsilon )
5980 CMYK create a CMY cube with a multi-dimensional cone toward black.
5982 if (p->colorspace == CMYKColorspace)
5984 pixel=p->black-q->black;
5985 distance+=pixel*pixel*scale;
5986 if (distance > fuzz)
5987 return(MagickFalse);
5988 scale*=(double) (QuantumScale*(QuantumRange-p->black));
5989 scale*=(double) (QuantumScale*(QuantumRange-q->black));
5992 RGB or CMY color cube.
5994 distance*=3.0; /* rescale appropriately */
5996 pixel=p->red-q->red;
5997 if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) ||
5998 (p->colorspace == HWBColorspace))
6001 This calculates a arc distance for hue-- it should be a vector angle
6002 of 'S'/'W' length with 'L'/'B' forming appropriate cones. In other
6003 words this is a hack - Anthony.
6005 if (fabs((double) pixel) > (QuantumRange/2))
6006 pixel-=QuantumRange;
6009 distance+=pixel*pixel*scale;
6010 if (distance > fuzz)
6011 return(MagickFalse);
6012 pixel=p->green-q->green;
6013 distance+=pixel*pixel*scale;
6014 if (distance > fuzz)
6015 return(MagickFalse);
6016 pixel=p->blue-q->blue;
6017 distance+=pixel*pixel*scale;
6018 if (distance > fuzz)
6019 return(MagickFalse);
6024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6028 % S e t P i x e l C h a n n e l M a p M a s k %
6032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6034 % SetPixelChannelMask() sets the pixel channel map from the specified
6037 % The format of the SetPixelChannelMask method is:
6039 % void SetPixelChannelMask(Image *image,const ChannelType channel_mask)
6041 % A description of each parameter follows:
6043 % o image: the image.
6045 % o channel_mask: the channel mask.
6048 MagickExport void SetPixelChannelMask(Image *image,
6049 const ChannelType channel_mask)
6051 #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
6056 if (image->debug != MagickFalse)
6057 (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%08x]", \
6058 image->filename,channel_mask); \
6059 image->channel_mask=channel_mask;
6060 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
6062 PixelChannel channel=GetPixelChannelChannel(image,i);
6063 SetPixelChannelTraits(image,channel,
6064 GetChannelBit(channel_mask,channel) == 0 ? CopyPixelTrait :
6065 image->alpha_trait != BlendPixelTrait || (channel == AlphaPixelChannel) ?
6066 UpdatePixelTrait : (PixelTrait) (UpdatePixelTrait | image->alpha_trait));
6068 if (image->storage_class == PseudoClass)
6069 SetPixelChannelTraits(image,IndexPixelChannel,CopyPixelTrait);
6070 if (image->mask != MagickFalse)
6071 SetPixelChannelTraits(image,MaskPixelChannel,CopyPixelTrait);
6072 if (image->debug != MagickFalse)
6073 LogPixelChannels(image);
6077 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6081 % S e t P i x e l M e t a C h a n n e l s %
6085 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6087 % SetPixelMetaChannels() sets the image meta channels.
6089 % The format of the SetPixelMetaChannels method is:
6091 % MagickBooleanType SetPixelMetaChannels(Image *image,
6092 % const size_t number_meta_channels,ExceptionInfo *exception)
6094 % A description of each parameter follows:
6096 % o image: the image.
6098 % o number_meta_channels: the number of meta channels.
6100 % o exception: return any errors or warnings in this structure.
6103 MagickExport MagickBooleanType SetPixelMetaChannels(Image *image,
6104 const size_t number_meta_channels,ExceptionInfo *exception)
6106 image->number_meta_channels=number_meta_channels;
6107 return(SyncImagePixelCache(image,exception));