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
370 q=(unsigned char *) pixels;
371 if (LocaleCompare(map,"BGR") == 0)
373 for (y=0; y < (ssize_t) roi->height; y++)
375 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
376 if (p == (const Quantum *) NULL)
378 for (x=0; x < (ssize_t) roi->width; x++)
380 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
381 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
382 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
383 p+=GetPixelChannels(image);
388 if (LocaleCompare(map,"BGRA") == 0)
390 for (y=0; y < (ssize_t) roi->height; y++)
392 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
393 if (p == (const Quantum *) NULL)
395 for (x=0; x < (ssize_t) roi->width; x++)
397 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
398 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
399 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
400 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
401 p+=GetPixelChannels(image);
406 if (LocaleCompare(map,"BGRP") == 0)
408 for (y=0; y < (ssize_t) roi->height; y++)
410 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
411 if (p == (const Quantum *) NULL)
413 for (x=0; x < (ssize_t) roi->width; x++)
415 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
416 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
417 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
418 *q++=ScaleQuantumToChar((Quantum) 0);
419 p+=GetPixelChannels(image);
424 if (LocaleCompare(map,"I") == 0)
426 for (y=0; y < (ssize_t) roi->height; y++)
428 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
429 if (p == (const Quantum *) NULL)
431 for (x=0; x < (ssize_t) roi->width; x++)
433 *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
434 p+=GetPixelChannels(image);
439 if (LocaleCompare(map,"RGB") == 0)
441 for (y=0; y < (ssize_t) roi->height; y++)
443 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
444 if (p == (const Quantum *) NULL)
446 for (x=0; x < (ssize_t) roi->width; x++)
448 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
449 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
450 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
451 p+=GetPixelChannels(image);
456 if (LocaleCompare(map,"RGBA") == 0)
458 for (y=0; y < (ssize_t) roi->height; y++)
460 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
461 if (p == (const Quantum *) NULL)
463 for (x=0; x < (ssize_t) roi->width; x++)
465 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
466 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
467 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
468 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
469 p+=GetPixelChannels(image);
474 if (LocaleCompare(map,"RGBP") == 0)
476 for (y=0; y < (ssize_t) roi->height; y++)
478 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
479 if (p == (const Quantum *) NULL)
481 for (x=0; x < (ssize_t) roi->width; x++)
483 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
484 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
485 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
486 *q++=ScaleQuantumToChar((Quantum) 0);
487 p+=GetPixelChannels(image);
492 for (y=0; y < (ssize_t) roi->height; y++)
494 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
495 if (p == (const Quantum *) NULL)
497 for (x=0; x < (ssize_t) roi->width; x++)
502 for (i=0; i < (ssize_t) strlen(map); i++)
505 switch (quantum_map[i])
510 *q=ScaleQuantumToChar(GetPixelRed(image,p));
516 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
522 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
527 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
532 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
537 if (image->colorspace == CMYKColorspace)
538 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
543 *q=ScaleQuantumToChar(GetPixelIntensity(image,p));
551 p+=GetPixelChannels(image);
556 static void ExportDoublePixel(const Image *image,const RectangleInfo *roi,
557 const char *restrict map,const QuantumType *quantum_map,void *pixels,
558 ExceptionInfo *exception)
560 register const Quantum
573 if (LocaleCompare(map,"BGR") == 0)
575 for (y=0; y < (ssize_t) roi->height; y++)
577 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
578 if (p == (const Quantum *) NULL)
580 for (x=0; x < (ssize_t) roi->width; x++)
582 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
583 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
584 *q++=(double) (QuantumScale*GetPixelRed(image,p));
585 p+=GetPixelChannels(image);
590 if (LocaleCompare(map,"BGRA") == 0)
592 for (y=0; y < (ssize_t) roi->height; y++)
594 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
595 if (p == (const Quantum *) NULL)
597 for (x=0; x < (ssize_t) roi->width; x++)
599 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
600 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
601 *q++=(double) (QuantumScale*GetPixelRed(image,p));
602 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
603 p+=GetPixelChannels(image);
608 if (LocaleCompare(map,"BGRP") == 0)
610 for (y=0; y < (ssize_t) roi->height; y++)
612 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
613 if (p == (const Quantum *) NULL)
615 for (x=0; x < (ssize_t) roi->width; x++)
617 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
618 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
619 *q++=(double) (QuantumScale*GetPixelRed(image,p));
621 p+=GetPixelChannels(image);
626 if (LocaleCompare(map,"I") == 0)
628 for (y=0; y < (ssize_t) roi->height; y++)
630 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
631 if (p == (const Quantum *) NULL)
633 for (x=0; x < (ssize_t) roi->width; x++)
635 *q++=(double) (QuantumScale*GetPixelIntensity(image,p));
636 p+=GetPixelChannels(image);
641 if (LocaleCompare(map,"RGB") == 0)
643 for (y=0; y < (ssize_t) roi->height; y++)
645 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
646 if (p == (const Quantum *) NULL)
648 for (x=0; x < (ssize_t) roi->width; x++)
650 *q++=(double) (QuantumScale*GetPixelRed(image,p));
651 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
652 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
653 p+=GetPixelChannels(image);
658 if (LocaleCompare(map,"RGBA") == 0)
660 for (y=0; y < (ssize_t) roi->height; y++)
662 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
663 if (p == (const Quantum *) NULL)
665 for (x=0; x < (ssize_t) roi->width; x++)
667 *q++=(double) (QuantumScale*GetPixelRed(image,p));
668 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
669 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
670 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
671 p+=GetPixelChannels(image);
676 if (LocaleCompare(map,"RGBP") == 0)
678 for (y=0; y < (ssize_t) roi->height; y++)
680 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
681 if (p == (const Quantum *) NULL)
683 for (x=0; x < (ssize_t) roi->width; x++)
685 *q++=(double) (QuantumScale*GetPixelRed(image,p));
686 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
687 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
689 p+=GetPixelChannels(image);
694 for (y=0; y < (ssize_t) roi->height; y++)
696 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
697 if (p == (const Quantum *) NULL)
699 for (x=0; x < (ssize_t) roi->width; x++)
704 for (i=0; i < (ssize_t) strlen(map); i++)
707 switch (quantum_map[i])
712 *q=(double) (QuantumScale*GetPixelRed(image,p));
718 *q=(double) (QuantumScale*GetPixelGreen(image,p));
724 *q=(double) (QuantumScale*GetPixelBlue(image,p));
729 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
734 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
739 if (image->colorspace == CMYKColorspace)
740 *q=(double) (QuantumScale*
741 GetPixelBlack(image,p));
746 *q=(double) (QuantumScale*GetPixelIntensity(image,p));
754 p+=GetPixelChannels(image);
759 static void ExportFloatPixel(const Image *image,const RectangleInfo *roi,
760 const char *restrict map,const QuantumType *quantum_map,void *pixels,
761 ExceptionInfo *exception)
763 register const Quantum
776 if (LocaleCompare(map,"BGR") == 0)
778 for (y=0; y < (ssize_t) roi->height; y++)
780 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
781 if (p == (const Quantum *) NULL)
783 for (x=0; x < (ssize_t) roi->width; x++)
785 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
786 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
787 *q++=(float) (QuantumScale*GetPixelRed(image,p));
788 p+=GetPixelChannels(image);
793 if (LocaleCompare(map,"BGRA") == 0)
795 for (y=0; y < (ssize_t) roi->height; y++)
797 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
798 if (p == (const Quantum *) NULL)
800 for (x=0; x < (ssize_t) roi->width; x++)
802 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
803 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
804 *q++=(float) (QuantumScale*GetPixelRed(image,p));
805 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
806 p+=GetPixelChannels(image);
811 if (LocaleCompare(map,"BGRP") == 0)
813 for (y=0; y < (ssize_t) roi->height; y++)
815 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
816 if (p == (const Quantum *) NULL)
818 for (x=0; x < (ssize_t) roi->width; x++)
820 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
821 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
822 *q++=(float) (QuantumScale*GetPixelRed(image,p));
824 p+=GetPixelChannels(image);
829 if (LocaleCompare(map,"I") == 0)
831 for (y=0; y < (ssize_t) roi->height; y++)
833 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
834 if (p == (const Quantum *) NULL)
836 for (x=0; x < (ssize_t) roi->width; x++)
838 *q++=(float) (QuantumScale*GetPixelIntensity(image,p));
839 p+=GetPixelChannels(image);
844 if (LocaleCompare(map,"RGB") == 0)
846 for (y=0; y < (ssize_t) roi->height; y++)
848 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
849 if (p == (const Quantum *) NULL)
851 for (x=0; x < (ssize_t) roi->width; x++)
853 *q++=(float) (QuantumScale*GetPixelRed(image,p));
854 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
855 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
856 p+=GetPixelChannels(image);
861 if (LocaleCompare(map,"RGBA") == 0)
863 for (y=0; y < (ssize_t) roi->height; y++)
865 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
866 if (p == (const Quantum *) NULL)
868 for (x=0; x < (ssize_t) roi->width; x++)
870 *q++=(float) (QuantumScale*GetPixelRed(image,p));
871 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
872 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
873 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
874 p+=GetPixelChannels(image);
879 if (LocaleCompare(map,"RGBP") == 0)
881 for (y=0; y < (ssize_t) roi->height; y++)
883 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
884 if (p == (const Quantum *) NULL)
886 for (x=0; x < (ssize_t) roi->width; x++)
888 *q++=(float) (QuantumScale*GetPixelRed(image,p));
889 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
890 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
892 p+=GetPixelChannels(image);
897 for (y=0; y < (ssize_t) roi->height; y++)
899 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
900 if (p == (const Quantum *) NULL)
902 for (x=0; x < (ssize_t) roi->width; x++)
907 for (i=0; i < (ssize_t) strlen(map); i++)
910 switch (quantum_map[i])
915 *q=(float) (QuantumScale*GetPixelRed(image,p));
921 *q=(float) (QuantumScale*GetPixelGreen(image,p));
927 *q=(float) (QuantumScale*GetPixelBlue(image,p));
932 *q=(float) (QuantumScale*((Quantum) (GetPixelAlpha(image,p))));
937 *q=(float) (QuantumScale*GetPixelAlpha(image,p));
942 if (image->colorspace == CMYKColorspace)
943 *q=(float) (QuantumScale* GetPixelBlack(image,p));
948 *q=(float) (QuantumScale*GetPixelIntensity(image,p));
956 p+=GetPixelChannels(image);
961 static void ExportLongPixel(const Image *image,const RectangleInfo *roi,
962 const char *restrict map,const QuantumType *quantum_map,void *pixels,
963 ExceptionInfo *exception)
965 register const Quantum
971 register unsigned int
977 q=(unsigned int *) pixels;
978 if (LocaleCompare(map,"BGR") == 0)
980 for (y=0; y < (ssize_t) roi->height; y++)
982 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
983 if (p == (const Quantum *) NULL)
985 for (x=0; x < (ssize_t) roi->width; x++)
987 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
988 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
989 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
990 p+=GetPixelChannels(image);
995 if (LocaleCompare(map,"BGRA") == 0)
997 for (y=0; y < (ssize_t) roi->height; y++)
999 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1000 if (p == (const Quantum *) NULL)
1002 for (x=0; x < (ssize_t) roi->width; x++)
1004 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1005 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1006 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1007 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1008 p+=GetPixelChannels(image);
1013 if (LocaleCompare(map,"BGRP") == 0)
1015 for (y=0; y < (ssize_t) roi->height; y++)
1017 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1018 if (p == (const Quantum *) NULL)
1020 for (x=0; x < (ssize_t) roi->width; x++)
1022 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1023 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1024 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1026 p+=GetPixelChannels(image);
1031 if (LocaleCompare(map,"I") == 0)
1033 for (y=0; y < (ssize_t) roi->height; y++)
1035 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1036 if (p == (const Quantum *) NULL)
1038 for (x=0; x < (ssize_t) roi->width; x++)
1040 *q++=ScaleQuantumToLong(GetPixelIntensity(image,p));
1041 p+=GetPixelChannels(image);
1046 if (LocaleCompare(map,"RGB") == 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(GetPixelRed(image,p));
1056 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1057 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1058 p+=GetPixelChannels(image);
1063 if (LocaleCompare(map,"RGBA") == 0)
1065 for (y=0; y < (ssize_t) roi->height; y++)
1067 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1068 if (p == (const Quantum *) NULL)
1070 for (x=0; x < (ssize_t) roi->width; x++)
1072 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1073 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1074 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1075 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1076 p+=GetPixelChannels(image);
1081 if (LocaleCompare(map,"RGBP") == 0)
1083 for (y=0; y < (ssize_t) roi->height; y++)
1085 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1086 if (p == (const Quantum *) NULL)
1088 for (x=0; x < (ssize_t) roi->width; x++)
1090 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1091 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1092 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1094 p+=GetPixelChannels(image);
1099 for (y=0; y < (ssize_t) roi->height; y++)
1101 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1102 if (p == (const Quantum *) NULL)
1104 for (x=0; x < (ssize_t) roi->width; x++)
1109 for (i=0; i < (ssize_t) strlen(map); i++)
1112 switch (quantum_map[i])
1117 *q=ScaleQuantumToLong(GetPixelRed(image,p));
1121 case MagentaQuantum:
1123 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
1129 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
1134 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1137 case OpacityQuantum:
1139 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1144 if (image->colorspace == CMYKColorspace)
1145 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
1150 *q=ScaleQuantumToLong(GetPixelIntensity(image,p));
1158 p+=GetPixelChannels(image);
1163 static void ExportLongLongPixel(const Image *image,const RectangleInfo *roi,
1164 const char *restrict map,const QuantumType *quantum_map,void *pixels,
1165 ExceptionInfo *exception)
1167 register const Quantum
1173 register MagickSizeType
1179 q=(MagickSizeType *) pixels;
1180 if (LocaleCompare(map,"BGR") == 0)
1182 for (y=0; y < (ssize_t) roi->height; y++)
1184 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1185 if (p == (const Quantum *) NULL)
1187 for (x=0; x < (ssize_t) roi->width; x++)
1189 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1190 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1191 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1192 p+=GetPixelChannels(image);
1197 if (LocaleCompare(map,"BGRA") == 0)
1199 for (y=0; y < (ssize_t) roi->height; y++)
1201 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1202 if (p == (const Quantum *) NULL)
1204 for (x=0; x < (ssize_t) roi->width; x++)
1206 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1207 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1208 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1209 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1210 p+=GetPixelChannels(image);
1215 if (LocaleCompare(map,"BGRP") == 0)
1217 for (y=0; y < (ssize_t) roi->height; y++)
1219 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1220 if (p == (const Quantum *) NULL)
1222 for (x=0; x < (ssize_t) roi->width; x++)
1224 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1225 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1226 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1228 p+=GetPixelChannels(image);
1233 if (LocaleCompare(map,"I") == 0)
1235 for (y=0; y < (ssize_t) roi->height; y++)
1237 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1238 if (p == (const Quantum *) NULL)
1240 for (x=0; x < (ssize_t) roi->width; x++)
1242 *q++=ScaleQuantumToLongLong(GetPixelIntensity(image,p));
1243 p+=GetPixelChannels(image);
1248 if (LocaleCompare(map,"RGB") == 0)
1250 for (y=0; y < (ssize_t) roi->height; y++)
1252 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1253 if (p == (const Quantum *) NULL)
1255 for (x=0; x < (ssize_t) roi->width; x++)
1257 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1258 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1259 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1260 p+=GetPixelChannels(image);
1265 if (LocaleCompare(map,"RGBA") == 0)
1267 for (y=0; y < (ssize_t) roi->height; y++)
1269 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1270 if (p == (const Quantum *) NULL)
1272 for (x=0; x < (ssize_t) roi->width; x++)
1274 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1275 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1276 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1277 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1278 p+=GetPixelChannels(image);
1283 if (LocaleCompare(map,"RGBP") == 0)
1285 for (y=0; y < (ssize_t) roi->height; y++)
1287 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1288 if (p == (const Quantum *) NULL)
1290 for (x=0; x < (ssize_t) roi->width; x++)
1292 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1293 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1294 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1296 p+=GetPixelChannels(image);
1301 for (y=0; y < (ssize_t) roi->height; y++)
1303 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1304 if (p == (const Quantum *) NULL)
1306 for (x=0; x < (ssize_t) roi->width; x++)
1311 for (i=0; i < (ssize_t) strlen(map); i++)
1314 switch (quantum_map[i])
1319 *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
1323 case MagentaQuantum:
1325 *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1331 *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1336 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1339 case OpacityQuantum:
1341 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1346 if (image->colorspace == CMYKColorspace)
1347 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
1352 *q=ScaleQuantumToLongLong(GetPixelIntensity(image,p));
1360 p+=GetPixelChannels(image);
1365 static void ExportQuantumPixel(const Image *image,const RectangleInfo *roi,
1366 const char *restrict map,const QuantumType *quantum_map,void *pixels,
1367 ExceptionInfo *exception)
1369 register const Quantum
1381 q=(Quantum *) pixels;
1382 if (LocaleCompare(map,"BGR") == 0)
1384 for (y=0; y < (ssize_t) roi->height; y++)
1386 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1387 if (p == (const Quantum *) NULL)
1389 for (x=0; x < (ssize_t) roi->width; x++)
1391 *q++=GetPixelBlue(image,p);
1392 *q++=GetPixelGreen(image,p);
1393 *q++=GetPixelRed(image,p);
1394 p+=GetPixelChannels(image);
1399 if (LocaleCompare(map,"BGRA") == 0)
1401 for (y=0; y < (ssize_t) roi->height; y++)
1403 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1404 if (p == (const Quantum *) NULL)
1406 for (x=0; x < (ssize_t) roi->width; x++)
1408 *q++=GetPixelBlue(image,p);
1409 *q++=GetPixelGreen(image,p);
1410 *q++=GetPixelRed(image,p);
1411 *q++=(Quantum) (GetPixelAlpha(image,p));
1412 p+=GetPixelChannels(image);
1417 if (LocaleCompare(map,"BGRP") == 0)
1419 for (y=0; y < (ssize_t) roi->height; y++)
1421 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1422 if (p == (const Quantum *) NULL)
1424 for (x=0; x < (ssize_t) roi->width; x++)
1426 *q++=GetPixelBlue(image,p);
1427 *q++=GetPixelGreen(image,p);
1428 *q++=GetPixelRed(image,p);
1430 p+=GetPixelChannels(image);
1435 if (LocaleCompare(map,"I") == 0)
1437 for (y=0; y < (ssize_t) roi->height; y++)
1439 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1440 if (p == (const Quantum *) NULL)
1442 for (x=0; x < (ssize_t) roi->width; x++)
1444 *q++=GetPixelIntensity(image,p);
1445 p+=GetPixelChannels(image);
1450 if (LocaleCompare(map,"RGB") == 0)
1452 for (y=0; y < (ssize_t) roi->height; y++)
1454 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1455 if (p == (const Quantum *) NULL)
1457 for (x=0; x < (ssize_t) roi->width; x++)
1459 *q++=GetPixelRed(image,p);
1460 *q++=GetPixelGreen(image,p);
1461 *q++=GetPixelBlue(image,p);
1462 p+=GetPixelChannels(image);
1467 if (LocaleCompare(map,"RGBA") == 0)
1469 for (y=0; y < (ssize_t) roi->height; y++)
1471 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1472 if (p == (const Quantum *) NULL)
1474 for (x=0; x < (ssize_t) roi->width; x++)
1476 *q++=GetPixelRed(image,p);
1477 *q++=GetPixelGreen(image,p);
1478 *q++=GetPixelBlue(image,p);
1479 *q++=(Quantum) (GetPixelAlpha(image,p));
1480 p+=GetPixelChannels(image);
1485 if (LocaleCompare(map,"RGBP") == 0)
1487 for (y=0; y < (ssize_t) roi->height; y++)
1489 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1490 if (p == (const Quantum *) NULL)
1492 for (x=0; x < (ssize_t) roi->width; x++)
1494 *q++=GetPixelRed(image,p);
1495 *q++=GetPixelGreen(image,p);
1496 *q++=GetPixelBlue(image,p);
1498 p+=GetPixelChannels(image);
1503 for (y=0; y < (ssize_t) roi->height; y++)
1505 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1506 if (p == (const Quantum *) NULL)
1508 for (x=0; x < (ssize_t) roi->width; x++)
1513 for (i=0; i < (ssize_t) strlen(map); i++)
1516 switch (quantum_map[i])
1521 *q=GetPixelRed(image,p);
1525 case MagentaQuantum:
1527 *q=GetPixelGreen(image,p);
1533 *q=GetPixelBlue(image,p);
1538 *q=GetPixelAlpha(image,p);
1541 case OpacityQuantum:
1543 *q=GetPixelAlpha(image,p);
1548 if (image->colorspace == CMYKColorspace)
1549 *q=GetPixelBlack(image,p);
1554 *q=(GetPixelIntensity(image,p));
1565 p+=GetPixelChannels(image);
1570 static void ExportShortPixel(const Image *image,const RectangleInfo *roi,
1571 const char *restrict map,const QuantumType *quantum_map,void *pixels,
1572 ExceptionInfo *exception)
1574 register const Quantum
1583 register unsigned short
1586 q=(unsigned short *) pixels;
1587 if (LocaleCompare(map,"BGR") == 0)
1589 for (y=0; y < (ssize_t) roi->height; y++)
1591 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1592 if (p == (const Quantum *) NULL)
1594 for (x=0; x < (ssize_t) roi->width; x++)
1596 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1597 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1598 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1599 p+=GetPixelChannels(image);
1604 if (LocaleCompare(map,"BGRA") == 0)
1606 for (y=0; y < (ssize_t) roi->height; y++)
1608 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1609 if (p == (const Quantum *) NULL)
1611 for (x=0; x < (ssize_t) roi->width; x++)
1613 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1614 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1615 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1616 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1617 p+=GetPixelChannels(image);
1622 if (LocaleCompare(map,"BGRP") == 0)
1624 for (y=0; y < (ssize_t) roi->height; y++)
1626 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1627 if (p == (const Quantum *) NULL)
1629 for (x=0; x < (ssize_t) roi->width; x++)
1631 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1632 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1633 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1635 p+=GetPixelChannels(image);
1640 if (LocaleCompare(map,"I") == 0)
1642 for (y=0; y < (ssize_t) roi->height; y++)
1644 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1645 if (p == (const Quantum *) NULL)
1647 for (x=0; x < (ssize_t) roi->width; x++)
1649 *q++=ScaleQuantumToShort(GetPixelIntensity(image,p));
1650 p+=GetPixelChannels(image);
1655 if (LocaleCompare(map,"RGB") == 0)
1657 for (y=0; y < (ssize_t) roi->height; y++)
1659 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1660 if (p == (const Quantum *) NULL)
1662 for (x=0; x < (ssize_t) roi->width; x++)
1664 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1665 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1666 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1667 p+=GetPixelChannels(image);
1672 if (LocaleCompare(map,"RGBA") == 0)
1674 for (y=0; y < (ssize_t) roi->height; y++)
1676 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1677 if (p == (const Quantum *) NULL)
1679 for (x=0; x < (ssize_t) roi->width; x++)
1681 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1682 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1683 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1684 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1685 p+=GetPixelChannels(image);
1690 if (LocaleCompare(map,"RGBP") == 0)
1692 for (y=0; y < (ssize_t) roi->height; y++)
1694 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1695 if (p == (const Quantum *) NULL)
1697 for (x=0; x < (ssize_t) roi->width; x++)
1699 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1700 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1701 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1703 p+=GetPixelChannels(image);
1708 for (y=0; y < (ssize_t) roi->height; y++)
1710 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1711 if (p == (const Quantum *) NULL)
1713 for (x=0; x < (ssize_t) roi->width; x++)
1718 for (i=0; i < (ssize_t) strlen(map); i++)
1721 switch (quantum_map[i])
1726 *q=ScaleQuantumToShort(GetPixelRed(image,p));
1730 case MagentaQuantum:
1732 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
1738 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
1743 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1746 case OpacityQuantum:
1748 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1753 if (image->colorspace == CMYKColorspace)
1754 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
1759 *q=ScaleQuantumToShort(GetPixelIntensity(image,p));
1767 p+=GetPixelChannels(image);
1772 MagickExport MagickBooleanType ExportImagePixels(const Image *image,
1773 const ssize_t x,const ssize_t y,const size_t width,const size_t height,
1774 const char *map,const StorageType type,void *pixels,ExceptionInfo *exception)
1785 assert(image != (Image *) NULL);
1786 assert(image->signature == MagickSignature);
1787 if (image->debug != MagickFalse)
1788 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1789 quantum_map=(QuantumType *) AcquireQuantumMemory(strlen(map),
1790 sizeof(*quantum_map));
1791 if (quantum_map == (QuantumType *) NULL)
1793 (void) ThrowMagickException(exception,GetMagickModule(),
1794 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1795 return(MagickFalse);
1797 for (i=0; i < (ssize_t) strlen(map); i++)
1804 quantum_map[i]=AlphaQuantum;
1810 quantum_map[i]=BlueQuantum;
1816 quantum_map[i]=CyanQuantum;
1817 if (image->colorspace == CMYKColorspace)
1819 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1820 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1821 "ColorSeparatedImageRequired","`%s'",map);
1822 return(MagickFalse);
1827 quantum_map[i]=GreenQuantum;
1833 quantum_map[i]=IndexQuantum;
1839 quantum_map[i]=BlackQuantum;
1840 if (image->colorspace == CMYKColorspace)
1842 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1843 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1844 "ColorSeparatedImageRequired","`%s'",map);
1845 return(MagickFalse);
1850 quantum_map[i]=MagentaQuantum;
1851 if (image->colorspace == CMYKColorspace)
1853 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1854 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1855 "ColorSeparatedImageRequired","`%s'",map);
1856 return(MagickFalse);
1861 quantum_map[i]=OpacityQuantum;
1867 quantum_map[i]=UndefinedQuantum;
1873 quantum_map[i]=RedQuantum;
1879 quantum_map[i]=YellowQuantum;
1880 if (image->colorspace == CMYKColorspace)
1882 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1883 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1884 "ColorSeparatedImageRequired","`%s'",map);
1885 return(MagickFalse);
1889 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1890 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1891 "UnrecognizedPixelMap","`%s'",map);
1892 return(MagickFalse);
1904 ExportCharPixel(image,&roi,map,quantum_map,pixels,exception);
1909 ExportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
1914 ExportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
1919 ExportLongPixel(image,&roi,map,quantum_map,pixels,exception);
1924 ExportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
1929 ExportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
1934 ExportShortPixel(image,&roi,map,quantum_map,pixels,exception);
1939 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1940 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1941 "UnrecognizedPixelMap","`%s'",map);
1945 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1950 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1954 % G e t P i x e l I n f o %
1958 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1960 % GetPixelInfo() initializes the PixelInfo structure.
1962 % The format of the GetPixelInfo method is:
1964 % GetPixelInfo(const Image *image,PixelInfo *pixel)
1966 % A description of each parameter follows:
1968 % o image: the image.
1970 % o pixel: Specifies a pointer to a PixelInfo structure.
1973 MagickExport void GetPixelInfo(const Image *image,PixelInfo *pixel)
1975 pixel->storage_class=DirectClass;
1976 pixel->colorspace=RGBColorspace;
1977 pixel->matte=MagickFalse;
1979 pixel->depth=MAGICKCORE_QUANTUM_DEPTH;
1984 pixel->alpha=(MagickRealType) OpaqueAlpha;
1986 if (image == (const Image *) NULL)
1988 pixel->storage_class=image->storage_class;
1989 pixel->colorspace=image->colorspace;
1990 pixel->matte=image->matte;
1991 pixel->depth=image->depth;
1992 pixel->fuzz=image->fuzz;
1996 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2000 % I m p o r t I m a g e P i x e l s %
2004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2006 % ImportImagePixels() accepts pixel data and stores in the image at the
2007 % location you specify. The method returns MagickTrue on success otherwise
2008 % MagickFalse if an error is encountered. The pixel data can be either char,
2009 % Quantum, short int, unsigned int, unsigned long long, float, or double in
2010 % the order specified by map.
2012 % Suppose your want to upload the first scanline of a 640x480 image from
2013 % character data in red-green-blue order:
2015 % ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels);
2017 % The format of the ImportImagePixels method is:
2019 % MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
2020 % const ssize_t y,const size_t width,const size_t height,
2021 % const char *map,const StorageType type,const void *pixels,
2022 % ExceptionInfo *exception)
2024 % A description of each parameter follows:
2026 % o image: the image.
2028 % o x,y,width,height: These values define the perimeter
2029 % of a region of pixels you want to define.
2031 % o map: This string reflects the expected ordering of the pixel array.
2032 % It can be any combination or order of R = red, G = green, B = blue,
2033 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
2034 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
2037 % o type: Define the data type of the pixels. Float and double types are
2038 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
2039 % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *),
2040 % LongPixel (unsigned int *), LongLongPixel (unsigned long long *),
2041 % QuantumPixel (Quantum *), or ShortPixel (unsigned short *).
2043 % o pixels: This array of values contain the pixel components as defined by
2044 % map and type. You must preallocate this array where the expected
2045 % length varies depending on the values of width, height, map, and type.
2047 % o exception: return any errors or warnings in this structure.
2051 static void ImportCharPixel(Image *image,const RectangleInfo *roi,
2052 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2053 ExceptionInfo *exception)
2055 register const unsigned char
2067 p=(const unsigned char *) pixels;
2068 if (LocaleCompare(map,"BGR") == 0)
2070 for (y=0; y < (ssize_t) roi->height; y++)
2072 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2073 if (q == (Quantum *) NULL)
2075 for (x=0; x < (ssize_t) roi->width; x++)
2077 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2078 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2079 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2080 q+=GetPixelChannels(image);
2082 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2087 if (LocaleCompare(map,"BGRA") == 0)
2089 for (y=0; y < (ssize_t) roi->height; y++)
2091 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2092 if (q == (Quantum *) NULL)
2094 for (x=0; x < (ssize_t) roi->width; x++)
2096 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2097 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2098 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2099 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2100 q+=GetPixelChannels(image);
2102 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2107 if (LocaleCompare(map,"BGRO") == 0)
2109 for (y=0; y < (ssize_t) roi->height; y++)
2111 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2112 if (q == (Quantum *) NULL)
2114 for (x=0; x < (ssize_t) roi->width; x++)
2116 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2117 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2118 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2119 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2120 q+=GetPixelChannels(image);
2122 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2127 if (LocaleCompare(map,"BGRP") == 0)
2129 for (y=0; y < (ssize_t) roi->height; y++)
2131 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2132 if (q == (Quantum *) NULL)
2134 for (x=0; x < (ssize_t) roi->width; x++)
2136 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2137 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2138 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2140 q+=GetPixelChannels(image);
2142 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2147 if (LocaleCompare(map,"I") == 0)
2149 for (y=0; y < (ssize_t) roi->height; y++)
2151 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2152 if (q == (Quantum *) NULL)
2154 for (x=0; x < (ssize_t) roi->width; x++)
2156 SetPixelGray(image,ScaleCharToQuantum(*p++),q);
2157 q+=GetPixelChannels(image);
2159 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2164 if (LocaleCompare(map,"RGB") == 0)
2166 for (y=0; y < (ssize_t) roi->height; y++)
2168 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2169 if (q == (Quantum *) NULL)
2171 for (x=0; x < (ssize_t) roi->width; x++)
2173 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2174 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2175 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2176 q+=GetPixelChannels(image);
2178 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2183 if (LocaleCompare(map,"RGBA") == 0)
2185 for (y=0; y < (ssize_t) roi->height; y++)
2187 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2188 if (q == (Quantum *) NULL)
2190 for (x=0; x < (ssize_t) roi->width; x++)
2192 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2193 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2194 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2195 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2196 q+=GetPixelChannels(image);
2198 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2203 if (LocaleCompare(map,"RGBO") == 0)
2205 for (y=0; y < (ssize_t) roi->height; y++)
2207 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2208 if (q == (Quantum *) NULL)
2210 for (x=0; x < (ssize_t) roi->width; x++)
2212 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2213 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2214 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2215 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2216 q+=GetPixelChannels(image);
2218 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2223 if (LocaleCompare(map,"RGBP") == 0)
2225 for (y=0; y < (ssize_t) roi->height; y++)
2227 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2228 if (q == (Quantum *) NULL)
2230 for (x=0; x < (ssize_t) roi->width; x++)
2232 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2233 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2234 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2236 q+=GetPixelChannels(image);
2238 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2243 for (y=0; y < (ssize_t) roi->height; y++)
2245 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2246 if (q == (Quantum *) NULL)
2248 for (x=0; x < (ssize_t) roi->width; x++)
2253 for (i=0; i < (ssize_t) strlen(map); i++)
2255 switch (quantum_map[i])
2260 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2264 case MagentaQuantum:
2266 SetPixelGreen(image,ScaleCharToQuantum(*p),q);
2272 SetPixelBlue(image,ScaleCharToQuantum(*p),q);
2277 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2280 case OpacityQuantum:
2282 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2287 SetPixelBlack(image,ScaleCharToQuantum(*p),q);
2292 SetPixelGray(image,ScaleCharToQuantum(*p),q);
2300 q+=GetPixelChannels(image);
2302 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2307 static void ImportDoublePixel(Image *image,const RectangleInfo *roi,
2308 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2309 ExceptionInfo *exception)
2311 register const double
2323 p=(const double *) pixels;
2324 if (LocaleCompare(map,"BGR") == 0)
2326 for (y=0; y < (ssize_t) roi->height; y++)
2328 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2329 if (q == (Quantum *) NULL)
2331 for (x=0; x < (ssize_t) roi->width; x++)
2333 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2336 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2339 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2342 q+=GetPixelChannels(image);
2344 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2349 if (LocaleCompare(map,"BGRA") == 0)
2351 for (y=0; y < (ssize_t) roi->height; y++)
2353 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2354 if (q == (Quantum *) NULL)
2356 for (x=0; x < (ssize_t) roi->width; x++)
2358 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2361 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2364 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2367 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2370 q+=GetPixelChannels(image);
2372 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2377 if (LocaleCompare(map,"BGRP") == 0)
2379 for (y=0; y < (ssize_t) roi->height; y++)
2381 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2382 if (q == (Quantum *) NULL)
2384 for (x=0; x < (ssize_t) roi->width; x++)
2386 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2389 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2392 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2396 q+=GetPixelChannels(image);
2398 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2403 if (LocaleCompare(map,"I") == 0)
2405 for (y=0; y < (ssize_t) roi->height; y++)
2407 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2408 if (q == (Quantum *) NULL)
2410 for (x=0; x < (ssize_t) roi->width; x++)
2412 SetPixelGray(image,ClampToQuantum((MagickRealType) QuantumRange*
2415 q+=GetPixelChannels(image);
2417 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2422 if (LocaleCompare(map,"RGB") == 0)
2424 for (y=0; y < (ssize_t) roi->height; y++)
2426 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2427 if (q == (Quantum *) NULL)
2429 for (x=0; x < (ssize_t) roi->width; x++)
2431 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2434 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2437 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2440 q+=GetPixelChannels(image);
2442 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2447 if (LocaleCompare(map,"RGBA") == 0)
2449 for (y=0; y < (ssize_t) roi->height; y++)
2451 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2452 if (q == (Quantum *) NULL)
2454 for (x=0; x < (ssize_t) roi->width; x++)
2456 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2459 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2462 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2465 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2468 q+=GetPixelChannels(image);
2470 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2475 if (LocaleCompare(map,"RGBP") == 0)
2477 for (y=0; y < (ssize_t) roi->height; y++)
2479 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2480 if (q == (Quantum *) NULL)
2482 for (x=0; x < (ssize_t) roi->width; x++)
2484 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2487 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2490 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2493 q+=GetPixelChannels(image);
2495 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2500 for (y=0; y < (ssize_t) roi->height; y++)
2502 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2503 if (q == (Quantum *) NULL)
2505 for (x=0; x < (ssize_t) roi->width; x++)
2510 for (i=0; i < (ssize_t) strlen(map); i++)
2512 switch (quantum_map[i])
2517 SetPixelRed(image,ClampToQuantum((MagickRealType)
2518 QuantumRange*(*p)),q);
2522 case MagentaQuantum:
2524 SetPixelGreen(image,ClampToQuantum((MagickRealType)
2525 QuantumRange*(*p)),q);
2531 SetPixelBlue(image,ClampToQuantum((MagickRealType)
2532 QuantumRange*(*p)),q);
2537 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2538 QuantumRange*(*p)),q);
2541 case OpacityQuantum:
2543 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2544 QuantumRange*(*p)),q);
2549 SetPixelBlack(image,ClampToQuantum((MagickRealType)
2550 QuantumRange*(*p)),q);
2555 SetPixelGray(image,ClampToQuantum((MagickRealType)
2556 QuantumRange*(*p)),q);
2564 q+=GetPixelChannels(image);
2566 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2571 static void ImportFloatPixel(Image *image,const RectangleInfo *roi,
2572 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2573 ExceptionInfo *exception)
2575 register const float
2587 p=(const float *) pixels;
2588 if (LocaleCompare(map,"BGR") == 0)
2590 for (y=0; y < (ssize_t) roi->height; y++)
2592 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2593 if (q == (Quantum *) NULL)
2595 for (x=0; x < (ssize_t) roi->width; x++)
2597 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2600 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2603 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2606 q+=GetPixelChannels(image);
2608 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2613 if (LocaleCompare(map,"BGRA") == 0)
2615 for (y=0; y < (ssize_t) roi->height; y++)
2617 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2618 if (q == (Quantum *) NULL)
2620 for (x=0; x < (ssize_t) roi->width; x++)
2622 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2625 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2628 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2631 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2634 q+=GetPixelChannels(image);
2636 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2641 if (LocaleCompare(map,"BGRP") == 0)
2643 for (y=0; y < (ssize_t) roi->height; y++)
2645 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2646 if (q == (Quantum *) NULL)
2648 for (x=0; x < (ssize_t) roi->width; x++)
2650 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2653 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2656 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2660 q+=GetPixelChannels(image);
2662 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2667 if (LocaleCompare(map,"I") == 0)
2669 for (y=0; y < (ssize_t) roi->height; y++)
2671 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2672 if (q == (Quantum *) NULL)
2674 for (x=0; x < (ssize_t) roi->width; x++)
2676 SetPixelGray(image,ClampToQuantum((MagickRealType) QuantumRange*
2679 q+=GetPixelChannels(image);
2681 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2686 if (LocaleCompare(map,"RGB") == 0)
2688 for (y=0; y < (ssize_t) roi->height; y++)
2690 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2691 if (q == (Quantum *) NULL)
2693 for (x=0; x < (ssize_t) roi->width; x++)
2695 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2698 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2701 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2704 q+=GetPixelChannels(image);
2706 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2711 if (LocaleCompare(map,"RGBA") == 0)
2713 for (y=0; y < (ssize_t) roi->height; y++)
2715 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2716 if (q == (Quantum *) NULL)
2718 for (x=0; x < (ssize_t) roi->width; x++)
2720 SetPixelRed(image,ClampToQuantum((MagickRealType)
2721 QuantumRange*(*p)),q);
2723 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2726 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2729 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2732 q+=GetPixelChannels(image);
2734 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2739 if (LocaleCompare(map,"RGBP") == 0)
2741 for (y=0; y < (ssize_t) roi->height; y++)
2743 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2744 if (q == (Quantum *) NULL)
2746 for (x=0; x < (ssize_t) roi->width; x++)
2748 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2751 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2754 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2757 q+=GetPixelChannels(image);
2759 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2764 for (y=0; y < (ssize_t) roi->height; y++)
2766 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2767 if (q == (Quantum *) NULL)
2769 for (x=0; x < (ssize_t) roi->width; x++)
2774 for (i=0; i < (ssize_t) strlen(map); i++)
2776 switch (quantum_map[i])
2781 SetPixelRed(image,ClampToQuantum((MagickRealType)
2782 QuantumRange*(*p)),q);
2786 case MagentaQuantum:
2788 SetPixelGreen(image,ClampToQuantum((MagickRealType)
2789 QuantumRange*(*p)),q);
2795 SetPixelBlue(image,ClampToQuantum((MagickRealType)
2796 QuantumRange*(*p)),q);
2801 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2802 QuantumRange*(*p)),q);
2805 case OpacityQuantum:
2807 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2808 QuantumRange*(*p)),q);
2813 SetPixelBlack(image,ClampToQuantum((MagickRealType)
2814 QuantumRange*(*p)),q);
2819 SetPixelGray(image,ClampToQuantum((MagickRealType)
2820 QuantumRange*(*p)),q);
2828 q+=GetPixelChannels(image);
2830 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2835 static void ImportLongPixel(Image *image,const RectangleInfo *roi,
2836 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2837 ExceptionInfo *exception)
2839 register const unsigned int
2851 p=(const unsigned int *) pixels;
2852 if (LocaleCompare(map,"BGR") == 0)
2854 for (y=0; y < (ssize_t) roi->height; y++)
2856 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2857 if (q == (Quantum *) NULL)
2859 for (x=0; x < (ssize_t) roi->width; x++)
2861 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2862 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2863 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2864 q+=GetPixelChannels(image);
2866 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2871 if (LocaleCompare(map,"BGRA") == 0)
2873 for (y=0; y < (ssize_t) roi->height; y++)
2875 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2876 if (q == (Quantum *) NULL)
2878 for (x=0; x < (ssize_t) roi->width; x++)
2880 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2881 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2882 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2883 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
2884 q+=GetPixelChannels(image);
2886 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2891 if (LocaleCompare(map,"BGRP") == 0)
2893 for (y=0; y < (ssize_t) roi->height; y++)
2895 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2896 if (q == (Quantum *) NULL)
2898 for (x=0; x < (ssize_t) roi->width; x++)
2900 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2901 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2902 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2904 q+=GetPixelChannels(image);
2906 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2911 if (LocaleCompare(map,"I") == 0)
2913 for (y=0; y < (ssize_t) roi->height; y++)
2915 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2916 if (q == (Quantum *) NULL)
2918 for (x=0; x < (ssize_t) roi->width; x++)
2920 SetPixelGray(image,ScaleLongToQuantum(*p++),q);
2921 q+=GetPixelChannels(image);
2923 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2928 if (LocaleCompare(map,"RGB") == 0)
2930 for (y=0; y < (ssize_t) roi->height; y++)
2932 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2933 if (q == (Quantum *) NULL)
2935 for (x=0; x < (ssize_t) roi->width; x++)
2937 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2938 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2939 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2940 q+=GetPixelChannels(image);
2942 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2947 if (LocaleCompare(map,"RGBA") == 0)
2949 for (y=0; y < (ssize_t) roi->height; y++)
2951 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2952 if (q == (Quantum *) NULL)
2954 for (x=0; x < (ssize_t) roi->width; x++)
2956 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2957 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2958 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2959 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
2960 q+=GetPixelChannels(image);
2962 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2967 if (LocaleCompare(map,"RGBP") == 0)
2969 for (y=0; y < (ssize_t) roi->height; y++)
2971 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2972 if (q == (Quantum *) NULL)
2974 for (x=0; x < (ssize_t) roi->width; x++)
2976 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2977 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2978 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2980 q+=GetPixelChannels(image);
2982 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2987 for (y=0; y < (ssize_t) roi->height; y++)
2989 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2990 if (q == (Quantum *) NULL)
2992 for (x=0; x < (ssize_t) roi->width; x++)
2997 for (i=0; i < (ssize_t) strlen(map); i++)
2999 switch (quantum_map[i])
3004 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3008 case MagentaQuantum:
3010 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
3016 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
3021 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3024 case OpacityQuantum:
3026 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3031 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
3036 SetPixelGray(image,ScaleLongToQuantum(*p),q);
3044 q+=GetPixelChannels(image);
3046 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3051 static void ImportLongLongPixel(Image *image,const RectangleInfo *roi,
3052 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3053 ExceptionInfo *exception)
3055 register const MagickSizeType
3067 p=(const MagickSizeType *) pixels;
3068 if (LocaleCompare(map,"BGR") == 0)
3070 for (y=0; y < (ssize_t) roi->height; y++)
3072 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3073 if (q == (Quantum *) NULL)
3075 for (x=0; x < (ssize_t) roi->width; x++)
3077 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3078 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3079 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3080 q+=GetPixelChannels(image);
3082 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3087 if (LocaleCompare(map,"BGRA") == 0)
3089 for (y=0; y < (ssize_t) roi->height; y++)
3091 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3092 if (q == (Quantum *) NULL)
3094 for (x=0; x < (ssize_t) roi->width; x++)
3096 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3097 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3098 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3099 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3100 q+=GetPixelChannels(image);
3102 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3107 if (LocaleCompare(map,"BGRP") == 0)
3109 for (y=0; y < (ssize_t) roi->height; y++)
3111 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3112 if (q == (Quantum *) NULL)
3114 for (x=0; x < (ssize_t) roi->width; x++)
3116 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3117 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3118 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3120 q+=GetPixelChannels(image);
3122 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3127 if (LocaleCompare(map,"I") == 0)
3129 for (y=0; y < (ssize_t) roi->height; y++)
3131 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3132 if (q == (Quantum *) NULL)
3134 for (x=0; x < (ssize_t) roi->width; x++)
3136 SetPixelGray(image,ScaleLongLongToQuantum(*p++),q);
3137 q+=GetPixelChannels(image);
3139 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3144 if (LocaleCompare(map,"RGB") == 0)
3146 for (y=0; y < (ssize_t) roi->height; y++)
3148 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3149 if (q == (Quantum *) NULL)
3151 for (x=0; x < (ssize_t) roi->width; x++)
3153 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3154 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3155 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3156 q+=GetPixelChannels(image);
3158 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3163 if (LocaleCompare(map,"RGBA") == 0)
3165 for (y=0; y < (ssize_t) roi->height; y++)
3167 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3168 if (q == (Quantum *) NULL)
3170 for (x=0; x < (ssize_t) roi->width; x++)
3172 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3173 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3174 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3175 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3176 q+=GetPixelChannels(image);
3178 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3183 if (LocaleCompare(map,"RGBP") == 0)
3185 for (y=0; y < (ssize_t) roi->height; y++)
3187 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3188 if (q == (Quantum *) NULL)
3190 for (x=0; x < (ssize_t) roi->width; x++)
3192 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3193 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3194 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3196 q+=GetPixelChannels(image);
3198 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3203 for (y=0; y < (ssize_t) roi->height; y++)
3205 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3206 if (q == (Quantum *) NULL)
3208 for (x=0; x < (ssize_t) roi->width; x++)
3213 for (i=0; i < (ssize_t) strlen(map); i++)
3215 switch (quantum_map[i])
3220 SetPixelRed(image,ScaleLongLongToQuantum(*p),q);
3224 case MagentaQuantum:
3226 SetPixelGreen(image,ScaleLongLongToQuantum(*p),q);
3232 SetPixelBlue(image,ScaleLongLongToQuantum(*p),q);
3237 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3240 case OpacityQuantum:
3242 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3247 SetPixelBlack(image,ScaleLongLongToQuantum(*p),q);
3252 SetPixelGray(image,ScaleLongLongToQuantum(*p),q);
3260 q+=GetPixelChannels(image);
3262 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3267 static void ImportQuantumPixel(Image *image,const RectangleInfo *roi,
3268 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3269 ExceptionInfo *exception)
3271 register const Quantum
3283 p=(const Quantum *) pixels;
3284 if (LocaleCompare(map,"BGR") == 0)
3286 for (y=0; y < (ssize_t) roi->height; y++)
3288 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3289 if (q == (Quantum *) NULL)
3291 for (x=0; x < (ssize_t) roi->width; x++)
3293 SetPixelBlue(image,*p++,q);
3294 SetPixelGreen(image,*p++,q);
3295 SetPixelRed(image,*p++,q);
3296 q+=GetPixelChannels(image);
3298 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3303 if (LocaleCompare(map,"BGRA") == 0)
3305 for (y=0; y < (ssize_t) roi->height; y++)
3307 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3308 if (q == (Quantum *) NULL)
3310 for (x=0; x < (ssize_t) roi->width; x++)
3312 SetPixelBlue(image,*p++,q);
3313 SetPixelGreen(image,*p++,q);
3314 SetPixelRed(image,*p++,q);
3315 SetPixelAlpha(image,*p++,q);
3316 q+=GetPixelChannels(image);
3318 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3323 if (LocaleCompare(map,"BGRP") == 0)
3325 for (y=0; y < (ssize_t) roi->height; y++)
3327 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3328 if (q == (Quantum *) NULL)
3330 for (x=0; x < (ssize_t) roi->width; x++)
3332 SetPixelBlue(image,*p++,q);
3333 SetPixelGreen(image,*p++,q);
3334 SetPixelRed(image,*p++,q);
3336 q+=GetPixelChannels(image);
3338 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3343 if (LocaleCompare(map,"I") == 0)
3345 for (y=0; y < (ssize_t) roi->height; y++)
3347 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3348 if (q == (Quantum *) NULL)
3350 for (x=0; x < (ssize_t) roi->width; x++)
3352 SetPixelGray(image,*p++,q);
3353 q+=GetPixelChannels(image);
3355 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3360 if (LocaleCompare(map,"RGB") == 0)
3362 for (y=0; y < (ssize_t) roi->height; y++)
3364 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3365 if (q == (Quantum *) NULL)
3367 for (x=0; x < (ssize_t) roi->width; x++)
3369 SetPixelRed(image,*p++,q);
3370 SetPixelGreen(image,*p++,q);
3371 SetPixelBlue(image,*p++,q);
3372 q+=GetPixelChannels(image);
3374 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3379 if (LocaleCompare(map,"RGBA") == 0)
3381 for (y=0; y < (ssize_t) roi->height; y++)
3383 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3384 if (q == (Quantum *) NULL)
3386 for (x=0; x < (ssize_t) roi->width; x++)
3388 SetPixelRed(image,*p++,q);
3389 SetPixelGreen(image,*p++,q);
3390 SetPixelBlue(image,*p++,q);
3391 SetPixelAlpha(image,*p++,q);
3392 q+=GetPixelChannels(image);
3394 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3399 if (LocaleCompare(map,"RGBP") == 0)
3401 for (y=0; y < (ssize_t) roi->height; y++)
3403 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3404 if (q == (Quantum *) NULL)
3406 for (x=0; x < (ssize_t) roi->width; x++)
3408 SetPixelRed(image,*p++,q);
3409 SetPixelGreen(image,*p++,q);
3410 SetPixelBlue(image,*p++,q);
3412 q+=GetPixelChannels(image);
3414 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3419 for (y=0; y < (ssize_t) roi->height; y++)
3421 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3422 if (q == (Quantum *) NULL)
3424 for (x=0; x < (ssize_t) roi->width; x++)
3429 for (i=0; i < (ssize_t) strlen(map); i++)
3431 switch (quantum_map[i])
3436 SetPixelRed(image,*p,q);
3440 case MagentaQuantum:
3442 SetPixelGreen(image,*p,q);
3448 SetPixelBlue(image,*p,q);
3453 SetPixelAlpha(image,*p,q);
3456 case OpacityQuantum:
3458 SetPixelAlpha(image,*p,q);
3463 SetPixelBlack(image,*p,q);
3468 SetPixelGray(image,*p,q);
3476 q+=GetPixelChannels(image);
3478 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3483 static void ImportShortPixel(Image *image,const RectangleInfo *roi,
3484 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3485 ExceptionInfo *exception)
3487 register const unsigned short
3499 p=(const unsigned short *) pixels;
3500 if (LocaleCompare(map,"BGR") == 0)
3502 for (y=0; y < (ssize_t) roi->height; y++)
3504 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3505 if (q == (Quantum *) NULL)
3507 for (x=0; x < (ssize_t) roi->width; x++)
3509 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3510 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3511 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3512 q+=GetPixelChannels(image);
3514 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3519 if (LocaleCompare(map,"BGRA") == 0)
3521 for (y=0; y < (ssize_t) roi->height; y++)
3523 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3524 if (q == (Quantum *) NULL)
3526 for (x=0; x < (ssize_t) roi->width; x++)
3528 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3529 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3530 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3531 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3532 q+=GetPixelChannels(image);
3534 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3539 if (LocaleCompare(map,"BGRP") == 0)
3541 for (y=0; y < (ssize_t) roi->height; y++)
3543 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3544 if (q == (Quantum *) NULL)
3546 for (x=0; x < (ssize_t) roi->width; x++)
3548 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3549 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3550 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3552 q+=GetPixelChannels(image);
3554 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3559 if (LocaleCompare(map,"I") == 0)
3561 for (y=0; y < (ssize_t) roi->height; y++)
3563 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3564 if (q == (Quantum *) NULL)
3566 for (x=0; x < (ssize_t) roi->width; x++)
3568 SetPixelGray(image,ScaleShortToQuantum(*p++),q);
3569 q+=GetPixelChannels(image);
3571 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3576 if (LocaleCompare(map,"RGB") == 0)
3578 for (y=0; y < (ssize_t) roi->height; y++)
3580 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3581 if (q == (Quantum *) NULL)
3583 for (x=0; x < (ssize_t) roi->width; x++)
3585 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3586 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3587 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3588 q+=GetPixelChannels(image);
3590 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3595 if (LocaleCompare(map,"RGBA") == 0)
3597 for (y=0; y < (ssize_t) roi->height; y++)
3599 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3600 if (q == (Quantum *) NULL)
3602 for (x=0; x < (ssize_t) roi->width; x++)
3604 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3605 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3606 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3607 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3608 q+=GetPixelChannels(image);
3610 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3615 if (LocaleCompare(map,"RGBP") == 0)
3617 for (y=0; y < (ssize_t) roi->height; y++)
3619 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3620 if (q == (Quantum *) NULL)
3622 for (x=0; x < (ssize_t) roi->width; x++)
3624 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3625 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3626 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3628 q+=GetPixelChannels(image);
3630 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3635 for (y=0; y < (ssize_t) roi->height; y++)
3637 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3638 if (q == (Quantum *) NULL)
3640 for (x=0; x < (ssize_t) roi->width; x++)
3645 for (i=0; i < (ssize_t) strlen(map); i++)
3647 switch (quantum_map[i])
3652 SetPixelRed(image,ScaleShortToQuantum(*p),q);
3656 case MagentaQuantum:
3658 SetPixelGreen(image,ScaleShortToQuantum(*p),q);
3664 SetPixelBlue(image,ScaleShortToQuantum(*p),q);
3669 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3672 case OpacityQuantum:
3674 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3679 SetPixelBlack(image,ScaleShortToQuantum(*p),q);
3684 SetPixelGray(image,ScaleShortToQuantum(*p),q);
3692 q+=GetPixelChannels(image);
3694 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3699 MagickExport MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
3700 const ssize_t y,const size_t width,const size_t height,const char *map,
3701 const StorageType type,const void *pixels,ExceptionInfo *exception)
3713 Allocate image structure.
3715 assert(image != (Image *) NULL);
3716 assert(image->signature == MagickSignature);
3717 if (image->debug != MagickFalse)
3718 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3719 quantum_map=(QuantumType *) AcquireQuantumMemory(strlen(map),
3720 sizeof(*quantum_map));
3721 if (quantum_map == (QuantumType *) NULL)
3722 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
3724 for (i=0; i < (ssize_t) strlen(map); i++)
3731 quantum_map[i]=AlphaQuantum;
3732 image->matte=MagickTrue;
3738 quantum_map[i]=BlueQuantum;
3744 quantum_map[i]=CyanQuantum;
3745 (void) SetImageColorspace(image,CMYKColorspace,exception);
3751 quantum_map[i]=GreenQuantum;
3757 quantum_map[i]=BlackQuantum;
3758 (void) SetImageColorspace(image,CMYKColorspace,exception);
3764 quantum_map[i]=IndexQuantum;
3770 quantum_map[i]=MagentaQuantum;
3771 (void) SetImageColorspace(image,CMYKColorspace,exception);
3777 quantum_map[i]=OpacityQuantum;
3778 image->matte=MagickTrue;
3784 quantum_map[i]=UndefinedQuantum;
3790 quantum_map[i]=RedQuantum;
3796 quantum_map[i]=YellowQuantum;
3797 (void) SetImageColorspace(image,CMYKColorspace,exception);
3802 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3803 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3804 "UnrecognizedPixelMap","`%s'",map);
3805 return(MagickFalse);
3809 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
3810 return(MagickFalse);
3812 Transfer the pixels from the pixel data to the image.
3822 ImportCharPixel(image,&roi,map,quantum_map,pixels,exception);
3827 ImportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
3832 ImportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
3837 ImportLongPixel(image,&roi,map,quantum_map,pixels,exception);
3842 ImportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
3847 ImportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
3852 ImportShortPixel(image,&roi,map,quantum_map,pixels,exception);
3857 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3858 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3859 "UnrecognizedPixelMap","`%s'",map);
3863 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3868 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3872 + 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 %
3876 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3878 % InitializePixelChannelMap() defines the standard pixel component map.
3880 % The format of the InitializePixelChannelMap() method is:
3882 % void InitializePixelChannelMap(Image *image)
3884 % A description of each parameter follows:
3886 % o image: the image.
3889 MagickExport void InitializePixelChannelMap(Image *image)
3900 assert(image != (Image *) NULL);
3901 assert(image->signature == MagickSignature);
3902 (void) ResetMagickMemory(image->channel_map,0,MaxPixelChannels*
3903 sizeof(*image->channel_map));
3904 trait=UpdatePixelTrait;
3905 if (image->matte != MagickFalse)
3906 trait=(PixelTrait) (trait | BlendPixelTrait);
3908 if (image->colorspace == GRAYColorspace)
3910 SetPixelChannelMap(image,BluePixelChannel,trait,n);
3911 SetPixelChannelMap(image,GreenPixelChannel,trait,n);
3912 SetPixelChannelMap(image,RedPixelChannel,trait,n++);
3916 SetPixelChannelMap(image,RedPixelChannel,trait,n++);
3917 SetPixelChannelMap(image,GreenPixelChannel,trait,n++);
3918 SetPixelChannelMap(image,BluePixelChannel,trait,n++);
3920 if (image->colorspace == CMYKColorspace)
3921 SetPixelChannelMap(image,BlackPixelChannel,trait,n++);
3922 if (image->matte != MagickFalse)
3923 SetPixelChannelMap(image,AlphaPixelChannel,CopyPixelTrait,n++);
3924 if (image->storage_class == PseudoClass)
3925 SetPixelChannelMap(image,IndexPixelChannel,CopyPixelTrait,n++);
3926 if (image->mask != MagickFalse)
3927 SetPixelChannelMap(image,MaskPixelChannel,CopyPixelTrait,n++);
3928 assert((n+image->number_meta_channels) < MaxPixelChannels);
3929 for (i=0; i < (ssize_t) image->number_meta_channels; i++)
3930 SetPixelChannelMap(image,(PixelChannel) (MetaPixelChannel+i),CopyPixelTrait,
3932 image->number_channels=(size_t) n;
3933 if (image->debug != MagickFalse)
3934 LogPixelChannels(image);
3935 (void) SetPixelChannelMask(image,image->channel_mask);
3939 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3943 % I n t e r p o l a t e P i x e l C h a n n e l %
3947 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3949 % InterpolatePixelChannel() applies a pixel interpolation method between a
3950 % floating point coordinate and the pixels surrounding that coordinate. No
3951 % pixel area resampling, or scaling of the result is performed.
3953 % The format of the InterpolatePixelChannel method is:
3955 % MagickBooleanType InterpolatePixelChannel(const Image *image,
3956 % const CacheView *image_view,const PixelChannel channel,
3957 % const PixelInterpolateMethod method,const double x,const double y,
3958 % double *pixel,ExceptionInfo *exception)
3960 % A description of each parameter follows:
3962 % o image: the image.
3964 % o image_view: the image view.
3966 % o channel: the pixel channel to interpolate.
3968 % o method: the pixel color interpolation method.
3970 % o x,y: A double representing the current (x,y) position of the pixel.
3972 % o pixel: return the interpolated pixel here.
3974 % o exception: return any errors or warnings in this structure.
3978 static inline double MagickMax(const MagickRealType x,const MagickRealType y)
3985 static inline MagickRealType CubicWeightingFunction(const MagickRealType x)
3991 alpha=MagickMax(x+2.0,0.0);
3992 gamma=1.0*alpha*alpha*alpha;
3993 alpha=MagickMax(x+1.0,0.0);
3994 gamma-=4.0*alpha*alpha*alpha;
3995 alpha=MagickMax(x+0.0,0.0);
3996 gamma+=6.0*alpha*alpha*alpha;
3997 alpha=MagickMax(x-1.0,0.0);
3998 gamma-=4.0*alpha*alpha*alpha;
4002 static inline double MeshInterpolate(const PointInfo *delta,const double p,
4003 const double x,const double y)
4005 return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
4008 static inline ssize_t NearestNeighbor(const MagickRealType x)
4011 return((ssize_t) (x+0.5));
4012 return((ssize_t) (x-0.5));
4015 MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
4016 const CacheView *image_view,const PixelChannel channel,
4017 const PixelInterpolateMethod method,const double x,const double y,
4018 double *pixel,ExceptionInfo *exception)
4031 register const Quantum
4041 assert(image != (Image *) NULL);
4042 assert(image != (Image *) NULL);
4043 assert(image->signature == MagickSignature);
4044 assert(image_view != (CacheView *) NULL);
4047 traits=GetPixelChannelMapTraits(image,channel);
4048 x_offset=(ssize_t) floor(x);
4049 y_offset=(ssize_t) floor(y);
4050 switch (method == UndefinedInterpolatePixel ? image->interpolate : method)
4052 case AverageInterpolatePixel:
4054 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4056 if (p == (const Quantum *) NULL)
4061 if ((traits & BlendPixelTrait) == 0)
4062 for (i=0; i < 16; i++)
4065 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4068 for (i=0; i < 16; i++)
4070 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4071 GetPixelChannels(image));
4072 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4074 for (i=0; i < 16; i++)
4076 gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]);
4077 *pixel+=gamma*0.0625*pixels[i];
4081 case BicubicInterpolatePixel:
4090 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4092 if (p == (const Quantum *) NULL)
4097 if ((traits & BlendPixelTrait) == 0)
4098 for (i=0; i < 16; i++)
4101 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4104 for (i=0; i < 16; i++)
4106 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4107 GetPixelChannels(image));
4108 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4112 for (i=0; i < 4; i++)
4114 u[0]=(pixels[4*i+3]-pixels[4*i+2])-(pixels[4*i+0]-pixels[4*i+1]);
4115 u[1]=(pixels[4*i+0]-pixels[4*i+1])-u[0];
4116 u[2]=pixels[4*i+2]-pixels[4*i+0];
4118 v[i]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x*
4121 u[0]=(v[3]-v[2])-(v[0]-v[1]);
4122 u[1]=(v[0]-v[1])-u[0];
4125 *pixel=(delta.y*delta.y*delta.y*u[0])+(delta.y*delta.y*u[1])+(delta.y*
4129 case BilinearInterpolatePixel:
4136 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4137 if (p == (const Quantum *) NULL)
4142 if ((traits & BlendPixelTrait) == 0)
4143 for (i=0; i < 4; i++)
4146 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4149 for (i=0; i < 4; i++)
4151 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4152 GetPixelChannels(image));
4153 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4157 epsilon.x=1.0-delta.x;
4158 epsilon.y=1.0-delta.y;
4159 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4160 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4161 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4162 *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
4163 (epsilon.x*pixels[2]+delta.x*pixels[3]));
4166 case FilterInterpolatePixel:
4180 geometry.x=x_offset-1;
4181 geometry.y=y_offset-1;
4182 excerpt_image=ExcerptImage(image,&geometry,exception);
4183 if (excerpt_image == (Image *) NULL)
4188 filter_image=ResizeImage(excerpt_image,1,1,image->filter,exception);
4189 excerpt_image=DestroyImage(excerpt_image);
4190 if (filter_image == (Image *) NULL)
4192 filter_view=AcquireCacheView(filter_image);
4193 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4194 if (p == (const Quantum *) NULL)
4197 *pixel=(double) GetPixelChannel(image,channel,p);
4198 filter_view=DestroyCacheView(filter_view);
4199 filter_image=DestroyImage(filter_image);
4202 case IntegerInterpolatePixel:
4204 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4205 if (p == (const Quantum *) NULL)
4210 *pixel=(double) GetPixelChannel(image,channel,p);
4213 case NearestNeighborInterpolatePixel:
4215 p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
4216 NearestNeighbor(y),1,1,exception);
4217 if (p == (const Quantum *) NULL)
4222 *pixel=(double) GetPixelChannel(image,channel,p);
4225 case MeshInterpolatePixel:
4231 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4232 if (p == (const Quantum *) NULL)
4237 if ((traits & BlendPixelTrait) == 0)
4238 for (i=0; i < 4; i++)
4241 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4244 for (i=0; i < 4; i++)
4246 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4247 GetPixelChannels(image));
4248 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4252 luminance.x=GetPixelLuminance(image,p)-(double)
4253 GetPixelLuminance(image,p+3*GetPixelChannels(image));
4254 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
4255 GetPixelLuminance(image,p+2*GetPixelChannels(image));
4256 if (fabs(luminance.x) < fabs(luminance.y))
4261 if (delta.x <= delta.y)
4264 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4266 delta.y=1.0-delta.y;
4267 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4268 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4269 *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
4275 Top-right triangle (pixel: 1, diagonal: 0-3).
4277 delta.x=1.0-delta.x;
4278 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4279 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4280 *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
4289 if (delta.x <= (1.0-delta.y))
4292 Top-left triangle (pixel: 0, diagonal: 1-2).
4294 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4295 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4296 *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
4302 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4304 delta.x=1.0-delta.x;
4305 delta.y=1.0-delta.y;
4306 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4307 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4308 *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
4314 case SplineInterpolatePixel:
4327 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4329 if (p == (const Quantum *) NULL)
4334 if ((traits & BlendPixelTrait) == 0)
4335 for (i=0; i < 16; i++)
4338 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4341 for (i=0; i < 16; i++)
4343 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4344 GetPixelChannels(image));
4345 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4350 for (i=(-1); i < 3L; i++)
4352 dy=CubicWeightingFunction((MagickRealType) i-delta.y);
4353 for (j=(-1); j < 3L; j++)
4355 dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
4356 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]);
4357 *pixel+=gamma*dx*dy*pixels[n];
4368 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4372 % I n t e r p o l a t e P i x e l C h a n n e l s %
4376 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4378 % InterpolatePixelChannels() applies a pixel interpolation method between a
4379 % floating point coordinate and the pixels surrounding that coordinate. No
4380 % pixel area resampling, or scaling of the result is performed.
4382 % The format of the InterpolatePixelChannels method is:
4384 % MagickBooleanType InterpolatePixelChannels(const Image *source,
4385 % const CacheView *source_view,const Image *destination,
4386 % const PixelInterpolateMethod method,const double x,const double y,
4387 % Quantum *pixel,ExceptionInfo *exception)
4389 % A description of each parameter follows:
4391 % o source: the source.
4393 % o source_view: the source view.
4395 % o destination: the destination image.
4397 % o method: the pixel color interpolation method.
4399 % o x,y: A double representing the current (x,y) position of the pixel.
4401 % o pixel: return the interpolated pixel here.
4403 % o exception: return any errors or warnings in this structure.
4406 MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
4407 const CacheView *source_view,const Image *destination,
4408 const PixelInterpolateMethod method,const double x,const double y,
4409 Quantum *pixel,ExceptionInfo *exception)
4426 register const Quantum
4436 assert(source != (Image *) NULL);
4437 assert(source != (Image *) NULL);
4438 assert(source->signature == MagickSignature);
4439 assert(source_view != (CacheView *) NULL);
4441 x_offset=(ssize_t) floor(x);
4442 y_offset=(ssize_t) floor(y);
4443 switch (method == UndefinedInterpolatePixel ? source->interpolate : method)
4445 case AverageInterpolatePixel:
4447 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4449 if (p == (const Quantum *) NULL)
4454 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4462 channel=GetPixelChannelMapChannel(source,i);
4463 traits=GetPixelChannelMapTraits(source,channel);
4464 destination_traits=GetPixelChannelMapTraits(destination,channel);
4465 if ((traits == UndefinedPixelTrait) ||
4466 (destination_traits == UndefinedPixelTrait))
4468 for (j=0; j < 16; j++)
4469 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4471 if ((traits & BlendPixelTrait) == 0)
4473 for (j=0; j < 16; j++)
4474 sum+=0.0625*pixels[j];
4475 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4478 for (j=0; j < 16; j++)
4480 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4481 GetPixelChannels(source));
4482 pixels[j]*=alpha[j];
4483 gamma=1.0/(fabs((double) alpha[j]) <= MagickEpsilon ? 1.0 : alpha[j]);
4484 sum+=gamma*0.0625*pixels[j];
4486 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4490 case BicubicInterpolatePixel:
4499 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4501 if (p == (const Quantum *) NULL)
4506 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4511 channel=GetPixelChannelMapChannel(source,i);
4512 traits=GetPixelChannelMapTraits(source,channel);
4513 destination_traits=GetPixelChannelMapTraits(destination,channel);
4514 if ((traits == UndefinedPixelTrait) ||
4515 (destination_traits == UndefinedPixelTrait))
4517 if ((traits & BlendPixelTrait) == 0)
4518 for (j=0; j < 16; j++)
4521 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4524 for (j=0; j < 16; j++)
4526 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4527 GetPixelChannels(source));
4528 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4532 for (j=0; j < 4; j++)
4534 u[0]=(pixels[4*j+3]-pixels[4*j+2])-(pixels[4*j+0]-pixels[4*j+1]);
4535 u[1]=(pixels[4*j+0]-pixels[4*j+1])-u[0];
4536 u[2]=pixels[4*j+2]-pixels[4*j+0];
4538 v[j]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x*
4541 u[0]=(v[3]-v[2])-(v[0]-v[1]);
4542 u[1]=(v[0]-v[1])-u[0];
4545 SetPixelChannel(destination,channel,ClampToQuantum((delta.y*delta.y*
4546 delta.y*u[0])+(delta.y*delta.y*u[1])+(delta.y*u[2])+u[3]),pixel);
4550 case BilinearInterpolatePixel:
4553 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4554 if (p == (const Quantum *) NULL)
4559 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4565 channel=GetPixelChannelMapChannel(source,i);
4566 traits=GetPixelChannelMapTraits(source,channel);
4567 destination_traits=GetPixelChannelMapTraits(destination,channel);
4568 if ((traits == UndefinedPixelTrait) ||
4569 (destination_traits == UndefinedPixelTrait))
4573 epsilon.x=1.0-delta.x;
4574 epsilon.y=1.0-delta.y;
4575 pixels[0]=(MagickRealType) p[i];
4576 pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i];
4577 pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i];
4578 pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i];
4579 if ((traits & BlendPixelTrait) == 0)
4581 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
4582 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4583 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4584 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*
4585 pixels[2]+delta.x*pixels[3]))),pixel);
4588 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4589 alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source));
4590 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4591 GetPixelChannels(source));
4592 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4593 GetPixelChannels(source));
4594 pixels[0]*=alpha[0];
4595 pixels[1]*=alpha[1];
4596 pixels[2]*=alpha[2];
4597 pixels[3]*=alpha[3];
4598 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4599 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4600 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4601 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4602 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+
4603 delta.x*pixels[3]))),pixel);
4607 case FilterInterpolatePixel:
4609 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4621 channel=GetPixelChannelMapChannel(source,i);
4622 traits=GetPixelChannelMapTraits(source,channel);
4623 destination_traits=GetPixelChannelMapTraits(destination,channel);
4624 if ((traits == UndefinedPixelTrait) ||
4625 (destination_traits == UndefinedPixelTrait))
4629 geometry.x=x_offset-1;
4630 geometry.y=y_offset-1;
4631 excerpt_source=ExcerptImage(source,&geometry,exception);
4632 if (excerpt_source == (Image *) NULL)
4637 filter_source=ResizeImage(excerpt_source,1,1,source->filter,exception);
4638 excerpt_source=DestroyImage(excerpt_source);
4639 if (filter_source == (Image *) NULL)
4641 filter_view=AcquireCacheView(filter_source);
4642 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4643 if (p == (const Quantum *) NULL)
4647 SetPixelChannel(destination,channel,p[i],pixel);
4649 filter_view=DestroyCacheView(filter_view);
4650 filter_source=DestroyImage(filter_source);
4654 case IntegerInterpolatePixel:
4656 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
4657 if (p == (const Quantum *) NULL)
4662 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4664 channel=GetPixelChannelMapChannel(source,i);
4665 traits=GetPixelChannelMapTraits(source,channel);
4666 destination_traits=GetPixelChannelMapTraits(destination,channel);
4667 if ((traits == UndefinedPixelTrait) ||
4668 (destination_traits == UndefinedPixelTrait))
4670 SetPixelChannel(destination,channel,p[i],pixel);
4674 case NearestNeighborInterpolatePixel:
4676 p=GetCacheViewVirtualPixels(source_view,NearestNeighbor(x),
4677 NearestNeighbor(y),1,1,exception);
4678 if (p == (const Quantum *) NULL)
4683 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4685 channel=GetPixelChannelMapChannel(source,i);
4686 traits=GetPixelChannelMapTraits(source,channel);
4687 destination_traits=GetPixelChannelMapTraits(destination,channel);
4688 if ((traits == UndefinedPixelTrait) ||
4689 (destination_traits == UndefinedPixelTrait))
4691 SetPixelChannel(destination,channel,p[i],pixel);
4695 case MeshInterpolatePixel:
4697 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4698 if (p == (const Quantum *) NULL)
4703 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4709 channel=GetPixelChannelMapChannel(source,i);
4710 traits=GetPixelChannelMapTraits(source,channel);
4711 destination_traits=GetPixelChannelMapTraits(destination,channel);
4712 if ((traits == UndefinedPixelTrait) ||
4713 (destination_traits == UndefinedPixelTrait))
4715 pixels[0]=(MagickRealType) p[i];
4716 pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i];
4717 pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i];
4718 pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i];
4719 if ((traits & BlendPixelTrait) == 0)
4728 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4729 alpha[1]=QuantumScale*GetPixelAlpha(source,p+
4730 GetPixelChannels(source));
4731 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4732 GetPixelChannels(source));
4733 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4734 GetPixelChannels(source));
4738 luminance.x=GetPixelLuminance(source,p)-(double)
4739 GetPixelLuminance(source,p+3*GetPixelChannels(source));
4740 luminance.y=GetPixelLuminance(source,p+GetPixelChannels(source))-
4741 (double) GetPixelLuminance(source,p+2*GetPixelChannels(source));
4742 if (fabs(luminance.x) < fabs(luminance.y))
4747 if (delta.x <= delta.y)
4750 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4752 delta.y=1.0-delta.y;
4753 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4754 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4755 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4756 MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel);
4761 Top-right triangle (pixel: 1, diagonal: 0-3).
4763 delta.x=1.0-delta.x;
4764 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4765 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4766 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4767 MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel);
4775 if (delta.x <= (1.0-delta.y))
4778 Top-left triangle (pixel: 0, diagonal: 1-2).
4780 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4781 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4782 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4783 MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel);
4788 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4790 delta.x=1.0-delta.x;
4791 delta.y=1.0-delta.y;
4792 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4793 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4794 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4795 MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel);
4801 case SplineInterpolatePixel:
4803 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4805 if (p == (const Quantum *) NULL)
4810 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4829 channel=GetPixelChannelMapChannel(source,i);
4830 traits=GetPixelChannelMapTraits(source,channel);
4831 destination_traits=GetPixelChannelMapTraits(destination,channel);
4832 if ((traits == UndefinedPixelTrait) ||
4833 (destination_traits == UndefinedPixelTrait))
4835 if ((traits & BlendPixelTrait) == 0)
4836 for (j=0; j < 16; j++)
4839 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4842 for (j=0; j < 16; j++)
4844 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4845 GetPixelChannels(source));
4846 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4852 for (j=(-1); j < 3L; j++)
4854 dy=CubicWeightingFunction((MagickRealType) j-delta.y);
4855 for (k=(-1); k < 3L; k++)
4857 dx=CubicWeightingFunction(delta.x-(MagickRealType) k);
4858 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 :
4860 sum+=gamma*dx*dy*pixels[n];
4864 SetPixelChannel(destination,channel,p[i],pixel);
4873 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4877 % I n t e r p o l a t e P i x e l I n f o %
4881 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4883 % InterpolatePixelInfo() applies a pixel interpolation method between a
4884 % floating point coordinate and the pixels surrounding that coordinate. No
4885 % pixel area resampling, or scaling of the result is performed.
4887 % The format of the InterpolatePixelInfo method is:
4889 % MagickBooleanType InterpolatePixelInfo(const Image *image,
4890 % const CacheView *image_view,const PixelInterpolateMethod method,
4891 % const double x,const double y,PixelInfo *pixel,
4892 % ExceptionInfo *exception)
4894 % A description of each parameter follows:
4896 % o image: the image.
4898 % o image_view: the image view.
4900 % o method: the pixel color interpolation method.
4902 % o x,y: A double representing the current (x,y) position of the pixel.
4904 % o pixel: return the interpolated pixel here.
4906 % o exception: return any errors or warnings in this structure.
4910 static inline void AlphaBlendPixelInfo(const Image *image,
4911 const Quantum *pixel,PixelInfo *pixel_info,MagickRealType *alpha)
4913 if (image->matte == MagickFalse)
4916 pixel_info->red=(MagickRealType) GetPixelRed(image,pixel);
4917 pixel_info->green=(MagickRealType) GetPixelGreen(image,pixel);
4918 pixel_info->blue=(MagickRealType) GetPixelBlue(image,pixel);
4919 pixel_info->black=0.0;
4920 if (image->colorspace == CMYKColorspace)
4921 pixel_info->black=(MagickRealType) GetPixelBlack(image,pixel);
4922 pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
4925 *alpha=QuantumScale*GetPixelAlpha(image,pixel);
4926 pixel_info->red=(*alpha*GetPixelRed(image,pixel));
4927 pixel_info->green=(*alpha*GetPixelGreen(image,pixel));
4928 pixel_info->blue=(*alpha*GetPixelBlue(image,pixel));
4929 pixel_info->black=0.0;
4930 if (image->colorspace == CMYKColorspace)
4931 pixel_info->black=(*alpha*GetPixelBlack(image,pixel));
4932 pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
4935 static void BicubicInterpolate(const PixelInfo *pixels,const double dx,
4946 p=(pixels[3].red-pixels[2].red)-(pixels[0].red-pixels[1].red);
4947 q=(pixels[0].red-pixels[1].red)-p;
4948 r=pixels[2].red-pixels[0].red;
4950 pixel->red=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4951 p=(pixels[3].green-pixels[2].green)-(pixels[0].green-pixels[1].green);
4952 q=(pixels[0].green-pixels[1].green)-p;
4953 r=pixels[2].green-pixels[0].green;
4955 pixel->green=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4956 p=(pixels[3].blue-pixels[2].blue)-(pixels[0].blue-pixels[1].blue);
4957 q=(pixels[0].blue-pixels[1].blue)-p;
4958 r=pixels[2].blue-pixels[0].blue;
4960 pixel->blue=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4961 p=(pixels[3].alpha-pixels[2].alpha)-(pixels[0].alpha-pixels[1].alpha);
4962 q=(pixels[0].alpha-pixels[1].alpha)-p;
4963 r=pixels[2].alpha-pixels[0].alpha;
4965 pixel->alpha=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4966 if (pixel->colorspace == CMYKColorspace)
4968 p=(pixels[3].black-pixels[2].black)-(pixels[0].black-pixels[1].black);
4969 q=(pixels[0].black-pixels[1].black)-p;
4970 r=pixels[2].black-pixels[0].black;
4972 pixel->black=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4976 MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
4977 const CacheView *image_view,const PixelInterpolateMethod method,
4978 const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception)
4990 register const Quantum
5000 assert(image != (Image *) NULL);
5001 assert(image->signature == MagickSignature);
5002 assert(image_view != (CacheView *) NULL);
5004 x_offset=(ssize_t) floor(x);
5005 y_offset=(ssize_t) floor(y);
5006 switch (method == UndefinedInterpolatePixel ? image->interpolate : method)
5008 case AverageInterpolatePixel:
5010 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5012 if (p == (const Quantum *) NULL)
5017 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5018 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5019 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5020 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5021 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
5022 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
5023 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
5024 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
5025 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
5026 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
5027 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
5029 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
5031 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
5033 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
5035 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
5037 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
5044 for (i=0; i < 16L; i++)
5046 gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]);
5047 pixel->red+=gamma*0.0625*pixels[i].red;
5048 pixel->green+=gamma*0.0625*pixels[i].green;
5049 pixel->blue+=gamma*0.0625*pixels[i].blue;
5050 if (image->colorspace == CMYKColorspace)
5051 pixel->black+=gamma*0.0625*pixels[i].black;
5052 pixel->alpha+=0.0625*pixels[i].alpha;
5056 case BicubicInterpolatePixel:
5064 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5066 if (p == (const Quantum *) NULL)
5071 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5072 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5073 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5074 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5075 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
5076 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
5077 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
5078 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
5079 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
5080 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
5081 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
5083 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
5085 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
5087 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
5089 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
5091 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
5095 for (i=0; i < 4L; i++)
5096 BicubicInterpolate(pixels+4*i,delta.x,u+i);
5097 BicubicInterpolate(u,delta.y,pixel);
5100 case BilinearInterpolatePixel:
5107 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5108 if (p == (const Quantum *) NULL)
5113 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5114 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5115 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5116 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5119 epsilon.x=1.0-delta.x;
5120 epsilon.y=1.0-delta.y;
5121 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5122 (epsilon.x*alpha[2]+delta.x*alpha[3])));
5123 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5124 pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
5125 pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red));
5126 pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x*
5127 pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x*
5129 pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x*
5130 pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x*
5132 if (image->colorspace == CMYKColorspace)
5133 pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x*
5134 pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x*
5136 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5137 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5138 pixel->alpha=(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x*
5139 pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x*
5143 case FilterInterpolatePixel:
5157 geometry.x=x_offset-1;
5158 geometry.y=y_offset-1;
5159 excerpt_image=ExcerptImage(image,&geometry,exception);
5160 if (excerpt_image == (Image *) NULL)
5165 filter_image=ResizeImage(excerpt_image,1,1,image->filter,exception);
5166 excerpt_image=DestroyImage(excerpt_image);
5167 if (filter_image == (Image *) NULL)
5169 filter_view=AcquireCacheView(filter_image);
5170 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
5171 if (p != (const Quantum *) NULL)
5172 GetPixelInfoPixel(image,p,pixel);
5173 filter_view=DestroyCacheView(filter_view);
5174 filter_image=DestroyImage(filter_image);
5177 case IntegerInterpolatePixel:
5179 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5180 if (p == (const Quantum *) NULL)
5185 GetPixelInfoPixel(image,p,pixel);
5188 case MeshInterpolatePixel:
5194 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5195 if (p == (const Quantum *) NULL)
5202 luminance.x=GetPixelLuminance(image,p)-(double)
5203 GetPixelLuminance(image,p+3*GetPixelChannels(image));
5204 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
5205 GetPixelLuminance(image,p+2*GetPixelChannels(image));
5206 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5207 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5208 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5209 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5210 if (fabs(luminance.x) < fabs(luminance.y))
5215 if (delta.x <= delta.y)
5218 Bottom-left triangle (pixel: 2, diagonal: 0-3).
5220 delta.y=1.0-delta.y;
5221 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5222 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5223 pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red,
5224 pixels[3].red,pixels[0].red);
5225 pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green,
5226 pixels[3].green,pixels[0].green);
5227 pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
5228 pixels[3].blue,pixels[0].blue);
5229 if (image->colorspace == CMYKColorspace)
5230 pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black,
5231 pixels[3].black,pixels[0].black);
5232 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5233 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha,
5234 pixels[3].alpha,pixels[0].alpha);
5239 Top-right triangle (pixel:1 , diagonal: 0-3).
5241 delta.x=1.0-delta.x;
5242 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5243 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5244 pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red,
5245 pixels[0].red,pixels[3].red);
5246 pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green,
5247 pixels[0].green,pixels[3].green);
5248 pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
5249 pixels[0].blue,pixels[3].blue);
5250 if (image->colorspace == CMYKColorspace)
5251 pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black,
5252 pixels[0].black,pixels[3].black);
5253 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5254 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha,
5255 pixels[0].alpha,pixels[3].alpha);
5263 if (delta.x <= (1.0-delta.y))
5266 Top-left triangle (pixel: 0, diagonal: 1-2).
5268 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5269 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5270 pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red,
5271 pixels[1].red,pixels[2].red);
5272 pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green,
5273 pixels[1].green,pixels[2].green);
5274 pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
5275 pixels[1].blue,pixels[2].blue);
5276 if (image->colorspace == CMYKColorspace)
5277 pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black,
5278 pixels[1].black,pixels[2].black);
5279 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5280 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha,
5281 pixels[1].alpha,pixels[2].alpha);
5286 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5288 delta.x=1.0-delta.x;
5289 delta.y=1.0-delta.y;
5290 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5291 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5292 pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red,
5293 pixels[2].red,pixels[1].red);
5294 pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green,
5295 pixels[2].green,pixels[1].green);
5296 pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
5297 pixels[2].blue,pixels[1].blue);
5298 if (image->colorspace == CMYKColorspace)
5299 pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black,
5300 pixels[2].black,pixels[1].black);
5301 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5302 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha,
5303 pixels[2].alpha,pixels[1].alpha);
5308 case NearestNeighborInterpolatePixel:
5310 p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
5311 NearestNeighbor(y),1,1,exception);
5312 if (p == (const Quantum *) NULL)
5317 GetPixelInfoPixel(image,p,pixel);
5320 case SplineInterpolatePixel:
5333 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5335 if (p == (const Quantum *) NULL)
5340 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5341 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5342 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5343 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5344 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
5345 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
5346 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
5347 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
5348 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
5349 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
5350 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
5352 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
5354 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
5356 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
5358 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
5360 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
5370 for (i=(-1); i < 3L; i++)
5372 dy=CubicWeightingFunction((MagickRealType) i-delta.y);
5373 for (j=(-1); j < 3L; j++)
5375 dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
5376 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]);
5377 pixel->red+=gamma*dx*dy*pixels[n].red;
5378 pixel->green+=gamma*dx*dy*pixels[n].green;
5379 pixel->blue+=gamma*dx*dy*pixels[n].blue;
5380 if (image->colorspace == CMYKColorspace)
5381 pixel->black+=gamma*dx*dy*pixels[n].black;
5382 pixel->alpha+=dx*dy*pixels[n].alpha;
5393 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5397 + I s F u z z y E q u i v a l e n c e P i x e l %
5401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5403 % IsFuzzyEquivalencePixel() returns MagickTrue if the distance between two
5404 % pixels is less than the specified distance in a linear three (or four)u
5405 % dimensional color space.
5407 % The format of the IsFuzzyEquivalencePixel method is:
5409 % void IsFuzzyEquivalencePixel(const Image *source,const Quantum *p,
5410 % const Image *destination,const Quantum *q)
5412 % A description of each parameter follows:
5414 % o source: the source image.
5418 % o destination: the destination image.
5423 MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *source,
5424 const Quantum *p,const Image *destination,const Quantum *q)
5430 register MagickRealType
5434 fuzz=MagickMax(source->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(
5435 destination->fuzz,(MagickRealType) MagickSQ1_2);
5438 if (source->matte != MagickFalse)
5441 Transparencies are involved - set alpha distance
5443 pixel=GetPixelAlpha(source,p)-(MagickRealType)
5444 GetPixelAlpha(destination,q);
5445 distance=pixel*pixel;
5446 if (distance > fuzz)
5447 return(MagickFalse);
5449 Generate a alpha scaling factor to generate a 4D cone on colorspace
5450 Note that if one color is transparent, distance has no color component.
5452 scale=QuantumScale*GetPixelAlpha(source,p);
5453 scale*=QuantumScale*GetPixelAlpha(destination,q);
5454 if (scale <= MagickEpsilon)
5458 RGB or CMY color cube
5460 distance*=3.0; /* rescale appropriately */
5462 pixel=GetPixelRed(source,p)-(MagickRealType) GetPixelRed(destination,q);
5463 if ((source->colorspace == HSLColorspace) ||
5464 (source->colorspace == HSBColorspace) ||
5465 (source->colorspace == HWBColorspace))
5468 Compute an arc distance for hue. It should be a vector angle of
5469 'S'/'W' length with 'L'/'B' forming appropriate cones.
5471 if (fabs((double) pixel) > (QuantumRange/2))
5472 pixel-=QuantumRange;
5475 distance+=scale*pixel*pixel;
5476 if (distance > fuzz)
5477 return(MagickFalse);
5478 pixel=GetPixelGreen(source,p)-(MagickRealType) GetPixelGreen(destination,q);
5479 distance+=scale*pixel*pixel;
5480 if (distance > fuzz)
5481 return(MagickFalse);
5482 pixel=GetPixelBlue(source,p)-(MagickRealType) GetPixelBlue(destination,q);
5483 distance+=scale*pixel*pixel;
5484 if (distance > fuzz)
5485 return(MagickFalse);
5490 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5494 + I s F u z z y E q u i v a l e n c e P i x e l I n f o %
5498 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5500 % IsFuzzyEquivalencePixelInfo() returns true if the distance between two
5501 % colors is less than the specified distance in a linear three (or four)
5502 % dimensional color space.
5504 % This implements the equivalent of:
5505 % fuzz < sqrt(color_distance^2 * u.a*v.a + alpha_distance^2)
5507 % Which produces a multi-dimensional cone for that colorspace along the
5508 % transparency vector.
5510 % For example for an RGB:
5511 % color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3
5513 % See http://www.imagemagick.org/Usage/bugs/fuzz_distance/
5515 % Hue colorspace distances need more work. Hue is not a distance, it is an
5518 % A check that q is in the same color space as p should be made and the
5519 % appropriate mapping made. -- Anthony Thyssen 8 December 2010
5521 % The format of the IsFuzzyEquivalencePixelInfo method is:
5523 % MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5524 % const PixelInfo *q)
5526 % A description of each parameter follows:
5533 MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5540 register MagickRealType
5544 if ((p->fuzz == 0.0) && (q->fuzz == 0.0))
5545 return(IsPixelInfoEquivalent(p,q));
5547 fuzz=MagickMax(q->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz,
5548 (MagickRealType) MagickSQ1_2);
5549 else if (q->fuzz == 0.0)
5550 fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(p->fuzz,
5551 (MagickRealType) MagickSQ1_2);
5553 fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz,
5554 (MagickRealType) MagickSQ1_2);
5557 if ((p->matte != MagickFalse) || (q->matte != MagickFalse))
5560 Transparencies are involved - set alpha distance.
5562 pixel=(p->matte != MagickFalse ? p->alpha : OpaqueAlpha)-
5563 (q->matte != MagickFalse ? q->alpha : OpaqueAlpha);
5564 distance=pixel*pixel;
5565 if (distance > fuzz)
5566 return(MagickFalse);
5568 Generate a alpha scaling factor to generate a 4D cone on colorspace.
5569 If one color is transparent, distance has no color component.
5571 if (p->matte != MagickFalse)
5572 scale=(QuantumScale*p->alpha);
5573 if (q->matte != MagickFalse)
5574 scale*=(QuantumScale*q->alpha);
5575 if (scale <= MagickEpsilon )
5579 CMYK create a CMY cube with a multi-dimensional cone toward black.
5581 if (p->colorspace == CMYKColorspace)
5583 pixel=p->black-q->black;
5584 distance+=pixel*pixel*scale;
5585 if (distance > fuzz)
5586 return(MagickFalse);
5587 scale*=(MagickRealType) (QuantumScale*(QuantumRange-p->black));
5588 scale*=(MagickRealType) (QuantumScale*(QuantumRange-q->black));
5591 RGB or CMY color cube.
5593 distance*=3.0; /* rescale appropriately */
5595 pixel=p->red-q->red;
5596 if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) ||
5597 (p->colorspace == HWBColorspace))
5600 This calculates a arc distance for hue-- it should be a vector angle
5601 of 'S'/'W' length with 'L'/'B' forming appropriate cones. In other
5602 words this is a hack - Anthony.
5604 if (fabs((double) pixel) > (QuantumRange/2))
5605 pixel-=QuantumRange;
5608 distance+=pixel*pixel*scale;
5609 if (distance > fuzz)
5610 return(MagickFalse);
5611 pixel=p->green-q->green;
5612 distance+=pixel*pixel*scale;
5613 if (distance > fuzz)
5614 return(MagickFalse);
5615 pixel=p->blue-q->blue;
5616 distance+=pixel*pixel*scale;
5617 if (distance > fuzz)
5618 return(MagickFalse);
5623 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5627 % S e t P i x e l C h a n n e l M a p M a s k %
5631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5633 % SetPixelChannelMapMask() sets the pixel channel map from the specified
5636 % The format of the SetPixelChannelMapMask method is:
5638 % void SetPixelChannelMapMask(Image *image,const ChannelType channel_mask)
5640 % A description of each parameter follows:
5642 % o image: the image.
5644 % o channel_mask: the channel mask.
5647 MagickExport void SetPixelChannelMapMask(Image *image,
5648 const ChannelType channel_mask)
5650 #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
5655 image->channel_mask=channel_mask;
5656 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5661 channel=GetPixelChannelMapChannel(image,i);
5662 SetPixelChannelMapTraits(image,channel,
5663 GetChannelBit(channel_mask,channel) == 0 ? CopyPixelTrait :
5664 image->matte == MagickFalse || (channel == AlphaPixelChannel) ?
5665 UpdatePixelTrait : (PixelTrait) (UpdatePixelTrait | BlendPixelTrait));
5667 if (image->storage_class == PseudoClass)
5668 SetPixelChannelMapTraits(image,IndexPixelChannel,CopyPixelTrait);
5669 if (image->mask != MagickFalse)
5670 SetPixelChannelMapTraits(image,MaskPixelChannel,CopyPixelTrait);
5671 if (image->debug != MagickFalse)
5672 LogPixelChannels(image);
5676 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5680 % S e t P i x e l C h a n n e l M a s k %
5684 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5686 % SetPixelChannelMask() sets the pixel channel mask from the specified channel
5689 % The format of the SetPixelChannelMask method is:
5691 % ChannelType SetPixelChannelMask(Image *image,
5692 % const ChannelType channel_mask)
5694 % A description of each parameter follows:
5696 % o image: the image.
5698 % o channel_mask: the channel mask.
5701 MagickExport ChannelType SetPixelChannelMask(Image *image,
5702 const ChannelType channel_mask)
5707 mask=image->channel_mask;
5708 image->channel_mask=channel_mask;
5709 SetPixelChannelMapMask(image,channel_mask);
5714 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5718 % S e t P i x e l M e t a C h a n n e l s %
5722 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5724 % SetPixelMetaChannels() sets the image meta channels.
5726 % The format of the SetPixelMetaChannels method is:
5728 % MagickBooleanType SetPixelMetaChannels(Image *image,
5729 % const size_t number_meta_channels,ExceptionInfo *exception)
5731 % A description of each parameter follows:
5733 % o image: the image.
5735 % o number_meta_channels: the number of meta channels.
5737 % o exception: return any errors or warnings in this structure.
5740 MagickExport MagickBooleanType SetPixelMetaChannels(Image *image,
5741 const size_t number_meta_channels,ExceptionInfo *exception)
5743 image->number_meta_channels=number_meta_channels;
5744 return(SyncImagePixelCache(image,exception));