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-2012 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/color-private.h"
46 #include "MagickCore/draw.h"
47 #include "MagickCore/exception.h"
48 #include "MagickCore/exception-private.h"
49 #include "MagickCore/cache.h"
50 #include "MagickCore/constitute.h"
51 #include "MagickCore/delegate.h"
52 #include "MagickCore/geometry.h"
53 #include "MagickCore/image-private.h"
54 #include "MagickCore/list.h"
55 #include "MagickCore/magick.h"
56 #include "MagickCore/memory_.h"
57 #include "MagickCore/monitor.h"
58 #include "MagickCore/option.h"
59 #include "MagickCore/pixel.h"
60 #include "MagickCore/pixel-accessor.h"
61 #include "MagickCore/quantum.h"
62 #include "MagickCore/quantum-private.h"
63 #include "MagickCore/resource_.h"
64 #include "MagickCore/semaphore.h"
65 #include "MagickCore/statistic.h"
66 #include "MagickCore/stream.h"
67 #include "MagickCore/string_.h"
68 #include "MagickCore/transform.h"
69 #include "MagickCore/utility.h"
71 #define LogPixelChannels(image) \
76 (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%.20g]", \
77 image->filename,(double) image->number_channels); \
78 for (i=0; i < (ssize_t) image->number_channels; i++) \
81 traits[MaxTextExtent]; \
89 switch (GetPixelChannelMapChannel(image,i)) \
91 case RedPixelChannel: \
94 if (image->colorspace == CMYKColorspace) \
96 if (image->colorspace == GRAYColorspace) \
100 case GreenPixelChannel: \
103 if (image->colorspace == CMYKColorspace) \
107 case BluePixelChannel: \
110 if (image->colorspace == CMYKColorspace) \
114 case BlackPixelChannel: \
117 if (image->storage_class == PseudoClass) \
121 case IndexPixelChannel: \
126 case AlphaPixelChannel: \
131 case MaskPixelChannel: \
136 case MetaPixelChannel: \
144 channel=GetPixelChannelMapChannel(image,i); \
146 if ((GetPixelChannelMapTraits(image,channel) & UpdatePixelTrait) != 0) \
147 (void) ConcatenateMagickString(traits,"update,",MaxTextExtent); \
148 if ((GetPixelChannelMapTraits(image,channel) & BlendPixelTrait) != 0) \
149 (void) ConcatenateMagickString(traits,"blend,",MaxTextExtent); \
150 if ((GetPixelChannelMapTraits(image,channel) & CopyPixelTrait) != 0) \
151 (void) ConcatenateMagickString(traits,"copy,",MaxTextExtent); \
152 if (*traits == '\0') \
153 (void) ConcatenateMagickString(traits,"undefined,",MaxTextExtent); \
154 traits[strlen(traits)-1]='\0'; \
155 (void) LogMagickEvent(PixelEvent,GetMagickModule()," %.20g: %s (%s)", \
156 (double) i,name,traits); \
161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165 + A c q u i r e P i x e l C h a n n e l M a p %
169 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171 % AcquirePixelChannelMap() acquires a pixel component map.
173 % The format of the AcquirePixelChannelMap() method is:
175 % PixelChannelMap *AcquirePixelChannelMap(void)
178 MagickExport PixelChannelMap *AcquirePixelChannelMap(void)
186 channel_map=(PixelChannelMap *) AcquireQuantumMemory(MaxPixelChannels,
187 sizeof(*channel_map));
188 if (channel_map == (PixelChannelMap *) NULL)
189 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
190 (void) ResetMagickMemory(channel_map,0,MaxPixelChannels*sizeof(*channel_map));
191 for (i=0; i < MaxPixelChannels; i++)
192 channel_map[i].channel=(PixelChannel) i;
197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 + C l o n e P i x e l C h a n n e l M a p %
205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
207 % ClonePixelChannelMap() clones a pixel component map.
209 % The format of the ClonePixelChannelMap() method is:
211 % PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
213 % A description of each parameter follows:
215 % o channel_map: the pixel component map.
218 MagickExport PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
223 assert(channel_map != (PixelChannelMap *) NULL);
224 clone_map=AcquirePixelChannelMap();
225 if (clone_map == (PixelChannelMap *) NULL)
226 return((PixelChannelMap *) NULL);
227 (void) CopyMagickMemory(clone_map,channel_map,MaxPixelChannels*
228 sizeof(*channel_map));
233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
237 + C l o n e P i x e l I n f o %
241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243 % ClonePixelInfo() makes a duplicate of the given pixel info structure, or if
244 % pixel info is NULL, a new one.
246 % The format of the ClonePixelInfo method is:
248 % PixelInfo *ClonePixelInfo(const PixelInfo *pixel_info)
250 % A description of each parameter follows:
252 % o pixel_info: the pixel info.
255 MagickExport PixelInfo *ClonePixelInfo(const PixelInfo *pixel)
260 pixel_info=(PixelInfo *) AcquireQuantumMemory(1,sizeof(*pixel_info));
261 if (pixel_info == (PixelInfo *) NULL)
262 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
263 *pixel_info=(*pixel);
268 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
272 + D e s t r o y P i x e l C h a n n e l M a p %
276 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278 % DestroyPixelChannelMap() deallocates memory associated with the pixel
281 % The format of the DestroyPixelChannelMap() method is:
283 % PixelChannelMap *DestroyPixelChannelMap(PixelChannelMap *channel_map)
285 % A description of each parameter follows:
287 % o channel_map: the pixel component map.
290 MagickExport PixelChannelMap *DestroyPixelChannelMap(
291 PixelChannelMap *channel_map)
293 assert(channel_map != (PixelChannelMap *) NULL);
294 channel_map=(PixelChannelMap *) RelinquishMagickMemory(channel_map);
295 return((PixelChannelMap *) RelinquishMagickMemory(channel_map));
299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
303 % E x p o r t I m a g e P i x e l s %
307 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309 % ExportImagePixels() extracts pixel data from an image and returns it to you.
310 % The method returns MagickTrue on success otherwise MagickFalse if an error is
311 % encountered. The data is returned as char, short int, Quantum, unsigned int,
312 % unsigned long long, float, or double in the order specified by map.
314 % Suppose you want to extract the first scanline of a 640x480 image as
315 % character data in red-green-blue order:
317 % ExportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels,exception);
319 % The format of the ExportImagePixels method is:
321 % MagickBooleanType ExportImagePixels(const Image *image,const ssize_t x,
322 % const ssize_t y,const size_t width,const size_t height,
323 % const char *map,const StorageType type,void *pixels,
324 % ExceptionInfo *exception)
326 % A description of each parameter follows:
328 % o image: the image.
330 % o x,y,width,height: These values define the perimeter
331 % of a region of pixels you want to extract.
333 % o map: This string reflects the expected ordering of the pixel array.
334 % It can be any combination or order of R = red, G = green, B = blue,
335 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
336 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
339 % o type: Define the data type of the pixels. Float and double types are
340 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
341 % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *),
342 % LongPixel (unsigned int *), LongLongPixel (unsigned long long *),
343 % QuantumPixel (Quantum *), or ShortPixel (unsigned short *).
345 % o pixels: This array of values contain the pixel components as defined by
346 % map and type. You must preallocate this array where the expected
347 % length varies depending on the values of width, height, map, and type.
349 % o exception: return any errors or warnings in this structure.
353 static void ExportCharPixel(const Image *image,const RectangleInfo *roi,
354 const char *restrict map,const QuantumType *quantum_map,void *pixels,
355 ExceptionInfo *exception)
357 register const Quantum
363 register unsigned char
369 q=(unsigned char *) pixels;
370 if (LocaleCompare(map,"BGR") == 0)
372 for (y=0; y < (ssize_t) roi->height; y++)
374 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
375 if (p == (const Quantum *) NULL)
377 for (x=0; x < (ssize_t) roi->width; x++)
379 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
380 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
381 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
382 p+=GetPixelChannels(image);
387 if (LocaleCompare(map,"BGRA") == 0)
389 for (y=0; y < (ssize_t) roi->height; y++)
391 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
392 if (p == (const Quantum *) NULL)
394 for (x=0; x < (ssize_t) roi->width; x++)
396 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
397 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
398 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
399 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
400 p+=GetPixelChannels(image);
405 if (LocaleCompare(map,"BGRP") == 0)
407 for (y=0; y < (ssize_t) roi->height; y++)
409 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
410 if (p == (const Quantum *) NULL)
412 for (x=0; x < (ssize_t) roi->width; x++)
414 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
415 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
416 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
417 *q++=ScaleQuantumToChar((Quantum) 0);
418 p+=GetPixelChannels(image);
423 if (LocaleCompare(map,"I") == 0)
425 for (y=0; y < (ssize_t) roi->height; y++)
427 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
428 if (p == (const Quantum *) NULL)
430 for (x=0; x < (ssize_t) roi->width; x++)
432 *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
433 p+=GetPixelChannels(image);
438 if (LocaleCompare(map,"RGB") == 0)
440 for (y=0; y < (ssize_t) roi->height; y++)
442 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
443 if (p == (const Quantum *) NULL)
445 for (x=0; x < (ssize_t) roi->width; x++)
447 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
448 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
449 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
450 p+=GetPixelChannels(image);
455 if (LocaleCompare(map,"RGBA") == 0)
457 for (y=0; y < (ssize_t) roi->height; y++)
459 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
460 if (p == (const Quantum *) NULL)
462 for (x=0; x < (ssize_t) roi->width; x++)
464 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
465 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
466 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
467 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
468 p+=GetPixelChannels(image);
473 if (LocaleCompare(map,"RGBP") == 0)
475 for (y=0; y < (ssize_t) roi->height; y++)
477 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
478 if (p == (const Quantum *) NULL)
480 for (x=0; x < (ssize_t) roi->width; x++)
482 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
483 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
484 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
485 *q++=ScaleQuantumToChar((Quantum) 0);
486 p+=GetPixelChannels(image);
491 for (y=0; y < (ssize_t) roi->height; y++)
493 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
494 if (p == (const Quantum *) NULL)
496 for (x=0; x < (ssize_t) roi->width; x++)
501 for (i=0; i < (ssize_t) strlen(map); i++)
504 switch (quantum_map[i])
509 *q=ScaleQuantumToChar(GetPixelRed(image,p));
515 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
521 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
526 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
531 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
536 if (image->colorspace == CMYKColorspace)
537 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
542 *q=ScaleQuantumToChar(GetPixelIntensity(image,p));
550 p+=GetPixelChannels(image);
555 static void ExportDoublePixel(const Image *image,const RectangleInfo *roi,
556 const char *restrict map,const QuantumType *quantum_map,void *pixels,
557 ExceptionInfo *exception)
559 register const Quantum
572 if (LocaleCompare(map,"BGR") == 0)
574 for (y=0; y < (ssize_t) roi->height; y++)
576 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
577 if (p == (const Quantum *) NULL)
579 for (x=0; x < (ssize_t) roi->width; x++)
581 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
582 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
583 *q++=(double) (QuantumScale*GetPixelRed(image,p));
584 p+=GetPixelChannels(image);
589 if (LocaleCompare(map,"BGRA") == 0)
591 for (y=0; y < (ssize_t) roi->height; y++)
593 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
594 if (p == (const Quantum *) NULL)
596 for (x=0; x < (ssize_t) roi->width; x++)
598 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
599 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
600 *q++=(double) (QuantumScale*GetPixelRed(image,p));
601 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
602 p+=GetPixelChannels(image);
607 if (LocaleCompare(map,"BGRP") == 0)
609 for (y=0; y < (ssize_t) roi->height; y++)
611 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
612 if (p == (const Quantum *) NULL)
614 for (x=0; x < (ssize_t) roi->width; x++)
616 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
617 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
618 *q++=(double) (QuantumScale*GetPixelRed(image,p));
620 p+=GetPixelChannels(image);
625 if (LocaleCompare(map,"I") == 0)
627 for (y=0; y < (ssize_t) roi->height; y++)
629 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
630 if (p == (const Quantum *) NULL)
632 for (x=0; x < (ssize_t) roi->width; x++)
634 *q++=(double) (QuantumScale*GetPixelIntensity(image,p));
635 p+=GetPixelChannels(image);
640 if (LocaleCompare(map,"RGB") == 0)
642 for (y=0; y < (ssize_t) roi->height; y++)
644 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
645 if (p == (const Quantum *) NULL)
647 for (x=0; x < (ssize_t) roi->width; x++)
649 *q++=(double) (QuantumScale*GetPixelRed(image,p));
650 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
651 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
652 p+=GetPixelChannels(image);
657 if (LocaleCompare(map,"RGBA") == 0)
659 for (y=0; y < (ssize_t) roi->height; y++)
661 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
662 if (p == (const Quantum *) NULL)
664 for (x=0; x < (ssize_t) roi->width; x++)
666 *q++=(double) (QuantumScale*GetPixelRed(image,p));
667 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
668 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
669 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
670 p+=GetPixelChannels(image);
675 if (LocaleCompare(map,"RGBP") == 0)
677 for (y=0; y < (ssize_t) roi->height; y++)
679 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
680 if (p == (const Quantum *) NULL)
682 for (x=0; x < (ssize_t) roi->width; x++)
684 *q++=(double) (QuantumScale*GetPixelRed(image,p));
685 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
686 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
688 p+=GetPixelChannels(image);
693 for (y=0; y < (ssize_t) roi->height; y++)
695 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
696 if (p == (const Quantum *) NULL)
698 for (x=0; x < (ssize_t) roi->width; x++)
703 for (i=0; i < (ssize_t) strlen(map); i++)
706 switch (quantum_map[i])
711 *q=(double) (QuantumScale*GetPixelRed(image,p));
717 *q=(double) (QuantumScale*GetPixelGreen(image,p));
723 *q=(double) (QuantumScale*GetPixelBlue(image,p));
728 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
733 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
738 if (image->colorspace == CMYKColorspace)
739 *q=(double) (QuantumScale*
740 GetPixelBlack(image,p));
745 *q=(double) (QuantumScale*GetPixelIntensity(image,p));
753 p+=GetPixelChannels(image);
758 static void ExportFloatPixel(const Image *image,const RectangleInfo *roi,
759 const char *restrict map,const QuantumType *quantum_map,void *pixels,
760 ExceptionInfo *exception)
762 register const Quantum
775 if (LocaleCompare(map,"BGR") == 0)
777 for (y=0; y < (ssize_t) roi->height; y++)
779 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
780 if (p == (const Quantum *) NULL)
782 for (x=0; x < (ssize_t) roi->width; x++)
784 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
785 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
786 *q++=(float) (QuantumScale*GetPixelRed(image,p));
787 p+=GetPixelChannels(image);
792 if (LocaleCompare(map,"BGRA") == 0)
794 for (y=0; y < (ssize_t) roi->height; y++)
796 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
797 if (p == (const Quantum *) NULL)
799 for (x=0; x < (ssize_t) roi->width; x++)
801 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
802 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
803 *q++=(float) (QuantumScale*GetPixelRed(image,p));
804 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
805 p+=GetPixelChannels(image);
810 if (LocaleCompare(map,"BGRP") == 0)
812 for (y=0; y < (ssize_t) roi->height; y++)
814 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
815 if (p == (const Quantum *) NULL)
817 for (x=0; x < (ssize_t) roi->width; x++)
819 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
820 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
821 *q++=(float) (QuantumScale*GetPixelRed(image,p));
823 p+=GetPixelChannels(image);
828 if (LocaleCompare(map,"I") == 0)
830 for (y=0; y < (ssize_t) roi->height; y++)
832 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
833 if (p == (const Quantum *) NULL)
835 for (x=0; x < (ssize_t) roi->width; x++)
837 *q++=(float) (QuantumScale*GetPixelIntensity(image,p));
838 p+=GetPixelChannels(image);
843 if (LocaleCompare(map,"RGB") == 0)
845 for (y=0; y < (ssize_t) roi->height; y++)
847 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
848 if (p == (const Quantum *) NULL)
850 for (x=0; x < (ssize_t) roi->width; x++)
852 *q++=(float) (QuantumScale*GetPixelRed(image,p));
853 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
854 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
855 p+=GetPixelChannels(image);
860 if (LocaleCompare(map,"RGBA") == 0)
862 for (y=0; y < (ssize_t) roi->height; y++)
864 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
865 if (p == (const Quantum *) NULL)
867 for (x=0; x < (ssize_t) roi->width; x++)
869 *q++=(float) (QuantumScale*GetPixelRed(image,p));
870 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
871 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
872 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
873 p+=GetPixelChannels(image);
878 if (LocaleCompare(map,"RGBP") == 0)
880 for (y=0; y < (ssize_t) roi->height; y++)
882 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
883 if (p == (const Quantum *) NULL)
885 for (x=0; x < (ssize_t) roi->width; x++)
887 *q++=(float) (QuantumScale*GetPixelRed(image,p));
888 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
889 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
891 p+=GetPixelChannels(image);
896 for (y=0; y < (ssize_t) roi->height; y++)
898 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
899 if (p == (const Quantum *) NULL)
901 for (x=0; x < (ssize_t) roi->width; x++)
906 for (i=0; i < (ssize_t) strlen(map); i++)
909 switch (quantum_map[i])
914 *q=(float) (QuantumScale*GetPixelRed(image,p));
920 *q=(float) (QuantumScale*GetPixelGreen(image,p));
926 *q=(float) (QuantumScale*GetPixelBlue(image,p));
931 *q=(float) (QuantumScale*((Quantum) (GetPixelAlpha(image,p))));
936 *q=(float) (QuantumScale*GetPixelAlpha(image,p));
941 if (image->colorspace == CMYKColorspace)
942 *q=(float) (QuantumScale* GetPixelBlack(image,p));
947 *q=(float) (QuantumScale*GetPixelIntensity(image,p));
955 p+=GetPixelChannels(image);
960 static void ExportLongPixel(const Image *image,const RectangleInfo *roi,
961 const char *restrict map,const QuantumType *quantum_map,void *pixels,
962 ExceptionInfo *exception)
964 register const Quantum
970 register unsigned int
976 q=(unsigned int *) pixels;
977 if (LocaleCompare(map,"BGR") == 0)
979 for (y=0; y < (ssize_t) roi->height; y++)
981 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
982 if (p == (const Quantum *) NULL)
984 for (x=0; x < (ssize_t) roi->width; x++)
986 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
987 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
988 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
989 p+=GetPixelChannels(image);
994 if (LocaleCompare(map,"BGRA") == 0)
996 for (y=0; y < (ssize_t) roi->height; y++)
998 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
999 if (p == (const Quantum *) NULL)
1001 for (x=0; x < (ssize_t) roi->width; x++)
1003 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1004 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1005 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1006 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1007 p+=GetPixelChannels(image);
1012 if (LocaleCompare(map,"BGRP") == 0)
1014 for (y=0; y < (ssize_t) roi->height; y++)
1016 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1017 if (p == (const Quantum *) NULL)
1019 for (x=0; x < (ssize_t) roi->width; x++)
1021 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1022 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1023 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1025 p+=GetPixelChannels(image);
1030 if (LocaleCompare(map,"I") == 0)
1032 for (y=0; y < (ssize_t) roi->height; y++)
1034 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1035 if (p == (const Quantum *) NULL)
1037 for (x=0; x < (ssize_t) roi->width; x++)
1039 *q++=ScaleQuantumToLong(GetPixelIntensity(image,p));
1040 p+=GetPixelChannels(image);
1045 if (LocaleCompare(map,"RGB") == 0)
1047 for (y=0; y < (ssize_t) roi->height; y++)
1049 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1050 if (p == (const Quantum *) NULL)
1052 for (x=0; x < (ssize_t) roi->width; x++)
1054 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1055 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1056 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1057 p+=GetPixelChannels(image);
1062 if (LocaleCompare(map,"RGBA") == 0)
1064 for (y=0; y < (ssize_t) roi->height; y++)
1066 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1067 if (p == (const Quantum *) NULL)
1069 for (x=0; x < (ssize_t) roi->width; x++)
1071 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1072 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1073 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1074 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1075 p+=GetPixelChannels(image);
1080 if (LocaleCompare(map,"RGBP") == 0)
1082 for (y=0; y < (ssize_t) roi->height; y++)
1084 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1085 if (p == (const Quantum *) NULL)
1087 for (x=0; x < (ssize_t) roi->width; x++)
1089 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1090 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1091 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1093 p+=GetPixelChannels(image);
1098 for (y=0; y < (ssize_t) roi->height; y++)
1100 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1101 if (p == (const Quantum *) NULL)
1103 for (x=0; x < (ssize_t) roi->width; x++)
1108 for (i=0; i < (ssize_t) strlen(map); i++)
1111 switch (quantum_map[i])
1116 *q=ScaleQuantumToLong(GetPixelRed(image,p));
1120 case MagentaQuantum:
1122 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
1128 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
1133 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1136 case OpacityQuantum:
1138 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1143 if (image->colorspace == CMYKColorspace)
1144 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
1149 *q=ScaleQuantumToLong(GetPixelIntensity(image,p));
1157 p+=GetPixelChannels(image);
1162 static void ExportLongLongPixel(const Image *image,const RectangleInfo *roi,
1163 const char *restrict map,const QuantumType *quantum_map,void *pixels,
1164 ExceptionInfo *exception)
1166 register const Quantum
1172 register MagickSizeType
1178 q=(MagickSizeType *) pixels;
1179 if (LocaleCompare(map,"BGR") == 0)
1181 for (y=0; y < (ssize_t) roi->height; y++)
1183 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1184 if (p == (const Quantum *) NULL)
1186 for (x=0; x < (ssize_t) roi->width; x++)
1188 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1189 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1190 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1191 p+=GetPixelChannels(image);
1196 if (LocaleCompare(map,"BGRA") == 0)
1198 for (y=0; y < (ssize_t) roi->height; y++)
1200 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1201 if (p == (const Quantum *) NULL)
1203 for (x=0; x < (ssize_t) roi->width; x++)
1205 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1206 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1207 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1208 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1209 p+=GetPixelChannels(image);
1214 if (LocaleCompare(map,"BGRP") == 0)
1216 for (y=0; y < (ssize_t) roi->height; y++)
1218 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1219 if (p == (const Quantum *) NULL)
1221 for (x=0; x < (ssize_t) roi->width; x++)
1223 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1224 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1225 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1227 p+=GetPixelChannels(image);
1232 if (LocaleCompare(map,"I") == 0)
1234 for (y=0; y < (ssize_t) roi->height; y++)
1236 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1237 if (p == (const Quantum *) NULL)
1239 for (x=0; x < (ssize_t) roi->width; x++)
1241 *q++=ScaleQuantumToLongLong(GetPixelIntensity(image,p));
1242 p+=GetPixelChannels(image);
1247 if (LocaleCompare(map,"RGB") == 0)
1249 for (y=0; y < (ssize_t) roi->height; y++)
1251 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1252 if (p == (const Quantum *) NULL)
1254 for (x=0; x < (ssize_t) roi->width; x++)
1256 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1257 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1258 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1259 p+=GetPixelChannels(image);
1264 if (LocaleCompare(map,"RGBA") == 0)
1266 for (y=0; y < (ssize_t) roi->height; y++)
1268 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1269 if (p == (const Quantum *) NULL)
1271 for (x=0; x < (ssize_t) roi->width; x++)
1273 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1274 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1275 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1276 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1277 p+=GetPixelChannels(image);
1282 if (LocaleCompare(map,"RGBP") == 0)
1284 for (y=0; y < (ssize_t) roi->height; y++)
1286 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1287 if (p == (const Quantum *) NULL)
1289 for (x=0; x < (ssize_t) roi->width; x++)
1291 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1292 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1293 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1295 p+=GetPixelChannels(image);
1300 for (y=0; y < (ssize_t) roi->height; y++)
1302 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1303 if (p == (const Quantum *) NULL)
1305 for (x=0; x < (ssize_t) roi->width; x++)
1310 for (i=0; i < (ssize_t) strlen(map); i++)
1313 switch (quantum_map[i])
1318 *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
1322 case MagentaQuantum:
1324 *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1330 *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1335 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1338 case OpacityQuantum:
1340 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1345 if (image->colorspace == CMYKColorspace)
1346 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
1351 *q=ScaleQuantumToLongLong(GetPixelIntensity(image,p));
1359 p+=GetPixelChannels(image);
1364 static void ExportQuantumPixel(const Image *image,const RectangleInfo *roi,
1365 const char *restrict map,const QuantumType *quantum_map,void *pixels,
1366 ExceptionInfo *exception)
1368 register const Quantum
1380 q=(Quantum *) pixels;
1381 if (LocaleCompare(map,"BGR") == 0)
1383 for (y=0; y < (ssize_t) roi->height; y++)
1385 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1386 if (p == (const Quantum *) NULL)
1388 for (x=0; x < (ssize_t) roi->width; x++)
1390 *q++=GetPixelBlue(image,p);
1391 *q++=GetPixelGreen(image,p);
1392 *q++=GetPixelRed(image,p);
1393 p+=GetPixelChannels(image);
1398 if (LocaleCompare(map,"BGRA") == 0)
1400 for (y=0; y < (ssize_t) roi->height; y++)
1402 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1403 if (p == (const Quantum *) NULL)
1405 for (x=0; x < (ssize_t) roi->width; x++)
1407 *q++=GetPixelBlue(image,p);
1408 *q++=GetPixelGreen(image,p);
1409 *q++=GetPixelRed(image,p);
1410 *q++=(Quantum) (GetPixelAlpha(image,p));
1411 p+=GetPixelChannels(image);
1416 if (LocaleCompare(map,"BGRP") == 0)
1418 for (y=0; y < (ssize_t) roi->height; y++)
1420 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1421 if (p == (const Quantum *) NULL)
1423 for (x=0; x < (ssize_t) roi->width; x++)
1425 *q++=GetPixelBlue(image,p);
1426 *q++=GetPixelGreen(image,p);
1427 *q++=GetPixelRed(image,p);
1429 p+=GetPixelChannels(image);
1434 if (LocaleCompare(map,"I") == 0)
1436 for (y=0; y < (ssize_t) roi->height; y++)
1438 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1439 if (p == (const Quantum *) NULL)
1441 for (x=0; x < (ssize_t) roi->width; x++)
1443 *q++=GetPixelIntensity(image,p);
1444 p+=GetPixelChannels(image);
1449 if (LocaleCompare(map,"RGB") == 0)
1451 for (y=0; y < (ssize_t) roi->height; y++)
1453 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1454 if (p == (const Quantum *) NULL)
1456 for (x=0; x < (ssize_t) roi->width; x++)
1458 *q++=GetPixelRed(image,p);
1459 *q++=GetPixelGreen(image,p);
1460 *q++=GetPixelBlue(image,p);
1461 p+=GetPixelChannels(image);
1466 if (LocaleCompare(map,"RGBA") == 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++=GetPixelRed(image,p);
1476 *q++=GetPixelGreen(image,p);
1477 *q++=GetPixelBlue(image,p);
1478 *q++=(Quantum) (GetPixelAlpha(image,p));
1479 p+=GetPixelChannels(image);
1484 if (LocaleCompare(map,"RGBP") == 0)
1486 for (y=0; y < (ssize_t) roi->height; y++)
1488 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1489 if (p == (const Quantum *) NULL)
1491 for (x=0; x < (ssize_t) roi->width; x++)
1493 *q++=GetPixelRed(image,p);
1494 *q++=GetPixelGreen(image,p);
1495 *q++=GetPixelBlue(image,p);
1497 p+=GetPixelChannels(image);
1502 for (y=0; y < (ssize_t) roi->height; y++)
1504 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1505 if (p == (const Quantum *) NULL)
1507 for (x=0; x < (ssize_t) roi->width; x++)
1512 for (i=0; i < (ssize_t) strlen(map); i++)
1515 switch (quantum_map[i])
1520 *q=GetPixelRed(image,p);
1524 case MagentaQuantum:
1526 *q=GetPixelGreen(image,p);
1532 *q=GetPixelBlue(image,p);
1537 *q=GetPixelAlpha(image,p);
1540 case OpacityQuantum:
1542 *q=GetPixelAlpha(image,p);
1547 if (image->colorspace == CMYKColorspace)
1548 *q=GetPixelBlack(image,p);
1553 *q=(GetPixelIntensity(image,p));
1564 p+=GetPixelChannels(image);
1569 static void ExportShortPixel(const Image *image,const RectangleInfo *roi,
1570 const char *restrict map,const QuantumType *quantum_map,void *pixels,
1571 ExceptionInfo *exception)
1573 register const Quantum
1582 register unsigned short
1585 q=(unsigned short *) pixels;
1586 if (LocaleCompare(map,"BGR") == 0)
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++)
1595 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1596 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1597 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1598 p+=GetPixelChannels(image);
1603 if (LocaleCompare(map,"BGRA") == 0)
1605 for (y=0; y < (ssize_t) roi->height; y++)
1607 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1608 if (p == (const Quantum *) NULL)
1610 for (x=0; x < (ssize_t) roi->width; x++)
1612 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1613 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1614 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1615 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1616 p+=GetPixelChannels(image);
1621 if (LocaleCompare(map,"BGRP") == 0)
1623 for (y=0; y < (ssize_t) roi->height; y++)
1625 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1626 if (p == (const Quantum *) NULL)
1628 for (x=0; x < (ssize_t) roi->width; x++)
1630 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1631 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1632 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1634 p+=GetPixelChannels(image);
1639 if (LocaleCompare(map,"I") == 0)
1641 for (y=0; y < (ssize_t) roi->height; y++)
1643 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1644 if (p == (const Quantum *) NULL)
1646 for (x=0; x < (ssize_t) roi->width; x++)
1648 *q++=ScaleQuantumToShort(GetPixelIntensity(image,p));
1649 p+=GetPixelChannels(image);
1654 if (LocaleCompare(map,"RGB") == 0)
1656 for (y=0; y < (ssize_t) roi->height; y++)
1658 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1659 if (p == (const Quantum *) NULL)
1661 for (x=0; x < (ssize_t) roi->width; x++)
1663 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1664 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1665 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1666 p+=GetPixelChannels(image);
1671 if (LocaleCompare(map,"RGBA") == 0)
1673 for (y=0; y < (ssize_t) roi->height; y++)
1675 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1676 if (p == (const Quantum *) NULL)
1678 for (x=0; x < (ssize_t) roi->width; x++)
1680 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1681 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1682 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1683 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1684 p+=GetPixelChannels(image);
1689 if (LocaleCompare(map,"RGBP") == 0)
1691 for (y=0; y < (ssize_t) roi->height; y++)
1693 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1694 if (p == (const Quantum *) NULL)
1696 for (x=0; x < (ssize_t) roi->width; x++)
1698 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1699 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1700 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1702 p+=GetPixelChannels(image);
1707 for (y=0; y < (ssize_t) roi->height; y++)
1709 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1710 if (p == (const Quantum *) NULL)
1712 for (x=0; x < (ssize_t) roi->width; x++)
1717 for (i=0; i < (ssize_t) strlen(map); i++)
1720 switch (quantum_map[i])
1725 *q=ScaleQuantumToShort(GetPixelRed(image,p));
1729 case MagentaQuantum:
1731 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
1737 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
1742 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1745 case OpacityQuantum:
1747 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1752 if (image->colorspace == CMYKColorspace)
1753 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
1758 *q=ScaleQuantumToShort(GetPixelIntensity(image,p));
1766 p+=GetPixelChannels(image);
1771 MagickExport MagickBooleanType ExportImagePixels(const Image *image,
1772 const ssize_t x,const ssize_t y,const size_t width,const size_t height,
1773 const char *map,const StorageType type,void *pixels,ExceptionInfo *exception)
1784 assert(image != (Image *) NULL);
1785 assert(image->signature == MagickSignature);
1786 if (image->debug != MagickFalse)
1787 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1788 quantum_map=(QuantumType *) AcquireQuantumMemory(strlen(map),
1789 sizeof(*quantum_map));
1790 if (quantum_map == (QuantumType *) NULL)
1792 (void) ThrowMagickException(exception,GetMagickModule(),
1793 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1794 return(MagickFalse);
1796 for (i=0; i < (ssize_t) strlen(map); i++)
1803 quantum_map[i]=AlphaQuantum;
1809 quantum_map[i]=BlueQuantum;
1815 quantum_map[i]=CyanQuantum;
1816 if (image->colorspace == CMYKColorspace)
1818 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1819 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1820 "ColorSeparatedImageRequired","`%s'",map);
1821 return(MagickFalse);
1826 quantum_map[i]=GreenQuantum;
1832 quantum_map[i]=IndexQuantum;
1838 quantum_map[i]=BlackQuantum;
1839 if (image->colorspace == CMYKColorspace)
1841 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1842 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1843 "ColorSeparatedImageRequired","`%s'",map);
1844 return(MagickFalse);
1849 quantum_map[i]=MagentaQuantum;
1850 if (image->colorspace == CMYKColorspace)
1852 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1853 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1854 "ColorSeparatedImageRequired","`%s'",map);
1855 return(MagickFalse);
1860 quantum_map[i]=OpacityQuantum;
1866 quantum_map[i]=UndefinedQuantum;
1872 quantum_map[i]=RedQuantum;
1878 quantum_map[i]=YellowQuantum;
1879 if (image->colorspace == CMYKColorspace)
1881 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1882 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1883 "ColorSeparatedImageRequired","`%s'",map);
1884 return(MagickFalse);
1888 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1889 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1890 "UnrecognizedPixelMap","`%s'",map);
1891 return(MagickFalse);
1903 ExportCharPixel(image,&roi,map,quantum_map,pixels,exception);
1908 ExportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
1913 ExportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
1918 ExportLongPixel(image,&roi,map,quantum_map,pixels,exception);
1923 ExportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
1928 ExportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
1933 ExportShortPixel(image,&roi,map,quantum_map,pixels,exception);
1938 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1939 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1940 "UnrecognizedPixelMap","`%s'",map);
1944 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1949 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1953 % G e t P i x e l I n f o %
1957 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1959 % GetPixelInfo() initializes the PixelInfo structure.
1961 % The format of the GetPixelInfo method is:
1963 % GetPixelInfo(const Image *image,PixelInfo *pixel)
1965 % A description of each parameter follows:
1967 % o image: the image.
1969 % o pixel: Specifies a pointer to a PixelInfo structure.
1972 MagickExport void GetPixelInfo(const Image *image,PixelInfo *pixel)
1974 pixel->storage_class=DirectClass;
1975 pixel->colorspace=RGBColorspace;
1976 pixel->matte=MagickFalse;
1978 pixel->depth=MAGICKCORE_QUANTUM_DEPTH;
1983 pixel->alpha=(MagickRealType) OpaqueAlpha;
1985 if (image == (const Image *) NULL)
1987 pixel->storage_class=image->storage_class;
1988 pixel->colorspace=image->colorspace;
1989 pixel->matte=image->matte;
1990 pixel->depth=image->depth;
1991 pixel->fuzz=image->fuzz;
1995 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999 % I m p o r t I m a g e P i x e l s %
2003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2005 % ImportImagePixels() accepts pixel data and stores in the image at the
2006 % location you specify. The method returns MagickTrue on success otherwise
2007 % MagickFalse if an error is encountered. The pixel data can be either char,
2008 % Quantum, short int, unsigned int, unsigned long long, float, or double in
2009 % the order specified by map.
2011 % Suppose your want to upload the first scanline of a 640x480 image from
2012 % character data in red-green-blue order:
2014 % ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels);
2016 % The format of the ImportImagePixels method is:
2018 % MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
2019 % const ssize_t y,const size_t width,const size_t height,
2020 % const char *map,const StorageType type,const void *pixels,
2021 % ExceptionInfo *exception)
2023 % A description of each parameter follows:
2025 % o image: the image.
2027 % o x,y,width,height: These values define the perimeter
2028 % of a region of pixels you want to define.
2030 % o map: This string reflects the expected ordering of the pixel array.
2031 % It can be any combination or order of R = red, G = green, B = blue,
2032 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
2033 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
2036 % o type: Define the data type of the pixels. Float and double types are
2037 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
2038 % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *),
2039 % LongPixel (unsigned int *), LongLongPixel (unsigned long long *),
2040 % QuantumPixel (Quantum *), or ShortPixel (unsigned short *).
2042 % o pixels: This array of values contain the pixel components as defined by
2043 % map and type. You must preallocate this array where the expected
2044 % length varies depending on the values of width, height, map, and type.
2046 % o exception: return any errors or warnings in this structure.
2050 static void ImportCharPixel(Image *image,const RectangleInfo *roi,
2051 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2052 ExceptionInfo *exception)
2054 register const unsigned char
2066 p=(const unsigned char *) pixels;
2067 if (LocaleCompare(map,"BGR") == 0)
2069 for (y=0; y < (ssize_t) roi->height; y++)
2071 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2072 if (q == (Quantum *) NULL)
2074 for (x=0; x < (ssize_t) roi->width; x++)
2076 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2077 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2078 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2079 q+=GetPixelChannels(image);
2081 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2086 if (LocaleCompare(map,"BGRA") == 0)
2088 for (y=0; y < (ssize_t) roi->height; y++)
2090 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2091 if (q == (Quantum *) NULL)
2093 for (x=0; x < (ssize_t) roi->width; x++)
2095 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2096 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2097 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2098 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2099 q+=GetPixelChannels(image);
2101 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2106 if (LocaleCompare(map,"BGRO") == 0)
2108 for (y=0; y < (ssize_t) roi->height; y++)
2110 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2111 if (q == (Quantum *) NULL)
2113 for (x=0; x < (ssize_t) roi->width; x++)
2115 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2116 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2117 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2118 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2119 q+=GetPixelChannels(image);
2121 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2126 if (LocaleCompare(map,"BGRP") == 0)
2128 for (y=0; y < (ssize_t) roi->height; y++)
2130 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2131 if (q == (Quantum *) NULL)
2133 for (x=0; x < (ssize_t) roi->width; x++)
2135 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2136 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2137 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2139 q+=GetPixelChannels(image);
2141 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2146 if (LocaleCompare(map,"I") == 0)
2148 for (y=0; y < (ssize_t) roi->height; y++)
2150 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2151 if (q == (Quantum *) NULL)
2153 for (x=0; x < (ssize_t) roi->width; x++)
2155 SetPixelGray(image,ScaleCharToQuantum(*p++),q);
2156 q+=GetPixelChannels(image);
2158 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2163 if (LocaleCompare(map,"RGB") == 0)
2165 for (y=0; y < (ssize_t) roi->height; y++)
2167 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2168 if (q == (Quantum *) NULL)
2170 for (x=0; x < (ssize_t) roi->width; x++)
2172 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2173 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2174 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2175 q+=GetPixelChannels(image);
2177 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2182 if (LocaleCompare(map,"RGBA") == 0)
2184 for (y=0; y < (ssize_t) roi->height; y++)
2186 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2187 if (q == (Quantum *) NULL)
2189 for (x=0; x < (ssize_t) roi->width; x++)
2191 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2192 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2193 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2194 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2195 q+=GetPixelChannels(image);
2197 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2202 if (LocaleCompare(map,"RGBO") == 0)
2204 for (y=0; y < (ssize_t) roi->height; y++)
2206 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2207 if (q == (Quantum *) NULL)
2209 for (x=0; x < (ssize_t) roi->width; x++)
2211 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2212 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2213 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2214 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2215 q+=GetPixelChannels(image);
2217 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2222 if (LocaleCompare(map,"RGBP") == 0)
2224 for (y=0; y < (ssize_t) roi->height; y++)
2226 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2227 if (q == (Quantum *) NULL)
2229 for (x=0; x < (ssize_t) roi->width; x++)
2231 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2232 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2233 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2235 q+=GetPixelChannels(image);
2237 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2242 for (y=0; y < (ssize_t) roi->height; y++)
2244 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2245 if (q == (Quantum *) NULL)
2247 for (x=0; x < (ssize_t) roi->width; x++)
2252 for (i=0; i < (ssize_t) strlen(map); i++)
2254 switch (quantum_map[i])
2259 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2263 case MagentaQuantum:
2265 SetPixelGreen(image,ScaleCharToQuantum(*p),q);
2271 SetPixelBlue(image,ScaleCharToQuantum(*p),q);
2276 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2279 case OpacityQuantum:
2281 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2286 SetPixelBlack(image,ScaleCharToQuantum(*p),q);
2291 SetPixelGray(image,ScaleCharToQuantum(*p),q);
2299 q+=GetPixelChannels(image);
2301 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2306 static void ImportDoublePixel(Image *image,const RectangleInfo *roi,
2307 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2308 ExceptionInfo *exception)
2310 register const double
2322 p=(const double *) pixels;
2323 if (LocaleCompare(map,"BGR") == 0)
2325 for (y=0; y < (ssize_t) roi->height; y++)
2327 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2328 if (q == (Quantum *) NULL)
2330 for (x=0; x < (ssize_t) roi->width; x++)
2332 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2335 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2338 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2341 q+=GetPixelChannels(image);
2343 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2348 if (LocaleCompare(map,"BGRA") == 0)
2350 for (y=0; y < (ssize_t) roi->height; y++)
2352 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2353 if (q == (Quantum *) NULL)
2355 for (x=0; x < (ssize_t) roi->width; x++)
2357 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2360 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2363 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2366 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2369 q+=GetPixelChannels(image);
2371 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2376 if (LocaleCompare(map,"BGRP") == 0)
2378 for (y=0; y < (ssize_t) roi->height; y++)
2380 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2381 if (q == (Quantum *) NULL)
2383 for (x=0; x < (ssize_t) roi->width; x++)
2385 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2388 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2391 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2395 q+=GetPixelChannels(image);
2397 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2402 if (LocaleCompare(map,"I") == 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 SetPixelGray(image,ClampToQuantum((MagickRealType) QuantumRange*
2414 q+=GetPixelChannels(image);
2416 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2421 if (LocaleCompare(map,"RGB") == 0)
2423 for (y=0; y < (ssize_t) roi->height; y++)
2425 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2426 if (q == (Quantum *) NULL)
2428 for (x=0; x < (ssize_t) roi->width; x++)
2430 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2433 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2436 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2439 q+=GetPixelChannels(image);
2441 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2446 if (LocaleCompare(map,"RGBA") == 0)
2448 for (y=0; y < (ssize_t) roi->height; y++)
2450 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2451 if (q == (Quantum *) NULL)
2453 for (x=0; x < (ssize_t) roi->width; x++)
2455 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2458 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2461 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2464 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2467 q+=GetPixelChannels(image);
2469 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2474 if (LocaleCompare(map,"RGBP") == 0)
2476 for (y=0; y < (ssize_t) roi->height; y++)
2478 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2479 if (q == (Quantum *) NULL)
2481 for (x=0; x < (ssize_t) roi->width; x++)
2483 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2486 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2489 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2492 q+=GetPixelChannels(image);
2494 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2499 for (y=0; y < (ssize_t) roi->height; y++)
2501 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2502 if (q == (Quantum *) NULL)
2504 for (x=0; x < (ssize_t) roi->width; x++)
2509 for (i=0; i < (ssize_t) strlen(map); i++)
2511 switch (quantum_map[i])
2516 SetPixelRed(image,ClampToQuantum((MagickRealType)
2517 QuantumRange*(*p)),q);
2521 case MagentaQuantum:
2523 SetPixelGreen(image,ClampToQuantum((MagickRealType)
2524 QuantumRange*(*p)),q);
2530 SetPixelBlue(image,ClampToQuantum((MagickRealType)
2531 QuantumRange*(*p)),q);
2536 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2537 QuantumRange*(*p)),q);
2540 case OpacityQuantum:
2542 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2543 QuantumRange*(*p)),q);
2548 SetPixelBlack(image,ClampToQuantum((MagickRealType)
2549 QuantumRange*(*p)),q);
2554 SetPixelGray(image,ClampToQuantum((MagickRealType)
2555 QuantumRange*(*p)),q);
2563 q+=GetPixelChannels(image);
2565 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2570 static void ImportFloatPixel(Image *image,const RectangleInfo *roi,
2571 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2572 ExceptionInfo *exception)
2574 register const float
2586 p=(const float *) pixels;
2587 if (LocaleCompare(map,"BGR") == 0)
2589 for (y=0; y < (ssize_t) roi->height; y++)
2591 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2592 if (q == (Quantum *) NULL)
2594 for (x=0; x < (ssize_t) roi->width; x++)
2596 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2599 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2602 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2605 q+=GetPixelChannels(image);
2607 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2612 if (LocaleCompare(map,"BGRA") == 0)
2614 for (y=0; y < (ssize_t) roi->height; y++)
2616 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2617 if (q == (Quantum *) NULL)
2619 for (x=0; x < (ssize_t) roi->width; x++)
2621 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2624 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2627 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2630 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2633 q+=GetPixelChannels(image);
2635 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2640 if (LocaleCompare(map,"BGRP") == 0)
2642 for (y=0; y < (ssize_t) roi->height; y++)
2644 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2645 if (q == (Quantum *) NULL)
2647 for (x=0; x < (ssize_t) roi->width; x++)
2649 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2652 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2655 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2659 q+=GetPixelChannels(image);
2661 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2666 if (LocaleCompare(map,"I") == 0)
2668 for (y=0; y < (ssize_t) roi->height; y++)
2670 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2671 if (q == (Quantum *) NULL)
2673 for (x=0; x < (ssize_t) roi->width; x++)
2675 SetPixelGray(image,ClampToQuantum((MagickRealType) QuantumRange*
2678 q+=GetPixelChannels(image);
2680 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2685 if (LocaleCompare(map,"RGB") == 0)
2687 for (y=0; y < (ssize_t) roi->height; y++)
2689 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2690 if (q == (Quantum *) NULL)
2692 for (x=0; x < (ssize_t) roi->width; x++)
2694 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2697 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2700 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2703 q+=GetPixelChannels(image);
2705 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2710 if (LocaleCompare(map,"RGBA") == 0)
2712 for (y=0; y < (ssize_t) roi->height; y++)
2714 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2715 if (q == (Quantum *) NULL)
2717 for (x=0; x < (ssize_t) roi->width; x++)
2719 SetPixelRed(image,ClampToQuantum((MagickRealType)
2720 QuantumRange*(*p)),q);
2722 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2725 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2728 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2731 q+=GetPixelChannels(image);
2733 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2738 if (LocaleCompare(map,"RGBP") == 0)
2740 for (y=0; y < (ssize_t) roi->height; y++)
2742 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2743 if (q == (Quantum *) NULL)
2745 for (x=0; x < (ssize_t) roi->width; x++)
2747 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2750 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2753 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2756 q+=GetPixelChannels(image);
2758 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2763 for (y=0; y < (ssize_t) roi->height; y++)
2765 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2766 if (q == (Quantum *) NULL)
2768 for (x=0; x < (ssize_t) roi->width; x++)
2773 for (i=0; i < (ssize_t) strlen(map); i++)
2775 switch (quantum_map[i])
2780 SetPixelRed(image,ClampToQuantum((MagickRealType)
2781 QuantumRange*(*p)),q);
2785 case MagentaQuantum:
2787 SetPixelGreen(image,ClampToQuantum((MagickRealType)
2788 QuantumRange*(*p)),q);
2794 SetPixelBlue(image,ClampToQuantum((MagickRealType)
2795 QuantumRange*(*p)),q);
2800 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2801 QuantumRange*(*p)),q);
2804 case OpacityQuantum:
2806 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2807 QuantumRange*(*p)),q);
2812 SetPixelBlack(image,ClampToQuantum((MagickRealType)
2813 QuantumRange*(*p)),q);
2818 SetPixelGray(image,ClampToQuantum((MagickRealType)
2819 QuantumRange*(*p)),q);
2827 q+=GetPixelChannels(image);
2829 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2834 static void ImportLongPixel(Image *image,const RectangleInfo *roi,
2835 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2836 ExceptionInfo *exception)
2838 register const unsigned int
2850 p=(const unsigned int *) pixels;
2851 if (LocaleCompare(map,"BGR") == 0)
2853 for (y=0; y < (ssize_t) roi->height; y++)
2855 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2856 if (q == (Quantum *) NULL)
2858 for (x=0; x < (ssize_t) roi->width; x++)
2860 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2861 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2862 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2863 q+=GetPixelChannels(image);
2865 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2870 if (LocaleCompare(map,"BGRA") == 0)
2872 for (y=0; y < (ssize_t) roi->height; y++)
2874 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2875 if (q == (Quantum *) NULL)
2877 for (x=0; x < (ssize_t) roi->width; x++)
2879 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2880 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2881 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2882 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
2883 q+=GetPixelChannels(image);
2885 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2890 if (LocaleCompare(map,"BGRP") == 0)
2892 for (y=0; y < (ssize_t) roi->height; y++)
2894 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2895 if (q == (Quantum *) NULL)
2897 for (x=0; x < (ssize_t) roi->width; x++)
2899 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2900 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2901 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2903 q+=GetPixelChannels(image);
2905 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2910 if (LocaleCompare(map,"I") == 0)
2912 for (y=0; y < (ssize_t) roi->height; y++)
2914 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2915 if (q == (Quantum *) NULL)
2917 for (x=0; x < (ssize_t) roi->width; x++)
2919 SetPixelGray(image,ScaleLongToQuantum(*p++),q);
2920 q+=GetPixelChannels(image);
2922 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2927 if (LocaleCompare(map,"RGB") == 0)
2929 for (y=0; y < (ssize_t) roi->height; y++)
2931 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2932 if (q == (Quantum *) NULL)
2934 for (x=0; x < (ssize_t) roi->width; x++)
2936 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2937 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2938 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2939 q+=GetPixelChannels(image);
2941 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2946 if (LocaleCompare(map,"RGBA") == 0)
2948 for (y=0; y < (ssize_t) roi->height; y++)
2950 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2951 if (q == (Quantum *) NULL)
2953 for (x=0; x < (ssize_t) roi->width; x++)
2955 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2956 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2957 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2958 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
2959 q+=GetPixelChannels(image);
2961 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2966 if (LocaleCompare(map,"RGBP") == 0)
2968 for (y=0; y < (ssize_t) roi->height; y++)
2970 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2971 if (q == (Quantum *) NULL)
2973 for (x=0; x < (ssize_t) roi->width; x++)
2975 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2976 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2977 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2979 q+=GetPixelChannels(image);
2981 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2986 for (y=0; y < (ssize_t) roi->height; y++)
2988 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2989 if (q == (Quantum *) NULL)
2991 for (x=0; x < (ssize_t) roi->width; x++)
2996 for (i=0; i < (ssize_t) strlen(map); i++)
2998 switch (quantum_map[i])
3003 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3007 case MagentaQuantum:
3009 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
3015 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
3020 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3023 case OpacityQuantum:
3025 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3030 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
3035 SetPixelGray(image,ScaleLongToQuantum(*p),q);
3043 q+=GetPixelChannels(image);
3045 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3050 static void ImportLongLongPixel(Image *image,const RectangleInfo *roi,
3051 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3052 ExceptionInfo *exception)
3054 register const MagickSizeType
3066 p=(const MagickSizeType *) pixels;
3067 if (LocaleCompare(map,"BGR") == 0)
3069 for (y=0; y < (ssize_t) roi->height; y++)
3071 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3072 if (q == (Quantum *) NULL)
3074 for (x=0; x < (ssize_t) roi->width; x++)
3076 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3077 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3078 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3079 q+=GetPixelChannels(image);
3081 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3086 if (LocaleCompare(map,"BGRA") == 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 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3096 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3097 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3098 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3099 q+=GetPixelChannels(image);
3101 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3106 if (LocaleCompare(map,"BGRP") == 0)
3108 for (y=0; y < (ssize_t) roi->height; y++)
3110 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3111 if (q == (Quantum *) NULL)
3113 for (x=0; x < (ssize_t) roi->width; x++)
3115 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3116 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3117 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3119 q+=GetPixelChannels(image);
3121 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3126 if (LocaleCompare(map,"I") == 0)
3128 for (y=0; y < (ssize_t) roi->height; y++)
3130 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3131 if (q == (Quantum *) NULL)
3133 for (x=0; x < (ssize_t) roi->width; x++)
3135 SetPixelGray(image,ScaleLongLongToQuantum(*p++),q);
3136 q+=GetPixelChannels(image);
3138 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3143 if (LocaleCompare(map,"RGB") == 0)
3145 for (y=0; y < (ssize_t) roi->height; y++)
3147 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3148 if (q == (Quantum *) NULL)
3150 for (x=0; x < (ssize_t) roi->width; x++)
3152 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3153 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3154 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3155 q+=GetPixelChannels(image);
3157 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3162 if (LocaleCompare(map,"RGBA") == 0)
3164 for (y=0; y < (ssize_t) roi->height; y++)
3166 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3167 if (q == (Quantum *) NULL)
3169 for (x=0; x < (ssize_t) roi->width; x++)
3171 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3172 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3173 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3174 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3175 q+=GetPixelChannels(image);
3177 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3182 if (LocaleCompare(map,"RGBP") == 0)
3184 for (y=0; y < (ssize_t) roi->height; y++)
3186 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3187 if (q == (Quantum *) NULL)
3189 for (x=0; x < (ssize_t) roi->width; x++)
3191 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3192 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3193 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3195 q+=GetPixelChannels(image);
3197 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3202 for (y=0; y < (ssize_t) roi->height; y++)
3204 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3205 if (q == (Quantum *) NULL)
3207 for (x=0; x < (ssize_t) roi->width; x++)
3212 for (i=0; i < (ssize_t) strlen(map); i++)
3214 switch (quantum_map[i])
3219 SetPixelRed(image,ScaleLongLongToQuantum(*p),q);
3223 case MagentaQuantum:
3225 SetPixelGreen(image,ScaleLongLongToQuantum(*p),q);
3231 SetPixelBlue(image,ScaleLongLongToQuantum(*p),q);
3236 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3239 case OpacityQuantum:
3241 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3246 SetPixelBlack(image,ScaleLongLongToQuantum(*p),q);
3251 SetPixelGray(image,ScaleLongLongToQuantum(*p),q);
3259 q+=GetPixelChannels(image);
3261 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3266 static void ImportQuantumPixel(Image *image,const RectangleInfo *roi,
3267 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3268 ExceptionInfo *exception)
3270 register const Quantum
3282 p=(const Quantum *) pixels;
3283 if (LocaleCompare(map,"BGR") == 0)
3285 for (y=0; y < (ssize_t) roi->height; y++)
3287 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3288 if (q == (Quantum *) NULL)
3290 for (x=0; x < (ssize_t) roi->width; x++)
3292 SetPixelBlue(image,*p++,q);
3293 SetPixelGreen(image,*p++,q);
3294 SetPixelRed(image,*p++,q);
3295 q+=GetPixelChannels(image);
3297 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3302 if (LocaleCompare(map,"BGRA") == 0)
3304 for (y=0; y < (ssize_t) roi->height; y++)
3306 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3307 if (q == (Quantum *) NULL)
3309 for (x=0; x < (ssize_t) roi->width; x++)
3311 SetPixelBlue(image,*p++,q);
3312 SetPixelGreen(image,*p++,q);
3313 SetPixelRed(image,*p++,q);
3314 SetPixelAlpha(image,*p++,q);
3315 q+=GetPixelChannels(image);
3317 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3322 if (LocaleCompare(map,"BGRP") == 0)
3324 for (y=0; y < (ssize_t) roi->height; y++)
3326 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3327 if (q == (Quantum *) NULL)
3329 for (x=0; x < (ssize_t) roi->width; x++)
3331 SetPixelBlue(image,*p++,q);
3332 SetPixelGreen(image,*p++,q);
3333 SetPixelRed(image,*p++,q);
3335 q+=GetPixelChannels(image);
3337 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3342 if (LocaleCompare(map,"I") == 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 SetPixelGray(image,*p++,q);
3352 q+=GetPixelChannels(image);
3354 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3359 if (LocaleCompare(map,"RGB") == 0)
3361 for (y=0; y < (ssize_t) roi->height; y++)
3363 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3364 if (q == (Quantum *) NULL)
3366 for (x=0; x < (ssize_t) roi->width; x++)
3368 SetPixelRed(image,*p++,q);
3369 SetPixelGreen(image,*p++,q);
3370 SetPixelBlue(image,*p++,q);
3371 q+=GetPixelChannels(image);
3373 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3378 if (LocaleCompare(map,"RGBA") == 0)
3380 for (y=0; y < (ssize_t) roi->height; y++)
3382 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3383 if (q == (Quantum *) NULL)
3385 for (x=0; x < (ssize_t) roi->width; x++)
3387 SetPixelRed(image,*p++,q);
3388 SetPixelGreen(image,*p++,q);
3389 SetPixelBlue(image,*p++,q);
3390 SetPixelAlpha(image,*p++,q);
3391 q+=GetPixelChannels(image);
3393 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3398 if (LocaleCompare(map,"RGBP") == 0)
3400 for (y=0; y < (ssize_t) roi->height; y++)
3402 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3403 if (q == (Quantum *) NULL)
3405 for (x=0; x < (ssize_t) roi->width; x++)
3407 SetPixelRed(image,*p++,q);
3408 SetPixelGreen(image,*p++,q);
3409 SetPixelBlue(image,*p++,q);
3411 q+=GetPixelChannels(image);
3413 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3418 for (y=0; y < (ssize_t) roi->height; y++)
3420 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3421 if (q == (Quantum *) NULL)
3423 for (x=0; x < (ssize_t) roi->width; x++)
3428 for (i=0; i < (ssize_t) strlen(map); i++)
3430 switch (quantum_map[i])
3435 SetPixelRed(image,*p,q);
3439 case MagentaQuantum:
3441 SetPixelGreen(image,*p,q);
3447 SetPixelBlue(image,*p,q);
3452 SetPixelAlpha(image,*p,q);
3455 case OpacityQuantum:
3457 SetPixelAlpha(image,*p,q);
3462 SetPixelBlack(image,*p,q);
3467 SetPixelGray(image,*p,q);
3475 q+=GetPixelChannels(image);
3477 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3482 static void ImportShortPixel(Image *image,const RectangleInfo *roi,
3483 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3484 ExceptionInfo *exception)
3486 register const unsigned short
3498 p=(const unsigned short *) pixels;
3499 if (LocaleCompare(map,"BGR") == 0)
3501 for (y=0; y < (ssize_t) roi->height; y++)
3503 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3504 if (q == (Quantum *) NULL)
3506 for (x=0; x < (ssize_t) roi->width; x++)
3508 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3509 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3510 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3511 q+=GetPixelChannels(image);
3513 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3518 if (LocaleCompare(map,"BGRA") == 0)
3520 for (y=0; y < (ssize_t) roi->height; y++)
3522 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3523 if (q == (Quantum *) NULL)
3525 for (x=0; x < (ssize_t) roi->width; x++)
3527 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3528 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3529 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3530 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3531 q+=GetPixelChannels(image);
3533 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3538 if (LocaleCompare(map,"BGRP") == 0)
3540 for (y=0; y < (ssize_t) roi->height; y++)
3542 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3543 if (q == (Quantum *) NULL)
3545 for (x=0; x < (ssize_t) roi->width; x++)
3547 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3548 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3549 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3551 q+=GetPixelChannels(image);
3553 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3558 if (LocaleCompare(map,"I") == 0)
3560 for (y=0; y < (ssize_t) roi->height; y++)
3562 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3563 if (q == (Quantum *) NULL)
3565 for (x=0; x < (ssize_t) roi->width; x++)
3567 SetPixelGray(image,ScaleShortToQuantum(*p++),q);
3568 q+=GetPixelChannels(image);
3570 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3575 if (LocaleCompare(map,"RGB") == 0)
3577 for (y=0; y < (ssize_t) roi->height; y++)
3579 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3580 if (q == (Quantum *) NULL)
3582 for (x=0; x < (ssize_t) roi->width; x++)
3584 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3585 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3586 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3587 q+=GetPixelChannels(image);
3589 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3594 if (LocaleCompare(map,"RGBA") == 0)
3596 for (y=0; y < (ssize_t) roi->height; y++)
3598 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3599 if (q == (Quantum *) NULL)
3601 for (x=0; x < (ssize_t) roi->width; x++)
3603 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3604 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3605 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3606 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3607 q+=GetPixelChannels(image);
3609 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3614 if (LocaleCompare(map,"RGBP") == 0)
3616 for (y=0; y < (ssize_t) roi->height; y++)
3618 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3619 if (q == (Quantum *) NULL)
3621 for (x=0; x < (ssize_t) roi->width; x++)
3623 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3624 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3625 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3627 q+=GetPixelChannels(image);
3629 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3634 for (y=0; y < (ssize_t) roi->height; y++)
3636 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3637 if (q == (Quantum *) NULL)
3639 for (x=0; x < (ssize_t) roi->width; x++)
3644 for (i=0; i < (ssize_t) strlen(map); i++)
3646 switch (quantum_map[i])
3651 SetPixelRed(image,ScaleShortToQuantum(*p),q);
3655 case MagentaQuantum:
3657 SetPixelGreen(image,ScaleShortToQuantum(*p),q);
3663 SetPixelBlue(image,ScaleShortToQuantum(*p),q);
3668 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3671 case OpacityQuantum:
3673 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3678 SetPixelBlack(image,ScaleShortToQuantum(*p),q);
3683 SetPixelGray(image,ScaleShortToQuantum(*p),q);
3691 q+=GetPixelChannels(image);
3693 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3698 MagickExport MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
3699 const ssize_t y,const size_t width,const size_t height,const char *map,
3700 const StorageType type,const void *pixels,ExceptionInfo *exception)
3712 Allocate image structure.
3714 assert(image != (Image *) NULL);
3715 assert(image->signature == MagickSignature);
3716 if (image->debug != MagickFalse)
3717 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3718 quantum_map=(QuantumType *) AcquireQuantumMemory(strlen(map),
3719 sizeof(*quantum_map));
3720 if (quantum_map == (QuantumType *) NULL)
3721 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
3723 for (i=0; i < (ssize_t) strlen(map); i++)
3730 quantum_map[i]=AlphaQuantum;
3731 image->matte=MagickTrue;
3737 quantum_map[i]=BlueQuantum;
3743 quantum_map[i]=CyanQuantum;
3744 (void) SetImageColorspace(image,CMYKColorspace,exception);
3750 quantum_map[i]=GreenQuantum;
3756 quantum_map[i]=BlackQuantum;
3757 (void) SetImageColorspace(image,CMYKColorspace,exception);
3763 quantum_map[i]=IndexQuantum;
3769 quantum_map[i]=MagentaQuantum;
3770 (void) SetImageColorspace(image,CMYKColorspace,exception);
3776 quantum_map[i]=OpacityQuantum;
3777 image->matte=MagickTrue;
3783 quantum_map[i]=UndefinedQuantum;
3789 quantum_map[i]=RedQuantum;
3795 quantum_map[i]=YellowQuantum;
3796 (void) SetImageColorspace(image,CMYKColorspace,exception);
3801 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3802 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3803 "UnrecognizedPixelMap","`%s'",map);
3804 return(MagickFalse);
3808 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
3809 return(MagickFalse);
3811 Transfer the pixels from the pixel data to the image.
3821 ImportCharPixel(image,&roi,map,quantum_map,pixels,exception);
3826 ImportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
3831 ImportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
3836 ImportLongPixel(image,&roi,map,quantum_map,pixels,exception);
3841 ImportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
3846 ImportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
3851 ImportShortPixel(image,&roi,map,quantum_map,pixels,exception);
3856 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3857 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3858 "UnrecognizedPixelMap","`%s'",map);
3862 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3867 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3871 + 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 %
3875 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3877 % InitializePixelChannelMap() defines the standard pixel component map.
3879 % The format of the InitializePixelChannelMap() method is:
3881 % void InitializePixelChannelMap(Image *image)
3883 % A description of each parameter follows:
3885 % o image: the image.
3888 MagickExport void InitializePixelChannelMap(Image *image)
3899 assert(image != (Image *) NULL);
3900 assert(image->signature == MagickSignature);
3901 (void) ResetMagickMemory(image->channel_map,0,MaxPixelChannels*
3902 sizeof(*image->channel_map));
3903 trait=UpdatePixelTrait;
3904 if (image->matte != MagickFalse)
3905 trait=(PixelTrait) (trait | BlendPixelTrait);
3907 if (image->colorspace == GRAYColorspace)
3909 SetPixelChannelMap(image,BluePixelChannel,trait,n);
3910 SetPixelChannelMap(image,GreenPixelChannel,trait,n);
3911 SetPixelChannelMap(image,RedPixelChannel,trait,n++);
3915 SetPixelChannelMap(image,RedPixelChannel,trait,n++);
3916 SetPixelChannelMap(image,GreenPixelChannel,trait,n++);
3917 SetPixelChannelMap(image,BluePixelChannel,trait,n++);
3919 if (image->colorspace == CMYKColorspace)
3920 SetPixelChannelMap(image,BlackPixelChannel,trait,n++);
3921 if (image->matte != MagickFalse)
3922 SetPixelChannelMap(image,AlphaPixelChannel,CopyPixelTrait,n++);
3923 if (image->storage_class == PseudoClass)
3924 SetPixelChannelMap(image,IndexPixelChannel,CopyPixelTrait,n++);
3925 assert((n+image->number_meta_channels) < MaxPixelChannels);
3926 for (i=0; i < (ssize_t) image->number_meta_channels; i++)
3927 SetPixelChannelMap(image,(PixelChannel) (MetaPixelChannel+i),CopyPixelTrait,
3929 image->number_channels=(size_t) n;
3930 if (image->debug != MagickFalse)
3931 LogPixelChannels(image);
3932 (void) SetPixelChannelMask(image,image->channel_mask);
3936 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3940 % I n t e r p o l a t e P i x e l C h a n n e l %
3944 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3946 % InterpolatePixelChannel() applies a pixel interpolation method between a
3947 % floating point coordinate and the pixels surrounding that coordinate. No
3948 % pixel area resampling, or scaling of the result is performed.
3950 % The format of the InterpolatePixelChannel method is:
3952 % MagickBooleanType InterpolatePixelChannel(const Image *image,
3953 % const CacheView *image_view,const PixelChannel channel,
3954 % const PixelInterpolateMethod method,const double x,const double y,
3955 % double *pixel,ExceptionInfo *exception)
3957 % A description of each parameter follows:
3959 % o image: the image.
3961 % o image_view: the image view.
3963 % o channel: the pixel channel to interpolate.
3965 % o method: the pixel color interpolation method.
3967 % o x,y: A double representing the current (x,y) position of the pixel.
3969 % o pixel: return the interpolated pixel here.
3971 % o exception: return any errors or warnings in this structure.
3975 static inline double MagickMax(const MagickRealType x,const MagickRealType y)
3982 static inline MagickRealType CubicWeightingFunction(const MagickRealType x)
3988 alpha=MagickMax(x+2.0,0.0);
3989 gamma=1.0*alpha*alpha*alpha;
3990 alpha=MagickMax(x+1.0,0.0);
3991 gamma-=4.0*alpha*alpha*alpha;
3992 alpha=MagickMax(x+0.0,0.0);
3993 gamma+=6.0*alpha*alpha*alpha;
3994 alpha=MagickMax(x-1.0,0.0);
3995 gamma-=4.0*alpha*alpha*alpha;
3999 static inline double MeshInterpolate(const PointInfo *delta,const double p,
4000 const double x,const double y)
4002 return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
4005 static inline ssize_t NearestNeighbor(const MagickRealType x)
4008 return((ssize_t) (x+0.5));
4009 return((ssize_t) (x-0.5));
4012 MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
4013 const CacheView *image_view,const PixelChannel channel,
4014 const PixelInterpolateMethod method,const double x,const double y,
4015 double *pixel,ExceptionInfo *exception)
4028 register const Quantum
4038 assert(image != (Image *) NULL);
4039 assert(image != (Image *) NULL);
4040 assert(image->signature == MagickSignature);
4041 assert(image_view != (CacheView *) NULL);
4044 traits=GetPixelChannelMapTraits(image,channel);
4045 x_offset=(ssize_t) floor(x);
4046 y_offset=(ssize_t) floor(y);
4047 switch (method == UndefinedInterpolatePixel ? image->interpolate : method)
4049 case AverageInterpolatePixel:
4051 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4053 if (p == (const Quantum *) NULL)
4058 if ((traits & BlendPixelTrait) == 0)
4059 for (i=0; i < 16; i++)
4062 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4065 for (i=0; i < 16; i++)
4067 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4068 GetPixelChannels(image));
4069 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4071 for (i=0; i < 16; i++)
4073 gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]);
4074 *pixel+=gamma*0.0625*pixels[i];
4078 case BicubicInterpolatePixel:
4087 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4089 if (p == (const Quantum *) NULL)
4094 if ((traits & BlendPixelTrait) == 0)
4095 for (i=0; i < 16; i++)
4098 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4101 for (i=0; i < 16; i++)
4103 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4104 GetPixelChannels(image));
4105 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4109 for (i=0; i < 4; i++)
4111 u[0]=(pixels[4*i+3]-pixels[4*i+2])-(pixels[4*i+0]-pixels[4*i+1]);
4112 u[1]=(pixels[4*i+0]-pixels[4*i+1])-u[0];
4113 u[2]=pixels[4*i+2]-pixels[4*i+0];
4115 v[i]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x*
4118 u[0]=(v[3]-v[2])-(v[0]-v[1]);
4119 u[1]=(v[0]-v[1])-u[0];
4122 *pixel=(delta.y*delta.y*delta.y*u[0])+(delta.y*delta.y*u[1])+(delta.y*
4126 case BilinearInterpolatePixel:
4133 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4134 if (p == (const Quantum *) NULL)
4139 if ((traits & BlendPixelTrait) == 0)
4140 for (i=0; i < 4; i++)
4143 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4146 for (i=0; i < 4; i++)
4148 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4149 GetPixelChannels(image));
4150 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4154 epsilon.x=1.0-delta.x;
4155 epsilon.y=1.0-delta.y;
4156 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4157 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4158 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4159 *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
4160 (epsilon.x*pixels[2]+delta.x*pixels[3]));
4163 case FilterInterpolatePixel:
4177 geometry.x=x_offset-1;
4178 geometry.y=y_offset-1;
4179 excerpt_image=ExcerptImage(image,&geometry,exception);
4180 if (excerpt_image == (Image *) NULL)
4185 filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur,
4187 excerpt_image=DestroyImage(excerpt_image);
4188 if (filter_image == (Image *) NULL)
4190 filter_view=AcquireCacheView(filter_image);
4191 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4192 if (p == (const Quantum *) NULL)
4195 *pixel=(double) GetPixelChannel(image,channel,p);
4196 filter_view=DestroyCacheView(filter_view);
4197 filter_image=DestroyImage(filter_image);
4200 case IntegerInterpolatePixel:
4202 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4203 if (p == (const Quantum *) NULL)
4208 *pixel=(double) GetPixelChannel(image,channel,p);
4211 case NearestNeighborInterpolatePixel:
4213 p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
4214 NearestNeighbor(y),1,1,exception);
4215 if (p == (const Quantum *) NULL)
4220 *pixel=(double) GetPixelChannel(image,channel,p);
4223 case MeshInterpolatePixel:
4229 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4230 if (p == (const Quantum *) NULL)
4235 if ((traits & BlendPixelTrait) == 0)
4236 for (i=0; i < 4; i++)
4239 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4242 for (i=0; i < 4; i++)
4244 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4245 GetPixelChannels(image));
4246 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4250 luminance.x=GetPixelLuminance(image,p)-(double)
4251 GetPixelLuminance(image,p+3*GetPixelChannels(image));
4252 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
4253 GetPixelLuminance(image,p+2*GetPixelChannels(image));
4254 if (fabs(luminance.x) < fabs(luminance.y))
4259 if (delta.x <= delta.y)
4262 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4264 delta.y=1.0-delta.y;
4265 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4266 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4267 *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
4273 Top-right triangle (pixel: 1, diagonal: 0-3).
4275 delta.x=1.0-delta.x;
4276 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4277 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4278 *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
4287 if (delta.x <= (1.0-delta.y))
4290 Top-left triangle (pixel: 0, diagonal: 1-2).
4292 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4293 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4294 *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
4300 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4302 delta.x=1.0-delta.x;
4303 delta.y=1.0-delta.y;
4304 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4305 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4306 *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
4312 case SplineInterpolatePixel:
4325 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4327 if (p == (const Quantum *) NULL)
4332 if ((traits & BlendPixelTrait) == 0)
4333 for (i=0; i < 16; i++)
4336 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4339 for (i=0; i < 16; i++)
4341 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4342 GetPixelChannels(image));
4343 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4348 for (i=(-1); i < 3L; i++)
4350 dy=CubicWeightingFunction((MagickRealType) i-delta.y);
4351 for (j=(-1); j < 3L; j++)
4353 dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
4354 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]);
4355 *pixel+=gamma*dx*dy*pixels[n];
4366 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4370 % I n t e r p o l a t e P i x e l C h a n n e l s %
4374 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4376 % InterpolatePixelChannels() applies a pixel interpolation method between a
4377 % floating point coordinate and the pixels surrounding that coordinate. No
4378 % pixel area resampling, or scaling of the result is performed.
4380 % The format of the InterpolatePixelChannels method is:
4382 % MagickBooleanType InterpolatePixelChannels(const Image *source,
4383 % const CacheView *source_view,const Image *destination,
4384 % const PixelInterpolateMethod method,const double x,const double y,
4385 % Quantum *pixel,ExceptionInfo *exception)
4387 % A description of each parameter follows:
4389 % o source: the source.
4391 % o source_view: the source view.
4393 % o destination: the destination image.
4395 % o method: the pixel color interpolation method.
4397 % o x,y: A double representing the current (x,y) position of the pixel.
4399 % o pixel: return the interpolated pixel here.
4401 % o exception: return any errors or warnings in this structure.
4404 MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
4405 const CacheView *source_view,const Image *destination,
4406 const PixelInterpolateMethod method,const double x,const double y,
4407 Quantum *pixel,ExceptionInfo *exception)
4424 register const Quantum
4434 assert(source != (Image *) NULL);
4435 assert(source != (Image *) NULL);
4436 assert(source->signature == MagickSignature);
4437 assert(source_view != (CacheView *) NULL);
4439 x_offset=(ssize_t) floor(x);
4440 y_offset=(ssize_t) floor(y);
4441 switch (method == UndefinedInterpolatePixel ? source->interpolate : method)
4443 case AverageInterpolatePixel:
4445 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4447 if (p == (const Quantum *) NULL)
4452 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4460 channel=GetPixelChannelMapChannel(source,i);
4461 traits=GetPixelChannelMapTraits(source,channel);
4462 destination_traits=GetPixelChannelMapTraits(destination,channel);
4463 if ((traits == UndefinedPixelTrait) ||
4464 (destination_traits == UndefinedPixelTrait))
4466 for (j=0; j < 16; j++)
4467 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4469 if ((traits & BlendPixelTrait) == 0)
4471 for (j=0; j < 16; j++)
4472 sum+=0.0625*pixels[j];
4473 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4476 for (j=0; j < 16; j++)
4478 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4479 GetPixelChannels(source));
4480 pixels[j]*=alpha[j];
4481 gamma=1.0/(fabs((double) alpha[j]) <= MagickEpsilon ? 1.0 : alpha[j]);
4482 sum+=gamma*0.0625*pixels[j];
4484 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4488 case BicubicInterpolatePixel:
4497 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4499 if (p == (const Quantum *) NULL)
4504 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4509 channel=GetPixelChannelMapChannel(source,i);
4510 traits=GetPixelChannelMapTraits(source,channel);
4511 destination_traits=GetPixelChannelMapTraits(destination,channel);
4512 if ((traits == UndefinedPixelTrait) ||
4513 (destination_traits == UndefinedPixelTrait))
4515 if ((traits & BlendPixelTrait) == 0)
4516 for (j=0; j < 16; j++)
4519 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4522 for (j=0; j < 16; j++)
4524 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4525 GetPixelChannels(source));
4526 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4530 for (j=0; j < 4; j++)
4532 u[0]=(pixels[4*j+3]-pixels[4*j+2])-(pixels[4*j+0]-pixels[4*j+1]);
4533 u[1]=(pixels[4*j+0]-pixels[4*j+1])-u[0];
4534 u[2]=pixels[4*j+2]-pixels[4*j+0];
4536 v[j]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x*
4539 u[0]=(v[3]-v[2])-(v[0]-v[1]);
4540 u[1]=(v[0]-v[1])-u[0];
4543 SetPixelChannel(destination,channel,ClampToQuantum((delta.y*delta.y*
4544 delta.y*u[0])+(delta.y*delta.y*u[1])+(delta.y*u[2])+u[3]),pixel);
4548 case BilinearInterpolatePixel:
4551 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4552 if (p == (const Quantum *) NULL)
4557 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4563 channel=GetPixelChannelMapChannel(source,i);
4564 traits=GetPixelChannelMapTraits(source,channel);
4565 destination_traits=GetPixelChannelMapTraits(destination,channel);
4566 if ((traits == UndefinedPixelTrait) ||
4567 (destination_traits == UndefinedPixelTrait))
4571 epsilon.x=1.0-delta.x;
4572 epsilon.y=1.0-delta.y;
4573 pixels[0]=(MagickRealType) p[i];
4574 pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i];
4575 pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i];
4576 pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i];
4577 if ((traits & BlendPixelTrait) == 0)
4579 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
4580 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4581 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4582 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*
4583 pixels[2]+delta.x*pixels[3]))),pixel);
4586 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4587 alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source));
4588 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4589 GetPixelChannels(source));
4590 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4591 GetPixelChannels(source));
4592 pixels[0]*=alpha[0];
4593 pixels[1]*=alpha[1];
4594 pixels[2]*=alpha[2];
4595 pixels[3]*=alpha[3];
4596 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4597 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4598 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4599 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4600 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+
4601 delta.x*pixels[3]))),pixel);
4605 case FilterInterpolatePixel:
4607 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4619 channel=GetPixelChannelMapChannel(source,i);
4620 traits=GetPixelChannelMapTraits(source,channel);
4621 destination_traits=GetPixelChannelMapTraits(destination,channel);
4622 if ((traits == UndefinedPixelTrait) ||
4623 (destination_traits == UndefinedPixelTrait))
4627 geometry.x=x_offset-1;
4628 geometry.y=y_offset-1;
4629 excerpt_source=ExcerptImage(source,&geometry,exception);
4630 if (excerpt_source == (Image *) NULL)
4635 filter_source=ResizeImage(excerpt_source,1,1,source->filter,
4636 source->blur,exception);
4637 excerpt_source=DestroyImage(excerpt_source);
4638 if (filter_source == (Image *) NULL)
4640 filter_view=AcquireCacheView(filter_source);
4641 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4642 if (p == (const Quantum *) NULL)
4646 SetPixelChannel(destination,channel,p[i],pixel);
4648 filter_view=DestroyCacheView(filter_view);
4649 filter_source=DestroyImage(filter_source);
4653 case IntegerInterpolatePixel:
4655 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
4656 if (p == (const Quantum *) NULL)
4661 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4663 channel=GetPixelChannelMapChannel(source,i);
4664 traits=GetPixelChannelMapTraits(source,channel);
4665 destination_traits=GetPixelChannelMapTraits(destination,channel);
4666 if ((traits == UndefinedPixelTrait) ||
4667 (destination_traits == UndefinedPixelTrait))
4669 SetPixelChannel(destination,channel,p[i],pixel);
4673 case NearestNeighborInterpolatePixel:
4675 p=GetCacheViewVirtualPixels(source_view,NearestNeighbor(x),
4676 NearestNeighbor(y),1,1,exception);
4677 if (p == (const Quantum *) NULL)
4682 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4684 channel=GetPixelChannelMapChannel(source,i);
4685 traits=GetPixelChannelMapTraits(source,channel);
4686 destination_traits=GetPixelChannelMapTraits(destination,channel);
4687 if ((traits == UndefinedPixelTrait) ||
4688 (destination_traits == UndefinedPixelTrait))
4690 SetPixelChannel(destination,channel,p[i],pixel);
4694 case MeshInterpolatePixel:
4696 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4697 if (p == (const Quantum *) NULL)
4702 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4708 channel=GetPixelChannelMapChannel(source,i);
4709 traits=GetPixelChannelMapTraits(source,channel);
4710 destination_traits=GetPixelChannelMapTraits(destination,channel);
4711 if ((traits == UndefinedPixelTrait) ||
4712 (destination_traits == UndefinedPixelTrait))
4714 pixels[0]=(MagickRealType) p[i];
4715 pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i];
4716 pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i];
4717 pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i];
4718 if ((traits & BlendPixelTrait) == 0)
4727 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4728 alpha[1]=QuantumScale*GetPixelAlpha(source,p+
4729 GetPixelChannels(source));
4730 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4731 GetPixelChannels(source));
4732 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4733 GetPixelChannels(source));
4737 luminance.x=GetPixelLuminance(source,p)-(double)
4738 GetPixelLuminance(source,p+3*GetPixelChannels(source));
4739 luminance.y=GetPixelLuminance(source,p+GetPixelChannels(source))-
4740 (double) GetPixelLuminance(source,p+2*GetPixelChannels(source));
4741 if (fabs(luminance.x) < fabs(luminance.y))
4746 if (delta.x <= delta.y)
4749 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4751 delta.y=1.0-delta.y;
4752 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4753 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4754 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4755 MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel);
4760 Top-right triangle (pixel: 1, diagonal: 0-3).
4762 delta.x=1.0-delta.x;
4763 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4764 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4765 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4766 MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel);
4774 if (delta.x <= (1.0-delta.y))
4777 Top-left triangle (pixel: 0, diagonal: 1-2).
4779 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4780 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4781 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4782 MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel);
4787 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4789 delta.x=1.0-delta.x;
4790 delta.y=1.0-delta.y;
4791 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4792 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4793 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4794 MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel);
4800 case SplineInterpolatePixel:
4802 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4804 if (p == (const Quantum *) NULL)
4809 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4828 channel=GetPixelChannelMapChannel(source,i);
4829 traits=GetPixelChannelMapTraits(source,channel);
4830 destination_traits=GetPixelChannelMapTraits(destination,channel);
4831 if ((traits == UndefinedPixelTrait) ||
4832 (destination_traits == UndefinedPixelTrait))
4834 if ((traits & BlendPixelTrait) == 0)
4835 for (j=0; j < 16; j++)
4838 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4841 for (j=0; j < 16; j++)
4843 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4844 GetPixelChannels(source));
4845 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4851 for (j=(-1); j < 3L; j++)
4853 dy=CubicWeightingFunction((MagickRealType) j-delta.y);
4854 for (k=(-1); k < 3L; k++)
4856 dx=CubicWeightingFunction(delta.x-(MagickRealType) k);
4857 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 :
4859 sum+=gamma*dx*dy*pixels[n];
4863 SetPixelChannel(destination,channel,p[i],pixel);
4872 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4876 % I n t e r p o l a t e P i x e l I n f o %
4880 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4882 % InterpolatePixelInfo() applies a pixel interpolation method between a
4883 % floating point coordinate and the pixels surrounding that coordinate. No
4884 % pixel area resampling, or scaling of the result is performed.
4886 % The format of the InterpolatePixelInfo method is:
4888 % MagickBooleanType InterpolatePixelInfo(const Image *image,
4889 % const CacheView *image_view,const PixelInterpolateMethod method,
4890 % const double x,const double y,PixelInfo *pixel,
4891 % ExceptionInfo *exception)
4893 % A description of each parameter follows:
4895 % o image: the image.
4897 % o image_view: the image view.
4899 % o method: the pixel color interpolation method.
4901 % o x,y: A double representing the current (x,y) position of the pixel.
4903 % o pixel: return the interpolated pixel here.
4905 % o exception: return any errors or warnings in this structure.
4909 static inline void AlphaBlendPixelInfo(const Image *image,
4910 const Quantum *pixel,PixelInfo *pixel_info,MagickRealType *alpha)
4912 if (image->matte == MagickFalse)
4915 pixel_info->red=(MagickRealType) GetPixelRed(image,pixel);
4916 pixel_info->green=(MagickRealType) GetPixelGreen(image,pixel);
4917 pixel_info->blue=(MagickRealType) GetPixelBlue(image,pixel);
4918 pixel_info->black=0.0;
4919 if (image->colorspace == CMYKColorspace)
4920 pixel_info->black=(MagickRealType) GetPixelBlack(image,pixel);
4921 pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
4924 *alpha=QuantumScale*GetPixelAlpha(image,pixel);
4925 pixel_info->red=(*alpha*GetPixelRed(image,pixel));
4926 pixel_info->green=(*alpha*GetPixelGreen(image,pixel));
4927 pixel_info->blue=(*alpha*GetPixelBlue(image,pixel));
4928 pixel_info->black=0.0;
4929 if (image->colorspace == CMYKColorspace)
4930 pixel_info->black=(*alpha*GetPixelBlack(image,pixel));
4931 pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
4934 static void BicubicInterpolate(const PixelInfo *pixels,const double dx,
4945 p=(pixels[3].red-pixels[2].red)-(pixels[0].red-pixels[1].red);
4946 q=(pixels[0].red-pixels[1].red)-p;
4947 r=pixels[2].red-pixels[0].red;
4949 pixel->red=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4950 p=(pixels[3].green-pixels[2].green)-(pixels[0].green-pixels[1].green);
4951 q=(pixels[0].green-pixels[1].green)-p;
4952 r=pixels[2].green-pixels[0].green;
4954 pixel->green=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4955 p=(pixels[3].blue-pixels[2].blue)-(pixels[0].blue-pixels[1].blue);
4956 q=(pixels[0].blue-pixels[1].blue)-p;
4957 r=pixels[2].blue-pixels[0].blue;
4959 pixel->blue=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4960 p=(pixels[3].alpha-pixels[2].alpha)-(pixels[0].alpha-pixels[1].alpha);
4961 q=(pixels[0].alpha-pixels[1].alpha)-p;
4962 r=pixels[2].alpha-pixels[0].alpha;
4964 pixel->alpha=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4965 if (pixel->colorspace == CMYKColorspace)
4967 p=(pixels[3].black-pixels[2].black)-(pixels[0].black-pixels[1].black);
4968 q=(pixels[0].black-pixels[1].black)-p;
4969 r=pixels[2].black-pixels[0].black;
4971 pixel->black=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4975 MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
4976 const CacheView *image_view,const PixelInterpolateMethod method,
4977 const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception)
4989 register const Quantum
4999 assert(image != (Image *) NULL);
5000 assert(image->signature == MagickSignature);
5001 assert(image_view != (CacheView *) NULL);
5003 x_offset=(ssize_t) floor(x);
5004 y_offset=(ssize_t) floor(y);
5005 switch (method == UndefinedInterpolatePixel ? image->interpolate : method)
5007 case AverageInterpolatePixel:
5009 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5011 if (p == (const Quantum *) NULL)
5016 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5017 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5018 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5019 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5020 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
5021 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
5022 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
5023 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
5024 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
5025 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
5026 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
5028 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
5030 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
5032 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
5034 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
5036 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
5043 for (i=0; i < 16L; i++)
5045 gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]);
5046 pixel->red+=gamma*0.0625*pixels[i].red;
5047 pixel->green+=gamma*0.0625*pixels[i].green;
5048 pixel->blue+=gamma*0.0625*pixels[i].blue;
5049 if (image->colorspace == CMYKColorspace)
5050 pixel->black+=gamma*0.0625*pixels[i].black;
5051 pixel->alpha+=0.0625*pixels[i].alpha;
5055 case BicubicInterpolatePixel:
5063 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5065 if (p == (const Quantum *) NULL)
5070 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5071 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5072 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5073 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5074 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
5075 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
5076 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
5077 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
5078 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
5079 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
5080 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
5082 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
5084 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
5086 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
5088 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
5090 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
5094 for (i=0; i < 4L; i++)
5095 BicubicInterpolate(pixels+4*i,delta.x,u+i);
5096 BicubicInterpolate(u,delta.y,pixel);
5099 case BilinearInterpolatePixel:
5106 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5107 if (p == (const Quantum *) NULL)
5112 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5113 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5114 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5115 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5118 epsilon.x=1.0-delta.x;
5119 epsilon.y=1.0-delta.y;
5120 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5121 (epsilon.x*alpha[2]+delta.x*alpha[3])));
5122 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5123 pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
5124 pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red));
5125 pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x*
5126 pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x*
5128 pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x*
5129 pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x*
5131 if (image->colorspace == CMYKColorspace)
5132 pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x*
5133 pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x*
5135 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5136 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5137 pixel->alpha=(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x*
5138 pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x*
5142 case FilterInterpolatePixel:
5156 geometry.x=x_offset-1;
5157 geometry.y=y_offset-1;
5158 excerpt_image=ExcerptImage(image,&geometry,exception);
5159 if (excerpt_image == (Image *) NULL)
5164 filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur,
5166 excerpt_image=DestroyImage(excerpt_image);
5167 if (filter_image == (Image *) NULL)
5169 filter_view=AcquireCacheView(filter_image);
5170 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
5171 if (p != (const Quantum *) NULL)
5172 GetPixelInfoPixel(image,p,pixel);
5173 filter_view=DestroyCacheView(filter_view);
5174 filter_image=DestroyImage(filter_image);
5177 case IntegerInterpolatePixel:
5179 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5180 if (p == (const Quantum *) NULL)
5185 GetPixelInfoPixel(image,p,pixel);
5188 case MeshInterpolatePixel:
5194 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5195 if (p == (const Quantum *) NULL)
5202 luminance.x=GetPixelLuminance(image,p)-(double)
5203 GetPixelLuminance(image,p+3*GetPixelChannels(image));
5204 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
5205 GetPixelLuminance(image,p+2*GetPixelChannels(image));
5206 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5207 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5208 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5209 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5210 if (fabs(luminance.x) < fabs(luminance.y))
5215 if (delta.x <= delta.y)
5218 Bottom-left triangle (pixel: 2, diagonal: 0-3).
5220 delta.y=1.0-delta.y;
5221 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5222 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5223 pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red,
5224 pixels[3].red,pixels[0].red);
5225 pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green,
5226 pixels[3].green,pixels[0].green);
5227 pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
5228 pixels[3].blue,pixels[0].blue);
5229 if (image->colorspace == CMYKColorspace)
5230 pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black,
5231 pixels[3].black,pixels[0].black);
5232 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5233 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha,
5234 pixels[3].alpha,pixels[0].alpha);
5239 Top-right triangle (pixel:1 , diagonal: 0-3).
5241 delta.x=1.0-delta.x;
5242 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5243 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5244 pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red,
5245 pixels[0].red,pixels[3].red);
5246 pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green,
5247 pixels[0].green,pixels[3].green);
5248 pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
5249 pixels[0].blue,pixels[3].blue);
5250 if (image->colorspace == CMYKColorspace)
5251 pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black,
5252 pixels[0].black,pixels[3].black);
5253 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5254 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha,
5255 pixels[0].alpha,pixels[3].alpha);
5263 if (delta.x <= (1.0-delta.y))
5266 Top-left triangle (pixel: 0, diagonal: 1-2).
5268 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5269 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5270 pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red,
5271 pixels[1].red,pixels[2].red);
5272 pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green,
5273 pixels[1].green,pixels[2].green);
5274 pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
5275 pixels[1].blue,pixels[2].blue);
5276 if (image->colorspace == CMYKColorspace)
5277 pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black,
5278 pixels[1].black,pixels[2].black);
5279 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5280 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha,
5281 pixels[1].alpha,pixels[2].alpha);
5286 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5288 delta.x=1.0-delta.x;
5289 delta.y=1.0-delta.y;
5290 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5291 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5292 pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red,
5293 pixels[2].red,pixels[1].red);
5294 pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green,
5295 pixels[2].green,pixels[1].green);
5296 pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
5297 pixels[2].blue,pixels[1].blue);
5298 if (image->colorspace == CMYKColorspace)
5299 pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black,
5300 pixels[2].black,pixels[1].black);
5301 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5302 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha,
5303 pixels[2].alpha,pixels[1].alpha);
5308 case NearestNeighborInterpolatePixel:
5310 p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
5311 NearestNeighbor(y),1,1,exception);
5312 if (p == (const Quantum *) NULL)
5317 GetPixelInfoPixel(image,p,pixel);
5320 case SplineInterpolatePixel:
5333 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5335 if (p == (const Quantum *) NULL)
5340 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5341 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5342 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5343 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5344 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
5345 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
5346 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
5347 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
5348 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
5349 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
5350 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
5352 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
5354 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
5356 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
5358 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
5360 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
5370 for (i=(-1); i < 3L; i++)
5372 dy=CubicWeightingFunction((MagickRealType) i-delta.y);
5373 for (j=(-1); j < 3L; j++)
5375 dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
5376 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]);
5377 pixel->red+=gamma*dx*dy*pixels[n].red;
5378 pixel->green+=gamma*dx*dy*pixels[n].green;
5379 pixel->blue+=gamma*dx*dy*pixels[n].blue;
5380 if (image->colorspace == CMYKColorspace)
5381 pixel->black+=gamma*dx*dy*pixels[n].black;
5382 pixel->alpha+=dx*dy*pixels[n].alpha;
5393 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5397 + I s F u z z y E q u i v a l e n c e P i x e l %
5401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5403 % IsFuzzyEquivalencePixel() returns MagickTrue if the distance between two
5404 % pixels is less than the specified distance in a linear three (or four)u
5405 % dimensional color space.
5407 % The format of the IsFuzzyEquivalencePixel method is:
5409 % void IsFuzzyEquivalencePixel(const Image *source,const Quantum *p,
5410 % const Image *destination,const Quantum *q)
5412 % A description of each parameter follows:
5414 % o source: the source image.
5418 % o destination: the destination image.
5423 MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *source,
5424 const Quantum *p,const Image *destination,const Quantum *q)
5430 register MagickRealType
5434 fuzz=MagickMax(source->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(
5435 destination->fuzz,(MagickRealType) MagickSQ1_2);
5438 if (source->matte != MagickFalse)
5441 Transparencies are involved - set alpha distance
5443 pixel=GetPixelAlpha(source,p)-(MagickRealType)
5444 GetPixelAlpha(destination,q);
5445 distance=pixel*pixel;
5446 if (distance > fuzz)
5447 return(MagickFalse);
5449 Generate a alpha scaling factor to generate a 4D cone on colorspace
5450 Note that if one color is transparent, distance has no color component.
5452 scale=QuantumScale*GetPixelAlpha(source,p);
5453 scale*=QuantumScale*GetPixelAlpha(destination,q);
5454 if (scale <= MagickEpsilon)
5458 RGB or CMY color cube
5460 distance*=3.0; /* rescale appropriately */
5462 pixel=GetPixelRed(source,p)-(MagickRealType) GetPixelRed(destination,q);
5463 if ((source->colorspace == HSLColorspace) ||
5464 (source->colorspace == HSBColorspace) ||
5465 (source->colorspace == HWBColorspace))
5468 Compute an arc distance for hue. It should be a vector angle of
5469 'S'/'W' length with 'L'/'B' forming appropriate cones.
5471 if (fabs((double) pixel) > (QuantumRange/2))
5472 pixel-=QuantumRange;
5475 distance+=scale*pixel*pixel;
5476 if (distance > fuzz)
5477 return(MagickFalse);
5478 pixel=GetPixelGreen(source,p)-(MagickRealType) GetPixelGreen(destination,q);
5479 distance+=scale*pixel*pixel;
5480 if (distance > fuzz)
5481 return(MagickFalse);
5482 pixel=GetPixelBlue(source,p)-(MagickRealType) GetPixelBlue(destination,q);
5483 distance+=scale*pixel*pixel;
5484 if (distance > fuzz)
5485 return(MagickFalse);
5490 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5494 + 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 %
5498 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5500 % IsFuzzyEquivalencePixelInfo() returns true if the distance between two
5501 % colors is less than the specified distance in a linear three (or four)
5502 % dimensional color space.
5504 % This implements the equivalent of:
5505 % fuzz < sqrt(color_distance^2 * u.a*v.a + alpha_distance^2)
5507 % Which produces a multi-dimensional cone for that colorspace along the
5508 % transparency vector.
5510 % For example for an RGB:
5511 % color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3
5513 % See http://www.imagemagick.org/Usage/bugs/fuzz_distance/
5515 % Hue colorspace distances need more work. Hue is not a distance, it is an
5518 % A check that q is in the same color space as p should be made and the
5519 % appropriate mapping made. -- Anthony Thyssen 8 December 2010
5521 % The format of the IsFuzzyEquivalencePixelInfo method is:
5523 % MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5524 % const PixelInfo *q)
5526 % A description of each parameter follows:
5533 MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5540 register MagickRealType
5544 if ((p->fuzz == 0.0) && (q->fuzz == 0.0))
5545 return(IsPixelInfoEquivalent(p,q));
5547 fuzz=MagickMax(q->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz,
5548 (MagickRealType) MagickSQ1_2);
5549 else if (q->fuzz == 0.0)
5550 fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(p->fuzz,
5551 (MagickRealType) MagickSQ1_2);
5553 fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz,
5554 (MagickRealType) MagickSQ1_2);
5557 if ((p->matte != MagickFalse) || (q->matte != MagickFalse))
5560 Transparencies are involved - set alpha distance.
5562 pixel=(p->matte != MagickFalse ? p->alpha : OpaqueAlpha)-
5563 (q->matte != MagickFalse ? q->alpha : OpaqueAlpha);
5564 distance=pixel*pixel;
5565 if (distance > fuzz)
5566 return(MagickFalse);
5568 Generate a alpha scaling factor to generate a 4D cone on colorspace.
5569 If one color is transparent, distance has no color component.
5571 if (p->matte != MagickFalse)
5572 scale=(QuantumScale*p->alpha);
5573 if (q->matte != MagickFalse)
5574 scale*=(QuantumScale*q->alpha);
5575 if (scale <= MagickEpsilon )
5579 CMYK create a CMY cube with a multi-dimensional cone toward black.
5581 if (p->colorspace == CMYKColorspace)
5583 pixel=p->black-q->black;
5584 distance+=pixel*pixel*scale;
5585 if (distance > fuzz)
5586 return(MagickFalse);
5587 scale*=(MagickRealType) (QuantumScale*(QuantumRange-p->black));
5588 scale*=(MagickRealType) (QuantumScale*(QuantumRange-q->black));
5591 RGB or CMY color cube.
5593 distance*=3.0; /* rescale appropriately */
5595 pixel=p->red-q->red;
5596 if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) ||
5597 (p->colorspace == HWBColorspace))
5600 This calculates a arc distance for hue-- it should be a vector angle
5601 of 'S'/'W' length with 'L'/'B' forming appropriate cones. In other
5602 words this is a hack - Anthony.
5604 if (fabs((double) pixel) > (QuantumRange/2))
5605 pixel-=QuantumRange;
5608 distance+=pixel*pixel*scale;
5609 if (distance > fuzz)
5610 return(MagickFalse);
5611 pixel=p->green-q->green;
5612 distance+=pixel*pixel*scale;
5613 if (distance > fuzz)
5614 return(MagickFalse);
5615 pixel=p->blue-q->blue;
5616 distance+=pixel*pixel*scale;
5617 if (distance > fuzz)
5618 return(MagickFalse);
5623 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5627 % S e t P i x e l C h a n n e l M a p M a s k %
5631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5633 % SetPixelChannelMapMask() sets the pixel channel map from the specified
5636 % The format of the SetPixelChannelMapMask method is:
5638 % void SetPixelChannelMapMask(Image *image,const ChannelType channel_mask)
5640 % A description of each parameter follows:
5642 % o image: the image.
5644 % o mask: the channel mask.
5647 MagickExport void SetPixelChannelMapMask(Image *image,
5648 const ChannelType channel_mask)
5650 #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
5655 image->channel_mask=channel_mask;
5656 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5661 channel=GetPixelChannelMapChannel(image,i);
5662 SetPixelChannelMapTraits(image,channel,
5663 GetChannelBit(channel_mask,channel) == 0 ? CopyPixelTrait :
5664 image->matte == MagickFalse || (channel == AlphaPixelChannel) ?
5665 UpdatePixelTrait : (PixelTrait) (UpdatePixelTrait | BlendPixelTrait));
5667 if (image->storage_class == PseudoClass)
5668 SetPixelChannelMapTraits(image,IndexPixelChannel,CopyPixelTrait);
5669 if (image->debug != MagickFalse)
5670 LogPixelChannels(image);
5674 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5678 % S e t P i x e l C h a n n e l M a s k %
5682 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5684 % SetPixelChannelMask() sets the pixel channel mask from the specified channel
5687 % The format of the SetPixelChannelMask method is:
5689 % ChannelType SetPixelChannelMask(Image *image,
5690 % const ChannelType channel_mask)
5692 % A description of each parameter follows:
5694 % o image: the image.
5696 % o channel_mask: the channel mask.
5699 MagickExport ChannelType SetPixelChannelMask(Image *image,
5700 const ChannelType channel_mask)
5705 mask=image->channel_mask;
5706 image->channel_mask=channel_mask;
5707 SetPixelChannelMapMask(image,channel_mask);