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 (GetPixelChannelChannel(image,i)) \
93 case RedPixelChannel: \
96 if (image->colorspace == CMYKColorspace) \
98 if (image->colorspace == GRAYColorspace) \
102 case GreenPixelChannel: \
105 if (image->colorspace == CMYKColorspace) \
109 case BluePixelChannel: \
112 if (image->colorspace == CMYKColorspace) \
116 case BlackPixelChannel: \
119 if (image->storage_class == PseudoClass) \
123 case IndexPixelChannel: \
128 case AlphaPixelChannel: \
133 case MaskPixelChannel: \
138 case MetaPixelChannel: \
146 channel=GetPixelChannelChannel(image,i); \
148 if ((GetPixelChannelTraits(image,channel) & UpdatePixelTrait) != 0) \
149 (void) ConcatenateMagickString(traits,"update,",MaxTextExtent); \
150 if ((GetPixelChannelTraits(image,channel) & BlendPixelTrait) != 0) \
151 (void) ConcatenateMagickString(traits,"blend,",MaxTextExtent); \
152 if ((GetPixelChannelTraits(image,channel) & CopyPixelTrait) != 0) \
153 (void) ConcatenateMagickString(traits,"copy,",MaxTextExtent); \
154 if (*traits == '\0') \
155 (void) ConcatenateMagickString(traits,"undefined,",MaxTextExtent); \
156 traits[strlen(traits)-1]='\0'; \
157 (void) LogMagickEvent(PixelEvent,GetMagickModule()," %.20g: %s (%s)", \
158 (double) i,name,traits); \
163 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
167 + A c q u i r e P i x e l C h a n n e l M a p %
171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173 % AcquirePixelChannelMap() acquires a pixel component map.
175 % The format of the AcquirePixelChannelMap() method is:
177 % PixelChannelMap *AcquirePixelChannelMap(void)
180 MagickExport PixelChannelMap *AcquirePixelChannelMap(void)
188 channel_map=(PixelChannelMap *) AcquireQuantumMemory(MaxPixelChannels,
189 sizeof(*channel_map));
190 if (channel_map == (PixelChannelMap *) NULL)
191 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
192 (void) ResetMagickMemory(channel_map,0,MaxPixelChannels*sizeof(*channel_map));
193 for (i=0; i < MaxPixelChannels; i++)
194 channel_map[i].channel=(PixelChannel) i;
199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 + C l o n e P i x e l C h a n n e l M a p %
207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209 % ClonePixelChannelMap() clones a pixel component map.
211 % The format of the ClonePixelChannelMap() method is:
213 % PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
215 % A description of each parameter follows:
217 % o channel_map: the pixel component map.
220 MagickExport PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
225 assert(channel_map != (PixelChannelMap *) NULL);
226 clone_map=AcquirePixelChannelMap();
227 if (clone_map == (PixelChannelMap *) NULL)
228 return((PixelChannelMap *) NULL);
229 (void) CopyMagickMemory(clone_map,channel_map,MaxPixelChannels*
230 sizeof(*channel_map));
235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239 + C l o n e P i x e l I n f o %
243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
245 % ClonePixelInfo() makes a duplicate of the given pixel info structure, or if
246 % pixel info is NULL, a new one.
248 % The format of the ClonePixelInfo method is:
250 % PixelInfo *ClonePixelInfo(const PixelInfo *pixel_info)
252 % A description of each parameter follows:
254 % o pixel_info: the pixel info.
257 MagickExport PixelInfo *ClonePixelInfo(const PixelInfo *pixel)
262 pixel_info=(PixelInfo *) AcquireQuantumMemory(1,sizeof(*pixel_info));
263 if (pixel_info == (PixelInfo *) NULL)
264 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
265 *pixel_info=(*pixel);
270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
274 + D e 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(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(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(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(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(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(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(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(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->alpha_trait=UndefinedPixelTrait;
2011 pixel->depth=MAGICKCORE_QUANTUM_DEPTH;
2016 pixel->alpha=(double) OpaqueAlpha;
2018 if (image == (const Image *) NULL)
2020 pixel->storage_class=image->storage_class;
2021 pixel->colorspace=image->colorspace;
2022 pixel->alpha_trait=image->alpha_trait;
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(QuantumRange*(*p)),q);
2374 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2376 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2378 q+=GetPixelChannels(image);
2380 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2385 if (LocaleCompare(map,"BGRA") == 0)
2387 for (y=0; y < (ssize_t) roi->height; y++)
2389 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2390 if (q == (Quantum *) NULL)
2392 for (x=0; x < (ssize_t) roi->width; x++)
2394 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2396 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2398 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2400 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2402 q+=GetPixelChannels(image);
2404 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2409 if (LocaleCompare(map,"BGRP") == 0)
2411 for (y=0; y < (ssize_t) roi->height; y++)
2413 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2414 if (q == (Quantum *) NULL)
2416 for (x=0; x < (ssize_t) roi->width; x++)
2418 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2420 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2422 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2425 q+=GetPixelChannels(image);
2427 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2432 if (LocaleCompare(map,"I") == 0)
2434 for (y=0; y < (ssize_t) roi->height; y++)
2436 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2437 if (q == (Quantum *) NULL)
2439 for (x=0; x < (ssize_t) roi->width; x++)
2441 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2443 q+=GetPixelChannels(image);
2445 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2450 if (LocaleCompare(map,"RGB") == 0)
2452 for (y=0; y < (ssize_t) roi->height; y++)
2454 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2455 if (q == (Quantum *) NULL)
2457 for (x=0; x < (ssize_t) roi->width; x++)
2459 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2461 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2463 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2465 q+=GetPixelChannels(image);
2467 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2472 if (LocaleCompare(map,"RGBA") == 0)
2474 for (y=0; y < (ssize_t) roi->height; y++)
2476 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2477 if (q == (Quantum *) NULL)
2479 for (x=0; x < (ssize_t) roi->width; x++)
2481 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2483 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2485 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2487 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2489 q+=GetPixelChannels(image);
2491 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2496 if (LocaleCompare(map,"RGBP") == 0)
2498 for (y=0; y < (ssize_t) roi->height; y++)
2500 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2501 if (q == (Quantum *) NULL)
2503 for (x=0; x < (ssize_t) roi->width; x++)
2505 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2507 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2509 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2511 q+=GetPixelChannels(image);
2513 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2519 for (y=0; y < (ssize_t) roi->height; y++)
2521 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2522 if (q == (Quantum *) NULL)
2524 for (x=0; x < (ssize_t) roi->width; x++)
2529 for (i=0; i < (ssize_t) length; i++)
2531 switch (quantum_map[i])
2536 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2540 case MagentaQuantum:
2542 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2548 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2553 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2556 case OpacityQuantum:
2558 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2563 SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q);
2568 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2576 q+=GetPixelChannels(image);
2578 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2583 static void ImportFloatPixel(Image *image,const RectangleInfo *roi,
2584 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2585 ExceptionInfo *exception)
2587 register const float
2602 p=(const float *) pixels;
2603 if (LocaleCompare(map,"BGR") == 0)
2605 for (y=0; y < (ssize_t) roi->height; y++)
2607 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2608 if (q == (Quantum *) NULL)
2610 for (x=0; x < (ssize_t) roi->width; x++)
2612 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2614 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2616 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2618 q+=GetPixelChannels(image);
2620 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2625 if (LocaleCompare(map,"BGRA") == 0)
2627 for (y=0; y < (ssize_t) roi->height; y++)
2629 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2630 if (q == (Quantum *) NULL)
2632 for (x=0; x < (ssize_t) roi->width; x++)
2634 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2636 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2638 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2640 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2642 q+=GetPixelChannels(image);
2644 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2649 if (LocaleCompare(map,"BGRP") == 0)
2651 for (y=0; y < (ssize_t) roi->height; y++)
2653 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2654 if (q == (Quantum *) NULL)
2656 for (x=0; x < (ssize_t) roi->width; x++)
2658 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2660 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2662 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2665 q+=GetPixelChannels(image);
2667 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2672 if (LocaleCompare(map,"I") == 0)
2674 for (y=0; y < (ssize_t) roi->height; y++)
2676 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2677 if (q == (Quantum *) NULL)
2679 for (x=0; x < (ssize_t) roi->width; x++)
2681 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2683 q+=GetPixelChannels(image);
2685 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2690 if (LocaleCompare(map,"RGB") == 0)
2692 for (y=0; y < (ssize_t) roi->height; y++)
2694 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2695 if (q == (Quantum *) NULL)
2697 for (x=0; x < (ssize_t) roi->width; x++)
2699 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2701 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2703 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2705 q+=GetPixelChannels(image);
2707 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2712 if (LocaleCompare(map,"RGBA") == 0)
2714 for (y=0; y < (ssize_t) roi->height; y++)
2716 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2717 if (q == (Quantum *) NULL)
2719 for (x=0; x < (ssize_t) roi->width; x++)
2721 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2723 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2725 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2727 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2729 q+=GetPixelChannels(image);
2731 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2736 if (LocaleCompare(map,"RGBP") == 0)
2738 for (y=0; y < (ssize_t) roi->height; y++)
2740 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2741 if (q == (Quantum *) NULL)
2743 for (x=0; x < (ssize_t) roi->width; x++)
2745 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2747 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2749 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2751 q+=GetPixelChannels(image);
2753 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2759 for (y=0; y < (ssize_t) roi->height; y++)
2761 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2762 if (q == (Quantum *) NULL)
2764 for (x=0; x < (ssize_t) roi->width; x++)
2769 for (i=0; i < (ssize_t) length; i++)
2771 switch (quantum_map[i])
2776 SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2780 case MagentaQuantum:
2782 SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2788 SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2793 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2796 case OpacityQuantum:
2798 SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2803 SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q);
2808 SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2816 q+=GetPixelChannels(image);
2818 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2823 static void ImportLongPixel(Image *image,const RectangleInfo *roi,
2824 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
2825 ExceptionInfo *exception)
2827 register const unsigned int
2842 p=(const unsigned int *) pixels;
2843 if (LocaleCompare(map,"BGR") == 0)
2845 for (y=0; y < (ssize_t) roi->height; y++)
2847 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2848 if (q == (Quantum *) NULL)
2850 for (x=0; x < (ssize_t) roi->width; x++)
2852 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2853 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2854 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2855 q+=GetPixelChannels(image);
2857 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2862 if (LocaleCompare(map,"BGRA") == 0)
2864 for (y=0; y < (ssize_t) roi->height; y++)
2866 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2867 if (q == (Quantum *) NULL)
2869 for (x=0; x < (ssize_t) roi->width; x++)
2871 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2872 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2873 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2874 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
2875 q+=GetPixelChannels(image);
2877 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2882 if (LocaleCompare(map,"BGRP") == 0)
2884 for (y=0; y < (ssize_t) roi->height; y++)
2886 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2887 if (q == (Quantum *) NULL)
2889 for (x=0; x < (ssize_t) roi->width; x++)
2891 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2892 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2893 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2895 q+=GetPixelChannels(image);
2897 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2902 if (LocaleCompare(map,"I") == 0)
2904 for (y=0; y < (ssize_t) roi->height; y++)
2906 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2907 if (q == (Quantum *) NULL)
2909 for (x=0; x < (ssize_t) roi->width; x++)
2911 SetPixelGray(image,ScaleLongToQuantum(*p++),q);
2912 q+=GetPixelChannels(image);
2914 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2919 if (LocaleCompare(map,"RGB") == 0)
2921 for (y=0; y < (ssize_t) roi->height; y++)
2923 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2924 if (q == (Quantum *) NULL)
2926 for (x=0; x < (ssize_t) roi->width; x++)
2928 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2929 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2930 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2931 q+=GetPixelChannels(image);
2933 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2938 if (LocaleCompare(map,"RGBA") == 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 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2948 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2949 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2950 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
2951 q+=GetPixelChannels(image);
2953 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2958 if (LocaleCompare(map,"RGBP") == 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 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2968 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2969 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2971 q+=GetPixelChannels(image);
2973 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2979 for (y=0; y < (ssize_t) roi->height; y++)
2981 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2982 if (q == (Quantum *) NULL)
2984 for (x=0; x < (ssize_t) roi->width; x++)
2989 for (i=0; i < (ssize_t) length; i++)
2991 switch (quantum_map[i])
2996 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3000 case MagentaQuantum:
3002 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
3008 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
3013 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3016 case OpacityQuantum:
3018 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3023 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
3028 SetPixelGray(image,ScaleLongToQuantum(*p),q);
3036 q+=GetPixelChannels(image);
3038 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3043 static void ImportLongLongPixel(Image *image,const RectangleInfo *roi,
3044 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3045 ExceptionInfo *exception)
3047 register const MagickSizeType
3062 p=(const MagickSizeType *) pixels;
3063 if (LocaleCompare(map,"BGR") == 0)
3065 for (y=0; y < (ssize_t) roi->height; y++)
3067 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3068 if (q == (Quantum *) NULL)
3070 for (x=0; x < (ssize_t) roi->width; x++)
3072 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3073 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3074 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3075 q+=GetPixelChannels(image);
3077 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3082 if (LocaleCompare(map,"BGRA") == 0)
3084 for (y=0; y < (ssize_t) roi->height; y++)
3086 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3087 if (q == (Quantum *) NULL)
3089 for (x=0; x < (ssize_t) roi->width; x++)
3091 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3092 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3093 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3094 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3095 q+=GetPixelChannels(image);
3097 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3102 if (LocaleCompare(map,"BGRP") == 0)
3104 for (y=0; y < (ssize_t) roi->height; y++)
3106 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3107 if (q == (Quantum *) NULL)
3109 for (x=0; x < (ssize_t) roi->width; x++)
3111 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3112 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3113 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3115 q+=GetPixelChannels(image);
3117 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3122 if (LocaleCompare(map,"I") == 0)
3124 for (y=0; y < (ssize_t) roi->height; y++)
3126 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3127 if (q == (Quantum *) NULL)
3129 for (x=0; x < (ssize_t) roi->width; x++)
3131 SetPixelGray(image,ScaleLongLongToQuantum(*p++),q);
3132 q+=GetPixelChannels(image);
3134 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3139 if (LocaleCompare(map,"RGB") == 0)
3141 for (y=0; y < (ssize_t) roi->height; y++)
3143 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3144 if (q == (Quantum *) NULL)
3146 for (x=0; x < (ssize_t) roi->width; x++)
3148 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3149 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3150 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3151 q+=GetPixelChannels(image);
3153 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3158 if (LocaleCompare(map,"RGBA") == 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 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3168 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3169 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3170 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3171 q+=GetPixelChannels(image);
3173 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3178 if (LocaleCompare(map,"RGBP") == 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 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3188 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3189 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3191 q+=GetPixelChannels(image);
3193 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3199 for (y=0; y < (ssize_t) roi->height; y++)
3201 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3202 if (q == (Quantum *) NULL)
3204 for (x=0; x < (ssize_t) roi->width; x++)
3209 for (i=0; i < (ssize_t) length; i++)
3211 switch (quantum_map[i])
3216 SetPixelRed(image,ScaleLongLongToQuantum(*p),q);
3220 case MagentaQuantum:
3222 SetPixelGreen(image,ScaleLongLongToQuantum(*p),q);
3228 SetPixelBlue(image,ScaleLongLongToQuantum(*p),q);
3233 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3236 case OpacityQuantum:
3238 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3243 SetPixelBlack(image,ScaleLongLongToQuantum(*p),q);
3248 SetPixelGray(image,ScaleLongLongToQuantum(*p),q);
3256 q+=GetPixelChannels(image);
3258 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3263 static void ImportQuantumPixel(Image *image,const RectangleInfo *roi,
3264 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3265 ExceptionInfo *exception)
3267 register const Quantum
3282 p=(const Quantum *) pixels;
3283 if (LocaleCompare(map,"BGR") == 0)
3285 for (y=0; y < (ssize_t) roi->height; y++)
3287 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3288 if (q == (Quantum *) NULL)
3290 for (x=0; x < (ssize_t) roi->width; x++)
3292 SetPixelBlue(image,*p++,q);
3293 SetPixelGreen(image,*p++,q);
3294 SetPixelRed(image,*p++,q);
3295 q+=GetPixelChannels(image);
3297 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3302 if (LocaleCompare(map,"BGRA") == 0)
3304 for (y=0; y < (ssize_t) roi->height; y++)
3306 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3307 if (q == (Quantum *) NULL)
3309 for (x=0; x < (ssize_t) roi->width; x++)
3311 SetPixelBlue(image,*p++,q);
3312 SetPixelGreen(image,*p++,q);
3313 SetPixelRed(image,*p++,q);
3314 SetPixelAlpha(image,*p++,q);
3315 q+=GetPixelChannels(image);
3317 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3322 if (LocaleCompare(map,"BGRP") == 0)
3324 for (y=0; y < (ssize_t) roi->height; y++)
3326 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3327 if (q == (Quantum *) NULL)
3329 for (x=0; x < (ssize_t) roi->width; x++)
3331 SetPixelBlue(image,*p++,q);
3332 SetPixelGreen(image,*p++,q);
3333 SetPixelRed(image,*p++,q);
3335 q+=GetPixelChannels(image);
3337 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3342 if (LocaleCompare(map,"I") == 0)
3344 for (y=0; y < (ssize_t) roi->height; y++)
3346 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3347 if (q == (Quantum *) NULL)
3349 for (x=0; x < (ssize_t) roi->width; x++)
3351 SetPixelGray(image,*p++,q);
3352 q+=GetPixelChannels(image);
3354 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3359 if (LocaleCompare(map,"RGB") == 0)
3361 for (y=0; y < (ssize_t) roi->height; y++)
3363 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3364 if (q == (Quantum *) NULL)
3366 for (x=0; x < (ssize_t) roi->width; x++)
3368 SetPixelRed(image,*p++,q);
3369 SetPixelGreen(image,*p++,q);
3370 SetPixelBlue(image,*p++,q);
3371 q+=GetPixelChannels(image);
3373 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3378 if (LocaleCompare(map,"RGBA") == 0)
3380 for (y=0; y < (ssize_t) roi->height; y++)
3382 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3383 if (q == (Quantum *) NULL)
3385 for (x=0; x < (ssize_t) roi->width; x++)
3387 SetPixelRed(image,*p++,q);
3388 SetPixelGreen(image,*p++,q);
3389 SetPixelBlue(image,*p++,q);
3390 SetPixelAlpha(image,*p++,q);
3391 q+=GetPixelChannels(image);
3393 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3398 if (LocaleCompare(map,"RGBP") == 0)
3400 for (y=0; y < (ssize_t) roi->height; y++)
3402 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3403 if (q == (Quantum *) NULL)
3405 for (x=0; x < (ssize_t) roi->width; x++)
3407 SetPixelRed(image,*p++,q);
3408 SetPixelGreen(image,*p++,q);
3409 SetPixelBlue(image,*p++,q);
3411 q+=GetPixelChannels(image);
3413 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3419 for (y=0; y < (ssize_t) roi->height; y++)
3421 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3422 if (q == (Quantum *) NULL)
3424 for (x=0; x < (ssize_t) roi->width; x++)
3429 for (i=0; i < (ssize_t) length; i++)
3431 switch (quantum_map[i])
3436 SetPixelRed(image,*p,q);
3440 case MagentaQuantum:
3442 SetPixelGreen(image,*p,q);
3448 SetPixelBlue(image,*p,q);
3453 SetPixelAlpha(image,*p,q);
3456 case OpacityQuantum:
3458 SetPixelAlpha(image,*p,q);
3463 SetPixelBlack(image,*p,q);
3468 SetPixelGray(image,*p,q);
3476 q+=GetPixelChannels(image);
3478 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3483 static void ImportShortPixel(Image *image,const RectangleInfo *roi,
3484 const char *restrict map,const QuantumType *quantum_map,const void *pixels,
3485 ExceptionInfo *exception)
3487 register const unsigned short
3502 p=(const unsigned short *) pixels;
3503 if (LocaleCompare(map,"BGR") == 0)
3505 for (y=0; y < (ssize_t) roi->height; y++)
3507 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3508 if (q == (Quantum *) NULL)
3510 for (x=0; x < (ssize_t) roi->width; x++)
3512 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3513 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3514 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3515 q+=GetPixelChannels(image);
3517 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3522 if (LocaleCompare(map,"BGRA") == 0)
3524 for (y=0; y < (ssize_t) roi->height; y++)
3526 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3527 if (q == (Quantum *) NULL)
3529 for (x=0; x < (ssize_t) roi->width; x++)
3531 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3532 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3533 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3534 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3535 q+=GetPixelChannels(image);
3537 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3542 if (LocaleCompare(map,"BGRP") == 0)
3544 for (y=0; y < (ssize_t) roi->height; y++)
3546 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3547 if (q == (Quantum *) NULL)
3549 for (x=0; x < (ssize_t) roi->width; x++)
3551 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3552 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3553 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3555 q+=GetPixelChannels(image);
3557 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3562 if (LocaleCompare(map,"I") == 0)
3564 for (y=0; y < (ssize_t) roi->height; y++)
3566 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3567 if (q == (Quantum *) NULL)
3569 for (x=0; x < (ssize_t) roi->width; x++)
3571 SetPixelGray(image,ScaleShortToQuantum(*p++),q);
3572 q+=GetPixelChannels(image);
3574 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3579 if (LocaleCompare(map,"RGB") == 0)
3581 for (y=0; y < (ssize_t) roi->height; y++)
3583 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3584 if (q == (Quantum *) NULL)
3586 for (x=0; x < (ssize_t) roi->width; x++)
3588 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3589 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3590 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3591 q+=GetPixelChannels(image);
3593 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3598 if (LocaleCompare(map,"RGBA") == 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 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3608 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3609 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3610 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3611 q+=GetPixelChannels(image);
3613 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3618 if (LocaleCompare(map,"RGBP") == 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 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3628 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3629 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3631 q+=GetPixelChannels(image);
3633 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3639 for (y=0; y < (ssize_t) roi->height; y++)
3641 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3642 if (q == (Quantum *) NULL)
3644 for (x=0; x < (ssize_t) roi->width; x++)
3649 for (i=0; i < (ssize_t) length; i++)
3651 switch (quantum_map[i])
3656 SetPixelRed(image,ScaleShortToQuantum(*p),q);
3660 case MagentaQuantum:
3662 SetPixelGreen(image,ScaleShortToQuantum(*p),q);
3668 SetPixelBlue(image,ScaleShortToQuantum(*p),q);
3673 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3676 case OpacityQuantum:
3678 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3683 SetPixelBlack(image,ScaleShortToQuantum(*p),q);
3688 SetPixelGray(image,ScaleShortToQuantum(*p),q);
3696 q+=GetPixelChannels(image);
3698 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3703 MagickExport MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
3704 const ssize_t y,const size_t width,const size_t height,const char *map,
3705 const StorageType type,const void *pixels,ExceptionInfo *exception)
3720 Allocate image structure.
3722 assert(image != (Image *) NULL);
3723 assert(image->signature == MagickSignature);
3724 if (image->debug != MagickFalse)
3725 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3727 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
3728 if (quantum_map == (QuantumType *) NULL)
3729 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
3731 for (i=0; i < (ssize_t) length; i++)
3738 quantum_map[i]=AlphaQuantum;
3739 image->alpha_trait=BlendPixelTrait;
3745 quantum_map[i]=BlueQuantum;
3751 quantum_map[i]=CyanQuantum;
3752 (void) SetImageColorspace(image,CMYKColorspace,exception);
3758 quantum_map[i]=GreenQuantum;
3764 quantum_map[i]=BlackQuantum;
3765 (void) SetImageColorspace(image,CMYKColorspace,exception);
3771 quantum_map[i]=IndexQuantum;
3772 (void) SetImageColorspace(image,GRAYColorspace,exception);
3778 quantum_map[i]=MagentaQuantum;
3779 (void) SetImageColorspace(image,CMYKColorspace,exception);
3785 quantum_map[i]=OpacityQuantum;
3786 image->alpha_trait=BlendPixelTrait;
3792 quantum_map[i]=UndefinedQuantum;
3798 quantum_map[i]=RedQuantum;
3804 quantum_map[i]=YellowQuantum;
3805 (void) SetImageColorspace(image,CMYKColorspace,exception);
3810 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3811 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3812 "UnrecognizedPixelMap","'%s'",map);
3813 return(MagickFalse);
3817 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
3818 return(MagickFalse);
3820 Transfer the pixels from the pixel data to the image.
3830 ImportCharPixel(image,&roi,map,quantum_map,pixels,exception);
3835 ImportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
3840 ImportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
3845 ImportLongPixel(image,&roi,map,quantum_map,pixels,exception);
3850 ImportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
3855 ImportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
3860 ImportShortPixel(image,&roi,map,quantum_map,pixels,exception);
3865 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3866 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3867 "UnrecognizedPixelMap","'%s'",map);
3871 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3876 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3880 + 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 %
3884 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3886 % InitializePixelChannelMap() defines the standard pixel component map.
3888 % The format of the InitializePixelChannelMap() method is:
3890 % void InitializePixelChannelMap(Image *image)
3892 % A description of each parameter follows:
3894 % o image: the image.
3897 MagickExport void InitializePixelChannelMap(Image *image)
3908 assert(image != (Image *) NULL);
3909 assert(image->signature == MagickSignature);
3910 (void) ResetMagickMemory(image->channel_map,0,MaxPixelChannels*
3911 sizeof(*image->channel_map));
3912 trait=UpdatePixelTrait;
3913 if (image->alpha_trait == BlendPixelTrait)
3914 trait=(PixelTrait) (trait | BlendPixelTrait);
3916 if (image->colorspace == GRAYColorspace)
3918 SetPixelChannelAttributes(image,BluePixelChannel,trait,n);
3919 SetPixelChannelAttributes(image,GreenPixelChannel,trait,n);
3920 SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
3924 SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
3925 SetPixelChannelAttributes(image,GreenPixelChannel,trait,n++);
3926 SetPixelChannelAttributes(image,BluePixelChannel,trait,n++);
3928 if (image->colorspace == CMYKColorspace)
3929 SetPixelChannelAttributes(image,BlackPixelChannel,trait,n++);
3930 if (image->alpha_trait != UndefinedPixelTrait)
3931 SetPixelChannelAttributes(image,AlphaPixelChannel,CopyPixelTrait,n++);
3932 if (image->storage_class == PseudoClass)
3933 SetPixelChannelAttributes(image,IndexPixelChannel,CopyPixelTrait,n++);
3934 if (image->mask != MagickFalse)
3935 SetPixelChannelAttributes(image,MaskPixelChannel,CopyPixelTrait,n++);
3936 assert((n+image->number_meta_channels) < MaxPixelChannels);
3937 for (i=0; i < (ssize_t) image->number_meta_channels; i++)
3938 SetPixelChannelAttributes(image,(PixelChannel) (MetaPixelChannel+i),
3939 CopyPixelTrait,n++);
3940 image->number_channels=(size_t) n;
3941 if (image->debug != MagickFalse)
3942 LogPixelChannels(image);
3943 (void) SetImageChannelMask(image,image->channel_mask);
3947 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3951 % I n t e r p o l a t e P i x e l C h a n n e l %
3955 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3957 % InterpolatePixelChannel() applies a pixel interpolation method between a
3958 % floating point coordinate and the pixels surrounding that coordinate. No
3959 % pixel area resampling, or scaling of the result is performed.
3961 % Interpolation is restricted to just the specified channel.
3963 % The format of the InterpolatePixelChannel method is:
3965 % MagickBooleanType InterpolatePixelChannel(const Image *image,
3966 % const CacheView *image_view,const PixelChannel channel,
3967 % const PixelInterpolateMethod method,const double x,const double y,
3968 % double *pixel,ExceptionInfo *exception)
3970 % A description of each parameter follows:
3972 % o image: the image.
3974 % o image_view: the image view.
3976 % o channel: the pixel channel to interpolate.
3978 % o method: the pixel color interpolation method.
3980 % o x,y: A double representing the current (x,y) position of the pixel.
3982 % o pixel: return the interpolated pixel here.
3984 % o exception: return any errors or warnings in this structure.
3988 static inline double MagickMax(const double x,const double y)
3995 static inline void CatromWeights(const double x,double (*weights)[4])
4003 Nicolas Robidoux' 10 flops (4* + 5- + 1+) refactoring of the computation
4004 of the standard four 1D Catmull-Rom weights. The sampling location is
4005 assumed between the second and third input pixel locations, and x is the
4006 position relative to the second input pixel location. Formulas originally
4007 derived for the VIPS (Virtual Image Processing System) library.
4009 alpha=(double) 1.0-x;
4010 beta=(double) (-0.5)*x*alpha;
4011 (*weights)[0]=alpha*beta;
4012 (*weights)[3]=x*beta;
4014 The following computation of the inner weights from the outer ones work
4015 for all Keys cubics.
4017 gamma=(*weights)[3]-(*weights)[0];
4018 (*weights)[1]=alpha-(*weights)[0]+gamma;
4019 (*weights)[2]=x-(*weights)[3]-gamma;
4022 static inline void SplineWeights(const double x,double (*weights)[4])
4029 Nicolas Robidoux' 12 flops (6* + 5- + 1+) refactoring of the
4030 computation of the standard four 1D cubic B-spline smoothing
4031 weights. The sampling location is assumed between the second and
4032 third input pixel locations, and x is the position relative to the
4033 second input pixel location.
4035 alpha=(double) 1.0-x;
4036 (*weights)[3]=(double) (1.0/6.0)*x*x*x;
4037 (*weights)[0]=(double) (1.0/6.0)*alpha*alpha*alpha;
4038 beta=(*weights)[3]-(*weights)[0];
4039 (*weights)[1]=alpha-(*weights)[0]+beta;
4040 (*weights)[2]=x-(*weights)[3]-beta;
4043 static inline double MeshInterpolate(const PointInfo *delta,const double p,
4044 const double x,const double y)
4046 return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
4050 static inline ssize_t NearestNeighbor(const double x)
4053 return((ssize_t) (x+0.5));
4054 return((ssize_t) (x-0.5));
4058 MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
4059 const CacheView *image_view,const PixelChannel channel,
4060 const PixelInterpolateMethod method,const double x,const double y,
4061 double *pixel,ExceptionInfo *exception)
4074 register const Quantum
4084 PixelInterpolateMethod
4087 assert(image != (Image *) NULL);
4088 assert(image != (Image *) NULL);
4089 assert(image->signature == MagickSignature);
4090 assert(image_view != (CacheView *) NULL);
4093 traits=GetPixelChannelTraits(image,channel);
4094 x_offset=(ssize_t) floor(x);
4095 y_offset=(ssize_t) floor(y);
4096 interpolate = method;
4097 if ( interpolate == UndefinedInterpolatePixel )
4098 interpolate = image->interpolate;
4099 switch (interpolate)
4101 case AverageInterpolatePixel: /* nearest 4 neighbours */
4102 case Average9InterpolatePixel: /* nearest 9 neighbours */
4103 case Average16InterpolatePixel: /* nearest 16 neighbours */
4106 count=2; /* size of the area to average - default nearest 4 */
4108 if (interpolate == Average9InterpolatePixel)
4111 x_offset=(ssize_t) (floor(x+0.5)-1);
4112 y_offset=(ssize_t) (floor(y+0.5)-1);
4114 else if (interpolate == Average16InterpolatePixel)
4120 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,count,count,
4122 if (p == (const Quantum *) NULL)
4128 count*=count; /* Number of pixels to Average */
4129 if ((traits & BlendPixelTrait) == 0)
4130 for (i=0; i < (ssize_t) count; i++)
4133 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4136 for (i=0; i < (ssize_t) count; i++)
4138 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4139 GetPixelChannels(image));
4140 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4142 for (i=0; i < (ssize_t) count; i++)
4144 gamma=MagickEpsilonReciprocal(alpha[i])/count;
4145 *pixel+=gamma*pixels[i];
4149 case BilinearInterpolatePixel:
4156 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4157 if (p == (const Quantum *) NULL)
4162 if ((traits & BlendPixelTrait) == 0)
4163 for (i=0; i < 4; i++)
4166 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4169 for (i=0; i < 4; i++)
4171 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4172 GetPixelChannels(image));
4173 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4177 epsilon.x=1.0-delta.x;
4178 epsilon.y=1.0-delta.y;
4179 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4180 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4181 gamma=MagickEpsilonReciprocal(gamma);
4182 *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
4183 (epsilon.x*pixels[2]+delta.x*pixels[3]));
4186 case CatromInterpolatePixel:
4192 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4194 if (p == (const Quantum *) NULL)
4199 if ((traits & BlendPixelTrait) == 0)
4200 for (i=0; i < 16; i++)
4203 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4206 for (i=0; i < 16; i++)
4208 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4209 GetPixelChannels(image));
4210 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4212 CatromWeights((double) (x-x_offset),&cx);
4213 CatromWeights((double) (y-y_offset),&cy);
4214 gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4215 MagickEpsilonReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4216 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4217 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4218 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4219 cx[2]*alpha[14]+cx[3]*alpha[15])));
4220 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4221 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4222 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4223 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4224 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4228 /* deprecated useless and very slow interpolator */
4229 case FilterInterpolatePixel:
4243 geometry.x=x_offset-1;
4244 geometry.y=y_offset-1;
4245 excerpt_image=ExcerptImage(image,&geometry,exception);
4246 if (excerpt_image == (Image *) NULL)
4251 filter_image=ResizeImage(excerpt_image,1,1,image->filter,exception);
4252 excerpt_image=DestroyImage(excerpt_image);
4253 if (filter_image == (Image *) NULL)
4255 filter_view=AcquireVirtualCacheView(filter_image,exception);
4256 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4257 if (p == (const Quantum *) NULL)
4260 *pixel=(double) GetPixelChannel(image,channel,p);
4261 filter_view=DestroyCacheView(filter_view);
4262 filter_image=DestroyImage(filter_image);
4266 case IntegerInterpolatePixel:
4268 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4269 if (p == (const Quantum *) NULL)
4274 *pixel=(double) GetPixelChannel(image,channel,p);
4277 case NearestInterpolatePixel:
4279 x_offset=(ssize_t) floor(x+0.5);
4280 y_offset=(ssize_t) floor(y+0.5);
4281 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4282 if (p == (const Quantum *) NULL)
4287 *pixel=(double) GetPixelChannel(image,channel,p);
4290 case MeshInterpolatePixel:
4296 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4297 if (p == (const Quantum *) NULL)
4302 if ((traits & BlendPixelTrait) == 0)
4303 for (i=0; i < 4; i++)
4306 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4309 for (i=0; i < 4; i++)
4311 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4312 GetPixelChannels(image));
4313 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4317 luminance.x=GetPixelLuminance(image,p)-(double)
4318 GetPixelLuminance(image,p+3*GetPixelChannels(image));
4319 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
4320 GetPixelLuminance(image,p+2*GetPixelChannels(image));
4321 if (fabs(luminance.x) < fabs(luminance.y))
4326 if (delta.x <= delta.y)
4329 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4331 delta.y=1.0-delta.y;
4332 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4333 gamma=MagickEpsilonReciprocal(gamma);
4334 *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
4340 Top-right triangle (pixel: 1, diagonal: 0-3).
4342 delta.x=1.0-delta.x;
4343 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4344 gamma=MagickEpsilonReciprocal(gamma);
4345 *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
4354 if (delta.x <= (1.0-delta.y))
4357 Top-left triangle (pixel: 0, diagonal: 1-2).
4359 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4360 gamma=MagickEpsilonReciprocal(gamma);
4361 *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
4367 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4369 delta.x=1.0-delta.x;
4370 delta.y=1.0-delta.y;
4371 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4372 gamma=MagickEpsilonReciprocal(gamma);
4373 *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
4379 case SplineInterpolatePixel:
4385 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4387 if (p == (const Quantum *) NULL)
4392 if ((traits & BlendPixelTrait) == 0)
4393 for (i=0; i < 16; i++)
4396 pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4399 for (i=0; i < 16; i++)
4401 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4402 GetPixelChannels(image));
4403 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4405 SplineWeights((double) (x-x_offset),&cx);
4406 SplineWeights((double) (y-y_offset),&cy);
4407 gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4408 MagickEpsilonReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4409 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4410 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4411 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4412 cx[2]*alpha[14]+cx[3]*alpha[15])));
4413 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4414 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4415 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4416 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4417 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4429 % I n t e r p o l a t e P i x e l C h a n n e l s %
4433 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4435 % InterpolatePixelChannels() applies a pixel interpolation method between a
4436 % floating point coordinate and the pixels surrounding that coordinate. No
4437 % pixel area resampling, or scaling of the result is performed.
4439 % Interpolation is restricted to just the current channel setting of the
4440 % destination image into which the color is to be stored
4442 % The format of the InterpolatePixelChannels method is:
4444 % MagickBooleanType InterpolatePixelChannels(const Image *source,
4445 % const CacheView *source_view,const Image *destination,
4446 % const PixelInterpolateMethod method,const double x,const double y,
4447 % Quantum *pixel,ExceptionInfo *exception)
4449 % A description of each parameter follows:
4451 % o source: the source.
4453 % o source_view: the source view.
4455 % o destination: the destination image, for the interpolated color
4457 % o method: the pixel color interpolation method.
4459 % o x,y: A double representing the current (x,y) position of the pixel.
4461 % o pixel: return the interpolated pixel here.
4463 % o exception: return any errors or warnings in this structure.
4466 MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
4467 const CacheView *source_view,const Image *destination,
4468 const PixelInterpolateMethod method,const double x,const double y,
4469 Quantum *pixel,ExceptionInfo *exception)
4486 register const Quantum
4496 PixelInterpolateMethod
4499 assert(source != (Image *) NULL);
4500 assert(source != (Image *) NULL);
4501 assert(source->signature == MagickSignature);
4502 assert(source_view != (CacheView *) NULL);
4504 x_offset=(ssize_t) floor(x);
4505 y_offset=(ssize_t) floor(y);
4506 interpolate = method;
4507 if ( interpolate == UndefinedInterpolatePixel )
4508 interpolate = source->interpolate;
4509 switch (interpolate)
4511 case AverageInterpolatePixel: /* nearest 4 neighbours */
4512 case Average9InterpolatePixel: /* nearest 9 neighbours */
4513 case Average16InterpolatePixel: /* nearest 16 neighbours */
4516 count=2; /* size of the area to average - default nearest 4 */
4518 if (interpolate == Average9InterpolatePixel)
4521 x_offset=(ssize_t) (floor(x+0.5)-1);
4522 y_offset=(ssize_t) (floor(y+0.5)-1);
4524 else if (interpolate == Average16InterpolatePixel)
4530 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,count,count,
4532 if (p == (const Quantum *) NULL)
4537 count*=count; /* Number of pixels to Average */
4538 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4546 channel=GetPixelChannelChannel(source,i);
4547 traits=GetPixelChannelTraits(source,channel);
4548 destination_traits=GetPixelChannelTraits(destination,channel);
4549 if ((traits == UndefinedPixelTrait) ||
4550 (destination_traits == UndefinedPixelTrait))
4552 for (j=0; j < (ssize_t) count; j++)
4553 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
4555 if ((traits & BlendPixelTrait) == 0)
4557 for (j=0; j < (ssize_t) count; j++)
4560 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4563 for (j=0; j < (ssize_t) count; j++)
4565 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4566 GetPixelChannels(source));
4567 pixels[j]*=alpha[j];
4568 gamma=MagickEpsilonReciprocal(alpha[j]);
4569 sum+=gamma*pixels[j];
4572 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4576 case BilinearInterpolatePixel:
4579 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4580 if (p == (const Quantum *) NULL)
4585 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4591 channel=GetPixelChannelChannel(source,i);
4592 traits=GetPixelChannelTraits(source,channel);
4593 destination_traits=GetPixelChannelTraits(destination,channel);
4594 if ((traits == UndefinedPixelTrait) ||
4595 (destination_traits == UndefinedPixelTrait))
4599 epsilon.x=1.0-delta.x;
4600 epsilon.y=1.0-delta.y;
4601 pixels[0]=(double) p[i];
4602 pixels[1]=(double) p[GetPixelChannels(source)+i];
4603 pixels[2]=(double) p[2*GetPixelChannels(source)+i];
4604 pixels[3]=(double) p[3*GetPixelChannels(source)+i];
4605 if ((traits & BlendPixelTrait) == 0)
4607 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
4608 gamma=MagickEpsilonReciprocal(gamma);
4609 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4610 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*
4611 pixels[2]+delta.x*pixels[3]))),pixel);
4614 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4615 alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source));
4616 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4617 GetPixelChannels(source));
4618 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4619 GetPixelChannels(source));
4620 pixels[0]*=alpha[0];
4621 pixels[1]*=alpha[1];
4622 pixels[2]*=alpha[2];
4623 pixels[3]*=alpha[3];
4624 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4625 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4626 gamma=MagickEpsilonReciprocal(gamma);
4627 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4628 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+
4629 delta.x*pixels[3]))),pixel);
4633 case CatromInterpolatePixel:
4639 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4641 if (p == (const Quantum *) NULL)
4646 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4651 channel=GetPixelChannelChannel(source,i);
4652 traits=GetPixelChannelTraits(source,channel);
4653 destination_traits=GetPixelChannelTraits(destination,channel);
4654 if ((traits == UndefinedPixelTrait) ||
4655 (destination_traits == UndefinedPixelTrait))
4657 if ((traits & BlendPixelTrait) == 0)
4658 for (j=0; j < 16; j++)
4661 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
4664 for (j=0; j < 16; j++)
4666 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4667 GetPixelChannels(source));
4668 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4670 CatromWeights((double) (x-x_offset),&cx);
4671 CatromWeights((double) (y-y_offset),&cy);
4672 gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
4673 MagickEpsilonReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4674 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4675 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4676 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4677 cx[2]*alpha[14]+cx[3]*alpha[15])));
4678 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
4679 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
4680 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
4681 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
4682 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
4683 pixels[14]+cx[3]*pixels[15]))),pixel);
4688 /* deprecated useless and very slow interpolator */
4689 case FilterInterpolatePixel:
4691 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4703 channel=GetPixelChannelChannel(source,i);
4704 traits=GetPixelChannelTraits(source,channel);
4705 destination_traits=GetPixelChannelTraits(destination,channel);
4706 if ((traits == UndefinedPixelTrait) ||
4707 (destination_traits == UndefinedPixelTrait))
4711 geometry.x=x_offset-1;
4712 geometry.y=y_offset-1;
4713 excerpt_source=ExcerptImage(source,&geometry,exception);
4714 if (excerpt_source == (Image *) NULL)
4719 filter_source=ResizeImage(excerpt_source,1,1,source->filter,exception);
4720 excerpt_source=DestroyImage(excerpt_source);
4721 if (filter_source == (Image *) NULL)
4723 filter_view=AcquireVirtualCacheView(filter_source,exception);
4724 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4725 if (p == (const Quantum *) NULL)
4729 SetPixelChannel(destination,channel,p[i],pixel);
4731 filter_view=DestroyCacheView(filter_view);
4732 filter_source=DestroyImage(filter_source);
4737 case IntegerInterpolatePixel:
4739 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
4740 if (p == (const Quantum *) NULL)
4745 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4747 channel=GetPixelChannelChannel(source,i);
4748 traits=GetPixelChannelTraits(source,channel);
4749 destination_traits=GetPixelChannelTraits(destination,channel);
4750 if ((traits == UndefinedPixelTrait) ||
4751 (destination_traits == UndefinedPixelTrait))
4753 SetPixelChannel(destination,channel,p[i],pixel);
4757 case NearestInterpolatePixel:
4759 x_offset=(ssize_t) floor(x+0.5);
4760 y_offset=(ssize_t) floor(y+0.5);
4761 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
4762 if (p == (const Quantum *) NULL)
4767 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4769 channel=GetPixelChannelChannel(source,i);
4770 traits=GetPixelChannelTraits(source,channel);
4771 destination_traits=GetPixelChannelTraits(destination,channel);
4772 if ((traits == UndefinedPixelTrait) ||
4773 (destination_traits == UndefinedPixelTrait))
4775 SetPixelChannel(destination,channel,p[i],pixel);
4779 case MeshInterpolatePixel:
4781 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4782 if (p == (const Quantum *) NULL)
4787 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4793 channel=GetPixelChannelChannel(source,i);
4794 traits=GetPixelChannelTraits(source,channel);
4795 destination_traits=GetPixelChannelTraits(destination,channel);
4796 if ((traits == UndefinedPixelTrait) ||
4797 (destination_traits == UndefinedPixelTrait))
4799 pixels[0]=(double) p[i];
4800 pixels[1]=(double) p[GetPixelChannels(source)+i];
4801 pixels[2]=(double) p[2*GetPixelChannels(source)+i];
4802 pixels[3]=(double) p[3*GetPixelChannels(source)+i];
4803 if ((traits & BlendPixelTrait) == 0)
4812 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4813 alpha[1]=QuantumScale*GetPixelAlpha(source,p+
4814 GetPixelChannels(source));
4815 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4816 GetPixelChannels(source));
4817 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4818 GetPixelChannels(source));
4822 luminance.x=fabs((double)(
4823 GetPixelLuminance(source,p)
4824 -GetPixelLuminance(source,p+3*GetPixelChannels(source))));
4825 luminance.y=fabs((double)(
4826 GetPixelLuminance(source,p+GetPixelChannels(source))
4827 -GetPixelLuminance(source,p+2*GetPixelChannels(source))));
4828 if (luminance.x < luminance.y)
4833 if (delta.x <= delta.y)
4836 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4838 delta.y=1.0-delta.y;
4839 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4840 gamma=MagickEpsilonReciprocal(gamma);
4841 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4842 MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel);
4847 Top-right triangle (pixel: 1, diagonal: 0-3).
4849 delta.x=1.0-delta.x;
4850 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4851 gamma=MagickEpsilonReciprocal(gamma);
4852 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4853 MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel);
4861 if (delta.x <= (1.0-delta.y))
4864 Top-left triangle (pixel: 0, diagonal: 1-2).
4866 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4867 gamma=MagickEpsilonReciprocal(gamma);
4868 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4869 MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel);
4874 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4876 delta.x=1.0-delta.x;
4877 delta.y=1.0-delta.y;
4878 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4879 gamma=MagickEpsilonReciprocal(gamma);
4880 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4881 MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel);
4887 case SplineInterpolatePixel:
4893 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4895 if (p == (const Quantum *) NULL)
4900 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4905 channel=GetPixelChannelChannel(source,i);
4906 traits=GetPixelChannelTraits(source,channel);
4907 destination_traits=GetPixelChannelTraits(destination,channel);
4908 if ((traits == UndefinedPixelTrait) ||
4909 (destination_traits == UndefinedPixelTrait))
4911 if ((traits & BlendPixelTrait) == 0)
4912 for (j=0; j < 16; j++)
4915 pixels[j]=(double) p[j*GetPixelChannels(source)+i];
4918 for (j=0; j < 16; j++)
4920 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4921 GetPixelChannels(source));
4922 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4924 SplineWeights((double) (x-x_offset),&cx);
4925 SplineWeights((double) (y-y_offset),&cy);
4926 gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
4927 MagickEpsilonReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4928 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4929 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4930 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4931 cx[2]*alpha[14]+cx[3]*alpha[15])));
4932 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
4933 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
4934 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
4935 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
4936 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
4937 pixels[14]+cx[3]*pixels[15]))),pixel);
4946 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4950 % I n t e r p o l a t e P i x e l I n f o %
4954 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4956 % InterpolatePixelInfo() applies a pixel interpolation method between a
4957 % floating point coordinate and the pixels surrounding that coordinate. No
4958 % pixel area resampling, or scaling of the result is performed.
4960 % Interpolation is restricted to just RGBKA channels.
4962 % The format of the InterpolatePixelInfo method is:
4964 % MagickBooleanType InterpolatePixelInfo(const Image *image,
4965 % const CacheView *image_view,const PixelInterpolateMethod method,
4966 % const double x,const double y,PixelInfo *pixel,
4967 % ExceptionInfo *exception)
4969 % A description of each parameter follows:
4971 % o image: the image.
4973 % o image_view: the image view.
4975 % o method: the pixel color interpolation method.
4977 % o x,y: A double representing the current (x,y) position of the pixel.
4979 % o pixel: return the interpolated pixel here.
4981 % o exception: return any errors or warnings in this structure.
4985 static inline void AlphaBlendPixelInfo(const Image *image,
4986 const Quantum *pixel,PixelInfo *pixel_info,double *alpha)
4988 if (image->alpha_trait != BlendPixelTrait)
4991 pixel_info->red=(double) GetPixelRed(image,pixel);
4992 pixel_info->green=(double) GetPixelGreen(image,pixel);
4993 pixel_info->blue=(double) GetPixelBlue(image,pixel);
4994 pixel_info->black=0.0;
4995 if (image->colorspace == CMYKColorspace)
4996 pixel_info->black=(double) GetPixelBlack(image,pixel);
4997 pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5000 *alpha=QuantumScale*GetPixelAlpha(image,pixel);
5001 pixel_info->red=(*alpha*GetPixelRed(image,pixel));
5002 pixel_info->green=(*alpha*GetPixelGreen(image,pixel));
5003 pixel_info->blue=(*alpha*GetPixelBlue(image,pixel));
5004 pixel_info->black=0.0;
5005 if (image->colorspace == CMYKColorspace)
5006 pixel_info->black=(*alpha*GetPixelBlack(image,pixel));
5007 pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5010 MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
5011 const CacheView *image_view,const PixelInterpolateMethod method,
5012 const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception)
5024 register const Quantum
5034 PixelInterpolateMethod
5037 assert(image != (Image *) NULL);
5038 assert(image->signature == MagickSignature);
5039 assert(image_view != (CacheView *) NULL);
5041 x_offset=(ssize_t) floor(x);
5042 y_offset=(ssize_t) floor(y);
5043 interpolate = method;
5044 if ( interpolate == UndefinedInterpolatePixel )
5045 interpolate = image->interpolate;
5046 switch (interpolate)
5048 case AverageInterpolatePixel: /* nearest 4 neighbours */
5049 case Average9InterpolatePixel: /* nearest 9 neighbours */
5050 case Average16InterpolatePixel: /* nearest 16 neighbours */
5053 count=2; /* size of the area to average - default nearest 4 */
5055 if (interpolate == Average9InterpolatePixel)
5058 x_offset=(ssize_t) (floor(x+0.5)-1);
5059 y_offset=(ssize_t) (floor(y+0.5)-1);
5061 else if (interpolate == Average16InterpolatePixel)
5067 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,count,count,
5069 if (p == (const Quantum *) NULL)
5079 count*=count; /* number of pixels - square of size */
5080 for (i=0; i < (ssize_t) count; i++)
5082 AlphaBlendPixelInfo(image,p,pixels,alpha);
5083 gamma=MagickEpsilonReciprocal(alpha[0]);
5084 pixel->red += gamma*pixels[0].red;
5085 pixel->green += gamma*pixels[0].green;
5086 pixel->blue += gamma*pixels[0].blue;
5087 pixel->black += gamma*pixels[0].black;
5088 pixel->alpha += pixels[0].alpha;
5089 p += GetPixelChannels(image);
5091 gamma=1.0/count; /* average weighting of each pixel in area */
5092 pixel->red *= gamma;
5093 pixel->green *= gamma;
5094 pixel->blue *= gamma;
5095 pixel->black *= gamma;
5096 pixel->alpha *= gamma;
5099 case BackgroundInterpolatePixel:
5101 *pixel = image->background_color; /* Copy PixelInfo Structure */
5104 case BilinearInterpolatePixel:
5111 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5112 if (p == (const Quantum *) NULL)
5117 for (i=0; i < 4L; i++)
5118 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5121 epsilon.x=1.0-delta.x;
5122 epsilon.y=1.0-delta.y;
5123 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5124 (epsilon.x*alpha[2]+delta.x*alpha[3])));
5125 gamma=MagickEpsilonReciprocal(gamma);
5126 pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
5127 pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red));
5128 pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x*
5129 pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x*
5131 pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x*
5132 pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x*
5134 if (image->colorspace == CMYKColorspace)
5135 pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x*
5136 pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x*
5138 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5139 gamma=MagickEpsilonReciprocal(gamma);
5140 pixel->alpha=(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x*
5141 pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x*
5145 case BlendInterpolatePixel:
5147 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5148 if (p == (const Quantum *) NULL)
5153 for (i=0; i < 4L; i++)
5154 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5155 gamma=1.0; /* number of pixels blended together */
5156 for (i=0; i <= 1L; i++) {
5157 if ( y-y_offset >= 0.75 ) {
5158 alpha[i] = alpha[i+2];
5159 pixels[i] = pixels[i+2];
5161 else if ( y-y_offset > 0.25 ) {
5162 gamma = 2.0; /* each y pixels have been blended */
5163 alpha[i] += alpha[i+2]; /* add up alpha weights */
5164 pixels[i].red += pixels[i+2].red;
5165 pixels[i].green += pixels[i+2].green;
5166 pixels[i].blue += pixels[i+2].blue;
5167 pixels[i].black += pixels[i+2].black;
5168 pixels[i].alpha += pixels[i+2].alpha;
5171 if ( x-x_offset >= 0.75 ) {
5172 alpha[0] = alpha[1];
5173 pixels[0] = pixels[1];
5175 else if ( x-x_offset > 0.25 ) {
5176 gamma *= 2.0; /* double number of pixels blended */
5177 alpha[0] += alpha[1]; /* add up alpha weights */
5178 pixels[0].red += pixels[1].red;
5179 pixels[0].green += pixels[1].green;
5180 pixels[0].blue += pixels[1].blue;
5181 pixels[0].black += pixels[1].black;
5182 pixels[0].alpha += pixels[1].alpha;
5185 alpha[0]=MagickEpsilonReciprocal(alpha[0]);
5186 pixel->red = alpha[0]*pixels[0].red;
5187 pixel->green = alpha[0]*pixels[0].green; /* divide by sum of alpha */
5188 pixel->blue = alpha[0]*pixels[0].blue;
5189 pixel->black = alpha[0]*pixels[0].black;
5190 pixel->alpha = gamma*pixels[0].alpha; /* divide by number of pixels */
5193 case CatromInterpolatePixel:
5199 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5201 if (p == (const Quantum *) NULL)
5206 for (i=0; i < 16L; i++)
5207 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5208 CatromWeights((double) (x-x_offset),&cx);
5209 CatromWeights((double) (y-y_offset),&cy);
5210 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*
5211 pixels[1].red+cx[2]*pixels[2].red+cx[3]*
5212 pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5213 pixels[5].red+cx[2]*pixels[6].red+cx[3]*
5214 pixels[7].red)+cy[2]*(cx[0]*pixels[8].red+cx[1]*
5215 pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5216 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*
5217 pixels[13].red+cx[2]*pixels[14].red+cx[3]*pixels[15].red));
5218 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*
5219 pixels[1].green+cx[2]*pixels[2].green+cx[3]*
5220 pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+cx[1]*
5221 pixels[5].green+cx[2]*pixels[6].green+cx[3]*
5222 pixels[7].green)+cy[2]*(cx[0]*pixels[8].green+cx[1]*
5223 pixels[9].green+cx[2]*pixels[10].green+cx[3]*
5224 pixels[11].green)+cy[3]*(cx[0]*pixels[12].green+cx[1]*
5225 pixels[13].green+cx[2]*pixels[14].green+cx[3]*pixels[15].green));
5226 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*
5227 pixels[1].blue+cx[2]*pixels[2].blue+cx[3]*
5228 pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5229 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*
5230 pixels[7].blue)+cy[2]*(cx[0]*pixels[8].blue+cx[1]*
5231 pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5232 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*
5233 pixels[13].blue+cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5234 if (image->colorspace == CMYKColorspace)
5235 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*
5236 pixels[1].black+cx[2]*pixels[2].black+cx[3]*
5237 pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+cx[1]*
5238 pixels[5].black+cx[2]*pixels[6].black+cx[3]*
5239 pixels[7].black)+cy[2]*(cx[0]*pixels[8].black+cx[1]*
5240 pixels[9].black+cx[2]*pixels[10].black+cx[3]*
5241 pixels[11].black)+cy[3]*(cx[0]*pixels[12].black+cx[1]*
5242 pixels[13].black+cx[2]*pixels[14].black+cx[3]*pixels[15].black));
5243 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*
5244 pixels[1].alpha+cx[2]*pixels[2].alpha+cx[3]*
5245 pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+cx[1]*
5246 pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*
5247 pixels[7].alpha)+cy[2]*(cx[0]*pixels[8].alpha+cx[1]*
5248 pixels[9].alpha+cx[2]*pixels[10].alpha+cx[3]*
5249 pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+cx[1]*
5250 pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5254 /* deprecated useless and very slow interpolator */
5255 case FilterInterpolatePixel:
5269 geometry.x=x_offset-1;
5270 geometry.y=y_offset-1;
5271 excerpt_image=ExcerptImage(image,&geometry,exception);
5272 if (excerpt_image == (Image *) NULL)
5277 filter_image=ResizeImage(excerpt_image,1,1,image->filter,exception);
5278 excerpt_image=DestroyImage(excerpt_image);
5279 if (filter_image == (Image *) NULL)
5281 filter_view=AcquireVirtualCacheView(filter_image,exception);
5282 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
5283 if (p != (const Quantum *) NULL)
5284 GetPixelInfoPixel(image,p,pixel);
5285 filter_view=DestroyCacheView(filter_view);
5286 filter_image=DestroyImage(filter_image);
5290 case IntegerInterpolatePixel:
5292 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5293 if (p == (const Quantum *) NULL)
5298 GetPixelInfoPixel(image,p,pixel);
5301 case MeshInterpolatePixel:
5307 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5308 if (p == (const Quantum *) NULL)
5315 luminance.x=GetPixelLuminance(image,p)-(double)
5316 GetPixelLuminance(image,p+3*GetPixelChannels(image));
5317 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
5318 GetPixelLuminance(image,p+2*GetPixelChannels(image));
5319 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5320 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5321 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5322 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5323 if (fabs(luminance.x) < fabs(luminance.y))
5328 if (delta.x <= delta.y)
5331 Bottom-left triangle (pixel: 2, diagonal: 0-3).
5333 delta.y=1.0-delta.y;
5334 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5335 gamma=MagickEpsilonReciprocal(gamma);
5336 pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red,
5337 pixels[3].red,pixels[0].red);
5338 pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green,
5339 pixels[3].green,pixels[0].green);
5340 pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
5341 pixels[3].blue,pixels[0].blue);
5342 if (image->colorspace == CMYKColorspace)
5343 pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black,
5344 pixels[3].black,pixels[0].black);
5345 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5346 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha,
5347 pixels[3].alpha,pixels[0].alpha);
5352 Top-right triangle (pixel:1 , diagonal: 0-3).
5354 delta.x=1.0-delta.x;
5355 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5356 gamma=MagickEpsilonReciprocal(gamma);
5357 pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red,
5358 pixels[0].red,pixels[3].red);
5359 pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green,
5360 pixels[0].green,pixels[3].green);
5361 pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
5362 pixels[0].blue,pixels[3].blue);
5363 if (image->colorspace == CMYKColorspace)
5364 pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black,
5365 pixels[0].black,pixels[3].black);
5366 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5367 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha,
5368 pixels[0].alpha,pixels[3].alpha);
5376 if (delta.x <= (1.0-delta.y))
5379 Top-left triangle (pixel: 0, diagonal: 1-2).
5381 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5382 gamma=MagickEpsilonReciprocal(gamma);
5383 pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red,
5384 pixels[1].red,pixels[2].red);
5385 pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green,
5386 pixels[1].green,pixels[2].green);
5387 pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
5388 pixels[1].blue,pixels[2].blue);
5389 if (image->colorspace == CMYKColorspace)
5390 pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black,
5391 pixels[1].black,pixels[2].black);
5392 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5393 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha,
5394 pixels[1].alpha,pixels[2].alpha);
5399 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5401 delta.x=1.0-delta.x;
5402 delta.y=1.0-delta.y;
5403 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5404 gamma=MagickEpsilonReciprocal(gamma);
5405 pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red,
5406 pixels[2].red,pixels[1].red);
5407 pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green,
5408 pixels[2].green,pixels[1].green);
5409 pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
5410 pixels[2].blue,pixels[1].blue);
5411 if (image->colorspace == CMYKColorspace)
5412 pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black,
5413 pixels[2].black,pixels[1].black);
5414 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5415 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha,
5416 pixels[2].alpha,pixels[1].alpha);
5421 case NearestInterpolatePixel:
5423 x_offset=(ssize_t) floor(x+0.5);
5424 y_offset=(ssize_t) floor(y+0.5);
5425 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5426 if (p == (const Quantum *) NULL)
5431 GetPixelInfoPixel(image,p,pixel);
5434 case SplineInterpolatePixel:
5440 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5442 if (p == (const Quantum *) NULL)
5447 for (i=0; i < 16L; i++)
5448 AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5449 SplineWeights((double) (x-x_offset),&cx);
5450 SplineWeights((double) (y-y_offset),&cy);
5451 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*
5452 pixels[1].red+cx[2]*pixels[2].red+cx[3]*
5453 pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5454 pixels[5].red+cx[2]*pixels[6].red+cx[3]*
5455 pixels[7].red)+cy[2]*(cx[0]*pixels[8].red+cx[1]*
5456 pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5457 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*
5458 pixels[13].red+cx[2]*pixels[14].red+cx[3]*pixels[15].red));
5459 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*
5460 pixels[1].green+cx[2]*pixels[2].green+cx[3]*
5461 pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+cx[1]*
5462 pixels[5].green+cx[2]*pixels[6].green+cx[3]*
5463 pixels[7].green)+cy[2]*(cx[0]*pixels[8].green+cx[1]*
5464 pixels[9].green+cx[2]*pixels[10].green+cx[3]*
5465 pixels[11].green)+cy[3]*(cx[0]*pixels[12].green+cx[1]*
5466 pixels[13].green+cx[2]*pixels[14].green+cx[3]*pixels[15].green));
5467 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*
5468 pixels[1].blue+cx[2]*pixels[2].blue+cx[3]*
5469 pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5470 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*
5471 pixels[7].blue)+cy[2]*(cx[0]*pixels[8].blue+cx[1]*
5472 pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5473 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*
5474 pixels[13].blue+cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5475 if (image->colorspace == CMYKColorspace)
5476 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*
5477 pixels[1].black+cx[2]*pixels[2].black+cx[3]*
5478 pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+cx[1]*
5479 pixels[5].black+cx[2]*pixels[6].black+cx[3]*
5480 pixels[7].black)+cy[2]*(cx[0]*pixels[8].black+cx[1]*
5481 pixels[9].black+cx[2]*pixels[10].black+cx[3]*
5482 pixels[11].black)+cy[3]*(cx[0]*pixels[12].black+cx[1]*
5483 pixels[13].black+cx[2]*pixels[14].black+cx[3]*pixels[15].black));
5484 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*
5485 pixels[1].alpha+cx[2]*pixels[2].alpha+cx[3]*
5486 pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+cx[1]*
5487 pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*
5488 pixels[7].alpha)+cy[2]*(cx[0]*pixels[8].alpha+cx[1]*
5489 pixels[9].alpha+cx[2]*pixels[10].alpha+cx[3]*
5490 pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+cx[1]*
5491 pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5499 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5503 + I s F u z z y E q u i v a l e n c e P i x e l %
5507 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5509 % IsFuzzyEquivalencePixel() returns MagickTrue if the distance between two
5510 % pixels is less than the specified distance in a linear three (or four)u
5511 % dimensional color space.
5513 % The format of the IsFuzzyEquivalencePixel method is:
5515 % void IsFuzzyEquivalencePixel(const Image *source,const Quantum *p,
5516 % const Image *destination,const Quantum *q)
5518 % A description of each parameter follows:
5520 % o source: the source image.
5524 % o destination: the destination image.
5529 MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *source,
5530 const Quantum *p,const Image *destination,const Quantum *q)
5540 fuzz=MagickMax(source->fuzz,(double) MagickSQ1_2)*MagickMax(
5541 destination->fuzz,(double) MagickSQ1_2);
5544 if (source->alpha_trait == BlendPixelTrait)
5547 Transparencies are involved - set alpha distance
5549 pixel=GetPixelAlpha(source,p)-(double)
5550 GetPixelAlpha(destination,q);
5551 distance=pixel*pixel;
5552 if (distance > fuzz)
5553 return(MagickFalse);
5555 Generate a alpha scaling factor to generate a 4D cone on colorspace
5556 Note that if one color is transparent, distance has no color component.
5558 scale=QuantumScale*GetPixelAlpha(source,p);
5559 scale*=QuantumScale*GetPixelAlpha(destination,q);
5560 if (scale <= MagickEpsilon)
5564 RGB or CMY color cube
5566 distance*=3.0; /* rescale appropriately */
5568 pixel=GetPixelRed(source,p)-(double) GetPixelRed(destination,q);
5569 if ((source->colorspace == HSLColorspace) ||
5570 (source->colorspace == HSBColorspace) ||
5571 (source->colorspace == HWBColorspace))
5574 Compute an arc distance for hue. It should be a vector angle of
5575 'S'/'W' length with 'L'/'B' forming appropriate cones.
5577 if (fabs((double) pixel) > (QuantumRange/2))
5578 pixel-=QuantumRange;
5581 distance+=scale*pixel*pixel;
5582 if (distance > fuzz)
5583 return(MagickFalse);
5584 pixel=GetPixelGreen(source,p)-(double) GetPixelGreen(destination,q);
5585 distance+=scale*pixel*pixel;
5586 if (distance > fuzz)
5587 return(MagickFalse);
5588 pixel=GetPixelBlue(source,p)-(double) GetPixelBlue(destination,q);
5589 distance+=scale*pixel*pixel;
5590 if (distance > fuzz)
5591 return(MagickFalse);
5596 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5600 + 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 %
5604 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5606 % IsFuzzyEquivalencePixelInfo() returns true if the distance between two
5607 % colors is less than the specified distance in a linear three (or four)
5608 % dimensional color space.
5610 % This implements the equivalent of:
5611 % fuzz < sqrt(color_distance^2 * u.a*v.a + alpha_distance^2)
5613 % Which produces a multi-dimensional cone for that colorspace along the
5614 % transparency vector.
5616 % For example for an RGB:
5617 % color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3
5619 % See http://www.imagemagick.org/Usage/bugs/fuzz_distance/
5621 % Hue colorspace distances need more work. Hue is not a distance, it is an
5624 % A check that q is in the same color space as p should be made and the
5625 % appropriate mapping made. -- Anthony Thyssen 8 December 2010
5627 % The format of the IsFuzzyEquivalencePixelInfo method is:
5629 % MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5630 % const PixelInfo *q)
5632 % A description of each parameter follows:
5639 MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5650 if ((p->fuzz == 0.0) && (q->fuzz == 0.0))
5651 return(IsPixelInfoEquivalent(p,q));
5653 fuzz=MagickMax(q->fuzz,(double) MagickSQ1_2)*MagickMax(q->fuzz,
5654 (double) MagickSQ1_2);
5655 else if (q->fuzz == 0.0)
5656 fuzz=MagickMax(p->fuzz,(double) MagickSQ1_2)*MagickMax(p->fuzz,
5657 (double) MagickSQ1_2);
5659 fuzz=MagickMax(p->fuzz,(double) MagickSQ1_2)*MagickMax(q->fuzz,
5660 (double) MagickSQ1_2);
5663 if ((p->alpha_trait == BlendPixelTrait) || (q->alpha_trait == BlendPixelTrait))
5666 Transparencies are involved - set alpha distance.
5668 pixel=(p->alpha_trait == BlendPixelTrait ? p->alpha : OpaqueAlpha)-
5669 (q->alpha_trait == BlendPixelTrait ? q->alpha : OpaqueAlpha);
5670 distance=pixel*pixel;
5671 if (distance > fuzz)
5672 return(MagickFalse);
5674 Generate a alpha scaling factor to generate a 4D cone on colorspace.
5675 If one color is transparent, distance has no color component.
5677 if (p->alpha_trait == BlendPixelTrait)
5678 scale=(QuantumScale*p->alpha);
5679 if (q->alpha_trait == BlendPixelTrait)
5680 scale*=(QuantumScale*q->alpha);
5681 if (scale <= MagickEpsilon )
5685 CMYK create a CMY cube with a multi-dimensional cone toward black.
5687 if (p->colorspace == CMYKColorspace)
5689 pixel=p->black-q->black;
5690 distance+=pixel*pixel*scale;
5691 if (distance > fuzz)
5692 return(MagickFalse);
5693 scale*=(double) (QuantumScale*(QuantumRange-p->black));
5694 scale*=(double) (QuantumScale*(QuantumRange-q->black));
5697 RGB or CMY color cube.
5699 distance*=3.0; /* rescale appropriately */
5701 pixel=p->red-q->red;
5702 if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) ||
5703 (p->colorspace == HWBColorspace))
5706 This calculates a arc distance for hue-- it should be a vector angle
5707 of 'S'/'W' length with 'L'/'B' forming appropriate cones. In other
5708 words this is a hack - Anthony.
5710 if (fabs((double) pixel) > (QuantumRange/2))
5711 pixel-=QuantumRange;
5714 distance+=pixel*pixel*scale;
5715 if (distance > fuzz)
5716 return(MagickFalse);
5717 pixel=p->green-q->green;
5718 distance+=pixel*pixel*scale;
5719 if (distance > fuzz)
5720 return(MagickFalse);
5721 pixel=p->blue-q->blue;
5722 distance+=pixel*pixel*scale;
5723 if (distance > fuzz)
5724 return(MagickFalse);
5729 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5733 % S e t P i x e l C h a n n e l M a p M a s k %
5737 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5739 % SetPixelChannelMask() sets the pixel channel map from the specified
5742 % The format of the SetPixelChannelMask method is:
5744 % void SetPixelChannelMask(Image *image,const ChannelType channel_mask)
5746 % A description of each parameter follows:
5748 % o image: the image.
5750 % o channel_mask: the channel mask.
5753 MagickExport void SetPixelChannelMask(Image *image,
5754 const ChannelType channel_mask)
5756 #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
5761 if (image->debug != MagickFalse)
5762 (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%08x]", \
5763 image->filename,channel_mask); \
5764 image->channel_mask=channel_mask;
5765 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5770 channel=GetPixelChannelChannel(image,i);
5771 SetPixelChannelTraits(image,channel,
5772 GetChannelBit(channel_mask,channel) == 0 ? CopyPixelTrait :
5773 image->alpha_trait != BlendPixelTrait || (channel == AlphaPixelChannel) ?
5774 UpdatePixelTrait : (PixelTrait) (UpdatePixelTrait | image->alpha_trait));
5776 if (image->storage_class == PseudoClass)
5777 SetPixelChannelTraits(image,IndexPixelChannel,CopyPixelTrait);
5778 if (image->mask != MagickFalse)
5779 SetPixelChannelTraits(image,MaskPixelChannel,CopyPixelTrait);
5780 if (image->debug != MagickFalse)
5781 LogPixelChannels(image);
5785 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5789 % S e t P i x e l M e t a C h a n n e l s %
5793 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5795 % SetPixelMetaChannels() sets the image meta channels.
5797 % The format of the SetPixelMetaChannels method is:
5799 % MagickBooleanType SetPixelMetaChannels(Image *image,
5800 % const size_t number_meta_channels,ExceptionInfo *exception)
5802 % A description of each parameter follows:
5804 % o image: the image.
5806 % o number_meta_channels: the number of meta channels.
5808 % o exception: return any errors or warnings in this structure.
5811 MagickExport MagickBooleanType SetPixelMetaChannels(Image *image,
5812 const size_t number_meta_channels,ExceptionInfo *exception)
5814 image->number_meta_channels=number_meta_channels;
5815 return(SyncImagePixelCache(image,exception));