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/pixel-private.h"
63 #include "MagickCore/quantum.h"
64 #include "MagickCore/quantum-private.h"
65 #include "MagickCore/resource_.h"
66 #include "MagickCore/semaphore.h"
67 #include "MagickCore/statistic.h"
68 #include "MagickCore/stream.h"
69 #include "MagickCore/string_.h"
70 #include "MagickCore/transform.h"
71 #include "MagickCore/utility.h"
73 #define LogPixelChannels(image) \
78 (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%.20g]", \
79 image->filename,(double) image->number_channels); \
80 for (i=0; i < (ssize_t) image->number_channels; i++) \
83 traits[MaxTextExtent]; \
91 switch (GetPixelChannelMapChannel(image,i)) \
93 case RedPixelChannel: \
96 if (image->colorspace == CMYKColorspace) \
98 if (image->colorspace == GRAYColorspace) \
102 case GreenPixelChannel: \
105 if (image->colorspace == CMYKColorspace) \
109 case BluePixelChannel: \
112 if (image->colorspace == CMYKColorspace) \
116 case BlackPixelChannel: \
119 if (image->storage_class == PseudoClass) \
123 case IndexPixelChannel: \
128 case AlphaPixelChannel: \
133 case MaskPixelChannel: \
138 case MetaPixelChannel: \
146 channel=GetPixelChannelMapChannel(image,i); \
148 if ((GetPixelChannelMapTraits(image,channel) & UpdatePixelTrait) != 0) \
149 (void) ConcatenateMagickString(traits,"update,",MaxTextExtent); \
150 if ((GetPixelChannelMapTraits(image,channel) & BlendPixelTrait) != 0) \
151 (void) ConcatenateMagickString(traits,"blend,",MaxTextExtent); \
152 if ((GetPixelChannelMapTraits(image,channel) & CopyPixelTrait) != 0) \
153 (void) ConcatenateMagickString(traits,"copy,",MaxTextExtent); \
154 if (*traits == '\0') \
155 (void) ConcatenateMagickString(traits,"undefined,",MaxTextExtent); \
156 traits[strlen(traits)-1]='\0'; \
157 (void) LogMagickEvent(PixelEvent,GetMagickModule()," %.20g: %s (%s)", \
158 (double) i,name,traits); \
163 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
167 + A c q u i r e P i x e l C h a n n e l M a p %
171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173 % AcquirePixelChannelMap() acquires a pixel component map.
175 % The format of the AcquirePixelChannelMap() method is:
177 % PixelChannelMap *AcquirePixelChannelMap(void)
180 MagickExport PixelChannelMap *AcquirePixelChannelMap(void)
188 channel_map=(PixelChannelMap *) AcquireQuantumMemory(MaxPixelChannels,
189 sizeof(*channel_map));
190 if (channel_map == (PixelChannelMap *) NULL)
191 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
192 (void) ResetMagickMemory(channel_map,0,MaxPixelChannels*sizeof(*channel_map));
193 for (i=0; i < MaxPixelChannels; i++)
194 channel_map[i].channel=(PixelChannel) i;
199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 + C l o n e P i x e l C h a n n e l M a p %
207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209 % ClonePixelChannelMap() clones a pixel component map.
211 % The format of the ClonePixelChannelMap() method is:
213 % PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
215 % A description of each parameter follows:
217 % o channel_map: the pixel component map.
220 MagickExport PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
225 assert(channel_map != (PixelChannelMap *) NULL);
226 clone_map=AcquirePixelChannelMap();
227 if (clone_map == (PixelChannelMap *) NULL)
228 return((PixelChannelMap *) NULL);
229 (void) CopyMagickMemory(clone_map,channel_map,MaxPixelChannels*
230 sizeof(*channel_map));
235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239 + C l o n e P i x e l I n f o %
243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
245 % ClonePixelInfo() makes a duplicate of the given pixel info structure, or if
246 % pixel info is NULL, a new one.
248 % The format of the ClonePixelInfo method is:
250 % PixelInfo *ClonePixelInfo(const PixelInfo *pixel_info)
252 % A description of each parameter follows:
254 % o pixel_info: the pixel info.
257 MagickExport PixelInfo *ClonePixelInfo(const PixelInfo *pixel)
262 pixel_info=(PixelInfo *) AcquireQuantumMemory(1,sizeof(*pixel_info));
263 if (pixel_info == (PixelInfo *) NULL)
264 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
265 *pixel_info=(*pixel);
270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
274 + D e s t r o y P i x e l C h a n n e l M a p %
278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280 % DestroyPixelChannelMap() deallocates memory associated with the pixel
283 % The format of the DestroyPixelChannelMap() method is:
285 % PixelChannelMap *DestroyPixelChannelMap(PixelChannelMap *channel_map)
287 % A description of each parameter follows:
289 % o channel_map: the pixel component map.
292 MagickExport PixelChannelMap *DestroyPixelChannelMap(
293 PixelChannelMap *channel_map)
295 assert(channel_map != (PixelChannelMap *) NULL);
296 channel_map=(PixelChannelMap *) RelinquishMagickMemory(channel_map);
297 return((PixelChannelMap *) RelinquishMagickMemory(channel_map));
301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
305 % E x p o r t I m a g e P i x e l s %
309 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
311 % ExportImagePixels() extracts pixel data from an image and returns it to you.
312 % The method returns MagickTrue on success otherwise MagickFalse if an error is
313 % encountered. The data is returned as char, short int, Quantum, unsigned int,
314 % unsigned long long, float, or double in the order specified by map.
316 % Suppose you want to extract the first scanline of a 640x480 image as
317 % character data in red-green-blue order:
319 % ExportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels,exception);
321 % The format of the ExportImagePixels method is:
323 % MagickBooleanType ExportImagePixels(const Image *image,const ssize_t x,
324 % const ssize_t y,const size_t width,const size_t height,
325 % const char *map,const StorageType type,void *pixels,
326 % ExceptionInfo *exception)
328 % A description of each parameter follows:
330 % o image: the image.
332 % o x,y,width,height: These values define the perimeter
333 % of a region of pixels you want to extract.
335 % o map: This string reflects the expected ordering of the pixel array.
336 % It can be any combination or order of R = red, G = green, B = blue,
337 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
338 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
341 % o type: Define the data type of the pixels. Float and double types are
342 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
343 % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *),
344 % LongPixel (unsigned int *), LongLongPixel (unsigned long long *),
345 % QuantumPixel (Quantum *), or ShortPixel (unsigned short *).
347 % o pixels: This array of values contain the pixel components as defined by
348 % map and type. You must preallocate this array where the expected
349 % length varies depending on the values of width, height, map, and type.
351 % o exception: return any errors or warnings in this structure.
355 static void ExportCharPixel(const Image *image,const RectangleInfo *roi,
356 const char *restrict map,const QuantumType *quantum_map,void *pixels,
357 ExceptionInfo *exception)
359 register const Quantum
365 register unsigned char
374 q=(unsigned char *) pixels;
375 if (LocaleCompare(map,"BGR") == 0)
377 for (y=0; y < (ssize_t) roi->height; y++)
379 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
380 if (p == (const Quantum *) NULL)
382 for (x=0; x < (ssize_t) roi->width; x++)
384 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
385 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
386 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
387 p+=GetPixelChannels(image);
392 if (LocaleCompare(map,"BGRA") == 0)
394 for (y=0; y < (ssize_t) roi->height; y++)
396 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
397 if (p == (const Quantum *) NULL)
399 for (x=0; x < (ssize_t) roi->width; x++)
401 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
402 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
403 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
404 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
405 p+=GetPixelChannels(image);
410 if (LocaleCompare(map,"BGRP") == 0)
412 for (y=0; y < (ssize_t) roi->height; y++)
414 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
415 if (p == (const Quantum *) NULL)
417 for (x=0; x < (ssize_t) roi->width; x++)
419 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
420 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
421 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
422 *q++=ScaleQuantumToChar((Quantum) 0);
423 p+=GetPixelChannels(image);
428 if (LocaleCompare(map,"I") == 0)
430 for (y=0; y < (ssize_t) roi->height; y++)
432 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
433 if (p == (const Quantum *) NULL)
435 for (x=0; x < (ssize_t) roi->width; x++)
437 *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
438 p+=GetPixelChannels(image);
443 if (LocaleCompare(map,"RGB") == 0)
445 for (y=0; y < (ssize_t) roi->height; y++)
447 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
448 if (p == (const Quantum *) NULL)
450 for (x=0; x < (ssize_t) roi->width; x++)
452 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
453 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
454 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
455 p+=GetPixelChannels(image);
460 if (LocaleCompare(map,"RGBA") == 0)
462 for (y=0; y < (ssize_t) roi->height; y++)
464 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
465 if (p == (const Quantum *) NULL)
467 for (x=0; x < (ssize_t) roi->width; x++)
469 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
470 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
471 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
472 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
473 p+=GetPixelChannels(image);
478 if (LocaleCompare(map,"RGBP") == 0)
480 for (y=0; y < (ssize_t) roi->height; y++)
482 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
483 if (p == (const Quantum *) NULL)
485 for (x=0; x < (ssize_t) roi->width; x++)
487 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
488 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
489 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
490 *q++=ScaleQuantumToChar((Quantum) 0);
491 p+=GetPixelChannels(image);
497 for (y=0; y < (ssize_t) roi->height; y++)
499 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
500 if (p == (const Quantum *) NULL)
502 for (x=0; x < (ssize_t) roi->width; x++)
507 for (i=0; i < (ssize_t) length; i++)
510 switch (quantum_map[i])
515 *q=ScaleQuantumToChar(GetPixelRed(image,p));
521 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
527 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
532 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
537 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
542 if (image->colorspace == CMYKColorspace)
543 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
548 *q=ScaleQuantumToChar(GetPixelIntensity(image,p));
556 p+=GetPixelChannels(image);
561 static void ExportDoublePixel(const Image *image,const RectangleInfo *roi,
562 const char *restrict map,const QuantumType *quantum_map,void *pixels,
563 ExceptionInfo *exception)
565 register const Quantum
581 if (LocaleCompare(map,"BGR") == 0)
583 for (y=0; y < (ssize_t) roi->height; y++)
585 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
586 if (p == (const Quantum *) NULL)
588 for (x=0; x < (ssize_t) roi->width; x++)
590 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
591 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
592 *q++=(double) (QuantumScale*GetPixelRed(image,p));
593 p+=GetPixelChannels(image);
598 if (LocaleCompare(map,"BGRA") == 0)
600 for (y=0; y < (ssize_t) roi->height; y++)
602 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
603 if (p == (const Quantum *) NULL)
605 for (x=0; x < (ssize_t) roi->width; x++)
607 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
608 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
609 *q++=(double) (QuantumScale*GetPixelRed(image,p));
610 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
611 p+=GetPixelChannels(image);
616 if (LocaleCompare(map,"BGRP") == 0)
618 for (y=0; y < (ssize_t) roi->height; y++)
620 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
621 if (p == (const Quantum *) NULL)
623 for (x=0; x < (ssize_t) roi->width; x++)
625 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
626 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
627 *q++=(double) (QuantumScale*GetPixelRed(image,p));
629 p+=GetPixelChannels(image);
634 if (LocaleCompare(map,"I") == 0)
636 for (y=0; y < (ssize_t) roi->height; y++)
638 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
639 if (p == (const Quantum *) NULL)
641 for (x=0; x < (ssize_t) roi->width; x++)
643 *q++=(double) (QuantumScale*GetPixelIntensity(image,p));
644 p+=GetPixelChannels(image);
649 if (LocaleCompare(map,"RGB") == 0)
651 for (y=0; y < (ssize_t) roi->height; y++)
653 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
654 if (p == (const Quantum *) NULL)
656 for (x=0; x < (ssize_t) roi->width; x++)
658 *q++=(double) (QuantumScale*GetPixelRed(image,p));
659 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
660 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
661 p+=GetPixelChannels(image);
666 if (LocaleCompare(map,"RGBA") == 0)
668 for (y=0; y < (ssize_t) roi->height; y++)
670 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
671 if (p == (const Quantum *) NULL)
673 for (x=0; x < (ssize_t) roi->width; x++)
675 *q++=(double) (QuantumScale*GetPixelRed(image,p));
676 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
677 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
678 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
679 p+=GetPixelChannels(image);
684 if (LocaleCompare(map,"RGBP") == 0)
686 for (y=0; y < (ssize_t) roi->height; y++)
688 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
689 if (p == (const Quantum *) NULL)
691 for (x=0; x < (ssize_t) roi->width; x++)
693 *q++=(double) (QuantumScale*GetPixelRed(image,p));
694 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
695 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
697 p+=GetPixelChannels(image);
703 for (y=0; y < (ssize_t) roi->height; y++)
705 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
706 if (p == (const Quantum *) NULL)
708 for (x=0; x < (ssize_t) roi->width; x++)
713 for (i=0; i < (ssize_t) length; i++)
716 switch (quantum_map[i])
721 *q=(double) (QuantumScale*GetPixelRed(image,p));
727 *q=(double) (QuantumScale*GetPixelGreen(image,p));
733 *q=(double) (QuantumScale*GetPixelBlue(image,p));
738 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
743 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
748 if (image->colorspace == CMYKColorspace)
749 *q=(double) (QuantumScale*
750 GetPixelBlack(image,p));
755 *q=(double) (QuantumScale*GetPixelIntensity(image,p));
763 p+=GetPixelChannels(image);
768 static void ExportFloatPixel(const Image *image,const RectangleInfo *roi,
769 const char *restrict map,const QuantumType *quantum_map,void *pixels,
770 ExceptionInfo *exception)
772 register const Quantum
788 if (LocaleCompare(map,"BGR") == 0)
790 for (y=0; y < (ssize_t) roi->height; y++)
792 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
793 if (p == (const Quantum *) NULL)
795 for (x=0; x < (ssize_t) roi->width; x++)
797 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
798 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
799 *q++=(float) (QuantumScale*GetPixelRed(image,p));
800 p+=GetPixelChannels(image);
805 if (LocaleCompare(map,"BGRA") == 0)
807 for (y=0; y < (ssize_t) roi->height; y++)
809 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
810 if (p == (const Quantum *) NULL)
812 for (x=0; x < (ssize_t) roi->width; x++)
814 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
815 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
816 *q++=(float) (QuantumScale*GetPixelRed(image,p));
817 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
818 p+=GetPixelChannels(image);
823 if (LocaleCompare(map,"BGRP") == 0)
825 for (y=0; y < (ssize_t) roi->height; y++)
827 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
828 if (p == (const Quantum *) NULL)
830 for (x=0; x < (ssize_t) roi->width; x++)
832 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
833 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
834 *q++=(float) (QuantumScale*GetPixelRed(image,p));
836 p+=GetPixelChannels(image);
841 if (LocaleCompare(map,"I") == 0)
843 for (y=0; y < (ssize_t) roi->height; y++)
845 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
846 if (p == (const Quantum *) NULL)
848 for (x=0; x < (ssize_t) roi->width; x++)
850 *q++=(float) (QuantumScale*GetPixelIntensity(image,p));
851 p+=GetPixelChannels(image);
856 if (LocaleCompare(map,"RGB") == 0)
858 for (y=0; y < (ssize_t) roi->height; y++)
860 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
861 if (p == (const Quantum *) NULL)
863 for (x=0; x < (ssize_t) roi->width; x++)
865 *q++=(float) (QuantumScale*GetPixelRed(image,p));
866 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
867 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
868 p+=GetPixelChannels(image);
873 if (LocaleCompare(map,"RGBA") == 0)
875 for (y=0; y < (ssize_t) roi->height; y++)
877 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
878 if (p == (const Quantum *) NULL)
880 for (x=0; x < (ssize_t) roi->width; x++)
882 *q++=(float) (QuantumScale*GetPixelRed(image,p));
883 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
884 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
885 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
886 p+=GetPixelChannels(image);
891 if (LocaleCompare(map,"RGBP") == 0)
893 for (y=0; y < (ssize_t) roi->height; y++)
895 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
896 if (p == (const Quantum *) NULL)
898 for (x=0; x < (ssize_t) roi->width; x++)
900 *q++=(float) (QuantumScale*GetPixelRed(image,p));
901 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
902 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
904 p+=GetPixelChannels(image);
910 for (y=0; y < (ssize_t) roi->height; y++)
912 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
913 if (p == (const Quantum *) NULL)
915 for (x=0; x < (ssize_t) roi->width; x++)
920 for (i=0; i < (ssize_t) length; i++)
923 switch (quantum_map[i])
928 *q=(float) (QuantumScale*GetPixelRed(image,p));
934 *q=(float) (QuantumScale*GetPixelGreen(image,p));
940 *q=(float) (QuantumScale*GetPixelBlue(image,p));
945 *q=(float) (QuantumScale*((Quantum) (GetPixelAlpha(image,p))));
950 *q=(float) (QuantumScale*GetPixelAlpha(image,p));
955 if (image->colorspace == CMYKColorspace)
956 *q=(float) (QuantumScale* GetPixelBlack(image,p));
961 *q=(float) (QuantumScale*GetPixelIntensity(image,p));
969 p+=GetPixelChannels(image);
974 static void ExportLongPixel(const Image *image,const RectangleInfo *roi,
975 const char *restrict map,const QuantumType *quantum_map,void *pixels,
976 ExceptionInfo *exception)
978 register const Quantum
984 register unsigned int
993 q=(unsigned int *) pixels;
994 if (LocaleCompare(map,"BGR") == 0)
996 for (y=0; y < (ssize_t) roi->height; y++)
998 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
999 if (p == (const Quantum *) NULL)
1001 for (x=0; x < (ssize_t) roi->width; x++)
1003 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1004 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1005 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1006 p+=GetPixelChannels(image);
1011 if (LocaleCompare(map,"BGRA") == 0)
1013 for (y=0; y < (ssize_t) roi->height; y++)
1015 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1016 if (p == (const Quantum *) NULL)
1018 for (x=0; x < (ssize_t) roi->width; x++)
1020 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1021 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1022 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1023 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1024 p+=GetPixelChannels(image);
1029 if (LocaleCompare(map,"BGRP") == 0)
1031 for (y=0; y < (ssize_t) roi->height; y++)
1033 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1034 if (p == (const Quantum *) NULL)
1036 for (x=0; x < (ssize_t) roi->width; x++)
1038 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1039 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1040 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1042 p+=GetPixelChannels(image);
1047 if (LocaleCompare(map,"I") == 0)
1049 for (y=0; y < (ssize_t) roi->height; y++)
1051 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1052 if (p == (const Quantum *) NULL)
1054 for (x=0; x < (ssize_t) roi->width; x++)
1056 *q++=ScaleQuantumToLong(GetPixelIntensity(image,p));
1057 p+=GetPixelChannels(image);
1062 if (LocaleCompare(map,"RGB") == 0)
1064 for (y=0; y < (ssize_t) roi->height; y++)
1066 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1067 if (p == (const Quantum *) NULL)
1069 for (x=0; x < (ssize_t) roi->width; x++)
1071 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1072 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1073 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1074 p+=GetPixelChannels(image);
1079 if (LocaleCompare(map,"RGBA") == 0)
1081 for (y=0; y < (ssize_t) roi->height; y++)
1083 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1084 if (p == (const Quantum *) NULL)
1086 for (x=0; x < (ssize_t) roi->width; x++)
1088 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1089 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1090 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1091 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1092 p+=GetPixelChannels(image);
1097 if (LocaleCompare(map,"RGBP") == 0)
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++)
1106 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1107 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1108 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1110 p+=GetPixelChannels(image);
1116 for (y=0; y < (ssize_t) roi->height; y++)
1118 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1119 if (p == (const Quantum *) NULL)
1121 for (x=0; x < (ssize_t) roi->width; x++)
1126 for (i=0; i < (ssize_t) length; i++)
1129 switch (quantum_map[i])
1134 *q=ScaleQuantumToLong(GetPixelRed(image,p));
1138 case MagentaQuantum:
1140 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
1146 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
1151 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1154 case OpacityQuantum:
1156 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1161 if (image->colorspace == CMYKColorspace)
1162 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
1167 *q=ScaleQuantumToLong(GetPixelIntensity(image,p));
1175 p+=GetPixelChannels(image);
1180 static void ExportLongLongPixel(const Image *image,const RectangleInfo *roi,
1181 const char *restrict map,const QuantumType *quantum_map,void *pixels,
1182 ExceptionInfo *exception)
1184 register const Quantum
1190 register MagickSizeType
1199 q=(MagickSizeType *) pixels;
1200 if (LocaleCompare(map,"BGR") == 0)
1202 for (y=0; y < (ssize_t) roi->height; y++)
1204 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1205 if (p == (const Quantum *) NULL)
1207 for (x=0; x < (ssize_t) roi->width; x++)
1209 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1210 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1211 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1212 p+=GetPixelChannels(image);
1217 if (LocaleCompare(map,"BGRA") == 0)
1219 for (y=0; y < (ssize_t) roi->height; y++)
1221 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1222 if (p == (const Quantum *) NULL)
1224 for (x=0; x < (ssize_t) roi->width; x++)
1226 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1227 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1228 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1229 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1230 p+=GetPixelChannels(image);
1235 if (LocaleCompare(map,"BGRP") == 0)
1237 for (y=0; y < (ssize_t) roi->height; y++)
1239 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1240 if (p == (const Quantum *) NULL)
1242 for (x=0; x < (ssize_t) roi->width; x++)
1244 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1245 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1246 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1248 p+=GetPixelChannels(image);
1253 if (LocaleCompare(map,"I") == 0)
1255 for (y=0; y < (ssize_t) roi->height; y++)
1257 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1258 if (p == (const Quantum *) NULL)
1260 for (x=0; x < (ssize_t) roi->width; x++)
1262 *q++=ScaleQuantumToLongLong(GetPixelIntensity(image,p));
1263 p+=GetPixelChannels(image);
1268 if (LocaleCompare(map,"RGB") == 0)
1270 for (y=0; y < (ssize_t) roi->height; y++)
1272 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1273 if (p == (const Quantum *) NULL)
1275 for (x=0; x < (ssize_t) roi->width; x++)
1277 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1278 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1279 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1280 p+=GetPixelChannels(image);
1285 if (LocaleCompare(map,"RGBA") == 0)
1287 for (y=0; y < (ssize_t) roi->height; y++)
1289 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1290 if (p == (const Quantum *) NULL)
1292 for (x=0; x < (ssize_t) roi->width; x++)
1294 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1295 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1296 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1297 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1298 p+=GetPixelChannels(image);
1303 if (LocaleCompare(map,"RGBP") == 0)
1305 for (y=0; y < (ssize_t) roi->height; y++)
1307 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1308 if (p == (const Quantum *) NULL)
1310 for (x=0; x < (ssize_t) roi->width; x++)
1312 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1313 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1314 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1316 p+=GetPixelChannels(image);
1322 for (y=0; y < (ssize_t) roi->height; y++)
1324 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1325 if (p == (const Quantum *) NULL)
1327 for (x=0; x < (ssize_t) roi->width; x++)
1332 for (i=0; i < (ssize_t) length; i++)
1335 switch (quantum_map[i])
1340 *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
1344 case MagentaQuantum:
1346 *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1352 *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1357 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1360 case OpacityQuantum:
1362 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1367 if (image->colorspace == CMYKColorspace)
1368 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
1373 *q=ScaleQuantumToLongLong(GetPixelIntensity(image,p));
1381 p+=GetPixelChannels(image);
1386 static void ExportQuantumPixel(const Image *image,const RectangleInfo *roi,
1387 const char *restrict map,const QuantumType *quantum_map,void *pixels,
1388 ExceptionInfo *exception)
1390 register const Quantum
1405 q=(Quantum *) pixels;
1406 if (LocaleCompare(map,"BGR") == 0)
1408 for (y=0; y < (ssize_t) roi->height; y++)
1410 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1411 if (p == (const Quantum *) NULL)
1413 for (x=0; x < (ssize_t) roi->width; x++)
1415 *q++=GetPixelBlue(image,p);
1416 *q++=GetPixelGreen(image,p);
1417 *q++=GetPixelRed(image,p);
1418 p+=GetPixelChannels(image);
1423 if (LocaleCompare(map,"BGRA") == 0)
1425 for (y=0; y < (ssize_t) roi->height; y++)
1427 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1428 if (p == (const Quantum *) NULL)
1430 for (x=0; x < (ssize_t) roi->width; x++)
1432 *q++=GetPixelBlue(image,p);
1433 *q++=GetPixelGreen(image,p);
1434 *q++=GetPixelRed(image,p);
1435 *q++=(Quantum) (GetPixelAlpha(image,p));
1436 p+=GetPixelChannels(image);
1441 if (LocaleCompare(map,"BGRP") == 0)
1443 for (y=0; y < (ssize_t) roi->height; y++)
1445 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1446 if (p == (const Quantum *) NULL)
1448 for (x=0; x < (ssize_t) roi->width; x++)
1450 *q++=GetPixelBlue(image,p);
1451 *q++=GetPixelGreen(image,p);
1452 *q++=GetPixelRed(image,p);
1454 p+=GetPixelChannels(image);
1459 if (LocaleCompare(map,"I") == 0)
1461 for (y=0; y < (ssize_t) roi->height; y++)
1463 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1464 if (p == (const Quantum *) NULL)
1466 for (x=0; x < (ssize_t) roi->width; x++)
1468 *q++=GetPixelIntensity(image,p);
1469 p+=GetPixelChannels(image);
1474 if (LocaleCompare(map,"RGB") == 0)
1476 for (y=0; y < (ssize_t) roi->height; y++)
1478 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1479 if (p == (const Quantum *) NULL)
1481 for (x=0; x < (ssize_t) roi->width; x++)
1483 *q++=GetPixelRed(image,p);
1484 *q++=GetPixelGreen(image,p);
1485 *q++=GetPixelBlue(image,p);
1486 p+=GetPixelChannels(image);
1491 if (LocaleCompare(map,"RGBA") == 0)
1493 for (y=0; y < (ssize_t) roi->height; y++)
1495 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1496 if (p == (const Quantum *) NULL)
1498 for (x=0; x < (ssize_t) roi->width; x++)
1500 *q++=GetPixelRed(image,p);
1501 *q++=GetPixelGreen(image,p);
1502 *q++=GetPixelBlue(image,p);
1503 *q++=(Quantum) (GetPixelAlpha(image,p));
1504 p+=GetPixelChannels(image);
1509 if (LocaleCompare(map,"RGBP") == 0)
1511 for (y=0; y < (ssize_t) roi->height; y++)
1513 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1514 if (p == (const Quantum *) NULL)
1516 for (x=0; x < (ssize_t) roi->width; x++)
1518 *q++=GetPixelRed(image,p);
1519 *q++=GetPixelGreen(image,p);
1520 *q++=GetPixelBlue(image,p);
1522 p+=GetPixelChannels(image);
1528 for (y=0; y < (ssize_t) roi->height; y++)
1530 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1531 if (p == (const Quantum *) NULL)
1533 for (x=0; x < (ssize_t) roi->width; x++)
1538 for (i=0; i < (ssize_t) length; i++)
1541 switch (quantum_map[i])
1546 *q=GetPixelRed(image,p);
1550 case MagentaQuantum:
1552 *q=GetPixelGreen(image,p);
1558 *q=GetPixelBlue(image,p);
1563 *q=GetPixelAlpha(image,p);
1566 case OpacityQuantum:
1568 *q=GetPixelAlpha(image,p);
1573 if (image->colorspace == CMYKColorspace)
1574 *q=GetPixelBlack(image,p);
1579 *q=(GetPixelIntensity(image,p));
1590 p+=GetPixelChannels(image);
1595 static void ExportShortPixel(const Image *image,const RectangleInfo *roi,
1596 const char *restrict map,const QuantumType *quantum_map,void *pixels,
1597 ExceptionInfo *exception)
1599 register const Quantum
1605 register unsigned short
1614 q=(unsigned short *) pixels;
1615 if (LocaleCompare(map,"BGR") == 0)
1617 for (y=0; y < (ssize_t) roi->height; y++)
1619 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1620 if (p == (const Quantum *) NULL)
1622 for (x=0; x < (ssize_t) roi->width; x++)
1624 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1625 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1626 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1627 p+=GetPixelChannels(image);
1632 if (LocaleCompare(map,"BGRA") == 0)
1634 for (y=0; y < (ssize_t) roi->height; y++)
1636 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1637 if (p == (const Quantum *) NULL)
1639 for (x=0; x < (ssize_t) roi->width; x++)
1641 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1642 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1643 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1644 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1645 p+=GetPixelChannels(image);
1650 if (LocaleCompare(map,"BGRP") == 0)
1652 for (y=0; y < (ssize_t) roi->height; y++)
1654 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1655 if (p == (const Quantum *) NULL)
1657 for (x=0; x < (ssize_t) roi->width; x++)
1659 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1660 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1661 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1663 p+=GetPixelChannels(image);
1668 if (LocaleCompare(map,"I") == 0)
1670 for (y=0; y < (ssize_t) roi->height; y++)
1672 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1673 if (p == (const Quantum *) NULL)
1675 for (x=0; x < (ssize_t) roi->width; x++)
1677 *q++=ScaleQuantumToShort(GetPixelIntensity(image,p));
1678 p+=GetPixelChannels(image);
1683 if (LocaleCompare(map,"RGB") == 0)
1685 for (y=0; y < (ssize_t) roi->height; y++)
1687 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1688 if (p == (const Quantum *) NULL)
1690 for (x=0; x < (ssize_t) roi->width; x++)
1692 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1693 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1694 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1695 p+=GetPixelChannels(image);
1700 if (LocaleCompare(map,"RGBA") == 0)
1702 for (y=0; y < (ssize_t) roi->height; y++)
1704 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1705 if (p == (const Quantum *) NULL)
1707 for (x=0; x < (ssize_t) roi->width; x++)
1709 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1710 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1711 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1712 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1713 p+=GetPixelChannels(image);
1718 if (LocaleCompare(map,"RGBP") == 0)
1720 for (y=0; y < (ssize_t) roi->height; y++)
1722 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1723 if (p == (const Quantum *) NULL)
1725 for (x=0; x < (ssize_t) roi->width; x++)
1727 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1728 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1729 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1731 p+=GetPixelChannels(image);
1737 for (y=0; y < (ssize_t) roi->height; y++)
1739 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1740 if (p == (const Quantum *) NULL)
1742 for (x=0; x < (ssize_t) roi->width; x++)
1747 for (i=0; i < (ssize_t) length; i++)
1750 switch (quantum_map[i])
1755 *q=ScaleQuantumToShort(GetPixelRed(image,p));
1759 case MagentaQuantum:
1761 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
1767 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
1772 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1775 case OpacityQuantum:
1777 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1782 if (image->colorspace == CMYKColorspace)
1783 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
1788 *q=ScaleQuantumToShort(GetPixelIntensity(image,p));
1796 p+=GetPixelChannels(image);
1801 MagickExport MagickBooleanType ExportImagePixels(const Image *image,
1802 const ssize_t x,const ssize_t y,const size_t width,const size_t height,
1803 const char *map,const StorageType type,void *pixels,ExceptionInfo *exception)
1817 assert(image != (Image *) NULL);
1818 assert(image->signature == MagickSignature);
1819 if (image->debug != MagickFalse)
1820 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1822 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1823 if (quantum_map == (QuantumType *) NULL)
1825 (void) ThrowMagickException(exception,GetMagickModule(),
1826 ResourceLimitError,"MemoryAllocationFailed","'%s'",image->filename);
1827 return(MagickFalse);
1829 for (i=0; i < (ssize_t) length; i++)
1836 quantum_map[i]=AlphaQuantum;
1842 quantum_map[i]=BlueQuantum;
1848 quantum_map[i]=CyanQuantum;
1849 if (image->colorspace == CMYKColorspace)
1851 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1852 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1853 "ColorSeparatedImageRequired","'%s'",map);
1854 return(MagickFalse);
1859 quantum_map[i]=GreenQuantum;
1865 quantum_map[i]=IndexQuantum;
1871 quantum_map[i]=BlackQuantum;
1872 if (image->colorspace == CMYKColorspace)
1874 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1875 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1876 "ColorSeparatedImageRequired","'%s'",map);
1877 return(MagickFalse);
1882 quantum_map[i]=MagentaQuantum;
1883 if (image->colorspace == CMYKColorspace)
1885 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1886 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1887 "ColorSeparatedImageRequired","'%s'",map);
1888 return(MagickFalse);
1893 quantum_map[i]=OpacityQuantum;
1899 quantum_map[i]=UndefinedQuantum;
1905 quantum_map[i]=RedQuantum;
1911 quantum_map[i]=YellowQuantum;
1912 if (image->colorspace == CMYKColorspace)
1914 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1915 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1916 "ColorSeparatedImageRequired","'%s'",map);
1917 return(MagickFalse);
1921 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1922 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1923 "UnrecognizedPixelMap","'%s'",map);
1924 return(MagickFalse);
1936 ExportCharPixel(image,&roi,map,quantum_map,pixels,exception);
1941 ExportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
1946 ExportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
1951 ExportLongPixel(image,&roi,map,quantum_map,pixels,exception);
1956 ExportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
1961 ExportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
1966 ExportShortPixel(image,&roi,map,quantum_map,pixels,exception);
1971 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1972 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1973 "UnrecognizedPixelMap","'%s'",map);
1977 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1982 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1986 % G e t P i x e l I n f o %
1990 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1992 % GetPixelInfo() initializes the PixelInfo structure.
1994 % The format of the GetPixelInfo method is:
1996 % GetPixelInfo(const Image *image,PixelInfo *pixel)
1998 % A description of each parameter follows:
2000 % o image: the image.
2002 % o pixel: Specifies a pointer to a PixelInfo structure.
2005 MagickExport void GetPixelInfo(const Image *image,PixelInfo *pixel)
2007 pixel->storage_class=DirectClass;
2008 pixel->colorspace=sRGBColorspace;
2009 pixel->matte=MagickFalse;
2011 pixel->depth=MAGICKCORE_QUANTUM_DEPTH;
2016 pixel->alpha=(MagickRealType) OpaqueAlpha;
2018 if (image == (const Image *) NULL)
2020 pixel->storage_class=image->storage_class;
2021 pixel->colorspace=image->colorspace;
2022 pixel->matte=image->matte;
2023 pixel->depth=image->depth;
2024 pixel->fuzz=image->fuzz;
2028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2032 % I m p o r t I m a g e P i x e l s %
2036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2038 % ImportImagePixels() accepts pixel data and stores in the image at the
2039 % location you specify. The method returns MagickTrue on success otherwise
2040 % MagickFalse if an error is encountered. The pixel data can be either char,
2041 % Quantum, short int, unsigned int, unsigned long long, float, or double in
2042 % the order specified by map.
2044 % Suppose your want to upload the first scanline of a 640x480 image from
2045 % character data in red-green-blue order:
2047 % ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels);
2049 % The format of the ImportImagePixels method is:
2051 % MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
2052 % const ssize_t y,const size_t width,const size_t height,
2053 % const char *map,const StorageType type,const void *pixels,
2054 % ExceptionInfo *exception)
2056 % A description of each parameter follows:
2058 % o image: the image.
2060 % o x,y,width,height: These values define the perimeter
2061 % of a region of pixels you want to define.
2063 % o map: This string reflects the expected ordering of the pixel array.
2064 % It can be any combination or order of R = red, G = green, B = blue,
2065 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
2066 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
2069 % o type: Define the data type of the pixels. Float and double types are
2070 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
2071 % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *),
2072 % LongPixel (unsigned int *), LongLongPixel (unsigned long long *),
2073 % QuantumPixel (Quantum *), or ShortPixel (unsigned short *).
2075 % o pixels: This array of values contain the pixel components as defined by
2076 % map and type. You must preallocate this array where the expected
2077 % length varies depending on the values of width, height, map, and type.
2079 % o exception: return any errors or warnings in this structure.
2083 static void ImportCharPixel(Image *image,const RectangleInfo *roi,
2084 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2085 ExceptionInfo *exception)
2087 register const unsigned char
2102 p=(const unsigned char *) pixels;
2103 if (LocaleCompare(map,"BGR") == 0)
2105 for (y=0; y < (ssize_t) roi->height; y++)
2107 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2108 if (q == (Quantum *) NULL)
2110 for (x=0; x < (ssize_t) roi->width; x++)
2112 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2113 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2114 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2115 q+=GetPixelChannels(image);
2117 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2122 if (LocaleCompare(map,"BGRA") == 0)
2124 for (y=0; y < (ssize_t) roi->height; y++)
2126 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2127 if (q == (Quantum *) NULL)
2129 for (x=0; x < (ssize_t) roi->width; x++)
2131 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2132 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2133 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2134 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2135 q+=GetPixelChannels(image);
2137 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2142 if (LocaleCompare(map,"BGRO") == 0)
2144 for (y=0; y < (ssize_t) roi->height; y++)
2146 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2147 if (q == (Quantum *) NULL)
2149 for (x=0; x < (ssize_t) roi->width; x++)
2151 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2152 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2153 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2154 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2155 q+=GetPixelChannels(image);
2157 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2162 if (LocaleCompare(map,"BGRP") == 0)
2164 for (y=0; y < (ssize_t) roi->height; y++)
2166 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2167 if (q == (Quantum *) NULL)
2169 for (x=0; x < (ssize_t) roi->width; x++)
2171 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2172 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2173 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2175 q+=GetPixelChannels(image);
2177 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2182 if (LocaleCompare(map,"I") == 0)
2184 for (y=0; y < (ssize_t) roi->height; y++)
2186 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2187 if (q == (Quantum *) NULL)
2189 for (x=0; x < (ssize_t) roi->width; x++)
2191 SetPixelGray(image,ScaleCharToQuantum(*p++),q);
2192 q+=GetPixelChannels(image);
2194 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2199 if (LocaleCompare(map,"RGB") == 0)
2201 for (y=0; y < (ssize_t) roi->height; y++)
2203 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2204 if (q == (Quantum *) NULL)
2206 for (x=0; x < (ssize_t) roi->width; x++)
2208 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2209 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2210 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2211 q+=GetPixelChannels(image);
2213 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2218 if (LocaleCompare(map,"RGBA") == 0)
2220 for (y=0; y < (ssize_t) roi->height; y++)
2222 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2223 if (q == (Quantum *) NULL)
2225 for (x=0; x < (ssize_t) roi->width; x++)
2227 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2228 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2229 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2230 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2231 q+=GetPixelChannels(image);
2233 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2238 if (LocaleCompare(map,"RGBO") == 0)
2240 for (y=0; y < (ssize_t) roi->height; y++)
2242 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2243 if (q == (Quantum *) NULL)
2245 for (x=0; x < (ssize_t) roi->width; x++)
2247 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2248 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2249 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2250 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2251 q+=GetPixelChannels(image);
2253 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2258 if (LocaleCompare(map,"RGBP") == 0)
2260 for (y=0; y < (ssize_t) roi->height; y++)
2262 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2263 if (q == (Quantum *) NULL)
2265 for (x=0; x < (ssize_t) roi->width; x++)
2267 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2268 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2269 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2271 q+=GetPixelChannels(image);
2273 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2279 for (y=0; y < (ssize_t) roi->height; y++)
2281 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2282 if (q == (Quantum *) NULL)
2284 for (x=0; x < (ssize_t) roi->width; x++)
2289 for (i=0; i < (ssize_t) length; i++)
2291 switch (quantum_map[i])
2296 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2300 case MagentaQuantum:
2302 SetPixelGreen(image,ScaleCharToQuantum(*p),q);
2308 SetPixelBlue(image,ScaleCharToQuantum(*p),q);
2313 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2316 case OpacityQuantum:
2318 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2323 SetPixelBlack(image,ScaleCharToQuantum(*p),q);
2328 SetPixelGray(image,ScaleCharToQuantum(*p),q);
2336 q+=GetPixelChannels(image);
2338 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2343 static void ImportDoublePixel(Image *image,const RectangleInfo *roi,
2344 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2345 ExceptionInfo *exception)
2347 register const double
2362 p=(const double *) pixels;
2363 if (LocaleCompare(map,"BGR") == 0)
2365 for (y=0; y < (ssize_t) roi->height; y++)
2367 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2368 if (q == (Quantum *) NULL)
2370 for (x=0; x < (ssize_t) roi->width; x++)
2372 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2375 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2378 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2381 q+=GetPixelChannels(image);
2383 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2388 if (LocaleCompare(map,"BGRA") == 0)
2390 for (y=0; y < (ssize_t) roi->height; y++)
2392 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2393 if (q == (Quantum *) NULL)
2395 for (x=0; x < (ssize_t) roi->width; x++)
2397 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2400 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2403 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2406 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2409 q+=GetPixelChannels(image);
2411 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2416 if (LocaleCompare(map,"BGRP") == 0)
2418 for (y=0; y < (ssize_t) roi->height; y++)
2420 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2421 if (q == (Quantum *) NULL)
2423 for (x=0; x < (ssize_t) roi->width; x++)
2425 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2428 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2431 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2435 q+=GetPixelChannels(image);
2437 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2442 if (LocaleCompare(map,"I") == 0)
2444 for (y=0; y < (ssize_t) roi->height; y++)
2446 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2447 if (q == (Quantum *) NULL)
2449 for (x=0; x < (ssize_t) roi->width; x++)
2451 SetPixelGray(image,ClampToQuantum((MagickRealType) QuantumRange*
2454 q+=GetPixelChannels(image);
2456 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2461 if (LocaleCompare(map,"RGB") == 0)
2463 for (y=0; y < (ssize_t) roi->height; y++)
2465 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2466 if (q == (Quantum *) NULL)
2468 for (x=0; x < (ssize_t) roi->width; x++)
2470 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2473 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2476 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2479 q+=GetPixelChannels(image);
2481 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2486 if (LocaleCompare(map,"RGBA") == 0)
2488 for (y=0; y < (ssize_t) roi->height; y++)
2490 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2491 if (q == (Quantum *) NULL)
2493 for (x=0; x < (ssize_t) roi->width; x++)
2495 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2498 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2501 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2504 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2507 q+=GetPixelChannels(image);
2509 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2514 if (LocaleCompare(map,"RGBP") == 0)
2516 for (y=0; y < (ssize_t) roi->height; y++)
2518 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2519 if (q == (Quantum *) NULL)
2521 for (x=0; x < (ssize_t) roi->width; x++)
2523 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2526 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2529 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2532 q+=GetPixelChannels(image);
2534 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2540 for (y=0; y < (ssize_t) roi->height; y++)
2542 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2543 if (q == (Quantum *) NULL)
2545 for (x=0; x < (ssize_t) roi->width; x++)
2550 for (i=0; i < (ssize_t) length; i++)
2552 switch (quantum_map[i])
2557 SetPixelRed(image,ClampToQuantum((MagickRealType)
2558 QuantumRange*(*p)),q);
2562 case MagentaQuantum:
2564 SetPixelGreen(image,ClampToQuantum((MagickRealType)
2565 QuantumRange*(*p)),q);
2571 SetPixelBlue(image,ClampToQuantum((MagickRealType)
2572 QuantumRange*(*p)),q);
2577 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2578 QuantumRange*(*p)),q);
2581 case OpacityQuantum:
2583 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2584 QuantumRange*(*p)),q);
2589 SetPixelBlack(image,ClampToQuantum((MagickRealType)
2590 QuantumRange*(*p)),q);
2595 SetPixelGray(image,ClampToQuantum((MagickRealType)
2596 QuantumRange*(*p)),q);
2604 q+=GetPixelChannels(image);
2606 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2611 static void ImportFloatPixel(Image *image,const RectangleInfo *roi,
2612 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2613 ExceptionInfo *exception)
2615 register const float
2630 p=(const float *) pixels;
2631 if (LocaleCompare(map,"BGR") == 0)
2633 for (y=0; y < (ssize_t) roi->height; y++)
2635 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2636 if (q == (Quantum *) NULL)
2638 for (x=0; x < (ssize_t) roi->width; x++)
2640 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2643 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2646 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2649 q+=GetPixelChannels(image);
2651 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2656 if (LocaleCompare(map,"BGRA") == 0)
2658 for (y=0; y < (ssize_t) roi->height; y++)
2660 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2661 if (q == (Quantum *) NULL)
2663 for (x=0; x < (ssize_t) roi->width; x++)
2665 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2668 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2671 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2674 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2677 q+=GetPixelChannels(image);
2679 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2684 if (LocaleCompare(map,"BGRP") == 0)
2686 for (y=0; y < (ssize_t) roi->height; y++)
2688 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2689 if (q == (Quantum *) NULL)
2691 for (x=0; x < (ssize_t) roi->width; x++)
2693 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2696 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2699 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2703 q+=GetPixelChannels(image);
2705 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2710 if (LocaleCompare(map,"I") == 0)
2712 for (y=0; y < (ssize_t) roi->height; y++)
2714 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2715 if (q == (Quantum *) NULL)
2717 for (x=0; x < (ssize_t) roi->width; x++)
2719 SetPixelGray(image,ClampToQuantum((MagickRealType) QuantumRange*
2722 q+=GetPixelChannels(image);
2724 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2729 if (LocaleCompare(map,"RGB") == 0)
2731 for (y=0; y < (ssize_t) roi->height; y++)
2733 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2734 if (q == (Quantum *) NULL)
2736 for (x=0; x < (ssize_t) roi->width; x++)
2738 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2741 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2744 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2747 q+=GetPixelChannels(image);
2749 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2754 if (LocaleCompare(map,"RGBA") == 0)
2756 for (y=0; y < (ssize_t) roi->height; y++)
2758 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2759 if (q == (Quantum *) NULL)
2761 for (x=0; x < (ssize_t) roi->width; x++)
2763 SetPixelRed(image,ClampToQuantum((MagickRealType)
2764 QuantumRange*(*p)),q);
2766 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2769 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2772 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2775 q+=GetPixelChannels(image);
2777 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2782 if (LocaleCompare(map,"RGBP") == 0)
2784 for (y=0; y < (ssize_t) roi->height; y++)
2786 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2787 if (q == (Quantum *) NULL)
2789 for (x=0; x < (ssize_t) roi->width; x++)
2791 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2794 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2797 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2800 q+=GetPixelChannels(image);
2802 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2808 for (y=0; y < (ssize_t) roi->height; y++)
2810 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2811 if (q == (Quantum *) NULL)
2813 for (x=0; x < (ssize_t) roi->width; x++)
2818 for (i=0; i < (ssize_t) length; i++)
2820 switch (quantum_map[i])
2825 SetPixelRed(image,ClampToQuantum((MagickRealType)
2826 QuantumRange*(*p)),q);
2830 case MagentaQuantum:
2832 SetPixelGreen(image,ClampToQuantum((MagickRealType)
2833 QuantumRange*(*p)),q);
2839 SetPixelBlue(image,ClampToQuantum((MagickRealType)
2840 QuantumRange*(*p)),q);
2845 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2846 QuantumRange*(*p)),q);
2849 case OpacityQuantum:
2851 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2852 QuantumRange*(*p)),q);
2857 SetPixelBlack(image,ClampToQuantum((MagickRealType)
2858 QuantumRange*(*p)),q);
2863 SetPixelGray(image,ClampToQuantum((MagickRealType)
2864 QuantumRange*(*p)),q);
2872 q+=GetPixelChannels(image);
2874 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2879 static void ImportLongPixel(Image *image,const RectangleInfo *roi,
2880 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2881 ExceptionInfo *exception)
2883 register const unsigned int
2898 p=(const unsigned int *) pixels;
2899 if (LocaleCompare(map,"BGR") == 0)
2901 for (y=0; y < (ssize_t) roi->height; y++)
2903 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2904 if (q == (Quantum *) NULL)
2906 for (x=0; x < (ssize_t) roi->width; x++)
2908 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2909 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2910 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2911 q+=GetPixelChannels(image);
2913 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2918 if (LocaleCompare(map,"BGRA") == 0)
2920 for (y=0; y < (ssize_t) roi->height; y++)
2922 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2923 if (q == (Quantum *) NULL)
2925 for (x=0; x < (ssize_t) roi->width; x++)
2927 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2928 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2929 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2930 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
2931 q+=GetPixelChannels(image);
2933 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2938 if (LocaleCompare(map,"BGRP") == 0)
2940 for (y=0; y < (ssize_t) roi->height; y++)
2942 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2943 if (q == (Quantum *) NULL)
2945 for (x=0; x < (ssize_t) roi->width; x++)
2947 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2948 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2949 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2951 q+=GetPixelChannels(image);
2953 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2958 if (LocaleCompare(map,"I") == 0)
2960 for (y=0; y < (ssize_t) roi->height; y++)
2962 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2963 if (q == (Quantum *) NULL)
2965 for (x=0; x < (ssize_t) roi->width; x++)
2967 SetPixelGray(image,ScaleLongToQuantum(*p++),q);
2968 q+=GetPixelChannels(image);
2970 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2975 if (LocaleCompare(map,"RGB") == 0)
2977 for (y=0; y < (ssize_t) roi->height; y++)
2979 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2980 if (q == (Quantum *) NULL)
2982 for (x=0; x < (ssize_t) roi->width; x++)
2984 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2985 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2986 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2987 q+=GetPixelChannels(image);
2989 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2994 if (LocaleCompare(map,"RGBA") == 0)
2996 for (y=0; y < (ssize_t) roi->height; y++)
2998 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2999 if (q == (Quantum *) NULL)
3001 for (x=0; x < (ssize_t) roi->width; x++)
3003 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3004 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3005 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3006 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3007 q+=GetPixelChannels(image);
3009 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3014 if (LocaleCompare(map,"RGBP") == 0)
3016 for (y=0; y < (ssize_t) roi->height; y++)
3018 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3019 if (q == (Quantum *) NULL)
3021 for (x=0; x < (ssize_t) roi->width; x++)
3023 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3024 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3025 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3027 q+=GetPixelChannels(image);
3029 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3035 for (y=0; y < (ssize_t) roi->height; y++)
3037 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3038 if (q == (Quantum *) NULL)
3040 for (x=0; x < (ssize_t) roi->width; x++)
3045 for (i=0; i < (ssize_t) length; i++)
3047 switch (quantum_map[i])
3052 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3056 case MagentaQuantum:
3058 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
3064 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
3069 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3072 case OpacityQuantum:
3074 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3079 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
3084 SetPixelGray(image,ScaleLongToQuantum(*p),q);
3092 q+=GetPixelChannels(image);
3094 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3099 static void ImportLongLongPixel(Image *image,const RectangleInfo *roi,
3100 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3101 ExceptionInfo *exception)
3103 register const MagickSizeType
3118 p=(const MagickSizeType *) pixels;
3119 if (LocaleCompare(map,"BGR") == 0)
3121 for (y=0; y < (ssize_t) roi->height; y++)
3123 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3124 if (q == (Quantum *) NULL)
3126 for (x=0; x < (ssize_t) roi->width; x++)
3128 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3129 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3130 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3131 q+=GetPixelChannels(image);
3133 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3138 if (LocaleCompare(map,"BGRA") == 0)
3140 for (y=0; y < (ssize_t) roi->height; y++)
3142 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3143 if (q == (Quantum *) NULL)
3145 for (x=0; x < (ssize_t) roi->width; x++)
3147 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3148 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3149 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3150 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3151 q+=GetPixelChannels(image);
3153 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3158 if (LocaleCompare(map,"BGRP") == 0)
3160 for (y=0; y < (ssize_t) roi->height; y++)
3162 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3163 if (q == (Quantum *) NULL)
3165 for (x=0; x < (ssize_t) roi->width; x++)
3167 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3168 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3169 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3171 q+=GetPixelChannels(image);
3173 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3178 if (LocaleCompare(map,"I") == 0)
3180 for (y=0; y < (ssize_t) roi->height; y++)
3182 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3183 if (q == (Quantum *) NULL)
3185 for (x=0; x < (ssize_t) roi->width; x++)
3187 SetPixelGray(image,ScaleLongLongToQuantum(*p++),q);
3188 q+=GetPixelChannels(image);
3190 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3195 if (LocaleCompare(map,"RGB") == 0)
3197 for (y=0; y < (ssize_t) roi->height; y++)
3199 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3200 if (q == (Quantum *) NULL)
3202 for (x=0; x < (ssize_t) roi->width; x++)
3204 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3205 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3206 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3207 q+=GetPixelChannels(image);
3209 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3214 if (LocaleCompare(map,"RGBA") == 0)
3216 for (y=0; y < (ssize_t) roi->height; y++)
3218 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3219 if (q == (Quantum *) NULL)
3221 for (x=0; x < (ssize_t) roi->width; x++)
3223 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3224 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3225 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3226 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3227 q+=GetPixelChannels(image);
3229 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3234 if (LocaleCompare(map,"RGBP") == 0)
3236 for (y=0; y < (ssize_t) roi->height; y++)
3238 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3239 if (q == (Quantum *) NULL)
3241 for (x=0; x < (ssize_t) roi->width; x++)
3243 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3244 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3245 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3247 q+=GetPixelChannels(image);
3249 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3255 for (y=0; y < (ssize_t) roi->height; y++)
3257 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3258 if (q == (Quantum *) NULL)
3260 for (x=0; x < (ssize_t) roi->width; x++)
3265 for (i=0; i < (ssize_t) length; i++)
3267 switch (quantum_map[i])
3272 SetPixelRed(image,ScaleLongLongToQuantum(*p),q);
3276 case MagentaQuantum:
3278 SetPixelGreen(image,ScaleLongLongToQuantum(*p),q);
3284 SetPixelBlue(image,ScaleLongLongToQuantum(*p),q);
3289 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3292 case OpacityQuantum:
3294 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3299 SetPixelBlack(image,ScaleLongLongToQuantum(*p),q);
3304 SetPixelGray(image,ScaleLongLongToQuantum(*p),q);
3312 q+=GetPixelChannels(image);
3314 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3319 static void ImportQuantumPixel(Image *image,const RectangleInfo *roi,
3320 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3321 ExceptionInfo *exception)
3323 register const Quantum
3338 p=(const Quantum *) pixels;
3339 if (LocaleCompare(map,"BGR") == 0)
3341 for (y=0; y < (ssize_t) roi->height; y++)
3343 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3344 if (q == (Quantum *) NULL)
3346 for (x=0; x < (ssize_t) roi->width; x++)
3348 SetPixelBlue(image,*p++,q);
3349 SetPixelGreen(image,*p++,q);
3350 SetPixelRed(image,*p++,q);
3351 q+=GetPixelChannels(image);
3353 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3358 if (LocaleCompare(map,"BGRA") == 0)
3360 for (y=0; y < (ssize_t) roi->height; y++)
3362 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3363 if (q == (Quantum *) NULL)
3365 for (x=0; x < (ssize_t) roi->width; x++)
3367 SetPixelBlue(image,*p++,q);
3368 SetPixelGreen(image,*p++,q);
3369 SetPixelRed(image,*p++,q);
3370 SetPixelAlpha(image,*p++,q);
3371 q+=GetPixelChannels(image);
3373 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3378 if (LocaleCompare(map,"BGRP") == 0)
3380 for (y=0; y < (ssize_t) roi->height; y++)
3382 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3383 if (q == (Quantum *) NULL)
3385 for (x=0; x < (ssize_t) roi->width; x++)
3387 SetPixelBlue(image,*p++,q);
3388 SetPixelGreen(image,*p++,q);
3389 SetPixelRed(image,*p++,q);
3391 q+=GetPixelChannels(image);
3393 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3398 if (LocaleCompare(map,"I") == 0)
3400 for (y=0; y < (ssize_t) roi->height; y++)
3402 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3403 if (q == (Quantum *) NULL)
3405 for (x=0; x < (ssize_t) roi->width; x++)
3407 SetPixelGray(image,*p++,q);
3408 q+=GetPixelChannels(image);
3410 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3415 if (LocaleCompare(map,"RGB") == 0)
3417 for (y=0; y < (ssize_t) roi->height; y++)
3419 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3420 if (q == (Quantum *) NULL)
3422 for (x=0; x < (ssize_t) roi->width; x++)
3424 SetPixelRed(image,*p++,q);
3425 SetPixelGreen(image,*p++,q);
3426 SetPixelBlue(image,*p++,q);
3427 q+=GetPixelChannels(image);
3429 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3434 if (LocaleCompare(map,"RGBA") == 0)
3436 for (y=0; y < (ssize_t) roi->height; y++)
3438 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3439 if (q == (Quantum *) NULL)
3441 for (x=0; x < (ssize_t) roi->width; x++)
3443 SetPixelRed(image,*p++,q);
3444 SetPixelGreen(image,*p++,q);
3445 SetPixelBlue(image,*p++,q);
3446 SetPixelAlpha(image,*p++,q);
3447 q+=GetPixelChannels(image);
3449 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3454 if (LocaleCompare(map,"RGBP") == 0)
3456 for (y=0; y < (ssize_t) roi->height; y++)
3458 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3459 if (q == (Quantum *) NULL)
3461 for (x=0; x < (ssize_t) roi->width; x++)
3463 SetPixelRed(image,*p++,q);
3464 SetPixelGreen(image,*p++,q);
3465 SetPixelBlue(image,*p++,q);
3467 q+=GetPixelChannels(image);
3469 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3475 for (y=0; y < (ssize_t) roi->height; y++)
3477 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3478 if (q == (Quantum *) NULL)
3480 for (x=0; x < (ssize_t) roi->width; x++)
3485 for (i=0; i < (ssize_t) length; i++)
3487 switch (quantum_map[i])
3492 SetPixelRed(image,*p,q);
3496 case MagentaQuantum:
3498 SetPixelGreen(image,*p,q);
3504 SetPixelBlue(image,*p,q);
3509 SetPixelAlpha(image,*p,q);
3512 case OpacityQuantum:
3514 SetPixelAlpha(image,*p,q);
3519 SetPixelBlack(image,*p,q);
3524 SetPixelGray(image,*p,q);
3532 q+=GetPixelChannels(image);
3534 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3539 static void ImportShortPixel(Image *image,const RectangleInfo *roi,
3540 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3541 ExceptionInfo *exception)
3543 register const unsigned short
3558 p=(const unsigned short *) pixels;
3559 if (LocaleCompare(map,"BGR") == 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 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3569 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3570 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3571 q+=GetPixelChannels(image);
3573 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3578 if (LocaleCompare(map,"BGRA") == 0)
3580 for (y=0; y < (ssize_t) roi->height; y++)
3582 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3583 if (q == (Quantum *) NULL)
3585 for (x=0; x < (ssize_t) roi->width; x++)
3587 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3588 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3589 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3590 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3591 q+=GetPixelChannels(image);
3593 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3598 if (LocaleCompare(map,"BGRP") == 0)
3600 for (y=0; y < (ssize_t) roi->height; y++)
3602 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3603 if (q == (Quantum *) NULL)
3605 for (x=0; x < (ssize_t) roi->width; x++)
3607 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3608 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3609 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3611 q+=GetPixelChannels(image);
3613 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3618 if (LocaleCompare(map,"I") == 0)
3620 for (y=0; y < (ssize_t) roi->height; y++)
3622 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3623 if (q == (Quantum *) NULL)
3625 for (x=0; x < (ssize_t) roi->width; x++)
3627 SetPixelGray(image,ScaleShortToQuantum(*p++),q);
3628 q+=GetPixelChannels(image);
3630 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3635 if (LocaleCompare(map,"RGB") == 0)
3637 for (y=0; y < (ssize_t) roi->height; y++)
3639 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3640 if (q == (Quantum *) NULL)
3642 for (x=0; x < (ssize_t) roi->width; x++)
3644 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3645 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3646 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3647 q+=GetPixelChannels(image);
3649 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3654 if (LocaleCompare(map,"RGBA") == 0)
3656 for (y=0; y < (ssize_t) roi->height; y++)
3658 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3659 if (q == (Quantum *) NULL)
3661 for (x=0; x < (ssize_t) roi->width; x++)
3663 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3664 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3665 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3666 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3667 q+=GetPixelChannels(image);
3669 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3674 if (LocaleCompare(map,"RGBP") == 0)
3676 for (y=0; y < (ssize_t) roi->height; y++)
3678 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3679 if (q == (Quantum *) NULL)
3681 for (x=0; x < (ssize_t) roi->width; x++)
3683 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3684 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3685 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3687 q+=GetPixelChannels(image);
3689 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3695 for (y=0; y < (ssize_t) roi->height; y++)
3697 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3698 if (q == (Quantum *) NULL)
3700 for (x=0; x < (ssize_t) roi->width; x++)
3705 for (i=0; i < (ssize_t) length; i++)
3707 switch (quantum_map[i])
3712 SetPixelRed(image,ScaleShortToQuantum(*p),q);
3716 case MagentaQuantum:
3718 SetPixelGreen(image,ScaleShortToQuantum(*p),q);
3724 SetPixelBlue(image,ScaleShortToQuantum(*p),q);
3729 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3732 case OpacityQuantum:
3734 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3739 SetPixelBlack(image,ScaleShortToQuantum(*p),q);
3744 SetPixelGray(image,ScaleShortToQuantum(*p),q);
3752 q+=GetPixelChannels(image);
3754 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3759 MagickExport MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
3760 const ssize_t y,const size_t width,const size_t height,const char *map,
3761 const StorageType type,const void *pixels,ExceptionInfo *exception)
3776 Allocate image structure.
3778 assert(image != (Image *) NULL);
3779 assert(image->signature == MagickSignature);
3780 if (image->debug != MagickFalse)
3781 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3783 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
3784 if (quantum_map == (QuantumType *) NULL)
3785 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
3787 for (i=0; i < (ssize_t) length; i++)
3794 quantum_map[i]=AlphaQuantum;
3795 image->matte=MagickTrue;
3801 quantum_map[i]=BlueQuantum;
3807 quantum_map[i]=CyanQuantum;
3808 (void) SetImageColorspace(image,CMYKColorspace,exception);
3814 quantum_map[i]=GreenQuantum;
3820 quantum_map[i]=BlackQuantum;
3821 (void) SetImageColorspace(image,CMYKColorspace,exception);
3827 quantum_map[i]=IndexQuantum;
3833 quantum_map[i]=MagentaQuantum;
3834 (void) SetImageColorspace(image,CMYKColorspace,exception);
3840 quantum_map[i]=OpacityQuantum;
3841 image->matte=MagickTrue;
3847 quantum_map[i]=UndefinedQuantum;
3853 quantum_map[i]=RedQuantum;
3859 quantum_map[i]=YellowQuantum;
3860 (void) SetImageColorspace(image,CMYKColorspace,exception);
3865 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3866 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3867 "UnrecognizedPixelMap","'%s'",map);
3868 return(MagickFalse);
3872 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
3873 return(MagickFalse);
3875 Transfer the pixels from the pixel data to the image.
3885 ImportCharPixel(image,&roi,map,quantum_map,pixels,exception);
3890 ImportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
3895 ImportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
3900 ImportLongPixel(image,&roi,map,quantum_map,pixels,exception);
3905 ImportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
3910 ImportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
3915 ImportShortPixel(image,&roi,map,quantum_map,pixels,exception);
3920 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3921 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3922 "UnrecognizedPixelMap","'%s'",map);
3926 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3931 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3935 + 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 %
3939 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3941 % InitializePixelChannelMap() defines the standard pixel component map.
3943 % The format of the InitializePixelChannelMap() method is:
3945 % void InitializePixelChannelMap(Image *image)
3947 % A description of each parameter follows:
3949 % o image: the image.
3952 MagickExport void InitializePixelChannelMap(Image *image)
3963 assert(image != (Image *) NULL);
3964 assert(image->signature == MagickSignature);
3965 (void) ResetMagickMemory(image->channel_map,0,MaxPixelChannels*
3966 sizeof(*image->channel_map));
3967 trait=UpdatePixelTrait;
3968 if (image->matte != MagickFalse)
3969 trait=(PixelTrait) (trait | BlendPixelTrait);
3971 if (image->colorspace == GRAYColorspace)
3973 SetPixelChannelMap(image,BluePixelChannel,trait,n);
3974 SetPixelChannelMap(image,GreenPixelChannel,trait,n);
3975 SetPixelChannelMap(image,RedPixelChannel,trait,n++);
3979 SetPixelChannelMap(image,RedPixelChannel,trait,n++);
3980 SetPixelChannelMap(image,GreenPixelChannel,trait,n++);
3981 SetPixelChannelMap(image,BluePixelChannel,trait,n++);
3983 if (image->colorspace == CMYKColorspace)
3984 SetPixelChannelMap(image,BlackPixelChannel,trait,n++);
3985 if (image->matte != MagickFalse)
3986 SetPixelChannelMap(image,AlphaPixelChannel,CopyPixelTrait,n++);
3987 if (image->storage_class == PseudoClass)
3988 SetPixelChannelMap(image,IndexPixelChannel,CopyPixelTrait,n++);
3989 if (image->mask != MagickFalse)
3990 SetPixelChannelMap(image,MaskPixelChannel,CopyPixelTrait,n++);
3991 assert((n+image->number_meta_channels) < MaxPixelChannels);
3992 for (i=0; i < (ssize_t) image->number_meta_channels; i++)
3993 SetPixelChannelMap(image,(PixelChannel) (MetaPixelChannel+i),CopyPixelTrait,
3995 image->number_channels=(size_t) n;
3996 if (image->debug != MagickFalse)
3997 LogPixelChannels(image);
3998 (void) SetPixelChannelMask(image,image->channel_mask);
4002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4006 % I n t e r p o l a t e P i x e l C h a n n e l %
4010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4012 % InterpolatePixelChannel() applies a pixel interpolation method between a
4013 % floating point coordinate and the pixels surrounding that coordinate. No
4014 % pixel area resampling, or scaling of the result is performed.
4016 % Interpolation is restricted to just the specified channel.
4018 % The format of the InterpolatePixelChannel method is:
4020 % MagickBooleanType InterpolatePixelChannel(const Image *image,
4021 % const CacheView *image_view,const PixelChannel channel,
4022 % const PixelInterpolateMethod method,const double x,const double y,
4023 % double *pixel,ExceptionInfo *exception)
4025 % A description of each parameter follows:
4027 % o image: the image.
4029 % o image_view: the image view.
4031 % o channel: the pixel channel to interpolate.
4033 % o method: the pixel color interpolation method.
4035 % o x,y: A double representing the current (x,y) position of the pixel.
4037 % o pixel: return the interpolated pixel here.
4039 % o exception: return any errors or warnings in this structure.
4043 static inline double MagickMax(const MagickRealType x,const MagickRealType y)
4050 static inline void CatromWeights(const MagickRealType x,
4051 MagickRealType (*weights)[4])
4054 Nicolas Robidoux' 10 flops (4* + 5- + 1+) refactoring of the
4055 computation of the standard four 1D Catmull-Rom weights. The
4056 sampling location is assumed between the second and third input
4057 pixel locations, and x is the position relative to the second
4058 input pixel location. Formulas originally derived for the VIPS
4059 (Virtual Image Processing System) library.
4066 alpha=(MagickRealType) 1.0-x;
4067 beta=(MagickRealType) (-0.5)*x*alpha;
4068 (*weights)[0]=alpha*beta;
4069 (*weights)[3]=x*beta;
4071 The following computation of the inner weights from the outer ones
4072 works for all Keys cubics.
4074 gamma=(*weights)[3]-(*weights)[0];
4075 (*weights)[1]=alpha-(*weights)[0]+gamma;
4076 (*weights)[2]=x-(*weights)[3]-gamma;
4079 static inline void SplineWeights(const MagickRealType x,
4080 MagickRealType (*weights)[4])
4083 Nicolas Robidoux' 12 flops (6* + 5- + 1+) refactoring of the
4084 computation of the standard four 1D cubic B-spline smoothing
4085 weights. The sampling location is assumed between the second and
4086 third input pixel locations, and x is the position relative to the
4087 second input pixel location.
4093 alpha=(MagickRealType) 1.0-x;
4094 (*weights)[3]=(MagickRealType) (1.0/6.0)*x*x*x;
4095 (*weights)[0]=(MagickRealType) (1.0/6.0)*alpha*alpha*alpha;
4096 beta=(*weights)[3]-(*weights)[0];
4097 (*weights)[1]=alpha-(*weights)[0]+beta;
4098 (*weights)[2]=x-(*weights)[3]-beta;
4101 static inline double MeshInterpolate(const PointInfo *delta,const double p,
4102 const double x,const double y)
4104 return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
4108 static inline ssize_t NearestNeighbor(const MagickRealType x)
4111 return((ssize_t) (x+0.5));
4112 return((ssize_t) (x-0.5));
4116 MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
4117 const CacheView *image_view,const PixelChannel channel,
4118 const PixelInterpolateMethod method,const double x,const double y,
4119 double *pixel,ExceptionInfo *exception)
4132 register const Quantum
4142 PixelInterpolateMethod
4145 assert(image != (Image *) NULL);
4146 assert(image != (Image *) NULL);
4147 assert(image->signature == MagickSignature);
4148 assert(image_view != (CacheView *) NULL);
4151 traits=GetPixelChannelMapTraits(image,channel);
4152 x_offset=(ssize_t) floor(x);
4153 y_offset=(ssize_t) floor(y);
4154 interpolate = method;
4155 if ( interpolate == UndefinedInterpolatePixel )
4156 interpolate = image->interpolate;
4157 switch (interpolate)
4159 case AverageInterpolatePixel: /* nearest 4 neighbours */
4160 case Average9InterpolatePixel: /* nearest 9 neighbours */
4161 case Average16InterpolatePixel: /* nearest 16 neighbours */
4164 count=2; /* size of the area to average - default nearest 4 */
4166 if (interpolate == Average9InterpolatePixel)
4169 x_offset=(ssize_t) (floor(x+0.5)-1);
4170 y_offset=(ssize_t) (floor(y+0.5)-1);
4172 else if (interpolate == Average16InterpolatePixel)
4178 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,count,count,
4180 if (p == (const Quantum *) NULL)
4186 count*=count; /* Number of pixels to Average */
4187 if ((traits & BlendPixelTrait) == 0)
4188 for (i=0; i < (ssize_t) count; i++)
4191 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4194 for (i=0; i < (ssize_t) count; i++)
4196 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4197 GetPixelChannels(image));
4198 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4200 for (i=0; i < (ssize_t) count; i++)
4202 gamma=MagickEpsilonReciprocal(alpha[i])/count;
4203 *pixel+=gamma*pixels[i];
4207 case BilinearInterpolatePixel:
4214 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4215 if (p == (const Quantum *) NULL)
4220 if ((traits & BlendPixelTrait) == 0)
4221 for (i=0; i < 4; i++)
4224 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4227 for (i=0; i < 4; i++)
4229 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4230 GetPixelChannels(image));
4231 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4235 epsilon.x=1.0-delta.x;
4236 epsilon.y=1.0-delta.y;
4237 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4238 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4239 gamma=MagickEpsilonReciprocal(gamma);
4240 *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
4241 (epsilon.x*pixels[2]+delta.x*pixels[3]));
4244 case CatromInterpolatePixel:
4250 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4252 if (p == (const Quantum *) NULL)
4257 if ((traits & BlendPixelTrait) == 0)
4258 for (i=0; i < 16; i++)
4261 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4264 for (i=0; i < 16; i++)
4266 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4267 GetPixelChannels(image));
4268 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4270 CatromWeights((MagickRealType) (x-x_offset),&cx);
4271 CatromWeights((MagickRealType) (y-y_offset),&cy);
4272 gamma=(channel == AlphaPixelChannel ? (MagickRealType) 1.0 :
4273 MagickEpsilonReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4274 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4275 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4276 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4277 cx[2]*alpha[14]+cx[3]*alpha[15])));
4278 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4279 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4280 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4281 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4282 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4286 /* deprecated useless and very slow interpolator */
4287 case FilterInterpolatePixel:
4301 geometry.x=x_offset-1;
4302 geometry.y=y_offset-1;
4303 excerpt_image=ExcerptImage(image,&geometry,exception);
4304 if (excerpt_image == (Image *) NULL)
4309 filter_image=ResizeImage(excerpt_image,1,1,image->filter,exception);
4310 excerpt_image=DestroyImage(excerpt_image);
4311 if (filter_image == (Image *) NULL)
4313 filter_view=AcquireVirtualCacheView(filter_image,exception);
4314 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4315 if (p == (const Quantum *) NULL)
4318 *pixel=(double) GetPixelChannel(image,channel,p);
4319 filter_view=DestroyCacheView(filter_view);
4320 filter_image=DestroyImage(filter_image);
4324 case IntegerInterpolatePixel:
4326 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4327 if (p == (const Quantum *) NULL)
4332 *pixel=(double) GetPixelChannel(image,channel,p);
4335 case NearestInterpolatePixel:
4337 x_offset=(ssize_t) floor(x+0.5);
4338 y_offset=(ssize_t) floor(y+0.5);
4339 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4340 if (p == (const Quantum *) NULL)
4345 *pixel=(double) GetPixelChannel(image,channel,p);
4348 case MeshInterpolatePixel:
4354 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4355 if (p == (const Quantum *) NULL)
4360 if ((traits & BlendPixelTrait) == 0)
4361 for (i=0; i < 4; i++)
4364 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4367 for (i=0; i < 4; i++)
4369 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4370 GetPixelChannels(image));
4371 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4375 luminance.x=GetPixelLuminance(image,p)-(double)
4376 GetPixelLuminance(image,p+3*GetPixelChannels(image));
4377 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
4378 GetPixelLuminance(image,p+2*GetPixelChannels(image));
4379 if (fabs(luminance.x) < fabs(luminance.y))
4384 if (delta.x <= delta.y)
4387 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4389 delta.y=1.0-delta.y;
4390 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4391 gamma=MagickEpsilonReciprocal(gamma);
4392 *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
4398 Top-right triangle (pixel: 1, diagonal: 0-3).
4400 delta.x=1.0-delta.x;
4401 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4402 gamma=MagickEpsilonReciprocal(gamma);
4403 *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
4412 if (delta.x <= (1.0-delta.y))
4415 Top-left triangle (pixel: 0, diagonal: 1-2).
4417 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4418 gamma=MagickEpsilonReciprocal(gamma);
4419 *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
4425 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4427 delta.x=1.0-delta.x;
4428 delta.y=1.0-delta.y;
4429 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4430 gamma=MagickEpsilonReciprocal(gamma);
4431 *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
4437 case SplineInterpolatePixel:
4443 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4445 if (p == (const Quantum *) NULL)
4450 if ((traits & BlendPixelTrait) == 0)
4451 for (i=0; i < 16; i++)
4454 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4457 for (i=0; i < 16; i++)
4459 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4460 GetPixelChannels(image));
4461 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4463 SplineWeights((MagickRealType) (x-x_offset),&cx);
4464 SplineWeights((MagickRealType) (y-y_offset),&cy);
4465 gamma=(channel == AlphaPixelChannel ? (MagickRealType) 1.0 :
4466 MagickEpsilonReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4467 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4468 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4469 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4470 cx[2]*alpha[14]+cx[3]*alpha[15])));
4471 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4472 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4473 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4474 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4475 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4483 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4487 % I n t e r p o l a t e P i x e l C h a n n e l s %
4491 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4493 % InterpolatePixelChannels() applies a pixel interpolation method between a
4494 % floating point coordinate and the pixels surrounding that coordinate. No
4495 % pixel area resampling, or scaling of the result is performed.
4497 % Interpolation is restricted to just the current channel setting of the
4498 % destination image into which the color is to be stored
4500 % The format of the InterpolatePixelChannels method is:
4502 % MagickBooleanType InterpolatePixelChannels(const Image *source,
4503 % const CacheView *source_view,const Image *destination,
4504 % const PixelInterpolateMethod method,const double x,const double y,
4505 % Quantum *pixel,ExceptionInfo *exception)
4507 % A description of each parameter follows:
4509 % o source: the source.
4511 % o source_view: the source view.
4513 % o destination: the destination image, for the interpolated color
4515 % o method: the pixel color interpolation method.
4517 % o x,y: A double representing the current (x,y) position of the pixel.
4519 % o pixel: return the interpolated pixel here.
4521 % o exception: return any errors or warnings in this structure.
4524 MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
4525 const CacheView *source_view,const Image *destination,
4526 const PixelInterpolateMethod method,const double x,const double y,
4527 Quantum *pixel,ExceptionInfo *exception)
4544 register const Quantum
4554 PixelInterpolateMethod
4557 assert(source != (Image *) NULL);
4558 assert(source != (Image *) NULL);
4559 assert(source->signature == MagickSignature);
4560 assert(source_view != (CacheView *) NULL);
4562 x_offset=(ssize_t) floor(x);
4563 y_offset=(ssize_t) floor(y);
4564 interpolate = method;
4565 if ( interpolate == UndefinedInterpolatePixel )
4566 interpolate = source->interpolate;
4567 switch (interpolate)
4569 case AverageInterpolatePixel: /* nearest 4 neighbours */
4570 case Average9InterpolatePixel: /* nearest 9 neighbours */
4571 case Average16InterpolatePixel: /* nearest 16 neighbours */
4574 count=2; /* size of the area to average - default nearest 4 */
4576 if (interpolate == Average9InterpolatePixel)
4579 x_offset=(ssize_t) (floor(x+0.5)-1);
4580 y_offset=(ssize_t) (floor(y+0.5)-1);
4582 else if (interpolate == Average16InterpolatePixel)
4588 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,count,count,
4590 if (p == (const Quantum *) NULL)
4595 count*=count; /* Number of pixels to Average */
4596 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4604 channel=GetPixelChannelMapChannel(source,i);
4605 traits=GetPixelChannelMapTraits(source,channel);
4606 destination_traits=GetPixelChannelMapTraits(destination,channel);
4607 if ((traits == UndefinedPixelTrait) ||
4608 (destination_traits == UndefinedPixelTrait))
4610 for (j=0; j < (ssize_t) count; j++)
4611 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4613 if ((traits & BlendPixelTrait) == 0)
4615 for (j=0; j < (ssize_t) count; j++)
4618 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4621 for (j=0; j < (ssize_t) count; j++)
4623 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4624 GetPixelChannels(source));
4625 pixels[j]*=alpha[j];
4626 gamma=MagickEpsilonReciprocal(alpha[j]);
4627 sum+=gamma*pixels[j];
4630 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4634 case BilinearInterpolatePixel:
4637 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4638 if (p == (const Quantum *) NULL)
4643 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4649 channel=GetPixelChannelMapChannel(source,i);
4650 traits=GetPixelChannelMapTraits(source,channel);
4651 destination_traits=GetPixelChannelMapTraits(destination,channel);
4652 if ((traits == UndefinedPixelTrait) ||
4653 (destination_traits == UndefinedPixelTrait))
4657 epsilon.x=1.0-delta.x;
4658 epsilon.y=1.0-delta.y;
4659 pixels[0]=(MagickRealType) p[i];
4660 pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i];
4661 pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i];
4662 pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i];
4663 if ((traits & BlendPixelTrait) == 0)
4665 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
4666 gamma=MagickEpsilonReciprocal(gamma);
4667 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4668 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*
4669 pixels[2]+delta.x*pixels[3]))),pixel);
4672 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4673 alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source));
4674 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4675 GetPixelChannels(source));
4676 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4677 GetPixelChannels(source));
4678 pixels[0]*=alpha[0];
4679 pixels[1]*=alpha[1];
4680 pixels[2]*=alpha[2];
4681 pixels[3]*=alpha[3];
4682 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4683 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4684 gamma=MagickEpsilonReciprocal(gamma);
4685 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4686 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+
4687 delta.x*pixels[3]))),pixel);
4691 case CatromInterpolatePixel:
4697 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4699 if (p == (const Quantum *) NULL)
4704 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 if ((traits & BlendPixelTrait) == 0)
4716 for (j=0; j < 16; j++)
4719 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4722 for (j=0; j < 16; j++)
4724 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4725 GetPixelChannels(source));
4726 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4728 CatromWeights((MagickRealType) (x-x_offset),&cx);
4729 CatromWeights((MagickRealType) (y-y_offset),&cy);
4730 gamma=((traits & BlendPixelTrait) ? (MagickRealType) (1.0) :
4731 MagickEpsilonReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4732 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4733 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4734 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4735 cx[2]*alpha[14]+cx[3]*alpha[15])));
4736 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
4737 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
4738 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
4739 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
4740 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
4741 pixels[14]+cx[3]*pixels[15]))),pixel);
4746 /* deprecated useless and very slow interpolator */
4747 case FilterInterpolatePixel:
4749 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4761 channel=GetPixelChannelMapChannel(source,i);
4762 traits=GetPixelChannelMapTraits(source,channel);
4763 destination_traits=GetPixelChannelMapTraits(destination,channel);
4764 if ((traits == UndefinedPixelTrait) ||
4765 (destination_traits == UndefinedPixelTrait))
4769 geometry.x=x_offset-1;
4770 geometry.y=y_offset-1;
4771 excerpt_source=ExcerptImage(source,&geometry,exception);
4772 if (excerpt_source == (Image *) NULL)
4777 filter_source=ResizeImage(excerpt_source,1,1,source->filter,exception);
4778 excerpt_source=DestroyImage(excerpt_source);
4779 if (filter_source == (Image *) NULL)
4781 filter_view=AcquireVirtualCacheView(filter_source,exception);
4782 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4783 if (p == (const Quantum *) NULL)
4787 SetPixelChannel(destination,channel,p[i],pixel);
4789 filter_view=DestroyCacheView(filter_view);
4790 filter_source=DestroyImage(filter_source);
4795 case IntegerInterpolatePixel:
4797 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
4798 if (p == (const Quantum *) NULL)
4803 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4805 channel=GetPixelChannelMapChannel(source,i);
4806 traits=GetPixelChannelMapTraits(source,channel);
4807 destination_traits=GetPixelChannelMapTraits(destination,channel);
4808 if ((traits == UndefinedPixelTrait) ||
4809 (destination_traits == UndefinedPixelTrait))
4811 SetPixelChannel(destination,channel,p[i],pixel);
4815 case NearestInterpolatePixel:
4817 x_offset=(ssize_t) floor(x+0.5);
4818 y_offset=(ssize_t) floor(y+0.5);
4819 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
4820 if (p == (const Quantum *) NULL)
4825 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4827 channel=GetPixelChannelMapChannel(source,i);
4828 traits=GetPixelChannelMapTraits(source,channel);
4829 destination_traits=GetPixelChannelMapTraits(destination,channel);
4830 if ((traits == UndefinedPixelTrait) ||
4831 (destination_traits == UndefinedPixelTrait))
4833 SetPixelChannel(destination,channel,p[i],pixel);
4837 case MeshInterpolatePixel:
4839 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4840 if (p == (const Quantum *) NULL)
4845 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4851 channel=GetPixelChannelMapChannel(source,i);
4852 traits=GetPixelChannelMapTraits(source,channel);
4853 destination_traits=GetPixelChannelMapTraits(destination,channel);
4854 if ((traits == UndefinedPixelTrait) ||
4855 (destination_traits == UndefinedPixelTrait))
4857 pixels[0]=(MagickRealType) p[i];
4858 pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i];
4859 pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i];
4860 pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i];
4861 if ((traits & BlendPixelTrait) == 0)
4870 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4871 alpha[1]=QuantumScale*GetPixelAlpha(source,p+
4872 GetPixelChannels(source));
4873 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4874 GetPixelChannels(source));
4875 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4876 GetPixelChannels(source));
4880 luminance.x=fabs((double)(
4881 GetPixelLuminance(source,p)
4882 -GetPixelLuminance(source,p+3*GetPixelChannels(source))));
4883 luminance.y=fabs((double)(
4884 GetPixelLuminance(source,p+GetPixelChannels(source))
4885 -GetPixelLuminance(source,p+2*GetPixelChannels(source))));
4886 if (luminance.x < luminance.y)
4891 if (delta.x <= delta.y)
4894 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4896 delta.y=1.0-delta.y;
4897 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4898 gamma=MagickEpsilonReciprocal(gamma);
4899 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4900 MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel);
4905 Top-right triangle (pixel: 1, diagonal: 0-3).
4907 delta.x=1.0-delta.x;
4908 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4909 gamma=MagickEpsilonReciprocal(gamma);
4910 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4911 MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel);
4919 if (delta.x <= (1.0-delta.y))
4922 Top-left triangle (pixel: 0, diagonal: 1-2).
4924 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4925 gamma=MagickEpsilonReciprocal(gamma);
4926 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4927 MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel);
4932 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4934 delta.x=1.0-delta.x;
4935 delta.y=1.0-delta.y;
4936 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4937 gamma=MagickEpsilonReciprocal(gamma);
4938 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4939 MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel);
4945 case SplineInterpolatePixel:
4951 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4953 if (p == (const Quantum *) NULL)
4958 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4963 channel=GetPixelChannelMapChannel(source,i);
4964 traits=GetPixelChannelMapTraits(source,channel);
4965 destination_traits=GetPixelChannelMapTraits(destination,channel);
4966 if ((traits == UndefinedPixelTrait) ||
4967 (destination_traits == UndefinedPixelTrait))
4969 if ((traits & BlendPixelTrait) == 0)
4970 for (j=0; j < 16; j++)
4973 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4976 for (j=0; j < 16; j++)
4978 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4979 GetPixelChannels(source));
4980 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4982 SplineWeights((MagickRealType) (x-x_offset),&cx);
4983 SplineWeights((MagickRealType) (y-y_offset),&cy);
4984 gamma=((traits & BlendPixelTrait) ? (MagickRealType) (1.0) :
4985 MagickEpsilonReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4986 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4987 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4988 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4989 cx[2]*alpha[14]+cx[3]*alpha[15])));
4990 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
4991 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
4992 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
4993 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
4994 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
4995 pixels[14]+cx[3]*pixels[15]))),pixel);
5004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5008 % I n t e r p o l a t e P i x e l I n f o %
5012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5014 % InterpolatePixelInfo() applies a pixel interpolation method between a
5015 % floating point coordinate and the pixels surrounding that coordinate. No
5016 % pixel area resampling, or scaling of the result is performed.
5018 % Interpolation is restricted to just RGBKA channels.
5020 % The format of the InterpolatePixelInfo method is:
5022 % MagickBooleanType InterpolatePixelInfo(const Image *image,
5023 % const CacheView *image_view,const PixelInterpolateMethod method,
5024 % const double x,const double y,PixelInfo *pixel,
5025 % ExceptionInfo *exception)
5027 % A description of each parameter follows:
5029 % o image: the image.
5031 % o image_view: the image view.
5033 % o method: the pixel color interpolation method.
5035 % o x,y: A double representing the current (x,y) position of the pixel.
5037 % o pixel: return the interpolated pixel here.
5039 % o exception: return any errors or warnings in this structure.
5043 static inline void AlphaBlendPixelInfo(const Image *image,
5044 const Quantum *pixel,PixelInfo *pixel_info,MagickRealType *alpha)
5046 if (image->matte == MagickFalse)
5049 pixel_info->red=(MagickRealType) GetPixelRed(image,pixel);
5050 pixel_info->green=(MagickRealType) GetPixelGreen(image,pixel);
5051 pixel_info->blue=(MagickRealType) GetPixelBlue(image,pixel);
5052 pixel_info->black=0.0;
5053 if (image->colorspace == CMYKColorspace)
5054 pixel_info->black=(MagickRealType) GetPixelBlack(image,pixel);
5055 pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
5058 *alpha=QuantumScale*GetPixelAlpha(image,pixel);
5059 pixel_info->red=(*alpha*GetPixelRed(image,pixel));
5060 pixel_info->green=(*alpha*GetPixelGreen(image,pixel));
5061 pixel_info->blue=(*alpha*GetPixelBlue(image,pixel));
5062 pixel_info->black=0.0;
5063 if (image->colorspace == CMYKColorspace)
5064 pixel_info->black=(*alpha*GetPixelBlack(image,pixel));
5065 pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
5068 MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
5069 const CacheView *image_view,const PixelInterpolateMethod method,
5070 const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception)
5082 register const Quantum
5092 PixelInterpolateMethod
5095 assert(image != (Image *) NULL);
5096 assert(image->signature == MagickSignature);
5097 assert(image_view != (CacheView *) NULL);
5099 x_offset=(ssize_t) floor(x);
5100 y_offset=(ssize_t) floor(y);
5101 interpolate = method;
5102 if ( interpolate == UndefinedInterpolatePixel )
5103 interpolate = image->interpolate;
5104 switch (interpolate)
5106 case AverageInterpolatePixel: /* nearest 4 neighbours */
5107 case Average9InterpolatePixel: /* nearest 9 neighbours */
5108 case Average16InterpolatePixel: /* nearest 16 neighbours */
5111 count=2; /* size of the area to average - default nearest 4 */
5113 if (interpolate == Average9InterpolatePixel)
5116 x_offset=(ssize_t) (floor(x+0.5)-1);
5117 y_offset=(ssize_t) (floor(y+0.5)-1);
5119 else if (interpolate == Average16InterpolatePixel)
5125 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,count,count,
5127 if (p == (const Quantum *) NULL)
5137 count*=count; /* number of pixels - square of size */
5138 for (i=0; i < (ssize_t) count; i++)
5140 AlphaBlendPixelInfo(image,p,pixels,alpha);
5141 gamma=MagickEpsilonReciprocal(alpha[0]);
5142 pixel->red += gamma*pixels[0].red;
5143 pixel->green += gamma*pixels[0].green;
5144 pixel->blue += gamma*pixels[0].blue;
5145 pixel->black += gamma*pixels[0].black;
5146 pixel->alpha += pixels[0].alpha;
5147 p += GetPixelChannels(image);
5149 gamma=1.0/count; /* average weighting of each pixel in area */
5150 pixel->red *= gamma;
5151 pixel->green *= gamma;
5152 pixel->blue *= gamma;
5153 pixel->black *= gamma;
5154 pixel->alpha *= gamma;
5157 case BackgroundInterpolatePixel:
5159 *pixel = image->background_color; /* Copy PixelInfo Structure */
5162 case BilinearInterpolatePixel:
5169 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5170 if (p == (const Quantum *) NULL)
5175 for (i=0; i < 4L; i++)
5176 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5179 epsilon.x=1.0-delta.x;
5180 epsilon.y=1.0-delta.y;
5181 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5182 (epsilon.x*alpha[2]+delta.x*alpha[3])));
5183 gamma=MagickEpsilonReciprocal(gamma);
5184 pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
5185 pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red));
5186 pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x*
5187 pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x*
5189 pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x*
5190 pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x*
5192 if (image->colorspace == CMYKColorspace)
5193 pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x*
5194 pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x*
5196 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5197 gamma=MagickEpsilonReciprocal(gamma);
5198 pixel->alpha=(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x*
5199 pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x*
5203 case BlendInterpolatePixel:
5205 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5206 if (p == (const Quantum *) NULL)
5211 for (i=0; i < 4L; i++)
5212 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5213 gamma=1.0; /* number of pixels blended together */
5214 for (i=0; i <= 1L; i++) {
5215 if ( y-y_offset >= 0.75 ) {
5216 alpha[i] = alpha[i+2];
5217 pixels[i] = pixels[i+2];
5219 else if ( y-y_offset > 0.25 ) {
5220 gamma = 2.0; /* each y pixels have been blended */
5221 alpha[i] += alpha[i+2]; /* add up alpha weights */
5222 pixels[i].red += pixels[i+2].red;
5223 pixels[i].green += pixels[i+2].green;
5224 pixels[i].blue += pixels[i+2].blue;
5225 pixels[i].black += pixels[i+2].black;
5226 pixels[i].alpha += pixels[i+2].alpha;
5229 if ( x-x_offset >= 0.75 ) {
5230 alpha[0] = alpha[1];
5231 pixels[0] = pixels[1];
5233 else if ( x-x_offset > 0.25 ) {
5234 gamma *= 2.0; /* double number of pixels blended */
5235 alpha[0] += alpha[1]; /* add up alpha weights */
5236 pixels[0].red += pixels[1].red;
5237 pixels[0].green += pixels[1].green;
5238 pixels[0].blue += pixels[1].blue;
5239 pixels[0].black += pixels[1].black;
5240 pixels[0].alpha += pixels[1].alpha;
5243 alpha[0]=MagickEpsilonReciprocal(alpha[0]);
5244 pixel->red = alpha[0]*pixels[0].red;
5245 pixel->green = alpha[0]*pixels[0].green; /* divide by sum of alpha */
5246 pixel->blue = alpha[0]*pixels[0].blue;
5247 pixel->black = alpha[0]*pixels[0].black;
5248 pixel->alpha = gamma*pixels[0].alpha; /* divide by number of pixels */
5251 case CatromInterpolatePixel:
5257 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5259 if (p == (const Quantum *) NULL)
5264 for (i=0; i < 16L; i++)
5265 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5266 CatromWeights((MagickRealType) (x-x_offset),&cx);
5267 CatromWeights((MagickRealType) (y-y_offset),&cy);
5268 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*
5269 pixels[1].red+cx[2]*pixels[2].red+cx[3]*
5270 pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5271 pixels[5].red+cx[2]*pixels[6].red+cx[3]*
5272 pixels[7].red)+cy[2]*(cx[0]*pixels[8].red+cx[1]*
5273 pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5274 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*
5275 pixels[13].red+cx[2]*pixels[14].red+cx[3]*pixels[15].red));
5276 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*
5277 pixels[1].green+cx[2]*pixels[2].green+cx[3]*
5278 pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+cx[1]*
5279 pixels[5].green+cx[2]*pixels[6].green+cx[3]*
5280 pixels[7].green)+cy[2]*(cx[0]*pixels[8].green+cx[1]*
5281 pixels[9].green+cx[2]*pixels[10].green+cx[3]*
5282 pixels[11].green)+cy[3]*(cx[0]*pixels[12].green+cx[1]*
5283 pixels[13].green+cx[2]*pixels[14].green+cx[3]*pixels[15].green));
5284 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*
5285 pixels[1].blue+cx[2]*pixels[2].blue+cx[3]*
5286 pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5287 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*
5288 pixels[7].blue)+cy[2]*(cx[0]*pixels[8].blue+cx[1]*
5289 pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5290 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*
5291 pixels[13].blue+cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5292 if (image->colorspace == CMYKColorspace)
5293 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*
5294 pixels[1].black+cx[2]*pixels[2].black+cx[3]*
5295 pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+cx[1]*
5296 pixels[5].black+cx[2]*pixels[6].black+cx[3]*
5297 pixels[7].black)+cy[2]*(cx[0]*pixels[8].black+cx[1]*
5298 pixels[9].black+cx[2]*pixels[10].black+cx[3]*
5299 pixels[11].black)+cy[3]*(cx[0]*pixels[12].black+cx[1]*
5300 pixels[13].black+cx[2]*pixels[14].black+cx[3]*pixels[15].black));
5301 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*
5302 pixels[1].alpha+cx[2]*pixels[2].alpha+cx[3]*
5303 pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+cx[1]*
5304 pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*
5305 pixels[7].alpha)+cy[2]*(cx[0]*pixels[8].alpha+cx[1]*
5306 pixels[9].alpha+cx[2]*pixels[10].alpha+cx[3]*
5307 pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+cx[1]*
5308 pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5312 /* deprecated useless and very slow interpolator */
5313 case FilterInterpolatePixel:
5327 geometry.x=x_offset-1;
5328 geometry.y=y_offset-1;
5329 excerpt_image=ExcerptImage(image,&geometry,exception);
5330 if (excerpt_image == (Image *) NULL)
5335 filter_image=ResizeImage(excerpt_image,1,1,image->filter,exception);
5336 excerpt_image=DestroyImage(excerpt_image);
5337 if (filter_image == (Image *) NULL)
5339 filter_view=AcquireVirtualCacheView(filter_image,exception);
5340 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
5341 if (p != (const Quantum *) NULL)
5342 GetPixelInfoPixel(image,p,pixel);
5343 filter_view=DestroyCacheView(filter_view);
5344 filter_image=DestroyImage(filter_image);
5348 case IntegerInterpolatePixel:
5350 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5351 if (p == (const Quantum *) NULL)
5356 GetPixelInfoPixel(image,p,pixel);
5359 case MeshInterpolatePixel:
5365 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5366 if (p == (const Quantum *) NULL)
5373 luminance.x=GetPixelLuminance(image,p)-(double)
5374 GetPixelLuminance(image,p+3*GetPixelChannels(image));
5375 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
5376 GetPixelLuminance(image,p+2*GetPixelChannels(image));
5377 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5378 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5379 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5380 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5381 if (fabs(luminance.x) < fabs(luminance.y))
5386 if (delta.x <= delta.y)
5389 Bottom-left triangle (pixel: 2, diagonal: 0-3).
5391 delta.y=1.0-delta.y;
5392 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5393 gamma=MagickEpsilonReciprocal(gamma);
5394 pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red,
5395 pixels[3].red,pixels[0].red);
5396 pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green,
5397 pixels[3].green,pixels[0].green);
5398 pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
5399 pixels[3].blue,pixels[0].blue);
5400 if (image->colorspace == CMYKColorspace)
5401 pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black,
5402 pixels[3].black,pixels[0].black);
5403 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5404 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha,
5405 pixels[3].alpha,pixels[0].alpha);
5410 Top-right triangle (pixel:1 , diagonal: 0-3).
5412 delta.x=1.0-delta.x;
5413 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5414 gamma=MagickEpsilonReciprocal(gamma);
5415 pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red,
5416 pixels[0].red,pixels[3].red);
5417 pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green,
5418 pixels[0].green,pixels[3].green);
5419 pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
5420 pixels[0].blue,pixels[3].blue);
5421 if (image->colorspace == CMYKColorspace)
5422 pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black,
5423 pixels[0].black,pixels[3].black);
5424 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5425 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha,
5426 pixels[0].alpha,pixels[3].alpha);
5434 if (delta.x <= (1.0-delta.y))
5437 Top-left triangle (pixel: 0, diagonal: 1-2).
5439 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5440 gamma=MagickEpsilonReciprocal(gamma);
5441 pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red,
5442 pixels[1].red,pixels[2].red);
5443 pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green,
5444 pixels[1].green,pixels[2].green);
5445 pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
5446 pixels[1].blue,pixels[2].blue);
5447 if (image->colorspace == CMYKColorspace)
5448 pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black,
5449 pixels[1].black,pixels[2].black);
5450 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5451 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha,
5452 pixels[1].alpha,pixels[2].alpha);
5457 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5459 delta.x=1.0-delta.x;
5460 delta.y=1.0-delta.y;
5461 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5462 gamma=MagickEpsilonReciprocal(gamma);
5463 pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red,
5464 pixels[2].red,pixels[1].red);
5465 pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green,
5466 pixels[2].green,pixels[1].green);
5467 pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
5468 pixels[2].blue,pixels[1].blue);
5469 if (image->colorspace == CMYKColorspace)
5470 pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black,
5471 pixels[2].black,pixels[1].black);
5472 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5473 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha,
5474 pixels[2].alpha,pixels[1].alpha);
5479 case NearestInterpolatePixel:
5481 x_offset=(ssize_t) floor(x+0.5);
5482 y_offset=(ssize_t) floor(y+0.5);
5483 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5484 if (p == (const Quantum *) NULL)
5489 GetPixelInfoPixel(image,p,pixel);
5492 case SplineInterpolatePixel:
5498 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5500 if (p == (const Quantum *) NULL)
5505 for (i=0; i < 16L; i++)
5506 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5507 SplineWeights((MagickRealType) (x-x_offset),&cx);
5508 SplineWeights((MagickRealType) (y-y_offset),&cy);
5509 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*
5510 pixels[1].red+cx[2]*pixels[2].red+cx[3]*
5511 pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5512 pixels[5].red+cx[2]*pixels[6].red+cx[3]*
5513 pixels[7].red)+cy[2]*(cx[0]*pixels[8].red+cx[1]*
5514 pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5515 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*
5516 pixels[13].red+cx[2]*pixels[14].red+cx[3]*pixels[15].red));
5517 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*
5518 pixels[1].green+cx[2]*pixels[2].green+cx[3]*
5519 pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+cx[1]*
5520 pixels[5].green+cx[2]*pixels[6].green+cx[3]*
5521 pixels[7].green)+cy[2]*(cx[0]*pixels[8].green+cx[1]*
5522 pixels[9].green+cx[2]*pixels[10].green+cx[3]*
5523 pixels[11].green)+cy[3]*(cx[0]*pixels[12].green+cx[1]*
5524 pixels[13].green+cx[2]*pixels[14].green+cx[3]*pixels[15].green));
5525 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*
5526 pixels[1].blue+cx[2]*pixels[2].blue+cx[3]*
5527 pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5528 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*
5529 pixels[7].blue)+cy[2]*(cx[0]*pixels[8].blue+cx[1]*
5530 pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5531 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*
5532 pixels[13].blue+cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5533 if (image->colorspace == CMYKColorspace)
5534 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*
5535 pixels[1].black+cx[2]*pixels[2].black+cx[3]*
5536 pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+cx[1]*
5537 pixels[5].black+cx[2]*pixels[6].black+cx[3]*
5538 pixels[7].black)+cy[2]*(cx[0]*pixels[8].black+cx[1]*
5539 pixels[9].black+cx[2]*pixels[10].black+cx[3]*
5540 pixels[11].black)+cy[3]*(cx[0]*pixels[12].black+cx[1]*
5541 pixels[13].black+cx[2]*pixels[14].black+cx[3]*pixels[15].black));
5542 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*
5543 pixels[1].alpha+cx[2]*pixels[2].alpha+cx[3]*
5544 pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+cx[1]*
5545 pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*
5546 pixels[7].alpha)+cy[2]*(cx[0]*pixels[8].alpha+cx[1]*
5547 pixels[9].alpha+cx[2]*pixels[10].alpha+cx[3]*
5548 pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+cx[1]*
5549 pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5557 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5561 + I s F u z z y E q u i v a l e n c e P i x e l %
5565 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5567 % IsFuzzyEquivalencePixel() returns MagickTrue if the distance between two
5568 % pixels is less than the specified distance in a linear three (or four)u
5569 % dimensional color space.
5571 % The format of the IsFuzzyEquivalencePixel method is:
5573 % void IsFuzzyEquivalencePixel(const Image *source,const Quantum *p,
5574 % const Image *destination,const Quantum *q)
5576 % A description of each parameter follows:
5578 % o source: the source image.
5582 % o destination: the destination image.
5587 MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *source,
5588 const Quantum *p,const Image *destination,const Quantum *q)
5594 register MagickRealType
5598 fuzz=MagickMax(source->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(
5599 destination->fuzz,(MagickRealType) MagickSQ1_2);
5602 if (source->matte != MagickFalse)
5605 Transparencies are involved - set alpha distance
5607 pixel=GetPixelAlpha(source,p)-(MagickRealType)
5608 GetPixelAlpha(destination,q);
5609 distance=pixel*pixel;
5610 if (distance > fuzz)
5611 return(MagickFalse);
5613 Generate a alpha scaling factor to generate a 4D cone on colorspace
5614 Note that if one color is transparent, distance has no color component.
5616 scale=QuantumScale*GetPixelAlpha(source,p);
5617 scale*=QuantumScale*GetPixelAlpha(destination,q);
5618 if (scale <= MagickEpsilon)
5622 RGB or CMY color cube
5624 distance*=3.0; /* rescale appropriately */
5626 pixel=GetPixelRed(source,p)-(MagickRealType) GetPixelRed(destination,q);
5627 if ((source->colorspace == HSLColorspace) ||
5628 (source->colorspace == HSBColorspace) ||
5629 (source->colorspace == HWBColorspace))
5632 Compute an arc distance for hue. It should be a vector angle of
5633 'S'/'W' length with 'L'/'B' forming appropriate cones.
5635 if (fabs((double) pixel) > (QuantumRange/2))
5636 pixel-=QuantumRange;
5639 distance+=scale*pixel*pixel;
5640 if (distance > fuzz)
5641 return(MagickFalse);
5642 pixel=GetPixelGreen(source,p)-(MagickRealType) GetPixelGreen(destination,q);
5643 distance+=scale*pixel*pixel;
5644 if (distance > fuzz)
5645 return(MagickFalse);
5646 pixel=GetPixelBlue(source,p)-(MagickRealType) GetPixelBlue(destination,q);
5647 distance+=scale*pixel*pixel;
5648 if (distance > fuzz)
5649 return(MagickFalse);
5654 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5658 + 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 %
5662 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5664 % IsFuzzyEquivalencePixelInfo() returns true if the distance between two
5665 % colors is less than the specified distance in a linear three (or four)
5666 % dimensional color space.
5668 % This implements the equivalent of:
5669 % fuzz < sqrt(color_distance^2 * u.a*v.a + alpha_distance^2)
5671 % Which produces a multi-dimensional cone for that colorspace along the
5672 % transparency vector.
5674 % For example for an RGB:
5675 % color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3
5677 % See http://www.imagemagick.org/Usage/bugs/fuzz_distance/
5679 % Hue colorspace distances need more work. Hue is not a distance, it is an
5682 % A check that q is in the same color space as p should be made and the
5683 % appropriate mapping made. -- Anthony Thyssen 8 December 2010
5685 % The format of the IsFuzzyEquivalencePixelInfo method is:
5687 % MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5688 % const PixelInfo *q)
5690 % A description of each parameter follows:
5697 MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5704 register MagickRealType
5708 if ((p->fuzz == 0.0) && (q->fuzz == 0.0))
5709 return(IsPixelInfoEquivalent(p,q));
5711 fuzz=MagickMax(q->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz,
5712 (MagickRealType) MagickSQ1_2);
5713 else if (q->fuzz == 0.0)
5714 fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(p->fuzz,
5715 (MagickRealType) MagickSQ1_2);
5717 fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz,
5718 (MagickRealType) MagickSQ1_2);
5721 if ((p->matte != MagickFalse) || (q->matte != MagickFalse))
5724 Transparencies are involved - set alpha distance.
5726 pixel=(p->matte != MagickFalse ? p->alpha : OpaqueAlpha)-
5727 (q->matte != MagickFalse ? q->alpha : OpaqueAlpha);
5728 distance=pixel*pixel;
5729 if (distance > fuzz)
5730 return(MagickFalse);
5732 Generate a alpha scaling factor to generate a 4D cone on colorspace.
5733 If one color is transparent, distance has no color component.
5735 if (p->matte != MagickFalse)
5736 scale=(QuantumScale*p->alpha);
5737 if (q->matte != MagickFalse)
5738 scale*=(QuantumScale*q->alpha);
5739 if (scale <= MagickEpsilon )
5743 CMYK create a CMY cube with a multi-dimensional cone toward black.
5745 if (p->colorspace == CMYKColorspace)
5747 pixel=p->black-q->black;
5748 distance+=pixel*pixel*scale;
5749 if (distance > fuzz)
5750 return(MagickFalse);
5751 scale*=(MagickRealType) (QuantumScale*(QuantumRange-p->black));
5752 scale*=(MagickRealType) (QuantumScale*(QuantumRange-q->black));
5755 RGB or CMY color cube.
5757 distance*=3.0; /* rescale appropriately */
5759 pixel=p->red-q->red;
5760 if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) ||
5761 (p->colorspace == HWBColorspace))
5764 This calculates a arc distance for hue-- it should be a vector angle
5765 of 'S'/'W' length with 'L'/'B' forming appropriate cones. In other
5766 words this is a hack - Anthony.
5768 if (fabs((double) pixel) > (QuantumRange/2))
5769 pixel-=QuantumRange;
5772 distance+=pixel*pixel*scale;
5773 if (distance > fuzz)
5774 return(MagickFalse);
5775 pixel=p->green-q->green;
5776 distance+=pixel*pixel*scale;
5777 if (distance > fuzz)
5778 return(MagickFalse);
5779 pixel=p->blue-q->blue;
5780 distance+=pixel*pixel*scale;
5781 if (distance > fuzz)
5782 return(MagickFalse);
5787 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5791 % S e t P i x e l C h a n n e l M a p M a s k %
5795 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5797 % SetPixelChannelMapMask() sets the pixel channel map from the specified
5800 % The format of the SetPixelChannelMapMask method is:
5802 % void SetPixelChannelMapMask(Image *image,const ChannelType channel_mask)
5804 % A description of each parameter follows:
5806 % o image: the image.
5808 % o channel_mask: the channel mask.
5811 MagickExport void SetPixelChannelMapMask(Image *image,
5812 const ChannelType channel_mask)
5814 #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
5819 if (image->debug != MagickFalse)
5820 (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%08x]", \
5821 image->filename,channel_mask); \
5822 image->channel_mask=channel_mask;
5823 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5828 channel=GetPixelChannelMapChannel(image,i);
5829 SetPixelChannelMapTraits(image,channel,
5830 GetChannelBit(channel_mask,channel) == 0 ? CopyPixelTrait :
5831 image->matte == MagickFalse || (channel == AlphaPixelChannel) ?
5832 UpdatePixelTrait : (PixelTrait) (UpdatePixelTrait | BlendPixelTrait));
5834 if (image->storage_class == PseudoClass)
5835 SetPixelChannelMapTraits(image,IndexPixelChannel,CopyPixelTrait);
5836 if (image->mask != MagickFalse)
5837 SetPixelChannelMapTraits(image,MaskPixelChannel,CopyPixelTrait);
5838 if (image->debug != MagickFalse)
5839 LogPixelChannels(image);
5843 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5847 % S e t P i x e l C h a n n e l M a s k %
5851 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5853 % SetPixelChannelMask() sets the pixel channel mask from the specified channel
5856 % The format of the SetPixelChannelMask method is:
5858 % ChannelType SetPixelChannelMask(Image *image,
5859 % const ChannelType channel_mask)
5861 % A description of each parameter follows:
5863 % o image: the image.
5865 % o channel_mask: the channel mask.
5868 MagickExport ChannelType SetPixelChannelMask(Image *image,
5869 const ChannelType channel_mask)
5874 mask=image->channel_mask;
5875 image->channel_mask=channel_mask;
5876 SetPixelChannelMapMask(image,channel_mask);
5881 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5885 % S e t P i x e l M e t a C h a n n e l s %
5889 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5891 % SetPixelMetaChannels() sets the image meta channels.
5893 % The format of the SetPixelMetaChannels method is:
5895 % MagickBooleanType SetPixelMetaChannels(Image *image,
5896 % const size_t number_meta_channels,ExceptionInfo *exception)
5898 % A description of each parameter follows:
5900 % o image: the image.
5902 % o number_meta_channels: the number of meta channels.
5904 % o exception: return any errors or warnings in this structure.
5907 MagickExport MagickBooleanType SetPixelMetaChannels(Image *image,
5908 const size_t number_meta_channels,ExceptionInfo *exception)
5910 image->number_meta_channels=number_meta_channels;
5911 return(SyncImagePixelCache(image,exception));