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/cache-private.h"
46 #include "MagickCore/color-private.h"
47 #include "MagickCore/draw.h"
48 #include "MagickCore/exception.h"
49 #include "MagickCore/exception-private.h"
50 #include "MagickCore/cache.h"
51 #include "MagickCore/constitute.h"
52 #include "MagickCore/delegate.h"
53 #include "MagickCore/geometry.h"
54 #include "MagickCore/image-private.h"
55 #include "MagickCore/list.h"
56 #include "MagickCore/magick.h"
57 #include "MagickCore/memory_.h"
58 #include "MagickCore/monitor.h"
59 #include "MagickCore/option.h"
60 #include "MagickCore/pixel.h"
61 #include "MagickCore/pixel-accessor.h"
62 #include "MagickCore/quantum.h"
63 #include "MagickCore/quantum-private.h"
64 #include "MagickCore/resource_.h"
65 #include "MagickCore/semaphore.h"
66 #include "MagickCore/statistic.h"
67 #include "MagickCore/stream.h"
68 #include "MagickCore/string_.h"
69 #include "MagickCore/transform.h"
70 #include "MagickCore/utility.h"
72 #define LogPixelChannels(image) \
77 (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%.20g]", \
78 image->filename,(double) image->number_channels); \
79 for (i=0; i < (ssize_t) image->number_channels; i++) \
82 traits[MaxTextExtent]; \
90 switch (GetPixelChannelMapChannel(image,i)) \
92 case RedPixelChannel: \
95 if (image->colorspace == CMYKColorspace) \
97 if (image->colorspace == GRAYColorspace) \
101 case GreenPixelChannel: \
104 if (image->colorspace == CMYKColorspace) \
108 case BluePixelChannel: \
111 if (image->colorspace == CMYKColorspace) \
115 case BlackPixelChannel: \
118 if (image->storage_class == PseudoClass) \
122 case IndexPixelChannel: \
127 case AlphaPixelChannel: \
132 case MaskPixelChannel: \
137 case MetaPixelChannel: \
145 channel=GetPixelChannelMapChannel(image,i); \
147 if ((GetPixelChannelMapTraits(image,channel) & UpdatePixelTrait) != 0) \
148 (void) ConcatenateMagickString(traits,"update,",MaxTextExtent); \
149 if ((GetPixelChannelMapTraits(image,channel) & BlendPixelTrait) != 0) \
150 (void) ConcatenateMagickString(traits,"blend,",MaxTextExtent); \
151 if ((GetPixelChannelMapTraits(image,channel) & CopyPixelTrait) != 0) \
152 (void) ConcatenateMagickString(traits,"copy,",MaxTextExtent); \
153 if (*traits == '\0') \
154 (void) ConcatenateMagickString(traits,"undefined,",MaxTextExtent); \
155 traits[strlen(traits)-1]='\0'; \
156 (void) LogMagickEvent(PixelEvent,GetMagickModule()," %.20g: %s (%s)", \
157 (double) i,name,traits); \
162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166 + A c q u i r e P i x e l C h a n n e l M a p %
170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172 % AcquirePixelChannelMap() acquires a pixel component map.
174 % The format of the AcquirePixelChannelMap() method is:
176 % PixelChannelMap *AcquirePixelChannelMap(void)
179 MagickExport PixelChannelMap *AcquirePixelChannelMap(void)
187 channel_map=(PixelChannelMap *) AcquireQuantumMemory(MaxPixelChannels,
188 sizeof(*channel_map));
189 if (channel_map == (PixelChannelMap *) NULL)
190 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
191 (void) ResetMagickMemory(channel_map,0,MaxPixelChannels*sizeof(*channel_map));
192 for (i=0; i < MaxPixelChannels; i++)
193 channel_map[i].channel=(PixelChannel) i;
198 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202 + C l o n e P i x e l C h a n n e l M a p %
206 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208 % ClonePixelChannelMap() clones a pixel component map.
210 % The format of the ClonePixelChannelMap() method is:
212 % PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
214 % A description of each parameter follows:
216 % o channel_map: the pixel component map.
219 MagickExport PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
224 assert(channel_map != (PixelChannelMap *) NULL);
225 clone_map=AcquirePixelChannelMap();
226 if (clone_map == (PixelChannelMap *) NULL)
227 return((PixelChannelMap *) NULL);
228 (void) CopyMagickMemory(clone_map,channel_map,MaxPixelChannels*
229 sizeof(*channel_map));
234 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238 + C l o n e P i x e l I n f o %
242 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244 % ClonePixelInfo() makes a duplicate of the given pixel info structure, or if
245 % pixel info is NULL, a new one.
247 % The format of the ClonePixelInfo method is:
249 % PixelInfo *ClonePixelInfo(const PixelInfo *pixel_info)
251 % A description of each parameter follows:
253 % o pixel_info: the pixel info.
256 MagickExport PixelInfo *ClonePixelInfo(const PixelInfo *pixel)
261 pixel_info=(PixelInfo *) AcquireQuantumMemory(1,sizeof(*pixel_info));
262 if (pixel_info == (PixelInfo *) NULL)
263 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
264 *pixel_info=(*pixel);
269 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
273 + D e s t r o y P i x e l C h a n n e l M a p %
277 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
279 % DestroyPixelChannelMap() deallocates memory associated with the pixel
282 % The format of the DestroyPixelChannelMap() method is:
284 % PixelChannelMap *DestroyPixelChannelMap(PixelChannelMap *channel_map)
286 % A description of each parameter follows:
288 % o channel_map: the pixel component map.
291 MagickExport PixelChannelMap *DestroyPixelChannelMap(
292 PixelChannelMap *channel_map)
294 assert(channel_map != (PixelChannelMap *) NULL);
295 channel_map=(PixelChannelMap *) RelinquishMagickMemory(channel_map);
296 return((PixelChannelMap *) RelinquishMagickMemory(channel_map));
300 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304 % E x p o r t I m a g e P i x e l s %
308 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
310 % ExportImagePixels() extracts pixel data from an image and returns it to you.
311 % The method returns MagickTrue on success otherwise MagickFalse if an error is
312 % encountered. The data is returned as char, short int, Quantum, unsigned int,
313 % unsigned long long, float, or double in the order specified by map.
315 % Suppose you want to extract the first scanline of a 640x480 image as
316 % character data in red-green-blue order:
318 % ExportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels,exception);
320 % The format of the ExportImagePixels method is:
322 % MagickBooleanType ExportImagePixels(const Image *image,const ssize_t x,
323 % const ssize_t y,const size_t width,const size_t height,
324 % const char *map,const StorageType type,void *pixels,
325 % ExceptionInfo *exception)
327 % A description of each parameter follows:
329 % o image: the image.
331 % o x,y,width,height: These values define the perimeter
332 % of a region of pixels you want to extract.
334 % o map: This string reflects the expected ordering of the pixel array.
335 % It can be any combination or order of R = red, G = green, B = blue,
336 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
337 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
340 % o type: Define the data type of the pixels. Float and double types are
341 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
342 % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *),
343 % LongPixel (unsigned int *), LongLongPixel (unsigned long long *),
344 % QuantumPixel (Quantum *), or ShortPixel (unsigned short *).
346 % o pixels: This array of values contain the pixel components as defined by
347 % map and type. You must preallocate this array where the expected
348 % length varies depending on the values of width, height, map, and type.
350 % o exception: return any errors or warnings in this structure.
354 static void ExportCharPixel(const Image *image,const RectangleInfo *roi,
355 const char *restrict map,const QuantumType *quantum_map,void *pixels,
356 ExceptionInfo *exception)
358 register const Quantum
364 register unsigned char
373 q=(unsigned char *) pixels;
374 if (LocaleCompare(map,"BGR") == 0)
376 for (y=0; y < (ssize_t) roi->height; y++)
378 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
379 if (p == (const Quantum *) NULL)
381 for (x=0; x < (ssize_t) roi->width; x++)
383 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
384 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
385 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
386 p+=GetPixelChannels(image);
391 if (LocaleCompare(map,"BGRA") == 0)
393 for (y=0; y < (ssize_t) roi->height; y++)
395 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
396 if (p == (const Quantum *) NULL)
398 for (x=0; x < (ssize_t) roi->width; x++)
400 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
401 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
402 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
403 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
404 p+=GetPixelChannels(image);
409 if (LocaleCompare(map,"BGRP") == 0)
411 for (y=0; y < (ssize_t) roi->height; y++)
413 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
414 if (p == (const Quantum *) NULL)
416 for (x=0; x < (ssize_t) roi->width; x++)
418 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
419 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
420 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
421 *q++=ScaleQuantumToChar((Quantum) 0);
422 p+=GetPixelChannels(image);
427 if (LocaleCompare(map,"I") == 0)
429 for (y=0; y < (ssize_t) roi->height; y++)
431 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
432 if (p == (const Quantum *) NULL)
434 for (x=0; x < (ssize_t) roi->width; x++)
436 *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
437 p+=GetPixelChannels(image);
442 if (LocaleCompare(map,"RGB") == 0)
444 for (y=0; y < (ssize_t) roi->height; y++)
446 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
447 if (p == (const Quantum *) NULL)
449 for (x=0; x < (ssize_t) roi->width; x++)
451 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
452 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
453 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
454 p+=GetPixelChannels(image);
459 if (LocaleCompare(map,"RGBA") == 0)
461 for (y=0; y < (ssize_t) roi->height; y++)
463 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
464 if (p == (const Quantum *) NULL)
466 for (x=0; x < (ssize_t) roi->width; x++)
468 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
469 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
470 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
471 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
472 p+=GetPixelChannels(image);
477 if (LocaleCompare(map,"RGBP") == 0)
479 for (y=0; y < (ssize_t) roi->height; y++)
481 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
482 if (p == (const Quantum *) NULL)
484 for (x=0; x < (ssize_t) roi->width; x++)
486 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
487 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
488 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
489 *q++=ScaleQuantumToChar((Quantum) 0);
490 p+=GetPixelChannels(image);
496 for (y=0; y < (ssize_t) roi->height; y++)
498 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
499 if (p == (const Quantum *) NULL)
501 for (x=0; x < (ssize_t) roi->width; x++)
506 for (i=0; i < (ssize_t) length; i++)
509 switch (quantum_map[i])
514 *q=ScaleQuantumToChar(GetPixelRed(image,p));
520 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
526 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
531 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
536 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
541 if (image->colorspace == CMYKColorspace)
542 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
547 *q=ScaleQuantumToChar(GetPixelIntensity(image,p));
555 p+=GetPixelChannels(image);
560 static void ExportDoublePixel(const Image *image,const RectangleInfo *roi,
561 const char *restrict map,const QuantumType *quantum_map,void *pixels,
562 ExceptionInfo *exception)
564 register const Quantum
580 if (LocaleCompare(map,"BGR") == 0)
582 for (y=0; y < (ssize_t) roi->height; y++)
584 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
585 if (p == (const Quantum *) NULL)
587 for (x=0; x < (ssize_t) roi->width; x++)
589 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
590 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
591 *q++=(double) (QuantumScale*GetPixelRed(image,p));
592 p+=GetPixelChannels(image);
597 if (LocaleCompare(map,"BGRA") == 0)
599 for (y=0; y < (ssize_t) roi->height; y++)
601 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
602 if (p == (const Quantum *) NULL)
604 for (x=0; x < (ssize_t) roi->width; x++)
606 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
607 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
608 *q++=(double) (QuantumScale*GetPixelRed(image,p));
609 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
610 p+=GetPixelChannels(image);
615 if (LocaleCompare(map,"BGRP") == 0)
617 for (y=0; y < (ssize_t) roi->height; y++)
619 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
620 if (p == (const Quantum *) NULL)
622 for (x=0; x < (ssize_t) roi->width; x++)
624 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
625 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
626 *q++=(double) (QuantumScale*GetPixelRed(image,p));
628 p+=GetPixelChannels(image);
633 if (LocaleCompare(map,"I") == 0)
635 for (y=0; y < (ssize_t) roi->height; y++)
637 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
638 if (p == (const Quantum *) NULL)
640 for (x=0; x < (ssize_t) roi->width; x++)
642 *q++=(double) (QuantumScale*GetPixelIntensity(image,p));
643 p+=GetPixelChannels(image);
648 if (LocaleCompare(map,"RGB") == 0)
650 for (y=0; y < (ssize_t) roi->height; y++)
652 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
653 if (p == (const Quantum *) NULL)
655 for (x=0; x < (ssize_t) roi->width; x++)
657 *q++=(double) (QuantumScale*GetPixelRed(image,p));
658 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
659 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
660 p+=GetPixelChannels(image);
665 if (LocaleCompare(map,"RGBA") == 0)
667 for (y=0; y < (ssize_t) roi->height; y++)
669 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
670 if (p == (const Quantum *) NULL)
672 for (x=0; x < (ssize_t) roi->width; x++)
674 *q++=(double) (QuantumScale*GetPixelRed(image,p));
675 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
676 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
677 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
678 p+=GetPixelChannels(image);
683 if (LocaleCompare(map,"RGBP") == 0)
685 for (y=0; y < (ssize_t) roi->height; y++)
687 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
688 if (p == (const Quantum *) NULL)
690 for (x=0; x < (ssize_t) roi->width; x++)
692 *q++=(double) (QuantumScale*GetPixelRed(image,p));
693 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
694 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
696 p+=GetPixelChannels(image);
702 for (y=0; y < (ssize_t) roi->height; y++)
704 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
705 if (p == (const Quantum *) NULL)
707 for (x=0; x < (ssize_t) roi->width; x++)
712 for (i=0; i < (ssize_t) length; i++)
715 switch (quantum_map[i])
720 *q=(double) (QuantumScale*GetPixelRed(image,p));
726 *q=(double) (QuantumScale*GetPixelGreen(image,p));
732 *q=(double) (QuantumScale*GetPixelBlue(image,p));
737 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
742 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
747 if (image->colorspace == CMYKColorspace)
748 *q=(double) (QuantumScale*
749 GetPixelBlack(image,p));
754 *q=(double) (QuantumScale*GetPixelIntensity(image,p));
762 p+=GetPixelChannels(image);
767 static void ExportFloatPixel(const Image *image,const RectangleInfo *roi,
768 const char *restrict map,const QuantumType *quantum_map,void *pixels,
769 ExceptionInfo *exception)
771 register const Quantum
787 if (LocaleCompare(map,"BGR") == 0)
789 for (y=0; y < (ssize_t) roi->height; y++)
791 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
792 if (p == (const Quantum *) NULL)
794 for (x=0; x < (ssize_t) roi->width; x++)
796 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
797 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
798 *q++=(float) (QuantumScale*GetPixelRed(image,p));
799 p+=GetPixelChannels(image);
804 if (LocaleCompare(map,"BGRA") == 0)
806 for (y=0; y < (ssize_t) roi->height; y++)
808 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
809 if (p == (const Quantum *) NULL)
811 for (x=0; x < (ssize_t) roi->width; x++)
813 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
814 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
815 *q++=(float) (QuantumScale*GetPixelRed(image,p));
816 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
817 p+=GetPixelChannels(image);
822 if (LocaleCompare(map,"BGRP") == 0)
824 for (y=0; y < (ssize_t) roi->height; y++)
826 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
827 if (p == (const Quantum *) NULL)
829 for (x=0; x < (ssize_t) roi->width; x++)
831 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
832 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
833 *q++=(float) (QuantumScale*GetPixelRed(image,p));
835 p+=GetPixelChannels(image);
840 if (LocaleCompare(map,"I") == 0)
842 for (y=0; y < (ssize_t) roi->height; y++)
844 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
845 if (p == (const Quantum *) NULL)
847 for (x=0; x < (ssize_t) roi->width; x++)
849 *q++=(float) (QuantumScale*GetPixelIntensity(image,p));
850 p+=GetPixelChannels(image);
855 if (LocaleCompare(map,"RGB") == 0)
857 for (y=0; y < (ssize_t) roi->height; y++)
859 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
860 if (p == (const Quantum *) NULL)
862 for (x=0; x < (ssize_t) roi->width; x++)
864 *q++=(float) (QuantumScale*GetPixelRed(image,p));
865 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
866 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
867 p+=GetPixelChannels(image);
872 if (LocaleCompare(map,"RGBA") == 0)
874 for (y=0; y < (ssize_t) roi->height; y++)
876 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
877 if (p == (const Quantum *) NULL)
879 for (x=0; x < (ssize_t) roi->width; x++)
881 *q++=(float) (QuantumScale*GetPixelRed(image,p));
882 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
883 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
884 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
885 p+=GetPixelChannels(image);
890 if (LocaleCompare(map,"RGBP") == 0)
892 for (y=0; y < (ssize_t) roi->height; y++)
894 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
895 if (p == (const Quantum *) NULL)
897 for (x=0; x < (ssize_t) roi->width; x++)
899 *q++=(float) (QuantumScale*GetPixelRed(image,p));
900 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
901 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
903 p+=GetPixelChannels(image);
909 for (y=0; y < (ssize_t) roi->height; y++)
911 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
912 if (p == (const Quantum *) NULL)
914 for (x=0; x < (ssize_t) roi->width; x++)
919 for (i=0; i < (ssize_t) length; i++)
922 switch (quantum_map[i])
927 *q=(float) (QuantumScale*GetPixelRed(image,p));
933 *q=(float) (QuantumScale*GetPixelGreen(image,p));
939 *q=(float) (QuantumScale*GetPixelBlue(image,p));
944 *q=(float) (QuantumScale*((Quantum) (GetPixelAlpha(image,p))));
949 *q=(float) (QuantumScale*GetPixelAlpha(image,p));
954 if (image->colorspace == CMYKColorspace)
955 *q=(float) (QuantumScale* GetPixelBlack(image,p));
960 *q=(float) (QuantumScale*GetPixelIntensity(image,p));
968 p+=GetPixelChannels(image);
973 static void ExportLongPixel(const Image *image,const RectangleInfo *roi,
974 const char *restrict map,const QuantumType *quantum_map,void *pixels,
975 ExceptionInfo *exception)
977 register const Quantum
983 register unsigned int
992 q=(unsigned int *) pixels;
993 if (LocaleCompare(map,"BGR") == 0)
995 for (y=0; y < (ssize_t) roi->height; y++)
997 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
998 if (p == (const Quantum *) NULL)
1000 for (x=0; x < (ssize_t) roi->width; x++)
1002 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1003 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1004 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1005 p+=GetPixelChannels(image);
1010 if (LocaleCompare(map,"BGRA") == 0)
1012 for (y=0; y < (ssize_t) roi->height; y++)
1014 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1015 if (p == (const Quantum *) NULL)
1017 for (x=0; x < (ssize_t) roi->width; x++)
1019 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1020 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1021 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1022 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1023 p+=GetPixelChannels(image);
1028 if (LocaleCompare(map,"BGRP") == 0)
1030 for (y=0; y < (ssize_t) roi->height; y++)
1032 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1033 if (p == (const Quantum *) NULL)
1035 for (x=0; x < (ssize_t) roi->width; x++)
1037 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1038 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1039 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1041 p+=GetPixelChannels(image);
1046 if (LocaleCompare(map,"I") == 0)
1048 for (y=0; y < (ssize_t) roi->height; y++)
1050 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1051 if (p == (const Quantum *) NULL)
1053 for (x=0; x < (ssize_t) roi->width; x++)
1055 *q++=ScaleQuantumToLong(GetPixelIntensity(image,p));
1056 p+=GetPixelChannels(image);
1061 if (LocaleCompare(map,"RGB") == 0)
1063 for (y=0; y < (ssize_t) roi->height; y++)
1065 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1066 if (p == (const Quantum *) NULL)
1068 for (x=0; x < (ssize_t) roi->width; x++)
1070 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1071 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1072 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1073 p+=GetPixelChannels(image);
1078 if (LocaleCompare(map,"RGBA") == 0)
1080 for (y=0; y < (ssize_t) roi->height; y++)
1082 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1083 if (p == (const Quantum *) NULL)
1085 for (x=0; x < (ssize_t) roi->width; x++)
1087 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1088 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1089 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1090 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1091 p+=GetPixelChannels(image);
1096 if (LocaleCompare(map,"RGBP") == 0)
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++)
1105 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1106 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1107 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1109 p+=GetPixelChannels(image);
1115 for (y=0; y < (ssize_t) roi->height; y++)
1117 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1118 if (p == (const Quantum *) NULL)
1120 for (x=0; x < (ssize_t) roi->width; x++)
1125 for (i=0; i < (ssize_t) length; i++)
1128 switch (quantum_map[i])
1133 *q=ScaleQuantumToLong(GetPixelRed(image,p));
1137 case MagentaQuantum:
1139 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
1145 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
1150 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1153 case OpacityQuantum:
1155 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1160 if (image->colorspace == CMYKColorspace)
1161 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
1166 *q=ScaleQuantumToLong(GetPixelIntensity(image,p));
1174 p+=GetPixelChannels(image);
1179 static void ExportLongLongPixel(const Image *image,const RectangleInfo *roi,
1180 const char *restrict map,const QuantumType *quantum_map,void *pixels,
1181 ExceptionInfo *exception)
1183 register const Quantum
1189 register MagickSizeType
1198 q=(MagickSizeType *) pixels;
1199 if (LocaleCompare(map,"BGR") == 0)
1201 for (y=0; y < (ssize_t) roi->height; y++)
1203 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1204 if (p == (const Quantum *) NULL)
1206 for (x=0; x < (ssize_t) roi->width; x++)
1208 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1209 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1210 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1211 p+=GetPixelChannels(image);
1216 if (LocaleCompare(map,"BGRA") == 0)
1218 for (y=0; y < (ssize_t) roi->height; y++)
1220 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1221 if (p == (const Quantum *) NULL)
1223 for (x=0; x < (ssize_t) roi->width; x++)
1225 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1226 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1227 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1228 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1229 p+=GetPixelChannels(image);
1234 if (LocaleCompare(map,"BGRP") == 0)
1236 for (y=0; y < (ssize_t) roi->height; y++)
1238 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1239 if (p == (const Quantum *) NULL)
1241 for (x=0; x < (ssize_t) roi->width; x++)
1243 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1244 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1245 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1247 p+=GetPixelChannels(image);
1252 if (LocaleCompare(map,"I") == 0)
1254 for (y=0; y < (ssize_t) roi->height; y++)
1256 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1257 if (p == (const Quantum *) NULL)
1259 for (x=0; x < (ssize_t) roi->width; x++)
1261 *q++=ScaleQuantumToLongLong(GetPixelIntensity(image,p));
1262 p+=GetPixelChannels(image);
1267 if (LocaleCompare(map,"RGB") == 0)
1269 for (y=0; y < (ssize_t) roi->height; y++)
1271 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1272 if (p == (const Quantum *) NULL)
1274 for (x=0; x < (ssize_t) roi->width; x++)
1276 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1277 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1278 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1279 p+=GetPixelChannels(image);
1284 if (LocaleCompare(map,"RGBA") == 0)
1286 for (y=0; y < (ssize_t) roi->height; y++)
1288 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1289 if (p == (const Quantum *) NULL)
1291 for (x=0; x < (ssize_t) roi->width; x++)
1293 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1294 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1295 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1296 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1297 p+=GetPixelChannels(image);
1302 if (LocaleCompare(map,"RGBP") == 0)
1304 for (y=0; y < (ssize_t) roi->height; y++)
1306 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1307 if (p == (const Quantum *) NULL)
1309 for (x=0; x < (ssize_t) roi->width; x++)
1311 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1312 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1313 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1315 p+=GetPixelChannels(image);
1321 for (y=0; y < (ssize_t) roi->height; y++)
1323 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1324 if (p == (const Quantum *) NULL)
1326 for (x=0; x < (ssize_t) roi->width; x++)
1331 for (i=0; i < (ssize_t) length; i++)
1334 switch (quantum_map[i])
1339 *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
1343 case MagentaQuantum:
1345 *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1351 *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1356 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1359 case OpacityQuantum:
1361 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1366 if (image->colorspace == CMYKColorspace)
1367 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
1372 *q=ScaleQuantumToLongLong(GetPixelIntensity(image,p));
1380 p+=GetPixelChannels(image);
1385 static void ExportQuantumPixel(const Image *image,const RectangleInfo *roi,
1386 const char *restrict map,const QuantumType *quantum_map,void *pixels,
1387 ExceptionInfo *exception)
1389 register const Quantum
1404 q=(Quantum *) pixels;
1405 if (LocaleCompare(map,"BGR") == 0)
1407 for (y=0; y < (ssize_t) roi->height; y++)
1409 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1410 if (p == (const Quantum *) NULL)
1412 for (x=0; x < (ssize_t) roi->width; x++)
1414 *q++=GetPixelBlue(image,p);
1415 *q++=GetPixelGreen(image,p);
1416 *q++=GetPixelRed(image,p);
1417 p+=GetPixelChannels(image);
1422 if (LocaleCompare(map,"BGRA") == 0)
1424 for (y=0; y < (ssize_t) roi->height; y++)
1426 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1427 if (p == (const Quantum *) NULL)
1429 for (x=0; x < (ssize_t) roi->width; x++)
1431 *q++=GetPixelBlue(image,p);
1432 *q++=GetPixelGreen(image,p);
1433 *q++=GetPixelRed(image,p);
1434 *q++=(Quantum) (GetPixelAlpha(image,p));
1435 p+=GetPixelChannels(image);
1440 if (LocaleCompare(map,"BGRP") == 0)
1442 for (y=0; y < (ssize_t) roi->height; y++)
1444 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1445 if (p == (const Quantum *) NULL)
1447 for (x=0; x < (ssize_t) roi->width; x++)
1449 *q++=GetPixelBlue(image,p);
1450 *q++=GetPixelGreen(image,p);
1451 *q++=GetPixelRed(image,p);
1453 p+=GetPixelChannels(image);
1458 if (LocaleCompare(map,"I") == 0)
1460 for (y=0; y < (ssize_t) roi->height; y++)
1462 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1463 if (p == (const Quantum *) NULL)
1465 for (x=0; x < (ssize_t) roi->width; x++)
1467 *q++=GetPixelIntensity(image,p);
1468 p+=GetPixelChannels(image);
1473 if (LocaleCompare(map,"RGB") == 0)
1475 for (y=0; y < (ssize_t) roi->height; y++)
1477 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1478 if (p == (const Quantum *) NULL)
1480 for (x=0; x < (ssize_t) roi->width; x++)
1482 *q++=GetPixelRed(image,p);
1483 *q++=GetPixelGreen(image,p);
1484 *q++=GetPixelBlue(image,p);
1485 p+=GetPixelChannels(image);
1490 if (LocaleCompare(map,"RGBA") == 0)
1492 for (y=0; y < (ssize_t) roi->height; y++)
1494 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1495 if (p == (const Quantum *) NULL)
1497 for (x=0; x < (ssize_t) roi->width; x++)
1499 *q++=GetPixelRed(image,p);
1500 *q++=GetPixelGreen(image,p);
1501 *q++=GetPixelBlue(image,p);
1502 *q++=(Quantum) (GetPixelAlpha(image,p));
1503 p+=GetPixelChannels(image);
1508 if (LocaleCompare(map,"RGBP") == 0)
1510 for (y=0; y < (ssize_t) roi->height; y++)
1512 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1513 if (p == (const Quantum *) NULL)
1515 for (x=0; x < (ssize_t) roi->width; x++)
1517 *q++=GetPixelRed(image,p);
1518 *q++=GetPixelGreen(image,p);
1519 *q++=GetPixelBlue(image,p);
1521 p+=GetPixelChannels(image);
1527 for (y=0; y < (ssize_t) roi->height; y++)
1529 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1530 if (p == (const Quantum *) NULL)
1532 for (x=0; x < (ssize_t) roi->width; x++)
1537 for (i=0; i < (ssize_t) length; i++)
1540 switch (quantum_map[i])
1545 *q=GetPixelRed(image,p);
1549 case MagentaQuantum:
1551 *q=GetPixelGreen(image,p);
1557 *q=GetPixelBlue(image,p);
1562 *q=GetPixelAlpha(image,p);
1565 case OpacityQuantum:
1567 *q=GetPixelAlpha(image,p);
1572 if (image->colorspace == CMYKColorspace)
1573 *q=GetPixelBlack(image,p);
1578 *q=(GetPixelIntensity(image,p));
1589 p+=GetPixelChannels(image);
1594 static void ExportShortPixel(const Image *image,const RectangleInfo *roi,
1595 const char *restrict map,const QuantumType *quantum_map,void *pixels,
1596 ExceptionInfo *exception)
1598 register const Quantum
1604 register unsigned short
1613 q=(unsigned short *) pixels;
1614 if (LocaleCompare(map,"BGR") == 0)
1616 for (y=0; y < (ssize_t) roi->height; y++)
1618 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1619 if (p == (const Quantum *) NULL)
1621 for (x=0; x < (ssize_t) roi->width; x++)
1623 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1624 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1625 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1626 p+=GetPixelChannels(image);
1631 if (LocaleCompare(map,"BGRA") == 0)
1633 for (y=0; y < (ssize_t) roi->height; y++)
1635 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1636 if (p == (const Quantum *) NULL)
1638 for (x=0; x < (ssize_t) roi->width; x++)
1640 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1641 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1642 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1643 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1644 p+=GetPixelChannels(image);
1649 if (LocaleCompare(map,"BGRP") == 0)
1651 for (y=0; y < (ssize_t) roi->height; y++)
1653 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1654 if (p == (const Quantum *) NULL)
1656 for (x=0; x < (ssize_t) roi->width; x++)
1658 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1659 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1660 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1662 p+=GetPixelChannels(image);
1667 if (LocaleCompare(map,"I") == 0)
1669 for (y=0; y < (ssize_t) roi->height; y++)
1671 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1672 if (p == (const Quantum *) NULL)
1674 for (x=0; x < (ssize_t) roi->width; x++)
1676 *q++=ScaleQuantumToShort(GetPixelIntensity(image,p));
1677 p+=GetPixelChannels(image);
1682 if (LocaleCompare(map,"RGB") == 0)
1684 for (y=0; y < (ssize_t) roi->height; y++)
1686 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1687 if (p == (const Quantum *) NULL)
1689 for (x=0; x < (ssize_t) roi->width; x++)
1691 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1692 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1693 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1694 p+=GetPixelChannels(image);
1699 if (LocaleCompare(map,"RGBA") == 0)
1701 for (y=0; y < (ssize_t) roi->height; y++)
1703 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1704 if (p == (const Quantum *) NULL)
1706 for (x=0; x < (ssize_t) roi->width; x++)
1708 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1709 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1710 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1711 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1712 p+=GetPixelChannels(image);
1717 if (LocaleCompare(map,"RGBP") == 0)
1719 for (y=0; y < (ssize_t) roi->height; y++)
1721 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1722 if (p == (const Quantum *) NULL)
1724 for (x=0; x < (ssize_t) roi->width; x++)
1726 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1727 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1728 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1730 p+=GetPixelChannels(image);
1736 for (y=0; y < (ssize_t) roi->height; y++)
1738 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1739 if (p == (const Quantum *) NULL)
1741 for (x=0; x < (ssize_t) roi->width; x++)
1746 for (i=0; i < (ssize_t) length; i++)
1749 switch (quantum_map[i])
1754 *q=ScaleQuantumToShort(GetPixelRed(image,p));
1758 case MagentaQuantum:
1760 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
1766 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
1771 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1774 case OpacityQuantum:
1776 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1781 if (image->colorspace == CMYKColorspace)
1782 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
1787 *q=ScaleQuantumToShort(GetPixelIntensity(image,p));
1795 p+=GetPixelChannels(image);
1800 MagickExport MagickBooleanType ExportImagePixels(const Image *image,
1801 const ssize_t x,const ssize_t y,const size_t width,const size_t height,
1802 const char *map,const StorageType type,void *pixels,ExceptionInfo *exception)
1816 assert(image != (Image *) NULL);
1817 assert(image->signature == MagickSignature);
1818 if (image->debug != MagickFalse)
1819 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1821 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1822 if (quantum_map == (QuantumType *) NULL)
1824 (void) ThrowMagickException(exception,GetMagickModule(),
1825 ResourceLimitError,"MemoryAllocationFailed","'%s'",image->filename);
1826 return(MagickFalse);
1828 for (i=0; i < (ssize_t) length; i++)
1835 quantum_map[i]=AlphaQuantum;
1841 quantum_map[i]=BlueQuantum;
1847 quantum_map[i]=CyanQuantum;
1848 if (image->colorspace == CMYKColorspace)
1850 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1851 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1852 "ColorSeparatedImageRequired","'%s'",map);
1853 return(MagickFalse);
1858 quantum_map[i]=GreenQuantum;
1864 quantum_map[i]=IndexQuantum;
1870 quantum_map[i]=BlackQuantum;
1871 if (image->colorspace == CMYKColorspace)
1873 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1874 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1875 "ColorSeparatedImageRequired","'%s'",map);
1876 return(MagickFalse);
1881 quantum_map[i]=MagentaQuantum;
1882 if (image->colorspace == CMYKColorspace)
1884 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1885 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1886 "ColorSeparatedImageRequired","'%s'",map);
1887 return(MagickFalse);
1892 quantum_map[i]=OpacityQuantum;
1898 quantum_map[i]=UndefinedQuantum;
1904 quantum_map[i]=RedQuantum;
1910 quantum_map[i]=YellowQuantum;
1911 if (image->colorspace == CMYKColorspace)
1913 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1914 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1915 "ColorSeparatedImageRequired","'%s'",map);
1916 return(MagickFalse);
1920 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1921 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1922 "UnrecognizedPixelMap","'%s'",map);
1923 return(MagickFalse);
1935 ExportCharPixel(image,&roi,map,quantum_map,pixels,exception);
1940 ExportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
1945 ExportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
1950 ExportLongPixel(image,&roi,map,quantum_map,pixels,exception);
1955 ExportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
1960 ExportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
1965 ExportShortPixel(image,&roi,map,quantum_map,pixels,exception);
1970 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1971 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1972 "UnrecognizedPixelMap","'%s'",map);
1976 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1981 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1985 % G e t P i x e l I n f o %
1989 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1991 % GetPixelInfo() initializes the PixelInfo structure.
1993 % The format of the GetPixelInfo method is:
1995 % GetPixelInfo(const Image *image,PixelInfo *pixel)
1997 % A description of each parameter follows:
1999 % o image: the image.
2001 % o pixel: Specifies a pointer to a PixelInfo structure.
2004 MagickExport void GetPixelInfo(const Image *image,PixelInfo *pixel)
2006 pixel->storage_class=DirectClass;
2007 pixel->colorspace=sRGBColorspace;
2008 pixel->matte=MagickFalse;
2010 pixel->depth=MAGICKCORE_QUANTUM_DEPTH;
2015 pixel->alpha=(MagickRealType) OpaqueAlpha;
2017 if (image == (const Image *) NULL)
2019 pixel->storage_class=image->storage_class;
2020 pixel->colorspace=image->colorspace;
2021 pixel->matte=image->matte;
2022 pixel->depth=image->depth;
2023 pixel->fuzz=image->fuzz;
2027 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2031 % I m p o r t I m a g e P i x e l s %
2035 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2037 % ImportImagePixels() accepts pixel data and stores in the image at the
2038 % location you specify. The method returns MagickTrue on success otherwise
2039 % MagickFalse if an error is encountered. The pixel data can be either char,
2040 % Quantum, short int, unsigned int, unsigned long long, float, or double in
2041 % the order specified by map.
2043 % Suppose your want to upload the first scanline of a 640x480 image from
2044 % character data in red-green-blue order:
2046 % ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels);
2048 % The format of the ImportImagePixels method is:
2050 % MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
2051 % const ssize_t y,const size_t width,const size_t height,
2052 % const char *map,const StorageType type,const void *pixels,
2053 % ExceptionInfo *exception)
2055 % A description of each parameter follows:
2057 % o image: the image.
2059 % o x,y,width,height: These values define the perimeter
2060 % of a region of pixels you want to define.
2062 % o map: This string reflects the expected ordering of the pixel array.
2063 % It can be any combination or order of R = red, G = green, B = blue,
2064 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
2065 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
2068 % o type: Define the data type of the pixels. Float and double types are
2069 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
2070 % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *),
2071 % LongPixel (unsigned int *), LongLongPixel (unsigned long long *),
2072 % QuantumPixel (Quantum *), or ShortPixel (unsigned short *).
2074 % o pixels: This array of values contain the pixel components as defined by
2075 % map and type. You must preallocate this array where the expected
2076 % length varies depending on the values of width, height, map, and type.
2078 % o exception: return any errors or warnings in this structure.
2082 static void ImportCharPixel(Image *image,const RectangleInfo *roi,
2083 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2084 ExceptionInfo *exception)
2086 register const unsigned char
2101 p=(const unsigned char *) pixels;
2102 if (LocaleCompare(map,"BGR") == 0)
2104 for (y=0; y < (ssize_t) roi->height; y++)
2106 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2107 if (q == (Quantum *) NULL)
2109 for (x=0; x < (ssize_t) roi->width; x++)
2111 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2112 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2113 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2114 q+=GetPixelChannels(image);
2116 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2121 if (LocaleCompare(map,"BGRA") == 0)
2123 for (y=0; y < (ssize_t) roi->height; y++)
2125 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2126 if (q == (Quantum *) NULL)
2128 for (x=0; x < (ssize_t) roi->width; x++)
2130 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2131 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2132 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2133 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2134 q+=GetPixelChannels(image);
2136 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2141 if (LocaleCompare(map,"BGRO") == 0)
2143 for (y=0; y < (ssize_t) roi->height; y++)
2145 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2146 if (q == (Quantum *) NULL)
2148 for (x=0; x < (ssize_t) roi->width; x++)
2150 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2151 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2152 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2153 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2154 q+=GetPixelChannels(image);
2156 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2161 if (LocaleCompare(map,"BGRP") == 0)
2163 for (y=0; y < (ssize_t) roi->height; y++)
2165 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2166 if (q == (Quantum *) NULL)
2168 for (x=0; x < (ssize_t) roi->width; x++)
2170 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2171 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2172 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2174 q+=GetPixelChannels(image);
2176 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2181 if (LocaleCompare(map,"I") == 0)
2183 for (y=0; y < (ssize_t) roi->height; y++)
2185 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2186 if (q == (Quantum *) NULL)
2188 for (x=0; x < (ssize_t) roi->width; x++)
2190 SetPixelGray(image,ScaleCharToQuantum(*p++),q);
2191 q+=GetPixelChannels(image);
2193 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2198 if (LocaleCompare(map,"RGB") == 0)
2200 for (y=0; y < (ssize_t) roi->height; y++)
2202 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2203 if (q == (Quantum *) NULL)
2205 for (x=0; x < (ssize_t) roi->width; x++)
2207 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2208 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2209 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2210 q+=GetPixelChannels(image);
2212 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2217 if (LocaleCompare(map,"RGBA") == 0)
2219 for (y=0; y < (ssize_t) roi->height; y++)
2221 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2222 if (q == (Quantum *) NULL)
2224 for (x=0; x < (ssize_t) roi->width; x++)
2226 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2227 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2228 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2229 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2230 q+=GetPixelChannels(image);
2232 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2237 if (LocaleCompare(map,"RGBO") == 0)
2239 for (y=0; y < (ssize_t) roi->height; y++)
2241 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2242 if (q == (Quantum *) NULL)
2244 for (x=0; x < (ssize_t) roi->width; x++)
2246 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2247 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2248 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2249 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2250 q+=GetPixelChannels(image);
2252 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2257 if (LocaleCompare(map,"RGBP") == 0)
2259 for (y=0; y < (ssize_t) roi->height; y++)
2261 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2262 if (q == (Quantum *) NULL)
2264 for (x=0; x < (ssize_t) roi->width; x++)
2266 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2267 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2268 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2270 q+=GetPixelChannels(image);
2272 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2278 for (y=0; y < (ssize_t) roi->height; y++)
2280 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2281 if (q == (Quantum *) NULL)
2283 for (x=0; x < (ssize_t) roi->width; x++)
2288 for (i=0; i < (ssize_t) length; i++)
2290 switch (quantum_map[i])
2295 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2299 case MagentaQuantum:
2301 SetPixelGreen(image,ScaleCharToQuantum(*p),q);
2307 SetPixelBlue(image,ScaleCharToQuantum(*p),q);
2312 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2315 case OpacityQuantum:
2317 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2322 SetPixelBlack(image,ScaleCharToQuantum(*p),q);
2327 SetPixelGray(image,ScaleCharToQuantum(*p),q);
2335 q+=GetPixelChannels(image);
2337 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2342 static void ImportDoublePixel(Image *image,const RectangleInfo *roi,
2343 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2344 ExceptionInfo *exception)
2346 register const double
2361 p=(const double *) pixels;
2362 if (LocaleCompare(map,"BGR") == 0)
2364 for (y=0; y < (ssize_t) roi->height; y++)
2366 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2367 if (q == (Quantum *) NULL)
2369 for (x=0; x < (ssize_t) roi->width; x++)
2371 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2374 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2377 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2380 q+=GetPixelChannels(image);
2382 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2387 if (LocaleCompare(map,"BGRA") == 0)
2389 for (y=0; y < (ssize_t) roi->height; y++)
2391 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2392 if (q == (Quantum *) NULL)
2394 for (x=0; x < (ssize_t) roi->width; x++)
2396 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2399 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2402 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2405 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2408 q+=GetPixelChannels(image);
2410 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2415 if (LocaleCompare(map,"BGRP") == 0)
2417 for (y=0; y < (ssize_t) roi->height; y++)
2419 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2420 if (q == (Quantum *) NULL)
2422 for (x=0; x < (ssize_t) roi->width; x++)
2424 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2427 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2430 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2434 q+=GetPixelChannels(image);
2436 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2441 if (LocaleCompare(map,"I") == 0)
2443 for (y=0; y < (ssize_t) roi->height; y++)
2445 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2446 if (q == (Quantum *) NULL)
2448 for (x=0; x < (ssize_t) roi->width; x++)
2450 SetPixelGray(image,ClampToQuantum((MagickRealType) QuantumRange*
2453 q+=GetPixelChannels(image);
2455 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2460 if (LocaleCompare(map,"RGB") == 0)
2462 for (y=0; y < (ssize_t) roi->height; y++)
2464 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2465 if (q == (Quantum *) NULL)
2467 for (x=0; x < (ssize_t) roi->width; x++)
2469 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2472 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2475 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2478 q+=GetPixelChannels(image);
2480 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2485 if (LocaleCompare(map,"RGBA") == 0)
2487 for (y=0; y < (ssize_t) roi->height; y++)
2489 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2490 if (q == (Quantum *) NULL)
2492 for (x=0; x < (ssize_t) roi->width; x++)
2494 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2497 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2500 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2503 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2506 q+=GetPixelChannels(image);
2508 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2513 if (LocaleCompare(map,"RGBP") == 0)
2515 for (y=0; y < (ssize_t) roi->height; y++)
2517 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2518 if (q == (Quantum *) NULL)
2520 for (x=0; x < (ssize_t) roi->width; x++)
2522 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2525 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2528 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2531 q+=GetPixelChannels(image);
2533 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2539 for (y=0; y < (ssize_t) roi->height; y++)
2541 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2542 if (q == (Quantum *) NULL)
2544 for (x=0; x < (ssize_t) roi->width; x++)
2549 for (i=0; i < (ssize_t) length; i++)
2551 switch (quantum_map[i])
2556 SetPixelRed(image,ClampToQuantum((MagickRealType)
2557 QuantumRange*(*p)),q);
2561 case MagentaQuantum:
2563 SetPixelGreen(image,ClampToQuantum((MagickRealType)
2564 QuantumRange*(*p)),q);
2570 SetPixelBlue(image,ClampToQuantum((MagickRealType)
2571 QuantumRange*(*p)),q);
2576 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2577 QuantumRange*(*p)),q);
2580 case OpacityQuantum:
2582 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2583 QuantumRange*(*p)),q);
2588 SetPixelBlack(image,ClampToQuantum((MagickRealType)
2589 QuantumRange*(*p)),q);
2594 SetPixelGray(image,ClampToQuantum((MagickRealType)
2595 QuantumRange*(*p)),q);
2603 q+=GetPixelChannels(image);
2605 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2610 static void ImportFloatPixel(Image *image,const RectangleInfo *roi,
2611 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2612 ExceptionInfo *exception)
2614 register const float
2629 p=(const float *) pixels;
2630 if (LocaleCompare(map,"BGR") == 0)
2632 for (y=0; y < (ssize_t) roi->height; y++)
2634 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2635 if (q == (Quantum *) NULL)
2637 for (x=0; x < (ssize_t) roi->width; x++)
2639 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2642 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2645 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2648 q+=GetPixelChannels(image);
2650 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2655 if (LocaleCompare(map,"BGRA") == 0)
2657 for (y=0; y < (ssize_t) roi->height; y++)
2659 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2660 if (q == (Quantum *) NULL)
2662 for (x=0; x < (ssize_t) roi->width; x++)
2664 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2667 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2670 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2673 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2676 q+=GetPixelChannels(image);
2678 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2683 if (LocaleCompare(map,"BGRP") == 0)
2685 for (y=0; y < (ssize_t) roi->height; y++)
2687 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2688 if (q == (Quantum *) NULL)
2690 for (x=0; x < (ssize_t) roi->width; x++)
2692 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2695 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2698 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2702 q+=GetPixelChannels(image);
2704 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2709 if (LocaleCompare(map,"I") == 0)
2711 for (y=0; y < (ssize_t) roi->height; y++)
2713 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2714 if (q == (Quantum *) NULL)
2716 for (x=0; x < (ssize_t) roi->width; x++)
2718 SetPixelGray(image,ClampToQuantum((MagickRealType) QuantumRange*
2721 q+=GetPixelChannels(image);
2723 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2728 if (LocaleCompare(map,"RGB") == 0)
2730 for (y=0; y < (ssize_t) roi->height; y++)
2732 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2733 if (q == (Quantum *) NULL)
2735 for (x=0; x < (ssize_t) roi->width; x++)
2737 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2740 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2743 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2746 q+=GetPixelChannels(image);
2748 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2753 if (LocaleCompare(map,"RGBA") == 0)
2755 for (y=0; y < (ssize_t) roi->height; y++)
2757 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2758 if (q == (Quantum *) NULL)
2760 for (x=0; x < (ssize_t) roi->width; x++)
2762 SetPixelRed(image,ClampToQuantum((MagickRealType)
2763 QuantumRange*(*p)),q);
2765 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2768 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2771 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2774 q+=GetPixelChannels(image);
2776 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2781 if (LocaleCompare(map,"RGBP") == 0)
2783 for (y=0; y < (ssize_t) roi->height; y++)
2785 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2786 if (q == (Quantum *) NULL)
2788 for (x=0; x < (ssize_t) roi->width; x++)
2790 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2793 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2796 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2799 q+=GetPixelChannels(image);
2801 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2807 for (y=0; y < (ssize_t) roi->height; y++)
2809 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2810 if (q == (Quantum *) NULL)
2812 for (x=0; x < (ssize_t) roi->width; x++)
2817 for (i=0; i < (ssize_t) length; i++)
2819 switch (quantum_map[i])
2824 SetPixelRed(image,ClampToQuantum((MagickRealType)
2825 QuantumRange*(*p)),q);
2829 case MagentaQuantum:
2831 SetPixelGreen(image,ClampToQuantum((MagickRealType)
2832 QuantumRange*(*p)),q);
2838 SetPixelBlue(image,ClampToQuantum((MagickRealType)
2839 QuantumRange*(*p)),q);
2844 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2845 QuantumRange*(*p)),q);
2848 case OpacityQuantum:
2850 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2851 QuantumRange*(*p)),q);
2856 SetPixelBlack(image,ClampToQuantum((MagickRealType)
2857 QuantumRange*(*p)),q);
2862 SetPixelGray(image,ClampToQuantum((MagickRealType)
2863 QuantumRange*(*p)),q);
2871 q+=GetPixelChannels(image);
2873 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2878 static void ImportLongPixel(Image *image,const RectangleInfo *roi,
2879 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2880 ExceptionInfo *exception)
2882 register const unsigned int
2897 p=(const unsigned int *) pixels;
2898 if (LocaleCompare(map,"BGR") == 0)
2900 for (y=0; y < (ssize_t) roi->height; y++)
2902 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2903 if (q == (Quantum *) NULL)
2905 for (x=0; x < (ssize_t) roi->width; x++)
2907 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2908 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2909 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2910 q+=GetPixelChannels(image);
2912 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2917 if (LocaleCompare(map,"BGRA") == 0)
2919 for (y=0; y < (ssize_t) roi->height; y++)
2921 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2922 if (q == (Quantum *) NULL)
2924 for (x=0; x < (ssize_t) roi->width; x++)
2926 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2927 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2928 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2929 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
2930 q+=GetPixelChannels(image);
2932 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2937 if (LocaleCompare(map,"BGRP") == 0)
2939 for (y=0; y < (ssize_t) roi->height; y++)
2941 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2942 if (q == (Quantum *) NULL)
2944 for (x=0; x < (ssize_t) roi->width; x++)
2946 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2947 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2948 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2950 q+=GetPixelChannels(image);
2952 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2957 if (LocaleCompare(map,"I") == 0)
2959 for (y=0; y < (ssize_t) roi->height; y++)
2961 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2962 if (q == (Quantum *) NULL)
2964 for (x=0; x < (ssize_t) roi->width; x++)
2966 SetPixelGray(image,ScaleLongToQuantum(*p++),q);
2967 q+=GetPixelChannels(image);
2969 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2974 if (LocaleCompare(map,"RGB") == 0)
2976 for (y=0; y < (ssize_t) roi->height; y++)
2978 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2979 if (q == (Quantum *) NULL)
2981 for (x=0; x < (ssize_t) roi->width; x++)
2983 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2984 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2985 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2986 q+=GetPixelChannels(image);
2988 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2993 if (LocaleCompare(map,"RGBA") == 0)
2995 for (y=0; y < (ssize_t) roi->height; y++)
2997 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2998 if (q == (Quantum *) NULL)
3000 for (x=0; x < (ssize_t) roi->width; x++)
3002 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3003 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3004 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3005 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3006 q+=GetPixelChannels(image);
3008 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3013 if (LocaleCompare(map,"RGBP") == 0)
3015 for (y=0; y < (ssize_t) roi->height; y++)
3017 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3018 if (q == (Quantum *) NULL)
3020 for (x=0; x < (ssize_t) roi->width; x++)
3022 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3023 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3024 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3026 q+=GetPixelChannels(image);
3028 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3034 for (y=0; y < (ssize_t) roi->height; y++)
3036 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3037 if (q == (Quantum *) NULL)
3039 for (x=0; x < (ssize_t) roi->width; x++)
3044 for (i=0; i < (ssize_t) length; i++)
3046 switch (quantum_map[i])
3051 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3055 case MagentaQuantum:
3057 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
3063 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
3068 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3071 case OpacityQuantum:
3073 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3078 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
3083 SetPixelGray(image,ScaleLongToQuantum(*p),q);
3091 q+=GetPixelChannels(image);
3093 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3098 static void ImportLongLongPixel(Image *image,const RectangleInfo *roi,
3099 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3100 ExceptionInfo *exception)
3102 register const MagickSizeType
3117 p=(const MagickSizeType *) pixels;
3118 if (LocaleCompare(map,"BGR") == 0)
3120 for (y=0; y < (ssize_t) roi->height; y++)
3122 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3123 if (q == (Quantum *) NULL)
3125 for (x=0; x < (ssize_t) roi->width; x++)
3127 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3128 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3129 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3130 q+=GetPixelChannels(image);
3132 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3137 if (LocaleCompare(map,"BGRA") == 0)
3139 for (y=0; y < (ssize_t) roi->height; y++)
3141 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3142 if (q == (Quantum *) NULL)
3144 for (x=0; x < (ssize_t) roi->width; x++)
3146 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3147 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3148 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3149 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3150 q+=GetPixelChannels(image);
3152 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3157 if (LocaleCompare(map,"BGRP") == 0)
3159 for (y=0; y < (ssize_t) roi->height; y++)
3161 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3162 if (q == (Quantum *) NULL)
3164 for (x=0; x < (ssize_t) roi->width; x++)
3166 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3167 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3168 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3170 q+=GetPixelChannels(image);
3172 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3177 if (LocaleCompare(map,"I") == 0)
3179 for (y=0; y < (ssize_t) roi->height; y++)
3181 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3182 if (q == (Quantum *) NULL)
3184 for (x=0; x < (ssize_t) roi->width; x++)
3186 SetPixelGray(image,ScaleLongLongToQuantum(*p++),q);
3187 q+=GetPixelChannels(image);
3189 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3194 if (LocaleCompare(map,"RGB") == 0)
3196 for (y=0; y < (ssize_t) roi->height; y++)
3198 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3199 if (q == (Quantum *) NULL)
3201 for (x=0; x < (ssize_t) roi->width; x++)
3203 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3204 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3205 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3206 q+=GetPixelChannels(image);
3208 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3213 if (LocaleCompare(map,"RGBA") == 0)
3215 for (y=0; y < (ssize_t) roi->height; y++)
3217 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3218 if (q == (Quantum *) NULL)
3220 for (x=0; x < (ssize_t) roi->width; x++)
3222 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3223 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3224 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3225 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3226 q+=GetPixelChannels(image);
3228 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3233 if (LocaleCompare(map,"RGBP") == 0)
3235 for (y=0; y < (ssize_t) roi->height; y++)
3237 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3238 if (q == (Quantum *) NULL)
3240 for (x=0; x < (ssize_t) roi->width; x++)
3242 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3243 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3244 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3246 q+=GetPixelChannels(image);
3248 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3254 for (y=0; y < (ssize_t) roi->height; y++)
3256 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3257 if (q == (Quantum *) NULL)
3259 for (x=0; x < (ssize_t) roi->width; x++)
3264 for (i=0; i < (ssize_t) length; i++)
3266 switch (quantum_map[i])
3271 SetPixelRed(image,ScaleLongLongToQuantum(*p),q);
3275 case MagentaQuantum:
3277 SetPixelGreen(image,ScaleLongLongToQuantum(*p),q);
3283 SetPixelBlue(image,ScaleLongLongToQuantum(*p),q);
3288 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3291 case OpacityQuantum:
3293 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3298 SetPixelBlack(image,ScaleLongLongToQuantum(*p),q);
3303 SetPixelGray(image,ScaleLongLongToQuantum(*p),q);
3311 q+=GetPixelChannels(image);
3313 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3318 static void ImportQuantumPixel(Image *image,const RectangleInfo *roi,
3319 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3320 ExceptionInfo *exception)
3322 register const Quantum
3337 p=(const Quantum *) pixels;
3338 if (LocaleCompare(map,"BGR") == 0)
3340 for (y=0; y < (ssize_t) roi->height; y++)
3342 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3343 if (q == (Quantum *) NULL)
3345 for (x=0; x < (ssize_t) roi->width; x++)
3347 SetPixelBlue(image,*p++,q);
3348 SetPixelGreen(image,*p++,q);
3349 SetPixelRed(image,*p++,q);
3350 q+=GetPixelChannels(image);
3352 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3357 if (LocaleCompare(map,"BGRA") == 0)
3359 for (y=0; y < (ssize_t) roi->height; y++)
3361 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3362 if (q == (Quantum *) NULL)
3364 for (x=0; x < (ssize_t) roi->width; x++)
3366 SetPixelBlue(image,*p++,q);
3367 SetPixelGreen(image,*p++,q);
3368 SetPixelRed(image,*p++,q);
3369 SetPixelAlpha(image,*p++,q);
3370 q+=GetPixelChannels(image);
3372 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3377 if (LocaleCompare(map,"BGRP") == 0)
3379 for (y=0; y < (ssize_t) roi->height; y++)
3381 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3382 if (q == (Quantum *) NULL)
3384 for (x=0; x < (ssize_t) roi->width; x++)
3386 SetPixelBlue(image,*p++,q);
3387 SetPixelGreen(image,*p++,q);
3388 SetPixelRed(image,*p++,q);
3390 q+=GetPixelChannels(image);
3392 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3397 if (LocaleCompare(map,"I") == 0)
3399 for (y=0; y < (ssize_t) roi->height; y++)
3401 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3402 if (q == (Quantum *) NULL)
3404 for (x=0; x < (ssize_t) roi->width; x++)
3406 SetPixelGray(image,*p++,q);
3407 q+=GetPixelChannels(image);
3409 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3414 if (LocaleCompare(map,"RGB") == 0)
3416 for (y=0; y < (ssize_t) roi->height; y++)
3418 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3419 if (q == (Quantum *) NULL)
3421 for (x=0; x < (ssize_t) roi->width; x++)
3423 SetPixelRed(image,*p++,q);
3424 SetPixelGreen(image,*p++,q);
3425 SetPixelBlue(image,*p++,q);
3426 q+=GetPixelChannels(image);
3428 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3433 if (LocaleCompare(map,"RGBA") == 0)
3435 for (y=0; y < (ssize_t) roi->height; y++)
3437 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3438 if (q == (Quantum *) NULL)
3440 for (x=0; x < (ssize_t) roi->width; x++)
3442 SetPixelRed(image,*p++,q);
3443 SetPixelGreen(image,*p++,q);
3444 SetPixelBlue(image,*p++,q);
3445 SetPixelAlpha(image,*p++,q);
3446 q+=GetPixelChannels(image);
3448 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3453 if (LocaleCompare(map,"RGBP") == 0)
3455 for (y=0; y < (ssize_t) roi->height; y++)
3457 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3458 if (q == (Quantum *) NULL)
3460 for (x=0; x < (ssize_t) roi->width; x++)
3462 SetPixelRed(image,*p++,q);
3463 SetPixelGreen(image,*p++,q);
3464 SetPixelBlue(image,*p++,q);
3466 q+=GetPixelChannels(image);
3468 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3474 for (y=0; y < (ssize_t) roi->height; y++)
3476 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3477 if (q == (Quantum *) NULL)
3479 for (x=0; x < (ssize_t) roi->width; x++)
3484 for (i=0; i < (ssize_t) length; i++)
3486 switch (quantum_map[i])
3491 SetPixelRed(image,*p,q);
3495 case MagentaQuantum:
3497 SetPixelGreen(image,*p,q);
3503 SetPixelBlue(image,*p,q);
3508 SetPixelAlpha(image,*p,q);
3511 case OpacityQuantum:
3513 SetPixelAlpha(image,*p,q);
3518 SetPixelBlack(image,*p,q);
3523 SetPixelGray(image,*p,q);
3531 q+=GetPixelChannels(image);
3533 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3538 static void ImportShortPixel(Image *image,const RectangleInfo *roi,
3539 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3540 ExceptionInfo *exception)
3542 register const unsigned short
3557 p=(const unsigned short *) pixels;
3558 if (LocaleCompare(map,"BGR") == 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 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3568 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3569 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3570 q+=GetPixelChannels(image);
3572 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3577 if (LocaleCompare(map,"BGRA") == 0)
3579 for (y=0; y < (ssize_t) roi->height; y++)
3581 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3582 if (q == (Quantum *) NULL)
3584 for (x=0; x < (ssize_t) roi->width; x++)
3586 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3587 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3588 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3589 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3590 q+=GetPixelChannels(image);
3592 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3597 if (LocaleCompare(map,"BGRP") == 0)
3599 for (y=0; y < (ssize_t) roi->height; y++)
3601 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3602 if (q == (Quantum *) NULL)
3604 for (x=0; x < (ssize_t) roi->width; x++)
3606 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3607 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3608 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3610 q+=GetPixelChannels(image);
3612 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3617 if (LocaleCompare(map,"I") == 0)
3619 for (y=0; y < (ssize_t) roi->height; y++)
3621 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3622 if (q == (Quantum *) NULL)
3624 for (x=0; x < (ssize_t) roi->width; x++)
3626 SetPixelGray(image,ScaleShortToQuantum(*p++),q);
3627 q+=GetPixelChannels(image);
3629 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3634 if (LocaleCompare(map,"RGB") == 0)
3636 for (y=0; y < (ssize_t) roi->height; y++)
3638 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3639 if (q == (Quantum *) NULL)
3641 for (x=0; x < (ssize_t) roi->width; x++)
3643 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3644 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3645 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3646 q+=GetPixelChannels(image);
3648 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3653 if (LocaleCompare(map,"RGBA") == 0)
3655 for (y=0; y < (ssize_t) roi->height; y++)
3657 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3658 if (q == (Quantum *) NULL)
3660 for (x=0; x < (ssize_t) roi->width; x++)
3662 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3663 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3664 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3665 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3666 q+=GetPixelChannels(image);
3668 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3673 if (LocaleCompare(map,"RGBP") == 0)
3675 for (y=0; y < (ssize_t) roi->height; y++)
3677 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3678 if (q == (Quantum *) NULL)
3680 for (x=0; x < (ssize_t) roi->width; x++)
3682 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3683 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3684 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3686 q+=GetPixelChannels(image);
3688 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3694 for (y=0; y < (ssize_t) roi->height; y++)
3696 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3697 if (q == (Quantum *) NULL)
3699 for (x=0; x < (ssize_t) roi->width; x++)
3704 for (i=0; i < (ssize_t) length; i++)
3706 switch (quantum_map[i])
3711 SetPixelRed(image,ScaleShortToQuantum(*p),q);
3715 case MagentaQuantum:
3717 SetPixelGreen(image,ScaleShortToQuantum(*p),q);
3723 SetPixelBlue(image,ScaleShortToQuantum(*p),q);
3728 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3731 case OpacityQuantum:
3733 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3738 SetPixelBlack(image,ScaleShortToQuantum(*p),q);
3743 SetPixelGray(image,ScaleShortToQuantum(*p),q);
3751 q+=GetPixelChannels(image);
3753 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3758 MagickExport MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
3759 const ssize_t y,const size_t width,const size_t height,const char *map,
3760 const StorageType type,const void *pixels,ExceptionInfo *exception)
3775 Allocate image structure.
3777 assert(image != (Image *) NULL);
3778 assert(image->signature == MagickSignature);
3779 if (image->debug != MagickFalse)
3780 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3782 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
3783 if (quantum_map == (QuantumType *) NULL)
3784 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
3786 for (i=0; i < (ssize_t) length; i++)
3793 quantum_map[i]=AlphaQuantum;
3794 image->matte=MagickTrue;
3800 quantum_map[i]=BlueQuantum;
3806 quantum_map[i]=CyanQuantum;
3807 (void) SetImageColorspace(image,CMYKColorspace,exception);
3813 quantum_map[i]=GreenQuantum;
3819 quantum_map[i]=BlackQuantum;
3820 (void) SetImageColorspace(image,CMYKColorspace,exception);
3826 quantum_map[i]=IndexQuantum;
3832 quantum_map[i]=MagentaQuantum;
3833 (void) SetImageColorspace(image,CMYKColorspace,exception);
3839 quantum_map[i]=OpacityQuantum;
3840 image->matte=MagickTrue;
3846 quantum_map[i]=UndefinedQuantum;
3852 quantum_map[i]=RedQuantum;
3858 quantum_map[i]=YellowQuantum;
3859 (void) SetImageColorspace(image,CMYKColorspace,exception);
3864 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3865 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3866 "UnrecognizedPixelMap","'%s'",map);
3867 return(MagickFalse);
3871 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
3872 return(MagickFalse);
3874 Transfer the pixels from the pixel data to the image.
3884 ImportCharPixel(image,&roi,map,quantum_map,pixels,exception);
3889 ImportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
3894 ImportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
3899 ImportLongPixel(image,&roi,map,quantum_map,pixels,exception);
3904 ImportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
3909 ImportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
3914 ImportShortPixel(image,&roi,map,quantum_map,pixels,exception);
3919 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3920 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3921 "UnrecognizedPixelMap","'%s'",map);
3925 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3930 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3934 + 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 %
3938 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3940 % InitializePixelChannelMap() defines the standard pixel component map.
3942 % The format of the InitializePixelChannelMap() method is:
3944 % void InitializePixelChannelMap(Image *image)
3946 % A description of each parameter follows:
3948 % o image: the image.
3951 MagickExport void InitializePixelChannelMap(Image *image)
3962 assert(image != (Image *) NULL);
3963 assert(image->signature == MagickSignature);
3964 (void) ResetMagickMemory(image->channel_map,0,MaxPixelChannels*
3965 sizeof(*image->channel_map));
3966 trait=UpdatePixelTrait;
3967 if (image->matte != MagickFalse)
3968 trait=(PixelTrait) (trait | BlendPixelTrait);
3970 if (image->colorspace == GRAYColorspace)
3972 SetPixelChannelMap(image,BluePixelChannel,trait,n);
3973 SetPixelChannelMap(image,GreenPixelChannel,trait,n);
3974 SetPixelChannelMap(image,RedPixelChannel,trait,n++);
3978 SetPixelChannelMap(image,RedPixelChannel,trait,n++);
3979 SetPixelChannelMap(image,GreenPixelChannel,trait,n++);
3980 SetPixelChannelMap(image,BluePixelChannel,trait,n++);
3982 if (image->colorspace == CMYKColorspace)
3983 SetPixelChannelMap(image,BlackPixelChannel,trait,n++);
3984 if (image->matte != MagickFalse)
3985 SetPixelChannelMap(image,AlphaPixelChannel,CopyPixelTrait,n++);
3986 if (image->storage_class == PseudoClass)
3987 SetPixelChannelMap(image,IndexPixelChannel,CopyPixelTrait,n++);
3988 if (image->mask != MagickFalse)
3989 SetPixelChannelMap(image,MaskPixelChannel,CopyPixelTrait,n++);
3990 assert((n+image->number_meta_channels) < MaxPixelChannels);
3991 for (i=0; i < (ssize_t) image->number_meta_channels; i++)
3992 SetPixelChannelMap(image,(PixelChannel) (MetaPixelChannel+i),CopyPixelTrait,
3994 image->number_channels=(size_t) n;
3995 if (image->debug != MagickFalse)
3996 LogPixelChannels(image);
3997 (void) SetPixelChannelMask(image,image->channel_mask);
4001 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4005 % I n t e r p o l a t e P i x e l C h a n n e l %
4009 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4011 % InterpolatePixelChannel() applies a pixel interpolation method between a
4012 % floating point coordinate and the pixels surrounding that coordinate. No
4013 % pixel area resampling, or scaling of the result is performed.
4015 % The format of the InterpolatePixelChannel method is:
4017 % MagickBooleanType InterpolatePixelChannel(const Image *image,
4018 % const CacheView *image_view,const PixelChannel channel,
4019 % const PixelInterpolateMethod method,const double x,const double y,
4020 % double *pixel,ExceptionInfo *exception)
4022 % A description of each parameter follows:
4024 % o image: the image.
4026 % o image_view: the image view.
4028 % o channel: the pixel channel to interpolate.
4030 % o method: the pixel color interpolation method.
4032 % o x,y: A double representing the current (x,y) position of the pixel.
4034 % o pixel: return the interpolated pixel here.
4036 % o exception: return any errors or warnings in this structure.
4040 static inline double MagickMax(const MagickRealType x,const MagickRealType y)
4047 static inline MagickRealType CubicWeightingFunction(const MagickRealType x)
4053 alpha=MagickMax(x+2.0,0.0);
4054 gamma=1.0*alpha*alpha*alpha;
4055 alpha=MagickMax(x+1.0,0.0);
4056 gamma-=4.0*alpha*alpha*alpha;
4057 alpha=MagickMax(x+0.0,0.0);
4058 gamma+=6.0*alpha*alpha*alpha;
4059 alpha=MagickMax(x-1.0,0.0);
4060 gamma-=4.0*alpha*alpha*alpha;
4064 static inline double MeshInterpolate(const PointInfo *delta,const double p,
4065 const double x,const double y)
4067 return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
4070 static inline ssize_t NearestNeighbor(const MagickRealType x)
4073 return((ssize_t) (x+0.5));
4074 return((ssize_t) (x-0.5));
4077 MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
4078 const CacheView *image_view,const PixelChannel channel,
4079 const PixelInterpolateMethod method,const double x,const double y,
4080 double *pixel,ExceptionInfo *exception)
4093 register const Quantum
4103 assert(image != (Image *) NULL);
4104 assert(image != (Image *) NULL);
4105 assert(image->signature == MagickSignature);
4106 assert(image_view != (CacheView *) NULL);
4109 traits=GetPixelChannelMapTraits(image,channel);
4110 x_offset=(ssize_t) floor(x);
4111 y_offset=(ssize_t) floor(y);
4112 switch (method == UndefinedInterpolatePixel ? image->interpolate : method)
4114 case AverageInterpolatePixel:
4116 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4118 if (p == (const Quantum *) NULL)
4123 if ((traits & BlendPixelTrait) == 0)
4124 for (i=0; i < 16; i++)
4127 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4130 for (i=0; i < 16; i++)
4132 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4133 GetPixelChannels(image));
4134 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4136 for (i=0; i < 16; i++)
4138 gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]);
4139 *pixel+=gamma*0.0625*pixels[i];
4143 case BicubicInterpolatePixel:
4152 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4154 if (p == (const Quantum *) NULL)
4159 if ((traits & BlendPixelTrait) == 0)
4160 for (i=0; i < 16; i++)
4163 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4166 for (i=0; i < 16; i++)
4168 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4169 GetPixelChannels(image));
4170 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4174 for (i=0; i < 4; i++)
4176 u[0]=(pixels[4*i+3]-pixels[4*i+2])-(pixels[4*i+0]-pixels[4*i+1]);
4177 u[1]=(pixels[4*i+0]-pixels[4*i+1])-u[0];
4178 u[2]=pixels[4*i+2]-pixels[4*i+0];
4180 v[i]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x*
4183 u[0]=(v[3]-v[2])-(v[0]-v[1]);
4184 u[1]=(v[0]-v[1])-u[0];
4187 *pixel=(delta.y*delta.y*delta.y*u[0])+(delta.y*delta.y*u[1])+(delta.y*
4191 case BilinearInterpolatePixel:
4198 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4199 if (p == (const Quantum *) NULL)
4204 if ((traits & BlendPixelTrait) == 0)
4205 for (i=0; i < 4; i++)
4208 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4211 for (i=0; i < 4; i++)
4213 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4214 GetPixelChannels(image));
4215 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4219 epsilon.x=1.0-delta.x;
4220 epsilon.y=1.0-delta.y;
4221 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4222 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4223 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4224 *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
4225 (epsilon.x*pixels[2]+delta.x*pixels[3]));
4228 case FilterInterpolatePixel:
4242 geometry.x=x_offset-1;
4243 geometry.y=y_offset-1;
4244 excerpt_image=ExcerptImage(image,&geometry,exception);
4245 if (excerpt_image == (Image *) NULL)
4250 filter_image=ResizeImage(excerpt_image,1,1,image->filter,exception);
4251 excerpt_image=DestroyImage(excerpt_image);
4252 if (filter_image == (Image *) NULL)
4254 filter_view=AcquireVirtualCacheView(filter_image,exception);
4255 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4256 if (p == (const Quantum *) NULL)
4259 *pixel=(double) GetPixelChannel(image,channel,p);
4260 filter_view=DestroyCacheView(filter_view);
4261 filter_image=DestroyImage(filter_image);
4264 case IntegerInterpolatePixel:
4266 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4267 if (p == (const Quantum *) NULL)
4272 *pixel=(double) GetPixelChannel(image,channel,p);
4275 case NearestNeighborInterpolatePixel:
4277 p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
4278 NearestNeighbor(y),1,1,exception);
4279 if (p == (const Quantum *) NULL)
4284 *pixel=(double) GetPixelChannel(image,channel,p);
4287 case MeshInterpolatePixel:
4293 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4294 if (p == (const Quantum *) NULL)
4299 if ((traits & BlendPixelTrait) == 0)
4300 for (i=0; i < 4; i++)
4303 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4306 for (i=0; i < 4; i++)
4308 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4309 GetPixelChannels(image));
4310 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4314 luminance.x=GetPixelLuminance(image,p)-(double)
4315 GetPixelLuminance(image,p+3*GetPixelChannels(image));
4316 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
4317 GetPixelLuminance(image,p+2*GetPixelChannels(image));
4318 if (fabs(luminance.x) < fabs(luminance.y))
4323 if (delta.x <= delta.y)
4326 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4328 delta.y=1.0-delta.y;
4329 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4330 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4331 *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
4337 Top-right triangle (pixel: 1, diagonal: 0-3).
4339 delta.x=1.0-delta.x;
4340 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4341 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4342 *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
4351 if (delta.x <= (1.0-delta.y))
4354 Top-left triangle (pixel: 0, diagonal: 1-2).
4356 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4357 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4358 *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
4364 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4366 delta.x=1.0-delta.x;
4367 delta.y=1.0-delta.y;
4368 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4369 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4370 *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
4376 case SplineInterpolatePixel:
4389 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4391 if (p == (const Quantum *) NULL)
4396 if ((traits & BlendPixelTrait) == 0)
4397 for (i=0; i < 16; i++)
4400 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4403 for (i=0; i < 16; i++)
4405 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4406 GetPixelChannels(image));
4407 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4412 for (i=(-1); i < 3L; i++)
4414 dy=CubicWeightingFunction((MagickRealType) i-delta.y);
4415 for (j=(-1); j < 3L; j++)
4417 dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
4418 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]);
4419 *pixel+=gamma*dx*dy*pixels[n];
4430 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4434 % I n t e r p o l a t e P i x e l C h a n n e l s %
4438 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4440 % InterpolatePixelChannels() applies a pixel interpolation method between a
4441 % floating point coordinate and the pixels surrounding that coordinate. No
4442 % pixel area resampling, or scaling of the result is performed.
4444 % The format of the InterpolatePixelChannels method is:
4446 % MagickBooleanType InterpolatePixelChannels(const Image *source,
4447 % const CacheView *source_view,const Image *destination,
4448 % const PixelInterpolateMethod method,const double x,const double y,
4449 % Quantum *pixel,ExceptionInfo *exception)
4451 % A description of each parameter follows:
4453 % o source: the source.
4455 % o source_view: the source view.
4457 % o destination: the destination image.
4459 % o method: the pixel color interpolation method.
4461 % o x,y: A double representing the current (x,y) position of the pixel.
4463 % o pixel: return the interpolated pixel here.
4465 % o exception: return any errors or warnings in this structure.
4468 MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
4469 const CacheView *source_view,const Image *destination,
4470 const PixelInterpolateMethod method,const double x,const double y,
4471 Quantum *pixel,ExceptionInfo *exception)
4488 register const Quantum
4498 assert(source != (Image *) NULL);
4499 assert(source != (Image *) NULL);
4500 assert(source->signature == MagickSignature);
4501 assert(source_view != (CacheView *) NULL);
4503 x_offset=(ssize_t) floor(x);
4504 y_offset=(ssize_t) floor(y);
4505 switch (method == UndefinedInterpolatePixel ? source->interpolate : method)
4507 case AverageInterpolatePixel:
4509 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4511 if (p == (const Quantum *) NULL)
4516 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4524 channel=GetPixelChannelMapChannel(source,i);
4525 traits=GetPixelChannelMapTraits(source,channel);
4526 destination_traits=GetPixelChannelMapTraits(destination,channel);
4527 if ((traits == UndefinedPixelTrait) ||
4528 (destination_traits == UndefinedPixelTrait))
4530 for (j=0; j < 16; j++)
4531 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4533 if ((traits & BlendPixelTrait) == 0)
4535 for (j=0; j < 16; j++)
4536 sum+=0.0625*pixels[j];
4537 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4540 for (j=0; j < 16; j++)
4542 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4543 GetPixelChannels(source));
4544 pixels[j]*=alpha[j];
4545 gamma=1.0/(fabs((double) alpha[j]) <= MagickEpsilon ? 1.0 : alpha[j]);
4546 sum+=gamma*0.0625*pixels[j];
4548 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4552 case BicubicInterpolatePixel:
4561 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4563 if (p == (const Quantum *) NULL)
4568 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4573 channel=GetPixelChannelMapChannel(source,i);
4574 traits=GetPixelChannelMapTraits(source,channel);
4575 destination_traits=GetPixelChannelMapTraits(destination,channel);
4576 if ((traits == UndefinedPixelTrait) ||
4577 (destination_traits == UndefinedPixelTrait))
4579 if ((traits & BlendPixelTrait) == 0)
4580 for (j=0; j < 16; j++)
4583 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4586 for (j=0; j < 16; j++)
4588 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4589 GetPixelChannels(source));
4590 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4594 for (j=0; j < 4; j++)
4596 u[0]=(pixels[4*j+3]-pixels[4*j+2])-(pixels[4*j+0]-pixels[4*j+1]);
4597 u[1]=(pixels[4*j+0]-pixels[4*j+1])-u[0];
4598 u[2]=pixels[4*j+2]-pixels[4*j+0];
4600 v[j]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x*
4603 u[0]=(v[3]-v[2])-(v[0]-v[1]);
4604 u[1]=(v[0]-v[1])-u[0];
4607 SetPixelChannel(destination,channel,ClampToQuantum((delta.y*delta.y*
4608 delta.y*u[0])+(delta.y*delta.y*u[1])+(delta.y*u[2])+u[3]),pixel);
4612 case BilinearInterpolatePixel:
4615 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4616 if (p == (const Quantum *) NULL)
4621 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4627 channel=GetPixelChannelMapChannel(source,i);
4628 traits=GetPixelChannelMapTraits(source,channel);
4629 destination_traits=GetPixelChannelMapTraits(destination,channel);
4630 if ((traits == UndefinedPixelTrait) ||
4631 (destination_traits == UndefinedPixelTrait))
4635 epsilon.x=1.0-delta.x;
4636 epsilon.y=1.0-delta.y;
4637 pixels[0]=(MagickRealType) p[i];
4638 pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i];
4639 pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i];
4640 pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i];
4641 if ((traits & BlendPixelTrait) == 0)
4643 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
4644 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4645 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4646 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*
4647 pixels[2]+delta.x*pixels[3]))),pixel);
4650 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4651 alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source));
4652 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4653 GetPixelChannels(source));
4654 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4655 GetPixelChannels(source));
4656 pixels[0]*=alpha[0];
4657 pixels[1]*=alpha[1];
4658 pixels[2]*=alpha[2];
4659 pixels[3]*=alpha[3];
4660 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4661 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4662 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4663 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4664 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+
4665 delta.x*pixels[3]))),pixel);
4669 case FilterInterpolatePixel:
4671 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4683 channel=GetPixelChannelMapChannel(source,i);
4684 traits=GetPixelChannelMapTraits(source,channel);
4685 destination_traits=GetPixelChannelMapTraits(destination,channel);
4686 if ((traits == UndefinedPixelTrait) ||
4687 (destination_traits == UndefinedPixelTrait))
4691 geometry.x=x_offset-1;
4692 geometry.y=y_offset-1;
4693 excerpt_source=ExcerptImage(source,&geometry,exception);
4694 if (excerpt_source == (Image *) NULL)
4699 filter_source=ResizeImage(excerpt_source,1,1,source->filter,exception);
4700 excerpt_source=DestroyImage(excerpt_source);
4701 if (filter_source == (Image *) NULL)
4703 filter_view=AcquireVirtualCacheView(filter_source,exception);
4704 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4705 if (p == (const Quantum *) NULL)
4709 SetPixelChannel(destination,channel,p[i],pixel);
4711 filter_view=DestroyCacheView(filter_view);
4712 filter_source=DestroyImage(filter_source);
4716 case IntegerInterpolatePixel:
4718 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
4719 if (p == (const Quantum *) NULL)
4724 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4726 channel=GetPixelChannelMapChannel(source,i);
4727 traits=GetPixelChannelMapTraits(source,channel);
4728 destination_traits=GetPixelChannelMapTraits(destination,channel);
4729 if ((traits == UndefinedPixelTrait) ||
4730 (destination_traits == UndefinedPixelTrait))
4732 SetPixelChannel(destination,channel,p[i],pixel);
4736 case NearestNeighborInterpolatePixel:
4738 p=GetCacheViewVirtualPixels(source_view,NearestNeighbor(x),
4739 NearestNeighbor(y),1,1,exception);
4740 if (p == (const Quantum *) NULL)
4745 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4747 channel=GetPixelChannelMapChannel(source,i);
4748 traits=GetPixelChannelMapTraits(source,channel);
4749 destination_traits=GetPixelChannelMapTraits(destination,channel);
4750 if ((traits == UndefinedPixelTrait) ||
4751 (destination_traits == UndefinedPixelTrait))
4753 SetPixelChannel(destination,channel,p[i],pixel);
4757 case MeshInterpolatePixel:
4759 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4760 if (p == (const Quantum *) NULL)
4765 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4771 channel=GetPixelChannelMapChannel(source,i);
4772 traits=GetPixelChannelMapTraits(source,channel);
4773 destination_traits=GetPixelChannelMapTraits(destination,channel);
4774 if ((traits == UndefinedPixelTrait) ||
4775 (destination_traits == UndefinedPixelTrait))
4777 pixels[0]=(MagickRealType) p[i];
4778 pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i];
4779 pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i];
4780 pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i];
4781 if ((traits & BlendPixelTrait) == 0)
4790 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4791 alpha[1]=QuantumScale*GetPixelAlpha(source,p+
4792 GetPixelChannels(source));
4793 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4794 GetPixelChannels(source));
4795 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4796 GetPixelChannels(source));
4800 luminance.x=GetPixelLuminance(source,p)-(double)
4801 GetPixelLuminance(source,p+3*GetPixelChannels(source));
4802 luminance.y=GetPixelLuminance(source,p+GetPixelChannels(source))-
4803 (double) GetPixelLuminance(source,p+2*GetPixelChannels(source));
4804 if (fabs(luminance.x) < fabs(luminance.y))
4809 if (delta.x <= delta.y)
4812 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4814 delta.y=1.0-delta.y;
4815 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4816 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4817 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4818 MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel);
4823 Top-right triangle (pixel: 1, diagonal: 0-3).
4825 delta.x=1.0-delta.x;
4826 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4827 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4828 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4829 MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel);
4837 if (delta.x <= (1.0-delta.y))
4840 Top-left triangle (pixel: 0, diagonal: 1-2).
4842 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4843 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4844 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4845 MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel);
4850 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4852 delta.x=1.0-delta.x;
4853 delta.y=1.0-delta.y;
4854 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4855 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4856 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4857 MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel);
4863 case SplineInterpolatePixel:
4865 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4867 if (p == (const Quantum *) NULL)
4872 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4891 channel=GetPixelChannelMapChannel(source,i);
4892 traits=GetPixelChannelMapTraits(source,channel);
4893 destination_traits=GetPixelChannelMapTraits(destination,channel);
4894 if ((traits == UndefinedPixelTrait) ||
4895 (destination_traits == UndefinedPixelTrait))
4897 if ((traits & BlendPixelTrait) == 0)
4898 for (j=0; j < 16; j++)
4901 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4904 for (j=0; j < 16; j++)
4906 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4907 GetPixelChannels(source));
4908 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4914 for (j=(-1); j < 3L; j++)
4916 dy=CubicWeightingFunction((MagickRealType) j-delta.y);
4917 for (k=(-1); k < 3L; k++)
4919 dx=CubicWeightingFunction(delta.x-(MagickRealType) k);
4920 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 :
4922 sum+=gamma*dx*dy*pixels[n];
4926 SetPixelChannel(destination,channel,p[i],pixel);
4935 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4939 % I n t e r p o l a t e P i x e l I n f o %
4943 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4945 % InterpolatePixelInfo() applies a pixel interpolation method between a
4946 % floating point coordinate and the pixels surrounding that coordinate. No
4947 % pixel area resampling, or scaling of the result is performed.
4949 % The format of the InterpolatePixelInfo method is:
4951 % MagickBooleanType InterpolatePixelInfo(const Image *image,
4952 % const CacheView *image_view,const PixelInterpolateMethod method,
4953 % const double x,const double y,PixelInfo *pixel,
4954 % ExceptionInfo *exception)
4956 % A description of each parameter follows:
4958 % o image: the image.
4960 % o image_view: the image view.
4962 % o method: the pixel color interpolation method.
4964 % o x,y: A double representing the current (x,y) position of the pixel.
4966 % o pixel: return the interpolated pixel here.
4968 % o exception: return any errors or warnings in this structure.
4972 static inline void AlphaBlendPixelInfo(const Image *image,
4973 const Quantum *pixel,PixelInfo *pixel_info,MagickRealType *alpha)
4975 if (image->matte == MagickFalse)
4978 pixel_info->red=(MagickRealType) GetPixelRed(image,pixel);
4979 pixel_info->green=(MagickRealType) GetPixelGreen(image,pixel);
4980 pixel_info->blue=(MagickRealType) GetPixelBlue(image,pixel);
4981 pixel_info->black=0.0;
4982 if (image->colorspace == CMYKColorspace)
4983 pixel_info->black=(MagickRealType) GetPixelBlack(image,pixel);
4984 pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
4987 *alpha=QuantumScale*GetPixelAlpha(image,pixel);
4988 pixel_info->red=(*alpha*GetPixelRed(image,pixel));
4989 pixel_info->green=(*alpha*GetPixelGreen(image,pixel));
4990 pixel_info->blue=(*alpha*GetPixelBlue(image,pixel));
4991 pixel_info->black=0.0;
4992 if (image->colorspace == CMYKColorspace)
4993 pixel_info->black=(*alpha*GetPixelBlack(image,pixel));
4994 pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
4997 static void BicubicInterpolate(const PixelInfo *pixels,const double dx,
5008 p=(pixels[3].red-pixels[2].red)-(pixels[0].red-pixels[1].red);
5009 q=(pixels[0].red-pixels[1].red)-p;
5010 r=pixels[2].red-pixels[0].red;
5012 pixel->red=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
5013 p=(pixels[3].green-pixels[2].green)-(pixels[0].green-pixels[1].green);
5014 q=(pixels[0].green-pixels[1].green)-p;
5015 r=pixels[2].green-pixels[0].green;
5017 pixel->green=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
5018 p=(pixels[3].blue-pixels[2].blue)-(pixels[0].blue-pixels[1].blue);
5019 q=(pixels[0].blue-pixels[1].blue)-p;
5020 r=pixels[2].blue-pixels[0].blue;
5022 pixel->blue=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
5023 p=(pixels[3].alpha-pixels[2].alpha)-(pixels[0].alpha-pixels[1].alpha);
5024 q=(pixels[0].alpha-pixels[1].alpha)-p;
5025 r=pixels[2].alpha-pixels[0].alpha;
5027 pixel->alpha=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
5028 if (pixel->colorspace == CMYKColorspace)
5030 p=(pixels[3].black-pixels[2].black)-(pixels[0].black-pixels[1].black);
5031 q=(pixels[0].black-pixels[1].black)-p;
5032 r=pixels[2].black-pixels[0].black;
5034 pixel->black=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
5038 MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
5039 const CacheView *image_view,const PixelInterpolateMethod method,
5040 const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception)
5052 register const Quantum
5062 assert(image != (Image *) NULL);
5063 assert(image->signature == MagickSignature);
5064 assert(image_view != (CacheView *) NULL);
5066 x_offset=(ssize_t) floor(x);
5067 y_offset=(ssize_t) floor(y);
5068 switch (method == UndefinedInterpolatePixel ? image->interpolate : method)
5070 case AverageInterpolatePixel:
5072 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5074 if (p == (const Quantum *) NULL)
5079 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5080 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5081 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5082 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5083 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
5084 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
5085 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
5086 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
5087 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
5088 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
5089 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
5091 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
5093 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
5095 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
5097 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
5099 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
5106 for (i=0; i < 16L; i++)
5108 gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]);
5109 pixel->red+=gamma*0.0625*pixels[i].red;
5110 pixel->green+=gamma*0.0625*pixels[i].green;
5111 pixel->blue+=gamma*0.0625*pixels[i].blue;
5112 if (image->colorspace == CMYKColorspace)
5113 pixel->black+=gamma*0.0625*pixels[i].black;
5114 pixel->alpha+=0.0625*pixels[i].alpha;
5118 case BicubicInterpolatePixel:
5126 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5128 if (p == (const Quantum *) NULL)
5133 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5134 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5135 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5136 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5137 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
5138 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
5139 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
5140 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
5141 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
5142 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
5143 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
5145 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
5147 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
5149 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
5151 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
5153 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
5157 for (i=0; i < 4L; i++)
5158 BicubicInterpolate(pixels+4*i,delta.x,u+i);
5159 BicubicInterpolate(u,delta.y,pixel);
5162 case BilinearInterpolatePixel:
5169 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5170 if (p == (const Quantum *) NULL)
5175 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5176 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5177 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5178 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5181 epsilon.x=1.0-delta.x;
5182 epsilon.y=1.0-delta.y;
5183 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5184 (epsilon.x*alpha[2]+delta.x*alpha[3])));
5185 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5186 pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
5187 pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red));
5188 pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x*
5189 pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x*
5191 pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x*
5192 pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x*
5194 if (image->colorspace == CMYKColorspace)
5195 pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x*
5196 pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x*
5198 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5199 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5200 pixel->alpha=(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x*
5201 pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x*
5205 case FilterInterpolatePixel:
5219 geometry.x=x_offset-1;
5220 geometry.y=y_offset-1;
5221 excerpt_image=ExcerptImage(image,&geometry,exception);
5222 if (excerpt_image == (Image *) NULL)
5227 filter_image=ResizeImage(excerpt_image,1,1,image->filter,exception);
5228 excerpt_image=DestroyImage(excerpt_image);
5229 if (filter_image == (Image *) NULL)
5231 filter_view=AcquireVirtualCacheView(filter_image,exception);
5232 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
5233 if (p != (const Quantum *) NULL)
5234 GetPixelInfoPixel(image,p,pixel);
5235 filter_view=DestroyCacheView(filter_view);
5236 filter_image=DestroyImage(filter_image);
5239 case IntegerInterpolatePixel:
5241 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5242 if (p == (const Quantum *) NULL)
5247 GetPixelInfoPixel(image,p,pixel);
5250 case MeshInterpolatePixel:
5256 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5257 if (p == (const Quantum *) NULL)
5264 luminance.x=GetPixelLuminance(image,p)-(double)
5265 GetPixelLuminance(image,p+3*GetPixelChannels(image));
5266 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
5267 GetPixelLuminance(image,p+2*GetPixelChannels(image));
5268 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5269 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5270 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5271 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5272 if (fabs(luminance.x) < fabs(luminance.y))
5277 if (delta.x <= delta.y)
5280 Bottom-left triangle (pixel: 2, diagonal: 0-3).
5282 delta.y=1.0-delta.y;
5283 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5284 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5285 pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red,
5286 pixels[3].red,pixels[0].red);
5287 pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green,
5288 pixels[3].green,pixels[0].green);
5289 pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
5290 pixels[3].blue,pixels[0].blue);
5291 if (image->colorspace == CMYKColorspace)
5292 pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black,
5293 pixels[3].black,pixels[0].black);
5294 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5295 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha,
5296 pixels[3].alpha,pixels[0].alpha);
5301 Top-right triangle (pixel:1 , diagonal: 0-3).
5303 delta.x=1.0-delta.x;
5304 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5305 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5306 pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red,
5307 pixels[0].red,pixels[3].red);
5308 pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green,
5309 pixels[0].green,pixels[3].green);
5310 pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
5311 pixels[0].blue,pixels[3].blue);
5312 if (image->colorspace == CMYKColorspace)
5313 pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black,
5314 pixels[0].black,pixels[3].black);
5315 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5316 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha,
5317 pixels[0].alpha,pixels[3].alpha);
5325 if (delta.x <= (1.0-delta.y))
5328 Top-left triangle (pixel: 0, diagonal: 1-2).
5330 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5331 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5332 pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red,
5333 pixels[1].red,pixels[2].red);
5334 pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green,
5335 pixels[1].green,pixels[2].green);
5336 pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
5337 pixels[1].blue,pixels[2].blue);
5338 if (image->colorspace == CMYKColorspace)
5339 pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black,
5340 pixels[1].black,pixels[2].black);
5341 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5342 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha,
5343 pixels[1].alpha,pixels[2].alpha);
5348 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5350 delta.x=1.0-delta.x;
5351 delta.y=1.0-delta.y;
5352 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5353 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5354 pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red,
5355 pixels[2].red,pixels[1].red);
5356 pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green,
5357 pixels[2].green,pixels[1].green);
5358 pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
5359 pixels[2].blue,pixels[1].blue);
5360 if (image->colorspace == CMYKColorspace)
5361 pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black,
5362 pixels[2].black,pixels[1].black);
5363 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5364 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha,
5365 pixels[2].alpha,pixels[1].alpha);
5370 case NearestNeighborInterpolatePixel:
5372 p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
5373 NearestNeighbor(y),1,1,exception);
5374 if (p == (const Quantum *) NULL)
5379 GetPixelInfoPixel(image,p,pixel);
5382 case SplineInterpolatePixel:
5395 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5397 if (p == (const Quantum *) NULL)
5402 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5403 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5404 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5405 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5406 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
5407 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
5408 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
5409 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
5410 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
5411 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
5412 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
5414 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
5416 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
5418 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
5420 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
5422 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
5432 for (i=(-1); i < 3L; i++)
5434 dy=CubicWeightingFunction((MagickRealType) i-delta.y);
5435 for (j=(-1); j < 3L; j++)
5437 dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
5438 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]);
5439 pixel->red+=gamma*dx*dy*pixels[n].red;
5440 pixel->green+=gamma*dx*dy*pixels[n].green;
5441 pixel->blue+=gamma*dx*dy*pixels[n].blue;
5442 if (image->colorspace == CMYKColorspace)
5443 pixel->black+=gamma*dx*dy*pixels[n].black;
5444 pixel->alpha+=dx*dy*pixels[n].alpha;
5455 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5459 + I s F u z z y E q u i v a l e n c e P i x e l %
5463 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5465 % IsFuzzyEquivalencePixel() returns MagickTrue if the distance between two
5466 % pixels is less than the specified distance in a linear three (or four)u
5467 % dimensional color space.
5469 % The format of the IsFuzzyEquivalencePixel method is:
5471 % void IsFuzzyEquivalencePixel(const Image *source,const Quantum *p,
5472 % const Image *destination,const Quantum *q)
5474 % A description of each parameter follows:
5476 % o source: the source image.
5480 % o destination: the destination image.
5485 MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *source,
5486 const Quantum *p,const Image *destination,const Quantum *q)
5492 register MagickRealType
5496 fuzz=MagickMax(source->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(
5497 destination->fuzz,(MagickRealType) MagickSQ1_2);
5500 if (source->matte != MagickFalse)
5503 Transparencies are involved - set alpha distance
5505 pixel=GetPixelAlpha(source,p)-(MagickRealType)
5506 GetPixelAlpha(destination,q);
5507 distance=pixel*pixel;
5508 if (distance > fuzz)
5509 return(MagickFalse);
5511 Generate a alpha scaling factor to generate a 4D cone on colorspace
5512 Note that if one color is transparent, distance has no color component.
5514 scale=QuantumScale*GetPixelAlpha(source,p);
5515 scale*=QuantumScale*GetPixelAlpha(destination,q);
5516 if (scale <= MagickEpsilon)
5520 RGB or CMY color cube
5522 distance*=3.0; /* rescale appropriately */
5524 pixel=GetPixelRed(source,p)-(MagickRealType) GetPixelRed(destination,q);
5525 if ((source->colorspace == HSLColorspace) ||
5526 (source->colorspace == HSBColorspace) ||
5527 (source->colorspace == HWBColorspace))
5530 Compute an arc distance for hue. It should be a vector angle of
5531 'S'/'W' length with 'L'/'B' forming appropriate cones.
5533 if (fabs((double) pixel) > (QuantumRange/2))
5534 pixel-=QuantumRange;
5537 distance+=scale*pixel*pixel;
5538 if (distance > fuzz)
5539 return(MagickFalse);
5540 pixel=GetPixelGreen(source,p)-(MagickRealType) GetPixelGreen(destination,q);
5541 distance+=scale*pixel*pixel;
5542 if (distance > fuzz)
5543 return(MagickFalse);
5544 pixel=GetPixelBlue(source,p)-(MagickRealType) GetPixelBlue(destination,q);
5545 distance+=scale*pixel*pixel;
5546 if (distance > fuzz)
5547 return(MagickFalse);
5552 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5556 + 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 %
5560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5562 % IsFuzzyEquivalencePixelInfo() returns true if the distance between two
5563 % colors is less than the specified distance in a linear three (or four)
5564 % dimensional color space.
5566 % This implements the equivalent of:
5567 % fuzz < sqrt(color_distance^2 * u.a*v.a + alpha_distance^2)
5569 % Which produces a multi-dimensional cone for that colorspace along the
5570 % transparency vector.
5572 % For example for an RGB:
5573 % color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3
5575 % See http://www.imagemagick.org/Usage/bugs/fuzz_distance/
5577 % Hue colorspace distances need more work. Hue is not a distance, it is an
5580 % A check that q is in the same color space as p should be made and the
5581 % appropriate mapping made. -- Anthony Thyssen 8 December 2010
5583 % The format of the IsFuzzyEquivalencePixelInfo method is:
5585 % MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5586 % const PixelInfo *q)
5588 % A description of each parameter follows:
5595 MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5602 register MagickRealType
5606 if ((p->fuzz == 0.0) && (q->fuzz == 0.0))
5607 return(IsPixelInfoEquivalent(p,q));
5609 fuzz=MagickMax(q->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz,
5610 (MagickRealType) MagickSQ1_2);
5611 else if (q->fuzz == 0.0)
5612 fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(p->fuzz,
5613 (MagickRealType) MagickSQ1_2);
5615 fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz,
5616 (MagickRealType) MagickSQ1_2);
5619 if ((p->matte != MagickFalse) || (q->matte != MagickFalse))
5622 Transparencies are involved - set alpha distance.
5624 pixel=(p->matte != MagickFalse ? p->alpha : OpaqueAlpha)-
5625 (q->matte != MagickFalse ? q->alpha : OpaqueAlpha);
5626 distance=pixel*pixel;
5627 if (distance > fuzz)
5628 return(MagickFalse);
5630 Generate a alpha scaling factor to generate a 4D cone on colorspace.
5631 If one color is transparent, distance has no color component.
5633 if (p->matte != MagickFalse)
5634 scale=(QuantumScale*p->alpha);
5635 if (q->matte != MagickFalse)
5636 scale*=(QuantumScale*q->alpha);
5637 if (scale <= MagickEpsilon )
5641 CMYK create a CMY cube with a multi-dimensional cone toward black.
5643 if (p->colorspace == CMYKColorspace)
5645 pixel=p->black-q->black;
5646 distance+=pixel*pixel*scale;
5647 if (distance > fuzz)
5648 return(MagickFalse);
5649 scale*=(MagickRealType) (QuantumScale*(QuantumRange-p->black));
5650 scale*=(MagickRealType) (QuantumScale*(QuantumRange-q->black));
5653 RGB or CMY color cube.
5655 distance*=3.0; /* rescale appropriately */
5657 pixel=p->red-q->red;
5658 if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) ||
5659 (p->colorspace == HWBColorspace))
5662 This calculates a arc distance for hue-- it should be a vector angle
5663 of 'S'/'W' length with 'L'/'B' forming appropriate cones. In other
5664 words this is a hack - Anthony.
5666 if (fabs((double) pixel) > (QuantumRange/2))
5667 pixel-=QuantumRange;
5670 distance+=pixel*pixel*scale;
5671 if (distance > fuzz)
5672 return(MagickFalse);
5673 pixel=p->green-q->green;
5674 distance+=pixel*pixel*scale;
5675 if (distance > fuzz)
5676 return(MagickFalse);
5677 pixel=p->blue-q->blue;
5678 distance+=pixel*pixel*scale;
5679 if (distance > fuzz)
5680 return(MagickFalse);
5685 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5689 % S e t P i x e l C h a n n e l M a p M a s k %
5693 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5695 % SetPixelChannelMapMask() sets the pixel channel map from the specified
5698 % The format of the SetPixelChannelMapMask method is:
5700 % void SetPixelChannelMapMask(Image *image,const ChannelType channel_mask)
5702 % A description of each parameter follows:
5704 % o image: the image.
5706 % o channel_mask: the channel mask.
5709 MagickExport void SetPixelChannelMapMask(Image *image,
5710 const ChannelType channel_mask)
5712 #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
5717 if (image->debug != MagickFalse)
5718 (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%08x]", \
5719 image->filename,channel_mask); \
5720 image->channel_mask=channel_mask;
5721 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5726 channel=GetPixelChannelMapChannel(image,i);
5727 SetPixelChannelMapTraits(image,channel,
5728 GetChannelBit(channel_mask,channel) == 0 ? CopyPixelTrait :
5729 image->matte == MagickFalse || (channel == AlphaPixelChannel) ?
5730 UpdatePixelTrait : (PixelTrait) (UpdatePixelTrait | BlendPixelTrait));
5732 if (image->storage_class == PseudoClass)
5733 SetPixelChannelMapTraits(image,IndexPixelChannel,CopyPixelTrait);
5734 if (image->mask != MagickFalse)
5735 SetPixelChannelMapTraits(image,MaskPixelChannel,CopyPixelTrait);
5736 if (image->debug != MagickFalse)
5737 LogPixelChannels(image);
5741 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5745 % S e t P i x e l C h a n n e l M a s k %
5749 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5751 % SetPixelChannelMask() sets the pixel channel mask from the specified channel
5754 % The format of the SetPixelChannelMask method is:
5756 % ChannelType SetPixelChannelMask(Image *image,
5757 % const ChannelType channel_mask)
5759 % A description of each parameter follows:
5761 % o image: the image.
5763 % o channel_mask: the channel mask.
5766 MagickExport ChannelType SetPixelChannelMask(Image *image,
5767 const ChannelType channel_mask)
5772 mask=image->channel_mask;
5773 image->channel_mask=channel_mask;
5774 SetPixelChannelMapMask(image,channel_mask);
5779 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5783 % S e t P i x e l M e t a C h a n n e l s %
5787 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5789 % SetPixelMetaChannels() sets the image meta channels.
5791 % The format of the SetPixelMetaChannels method is:
5793 % MagickBooleanType SetPixelMetaChannels(Image *image,
5794 % const size_t number_meta_channels,ExceptionInfo *exception)
5796 % A description of each parameter follows:
5798 % o image: the image.
5800 % o number_meta_channels: the number of meta channels.
5802 % o exception: return any errors or warnings in this structure.
5805 MagickExport MagickBooleanType SetPixelMetaChannels(Image *image,
5806 const size_t number_meta_channels,ExceptionInfo *exception)
5808 image->number_meta_channels=number_meta_channels;
5809 return(SyncImagePixelCache(image,exception));