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-2011 ImageMagick Studio LLC, a non-profit organization %
20 % dedicated to making software imaging solutions freely available. %
22 % You may not use this file except in compliance with the License. You may %
23 % obtain a copy of the License at %
25 % http://www.imagemagick.org/script/license.php %
27 % Unless required by applicable law or agreed to in writing, software %
28 % distributed under the License is distributed on an "AS IS" BASIS, %
29 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
30 % See the License for the specific language governing permissions and %
31 % limitations under the License. %
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 #include "MagickCore/studio.h"
42 #include "MagickCore/property.h"
43 #include "MagickCore/blob.h"
44 #include "MagickCore/blob-private.h"
45 #include "MagickCore/color-private.h"
46 #include "MagickCore/draw.h"
47 #include "MagickCore/exception.h"
48 #include "MagickCore/exception-private.h"
49 #include "MagickCore/cache.h"
50 #include "MagickCore/constitute.h"
51 #include "MagickCore/delegate.h"
52 #include "MagickCore/geometry.h"
53 #include "MagickCore/image-private.h"
54 #include "MagickCore/list.h"
55 #include "MagickCore/magick.h"
56 #include "MagickCore/memory_.h"
57 #include "MagickCore/monitor.h"
58 #include "MagickCore/option.h"
59 #include "MagickCore/pixel.h"
60 #include "MagickCore/pixel-accessor.h"
61 #include "MagickCore/quantum.h"
62 #include "MagickCore/quantum-private.h"
63 #include "MagickCore/resource_.h"
64 #include "MagickCore/semaphore.h"
65 #include "MagickCore/statistic.h"
66 #include "MagickCore/stream.h"
67 #include "MagickCore/string_.h"
68 #include "MagickCore/transform.h"
69 #include "MagickCore/utility.h"
71 #define LogPixelChannels(image) \
76 (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%.20g]", \
77 image->filename,(double) image->number_channels); \
78 for (i=0; i < (ssize_t) image->number_channels; i++) \
81 traits[MaxTextExtent]; \
89 switch (GetPixelChannelMapChannel(image,i)) \
91 case RedPixelChannel: \
94 if (image->colorspace == CMYKColorspace) \
96 if (image->colorspace == GRAYColorspace) \
100 case GreenPixelChannel: \
103 if (image->colorspace == CMYKColorspace) \
107 case BluePixelChannel: \
110 if (image->colorspace == CMYKColorspace) \
114 case BlackPixelChannel: \
117 if (image->storage_class == PseudoClass) \
121 case IndexPixelChannel: \
126 case AlphaPixelChannel: \
131 case MaskPixelChannel: \
136 case MetaPixelChannel: \
144 channel=GetPixelChannelMapChannel(image,i); \
146 if ((GetPixelChannelMapTraits(image,channel) & UpdatePixelTrait) != 0) \
147 (void) ConcatenateMagickString(traits,"update,",MaxTextExtent); \
148 if ((GetPixelChannelMapTraits(image,channel) & BlendPixelTrait) != 0) \
149 (void) ConcatenateMagickString(traits,"blend,",MaxTextExtent); \
150 if ((GetPixelChannelMapTraits(image,channel) & CopyPixelTrait) != 0) \
151 (void) ConcatenateMagickString(traits,"copy,",MaxTextExtent); \
152 if (*traits == '\0') \
153 (void) ConcatenateMagickString(traits,"undefined,",MaxTextExtent); \
154 traits[strlen(traits)-1]='\0'; \
155 (void) LogMagickEvent(PixelEvent,GetMagickModule()," %.20g: %s (%s)", \
156 (double) i,name,traits); \
161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165 + A c q u i r e P i x e l C h a n n e l M a p %
169 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171 % AcquirePixelChannelMap() acquires a pixel component map.
173 % The format of the AcquirePixelChannelMap() method is:
175 % PixelChannelMap *AcquirePixelChannelMap(void)
178 MagickExport PixelChannelMap *AcquirePixelChannelMap(void)
186 channel_map=(PixelChannelMap *) AcquireQuantumMemory(MaxPixelChannels,
187 sizeof(*channel_map));
188 if (channel_map == (PixelChannelMap *) NULL)
189 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
190 (void) ResetMagickMemory(channel_map,0,MaxPixelChannels*sizeof(*channel_map));
191 for (i=0; i < MaxPixelChannels; i++)
192 channel_map[i].channel=(PixelChannel) i;
197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 + C l o n e P i x e l C h a n n e l M a p %
205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
207 % ClonePixelChannelMap() clones a pixel component map.
209 % The format of the ClonePixelChannelMap() method is:
211 % PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
213 % A description of each parameter follows:
215 % o channel_map: the pixel component map.
218 MagickExport PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
223 assert(channel_map != (PixelChannelMap *) NULL);
224 clone_map=AcquirePixelChannelMap();
225 if (clone_map == (PixelChannelMap *) NULL)
226 return((PixelChannelMap *) NULL);
227 (void) CopyMagickMemory(clone_map,channel_map,MaxPixelChannels*
228 sizeof(*channel_map));
233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
237 + C l o n e P i x e l I n f o %
241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243 % ClonePixelInfo() makes a duplicate of the given pixel info structure, or if
244 % pixel info is NULL, a new one.
246 % The format of the ClonePixelInfo method is:
248 % PixelInfo *ClonePixelInfo(const PixelInfo *pixel_info)
250 % A description of each parameter follows:
252 % o pixel_info: the pixel info.
255 MagickExport PixelInfo *ClonePixelInfo(const PixelInfo *pixel)
260 pixel_info=(PixelInfo *) AcquireQuantumMemory(1,sizeof(*pixel_info));
261 if (pixel_info == (PixelInfo *) NULL)
262 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
263 *pixel_info=(*pixel);
268 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
272 + D e s t r o y P i x e l C h a n n e l M a p %
276 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278 % DestroyPixelChannelMap() deallocates memory associated with the pixel
281 % The format of the DestroyPixelChannelMap() method is:
283 % PixelChannelMap *DestroyPixelChannelMap(PixelChannelMap *channel_map)
285 % A description of each parameter follows:
287 % o channel_map: the pixel component map.
290 MagickExport PixelChannelMap *DestroyPixelChannelMap(
291 PixelChannelMap *channel_map)
293 assert(channel_map != (PixelChannelMap *) NULL);
294 channel_map=(PixelChannelMap *) RelinquishMagickMemory(channel_map);
295 return((PixelChannelMap *) RelinquishMagickMemory(channel_map));
299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
303 % E x p o r t I m a g e P i x e l s %
307 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309 % ExportImagePixels() extracts pixel data from an image and returns it to you.
310 % The method returns MagickTrue on success otherwise MagickFalse if an error is
311 % encountered. The data is returned as char, short int, int, ssize_t, float,
312 % or double in the order specified by map.
314 % Suppose you want to extract the first scanline of a 640x480 image as
315 % character data in red-green-blue order:
317 % ExportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels,exception);
319 % The format of the ExportImagePixels method is:
321 % MagickBooleanType ExportImagePixels(const Image *image,
322 % const ssize_t x_offset,const ssize_t y_offset,const size_t columns,
323 % const size_t rows,const char *map,const StorageType type,
324 % void *pixels,ExceptionInfo *exception)
326 % A description of each parameter follows:
328 % o image: the image.
330 % o x_offset,y_offset,columns,rows: These values define the perimeter
331 % of a region of pixels you want to extract.
333 % o map: This string reflects the expected ordering of the pixel array.
334 % It can be any combination or order of R = red, G = green, B = blue,
335 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
336 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
339 % o type: Define the data type of the pixels. Float and double types are
340 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
341 % types: CharPixel, DoublePixel, FloatPixel, IntegerPixel, LongPixel,
342 % QuantumPixel, or ShortPixel.
344 % o pixels: This array of values contain the pixel components as defined by
345 % map and type. You must preallocate this array where the expected
346 % length varies depending on the values of width, height, map, and type.
348 % o exception: return any errors or warnings in this structure.
351 MagickExport MagickBooleanType ExportImagePixels(const Image *image,
352 const ssize_t x_offset,const ssize_t y_offset,const size_t columns,
353 const size_t rows,const char *map,const StorageType type,void *pixels,
354 ExceptionInfo *exception)
363 register const Quantum
372 assert(image != (Image *) NULL);
373 assert(image->signature == MagickSignature);
374 if (image->debug != MagickFalse)
375 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
377 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
378 if (quantum_map == (QuantumType *) NULL)
380 (void) ThrowMagickException(exception,GetMagickModule(),
381 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
384 for (i=0; i < (ssize_t) length; i++)
391 quantum_map[i]=AlphaQuantum;
397 quantum_map[i]=BlueQuantum;
403 quantum_map[i]=CyanQuantum;
404 if (image->colorspace == CMYKColorspace)
406 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
407 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
408 "ColorSeparatedImageRequired","`%s'",map);
414 quantum_map[i]=GreenQuantum;
420 quantum_map[i]=IndexQuantum;
426 quantum_map[i]=BlackQuantum;
427 if (image->colorspace == CMYKColorspace)
429 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
430 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
431 "ColorSeparatedImageRequired","`%s'",map);
437 quantum_map[i]=MagentaQuantum;
438 if (image->colorspace == CMYKColorspace)
440 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
441 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
442 "ColorSeparatedImageRequired","`%s'",map);
448 quantum_map[i]=OpacityQuantum;
454 quantum_map[i]=UndefinedQuantum;
460 quantum_map[i]=RedQuantum;
466 quantum_map[i]=YellowQuantum;
467 if (image->colorspace == CMYKColorspace)
469 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
470 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
471 "ColorSeparatedImageRequired","`%s'",map);
476 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
477 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
478 "UnrecognizedPixelMap","`%s'",map);
487 register unsigned char
490 q=(unsigned char *) pixels;
491 if (LocaleCompare(map,"BGR") == 0)
493 for (y=0; y < (ssize_t) rows; y++)
495 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
496 if (p == (const Quantum *) NULL)
498 for (x=0; x < (ssize_t) columns; x++)
500 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
501 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
502 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
503 p+=GetPixelChannels(image);
508 if (LocaleCompare(map,"BGRA") == 0)
510 for (y=0; y < (ssize_t) rows; y++)
512 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
513 if (p == (const Quantum *) NULL)
515 for (x=0; x < (ssize_t) columns; x++)
517 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
518 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
519 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
520 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
521 p+=GetPixelChannels(image);
526 if (LocaleCompare(map,"BGRP") == 0)
528 for (y=0; y < (ssize_t) rows; y++)
530 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
531 if (p == (const Quantum *) NULL)
533 for (x=0; x < (ssize_t) columns; x++)
535 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
536 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
537 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
538 *q++=ScaleQuantumToChar((Quantum) 0);
539 p+=GetPixelChannels(image);
544 if (LocaleCompare(map,"I") == 0)
546 for (y=0; y < (ssize_t) rows; y++)
548 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
549 if (p == (const Quantum *) NULL)
551 for (x=0; x < (ssize_t) columns; x++)
553 *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
554 p+=GetPixelChannels(image);
559 if (LocaleCompare(map,"RGB") == 0)
561 for (y=0; y < (ssize_t) rows; y++)
563 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
564 if (p == (const Quantum *) NULL)
566 for (x=0; x < (ssize_t) columns; x++)
568 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
569 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
570 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
571 p+=GetPixelChannels(image);
576 if (LocaleCompare(map,"RGBA") == 0)
578 for (y=0; y < (ssize_t) rows; y++)
580 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
581 if (p == (const Quantum *) NULL)
583 for (x=0; x < (ssize_t) columns; x++)
585 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
586 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
587 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
588 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
589 p+=GetPixelChannels(image);
594 if (LocaleCompare(map,"RGBP") == 0)
596 for (y=0; y < (ssize_t) rows; y++)
598 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
599 if (p == (const Quantum *) NULL)
601 for (x=0; x < (ssize_t) columns; x++)
603 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
604 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
605 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
606 *q++=ScaleQuantumToChar((Quantum) 0);
607 p+=GetPixelChannels(image);
612 for (y=0; y < (ssize_t) rows; y++)
614 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
615 if (p == (const Quantum *) NULL)
617 for (x=0; x < (ssize_t) columns; x++)
619 for (i=0; i < (ssize_t) length; i++)
622 switch (quantum_map[i])
627 *q=ScaleQuantumToChar(GetPixelRed(image,p));
633 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
639 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
644 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
649 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
654 if (image->colorspace == CMYKColorspace)
655 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
660 *q=ScaleQuantumToChar(GetPixelIntensity(image,p));
668 p+=GetPixelChannels(image);
679 if (LocaleCompare(map,"BGR") == 0)
681 for (y=0; y < (ssize_t) rows; y++)
683 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
684 if (p == (const Quantum *) NULL)
686 for (x=0; x < (ssize_t) columns; x++)
688 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
689 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
690 *q++=(double) (QuantumScale*GetPixelRed(image,p));
691 p+=GetPixelChannels(image);
696 if (LocaleCompare(map,"BGRA") == 0)
698 for (y=0; y < (ssize_t) rows; y++)
700 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
701 if (p == (const Quantum *) NULL)
703 for (x=0; x < (ssize_t) columns; x++)
705 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
706 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
707 *q++=(double) (QuantumScale*GetPixelRed(image,p));
708 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
709 p+=GetPixelChannels(image);
714 if (LocaleCompare(map,"BGRP") == 0)
716 for (y=0; y < (ssize_t) rows; y++)
718 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
719 if (p == (const Quantum *) NULL)
721 for (x=0; x < (ssize_t) columns; x++)
723 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
724 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
725 *q++=(double) (QuantumScale*GetPixelRed(image,p));
727 p+=GetPixelChannels(image);
732 if (LocaleCompare(map,"I") == 0)
734 for (y=0; y < (ssize_t) rows; y++)
736 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
737 if (p == (const Quantum *) NULL)
739 for (x=0; x < (ssize_t) columns; x++)
741 *q++=(double) (QuantumScale*GetPixelIntensity(image,p));
742 p+=GetPixelChannels(image);
747 if (LocaleCompare(map,"RGB") == 0)
749 for (y=0; y < (ssize_t) rows; y++)
751 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
752 if (p == (const Quantum *) NULL)
754 for (x=0; x < (ssize_t) columns; x++)
756 *q++=(double) (QuantumScale*GetPixelRed(image,p));
757 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
758 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
759 p+=GetPixelChannels(image);
764 if (LocaleCompare(map,"RGBA") == 0)
766 for (y=0; y < (ssize_t) rows; y++)
768 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
769 if (p == (const Quantum *) NULL)
771 for (x=0; x < (ssize_t) columns; x++)
773 *q++=(double) (QuantumScale*GetPixelRed(image,p));
774 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
775 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
776 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
777 p+=GetPixelChannels(image);
782 if (LocaleCompare(map,"RGBP") == 0)
784 for (y=0; y < (ssize_t) rows; y++)
786 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
787 if (p == (const Quantum *) NULL)
789 for (x=0; x < (ssize_t) columns; x++)
791 *q++=(double) (QuantumScale*GetPixelRed(image,p));
792 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
793 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
795 p+=GetPixelChannels(image);
800 for (y=0; y < (ssize_t) rows; y++)
802 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
803 if (p == (const Quantum *) NULL)
805 for (x=0; x < (ssize_t) columns; x++)
807 for (i=0; i < (ssize_t) length; i++)
810 switch (quantum_map[i])
815 *q=(double) (QuantumScale*GetPixelRed(image,p));
821 *q=(double) (QuantumScale*GetPixelGreen(image,p));
827 *q=(double) (QuantumScale*GetPixelBlue(image,p));
832 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
837 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
842 if (image->colorspace == CMYKColorspace)
843 *q=(double) (QuantumScale*
844 GetPixelBlack(image,p));
849 *q=(double) (QuantumScale*GetPixelIntensity(image,p));
857 p+=GetPixelChannels(image);
868 if (LocaleCompare(map,"BGR") == 0)
870 for (y=0; y < (ssize_t) rows; y++)
872 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
873 if (p == (const Quantum *) NULL)
875 for (x=0; x < (ssize_t) columns; x++)
877 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
878 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
879 *q++=(float) (QuantumScale*GetPixelRed(image,p));
880 p+=GetPixelChannels(image);
885 if (LocaleCompare(map,"BGRA") == 0)
887 for (y=0; y < (ssize_t) rows; y++)
889 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
890 if (p == (const Quantum *) NULL)
892 for (x=0; x < (ssize_t) columns; x++)
894 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
895 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
896 *q++=(float) (QuantumScale*GetPixelRed(image,p));
897 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
898 p+=GetPixelChannels(image);
903 if (LocaleCompare(map,"BGRP") == 0)
905 for (y=0; y < (ssize_t) rows; y++)
907 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
908 if (p == (const Quantum *) NULL)
910 for (x=0; x < (ssize_t) columns; x++)
912 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
913 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
914 *q++=(float) (QuantumScale*GetPixelRed(image,p));
916 p+=GetPixelChannels(image);
921 if (LocaleCompare(map,"I") == 0)
923 for (y=0; y < (ssize_t) rows; y++)
925 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
926 if (p == (const Quantum *) NULL)
928 for (x=0; x < (ssize_t) columns; x++)
930 *q++=(float) (QuantumScale*GetPixelIntensity(image,p));
931 p+=GetPixelChannels(image);
936 if (LocaleCompare(map,"RGB") == 0)
938 for (y=0; y < (ssize_t) rows; y++)
940 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
941 if (p == (const Quantum *) NULL)
943 for (x=0; x < (ssize_t) columns; x++)
945 *q++=(float) (QuantumScale*GetPixelRed(image,p));
946 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
947 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
948 p+=GetPixelChannels(image);
953 if (LocaleCompare(map,"RGBA") == 0)
955 for (y=0; y < (ssize_t) rows; y++)
957 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
958 if (p == (const Quantum *) NULL)
960 for (x=0; x < (ssize_t) columns; x++)
962 *q++=(float) (QuantumScale*GetPixelRed(image,p));
963 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
964 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
965 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
966 p+=GetPixelChannels(image);
971 if (LocaleCompare(map,"RGBP") == 0)
973 for (y=0; y < (ssize_t) rows; y++)
975 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
976 if (p == (const Quantum *) NULL)
978 for (x=0; x < (ssize_t) columns; x++)
980 *q++=(float) (QuantumScale*GetPixelRed(image,p));
981 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
982 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
984 p+=GetPixelChannels(image);
989 for (y=0; y < (ssize_t) rows; y++)
991 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
992 if (p == (const Quantum *) NULL)
994 for (x=0; x < (ssize_t) columns; x++)
996 for (i=0; i < (ssize_t) length; i++)
999 switch (quantum_map[i])
1004 *q=(float) (QuantumScale*GetPixelRed(image,p));
1008 case MagentaQuantum:
1010 *q=(float) (QuantumScale*GetPixelGreen(image,p));
1016 *q=(float) (QuantumScale*GetPixelBlue(image,p));
1021 *q=(float) (QuantumScale*((Quantum) (GetPixelAlpha(image,p))));
1024 case OpacityQuantum:
1026 *q=(float) (QuantumScale*GetPixelAlpha(image,p));
1031 if (image->colorspace == CMYKColorspace)
1032 *q=(float) (QuantumScale* GetPixelBlack(image,p));
1037 *q=(float) (QuantumScale*GetPixelIntensity(image,p));
1045 p+=GetPixelChannels(image);
1052 register unsigned int
1055 q=(unsigned int *) pixels;
1056 if (LocaleCompare(map,"BGR") == 0)
1058 for (y=0; y < (ssize_t) rows; y++)
1060 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1061 if (p == (const Quantum *) NULL)
1063 for (x=0; x < (ssize_t) columns; x++)
1065 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1066 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1067 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1068 p+=GetPixelChannels(image);
1073 if (LocaleCompare(map,"BGRA") == 0)
1075 for (y=0; y < (ssize_t) rows; y++)
1077 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1078 if (p == (const Quantum *) NULL)
1080 for (x=0; x < (ssize_t) columns; x++)
1082 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1083 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1084 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1085 *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
1086 p+=GetPixelChannels(image);
1091 if (LocaleCompare(map,"BGRP") == 0)
1093 for (y=0; y < (ssize_t) rows; y++)
1095 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1096 if (p == (const Quantum *) NULL)
1098 for (x=0; x < (ssize_t) columns; x++)
1100 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1101 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1102 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1104 p+=GetPixelChannels(image);
1109 if (LocaleCompare(map,"I") == 0)
1111 for (y=0; y < (ssize_t) rows; y++)
1113 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1114 if (p == (const Quantum *) NULL)
1116 for (x=0; x < (ssize_t) columns; x++)
1118 *q++=(unsigned int) ScaleQuantumToLong(
1119 GetPixelIntensity(image,p));
1120 p+=GetPixelChannels(image);
1125 if (LocaleCompare(map,"RGB") == 0)
1127 for (y=0; y < (ssize_t) rows; y++)
1129 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1130 if (p == (const Quantum *) NULL)
1132 for (x=0; x < (ssize_t) columns; x++)
1134 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1135 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1136 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1137 p+=GetPixelChannels(image);
1142 if (LocaleCompare(map,"RGBA") == 0)
1144 for (y=0; y < (ssize_t) rows; y++)
1146 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1147 if (p == (const Quantum *) NULL)
1149 for (x=0; x < (ssize_t) columns; x++)
1151 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1152 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1153 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1154 *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
1155 p+=GetPixelChannels(image);
1160 if (LocaleCompare(map,"RGBP") == 0)
1162 for (y=0; y < (ssize_t) rows; y++)
1164 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1165 if (p == (const Quantum *) NULL)
1167 for (x=0; x < (ssize_t) columns; x++)
1169 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1170 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1171 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1173 p+=GetPixelChannels(image);
1178 for (y=0; y < (ssize_t) rows; y++)
1180 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1181 if (p == (const Quantum *) NULL)
1183 for (x=0; x < (ssize_t) columns; x++)
1185 for (i=0; i < (ssize_t) length; i++)
1188 switch (quantum_map[i])
1193 *q=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1197 case MagentaQuantum:
1199 *q=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1205 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1210 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
1213 case OpacityQuantum:
1215 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
1220 if (image->colorspace == CMYKColorspace)
1221 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlack(image,p));
1226 *q=(unsigned int) ScaleQuantumToLong(
1227 GetPixelIntensity(image,p));
1235 p+=GetPixelChannels(image);
1245 q=(size_t *) pixels;
1246 if (LocaleCompare(map,"BGR") == 0)
1248 for (y=0; y < (ssize_t) rows; y++)
1250 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1251 if (p == (const Quantum *) NULL)
1253 for (x=0; x < (ssize_t) columns; x++)
1255 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1256 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1257 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1258 p+=GetPixelChannels(image);
1263 if (LocaleCompare(map,"BGRA") == 0)
1265 for (y=0; y < (ssize_t) rows; y++)
1267 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1268 if (p == (const Quantum *) NULL)
1270 for (x=0; x < (ssize_t) columns; x++)
1272 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1273 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1274 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1275 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1276 p+=GetPixelChannels(image);
1281 if (LocaleCompare(map,"BGRP") == 0)
1283 for (y=0; y < (ssize_t) rows; y++)
1285 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1286 if (p == (const Quantum *) NULL)
1288 for (x=0; x < (ssize_t) columns; x++)
1290 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1291 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1292 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1294 p+=GetPixelChannels(image);
1299 if (LocaleCompare(map,"I") == 0)
1301 for (y=0; y < (ssize_t) rows; y++)
1303 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1304 if (p == (const Quantum *) NULL)
1306 for (x=0; x < (ssize_t) columns; x++)
1308 *q++=ScaleQuantumToLong(GetPixelIntensity(image,p));
1309 p+=GetPixelChannels(image);
1314 if (LocaleCompare(map,"RGB") == 0)
1316 for (y=0; y < (ssize_t) rows; y++)
1318 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1319 if (p == (const Quantum *) NULL)
1321 for (x=0; x < (ssize_t) columns; x++)
1323 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1324 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1325 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1326 p+=GetPixelChannels(image);
1331 if (LocaleCompare(map,"RGBA") == 0)
1333 for (y=0; y < (ssize_t) rows; y++)
1335 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1336 if (p == (const Quantum *) NULL)
1338 for (x=0; x < (ssize_t) columns; x++)
1340 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1341 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1342 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1343 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1344 p+=GetPixelChannels(image);
1349 if (LocaleCompare(map,"RGBP") == 0)
1351 for (y=0; y < (ssize_t) rows; y++)
1353 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1354 if (p == (const Quantum *) NULL)
1356 for (x=0; x < (ssize_t) columns; x++)
1358 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1359 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1360 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1362 p+=GetPixelChannels(image);
1367 for (y=0; y < (ssize_t) rows; y++)
1369 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1370 if (p == (const Quantum *) NULL)
1372 for (x=0; x < (ssize_t) columns; x++)
1374 for (i=0; i < (ssize_t) length; i++)
1377 switch (quantum_map[i])
1382 *q=ScaleQuantumToLong(GetPixelRed(image,p));
1386 case MagentaQuantum:
1388 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
1394 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
1399 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1402 case OpacityQuantum:
1404 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1409 if (image->colorspace == CMYKColorspace)
1410 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
1415 *q=ScaleQuantumToLong(GetPixelIntensity(image,p));
1423 p+=GetPixelChannels(image);
1433 q=(Quantum *) pixels;
1434 if (LocaleCompare(map,"BGR") == 0)
1436 for (y=0; y < (ssize_t) rows; y++)
1438 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1439 if (p == (const Quantum *) NULL)
1441 for (x=0; x < (ssize_t) columns; x++)
1443 *q++=GetPixelBlue(image,p);
1444 *q++=GetPixelGreen(image,p);
1445 *q++=GetPixelRed(image,p);
1446 p+=GetPixelChannels(image);
1451 if (LocaleCompare(map,"BGRA") == 0)
1453 for (y=0; y < (ssize_t) rows; y++)
1455 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1456 if (p == (const Quantum *) NULL)
1458 for (x=0; x < (ssize_t) columns; x++)
1460 *q++=GetPixelBlue(image,p);
1461 *q++=GetPixelGreen(image,p);
1462 *q++=GetPixelRed(image,p);
1463 *q++=(Quantum) (GetPixelAlpha(image,p));
1464 p+=GetPixelChannels(image);
1469 if (LocaleCompare(map,"BGRP") == 0)
1471 for (y=0; y < (ssize_t) rows; y++)
1473 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1474 if (p == (const Quantum *) NULL)
1476 for (x=0; x < (ssize_t) columns; x++)
1478 *q++=GetPixelBlue(image,p);
1479 *q++=GetPixelGreen(image,p);
1480 *q++=GetPixelRed(image,p);
1482 p+=GetPixelChannels(image);
1487 if (LocaleCompare(map,"I") == 0)
1489 for (y=0; y < (ssize_t) rows; y++)
1491 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1492 if (p == (const Quantum *) NULL)
1494 for (x=0; x < (ssize_t) columns; x++)
1496 *q++=GetPixelIntensity(image,p);
1497 p+=GetPixelChannels(image);
1502 if (LocaleCompare(map,"RGB") == 0)
1504 for (y=0; y < (ssize_t) rows; y++)
1506 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1507 if (p == (const Quantum *) NULL)
1509 for (x=0; x < (ssize_t) columns; x++)
1511 *q++=GetPixelRed(image,p);
1512 *q++=GetPixelGreen(image,p);
1513 *q++=GetPixelBlue(image,p);
1514 p+=GetPixelChannels(image);
1519 if (LocaleCompare(map,"RGBA") == 0)
1521 for (y=0; y < (ssize_t) rows; y++)
1523 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1524 if (p == (const Quantum *) NULL)
1526 for (x=0; x < (ssize_t) columns; x++)
1528 *q++=GetPixelRed(image,p);
1529 *q++=GetPixelGreen(image,p);
1530 *q++=GetPixelBlue(image,p);
1531 *q++=(Quantum) (GetPixelAlpha(image,p));
1532 p+=GetPixelChannels(image);
1537 if (LocaleCompare(map,"RGBP") == 0)
1539 for (y=0; y < (ssize_t) rows; y++)
1541 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1542 if (p == (const Quantum *) NULL)
1544 for (x=0; x < (ssize_t) columns; x++)
1546 *q++=GetPixelRed(image,p);
1547 *q++=GetPixelGreen(image,p);
1548 *q++=GetPixelBlue(image,p);
1550 p+=GetPixelChannels(image);
1555 for (y=0; y < (ssize_t) rows; y++)
1557 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1558 if (p == (const Quantum *) NULL)
1560 for (x=0; x < (ssize_t) columns; x++)
1562 for (i=0; i < (ssize_t) length; i++)
1565 switch (quantum_map[i])
1570 *q=GetPixelRed(image,p);
1574 case MagentaQuantum:
1576 *q=GetPixelGreen(image,p);
1582 *q=GetPixelBlue(image,p);
1587 *q=(Quantum) (GetPixelAlpha(image,p));
1590 case OpacityQuantum:
1592 *q=GetPixelAlpha(image,p);
1597 if (image->colorspace == CMYKColorspace)
1598 *q=GetPixelBlack(image,p);
1603 *q=(GetPixelIntensity(image,p));
1611 p+=GetPixelChannels(image);
1618 register unsigned short
1621 q=(unsigned short *) pixels;
1622 if (LocaleCompare(map,"BGR") == 0)
1624 for (y=0; y < (ssize_t) rows; y++)
1626 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1627 if (p == (const Quantum *) NULL)
1629 for (x=0; x < (ssize_t) columns; x++)
1631 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1632 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1633 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1634 p+=GetPixelChannels(image);
1639 if (LocaleCompare(map,"BGRA") == 0)
1641 for (y=0; y < (ssize_t) rows; y++)
1643 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1644 if (p == (const Quantum *) NULL)
1646 for (x=0; x < (ssize_t) columns; x++)
1648 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1649 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1650 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1651 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1652 p+=GetPixelChannels(image);
1657 if (LocaleCompare(map,"BGRP") == 0)
1659 for (y=0; y < (ssize_t) rows; y++)
1661 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1662 if (p == (const Quantum *) NULL)
1664 for (x=0; x < (ssize_t) columns; x++)
1666 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1667 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1668 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1670 p+=GetPixelChannels(image);
1675 if (LocaleCompare(map,"I") == 0)
1677 for (y=0; y < (ssize_t) rows; y++)
1679 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1680 if (p == (const Quantum *) NULL)
1682 for (x=0; x < (ssize_t) columns; x++)
1684 *q++=ScaleQuantumToShort(GetPixelIntensity(image,p));
1685 p+=GetPixelChannels(image);
1690 if (LocaleCompare(map,"RGB") == 0)
1692 for (y=0; y < (ssize_t) rows; y++)
1694 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1695 if (p == (const Quantum *) NULL)
1697 for (x=0; x < (ssize_t) columns; x++)
1699 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1700 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1701 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1702 p+=GetPixelChannels(image);
1707 if (LocaleCompare(map,"RGBA") == 0)
1709 for (y=0; y < (ssize_t) rows; y++)
1711 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1712 if (p == (const Quantum *) NULL)
1714 for (x=0; x < (ssize_t) columns; x++)
1716 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1717 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1718 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1719 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1720 p+=GetPixelChannels(image);
1725 if (LocaleCompare(map,"RGBP") == 0)
1727 for (y=0; y < (ssize_t) rows; y++)
1729 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1730 if (p == (const Quantum *) NULL)
1732 for (x=0; x < (ssize_t) columns; x++)
1734 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1735 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1736 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1738 p+=GetPixelChannels(image);
1743 for (y=0; y < (ssize_t) rows; y++)
1745 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1746 if (p == (const Quantum *) NULL)
1748 for (x=0; x < (ssize_t) columns; x++)
1750 for (i=0; i < (ssize_t) length; i++)
1753 switch (quantum_map[i])
1758 *q=ScaleQuantumToShort(GetPixelRed(image,p));
1762 case MagentaQuantum:
1764 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
1770 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
1775 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1778 case OpacityQuantum:
1780 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1785 if (image->colorspace == CMYKColorspace)
1786 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
1791 *q=ScaleQuantumToShort(GetPixelIntensity(image,p));
1799 p+=GetPixelChannels(image);
1806 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1807 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1808 "UnrecognizedPixelMap","`%s'",map);
1812 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1817 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1821 % G e t P i x e l I n f o %
1825 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1827 % GetPixelInfo() initializes the PixelInfo structure.
1829 % The format of the GetPixelInfo method is:
1831 % GetPixelInfo(const Image *image,PixelInfo *pixel)
1833 % A description of each parameter follows:
1835 % o image: the image.
1837 % o pixel: Specifies a pointer to a PixelInfo structure.
1840 MagickExport void GetPixelInfo(const Image *image,PixelInfo *pixel)
1842 pixel->storage_class=DirectClass;
1843 pixel->colorspace=RGBColorspace;
1844 pixel->matte=MagickFalse;
1846 pixel->depth=MAGICKCORE_QUANTUM_DEPTH;
1851 pixel->alpha=(MagickRealType) OpaqueAlpha;
1853 if (image == (const Image *) NULL)
1855 pixel->storage_class=image->storage_class;
1856 pixel->colorspace=image->colorspace;
1857 pixel->matte=image->matte;
1858 pixel->depth=image->depth;
1859 pixel->fuzz=image->fuzz;
1863 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1867 % I m p o r t I m a g e P i x e l s %
1871 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1873 % ImportImagePixels() accepts pixel data and stores in the image at the
1874 % location you specify. The method returns MagickTrue on success otherwise
1875 % MagickFalse if an error is encountered. The pixel data can be either char,
1876 % short int, int, ssize_t, float, or double in the order specified by map.
1878 % Suppose your want to upload the first scanline of a 640x480 image from
1879 % character data in red-green-blue order:
1881 % ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels);
1883 % The format of the ImportImagePixels method is:
1885 % MagickBooleanType ImportImagePixels(Image *image,const ssize_t x_offset,
1886 % const ssize_t y_offset,const size_t columns,
1887 % const size_t rows,const char *map,const StorageType type,
1888 % const void *pixels,ExceptionInfo *exception)
1890 % A description of each parameter follows:
1892 % o image: the image.
1894 % o x_offset,y_offset,columns,rows: These values define the perimeter
1895 % of a region of pixels you want to define.
1897 % o map: This string reflects the expected ordering of the pixel array.
1898 % It can be any combination or order of R = red, G = green, B = blue,
1899 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
1900 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
1903 % o type: Define the data type of the pixels. Float and double types are
1904 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
1905 % types: CharPixel, ShortPixel, IntegerPixel, LongPixel, FloatPixel, or
1908 % o pixels: This array of values contain the pixel components as defined by
1909 % map and type. You must preallocate this array where the expected
1910 % length varies depending on the values of width, height, map, and type.
1912 % o exception: return any errors or warnings in this structure.
1915 MagickExport MagickBooleanType ImportImagePixels(Image *image,
1916 const ssize_t x_offset,const ssize_t y_offset,const size_t columns,
1917 const size_t rows,const char *map,const StorageType type,
1918 const void *pixels,ExceptionInfo *exception)
1937 Allocate image structure.
1939 assert(image != (Image *) NULL);
1940 assert(image->signature == MagickSignature);
1941 if (image->debug != MagickFalse)
1942 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1944 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1945 if (quantum_map == (QuantumType *) NULL)
1946 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1948 for (i=0; i < (ssize_t) length; i++)
1955 quantum_map[i]=AlphaQuantum;
1956 image->matte=MagickTrue;
1962 quantum_map[i]=BlueQuantum;
1968 quantum_map[i]=CyanQuantum;
1969 (void) SetImageColorspace(image,CMYKColorspace,exception);
1975 quantum_map[i]=GreenQuantum;
1981 quantum_map[i]=BlackQuantum;
1982 (void) SetImageColorspace(image,CMYKColorspace,exception);
1988 quantum_map[i]=IndexQuantum;
1994 quantum_map[i]=MagentaQuantum;
1995 (void) SetImageColorspace(image,CMYKColorspace,exception);
2001 quantum_map[i]=OpacityQuantum;
2002 image->matte=MagickTrue;
2008 quantum_map[i]=UndefinedQuantum;
2014 quantum_map[i]=RedQuantum;
2020 quantum_map[i]=YellowQuantum;
2021 (void) SetImageColorspace(image,CMYKColorspace,exception);
2026 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2027 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2028 "UnrecognizedPixelMap","`%s'",map);
2029 return(MagickFalse);
2033 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2034 return(MagickFalse);
2036 Transfer the pixels from the pixel datarray to the image.
2042 register const unsigned char
2045 p=(const unsigned char *) pixels;
2046 if (LocaleCompare(map,"BGR") == 0)
2048 for (y=0; y < (ssize_t) rows; y++)
2050 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2051 if (q == (Quantum *) NULL)
2053 for (x=0; x < (ssize_t) columns; x++)
2055 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2056 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2057 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2058 q+=GetPixelChannels(image);
2060 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2065 if (LocaleCompare(map,"BGRA") == 0)
2067 for (y=0; y < (ssize_t) rows; y++)
2069 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2070 if (q == (Quantum *) NULL)
2072 for (x=0; x < (ssize_t) columns; x++)
2074 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2075 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2076 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2077 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2078 q+=GetPixelChannels(image);
2080 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2085 if (LocaleCompare(map,"BGRO") == 0)
2087 for (y=0; y < (ssize_t) rows; y++)
2089 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2090 if (q == (Quantum *) NULL)
2092 for (x=0; x < (ssize_t) columns; x++)
2094 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2095 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2096 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2097 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2098 q+=GetPixelChannels(image);
2100 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2105 if (LocaleCompare(map,"BGRP") == 0)
2107 for (y=0; y < (ssize_t) rows; y++)
2109 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2110 if (q == (Quantum *) NULL)
2112 for (x=0; x < (ssize_t) columns; x++)
2114 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2115 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2116 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2118 q+=GetPixelChannels(image);
2120 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2125 if (LocaleCompare(map,"I") == 0)
2127 for (y=0; y < (ssize_t) rows; y++)
2129 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2130 if (q == (Quantum *) NULL)
2132 for (x=0; x < (ssize_t) columns; x++)
2134 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2135 SetPixelGreen(image,GetPixelRed(image,q),q);
2136 SetPixelBlue(image,GetPixelRed(image,q),q);
2137 q+=GetPixelChannels(image);
2139 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2144 if (LocaleCompare(map,"RGB") == 0)
2146 for (y=0; y < (ssize_t) rows; y++)
2148 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2149 if (q == (Quantum *) NULL)
2151 for (x=0; x < (ssize_t) columns; x++)
2153 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2154 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2155 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2156 q+=GetPixelChannels(image);
2158 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2163 if (LocaleCompare(map,"RGBA") == 0)
2165 for (y=0; y < (ssize_t) rows; y++)
2167 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2168 if (q == (Quantum *) NULL)
2170 for (x=0; x < (ssize_t) columns; x++)
2172 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2173 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2174 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2175 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2176 q+=GetPixelChannels(image);
2178 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2183 if (LocaleCompare(map,"RGBO") == 0)
2185 for (y=0; y < (ssize_t) rows; y++)
2187 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2188 if (q == (Quantum *) NULL)
2190 for (x=0; x < (ssize_t) columns; x++)
2192 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2193 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2194 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2195 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2196 q+=GetPixelChannels(image);
2198 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2203 if (LocaleCompare(map,"RGBP") == 0)
2205 for (y=0; y < (ssize_t) rows; y++)
2207 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2208 if (q == (Quantum *) NULL)
2210 for (x=0; x < (ssize_t) columns; x++)
2212 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2213 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2214 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2216 q+=GetPixelChannels(image);
2218 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2223 for (y=0; y < (ssize_t) rows; y++)
2225 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2226 if (q == (Quantum *) NULL)
2228 for (x=0; x < (ssize_t) columns; x++)
2230 for (i=0; i < (ssize_t) length; i++)
2232 switch (quantum_map[i])
2237 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2241 case MagentaQuantum:
2243 SetPixelGreen(image,ScaleCharToQuantum(*p),q);
2249 SetPixelBlue(image,ScaleCharToQuantum(*p),q);
2254 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2257 case OpacityQuantum:
2259 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2264 SetPixelBlack(image,ScaleCharToQuantum(*p),q);
2269 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2270 SetPixelGreen(image,GetPixelRed(image,q),q);
2271 SetPixelBlue(image,GetPixelRed(image,q),q);
2279 q+=GetPixelChannels(image);
2281 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2288 register const double
2291 p=(const double *) pixels;
2292 if (LocaleCompare(map,"BGR") == 0)
2294 for (y=0; y < (ssize_t) rows; y++)
2296 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2297 if (q == (Quantum *) NULL)
2299 for (x=0; x < (ssize_t) columns; x++)
2301 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2304 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2307 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2310 q+=GetPixelChannels(image);
2312 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2317 if (LocaleCompare(map,"BGRA") == 0)
2319 for (y=0; y < (ssize_t) rows; y++)
2321 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2322 if (q == (Quantum *) NULL)
2324 for (x=0; x < (ssize_t) columns; x++)
2326 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2329 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2332 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2335 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2338 q+=GetPixelChannels(image);
2340 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2345 if (LocaleCompare(map,"BGRP") == 0)
2347 for (y=0; y < (ssize_t) rows; y++)
2349 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2350 if (q == (Quantum *) NULL)
2352 for (x=0; x < (ssize_t) columns; x++)
2354 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2357 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2360 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2364 q+=GetPixelChannels(image);
2366 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2371 if (LocaleCompare(map,"I") == 0)
2373 for (y=0; y < (ssize_t) rows; y++)
2375 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2376 if (q == (Quantum *) NULL)
2378 for (x=0; x < (ssize_t) columns; x++)
2380 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2382 SetPixelGreen(image,GetPixelRed(image,q),q);
2383 SetPixelBlue(image,GetPixelRed(image,q),q);
2385 q+=GetPixelChannels(image);
2387 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2392 if (LocaleCompare(map,"RGB") == 0)
2394 for (y=0; y < (ssize_t) rows; y++)
2396 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2397 if (q == (Quantum *) NULL)
2399 for (x=0; x < (ssize_t) columns; x++)
2401 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2404 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2407 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2410 q+=GetPixelChannels(image);
2412 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2417 if (LocaleCompare(map,"RGBA") == 0)
2419 for (y=0; y < (ssize_t) rows; y++)
2421 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2422 if (q == (Quantum *) NULL)
2424 for (x=0; x < (ssize_t) columns; x++)
2426 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2429 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2432 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2435 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2438 q+=GetPixelChannels(image);
2440 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2445 if (LocaleCompare(map,"RGBP") == 0)
2447 for (y=0; y < (ssize_t) rows; y++)
2449 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2450 if (q == (Quantum *) NULL)
2452 for (x=0; x < (ssize_t) columns; x++)
2454 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2457 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2460 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2463 q+=GetPixelChannels(image);
2465 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2470 for (y=0; y < (ssize_t) rows; y++)
2472 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2473 if (q == (Quantum *) NULL)
2475 for (x=0; x < (ssize_t) columns; x++)
2477 for (i=0; i < (ssize_t) length; i++)
2479 switch (quantum_map[i])
2484 SetPixelRed(image,ClampToQuantum((MagickRealType)
2485 QuantumRange*(*p)),q);
2489 case MagentaQuantum:
2491 SetPixelGreen(image,ClampToQuantum((MagickRealType)
2492 QuantumRange*(*p)),q);
2498 SetPixelBlue(image,ClampToQuantum((MagickRealType)
2499 QuantumRange*(*p)),q);
2504 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2505 QuantumRange*(*p)),q);
2508 case OpacityQuantum:
2510 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2511 QuantumRange*(*p)),q);
2516 SetPixelBlack(image,ClampToQuantum((MagickRealType)
2517 QuantumRange*(*p)),q);
2522 SetPixelRed(image,ClampToQuantum((MagickRealType)
2523 QuantumRange*(*p)),q);
2524 SetPixelGreen(image,GetPixelRed(image,q),q);
2525 SetPixelBlue(image,GetPixelRed(image,q),q);
2533 q+=GetPixelChannels(image);
2535 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2542 register const float
2545 p=(const float *) pixels;
2546 if (LocaleCompare(map,"BGR") == 0)
2548 for (y=0; y < (ssize_t) rows; y++)
2550 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2551 if (q == (Quantum *) NULL)
2553 for (x=0; x < (ssize_t) columns; x++)
2555 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2558 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2561 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2564 q+=GetPixelChannels(image);
2566 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2571 if (LocaleCompare(map,"BGRA") == 0)
2573 for (y=0; y < (ssize_t) rows; y++)
2575 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2576 if (q == (Quantum *) NULL)
2578 for (x=0; x < (ssize_t) columns; x++)
2580 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2583 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2586 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2589 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2592 q+=GetPixelChannels(image);
2594 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2599 if (LocaleCompare(map,"BGRP") == 0)
2601 for (y=0; y < (ssize_t) rows; y++)
2603 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2604 if (q == (Quantum *) NULL)
2606 for (x=0; x < (ssize_t) columns; x++)
2608 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2611 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2614 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2618 q+=GetPixelChannels(image);
2620 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2625 if (LocaleCompare(map,"I") == 0)
2627 for (y=0; y < (ssize_t) rows; y++)
2629 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2630 if (q == (Quantum *) NULL)
2632 for (x=0; x < (ssize_t) columns; x++)
2634 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2636 SetPixelGreen(image,GetPixelRed(image,q),q);
2637 SetPixelBlue(image,GetPixelRed(image,q),q);
2639 q+=GetPixelChannels(image);
2641 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2646 if (LocaleCompare(map,"RGB") == 0)
2648 for (y=0; y < (ssize_t) rows; y++)
2650 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2651 if (q == (Quantum *) NULL)
2653 for (x=0; x < (ssize_t) columns; x++)
2655 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2658 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2661 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2664 q+=GetPixelChannels(image);
2666 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2671 if (LocaleCompare(map,"RGBA") == 0)
2673 for (y=0; y < (ssize_t) rows; y++)
2675 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2676 if (q == (Quantum *) NULL)
2678 for (x=0; x < (ssize_t) columns; x++)
2680 SetPixelRed(image,ClampToQuantum((MagickRealType)
2681 QuantumRange*(*p)),q);
2683 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2686 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2689 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2692 q+=GetPixelChannels(image);
2694 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2699 if (LocaleCompare(map,"RGBP") == 0)
2701 for (y=0; y < (ssize_t) rows; y++)
2703 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2704 if (q == (Quantum *) NULL)
2706 for (x=0; x < (ssize_t) columns; x++)
2708 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2711 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2714 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2717 q+=GetPixelChannels(image);
2719 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2724 for (y=0; y < (ssize_t) rows; y++)
2726 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2727 if (q == (Quantum *) NULL)
2729 for (x=0; x < (ssize_t) columns; x++)
2731 for (i=0; i < (ssize_t) length; i++)
2733 switch (quantum_map[i])
2738 SetPixelRed(image,ClampToQuantum((MagickRealType)
2739 QuantumRange*(*p)),q);
2743 case MagentaQuantum:
2745 SetPixelGreen(image,ClampToQuantum((MagickRealType)
2746 QuantumRange*(*p)),q);
2752 SetPixelBlue(image,ClampToQuantum((MagickRealType)
2753 QuantumRange*(*p)),q);
2758 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2759 QuantumRange*(*p)),q);
2762 case OpacityQuantum:
2764 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2765 QuantumRange*(*p)),q);
2770 SetPixelBlack(image,ClampToQuantum((MagickRealType)
2771 QuantumRange*(*p)),q);
2776 SetPixelRed(image,ClampToQuantum((MagickRealType)
2777 QuantumRange*(*p)),q);
2778 SetPixelGreen(image,GetPixelRed(image,q),q);
2779 SetPixelBlue(image,GetPixelRed(image,q),q);
2787 q+=GetPixelChannels(image);
2789 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2796 register const unsigned int
2799 p=(const unsigned int *) pixels;
2800 if (LocaleCompare(map,"BGR") == 0)
2802 for (y=0; y < (ssize_t) rows; y++)
2804 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2805 if (q == (Quantum *) NULL)
2807 for (x=0; x < (ssize_t) columns; x++)
2809 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2810 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2811 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2812 q+=GetPixelChannels(image);
2814 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2819 if (LocaleCompare(map,"BGRA") == 0)
2821 for (y=0; y < (ssize_t) rows; y++)
2823 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2824 if (q == (Quantum *) NULL)
2826 for (x=0; x < (ssize_t) columns; x++)
2828 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2829 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2830 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2831 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
2832 q+=GetPixelChannels(image);
2834 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2839 if (LocaleCompare(map,"BGRP") == 0)
2841 for (y=0; y < (ssize_t) rows; y++)
2843 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2844 if (q == (Quantum *) NULL)
2846 for (x=0; x < (ssize_t) columns; x++)
2848 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2849 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2850 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2852 q+=GetPixelChannels(image);
2854 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2859 if (LocaleCompare(map,"I") == 0)
2861 for (y=0; y < (ssize_t) rows; y++)
2863 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2864 if (q == (Quantum *) NULL)
2866 for (x=0; x < (ssize_t) columns; x++)
2868 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2869 SetPixelGreen(image,GetPixelRed(image,q),q);
2870 SetPixelBlue(image,GetPixelRed(image,q),q);
2871 q+=GetPixelChannels(image);
2873 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2878 if (LocaleCompare(map,"RGB") == 0)
2880 for (y=0; y < (ssize_t) rows; y++)
2882 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2883 if (q == (Quantum *) NULL)
2885 for (x=0; x < (ssize_t) columns; x++)
2887 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2888 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2889 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2890 q+=GetPixelChannels(image);
2892 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2897 if (LocaleCompare(map,"RGBA") == 0)
2899 for (y=0; y < (ssize_t) rows; y++)
2901 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2902 if (q == (Quantum *) NULL)
2904 for (x=0; x < (ssize_t) columns; x++)
2906 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2907 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2908 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2909 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
2910 q+=GetPixelChannels(image);
2912 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2917 if (LocaleCompare(map,"RGBP") == 0)
2919 for (y=0; y < (ssize_t) rows; y++)
2921 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2922 if (q == (Quantum *) NULL)
2924 for (x=0; x < (ssize_t) columns; x++)
2926 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2927 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2928 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2930 q+=GetPixelChannels(image);
2932 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2937 for (y=0; y < (ssize_t) rows; y++)
2939 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2940 if (q == (Quantum *) NULL)
2942 for (x=0; x < (ssize_t) columns; x++)
2944 for (i=0; i < (ssize_t) length; i++)
2946 switch (quantum_map[i])
2951 SetPixelRed(image,ScaleLongToQuantum(*p),q);
2955 case MagentaQuantum:
2957 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
2963 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
2968 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
2971 case OpacityQuantum:
2973 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
2978 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
2983 SetPixelRed(image,ScaleLongToQuantum(*p),q);
2984 SetPixelGreen(image,GetPixelRed(image,q),q);
2985 SetPixelBlue(image,GetPixelRed(image,q),q);
2993 q+=GetPixelChannels(image);
2995 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3002 register const unsigned int
3005 p=(const unsigned int *) pixels;
3006 if (LocaleCompare(map,"BGR") == 0)
3008 for (y=0; y < (ssize_t) rows; y++)
3010 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3011 if (q == (Quantum *) NULL)
3013 for (x=0; x < (ssize_t) columns; x++)
3015 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3016 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3017 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3018 q+=GetPixelChannels(image);
3020 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3025 if (LocaleCompare(map,"BGRA") == 0)
3027 for (y=0; y < (ssize_t) rows; y++)
3029 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3030 if (q == (Quantum *) NULL)
3032 for (x=0; x < (ssize_t) columns; x++)
3034 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3035 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3036 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3037 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3038 q+=GetPixelChannels(image);
3040 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3045 if (LocaleCompare(map,"BGRP") == 0)
3047 for (y=0; y < (ssize_t) rows; y++)
3049 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3050 if (q == (Quantum *) NULL)
3052 for (x=0; x < (ssize_t) columns; x++)
3054 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3055 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3056 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3058 q+=GetPixelChannels(image);
3060 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3065 if (LocaleCompare(map,"I") == 0)
3067 for (y=0; y < (ssize_t) rows; y++)
3069 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3070 if (q == (Quantum *) NULL)
3072 for (x=0; x < (ssize_t) columns; x++)
3074 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3075 SetPixelGreen(image,GetPixelRed(image,q),q);
3076 SetPixelBlue(image,GetPixelRed(image,q),q);
3077 q+=GetPixelChannels(image);
3079 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3084 if (LocaleCompare(map,"RGB") == 0)
3086 for (y=0; y < (ssize_t) rows; y++)
3088 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3089 if (q == (Quantum *) NULL)
3091 for (x=0; x < (ssize_t) columns; x++)
3093 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3094 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3095 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3096 q+=GetPixelChannels(image);
3098 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3103 if (LocaleCompare(map,"RGBA") == 0)
3105 for (y=0; y < (ssize_t) rows; y++)
3107 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3108 if (q == (Quantum *) NULL)
3110 for (x=0; x < (ssize_t) columns; x++)
3112 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3113 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3114 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3115 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3116 q+=GetPixelChannels(image);
3118 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3123 if (LocaleCompare(map,"RGBP") == 0)
3125 for (y=0; y < (ssize_t) rows; y++)
3127 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3128 if (q == (Quantum *) NULL)
3130 for (x=0; x < (ssize_t) columns; x++)
3132 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3133 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3134 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3136 q+=GetPixelChannels(image);
3138 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3143 for (y=0; y < (ssize_t) rows; y++)
3145 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3146 if (q == (Quantum *) NULL)
3148 for (x=0; x < (ssize_t) columns; x++)
3150 for (i=0; i < (ssize_t) length; i++)
3152 switch (quantum_map[i])
3157 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3161 case MagentaQuantum:
3163 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
3169 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
3174 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3177 case OpacityQuantum:
3179 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3184 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
3189 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3190 SetPixelGreen(image,GetPixelRed(image,q),q);
3191 SetPixelBlue(image,GetPixelRed(image,q),q);
3199 q+=GetPixelChannels(image);
3201 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3208 register const Quantum
3211 p=(const Quantum *) pixels;
3212 if (LocaleCompare(map,"BGR") == 0)
3214 for (y=0; y < (ssize_t) rows; y++)
3216 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3217 if (q == (Quantum *) NULL)
3219 for (x=0; x < (ssize_t) columns; x++)
3221 SetPixelBlue(image,*p++,q);
3222 SetPixelGreen(image,*p++,q);
3223 SetPixelRed(image,*p++,q);
3224 q+=GetPixelChannels(image);
3226 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3231 if (LocaleCompare(map,"BGRA") == 0)
3233 for (y=0; y < (ssize_t) rows; y++)
3235 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3236 if (q == (Quantum *) NULL)
3238 for (x=0; x < (ssize_t) columns; x++)
3240 SetPixelBlue(image,*p++,q);
3241 SetPixelGreen(image,*p++,q);
3242 SetPixelRed(image,*p++,q);
3243 SetPixelAlpha(image,*p++,q);
3244 q+=GetPixelChannels(image);
3246 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3251 if (LocaleCompare(map,"BGRP") == 0)
3253 for (y=0; y < (ssize_t) rows; y++)
3255 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3256 if (q == (Quantum *) NULL)
3258 for (x=0; x < (ssize_t) columns; x++)
3260 SetPixelBlue(image,*p++,q);
3261 SetPixelGreen(image,*p++,q);
3262 SetPixelRed(image,*p++,q);
3264 q+=GetPixelChannels(image);
3266 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3271 if (LocaleCompare(map,"I") == 0)
3273 for (y=0; y < (ssize_t) rows; y++)
3275 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3276 if (q == (Quantum *) NULL)
3278 for (x=0; x < (ssize_t) columns; x++)
3280 SetPixelRed(image,*p++,q);
3281 SetPixelGreen(image,GetPixelRed(image,q),q);
3282 SetPixelBlue(image,GetPixelRed(image,q),q);
3283 q+=GetPixelChannels(image);
3285 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3290 if (LocaleCompare(map,"RGB") == 0)
3292 for (y=0; y < (ssize_t) rows; y++)
3294 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3295 if (q == (Quantum *) NULL)
3297 for (x=0; x < (ssize_t) columns; x++)
3299 SetPixelRed(image,*p++,q);
3300 SetPixelGreen(image,*p++,q);
3301 SetPixelBlue(image,*p++,q);
3302 q+=GetPixelChannels(image);
3304 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3309 if (LocaleCompare(map,"RGBA") == 0)
3311 for (y=0; y < (ssize_t) rows; y++)
3313 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3314 if (q == (Quantum *) NULL)
3316 for (x=0; x < (ssize_t) columns; x++)
3318 SetPixelRed(image,*p++,q);
3319 SetPixelGreen(image,*p++,q);
3320 SetPixelBlue(image,*p++,q);
3321 SetPixelAlpha(image,*p++,q);
3322 q+=GetPixelChannels(image);
3324 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3329 if (LocaleCompare(map,"RGBP") == 0)
3331 for (y=0; y < (ssize_t) rows; y++)
3333 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3334 if (q == (Quantum *) NULL)
3336 for (x=0; x < (ssize_t) columns; x++)
3338 SetPixelRed(image,*p++,q);
3339 SetPixelGreen(image,*p++,q);
3340 SetPixelBlue(image,*p++,q);
3342 q+=GetPixelChannels(image);
3344 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3349 for (y=0; y < (ssize_t) rows; y++)
3351 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3352 if (q == (Quantum *) NULL)
3354 for (x=0; x < (ssize_t) columns; x++)
3356 for (i=0; i < (ssize_t) length; i++)
3358 switch (quantum_map[i])
3363 SetPixelRed(image,*p,q);
3367 case MagentaQuantum:
3369 SetPixelGreen(image,*p,q);
3375 SetPixelBlue(image,*p,q);
3380 SetPixelAlpha(image,*p,q);
3383 case OpacityQuantum:
3385 SetPixelAlpha(image,*p,q);
3390 SetPixelBlack(image,*p,q);
3395 SetPixelRed(image,*p,q);
3396 SetPixelGreen(image,GetPixelRed(image,q),q);
3397 SetPixelBlue(image,GetPixelRed(image,q),q);
3405 q+=GetPixelChannels(image);
3407 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3414 register const unsigned short
3417 p=(const unsigned short *) pixels;
3418 if (LocaleCompare(map,"BGR") == 0)
3420 for (y=0; y < (ssize_t) rows; y++)
3422 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3423 if (q == (Quantum *) NULL)
3425 for (x=0; x < (ssize_t) columns; x++)
3427 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3428 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3429 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3430 q+=GetPixelChannels(image);
3432 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3437 if (LocaleCompare(map,"BGRA") == 0)
3439 for (y=0; y < (ssize_t) rows; y++)
3441 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3442 if (q == (Quantum *) NULL)
3444 for (x=0; x < (ssize_t) columns; x++)
3446 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3447 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3448 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3449 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3450 q+=GetPixelChannels(image);
3452 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3457 if (LocaleCompare(map,"BGRP") == 0)
3459 for (y=0; y < (ssize_t) rows; y++)
3461 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3462 if (q == (Quantum *) NULL)
3464 for (x=0; x < (ssize_t) columns; x++)
3466 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3467 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3468 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3470 q+=GetPixelChannels(image);
3472 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3477 if (LocaleCompare(map,"I") == 0)
3479 for (y=0; y < (ssize_t) rows; y++)
3481 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3482 if (q == (Quantum *) NULL)
3484 for (x=0; x < (ssize_t) columns; x++)
3486 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3487 SetPixelGreen(image,GetPixelRed(image,q),q);
3488 SetPixelBlue(image,GetPixelRed(image,q),q);
3489 q+=GetPixelChannels(image);
3491 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3496 if (LocaleCompare(map,"RGB") == 0)
3498 for (y=0; y < (ssize_t) rows; y++)
3500 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3501 if (q == (Quantum *) NULL)
3503 for (x=0; x < (ssize_t) columns; x++)
3505 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3506 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3507 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3508 q+=GetPixelChannels(image);
3510 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3515 if (LocaleCompare(map,"RGBA") == 0)
3517 for (y=0; y < (ssize_t) rows; y++)
3519 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3520 if (q == (Quantum *) NULL)
3522 for (x=0; x < (ssize_t) columns; x++)
3524 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3525 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3526 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3527 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3528 q+=GetPixelChannels(image);
3530 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3535 if (LocaleCompare(map,"RGBP") == 0)
3537 for (y=0; y < (ssize_t) rows; y++)
3539 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3540 if (q == (Quantum *) NULL)
3542 for (x=0; x < (ssize_t) columns; x++)
3544 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3545 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3546 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3548 q+=GetPixelChannels(image);
3550 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3555 for (y=0; y < (ssize_t) rows; y++)
3557 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3558 if (q == (Quantum *) NULL)
3560 for (x=0; x < (ssize_t) columns; x++)
3562 for (i=0; i < (ssize_t) length; i++)
3564 switch (quantum_map[i])
3569 SetPixelRed(image,ScaleShortToQuantum(*p),q);
3573 case MagentaQuantum:
3575 SetPixelGreen(image,ScaleShortToQuantum(*p),q);
3581 SetPixelBlue(image,ScaleShortToQuantum(*p),q);
3586 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3589 case OpacityQuantum:
3591 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3596 SetPixelBlack(image,ScaleShortToQuantum(*p),q);
3601 SetPixelRed(image,ScaleShortToQuantum(*p),q);
3602 SetPixelGreen(image,GetPixelRed(image,q),q);
3603 SetPixelBlue(image,GetPixelRed(image,q),q);
3611 q+=GetPixelChannels(image);
3613 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3620 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3621 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3622 "UnrecognizedPixelMap","`%s'",map);
3626 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3635 + 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 %
3639 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3641 % InitializePixelChannelMap() defines the standard pixel component map.
3643 % The format of the InitializePixelChannelMap() method is:
3645 % void InitializePixelChannelMap(Image *image)
3647 % A description of each parameter follows:
3649 % o image: the image.
3652 MagickExport void InitializePixelChannelMap(Image *image)
3663 assert(image != (Image *) NULL);
3664 assert(image->signature == MagickSignature);
3665 (void) ResetMagickMemory(image->channel_map,0,MaxPixelChannels*
3666 sizeof(*image->channel_map));
3667 trait=UpdatePixelTrait;
3668 if (image->matte != MagickFalse)
3669 trait=(PixelTrait) (trait | BlendPixelTrait);
3671 if (0 && image->colorspace == GRAYColorspace)
3673 SetPixelChannelMap(image,BluePixelChannel,trait,n);
3674 SetPixelChannelMap(image,GreenPixelChannel,trait,n);
3675 SetPixelChannelMap(image,RedPixelChannel,trait,n++);
3679 SetPixelChannelMap(image,RedPixelChannel,trait,n++);
3680 SetPixelChannelMap(image,GreenPixelChannel,trait,n++);
3681 SetPixelChannelMap(image,BluePixelChannel,trait,n++);
3683 if (image->colorspace == CMYKColorspace)
3684 SetPixelChannelMap(image,BlackPixelChannel,trait,n++);
3685 if (image->matte != MagickFalse)
3686 SetPixelChannelMap(image,AlphaPixelChannel,CopyPixelTrait,n++);
3687 if (image->storage_class == PseudoClass)
3688 SetPixelChannelMap(image,IndexPixelChannel,CopyPixelTrait,n++);
3689 assert((n+image->number_meta_channels) < MaxPixelChannels);
3690 for (i=0; i < (ssize_t) image->number_meta_channels; i++)
3691 SetPixelChannelMap(image,(PixelChannel) (MetaPixelChannel+i),CopyPixelTrait,
3693 image->number_channels=(size_t) n;
3694 if (image->debug != MagickFalse)
3695 LogPixelChannels(image);
3696 (void) SetPixelChannelMask(image,image->channel_mask);
3700 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3704 % I n t e r p o l a t e P i x e l C h a n n e l %
3708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3710 % InterpolatePixelChannel() applies a pixel interpolation method between a
3711 % floating point coordinate and the pixels surrounding that coordinate. No
3712 % pixel area resampling, or scaling of the result is performed.
3714 % The format of the InterpolatePixelChannel method is:
3716 % MagickBooleanType InterpolatePixelChannel(const Image *image,
3717 % const CacheView *image_view,const PixelChannel channel,
3718 % const PixelInterpolateMethod method,const double x,const double y,
3719 % double *pixel,ExceptionInfo *exception)
3721 % A description of each parameter follows:
3723 % o image: the image.
3725 % o image_view: the image view.
3727 % o channel: the pixel channel to interpolate.
3729 % o method: the pixel color interpolation method.
3731 % o x,y: A double representing the current (x,y) position of the pixel.
3733 % o pixel: return the interpolated pixel here.
3735 % o exception: return any errors or warnings in this structure.
3739 static inline double MagickMax(const MagickRealType x,const MagickRealType y)
3746 static inline MagickRealType CubicWeightingFunction(const MagickRealType x)
3752 alpha=MagickMax(x+2.0,0.0);
3753 gamma=1.0*alpha*alpha*alpha;
3754 alpha=MagickMax(x+1.0,0.0);
3755 gamma-=4.0*alpha*alpha*alpha;
3756 alpha=MagickMax(x+0.0,0.0);
3757 gamma+=6.0*alpha*alpha*alpha;
3758 alpha=MagickMax(x-1.0,0.0);
3759 gamma-=4.0*alpha*alpha*alpha;
3763 static inline double MeshInterpolate(const PointInfo *delta,const double p,
3764 const double x,const double y)
3766 return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
3769 static inline ssize_t NearestNeighbor(const MagickRealType x)
3772 return((ssize_t) (x+0.5));
3773 return((ssize_t) (x-0.5));
3776 MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
3777 const CacheView *image_view,const PixelChannel channel,
3778 const PixelInterpolateMethod method,const double x,const double y,
3779 double *pixel,ExceptionInfo *exception)
3792 register const Quantum
3802 assert(image != (Image *) NULL);
3803 assert(image != (Image *) NULL);
3804 assert(image->signature == MagickSignature);
3805 assert(image_view != (CacheView *) NULL);
3808 traits=GetPixelChannelMapTraits(image,channel);
3809 x_offset=(ssize_t) floor(x);
3810 y_offset=(ssize_t) floor(y);
3811 switch (method == UndefinedInterpolatePixel ? image->interpolate : method)
3813 case AverageInterpolatePixel:
3815 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
3817 if (p == (const Quantum *) NULL)
3822 if ((traits & BlendPixelTrait) == 0)
3823 for (i=0; i < 16; i++)
3826 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
3829 for (i=0; i < 16; i++)
3831 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
3832 GetPixelChannels(image));
3833 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
3835 for (i=0; i < 16; i++)
3837 gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]);
3838 *pixel+=gamma*0.0625*pixels[i];
3842 case BicubicInterpolatePixel:
3851 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
3853 if (p == (const Quantum *) NULL)
3858 if ((traits & BlendPixelTrait) == 0)
3859 for (i=0; i < 16; i++)
3862 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
3865 for (i=0; i < 16; i++)
3867 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
3868 GetPixelChannels(image));
3869 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
3873 for (i=0; i < 4; i++)
3875 u[0]=(pixels[4*i+3]-pixels[4*i+2])-(pixels[4*i+0]-pixels[4*i+1]);
3876 u[1]=(pixels[4*i+0]-pixels[4*i+1])-u[0];
3877 u[2]=pixels[4*i+2]-pixels[4*i+0];
3879 v[i]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x*
3882 u[0]=(v[3]-v[2])-(v[0]-v[1]);
3883 u[1]=(v[0]-v[1])-u[0];
3886 *pixel=(delta.y*delta.y*delta.y*u[0])+(delta.y*delta.y*u[1])+(delta.y*
3890 case BilinearInterpolatePixel:
3897 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
3898 if (p == (const Quantum *) NULL)
3903 if ((traits & BlendPixelTrait) == 0)
3904 for (i=0; i < 4; i++)
3907 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
3910 for (i=0; i < 4; i++)
3912 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
3913 GetPixelChannels(image));
3914 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
3918 epsilon.x=1.0-delta.x;
3919 epsilon.y=1.0-delta.y;
3920 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
3921 (epsilon.x*alpha[2]+delta.x*alpha[3])));
3922 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3923 *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
3924 (epsilon.x*pixels[2]+delta.x*pixels[3]));
3927 case FilterInterpolatePixel:
3941 geometry.x=x_offset-1;
3942 geometry.y=y_offset-1;
3943 excerpt_image=ExcerptImage(image,&geometry,exception);
3944 if (excerpt_image == (Image *) NULL)
3949 filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur,
3951 excerpt_image=DestroyImage(excerpt_image);
3952 if (filter_image == (Image *) NULL)
3954 filter_view=AcquireCacheView(filter_image);
3955 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
3956 if (p == (const Quantum *) NULL)
3959 *pixel=(double) GetPixelChannel(image,channel,p);
3960 filter_view=DestroyCacheView(filter_view);
3961 filter_image=DestroyImage(filter_image);
3964 case IntegerInterpolatePixel:
3966 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
3967 if (p == (const Quantum *) NULL)
3972 *pixel=(double) GetPixelChannel(image,channel,p);
3975 case NearestNeighborInterpolatePixel:
3977 p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
3978 NearestNeighbor(y),1,1,exception);
3979 if (p == (const Quantum *) NULL)
3984 *pixel=(double) GetPixelChannel(image,channel,p);
3987 case MeshInterpolatePixel:
3993 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
3994 if (p == (const Quantum *) NULL)
3999 if ((traits & BlendPixelTrait) == 0)
4000 for (i=0; i < 4; i++)
4003 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4006 for (i=0; i < 4; i++)
4008 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4009 GetPixelChannels(image));
4010 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4014 luminance.x=GetPixelLuminance(image,p)-(double)
4015 GetPixelLuminance(image,p+3*GetPixelChannels(image));
4016 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
4017 GetPixelLuminance(image,p+2*GetPixelChannels(image));
4018 if (fabs(luminance.x) < fabs(luminance.y))
4023 if (delta.x <= delta.y)
4026 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4028 delta.y=1.0-delta.y;
4029 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4030 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4031 *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
4037 Top-right triangle (pixel: 1, diagonal: 0-3).
4039 delta.x=1.0-delta.x;
4040 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4041 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4042 *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
4051 if (delta.x <= (1.0-delta.y))
4054 Top-left triangle (pixel: 0, diagonal: 1-2).
4056 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4057 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4058 *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
4064 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4066 delta.x=1.0-delta.x;
4067 delta.y=1.0-delta.y;
4068 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4069 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4070 *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
4076 case SplineInterpolatePixel:
4089 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4091 if (p == (const Quantum *) NULL)
4096 if ((traits & BlendPixelTrait) == 0)
4097 for (i=0; i < 16; i++)
4100 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4103 for (i=0; i < 16; i++)
4105 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4106 GetPixelChannels(image));
4107 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4112 for (i=(-1); i < 3L; i++)
4114 dy=CubicWeightingFunction((MagickRealType) i-delta.y);
4115 for (j=(-1); j < 3L; j++)
4117 dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
4118 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]);
4119 *pixel+=gamma*dx*dy*pixels[n];
4130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4134 % I n t e r p o l a t e P i x e l C h a n n e l s %
4138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4140 % InterpolatePixelChannels() applies a pixel interpolation method between a
4141 % floating point coordinate and the pixels surrounding that coordinate. No
4142 % pixel area resampling, or scaling of the result is performed.
4144 % The format of the InterpolatePixelChannels method is:
4146 % MagickBooleanType InterpolatePixelChannels(const Image *source,
4147 % const CacheView *source_view,const Image *destination,
4148 % const PixelInterpolateMethod method,const double x,const double y,
4149 % Quantum *pixel,ExceptionInfo *exception)
4151 % A description of each parameter follows:
4153 % o source: the source.
4155 % o source_view: the source view.
4157 % o destination: the destination image.
4159 % o method: the pixel color interpolation method.
4161 % o x,y: A double representing the current (x,y) position of the pixel.
4163 % o pixel: return the interpolated pixel here.
4165 % o exception: return any errors or warnings in this structure.
4168 MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
4169 const CacheView *source_view,const Image *destination,
4170 const PixelInterpolateMethod method,const double x,const double y,
4171 Quantum *pixel,ExceptionInfo *exception)
4188 register const Quantum
4198 assert(source != (Image *) NULL);
4199 assert(source != (Image *) NULL);
4200 assert(source->signature == MagickSignature);
4201 assert(source_view != (CacheView *) NULL);
4203 x_offset=(ssize_t) floor(x);
4204 y_offset=(ssize_t) floor(y);
4205 switch (method == UndefinedInterpolatePixel ? source->interpolate : method)
4207 case AverageInterpolatePixel:
4209 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4211 if (p == (const Quantum *) NULL)
4216 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4224 channel=GetPixelChannelMapChannel(source,i);
4225 traits=GetPixelChannelMapTraits(source,channel);
4226 destination_traits=GetPixelChannelMapTraits(destination,channel);
4227 if ((traits == UndefinedPixelTrait) ||
4228 (destination_traits == UndefinedPixelTrait))
4230 for (j=0; j < 16; j++)
4231 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4233 if ((traits & BlendPixelTrait) == 0)
4235 for (j=0; j < 16; j++)
4236 sum+=0.0625*pixels[j];
4237 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4240 for (j=0; j < 16; j++)
4242 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4243 GetPixelChannels(source));
4244 pixels[j]*=alpha[j];
4245 gamma=1.0/(fabs((double) alpha[j]) <= MagickEpsilon ? 1.0 : alpha[j]);
4246 sum+=gamma*0.0625*pixels[j];
4248 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4252 case BicubicInterpolatePixel:
4261 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4263 if (p == (const Quantum *) NULL)
4268 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4273 channel=GetPixelChannelMapChannel(source,i);
4274 traits=GetPixelChannelMapTraits(source,channel);
4275 destination_traits=GetPixelChannelMapTraits(destination,channel);
4276 if ((traits == UndefinedPixelTrait) ||
4277 (destination_traits == UndefinedPixelTrait))
4279 if ((traits & BlendPixelTrait) == 0)
4280 for (j=0; j < 16; j++)
4283 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4286 for (j=0; j < 16; j++)
4288 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4289 GetPixelChannels(source));
4290 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4294 for (j=0; j < 4; j++)
4296 u[0]=(pixels[4*j+3]-pixels[4*j+2])-(pixels[4*j+0]-pixels[4*j+1]);
4297 u[1]=(pixels[4*j+0]-pixels[4*j+1])-u[0];
4298 u[2]=pixels[4*j+2]-pixels[4*j+0];
4300 v[j]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x*
4303 u[0]=(v[3]-v[2])-(v[0]-v[1]);
4304 u[1]=(v[0]-v[1])-u[0];
4307 SetPixelChannel(destination,channel,ClampToQuantum((delta.y*delta.y*
4308 delta.y*u[0])+(delta.y*delta.y*u[1])+(delta.y*u[2])+u[3]),pixel);
4312 case BilinearInterpolatePixel:
4315 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4316 if (p == (const Quantum *) NULL)
4321 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4327 channel=GetPixelChannelMapChannel(source,i);
4328 traits=GetPixelChannelMapTraits(source,channel);
4329 destination_traits=GetPixelChannelMapTraits(destination,channel);
4330 if ((traits == UndefinedPixelTrait) ||
4331 (destination_traits == UndefinedPixelTrait))
4335 epsilon.x=1.0-delta.x;
4336 epsilon.y=1.0-delta.y;
4337 pixels[0]=(MagickRealType) p[i];
4338 pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i];
4339 pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i];
4340 pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i];
4341 if ((traits & BlendPixelTrait) == 0)
4343 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
4344 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4345 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4346 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*
4347 pixels[2]+delta.x*pixels[3]))),pixel);
4350 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4351 alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source));
4352 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4353 GetPixelChannels(source));
4354 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4355 GetPixelChannels(source));
4356 pixels[0]*=alpha[0];
4357 pixels[1]*=alpha[1];
4358 pixels[2]*=alpha[2];
4359 pixels[3]*=alpha[3];
4360 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4361 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4362 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4363 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4364 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+
4365 delta.x*pixels[3]))),pixel);
4369 case FilterInterpolatePixel:
4371 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4383 channel=GetPixelChannelMapChannel(source,i);
4384 traits=GetPixelChannelMapTraits(source,channel);
4385 destination_traits=GetPixelChannelMapTraits(destination,channel);
4386 if ((traits == UndefinedPixelTrait) ||
4387 (destination_traits == UndefinedPixelTrait))
4391 geometry.x=x_offset-1;
4392 geometry.y=y_offset-1;
4393 excerpt_source=ExcerptImage(source,&geometry,exception);
4394 if (excerpt_source == (Image *) NULL)
4399 filter_source=ResizeImage(excerpt_source,1,1,source->filter,
4400 source->blur,exception);
4401 excerpt_source=DestroyImage(excerpt_source);
4402 if (filter_source == (Image *) NULL)
4404 filter_view=AcquireCacheView(filter_source);
4405 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4406 if (p == (const Quantum *) NULL)
4410 SetPixelChannel(destination,channel,p[i],pixel);
4412 filter_view=DestroyCacheView(filter_view);
4413 filter_source=DestroyImage(filter_source);
4417 case IntegerInterpolatePixel:
4419 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
4420 if (p == (const Quantum *) NULL)
4425 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4427 channel=GetPixelChannelMapChannel(source,i);
4428 traits=GetPixelChannelMapTraits(source,channel);
4429 destination_traits=GetPixelChannelMapTraits(destination,channel);
4430 if ((traits == UndefinedPixelTrait) ||
4431 (destination_traits == UndefinedPixelTrait))
4433 SetPixelChannel(destination,channel,p[i],pixel);
4437 case NearestNeighborInterpolatePixel:
4439 p=GetCacheViewVirtualPixels(source_view,NearestNeighbor(x),
4440 NearestNeighbor(y),1,1,exception);
4441 if (p == (const Quantum *) NULL)
4446 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4448 channel=GetPixelChannelMapChannel(source,i);
4449 traits=GetPixelChannelMapTraits(source,channel);
4450 destination_traits=GetPixelChannelMapTraits(destination,channel);
4451 if ((traits == UndefinedPixelTrait) ||
4452 (destination_traits == UndefinedPixelTrait))
4454 SetPixelChannel(destination,channel,p[i],pixel);
4458 case MeshInterpolatePixel:
4460 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4461 if (p == (const Quantum *) NULL)
4466 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4472 channel=GetPixelChannelMapChannel(source,i);
4473 traits=GetPixelChannelMapTraits(source,channel);
4474 destination_traits=GetPixelChannelMapTraits(destination,channel);
4475 if ((traits == UndefinedPixelTrait) ||
4476 (destination_traits == UndefinedPixelTrait))
4478 pixels[0]=(MagickRealType) p[i];
4479 pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i];
4480 pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i];
4481 pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i];
4482 if ((traits & BlendPixelTrait) == 0)
4491 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4492 alpha[1]=QuantumScale*GetPixelAlpha(source,p+
4493 GetPixelChannels(source));
4494 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4495 GetPixelChannels(source));
4496 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4497 GetPixelChannels(source));
4501 luminance.x=GetPixelLuminance(source,p)-(double)
4502 GetPixelLuminance(source,p+3*GetPixelChannels(source));
4503 luminance.y=GetPixelLuminance(source,p+GetPixelChannels(source))-
4504 (double) GetPixelLuminance(source,p+2*GetPixelChannels(source));
4505 if (fabs(luminance.x) < fabs(luminance.y))
4510 if (delta.x <= delta.y)
4513 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4515 delta.y=1.0-delta.y;
4516 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4517 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4518 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4519 MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel);
4524 Top-right triangle (pixel: 1, diagonal: 0-3).
4526 delta.x=1.0-delta.x;
4527 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4528 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4529 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4530 MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel);
4538 if (delta.x <= (1.0-delta.y))
4541 Top-left triangle (pixel: 0, diagonal: 1-2).
4543 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4544 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4545 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4546 MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel);
4551 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4553 delta.x=1.0-delta.x;
4554 delta.y=1.0-delta.y;
4555 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4556 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4557 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4558 MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel);
4564 case SplineInterpolatePixel:
4566 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4568 if (p == (const Quantum *) NULL)
4573 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4592 channel=GetPixelChannelMapChannel(source,i);
4593 traits=GetPixelChannelMapTraits(source,channel);
4594 destination_traits=GetPixelChannelMapTraits(destination,channel);
4595 if ((traits == UndefinedPixelTrait) ||
4596 (destination_traits == UndefinedPixelTrait))
4598 if ((traits & BlendPixelTrait) == 0)
4599 for (j=0; j < 16; j++)
4602 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4605 for (j=0; j < 16; j++)
4607 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4608 GetPixelChannels(source));
4609 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4615 for (j=(-1); j < 3L; j++)
4617 dy=CubicWeightingFunction((MagickRealType) j-delta.y);
4618 for (k=(-1); k < 3L; k++)
4620 dx=CubicWeightingFunction(delta.x-(MagickRealType) k);
4621 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 :
4623 sum+=gamma*dx*dy*pixels[n];
4627 SetPixelChannel(destination,channel,p[i],pixel);
4636 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4640 % I n t e r p o l a t e P i x e l I n f o %
4644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4646 % InterpolatePixelInfo() applies a pixel interpolation method between a
4647 % floating point coordinate and the pixels surrounding that coordinate. No
4648 % pixel area resampling, or scaling of the result is performed.
4650 % The format of the InterpolatePixelInfo method is:
4652 % MagickBooleanType InterpolatePixelInfo(const Image *image,
4653 % const CacheView *image_view,const PixelInterpolateMethod method,
4654 % const double x,const double y,PixelInfo *pixel,
4655 % ExceptionInfo *exception)
4657 % A description of each parameter follows:
4659 % o image: the image.
4661 % o image_view: the image view.
4663 % o method: the pixel color interpolation method.
4665 % o x,y: A double representing the current (x,y) position of the pixel.
4667 % o pixel: return the interpolated pixel here.
4669 % o exception: return any errors or warnings in this structure.
4673 static inline void AlphaBlendPixelInfo(const Image *image,
4674 const Quantum *pixel,PixelInfo *pixel_info,MagickRealType *alpha)
4676 if (image->matte == MagickFalse)
4679 pixel_info->red=(MagickRealType) GetPixelRed(image,pixel);
4680 pixel_info->green=(MagickRealType) GetPixelGreen(image,pixel);
4681 pixel_info->blue=(MagickRealType) GetPixelBlue(image,pixel);
4682 pixel_info->black=0.0;
4683 if (image->colorspace == CMYKColorspace)
4684 pixel_info->black=(MagickRealType) GetPixelBlack(image,pixel);
4685 pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
4688 *alpha=QuantumScale*GetPixelAlpha(image,pixel);
4689 pixel_info->red=(*alpha*GetPixelRed(image,pixel));
4690 pixel_info->green=(*alpha*GetPixelGreen(image,pixel));
4691 pixel_info->blue=(*alpha*GetPixelBlue(image,pixel));
4692 pixel_info->black=0.0;
4693 if (image->colorspace == CMYKColorspace)
4694 pixel_info->black=(*alpha*GetPixelBlack(image,pixel));
4695 pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
4698 static void BicubicInterpolate(const PixelInfo *pixels,const double dx,
4709 p=(pixels[3].red-pixels[2].red)-(pixels[0].red-pixels[1].red);
4710 q=(pixels[0].red-pixels[1].red)-p;
4711 r=pixels[2].red-pixels[0].red;
4713 pixel->red=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4714 p=(pixels[3].green-pixels[2].green)-(pixels[0].green-pixels[1].green);
4715 q=(pixels[0].green-pixels[1].green)-p;
4716 r=pixels[2].green-pixels[0].green;
4718 pixel->green=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4719 p=(pixels[3].blue-pixels[2].blue)-(pixels[0].blue-pixels[1].blue);
4720 q=(pixels[0].blue-pixels[1].blue)-p;
4721 r=pixels[2].blue-pixels[0].blue;
4723 pixel->blue=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4724 p=(pixels[3].alpha-pixels[2].alpha)-(pixels[0].alpha-pixels[1].alpha);
4725 q=(pixels[0].alpha-pixels[1].alpha)-p;
4726 r=pixels[2].alpha-pixels[0].alpha;
4728 pixel->alpha=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4729 if (pixel->colorspace == CMYKColorspace)
4731 p=(pixels[3].black-pixels[2].black)-(pixels[0].black-pixels[1].black);
4732 q=(pixels[0].black-pixels[1].black)-p;
4733 r=pixels[2].black-pixels[0].black;
4735 pixel->black=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4739 MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
4740 const CacheView *image_view,const PixelInterpolateMethod method,
4741 const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception)
4753 register const Quantum
4763 assert(image != (Image *) NULL);
4764 assert(image->signature == MagickSignature);
4765 assert(image_view != (CacheView *) NULL);
4767 x_offset=(ssize_t) floor(x);
4768 y_offset=(ssize_t) floor(y);
4769 switch (method == UndefinedInterpolatePixel ? image->interpolate : method)
4771 case AverageInterpolatePixel:
4773 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4775 if (p == (const Quantum *) NULL)
4780 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
4781 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
4782 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
4783 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
4784 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
4785 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
4786 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
4787 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
4788 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
4789 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
4790 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
4792 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
4794 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
4796 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
4798 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
4800 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
4807 for (i=0; i < 16L; i++)
4809 gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]);
4810 pixel->red+=gamma*0.0625*pixels[i].red;
4811 pixel->green+=gamma*0.0625*pixels[i].green;
4812 pixel->blue+=gamma*0.0625*pixels[i].blue;
4813 if (image->colorspace == CMYKColorspace)
4814 pixel->black+=gamma*0.0625*pixels[i].black;
4815 pixel->alpha+=0.0625*pixels[i].alpha;
4819 case BicubicInterpolatePixel:
4827 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4829 if (p == (const Quantum *) NULL)
4834 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
4835 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
4836 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
4837 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
4838 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
4839 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
4840 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
4841 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
4842 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
4843 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
4844 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
4846 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
4848 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
4850 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
4852 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
4854 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
4858 for (i=0; i < 4L; i++)
4859 BicubicInterpolate(pixels+4*i,delta.x,u+i);
4860 BicubicInterpolate(u,delta.y,pixel);
4863 case BilinearInterpolatePixel:
4870 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4871 if (p == (const Quantum *) NULL)
4876 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
4877 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
4878 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
4879 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
4882 epsilon.x=1.0-delta.x;
4883 epsilon.y=1.0-delta.y;
4884 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4885 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4886 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4887 pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
4888 pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red));
4889 pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x*
4890 pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x*
4892 pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x*
4893 pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x*
4895 if (image->colorspace == CMYKColorspace)
4896 pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x*
4897 pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x*
4899 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
4900 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4901 pixel->alpha=(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x*
4902 pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x*
4906 case FilterInterpolatePixel:
4920 geometry.x=x_offset-1;
4921 geometry.y=y_offset-1;
4922 excerpt_image=ExcerptImage(image,&geometry,exception);
4923 if (excerpt_image == (Image *) NULL)
4928 filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur,
4930 excerpt_image=DestroyImage(excerpt_image);
4931 if (filter_image == (Image *) NULL)
4933 filter_view=AcquireCacheView(filter_image);
4934 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4935 if (p != (const Quantum *) NULL)
4936 GetPixelInfoPixel(image,p,pixel);
4937 filter_view=DestroyCacheView(filter_view);
4938 filter_image=DestroyImage(filter_image);
4941 case IntegerInterpolatePixel:
4943 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4944 if (p == (const Quantum *) NULL)
4949 GetPixelInfoPixel(image,p,pixel);
4952 case MeshInterpolatePixel:
4958 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4959 if (p == (const Quantum *) NULL)
4966 luminance.x=GetPixelLuminance(image,p)-(double)
4967 GetPixelLuminance(image,p+3*GetPixelChannels(image));
4968 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
4969 GetPixelLuminance(image,p+2*GetPixelChannels(image));
4970 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
4971 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
4972 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
4973 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
4974 if (fabs(luminance.x) < fabs(luminance.y))
4979 if (delta.x <= delta.y)
4982 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4984 delta.y=1.0-delta.y;
4985 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4986 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4987 pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red,
4988 pixels[3].red,pixels[0].red);
4989 pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green,
4990 pixels[3].green,pixels[0].green);
4991 pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
4992 pixels[3].blue,pixels[0].blue);
4993 if (image->colorspace == CMYKColorspace)
4994 pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black,
4995 pixels[3].black,pixels[0].black);
4996 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
4997 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha,
4998 pixels[3].alpha,pixels[0].alpha);
5003 Top-right triangle (pixel:1 , diagonal: 0-3).
5005 delta.x=1.0-delta.x;
5006 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5007 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5008 pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red,
5009 pixels[0].red,pixels[3].red);
5010 pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green,
5011 pixels[0].green,pixels[3].green);
5012 pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
5013 pixels[0].blue,pixels[3].blue);
5014 if (image->colorspace == CMYKColorspace)
5015 pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black,
5016 pixels[0].black,pixels[3].black);
5017 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5018 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha,
5019 pixels[0].alpha,pixels[3].alpha);
5027 if (delta.x <= (1.0-delta.y))
5030 Top-left triangle (pixel: 0, diagonal: 1-2).
5032 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5033 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5034 pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red,
5035 pixels[1].red,pixels[2].red);
5036 pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green,
5037 pixels[1].green,pixels[2].green);
5038 pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
5039 pixels[1].blue,pixels[2].blue);
5040 if (image->colorspace == CMYKColorspace)
5041 pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black,
5042 pixels[1].black,pixels[2].black);
5043 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5044 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha,
5045 pixels[1].alpha,pixels[2].alpha);
5050 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5052 delta.x=1.0-delta.x;
5053 delta.y=1.0-delta.y;
5054 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5055 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5056 pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red,
5057 pixels[2].red,pixels[1].red);
5058 pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green,
5059 pixels[2].green,pixels[1].green);
5060 pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
5061 pixels[2].blue,pixels[1].blue);
5062 if (image->colorspace == CMYKColorspace)
5063 pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black,
5064 pixels[2].black,pixels[1].black);
5065 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5066 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha,
5067 pixels[2].alpha,pixels[1].alpha);
5072 case NearestNeighborInterpolatePixel:
5074 p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
5075 NearestNeighbor(y),1,1,exception);
5076 if (p == (const Quantum *) NULL)
5081 GetPixelInfoPixel(image,p,pixel);
5084 case SplineInterpolatePixel:
5097 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5099 if (p == (const Quantum *) NULL)
5104 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5105 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5106 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5107 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5108 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
5109 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
5110 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
5111 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
5112 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
5113 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
5114 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
5116 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
5118 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
5120 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
5122 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
5124 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
5134 for (i=(-1); i < 3L; i++)
5136 dy=CubicWeightingFunction((MagickRealType) i-delta.y);
5137 for (j=(-1); j < 3L; j++)
5139 dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
5140 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]);
5141 pixel->red+=gamma*dx*dy*pixels[n].red;
5142 pixel->green+=gamma*dx*dy*pixels[n].green;
5143 pixel->blue+=gamma*dx*dy*pixels[n].blue;
5144 if (image->colorspace == CMYKColorspace)
5145 pixel->black+=gamma*dx*dy*pixels[n].black;
5146 pixel->alpha+=dx*dy*pixels[n].alpha;
5157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5161 + I s F u z z y E q u i v a l e n c e P i x e l %
5165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5167 % IsFuzzyEquivalencePixel() returns MagickTrue if the distance between two
5168 % pixels is less than the specified distance in a linear three (or four)u
5169 % dimensional color space.
5171 % The format of the IsFuzzyEquivalencePixel method is:
5173 % void IsFuzzyEquivalencePixel(const Image *image,const Quantum *p,
5176 % A description of each parameter follows:
5178 % o image: the image.
5185 MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *image,
5186 const Quantum *p,const Quantum *q)
5192 register MagickRealType
5196 fuzz=MagickMax(image->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(
5197 image->fuzz,(MagickRealType) MagickSQ1_2);
5200 if (image->matte != MagickFalse)
5203 Transparencies are involved - set alpha distance
5205 pixel=(MagickRealType) ((image->matte != MagickFalse ?
5206 GetPixelAlpha(image,p) : OpaqueAlpha)-(image->matte != MagickFalse ?
5207 GetPixelAlpha(image,q) : OpaqueAlpha));
5208 distance=pixel*pixel;
5209 if (distance > fuzz)
5210 return(MagickFalse);
5212 Generate a alpha scaling factor to generate a 4D cone on colorspace
5213 Note that if one color is transparent, distance has no color component.
5215 scale=QuantumScale*GetPixelAlpha(image,p);
5216 scale*=QuantumScale*GetPixelAlpha(image,q);
5217 if (scale <= MagickEpsilon)
5221 RGB or CMY color cube
5223 distance*=3.0; /* rescale appropriately */
5225 pixel=GetPixelRed(image,p)-(MagickRealType) GetPixelRed(image,q);
5226 if ((image->colorspace == HSLColorspace) ||
5227 (image->colorspace == HSBColorspace) ||
5228 (image->colorspace == HWBColorspace))
5231 Compute an arc distance for hue. It should be a vector angle of
5232 'S'/'W' length with 'L'/'B' forming appropriate cones.
5234 if (fabs((double) pixel) > (QuantumRange/2))
5235 pixel-=QuantumRange;
5238 distance+=scale*pixel*pixel;
5239 if (distance > fuzz)
5240 return(MagickFalse);
5241 pixel=GetPixelGreen(image,p)-(MagickRealType) GetPixelGreen(image,q);
5242 distance+=scale*pixel*pixel;
5243 if (distance > fuzz)
5244 return(MagickFalse);
5245 pixel=GetPixelBlue(image,p)-(MagickRealType) GetPixelBlue(image,q);
5246 distance+=scale*pixel*pixel;
5247 if (distance > fuzz)
5248 return(MagickFalse);
5253 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5257 + 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 %
5261 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5263 % IsFuzzyEquivalencePixelInfo() returns true if the distance between two
5264 % colors is less than the specified distance in a linear three (or four)
5265 % dimensional color space.
5267 % This implements the equivalent of:
5268 % fuzz < sqrt(color_distance^2 * u.a*v.a + alpha_distance^2)
5270 % Which produces a multi-dimensional cone for that colorspace along the
5271 % transparency vector.
5273 % For example for an RGB:
5274 % color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3
5276 % See http://www.imagemagick.org/Usage/bugs/fuzz_distance/
5278 % Hue colorspace distances need more work. Hue is not a distance, it is an
5281 % A check that q is in the same color space as p should be made and the
5282 % appropriate mapping made. -- Anthony Thyssen 8 December 2010
5284 % The format of the IsFuzzyEquivalencePixelInfo method is:
5286 % MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5287 % const PixelInfo *q)
5289 % A description of each parameter follows:
5296 MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5303 register MagickRealType
5307 if ((p->fuzz == 0.0) && (q->fuzz == 0.0))
5308 return(IsPixelInfoEquivalent(p,q));
5310 fuzz=MagickMax(q->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz,
5311 (MagickRealType) MagickSQ1_2);
5312 else if (q->fuzz == 0.0)
5313 fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(p->fuzz,
5314 (MagickRealType) MagickSQ1_2);
5316 fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz,
5317 (MagickRealType) MagickSQ1_2);
5320 if ((p->matte != MagickFalse) || (q->matte != MagickFalse))
5323 Transparencies are involved - set alpha distance.
5325 pixel=(p->matte != MagickFalse ? p->alpha : OpaqueAlpha)-
5326 (q->matte != MagickFalse ? q->alpha : OpaqueAlpha);
5327 distance=pixel*pixel;
5328 if (distance > fuzz)
5329 return(MagickFalse);
5331 Generate a alpha scaling factor to generate a 4D cone on colorspace.
5332 If one color is transparent, distance has no color component.
5334 if (p->matte != MagickFalse)
5335 scale=(QuantumScale*p->alpha);
5336 if (q->matte != MagickFalse)
5337 scale*=(QuantumScale*q->alpha);
5338 if (scale <= MagickEpsilon )
5342 CMYK create a CMY cube with a multi-dimensional cone toward black.
5344 if (p->colorspace == CMYKColorspace)
5346 pixel=p->black-q->black;
5347 distance+=pixel*pixel*scale;
5348 if (distance > fuzz)
5349 return(MagickFalse);
5350 scale*=(MagickRealType) (QuantumScale*(QuantumRange-p->black));
5351 scale*=(MagickRealType) (QuantumScale*(QuantumRange-q->black));
5354 RGB or CMY color cube.
5356 distance*=3.0; /* rescale appropriately */
5358 pixel=p->red-q->red;
5359 if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) ||
5360 (p->colorspace == HWBColorspace))
5363 This calculates a arc distance for hue-- it should be a vector angle
5364 of 'S'/'W' length with 'L'/'B' forming appropriate cones. In other
5365 words this is a hack - Anthony.
5367 if (fabs((double) pixel) > (QuantumRange/2))
5368 pixel-=QuantumRange;
5371 distance+=pixel*pixel*scale;
5372 if (distance > fuzz)
5373 return(MagickFalse);
5374 pixel=p->green-q->green;
5375 distance+=pixel*pixel*scale;
5376 if (distance > fuzz)
5377 return(MagickFalse);
5378 pixel=p->blue-q->blue;
5379 distance+=pixel*pixel*scale;
5380 if (distance > fuzz)
5381 return(MagickFalse);
5386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5390 % S e t P i x e l C h a n n e l M a p M a s k %
5394 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5396 % SetPixelChannelMapMask() sets the pixel channel map from the specified
5399 % The format of the SetPixelChannelMapMask method is:
5401 % void SetPixelChannelMapMask(Image *image,const ChannelType channel_mask)
5403 % A description of each parameter follows:
5405 % o image: the image.
5407 % o mask: the channel mask.
5410 MagickExport void SetPixelChannelMapMask(Image *image,
5411 const ChannelType channel_mask)
5413 #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
5418 image->channel_mask=channel_mask;
5419 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5424 channel=GetPixelChannelMapChannel(image,i);
5425 SetPixelChannelMapTraits(image,channel,
5426 GetChannelBit(channel_mask,channel) == 0 ? CopyPixelTrait :
5427 image->matte == MagickFalse || (channel == AlphaPixelChannel) ?
5428 UpdatePixelTrait : (PixelTrait) (UpdatePixelTrait | BlendPixelTrait));
5430 if (image->storage_class == PseudoClass)
5431 SetPixelChannelMapTraits(image,IndexPixelChannel,CopyPixelTrait);
5432 if (image->debug != MagickFalse)
5433 LogPixelChannels(image);
5437 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5441 % S e t P i x e l C h a n n e l M a s k %
5445 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5447 % SetPixelChannelMask() sets the pixel channel mask from the specified channel
5450 % The format of the SetPixelChannelMask method is:
5452 % ChannelType SetPixelChannelMask(Image *image,
5453 % const ChannelType channel_mask)
5455 % A description of each parameter follows:
5457 % o image: the image.
5459 % o channel_mask: the channel mask.
5462 MagickExport ChannelType SetPixelChannelMask(Image *image,
5463 const ChannelType channel_mask)
5468 mask=image->channel_mask;
5469 image->channel_mask=channel_mask;
5470 SetPixelChannelMapMask(image,channel_mask);