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"
74 #define LogPixelChannels(image) \
79 (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%.20g]", \
80 image->filename,(double) image->number_channels); \
81 for (i=0; i < (ssize_t) image->number_channels; i++) \
84 traits[MaxTextExtent]; \
89 switch (image->channel_map[i].channel) \
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 AlphaPixelChannel: \
126 case MaskPixelChannel: \
133 channel="undefined"; \
137 if ((image->channel_map[i].traits & UpdatePixelTrait) != 0) \
138 (void) ConcatenateMagickString(traits,"update,",MaxTextExtent); \
139 if ((image->channel_map[i].traits & BlendPixelTrait) != 0) \
140 (void) ConcatenateMagickString(traits,"blend,",MaxTextExtent); \
141 if ((image->channel_map[i].traits & CopyPixelTrait) != 0) \
142 (void) ConcatenateMagickString(traits,"copy,",MaxTextExtent); \
143 if (*traits == '\0') \
144 (void) ConcatenateMagickString(traits,"undefined,",MaxTextExtent); \
145 traits[strlen(traits)-1]='\0'; \
146 (void) LogMagickEvent(PixelEvent,GetMagickModule()," %.20g: %s (%s)", \
147 (double) i,channel,traits); \
152 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156 + A c q u i r e P i x e l C h a n n e l M a p %
160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162 % AcquirePixelChannelMap() acquires a pixel component map.
164 % The format of the AcquirePixelChannelMap() method is:
166 % PixelChannelMap *AcquirePixelChannelMap(void)
169 MagickExport PixelChannelMap *AcquirePixelChannelMap(void)
177 channel_map=(PixelChannelMap *) AcquireQuantumMemory(MaxPixelChannels,
178 sizeof(*channel_map));
179 if (channel_map == (PixelChannelMap *) NULL)
180 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
181 (void) ResetMagickMemory(channel_map,0,MaxPixelChannels*sizeof(*channel_map));
182 for (i=0; i < MaxPixelChannels; i++)
183 channel_map[i].channel=(PixelChannel) i;
188 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192 + C l o n e P i x e l C h a n n e l M a p %
196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
198 % ClonePixelChannelMap() clones a pixel component map.
200 % The format of the ClonePixelChannelMap() method is:
202 % PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
204 % A description of each parameter follows:
206 % o channel_map: the pixel component map.
209 MagickExport PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
214 assert(channel_map != (PixelChannelMap *) NULL);
215 clone_map=AcquirePixelChannelMap();
216 if (clone_map == (PixelChannelMap *) NULL)
217 return((PixelChannelMap *) NULL);
218 (void) CopyMagickMemory(clone_map,channel_map,MaxPixelChannels*
219 sizeof(*channel_map));
224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228 + C l o n e P i x e l I n f o %
232 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234 % ClonePixelInfo() makes a duplicate of the given pixel info structure, or if
235 % pixel info is NULL, a new one.
237 % The format of the ClonePixelInfo method is:
239 % PixelInfo *ClonePixelInfo(const PixelInfo *pixel_info)
241 % A description of each parameter follows:
243 % o pixel_info: the pixel info.
246 MagickExport PixelInfo *ClonePixelInfo(const PixelInfo *pixel)
251 pixel_info=(PixelInfo *) AcquireQuantumMemory(1,sizeof(*pixel_info));
252 if (pixel_info == (PixelInfo *) NULL)
253 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
254 *pixel_info=(*pixel);
259 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
263 + D e s t r o y P i x e l C h a n n e l M a p %
267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269 % DestroyPixelChannelMap() deallocates memory associated with the pixel
272 % The format of the DestroyPixelChannelMap() method is:
274 % PixelChannelMap *DestroyPixelChannelMap(PixelChannelMap *channel_map)
276 % A description of each parameter follows:
278 % o channel_map: the pixel component map.
281 MagickExport PixelChannelMap *DestroyPixelChannelMap(
282 PixelChannelMap *channel_map)
284 assert(channel_map != (PixelChannelMap *) NULL);
285 channel_map=(PixelChannelMap *) RelinquishMagickMemory(channel_map);
286 return((PixelChannelMap *) RelinquishMagickMemory(channel_map));
290 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
294 % E x p o r t I m a g e P i x e l s %
298 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
300 % ExportImagePixels() extracts pixel data from an image and returns it to you.
301 % The method returns MagickTrue on success otherwise MagickFalse if an error is
302 % encountered. The data is returned as char, short int, int, ssize_t, float,
303 % or double in the order specified by map.
305 % Suppose you want to extract the first scanline of a 640x480 image as
306 % character data in red-green-blue order:
308 % ExportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels,exception);
310 % The format of the ExportImagePixels method is:
312 % MagickBooleanType ExportImagePixels(const Image *image,
313 % const ssize_t x_offset,const ssize_t y_offset,const size_t columns,
314 % const size_t rows,const char *map,const StorageType type,
315 % void *pixels,ExceptionInfo *exception)
317 % A description of each parameter follows:
319 % o image: the image.
321 % o x_offset,y_offset,columns,rows: These values define the perimeter
322 % of a region of pixels you want to extract.
324 % o map: This string reflects the expected ordering of the pixel array.
325 % It can be any combination or order of R = red, G = green, B = blue,
326 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
327 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
330 % o type: Define the data type of the pixels. Float and double types are
331 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
332 % types: CharPixel, DoublePixel, FloatPixel, IntegerPixel, LongPixel,
333 % QuantumPixel, or ShortPixel.
335 % o pixels: This array of values contain the pixel components as defined by
336 % map and type. You must preallocate this array where the expected
337 % length varies depending on the values of width, height, map, and type.
339 % o exception: return any errors or warnings in this structure.
342 MagickExport MagickBooleanType ExportImagePixels(const Image *image,
343 const ssize_t x_offset,const ssize_t y_offset,const size_t columns,
344 const size_t rows,const char *map,const StorageType type,void *pixels,
345 ExceptionInfo *exception)
354 register const Quantum
363 assert(image != (Image *) NULL);
364 assert(image->signature == MagickSignature);
365 if (image->debug != MagickFalse)
366 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
368 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
369 if (quantum_map == (QuantumType *) NULL)
371 (void) ThrowMagickException(exception,GetMagickModule(),
372 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
375 for (i=0; i < (ssize_t) length; i++)
382 quantum_map[i]=AlphaQuantum;
388 quantum_map[i]=BlueQuantum;
394 quantum_map[i]=CyanQuantum;
395 if (image->colorspace == CMYKColorspace)
397 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
398 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
399 "ColorSeparatedImageRequired","`%s'",map);
405 quantum_map[i]=GreenQuantum;
411 quantum_map[i]=IndexQuantum;
417 quantum_map[i]=BlackQuantum;
418 if (image->colorspace == CMYKColorspace)
420 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
421 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
422 "ColorSeparatedImageRequired","`%s'",map);
428 quantum_map[i]=MagentaQuantum;
429 if (image->colorspace == CMYKColorspace)
431 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
432 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
433 "ColorSeparatedImageRequired","`%s'",map);
439 quantum_map[i]=OpacityQuantum;
445 quantum_map[i]=UndefinedQuantum;
451 quantum_map[i]=RedQuantum;
457 quantum_map[i]=YellowQuantum;
458 if (image->colorspace == CMYKColorspace)
460 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
461 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
462 "ColorSeparatedImageRequired","`%s'",map);
467 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
468 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
469 "UnrecognizedPixelMap","`%s'",map);
478 register unsigned char
481 q=(unsigned char *) pixels;
482 if (LocaleCompare(map,"BGR") == 0)
484 for (y=0; y < (ssize_t) rows; y++)
486 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
487 if (p == (const Quantum *) NULL)
489 for (x=0; x < (ssize_t) columns; x++)
491 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
492 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
493 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
494 p+=GetPixelChannels(image);
499 if (LocaleCompare(map,"BGRA") == 0)
501 for (y=0; y < (ssize_t) rows; y++)
503 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
504 if (p == (const Quantum *) NULL)
506 for (x=0; x < (ssize_t) columns; x++)
508 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
509 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
510 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
511 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
512 p+=GetPixelChannels(image);
517 if (LocaleCompare(map,"BGRP") == 0)
519 for (y=0; y < (ssize_t) rows; y++)
521 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
522 if (p == (const Quantum *) NULL)
524 for (x=0; x < (ssize_t) columns; x++)
526 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
527 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
528 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
529 *q++=ScaleQuantumToChar((Quantum) 0);
530 p+=GetPixelChannels(image);
535 if (LocaleCompare(map,"I") == 0)
537 for (y=0; y < (ssize_t) rows; y++)
539 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
540 if (p == (const Quantum *) NULL)
542 for (x=0; x < (ssize_t) columns; x++)
544 *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
545 p+=GetPixelChannels(image);
550 if (LocaleCompare(map,"RGB") == 0)
552 for (y=0; y < (ssize_t) rows; y++)
554 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
555 if (p == (const Quantum *) NULL)
557 for (x=0; x < (ssize_t) columns; x++)
559 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
560 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
561 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
562 p+=GetPixelChannels(image);
567 if (LocaleCompare(map,"RGBA") == 0)
569 for (y=0; y < (ssize_t) rows; y++)
571 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
572 if (p == (const Quantum *) NULL)
574 for (x=0; x < (ssize_t) columns; x++)
576 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
577 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
578 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
579 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
580 p+=GetPixelChannels(image);
585 if (LocaleCompare(map,"RGBP") == 0)
587 for (y=0; y < (ssize_t) rows; y++)
589 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
590 if (p == (const Quantum *) NULL)
592 for (x=0; x < (ssize_t) columns; x++)
594 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
595 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
596 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
597 *q++=ScaleQuantumToChar((Quantum) 0);
598 p+=GetPixelChannels(image);
603 for (y=0; y < (ssize_t) rows; y++)
605 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
606 if (p == (const Quantum *) NULL)
608 for (x=0; x < (ssize_t) columns; x++)
610 for (i=0; i < (ssize_t) length; i++)
613 switch (quantum_map[i])
618 *q=ScaleQuantumToChar(GetPixelRed(image,p));
624 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
630 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
635 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
640 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
645 if (image->colorspace == CMYKColorspace)
646 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
651 *q=ScaleQuantumToChar(GetPixelIntensity(image,p));
659 p+=GetPixelChannels(image);
670 if (LocaleCompare(map,"BGR") == 0)
672 for (y=0; y < (ssize_t) rows; y++)
674 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
675 if (p == (const Quantum *) NULL)
677 for (x=0; x < (ssize_t) columns; x++)
679 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
680 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
681 *q++=(double) (QuantumScale*GetPixelRed(image,p));
682 p+=GetPixelChannels(image);
687 if (LocaleCompare(map,"BGRA") == 0)
689 for (y=0; y < (ssize_t) rows; y++)
691 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
692 if (p == (const Quantum *) NULL)
694 for (x=0; x < (ssize_t) columns; x++)
696 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
697 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
698 *q++=(double) (QuantumScale*GetPixelRed(image,p));
699 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
700 p+=GetPixelChannels(image);
705 if (LocaleCompare(map,"BGRP") == 0)
707 for (y=0; y < (ssize_t) rows; y++)
709 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
710 if (p == (const Quantum *) NULL)
712 for (x=0; x < (ssize_t) columns; x++)
714 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
715 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
716 *q++=(double) (QuantumScale*GetPixelRed(image,p));
718 p+=GetPixelChannels(image);
723 if (LocaleCompare(map,"I") == 0)
725 for (y=0; y < (ssize_t) rows; y++)
727 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
728 if (p == (const Quantum *) NULL)
730 for (x=0; x < (ssize_t) columns; x++)
732 *q++=(double) (QuantumScale*GetPixelIntensity(image,p));
733 p+=GetPixelChannels(image);
738 if (LocaleCompare(map,"RGB") == 0)
740 for (y=0; y < (ssize_t) rows; y++)
742 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
743 if (p == (const Quantum *) NULL)
745 for (x=0; x < (ssize_t) columns; x++)
747 *q++=(double) (QuantumScale*GetPixelRed(image,p));
748 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
749 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
750 p+=GetPixelChannels(image);
755 if (LocaleCompare(map,"RGBA") == 0)
757 for (y=0; y < (ssize_t) rows; y++)
759 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
760 if (p == (const Quantum *) NULL)
762 for (x=0; x < (ssize_t) columns; x++)
764 *q++=(double) (QuantumScale*GetPixelRed(image,p));
765 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
766 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
767 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
768 p+=GetPixelChannels(image);
773 if (LocaleCompare(map,"RGBP") == 0)
775 for (y=0; y < (ssize_t) rows; y++)
777 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
778 if (p == (const Quantum *) NULL)
780 for (x=0; x < (ssize_t) columns; x++)
782 *q++=(double) (QuantumScale*GetPixelRed(image,p));
783 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
784 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
786 p+=GetPixelChannels(image);
791 for (y=0; y < (ssize_t) rows; y++)
793 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
794 if (p == (const Quantum *) NULL)
796 for (x=0; x < (ssize_t) columns; x++)
798 for (i=0; i < (ssize_t) length; i++)
801 switch (quantum_map[i])
806 *q=(double) (QuantumScale*GetPixelRed(image,p));
812 *q=(double) (QuantumScale*GetPixelGreen(image,p));
818 *q=(double) (QuantumScale*GetPixelBlue(image,p));
823 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
828 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
833 if (image->colorspace == CMYKColorspace)
834 *q=(double) (QuantumScale*
835 GetPixelBlack(image,p));
840 *q=(double) (QuantumScale*GetPixelIntensity(image,p));
848 p+=GetPixelChannels(image);
859 if (LocaleCompare(map,"BGR") == 0)
861 for (y=0; y < (ssize_t) rows; y++)
863 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
864 if (p == (const Quantum *) NULL)
866 for (x=0; x < (ssize_t) columns; x++)
868 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
869 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
870 *q++=(float) (QuantumScale*GetPixelRed(image,p));
871 p+=GetPixelChannels(image);
876 if (LocaleCompare(map,"BGRA") == 0)
878 for (y=0; y < (ssize_t) rows; y++)
880 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
881 if (p == (const Quantum *) NULL)
883 for (x=0; x < (ssize_t) columns; x++)
885 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
886 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
887 *q++=(float) (QuantumScale*GetPixelRed(image,p));
888 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
889 p+=GetPixelChannels(image);
894 if (LocaleCompare(map,"BGRP") == 0)
896 for (y=0; y < (ssize_t) rows; y++)
898 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
899 if (p == (const Quantum *) NULL)
901 for (x=0; x < (ssize_t) columns; x++)
903 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
904 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
905 *q++=(float) (QuantumScale*GetPixelRed(image,p));
907 p+=GetPixelChannels(image);
912 if (LocaleCompare(map,"I") == 0)
914 for (y=0; y < (ssize_t) rows; y++)
916 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
917 if (p == (const Quantum *) NULL)
919 for (x=0; x < (ssize_t) columns; x++)
921 *q++=(float) (QuantumScale*GetPixelIntensity(image,p));
922 p+=GetPixelChannels(image);
927 if (LocaleCompare(map,"RGB") == 0)
929 for (y=0; y < (ssize_t) rows; y++)
931 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
932 if (p == (const Quantum *) NULL)
934 for (x=0; x < (ssize_t) columns; x++)
936 *q++=(float) (QuantumScale*GetPixelRed(image,p));
937 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
938 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
939 p+=GetPixelChannels(image);
944 if (LocaleCompare(map,"RGBA") == 0)
946 for (y=0; y < (ssize_t) rows; y++)
948 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
949 if (p == (const Quantum *) NULL)
951 for (x=0; x < (ssize_t) columns; x++)
953 *q++=(float) (QuantumScale*GetPixelRed(image,p));
954 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
955 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
956 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
957 p+=GetPixelChannels(image);
962 if (LocaleCompare(map,"RGBP") == 0)
964 for (y=0; y < (ssize_t) rows; y++)
966 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
967 if (p == (const Quantum *) NULL)
969 for (x=0; x < (ssize_t) columns; x++)
971 *q++=(float) (QuantumScale*GetPixelRed(image,p));
972 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
973 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
975 p+=GetPixelChannels(image);
980 for (y=0; y < (ssize_t) rows; y++)
982 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
983 if (p == (const Quantum *) NULL)
985 for (x=0; x < (ssize_t) columns; x++)
987 for (i=0; i < (ssize_t) length; i++)
990 switch (quantum_map[i])
995 *q=(float) (QuantumScale*GetPixelRed(image,p));
1001 *q=(float) (QuantumScale*GetPixelGreen(image,p));
1007 *q=(float) (QuantumScale*GetPixelBlue(image,p));
1012 *q=(float) (QuantumScale*((Quantum) (GetPixelAlpha(image,p))));
1015 case OpacityQuantum:
1017 *q=(float) (QuantumScale*GetPixelAlpha(image,p));
1022 if (image->colorspace == CMYKColorspace)
1023 *q=(float) (QuantumScale* GetPixelBlack(image,p));
1028 *q=(float) (QuantumScale*GetPixelIntensity(image,p));
1036 p+=GetPixelChannels(image);
1043 register unsigned int
1046 q=(unsigned int *) pixels;
1047 if (LocaleCompare(map,"BGR") == 0)
1049 for (y=0; y < (ssize_t) rows; y++)
1051 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1052 if (p == (const Quantum *) NULL)
1054 for (x=0; x < (ssize_t) columns; x++)
1056 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1057 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1058 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1059 p+=GetPixelChannels(image);
1064 if (LocaleCompare(map,"BGRA") == 0)
1066 for (y=0; y < (ssize_t) rows; y++)
1068 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1069 if (p == (const Quantum *) NULL)
1071 for (x=0; x < (ssize_t) columns; x++)
1073 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1074 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1075 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1076 *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
1077 p+=GetPixelChannels(image);
1082 if (LocaleCompare(map,"BGRP") == 0)
1084 for (y=0; y < (ssize_t) rows; y++)
1086 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1087 if (p == (const Quantum *) NULL)
1089 for (x=0; x < (ssize_t) columns; x++)
1091 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1092 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1093 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1095 p+=GetPixelChannels(image);
1100 if (LocaleCompare(map,"I") == 0)
1102 for (y=0; y < (ssize_t) rows; y++)
1104 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1105 if (p == (const Quantum *) NULL)
1107 for (x=0; x < (ssize_t) columns; x++)
1109 *q++=(unsigned int) ScaleQuantumToLong(
1110 GetPixelIntensity(image,p));
1111 p+=GetPixelChannels(image);
1116 if (LocaleCompare(map,"RGB") == 0)
1118 for (y=0; y < (ssize_t) rows; y++)
1120 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1121 if (p == (const Quantum *) NULL)
1123 for (x=0; x < (ssize_t) columns; x++)
1125 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1126 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1127 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1128 p+=GetPixelChannels(image);
1133 if (LocaleCompare(map,"RGBA") == 0)
1135 for (y=0; y < (ssize_t) rows; y++)
1137 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1138 if (p == (const Quantum *) NULL)
1140 for (x=0; x < (ssize_t) columns; x++)
1142 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1143 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1144 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1145 *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
1146 p+=GetPixelChannels(image);
1151 if (LocaleCompare(map,"RGBP") == 0)
1153 for (y=0; y < (ssize_t) rows; y++)
1155 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1156 if (p == (const Quantum *) NULL)
1158 for (x=0; x < (ssize_t) columns; x++)
1160 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1161 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1162 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1164 p+=GetPixelChannels(image);
1169 for (y=0; y < (ssize_t) rows; y++)
1171 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1172 if (p == (const Quantum *) NULL)
1174 for (x=0; x < (ssize_t) columns; x++)
1176 for (i=0; i < (ssize_t) length; i++)
1179 switch (quantum_map[i])
1184 *q=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1188 case MagentaQuantum:
1190 *q=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1196 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1201 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
1204 case OpacityQuantum:
1206 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
1211 if (image->colorspace == CMYKColorspace)
1212 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlack(image,p));
1217 *q=(unsigned int) ScaleQuantumToLong(
1218 GetPixelIntensity(image,p));
1226 p+=GetPixelChannels(image);
1236 q=(size_t *) pixels;
1237 if (LocaleCompare(map,"BGR") == 0)
1239 for (y=0; y < (ssize_t) rows; y++)
1241 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1242 if (p == (const Quantum *) NULL)
1244 for (x=0; x < (ssize_t) columns; x++)
1246 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1247 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1248 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1249 p+=GetPixelChannels(image);
1254 if (LocaleCompare(map,"BGRA") == 0)
1256 for (y=0; y < (ssize_t) rows; y++)
1258 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1259 if (p == (const Quantum *) NULL)
1261 for (x=0; x < (ssize_t) columns; x++)
1263 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1264 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1265 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1266 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1267 p+=GetPixelChannels(image);
1272 if (LocaleCompare(map,"BGRP") == 0)
1274 for (y=0; y < (ssize_t) rows; y++)
1276 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1277 if (p == (const Quantum *) NULL)
1279 for (x=0; x < (ssize_t) columns; x++)
1281 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1282 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1283 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1285 p+=GetPixelChannels(image);
1290 if (LocaleCompare(map,"I") == 0)
1292 for (y=0; y < (ssize_t) rows; y++)
1294 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1295 if (p == (const Quantum *) NULL)
1297 for (x=0; x < (ssize_t) columns; x++)
1299 *q++=ScaleQuantumToLong(GetPixelIntensity(image,p));
1300 p+=GetPixelChannels(image);
1305 if (LocaleCompare(map,"RGB") == 0)
1307 for (y=0; y < (ssize_t) rows; y++)
1309 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1310 if (p == (const Quantum *) NULL)
1312 for (x=0; x < (ssize_t) columns; x++)
1314 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1315 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1316 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1317 p+=GetPixelChannels(image);
1322 if (LocaleCompare(map,"RGBA") == 0)
1324 for (y=0; y < (ssize_t) rows; y++)
1326 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1327 if (p == (const Quantum *) NULL)
1329 for (x=0; x < (ssize_t) columns; x++)
1331 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1332 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1333 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1334 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1335 p+=GetPixelChannels(image);
1340 if (LocaleCompare(map,"RGBP") == 0)
1342 for (y=0; y < (ssize_t) rows; y++)
1344 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1345 if (p == (const Quantum *) NULL)
1347 for (x=0; x < (ssize_t) columns; x++)
1349 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1350 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1351 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1353 p+=GetPixelChannels(image);
1358 for (y=0; y < (ssize_t) rows; y++)
1360 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1361 if (p == (const Quantum *) NULL)
1363 for (x=0; x < (ssize_t) columns; x++)
1365 for (i=0; i < (ssize_t) length; i++)
1368 switch (quantum_map[i])
1373 *q=ScaleQuantumToLong(GetPixelRed(image,p));
1377 case MagentaQuantum:
1379 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
1385 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
1390 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1393 case OpacityQuantum:
1395 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1400 if (image->colorspace == CMYKColorspace)
1401 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
1406 *q=ScaleQuantumToLong(GetPixelIntensity(image,p));
1414 p+=GetPixelChannels(image);
1424 q=(Quantum *) pixels;
1425 if (LocaleCompare(map,"BGR") == 0)
1427 for (y=0; y < (ssize_t) rows; y++)
1429 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1430 if (p == (const Quantum *) NULL)
1432 for (x=0; x < (ssize_t) columns; x++)
1434 *q++=GetPixelBlue(image,p);
1435 *q++=GetPixelGreen(image,p);
1436 *q++=GetPixelRed(image,p);
1437 p+=GetPixelChannels(image);
1442 if (LocaleCompare(map,"BGRA") == 0)
1444 for (y=0; y < (ssize_t) rows; y++)
1446 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1447 if (p == (const Quantum *) NULL)
1449 for (x=0; x < (ssize_t) columns; x++)
1451 *q++=GetPixelBlue(image,p);
1452 *q++=GetPixelGreen(image,p);
1453 *q++=GetPixelRed(image,p);
1454 *q++=(Quantum) (GetPixelAlpha(image,p));
1455 p+=GetPixelChannels(image);
1460 if (LocaleCompare(map,"BGRP") == 0)
1462 for (y=0; y < (ssize_t) rows; y++)
1464 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1465 if (p == (const Quantum *) NULL)
1467 for (x=0; x < (ssize_t) columns; x++)
1469 *q++=GetPixelBlue(image,p);
1470 *q++=GetPixelGreen(image,p);
1471 *q++=GetPixelRed(image,p);
1473 p+=GetPixelChannels(image);
1478 if (LocaleCompare(map,"I") == 0)
1480 for (y=0; y < (ssize_t) rows; y++)
1482 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1483 if (p == (const Quantum *) NULL)
1485 for (x=0; x < (ssize_t) columns; x++)
1487 *q++=GetPixelIntensity(image,p);
1488 p+=GetPixelChannels(image);
1493 if (LocaleCompare(map,"RGB") == 0)
1495 for (y=0; y < (ssize_t) rows; y++)
1497 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1498 if (p == (const Quantum *) NULL)
1500 for (x=0; x < (ssize_t) columns; x++)
1502 *q++=GetPixelRed(image,p);
1503 *q++=GetPixelGreen(image,p);
1504 *q++=GetPixelBlue(image,p);
1505 p+=GetPixelChannels(image);
1510 if (LocaleCompare(map,"RGBA") == 0)
1512 for (y=0; y < (ssize_t) rows; y++)
1514 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1515 if (p == (const Quantum *) NULL)
1517 for (x=0; x < (ssize_t) columns; x++)
1519 *q++=GetPixelRed(image,p);
1520 *q++=GetPixelGreen(image,p);
1521 *q++=GetPixelBlue(image,p);
1522 *q++=(Quantum) (GetPixelAlpha(image,p));
1523 p+=GetPixelChannels(image);
1528 if (LocaleCompare(map,"RGBP") == 0)
1530 for (y=0; y < (ssize_t) rows; y++)
1532 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1533 if (p == (const Quantum *) NULL)
1535 for (x=0; x < (ssize_t) columns; x++)
1537 *q++=GetPixelRed(image,p);
1538 *q++=GetPixelGreen(image,p);
1539 *q++=GetPixelBlue(image,p);
1541 p+=GetPixelChannels(image);
1546 for (y=0; y < (ssize_t) rows; y++)
1548 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1549 if (p == (const Quantum *) NULL)
1551 for (x=0; x < (ssize_t) columns; x++)
1553 for (i=0; i < (ssize_t) length; i++)
1556 switch (quantum_map[i])
1561 *q=GetPixelRed(image,p);
1565 case MagentaQuantum:
1567 *q=GetPixelGreen(image,p);
1573 *q=GetPixelBlue(image,p);
1578 *q=(Quantum) (GetPixelAlpha(image,p));
1581 case OpacityQuantum:
1583 *q=GetPixelAlpha(image,p);
1588 if (image->colorspace == CMYKColorspace)
1589 *q=GetPixelBlack(image,p);
1594 *q=(GetPixelIntensity(image,p));
1602 p+=GetPixelChannels(image);
1609 register unsigned short
1612 q=(unsigned short *) pixels;
1613 if (LocaleCompare(map,"BGR") == 0)
1615 for (y=0; y < (ssize_t) rows; y++)
1617 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1618 if (p == (const Quantum *) NULL)
1620 for (x=0; x < (ssize_t) columns; x++)
1622 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1623 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1624 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1625 p+=GetPixelChannels(image);
1630 if (LocaleCompare(map,"BGRA") == 0)
1632 for (y=0; y < (ssize_t) rows; y++)
1634 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1635 if (p == (const Quantum *) NULL)
1637 for (x=0; x < (ssize_t) columns; x++)
1639 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1640 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1641 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1642 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1643 p+=GetPixelChannels(image);
1648 if (LocaleCompare(map,"BGRP") == 0)
1650 for (y=0; y < (ssize_t) rows; y++)
1652 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1653 if (p == (const Quantum *) NULL)
1655 for (x=0; x < (ssize_t) columns; x++)
1657 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1658 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1659 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1661 p+=GetPixelChannels(image);
1666 if (LocaleCompare(map,"I") == 0)
1668 for (y=0; y < (ssize_t) rows; y++)
1670 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1671 if (p == (const Quantum *) NULL)
1673 for (x=0; x < (ssize_t) columns; x++)
1675 *q++=ScaleQuantumToShort(GetPixelIntensity(image,p));
1676 p+=GetPixelChannels(image);
1681 if (LocaleCompare(map,"RGB") == 0)
1683 for (y=0; y < (ssize_t) rows; y++)
1685 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1686 if (p == (const Quantum *) NULL)
1688 for (x=0; x < (ssize_t) columns; x++)
1690 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1691 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1692 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1693 p+=GetPixelChannels(image);
1698 if (LocaleCompare(map,"RGBA") == 0)
1700 for (y=0; y < (ssize_t) rows; y++)
1702 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1703 if (p == (const Quantum *) NULL)
1705 for (x=0; x < (ssize_t) columns; x++)
1707 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1708 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1709 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1710 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1711 p+=GetPixelChannels(image);
1716 if (LocaleCompare(map,"RGBP") == 0)
1718 for (y=0; y < (ssize_t) rows; y++)
1720 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1721 if (p == (const Quantum *) NULL)
1723 for (x=0; x < (ssize_t) columns; x++)
1725 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1726 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1727 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1729 p+=GetPixelChannels(image);
1734 for (y=0; y < (ssize_t) rows; y++)
1736 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1737 if (p == (const Quantum *) NULL)
1739 for (x=0; x < (ssize_t) columns; x++)
1741 for (i=0; i < (ssize_t) length; i++)
1744 switch (quantum_map[i])
1749 *q=ScaleQuantumToShort(GetPixelRed(image,p));
1753 case MagentaQuantum:
1755 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
1761 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
1766 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1769 case OpacityQuantum:
1771 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1776 if (image->colorspace == CMYKColorspace)
1777 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
1782 *q=ScaleQuantumToShort(GetPixelIntensity(image,p));
1790 p+=GetPixelChannels(image);
1797 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1798 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1799 "UnrecognizedPixelMap","`%s'",map);
1803 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1808 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1812 % G e t P i x e l I n f o %
1816 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1818 % GetPixelInfo() initializes the PixelInfo structure.
1820 % The format of the GetPixelInfo method is:
1822 % GetPixelInfo(const Image *image,PixelInfo *pixel)
1824 % A description of each parameter follows:
1826 % o image: the image.
1828 % o pixel: Specifies a pointer to a PixelInfo structure.
1831 MagickExport void GetPixelInfo(const Image *image,PixelInfo *pixel)
1833 pixel->storage_class=DirectClass;
1834 pixel->colorspace=RGBColorspace;
1835 pixel->matte=MagickFalse;
1837 pixel->depth=MAGICKCORE_QUANTUM_DEPTH;
1842 pixel->alpha=(MagickRealType) OpaqueAlpha;
1844 if (image == (const Image *) NULL)
1846 pixel->storage_class=image->storage_class;
1847 pixel->colorspace=image->colorspace;
1848 pixel->matte=image->matte;
1849 pixel->depth=image->depth;
1850 pixel->fuzz=image->fuzz;
1854 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1858 % I m p o r t I m a g e P i x e l s %
1862 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1864 % ImportImagePixels() accepts pixel data and stores in the image at the
1865 % location you specify. The method returns MagickTrue on success otherwise
1866 % MagickFalse if an error is encountered. The pixel data can be either char,
1867 % short int, int, ssize_t, float, or double in the order specified by map.
1869 % Suppose your want to upload the first scanline of a 640x480 image from
1870 % character data in red-green-blue order:
1872 % ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels);
1874 % The format of the ImportImagePixels method is:
1876 % MagickBooleanType ImportImagePixels(Image *image,const ssize_t x_offset,
1877 % const ssize_t y_offset,const size_t columns,
1878 % const size_t rows,const char *map,const StorageType type,
1879 % const void *pixels,ExceptionInfo *exception)
1881 % A description of each parameter follows:
1883 % o image: the image.
1885 % o x_offset,y_offset,columns,rows: These values define the perimeter
1886 % of a region of pixels you want to define.
1888 % o map: This string reflects the expected ordering of the pixel array.
1889 % It can be any combination or order of R = red, G = green, B = blue,
1890 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
1891 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
1894 % o type: Define the data type of the pixels. Float and double types are
1895 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
1896 % types: CharPixel, ShortPixel, IntegerPixel, LongPixel, FloatPixel, or
1899 % o pixels: This array of values contain the pixel components as defined by
1900 % map and type. You must preallocate this array where the expected
1901 % length varies depending on the values of width, height, map, and type.
1903 % o exception: return any errors or warnings in this structure.
1906 MagickExport MagickBooleanType ImportImagePixels(Image *image,
1907 const ssize_t x_offset,const ssize_t y_offset,const size_t columns,
1908 const size_t rows,const char *map,const StorageType type,
1909 const void *pixels,ExceptionInfo *exception)
1928 Allocate image structure.
1930 assert(image != (Image *) NULL);
1931 assert(image->signature == MagickSignature);
1932 if (image->debug != MagickFalse)
1933 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1935 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1936 if (quantum_map == (QuantumType *) NULL)
1937 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1939 for (i=0; i < (ssize_t) length; i++)
1946 quantum_map[i]=AlphaQuantum;
1947 image->matte=MagickTrue;
1953 quantum_map[i]=BlueQuantum;
1959 quantum_map[i]=CyanQuantum;
1960 (void) SetImageColorspace(image,CMYKColorspace,exception);
1966 quantum_map[i]=GreenQuantum;
1972 quantum_map[i]=BlackQuantum;
1973 (void) SetImageColorspace(image,CMYKColorspace,exception);
1979 quantum_map[i]=IndexQuantum;
1985 quantum_map[i]=MagentaQuantum;
1986 (void) SetImageColorspace(image,CMYKColorspace,exception);
1992 quantum_map[i]=OpacityQuantum;
1993 image->matte=MagickTrue;
1999 quantum_map[i]=UndefinedQuantum;
2005 quantum_map[i]=RedQuantum;
2011 quantum_map[i]=YellowQuantum;
2012 (void) SetImageColorspace(image,CMYKColorspace,exception);
2017 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2018 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2019 "UnrecognizedPixelMap","`%s'",map);
2020 return(MagickFalse);
2024 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2025 return(MagickFalse);
2027 Transfer the pixels from the pixel datarray to the image.
2033 register const unsigned char
2036 p=(const unsigned char *) pixels;
2037 if (LocaleCompare(map,"BGR") == 0)
2039 for (y=0; y < (ssize_t) rows; y++)
2041 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2042 if (q == (Quantum *) NULL)
2044 for (x=0; x < (ssize_t) columns; x++)
2046 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2047 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2048 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2049 q+=GetPixelChannels(image);
2051 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2056 if (LocaleCompare(map,"BGRA") == 0)
2058 for (y=0; y < (ssize_t) rows; y++)
2060 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2061 if (q == (Quantum *) NULL)
2063 for (x=0; x < (ssize_t) columns; x++)
2065 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2066 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2067 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2068 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2069 q+=GetPixelChannels(image);
2071 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2076 if (LocaleCompare(map,"BGRO") == 0)
2078 for (y=0; y < (ssize_t) rows; y++)
2080 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2081 if (q == (Quantum *) NULL)
2083 for (x=0; x < (ssize_t) columns; x++)
2085 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2086 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2087 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2088 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2089 q+=GetPixelChannels(image);
2091 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2096 if (LocaleCompare(map,"BGRP") == 0)
2098 for (y=0; y < (ssize_t) rows; y++)
2100 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2101 if (q == (Quantum *) NULL)
2103 for (x=0; x < (ssize_t) columns; x++)
2105 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2106 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2107 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2109 q+=GetPixelChannels(image);
2111 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2116 if (LocaleCompare(map,"I") == 0)
2118 for (y=0; y < (ssize_t) rows; y++)
2120 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2121 if (q == (Quantum *) NULL)
2123 for (x=0; x < (ssize_t) columns; x++)
2125 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2126 SetPixelGreen(image,GetPixelRed(image,q),q);
2127 SetPixelBlue(image,GetPixelRed(image,q),q);
2128 q+=GetPixelChannels(image);
2130 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2135 if (LocaleCompare(map,"RGB") == 0)
2137 for (y=0; y < (ssize_t) rows; y++)
2139 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2140 if (q == (Quantum *) NULL)
2142 for (x=0; x < (ssize_t) columns; x++)
2144 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2145 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2146 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2147 q+=GetPixelChannels(image);
2149 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2154 if (LocaleCompare(map,"RGBA") == 0)
2156 for (y=0; y < (ssize_t) rows; y++)
2158 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2159 if (q == (Quantum *) NULL)
2161 for (x=0; x < (ssize_t) columns; x++)
2163 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2164 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2165 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2166 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2167 q+=GetPixelChannels(image);
2169 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2174 if (LocaleCompare(map,"RGBO") == 0)
2176 for (y=0; y < (ssize_t) rows; y++)
2178 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2179 if (q == (Quantum *) NULL)
2181 for (x=0; x < (ssize_t) columns; x++)
2183 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2184 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2185 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2186 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2187 q+=GetPixelChannels(image);
2189 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2194 if (LocaleCompare(map,"RGBP") == 0)
2196 for (y=0; y < (ssize_t) rows; y++)
2198 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2199 if (q == (Quantum *) NULL)
2201 for (x=0; x < (ssize_t) columns; x++)
2203 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2204 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2205 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2207 q+=GetPixelChannels(image);
2209 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2214 for (y=0; y < (ssize_t) rows; y++)
2216 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2217 if (q == (Quantum *) NULL)
2219 for (x=0; x < (ssize_t) columns; x++)
2221 for (i=0; i < (ssize_t) length; i++)
2223 switch (quantum_map[i])
2228 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2232 case MagentaQuantum:
2234 SetPixelGreen(image,ScaleCharToQuantum(*p),q);
2240 SetPixelBlue(image,ScaleCharToQuantum(*p),q);
2245 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2248 case OpacityQuantum:
2250 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2255 SetPixelBlack(image,ScaleCharToQuantum(*p),q);
2260 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2261 SetPixelGreen(image,GetPixelRed(image,q),q);
2262 SetPixelBlue(image,GetPixelRed(image,q),q);
2270 q+=GetPixelChannels(image);
2272 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2279 register const double
2282 p=(const double *) pixels;
2283 if (LocaleCompare(map,"BGR") == 0)
2285 for (y=0; y < (ssize_t) rows; y++)
2287 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2288 if (q == (Quantum *) NULL)
2290 for (x=0; x < (ssize_t) columns; x++)
2292 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2295 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2298 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2301 q+=GetPixelChannels(image);
2303 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2308 if (LocaleCompare(map,"BGRA") == 0)
2310 for (y=0; y < (ssize_t) rows; y++)
2312 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2313 if (q == (Quantum *) NULL)
2315 for (x=0; x < (ssize_t) columns; x++)
2317 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2320 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2323 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2326 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2329 q+=GetPixelChannels(image);
2331 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2336 if (LocaleCompare(map,"BGRP") == 0)
2338 for (y=0; y < (ssize_t) rows; y++)
2340 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2341 if (q == (Quantum *) NULL)
2343 for (x=0; x < (ssize_t) columns; x++)
2345 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2348 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2351 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2355 q+=GetPixelChannels(image);
2357 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2362 if (LocaleCompare(map,"I") == 0)
2364 for (y=0; y < (ssize_t) rows; y++)
2366 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2367 if (q == (Quantum *) NULL)
2369 for (x=0; x < (ssize_t) columns; x++)
2371 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2373 SetPixelGreen(image,GetPixelRed(image,q),q);
2374 SetPixelBlue(image,GetPixelRed(image,q),q);
2376 q+=GetPixelChannels(image);
2378 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2383 if (LocaleCompare(map,"RGB") == 0)
2385 for (y=0; y < (ssize_t) rows; y++)
2387 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2388 if (q == (Quantum *) NULL)
2390 for (x=0; x < (ssize_t) columns; x++)
2392 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2395 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2398 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2401 q+=GetPixelChannels(image);
2403 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2408 if (LocaleCompare(map,"RGBA") == 0)
2410 for (y=0; y < (ssize_t) rows; y++)
2412 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2413 if (q == (Quantum *) NULL)
2415 for (x=0; x < (ssize_t) columns; x++)
2417 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2420 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2423 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2426 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2429 q+=GetPixelChannels(image);
2431 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2436 if (LocaleCompare(map,"RGBP") == 0)
2438 for (y=0; y < (ssize_t) rows; y++)
2440 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2441 if (q == (Quantum *) NULL)
2443 for (x=0; x < (ssize_t) columns; x++)
2445 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2448 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2451 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2454 q+=GetPixelChannels(image);
2456 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2461 for (y=0; y < (ssize_t) rows; y++)
2463 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2464 if (q == (Quantum *) NULL)
2466 for (x=0; x < (ssize_t) columns; x++)
2468 for (i=0; i < (ssize_t) length; i++)
2470 switch (quantum_map[i])
2475 SetPixelRed(image,ClampToQuantum((MagickRealType)
2476 QuantumRange*(*p)),q);
2480 case MagentaQuantum:
2482 SetPixelGreen(image,ClampToQuantum((MagickRealType)
2483 QuantumRange*(*p)),q);
2489 SetPixelBlue(image,ClampToQuantum((MagickRealType)
2490 QuantumRange*(*p)),q);
2495 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2496 QuantumRange*(*p)),q);
2499 case OpacityQuantum:
2501 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2502 QuantumRange*(*p)),q);
2507 SetPixelBlack(image,ClampToQuantum((MagickRealType)
2508 QuantumRange*(*p)),q);
2513 SetPixelRed(image,ClampToQuantum((MagickRealType)
2514 QuantumRange*(*p)),q);
2515 SetPixelGreen(image,GetPixelRed(image,q),q);
2516 SetPixelBlue(image,GetPixelRed(image,q),q);
2524 q+=GetPixelChannels(image);
2526 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2533 register const float
2536 p=(const float *) pixels;
2537 if (LocaleCompare(map,"BGR") == 0)
2539 for (y=0; y < (ssize_t) rows; y++)
2541 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2542 if (q == (Quantum *) NULL)
2544 for (x=0; x < (ssize_t) columns; x++)
2546 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2549 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2552 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2555 q+=GetPixelChannels(image);
2557 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2562 if (LocaleCompare(map,"BGRA") == 0)
2564 for (y=0; y < (ssize_t) rows; y++)
2566 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2567 if (q == (Quantum *) NULL)
2569 for (x=0; x < (ssize_t) columns; x++)
2571 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2574 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2577 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2580 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2583 q+=GetPixelChannels(image);
2585 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2590 if (LocaleCompare(map,"BGRP") == 0)
2592 for (y=0; y < (ssize_t) rows; y++)
2594 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2595 if (q == (Quantum *) NULL)
2597 for (x=0; x < (ssize_t) columns; x++)
2599 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2602 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2605 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2609 q+=GetPixelChannels(image);
2611 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2616 if (LocaleCompare(map,"I") == 0)
2618 for (y=0; y < (ssize_t) rows; y++)
2620 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2621 if (q == (Quantum *) NULL)
2623 for (x=0; x < (ssize_t) columns; x++)
2625 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2627 SetPixelGreen(image,GetPixelRed(image,q),q);
2628 SetPixelBlue(image,GetPixelRed(image,q),q);
2630 q+=GetPixelChannels(image);
2632 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2637 if (LocaleCompare(map,"RGB") == 0)
2639 for (y=0; y < (ssize_t) rows; y++)
2641 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2642 if (q == (Quantum *) NULL)
2644 for (x=0; x < (ssize_t) columns; x++)
2646 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2649 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2652 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2655 q+=GetPixelChannels(image);
2657 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2662 if (LocaleCompare(map,"RGBA") == 0)
2664 for (y=0; y < (ssize_t) rows; y++)
2666 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2667 if (q == (Quantum *) NULL)
2669 for (x=0; x < (ssize_t) columns; x++)
2671 SetPixelRed(image,ClampToQuantum((MagickRealType)
2672 QuantumRange*(*p)),q);
2674 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2677 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2680 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2683 q+=GetPixelChannels(image);
2685 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2690 if (LocaleCompare(map,"RGBP") == 0)
2692 for (y=0; y < (ssize_t) rows; y++)
2694 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2695 if (q == (Quantum *) NULL)
2697 for (x=0; x < (ssize_t) columns; x++)
2699 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2702 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2705 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2708 q+=GetPixelChannels(image);
2710 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2715 for (y=0; y < (ssize_t) rows; y++)
2717 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2718 if (q == (Quantum *) NULL)
2720 for (x=0; x < (ssize_t) columns; x++)
2722 for (i=0; i < (ssize_t) length; i++)
2724 switch (quantum_map[i])
2729 SetPixelRed(image,ClampToQuantum((MagickRealType)
2730 QuantumRange*(*p)),q);
2734 case MagentaQuantum:
2736 SetPixelGreen(image,ClampToQuantum((MagickRealType)
2737 QuantumRange*(*p)),q);
2743 SetPixelBlue(image,ClampToQuantum((MagickRealType)
2744 QuantumRange*(*p)),q);
2749 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2750 QuantumRange*(*p)),q);
2753 case OpacityQuantum:
2755 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2756 QuantumRange*(*p)),q);
2761 SetPixelBlack(image,ClampToQuantum((MagickRealType)
2762 QuantumRange*(*p)),q);
2767 SetPixelRed(image,ClampToQuantum((MagickRealType)
2768 QuantumRange*(*p)),q);
2769 SetPixelGreen(image,GetPixelRed(image,q),q);
2770 SetPixelBlue(image,GetPixelRed(image,q),q);
2778 q+=GetPixelChannels(image);
2780 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2787 register const unsigned int
2790 p=(const unsigned int *) pixels;
2791 if (LocaleCompare(map,"BGR") == 0)
2793 for (y=0; y < (ssize_t) rows; y++)
2795 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2796 if (q == (Quantum *) NULL)
2798 for (x=0; x < (ssize_t) columns; x++)
2800 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2801 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2802 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2803 q+=GetPixelChannels(image);
2805 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2810 if (LocaleCompare(map,"BGRA") == 0)
2812 for (y=0; y < (ssize_t) rows; y++)
2814 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2815 if (q == (Quantum *) NULL)
2817 for (x=0; x < (ssize_t) columns; x++)
2819 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2820 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2821 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2822 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
2823 q+=GetPixelChannels(image);
2825 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2830 if (LocaleCompare(map,"BGRP") == 0)
2832 for (y=0; y < (ssize_t) rows; y++)
2834 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2835 if (q == (Quantum *) NULL)
2837 for (x=0; x < (ssize_t) columns; x++)
2839 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2840 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2841 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2843 q+=GetPixelChannels(image);
2845 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2850 if (LocaleCompare(map,"I") == 0)
2852 for (y=0; y < (ssize_t) rows; y++)
2854 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2855 if (q == (Quantum *) NULL)
2857 for (x=0; x < (ssize_t) columns; x++)
2859 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2860 SetPixelGreen(image,GetPixelRed(image,q),q);
2861 SetPixelBlue(image,GetPixelRed(image,q),q);
2862 q+=GetPixelChannels(image);
2864 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2869 if (LocaleCompare(map,"RGB") == 0)
2871 for (y=0; y < (ssize_t) rows; y++)
2873 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2874 if (q == (Quantum *) NULL)
2876 for (x=0; x < (ssize_t) columns; x++)
2878 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2879 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2880 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2881 q+=GetPixelChannels(image);
2883 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2888 if (LocaleCompare(map,"RGBA") == 0)
2890 for (y=0; y < (ssize_t) rows; y++)
2892 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2893 if (q == (Quantum *) NULL)
2895 for (x=0; x < (ssize_t) columns; x++)
2897 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2898 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2899 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2900 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
2901 q+=GetPixelChannels(image);
2903 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2908 if (LocaleCompare(map,"RGBP") == 0)
2910 for (y=0; y < (ssize_t) rows; y++)
2912 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2913 if (q == (Quantum *) NULL)
2915 for (x=0; x < (ssize_t) columns; x++)
2917 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2918 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2919 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2921 q+=GetPixelChannels(image);
2923 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2928 for (y=0; y < (ssize_t) rows; y++)
2930 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2931 if (q == (Quantum *) NULL)
2933 for (x=0; x < (ssize_t) columns; x++)
2935 for (i=0; i < (ssize_t) length; i++)
2937 switch (quantum_map[i])
2942 SetPixelRed(image,ScaleLongToQuantum(*p),q);
2946 case MagentaQuantum:
2948 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
2954 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
2959 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
2962 case OpacityQuantum:
2964 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
2969 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
2974 SetPixelRed(image,ScaleLongToQuantum(*p),q);
2975 SetPixelGreen(image,GetPixelRed(image,q),q);
2976 SetPixelBlue(image,GetPixelRed(image,q),q);
2984 q+=GetPixelChannels(image);
2986 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2993 register const unsigned int
2996 p=(const unsigned int *) pixels;
2997 if (LocaleCompare(map,"BGR") == 0)
2999 for (y=0; y < (ssize_t) rows; y++)
3001 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3002 if (q == (Quantum *) NULL)
3004 for (x=0; x < (ssize_t) columns; x++)
3006 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3007 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3008 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3009 q+=GetPixelChannels(image);
3011 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3016 if (LocaleCompare(map,"BGRA") == 0)
3018 for (y=0; y < (ssize_t) rows; y++)
3020 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3021 if (q == (Quantum *) NULL)
3023 for (x=0; x < (ssize_t) columns; x++)
3025 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3026 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3027 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3028 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3029 q+=GetPixelChannels(image);
3031 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3036 if (LocaleCompare(map,"BGRP") == 0)
3038 for (y=0; y < (ssize_t) rows; y++)
3040 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3041 if (q == (Quantum *) NULL)
3043 for (x=0; x < (ssize_t) columns; x++)
3045 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3046 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3047 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3049 q+=GetPixelChannels(image);
3051 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3056 if (LocaleCompare(map,"I") == 0)
3058 for (y=0; y < (ssize_t) rows; y++)
3060 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3061 if (q == (Quantum *) NULL)
3063 for (x=0; x < (ssize_t) columns; x++)
3065 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3066 SetPixelGreen(image,GetPixelRed(image,q),q);
3067 SetPixelBlue(image,GetPixelRed(image,q),q);
3068 q+=GetPixelChannels(image);
3070 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3075 if (LocaleCompare(map,"RGB") == 0)
3077 for (y=0; y < (ssize_t) rows; y++)
3079 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3080 if (q == (Quantum *) NULL)
3082 for (x=0; x < (ssize_t) columns; x++)
3084 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3085 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3086 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3087 q+=GetPixelChannels(image);
3089 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3094 if (LocaleCompare(map,"RGBA") == 0)
3096 for (y=0; y < (ssize_t) rows; y++)
3098 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3099 if (q == (Quantum *) NULL)
3101 for (x=0; x < (ssize_t) columns; x++)
3103 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3104 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3105 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3106 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3107 q+=GetPixelChannels(image);
3109 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3114 if (LocaleCompare(map,"RGBP") == 0)
3116 for (y=0; y < (ssize_t) rows; y++)
3118 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3119 if (q == (Quantum *) NULL)
3121 for (x=0; x < (ssize_t) columns; x++)
3123 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3124 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3125 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3127 q+=GetPixelChannels(image);
3129 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3134 for (y=0; y < (ssize_t) rows; y++)
3136 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3137 if (q == (Quantum *) NULL)
3139 for (x=0; x < (ssize_t) columns; x++)
3141 for (i=0; i < (ssize_t) length; i++)
3143 switch (quantum_map[i])
3148 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3152 case MagentaQuantum:
3154 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
3160 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
3165 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3168 case OpacityQuantum:
3170 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3175 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
3180 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3181 SetPixelGreen(image,GetPixelRed(image,q),q);
3182 SetPixelBlue(image,GetPixelRed(image,q),q);
3190 q+=GetPixelChannels(image);
3192 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3199 register const Quantum
3202 p=(const Quantum *) pixels;
3203 if (LocaleCompare(map,"BGR") == 0)
3205 for (y=0; y < (ssize_t) rows; y++)
3207 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3208 if (q == (Quantum *) NULL)
3210 for (x=0; x < (ssize_t) columns; x++)
3212 SetPixelBlue(image,*p++,q);
3213 SetPixelGreen(image,*p++,q);
3214 SetPixelRed(image,*p++,q);
3215 q+=GetPixelChannels(image);
3217 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3222 if (LocaleCompare(map,"BGRA") == 0)
3224 for (y=0; y < (ssize_t) rows; y++)
3226 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3227 if (q == (Quantum *) NULL)
3229 for (x=0; x < (ssize_t) columns; x++)
3231 SetPixelBlue(image,*p++,q);
3232 SetPixelGreen(image,*p++,q);
3233 SetPixelRed(image,*p++,q);
3234 SetPixelAlpha(image,*p++,q);
3235 q+=GetPixelChannels(image);
3237 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3242 if (LocaleCompare(map,"BGRP") == 0)
3244 for (y=0; y < (ssize_t) rows; y++)
3246 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3247 if (q == (Quantum *) NULL)
3249 for (x=0; x < (ssize_t) columns; x++)
3251 SetPixelBlue(image,*p++,q);
3252 SetPixelGreen(image,*p++,q);
3253 SetPixelRed(image,*p++,q);
3255 q+=GetPixelChannels(image);
3257 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3262 if (LocaleCompare(map,"I") == 0)
3264 for (y=0; y < (ssize_t) rows; y++)
3266 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3267 if (q == (Quantum *) NULL)
3269 for (x=0; x < (ssize_t) columns; x++)
3271 SetPixelRed(image,*p++,q);
3272 SetPixelGreen(image,GetPixelRed(image,q),q);
3273 SetPixelBlue(image,GetPixelRed(image,q),q);
3274 q+=GetPixelChannels(image);
3276 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3281 if (LocaleCompare(map,"RGB") == 0)
3283 for (y=0; y < (ssize_t) rows; y++)
3285 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3286 if (q == (Quantum *) NULL)
3288 for (x=0; x < (ssize_t) columns; x++)
3290 SetPixelRed(image,*p++,q);
3291 SetPixelGreen(image,*p++,q);
3292 SetPixelBlue(image,*p++,q);
3293 q+=GetPixelChannels(image);
3295 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3300 if (LocaleCompare(map,"RGBA") == 0)
3302 for (y=0; y < (ssize_t) rows; y++)
3304 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3305 if (q == (Quantum *) NULL)
3307 for (x=0; x < (ssize_t) columns; x++)
3309 SetPixelRed(image,*p++,q);
3310 SetPixelGreen(image,*p++,q);
3311 SetPixelBlue(image,*p++,q);
3312 SetPixelAlpha(image,*p++,q);
3313 q+=GetPixelChannels(image);
3315 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3320 if (LocaleCompare(map,"RGBP") == 0)
3322 for (y=0; y < (ssize_t) rows; y++)
3324 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3325 if (q == (Quantum *) NULL)
3327 for (x=0; x < (ssize_t) columns; x++)
3329 SetPixelRed(image,*p++,q);
3330 SetPixelGreen(image,*p++,q);
3331 SetPixelBlue(image,*p++,q);
3333 q+=GetPixelChannels(image);
3335 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3340 for (y=0; y < (ssize_t) rows; y++)
3342 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3343 if (q == (Quantum *) NULL)
3345 for (x=0; x < (ssize_t) columns; x++)
3347 for (i=0; i < (ssize_t) length; i++)
3349 switch (quantum_map[i])
3354 SetPixelRed(image,*p,q);
3358 case MagentaQuantum:
3360 SetPixelGreen(image,*p,q);
3366 SetPixelBlue(image,*p,q);
3371 SetPixelAlpha(image,*p,q);
3374 case OpacityQuantum:
3376 SetPixelAlpha(image,*p,q);
3381 SetPixelBlack(image,*p,q);
3386 SetPixelRed(image,*p,q);
3387 SetPixelGreen(image,GetPixelRed(image,q),q);
3388 SetPixelBlue(image,GetPixelRed(image,q),q);
3396 q+=GetPixelChannels(image);
3398 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3405 register const unsigned short
3408 p=(const unsigned short *) pixels;
3409 if (LocaleCompare(map,"BGR") == 0)
3411 for (y=0; y < (ssize_t) rows; y++)
3413 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3414 if (q == (Quantum *) NULL)
3416 for (x=0; x < (ssize_t) columns; x++)
3418 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3419 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3420 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3421 q+=GetPixelChannels(image);
3423 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3428 if (LocaleCompare(map,"BGRA") == 0)
3430 for (y=0; y < (ssize_t) rows; y++)
3432 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3433 if (q == (Quantum *) NULL)
3435 for (x=0; x < (ssize_t) columns; x++)
3437 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3438 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3439 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3440 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3441 q+=GetPixelChannels(image);
3443 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3448 if (LocaleCompare(map,"BGRP") == 0)
3450 for (y=0; y < (ssize_t) rows; y++)
3452 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3453 if (q == (Quantum *) NULL)
3455 for (x=0; x < (ssize_t) columns; x++)
3457 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3458 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3459 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3461 q+=GetPixelChannels(image);
3463 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3468 if (LocaleCompare(map,"I") == 0)
3470 for (y=0; y < (ssize_t) rows; y++)
3472 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3473 if (q == (Quantum *) NULL)
3475 for (x=0; x < (ssize_t) columns; x++)
3477 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3478 SetPixelGreen(image,GetPixelRed(image,q),q);
3479 SetPixelBlue(image,GetPixelRed(image,q),q);
3480 q+=GetPixelChannels(image);
3482 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3487 if (LocaleCompare(map,"RGB") == 0)
3489 for (y=0; y < (ssize_t) rows; y++)
3491 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3492 if (q == (Quantum *) NULL)
3494 for (x=0; x < (ssize_t) columns; x++)
3496 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3497 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3498 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3499 q+=GetPixelChannels(image);
3501 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3506 if (LocaleCompare(map,"RGBA") == 0)
3508 for (y=0; y < (ssize_t) rows; y++)
3510 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3511 if (q == (Quantum *) NULL)
3513 for (x=0; x < (ssize_t) columns; x++)
3515 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3516 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3517 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3518 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3519 q+=GetPixelChannels(image);
3521 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3526 if (LocaleCompare(map,"RGBP") == 0)
3528 for (y=0; y < (ssize_t) rows; y++)
3530 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3531 if (q == (Quantum *) NULL)
3533 for (x=0; x < (ssize_t) columns; x++)
3535 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3536 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3537 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3539 q+=GetPixelChannels(image);
3541 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3546 for (y=0; y < (ssize_t) rows; y++)
3548 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3549 if (q == (Quantum *) NULL)
3551 for (x=0; x < (ssize_t) columns; x++)
3553 for (i=0; i < (ssize_t) length; i++)
3555 switch (quantum_map[i])
3560 SetPixelRed(image,ScaleShortToQuantum(*p),q);
3564 case MagentaQuantum:
3566 SetPixelGreen(image,ScaleShortToQuantum(*p),q);
3572 SetPixelBlue(image,ScaleShortToQuantum(*p),q);
3577 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3580 case OpacityQuantum:
3582 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3587 SetPixelBlack(image,ScaleShortToQuantum(*p),q);
3592 SetPixelRed(image,ScaleShortToQuantum(*p),q);
3593 SetPixelGreen(image,GetPixelRed(image,q),q);
3594 SetPixelBlue(image,GetPixelRed(image,q),q);
3602 q+=GetPixelChannels(image);
3604 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3611 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3612 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3613 "UnrecognizedPixelMap","`%s'",map);
3617 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3622 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3626 + 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 %
3630 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3632 % InitializePixelChannelMap() defines the standard pixel component map.
3634 % The format of the InitializePixelChannelMap() method is:
3636 % void InitializePixelChannelMap(Image *image)
3638 % A description of each parameter follows:
3640 % o image: the image.
3643 MagickExport void InitializePixelChannelMap(Image *image)
3651 assert(image != (Image *) NULL);
3652 assert(image->signature == MagickSignature);
3653 for (i=0; i < (ssize_t) MaxPixelChannels; i++)
3655 SetPixelChannelMapChannel(image,(PixelChannel) i,(PixelChannel) i);
3656 SetPixelChannelMapTraits(image,(PixelChannel) i,UndefinedPixelTrait);
3658 image->number_channels=4;
3659 if (0 && image->colorspace == GRAYColorspace)
3660 image->number_channels=2;
3661 if (image->colorspace == CMYKColorspace)
3662 image->number_channels++;
3663 if (image->storage_class == PseudoClass)
3664 image->number_channels++;
3665 for (i=0; i < (ssize_t) image->number_channels; i++)
3666 SetPixelChannelMapTraits(image,(PixelChannel) i,(PixelTrait)
3668 alpha_channel=GetPixelChannelMapChannel(image,AlphaPixelChannel);
3669 if (image->matte == MagickFalse)
3670 SetPixelChannelMapTraits(image,AlphaPixelChannel,CopyPixelTrait);
3672 for (i=0; i < (ssize_t) image->number_channels; i++)
3673 if ((PixelChannel) i != alpha_channel)
3674 SetPixelChannelMapTraits(image,(PixelChannel) i,(PixelTrait)
3675 (UpdatePixelTrait | BlendPixelTrait));
3676 if (0 && image->colorspace == GRAYColorspace)
3678 image->number_channels=2;
3679 SetPixelChannelMapChannel(image,GreenPixelChannel,RedPixelChannel);
3680 SetPixelChannelMapChannel(image,BluePixelChannel,RedPixelChannel);
3682 if (image->storage_class == PseudoClass)
3684 SetPixelChannelMapChannel(image,IndexPixelChannel,IndexPixelChannel);
3685 SetPixelChannelMapTraits(image,IndexPixelChannel,CopyPixelTrait);
3687 image->number_channels+=image->number_meta_channels;
3688 for ( ; i < (ssize_t) image->number_channels; i++)
3689 SetPixelChannelMapTraits(image,(PixelChannel) i,CopyPixelTrait);
3690 if (image->debug != MagickFalse)
3691 LogPixelChannels(image);
3692 (void) SetPixelChannelMask(image,image->channel_mask);
3696 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3700 % I n t e r p o l a t e P i x e l C h a n n e l %
3704 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3706 % InterpolatePixelChannel() applies a pixel interpolation method between a
3707 % floating point coordinate and the pixels surrounding that coordinate. No
3708 % pixel area resampling, or scaling of the result is performed.
3710 % The format of the InterpolatePixelChannel method is:
3712 % MagickBooleanType InterpolatePixelChannel(const Image *image,
3713 % const CacheView *image_view,const PixelChannel channel,
3714 % const PixelInterpolateMethod method,const double x,const double y,
3715 % double *pixel,ExceptionInfo *exception)
3717 % A description of each parameter follows:
3719 % o image: the image.
3721 % o image_view: the image view.
3723 % o channel: the pixel channel to interpolate.
3725 % o method: the pixel color interpolation method.
3727 % o x,y: A double representing the current (x,y) position of the pixel.
3729 % o pixel: return the interpolated pixel here.
3731 % o exception: return any errors or warnings in this structure.
3735 static inline double MagickMax(const MagickRealType x,const MagickRealType y)
3742 static inline MagickRealType CubicWeightingFunction(const MagickRealType x)
3748 alpha=MagickMax(x+2.0,0.0);
3749 gamma=1.0*alpha*alpha*alpha;
3750 alpha=MagickMax(x+1.0,0.0);
3751 gamma-=4.0*alpha*alpha*alpha;
3752 alpha=MagickMax(x+0.0,0.0);
3753 gamma+=6.0*alpha*alpha*alpha;
3754 alpha=MagickMax(x-1.0,0.0);
3755 gamma-=4.0*alpha*alpha*alpha;
3759 static inline double MeshInterpolate(const PointInfo *delta,const double p,
3760 const double x,const double y)
3762 return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
3765 static inline ssize_t NearestNeighbor(const MagickRealType x)
3768 return((ssize_t) (x+0.5));
3769 return((ssize_t) (x-0.5));
3772 MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
3773 const CacheView *image_view,const PixelChannel channel,
3774 const PixelInterpolateMethod method,const double x,const double y,
3775 double *pixel,ExceptionInfo *exception)
3788 register const Quantum
3798 assert(image != (Image *) NULL);
3799 assert(image != (Image *) NULL);
3800 assert(image->signature == MagickSignature);
3801 assert(image_view != (CacheView *) NULL);
3804 traits=GetPixelChannelMapTraits(image,channel);
3805 x_offset=(ssize_t) floor(x);
3806 y_offset=(ssize_t) floor(y);
3807 switch (method == UndefinedInterpolatePixel ? image->interpolate : method)
3809 case AverageInterpolatePixel:
3811 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
3813 if (p == (const Quantum *) NULL)
3818 if ((traits & BlendPixelTrait) == 0)
3819 for (i=0; i < 16; i++)
3822 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
3825 for (i=0; i < 16; i++)
3827 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
3828 GetPixelChannels(image));
3829 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
3831 for (i=0; i < 16; i++)
3833 gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]);
3834 *pixel+=gamma*0.0625*pixels[i];
3838 case BicubicInterpolatePixel:
3847 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
3849 if (p == (const Quantum *) NULL)
3854 if ((traits & BlendPixelTrait) == 0)
3855 for (i=0; i < 16; i++)
3858 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
3861 for (i=0; i < 16; i++)
3863 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
3864 GetPixelChannels(image));
3865 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
3869 for (i=0; i < 4; i++)
3871 u[0]=(pixels[4*i+3]-pixels[4*i+2])-(pixels[4*i+0]-pixels[4*i+1]);
3872 u[1]=(pixels[4*i+0]-pixels[4*i+1])-u[0];
3873 u[2]=pixels[4*i+2]-pixels[4*i+0];
3875 v[i]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x*
3878 u[0]=(v[3]-v[2])-(v[0]-v[1]);
3879 u[1]=(v[0]-v[1])-u[0];
3882 *pixel=(delta.y*delta.y*delta.y*u[0])+(delta.y*delta.y*u[1])+(delta.y*
3886 case BilinearInterpolatePixel:
3893 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
3894 if (p == (const Quantum *) NULL)
3899 if ((traits & BlendPixelTrait) == 0)
3900 for (i=0; i < 4; i++)
3903 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
3906 for (i=0; i < 4; i++)
3908 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
3909 GetPixelChannels(image));
3910 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
3914 epsilon.x=1.0-delta.x;
3915 epsilon.y=1.0-delta.y;
3916 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
3917 (epsilon.x*alpha[2]+delta.x*alpha[3])));
3918 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3919 *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
3920 (epsilon.x*pixels[2]+delta.x*pixels[3]));
3923 case FilterInterpolatePixel:
3937 geometry.x=x_offset-1;
3938 geometry.y=y_offset-1;
3939 excerpt_image=ExcerptImage(image,&geometry,exception);
3940 if (excerpt_image == (Image *) NULL)
3945 filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur,
3947 excerpt_image=DestroyImage(excerpt_image);
3948 if (filter_image == (Image *) NULL)
3950 filter_view=AcquireCacheView(filter_image);
3951 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
3952 if (p == (const Quantum *) NULL)
3955 *pixel=(double) GetPixelChannel(image,channel,p);
3956 filter_view=DestroyCacheView(filter_view);
3957 filter_image=DestroyImage(filter_image);
3960 case IntegerInterpolatePixel:
3962 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
3963 if (p == (const Quantum *) NULL)
3968 *pixel=(double) GetPixelChannel(image,channel,p);
3971 case NearestNeighborInterpolatePixel:
3973 p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
3974 NearestNeighbor(y),1,1,exception);
3975 if (p == (const Quantum *) NULL)
3980 *pixel=(double) GetPixelChannel(image,channel,p);
3983 case MeshInterpolatePixel:
3989 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
3990 if (p == (const Quantum *) NULL)
3995 if ((traits & BlendPixelTrait) == 0)
3996 for (i=0; i < 4; i++)
3999 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4002 for (i=0; i < 4; i++)
4004 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4005 GetPixelChannels(image));
4006 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4010 luminance.x=GetPixelLuminance(image,p)-(double)
4011 GetPixelLuminance(image,p+3*GetPixelChannels(image));
4012 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
4013 GetPixelLuminance(image,p+2*GetPixelChannels(image));
4014 if (fabs(luminance.x) < fabs(luminance.y))
4019 if (delta.x <= delta.y)
4022 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4024 delta.y=1.0-delta.y;
4025 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4026 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4027 *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
4033 Top-right triangle (pixel: 1, diagonal: 0-3).
4035 delta.x=1.0-delta.x;
4036 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4037 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4038 *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
4047 if (delta.x <= (1.0-delta.y))
4050 Top-left triangle (pixel: 0, diagonal: 1-2).
4052 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4053 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4054 *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
4060 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4062 delta.x=1.0-delta.x;
4063 delta.y=1.0-delta.y;
4064 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4065 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4066 *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
4072 case SplineInterpolatePixel:
4085 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4087 if (p == (const Quantum *) NULL)
4092 if ((traits & BlendPixelTrait) == 0)
4093 for (i=0; i < 16; i++)
4096 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4099 for (i=0; i < 16; i++)
4101 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4102 GetPixelChannels(image));
4103 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4108 for (i=(-1); i < 3L; i++)
4110 dy=CubicWeightingFunction((MagickRealType) i-delta.y);
4111 for (j=(-1); j < 3L; j++)
4113 dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
4114 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]);
4115 *pixel+=gamma*dx*dy*pixels[n];
4126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4130 % I n t e r p o l a t e P i x e l C h a n n e l s %
4134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4136 % InterpolatePixelChannels() applies a pixel interpolation method between a
4137 % floating point coordinate and the pixels surrounding that coordinate. No
4138 % pixel area resampling, or scaling of the result is performed.
4140 % The format of the InterpolatePixelChannels method is:
4142 % MagickBooleanType InterpolatePixelChannels(const Image *source,
4143 % const CacheView *source_view,const Image *destination,
4144 % const PixelInterpolateMethod method,const double x,const double y,
4145 % Quantum *pixel,ExceptionInfo *exception)
4147 % A description of each parameter follows:
4149 % o source: the source.
4151 % o source_view: the source view.
4153 % o destination: the destination image.
4155 % o method: the pixel color interpolation method.
4157 % o x,y: A double representing the current (x,y) position of the pixel.
4159 % o pixel: return the interpolated pixel here.
4161 % o exception: return any errors or warnings in this structure.
4164 MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
4165 const CacheView *source_view,const Image *destination,
4166 const PixelInterpolateMethod method,const double x,const double y,
4167 Quantum *pixel,ExceptionInfo *exception)
4184 register const Quantum
4194 assert(source != (Image *) NULL);
4195 assert(source != (Image *) NULL);
4196 assert(source->signature == MagickSignature);
4197 assert(source_view != (CacheView *) NULL);
4199 x_offset=(ssize_t) floor(x);
4200 y_offset=(ssize_t) floor(y);
4201 switch (method == UndefinedInterpolatePixel ? source->interpolate : method)
4203 case AverageInterpolatePixel:
4205 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4207 if (p == (const Quantum *) NULL)
4212 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4220 traits=GetPixelChannelMapTraits(source,(PixelChannel) i);
4221 channel=GetPixelChannelMapChannel(source,(PixelChannel) i);
4222 destination_traits=GetPixelChannelMapTraits(destination,channel);
4223 if ((traits == UndefinedPixelTrait) ||
4224 (destination_traits == UndefinedPixelTrait))
4226 for (j=0; j < 16; j++)
4227 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4228 if ((traits & BlendPixelTrait) == 0)
4230 for (j=0; j < 16; j++)
4231 pixel[channel]+=0.0625*pixels[j];
4235 for (j=0; j < 16; j++)
4237 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4238 GetPixelChannels(source));
4239 pixels[j]*=alpha[j];
4240 gamma=1.0/(fabs((double) alpha[j]) <= MagickEpsilon ? 1.0 : alpha[j]);
4241 sum+=gamma*0.0625*pixels[j];
4243 pixel[channel]=ClampToQuantum(sum);
4247 case BicubicInterpolatePixel:
4256 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4258 if (p == (const Quantum *) NULL)
4263 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4268 traits=GetPixelChannelMapTraits(source,(PixelChannel) i);
4269 channel=GetPixelChannelMapChannel(source,(PixelChannel) i);
4270 destination_traits=GetPixelChannelMapTraits(destination,channel);
4271 if ((traits == UndefinedPixelTrait) ||
4272 (destination_traits == UndefinedPixelTrait))
4274 if ((traits & BlendPixelTrait) == 0)
4275 for (j=0; j < 16; j++)
4278 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4281 for (j=0; j < 16; j++)
4283 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4284 GetPixelChannels(source));
4285 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4289 for (j=0; j < 4; j++)
4291 u[0]=(pixels[4*j+3]-pixels[4*j+2])-(pixels[4*j+0]-pixels[4*j+1]);
4292 u[1]=(pixels[4*j+0]-pixels[4*j+1])-u[0];
4293 u[2]=pixels[4*j+2]-pixels[4*j+0];
4295 v[j]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x*
4298 u[0]=(v[3]-v[2])-(v[0]-v[1]);
4299 u[1]=(v[0]-v[1])-u[0];
4302 pixel[channel]=ClampToQuantum((delta.y*delta.y*delta.y*u[0])+(delta.y*
4303 delta.y*u[1])+(delta.y*u[2])+u[3]);
4307 case BilinearInterpolatePixel:
4310 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4311 if (p == (const Quantum *) NULL)
4316 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4322 traits=GetPixelChannelMapTraits(source,(PixelChannel) i);
4323 channel=GetPixelChannelMapChannel(source,(PixelChannel) i);
4324 destination_traits=GetPixelChannelMapTraits(destination,channel);
4325 if ((traits == UndefinedPixelTrait) ||
4326 (destination_traits == UndefinedPixelTrait))
4330 epsilon.x=1.0-delta.x;
4331 epsilon.y=1.0-delta.y;
4332 pixels[0]=(MagickRealType) p[i];
4333 pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i];
4334 pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i];
4335 pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i];
4336 if ((traits & BlendPixelTrait) == 0)
4338 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
4339 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4340 pixel[channel]=ClampToQuantum(gamma*(epsilon.y*(epsilon.x*pixels[0]+
4341 delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+delta.x*
4345 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4346 alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source));
4347 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4348 GetPixelChannels(source));
4349 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4350 GetPixelChannels(source));
4351 pixels[0]*=alpha[0];
4352 pixels[1]*=alpha[1];
4353 pixels[2]*=alpha[2];
4354 pixels[3]*=alpha[3];
4355 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4356 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4357 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4358 pixel[channel]=ClampToQuantum(gamma*(epsilon.y*(epsilon.x*pixels[0]+
4359 delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+delta.x*pixels[3])));
4363 case FilterInterpolatePixel:
4365 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4377 traits=GetPixelChannelMapTraits(source,(PixelChannel) i);
4378 channel=GetPixelChannelMapChannel(source,(PixelChannel) i);
4379 destination_traits=GetPixelChannelMapTraits(destination,channel);
4380 if ((traits == UndefinedPixelTrait) ||
4381 (destination_traits == UndefinedPixelTrait))
4385 geometry.x=x_offset-1;
4386 geometry.y=y_offset-1;
4387 excerpt_source=ExcerptImage(source,&geometry,exception);
4388 if (excerpt_source == (Image *) NULL)
4393 filter_source=ResizeImage(excerpt_source,1,1,source->filter,
4394 source->blur,exception);
4395 excerpt_source=DestroyImage(excerpt_source);
4396 if (filter_source == (Image *) NULL)
4398 filter_view=AcquireCacheView(filter_source);
4399 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4400 if (p == (const Quantum *) NULL)
4403 pixel[channel]=p[i];
4404 filter_view=DestroyCacheView(filter_view);
4405 filter_source=DestroyImage(filter_source);
4409 case IntegerInterpolatePixel:
4411 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
4412 if (p == (const Quantum *) NULL)
4417 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4419 traits=GetPixelChannelMapTraits(source,(PixelChannel) i);
4420 channel=GetPixelChannelMapChannel(source,(PixelChannel) i);
4421 destination_traits=GetPixelChannelMapTraits(destination,channel);
4422 if ((traits == UndefinedPixelTrait) ||
4423 (destination_traits == UndefinedPixelTrait))
4425 pixel[channel]=p[i];
4429 case NearestNeighborInterpolatePixel:
4431 p=GetCacheViewVirtualPixels(source_view,NearestNeighbor(x),
4432 NearestNeighbor(y),1,1,exception);
4433 if (p == (const Quantum *) NULL)
4438 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4440 traits=GetPixelChannelMapTraits(source,(PixelChannel) i);
4441 channel=GetPixelChannelMapChannel(source,(PixelChannel) i);
4442 destination_traits=GetPixelChannelMapTraits(destination,channel);
4443 if ((traits == UndefinedPixelTrait) ||
4444 (destination_traits == UndefinedPixelTrait))
4446 pixel[channel]=p[i];
4450 case MeshInterpolatePixel:
4452 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4453 if (p == (const Quantum *) NULL)
4458 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4464 traits=GetPixelChannelMapTraits(source,(PixelChannel) i);
4465 channel=GetPixelChannelMapChannel(source,(PixelChannel) i);
4466 destination_traits=GetPixelChannelMapTraits(destination,channel);
4467 if ((traits == UndefinedPixelTrait) ||
4468 (destination_traits == UndefinedPixelTrait))
4470 pixels[0]=(MagickRealType) p[i];
4471 pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i];
4472 pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i];
4473 pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i];
4474 if ((traits & BlendPixelTrait) == 0)
4483 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4484 alpha[1]=QuantumScale*GetPixelAlpha(source,p+
4485 GetPixelChannels(source));
4486 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4487 GetPixelChannels(source));
4488 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4489 GetPixelChannels(source));
4493 luminance.x=GetPixelLuminance(source,p)-(double)
4494 GetPixelLuminance(source,p+3*GetPixelChannels(source));
4495 luminance.y=GetPixelLuminance(source,p+GetPixelChannels(source))-
4496 (double) GetPixelLuminance(source,p+2*GetPixelChannels(source));
4497 if (fabs(luminance.x) < fabs(luminance.y))
4502 if (delta.x <= delta.y)
4505 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4507 delta.y=1.0-delta.y;
4508 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4509 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4510 pixel[channel]=ClampToQuantum(gamma*MeshInterpolate(&delta,
4511 pixels[2],pixels[3],pixels[0]));
4516 Top-right triangle (pixel: 1, diagonal: 0-3).
4518 delta.x=1.0-delta.x;
4519 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4520 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4521 pixel[channel]=ClampToQuantum(gamma*MeshInterpolate(&delta,
4522 pixels[1],pixels[0],pixels[3]));
4530 if (delta.x <= (1.0-delta.y))
4533 Top-left triangle (pixel: 0, diagonal: 1-2).
4535 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4536 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4537 pixel[channel]=ClampToQuantum(gamma*MeshInterpolate(&delta,
4538 pixels[0],pixels[1],pixels[2]));
4543 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4545 delta.x=1.0-delta.x;
4546 delta.y=1.0-delta.y;
4547 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4548 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4549 pixel[channel]=ClampToQuantum(gamma*MeshInterpolate(&delta,
4550 pixels[3],pixels[2],pixels[1]));
4556 case SplineInterpolatePixel:
4558 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4560 if (p == (const Quantum *) NULL)
4565 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4584 traits=GetPixelChannelMapTraits(source,(PixelChannel) i);
4585 channel=GetPixelChannelMapChannel(source,(PixelChannel) i);
4586 destination_traits=GetPixelChannelMapTraits(destination,channel);
4587 if ((traits == UndefinedPixelTrait) ||
4588 (destination_traits == UndefinedPixelTrait))
4590 if ((traits & BlendPixelTrait) == 0)
4591 for (j=0; j < 16; j++)
4594 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4597 for (j=0; j < 16; j++)
4599 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4600 GetPixelChannels(source));
4601 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4607 for (j=(-1); j < 3L; j++)
4609 dy=CubicWeightingFunction((MagickRealType) j-delta.y);
4610 for (k=(-1); k < 3L; k++)
4612 dx=CubicWeightingFunction(delta.x-(MagickRealType) k);
4613 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 :
4615 sum+=gamma*dx*dy*pixels[n];
4619 pixel[channel]=ClampToQuantum(sum);
4628 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4632 % I n t e r p o l a t e P i x e l I n f o %
4636 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4638 % InterpolatePixelInfo() applies a pixel interpolation method between a
4639 % floating point coordinate and the pixels surrounding that coordinate. No
4640 % pixel area resampling, or scaling of the result is performed.
4642 % The format of the InterpolatePixelInfo method is:
4644 % MagickBooleanType InterpolatePixelInfo(const Image *image,
4645 % const CacheView *image_view,const PixelInterpolateMethod method,
4646 % const double x,const double y,PixelInfo *pixel,
4647 % ExceptionInfo *exception)
4649 % A description of each parameter follows:
4651 % o image: the image.
4653 % o image_view: the image view.
4655 % o method: the pixel color interpolation method.
4657 % o x,y: A double representing the current (x,y) position of the pixel.
4659 % o pixel: return the interpolated pixel here.
4661 % o exception: return any errors or warnings in this structure.
4665 static inline void AlphaBlendPixelInfo(const Image *image,
4666 const Quantum *pixel,PixelInfo *pixel_info,MagickRealType *alpha)
4668 if (image->matte == MagickFalse)
4671 pixel_info->red=(MagickRealType) GetPixelRed(image,pixel);
4672 pixel_info->green=(MagickRealType) GetPixelGreen(image,pixel);
4673 pixel_info->blue=(MagickRealType) GetPixelBlue(image,pixel);
4674 pixel_info->black=0.0;
4675 if (image->colorspace == CMYKColorspace)
4676 pixel_info->black=(MagickRealType) GetPixelBlack(image,pixel);
4677 pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
4680 *alpha=QuantumScale*GetPixelAlpha(image,pixel);
4681 pixel_info->red=(*alpha*GetPixelRed(image,pixel));
4682 pixel_info->green=(*alpha*GetPixelGreen(image,pixel));
4683 pixel_info->blue=(*alpha*GetPixelBlue(image,pixel));
4684 pixel_info->black=0.0;
4685 if (image->colorspace == CMYKColorspace)
4686 pixel_info->black=(*alpha*GetPixelBlack(image,pixel));
4687 pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
4690 static void BicubicInterpolate(const PixelInfo *pixels,const double dx,
4701 p=(pixels[3].red-pixels[2].red)-(pixels[0].red-pixels[1].red);
4702 q=(pixels[0].red-pixels[1].red)-p;
4703 r=pixels[2].red-pixels[0].red;
4705 pixel->red=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4706 p=(pixels[3].green-pixels[2].green)-(pixels[0].green-pixels[1].green);
4707 q=(pixels[0].green-pixels[1].green)-p;
4708 r=pixels[2].green-pixels[0].green;
4710 pixel->green=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4711 p=(pixels[3].blue-pixels[2].blue)-(pixels[0].blue-pixels[1].blue);
4712 q=(pixels[0].blue-pixels[1].blue)-p;
4713 r=pixels[2].blue-pixels[0].blue;
4715 pixel->blue=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4716 p=(pixels[3].alpha-pixels[2].alpha)-(pixels[0].alpha-pixels[1].alpha);
4717 q=(pixels[0].alpha-pixels[1].alpha)-p;
4718 r=pixels[2].alpha-pixels[0].alpha;
4720 pixel->alpha=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4721 if (pixel->colorspace == CMYKColorspace)
4723 p=(pixels[3].black-pixels[2].black)-(pixels[0].black-pixels[1].black);
4724 q=(pixels[0].black-pixels[1].black)-p;
4725 r=pixels[2].black-pixels[0].black;
4727 pixel->black=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4731 MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
4732 const CacheView *image_view,const PixelInterpolateMethod method,
4733 const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception)
4745 register const Quantum
4755 assert(image != (Image *) NULL);
4756 assert(image->signature == MagickSignature);
4757 assert(image_view != (CacheView *) NULL);
4759 x_offset=(ssize_t) floor(x);
4760 y_offset=(ssize_t) floor(y);
4761 switch (method == UndefinedInterpolatePixel ? image->interpolate : method)
4763 case AverageInterpolatePixel:
4765 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4767 if (p == (const Quantum *) NULL)
4772 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
4773 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
4774 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
4775 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
4776 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
4777 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
4778 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
4779 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
4780 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
4781 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
4782 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
4784 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
4786 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
4788 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
4790 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
4792 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
4799 for (i=0; i < 16L; i++)
4801 gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]);
4802 pixel->red+=gamma*0.0625*pixels[i].red;
4803 pixel->green+=gamma*0.0625*pixels[i].green;
4804 pixel->blue+=gamma*0.0625*pixels[i].blue;
4805 if (image->colorspace == CMYKColorspace)
4806 pixel->black+=gamma*0.0625*pixels[i].black;
4807 pixel->alpha+=0.0625*pixels[i].alpha;
4811 case BicubicInterpolatePixel:
4819 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4821 if (p == (const Quantum *) NULL)
4826 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
4827 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
4828 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
4829 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
4830 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
4831 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
4832 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
4833 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
4834 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
4835 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
4836 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
4838 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
4840 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
4842 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
4844 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
4846 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
4850 for (i=0; i < 4L; i++)
4851 BicubicInterpolate(pixels+4*i,delta.x,u+i);
4852 BicubicInterpolate(u,delta.y,pixel);
4855 case BilinearInterpolatePixel:
4862 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4863 if (p == (const Quantum *) NULL)
4868 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
4869 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
4870 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
4871 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
4874 epsilon.x=1.0-delta.x;
4875 epsilon.y=1.0-delta.y;
4876 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4877 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4878 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4879 pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
4880 pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red));
4881 pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x*
4882 pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x*
4884 pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x*
4885 pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x*
4887 if (image->colorspace == CMYKColorspace)
4888 pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x*
4889 pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x*
4891 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
4892 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4893 pixel->alpha=(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x*
4894 pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x*
4898 case FilterInterpolatePixel:
4912 geometry.x=x_offset-1;
4913 geometry.y=y_offset-1;
4914 excerpt_image=ExcerptImage(image,&geometry,exception);
4915 if (excerpt_image == (Image *) NULL)
4920 filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur,
4922 excerpt_image=DestroyImage(excerpt_image);
4923 if (filter_image == (Image *) NULL)
4925 filter_view=AcquireCacheView(filter_image);
4926 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4927 if (p != (const Quantum *) NULL)
4928 SetPixelInfo(image,p,pixel);
4929 filter_view=DestroyCacheView(filter_view);
4930 filter_image=DestroyImage(filter_image);
4933 case IntegerInterpolatePixel:
4935 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4936 if (p == (const Quantum *) NULL)
4941 SetPixelInfo(image,p,pixel);
4944 case MeshInterpolatePixel:
4950 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4951 if (p == (const Quantum *) NULL)
4958 luminance.x=GetPixelLuminance(image,p)-(double)
4959 GetPixelLuminance(image,p+3*GetPixelChannels(image));
4960 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
4961 GetPixelLuminance(image,p+2*GetPixelChannels(image));
4962 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
4963 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
4964 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
4965 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
4966 if (fabs(luminance.x) < fabs(luminance.y))
4971 if (delta.x <= delta.y)
4974 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4976 delta.y=1.0-delta.y;
4977 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4978 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4979 pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red,
4980 pixels[3].red,pixels[0].red);
4981 pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green,
4982 pixels[3].green,pixels[0].green);
4983 pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
4984 pixels[3].blue,pixels[0].blue);
4985 if (image->colorspace == CMYKColorspace)
4986 pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black,
4987 pixels[3].black,pixels[0].black);
4988 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
4989 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha,
4990 pixels[3].alpha,pixels[0].alpha);
4995 Top-right triangle (pixel:1 , diagonal: 0-3).
4997 delta.x=1.0-delta.x;
4998 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4999 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5000 pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red,
5001 pixels[0].red,pixels[3].red);
5002 pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green,
5003 pixels[0].green,pixels[3].green);
5004 pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
5005 pixels[0].blue,pixels[3].blue);
5006 if (image->colorspace == CMYKColorspace)
5007 pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black,
5008 pixels[0].black,pixels[3].black);
5009 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5010 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha,
5011 pixels[0].alpha,pixels[3].alpha);
5019 if (delta.x <= (1.0-delta.y))
5022 Top-left triangle (pixel: 0, diagonal: 1-2).
5024 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5025 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5026 pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red,
5027 pixels[1].red,pixels[2].red);
5028 pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green,
5029 pixels[1].green,pixels[2].green);
5030 pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
5031 pixels[1].blue,pixels[2].blue);
5032 if (image->colorspace == CMYKColorspace)
5033 pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black,
5034 pixels[1].black,pixels[2].black);
5035 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5036 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha,
5037 pixels[1].alpha,pixels[2].alpha);
5042 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5044 delta.x=1.0-delta.x;
5045 delta.y=1.0-delta.y;
5046 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5047 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5048 pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red,
5049 pixels[2].red,pixels[1].red);
5050 pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green,
5051 pixels[2].green,pixels[1].green);
5052 pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
5053 pixels[2].blue,pixels[1].blue);
5054 if (image->colorspace == CMYKColorspace)
5055 pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black,
5056 pixels[2].black,pixels[1].black);
5057 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5058 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha,
5059 pixels[2].alpha,pixels[1].alpha);
5064 case NearestNeighborInterpolatePixel:
5066 p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
5067 NearestNeighbor(y),1,1,exception);
5068 if (p == (const Quantum *) NULL)
5073 SetPixelInfo(image,p,pixel);
5076 case SplineInterpolatePixel:
5089 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5091 if (p == (const Quantum *) NULL)
5096 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5097 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5098 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5099 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5100 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
5101 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
5102 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
5103 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
5104 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
5105 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
5106 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
5108 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
5110 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
5112 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
5114 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
5116 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
5126 for (i=(-1); i < 3L; i++)
5128 dy=CubicWeightingFunction((MagickRealType) i-delta.y);
5129 for (j=(-1); j < 3L; j++)
5131 dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
5132 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]);
5133 pixel->red+=gamma*dx*dy*pixels[n].red;
5134 pixel->green+=gamma*dx*dy*pixels[n].green;
5135 pixel->blue+=gamma*dx*dy*pixels[n].blue;
5136 if (image->colorspace == CMYKColorspace)
5137 pixel->black+=gamma*dx*dy*pixels[n].black;
5138 pixel->alpha+=dx*dy*pixels[n].alpha;
5149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5153 + I s F u z z y E q u i v a l e n c e P i x e l %
5157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5159 % IsFuzzyEquivalencePixel() returns MagickTrue if the distance between two
5160 % pixels is less than the specified distance in a linear three (or four)u
5161 % dimensional color space.
5163 % The format of the IsFuzzyEquivalencePixel method is:
5165 % void IsFuzzyEquivalencePixel(const Image *image,const Quantum *p,
5168 % A description of each parameter follows:
5170 % o image: the image.
5177 MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *image,
5178 const Quantum *p,const Quantum *q)
5184 register MagickRealType
5188 fuzz=MagickMax(image->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(
5189 image->fuzz,(MagickRealType) MagickSQ1_2);
5192 if (image->matte != MagickFalse)
5195 Transparencies are involved - set alpha distance
5197 pixel=(MagickRealType) ((image->matte != MagickFalse ?
5198 GetPixelAlpha(image,p) : OpaqueAlpha)-(image->matte != MagickFalse ?
5199 GetPixelAlpha(image,q) : OpaqueAlpha));
5200 distance=pixel*pixel;
5201 if (distance > fuzz)
5202 return(MagickFalse);
5204 Generate a alpha scaling factor to generate a 4D cone on colorspace
5205 Note that if one color is transparent, distance has no color component.
5207 scale=QuantumScale*GetPixelAlpha(image,p);
5208 scale*=QuantumScale*GetPixelAlpha(image,q);
5209 if (scale <= MagickEpsilon)
5213 RGB or CMY color cube
5215 distance*=3.0; /* rescale appropriately */
5217 pixel=GetPixelRed(image,p)-(MagickRealType) GetPixelRed(image,q);
5218 if ((image->colorspace == HSLColorspace) ||
5219 (image->colorspace == HSBColorspace) ||
5220 (image->colorspace == HWBColorspace))
5223 Compute an arc distance for hue. It should be a vector angle of
5224 'S'/'W' length with 'L'/'B' forming appropriate cones.
5226 if (fabs((double) pixel) > (QuantumRange/2))
5227 pixel-=QuantumRange;
5230 distance+=scale*pixel*pixel;
5231 if (distance > fuzz)
5232 return(MagickFalse);
5233 pixel=GetPixelGreen(image,p)-(MagickRealType) GetPixelGreen(image,q);
5234 distance+=scale*pixel*pixel;
5235 if (distance > fuzz)
5236 return(MagickFalse);
5237 pixel=GetPixelBlue(image,p)-(MagickRealType) GetPixelBlue(image,q);
5238 distance+=scale*pixel*pixel;
5239 if (distance > fuzz)
5240 return(MagickFalse);
5245 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5249 + 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 %
5253 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5255 % IsFuzzyEquivalencePixelInfo() returns true if the distance between two
5256 % colors is less than the specified distance in a linear three (or four)
5257 % dimensional color space.
5259 % This implements the equivalent of:
5260 % fuzz < sqrt(color_distance^2 * u.a*v.a + alpha_distance^2)
5262 % Which produces a multi-dimensional cone for that colorspace along the
5263 % transparency vector.
5265 % For example for an RGB:
5266 % color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3
5268 % See http://www.imagemagick.org/Usage/bugs/fuzz_distance/
5270 % Hue colorspace distances need more work. Hue is not a distance, it is an
5273 % A check that q is in the same color space as p should be made and the
5274 % appropriate mapping made. -- Anthony Thyssen 8 December 2010
5276 % The format of the IsFuzzyEquivalencePixelInfo method is:
5278 % MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5279 % const PixelInfo *q)
5281 % A description of each parameter follows:
5288 MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5295 register MagickRealType
5299 if ((p->fuzz == 0.0) && (q->fuzz == 0.0))
5300 return(IsPixelInfoEquivalent(p,q));
5302 fuzz=MagickMax(q->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz,
5303 (MagickRealType) MagickSQ1_2);
5304 else if (q->fuzz == 0.0)
5305 fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(p->fuzz,
5306 (MagickRealType) MagickSQ1_2);
5308 fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz,
5309 (MagickRealType) MagickSQ1_2);
5312 if ((p->matte != MagickFalse) || (q->matte != MagickFalse))
5315 Transparencies are involved - set alpha distance.
5317 pixel=(p->matte != MagickFalse ? p->alpha : OpaqueAlpha)-
5318 (q->matte != MagickFalse ? q->alpha : OpaqueAlpha);
5319 distance=pixel*pixel;
5320 if (distance > fuzz)
5321 return(MagickFalse);
5323 Generate a alpha scaling factor to generate a 4D cone on colorspace.
5324 If one color is transparent, distance has no color component.
5326 if (p->matte != MagickFalse)
5327 scale=(QuantumScale*p->alpha);
5328 if (q->matte != MagickFalse)
5329 scale*=(QuantumScale*q->alpha);
5330 if (scale <= MagickEpsilon )
5334 CMYK create a CMY cube with a multi-dimensional cone toward black.
5336 if (p->colorspace == CMYKColorspace)
5338 pixel=p->black-q->black;
5339 distance+=pixel*pixel*scale;
5340 if (distance > fuzz)
5341 return(MagickFalse);
5342 scale*=(MagickRealType) (QuantumScale*(QuantumRange-p->black));
5343 scale*=(MagickRealType) (QuantumScale*(QuantumRange-q->black));
5346 RGB or CMY color cube.
5348 distance*=3.0; /* rescale appropriately */
5350 pixel=p->red-q->red;
5351 if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) ||
5352 (p->colorspace == HWBColorspace))
5355 This calculates a arc distance for hue-- it should be a vector angle
5356 of 'S'/'W' length with 'L'/'B' forming appropriate cones. In other
5357 words this is a hack - Anthony.
5359 if (fabs((double) pixel) > (QuantumRange/2))
5360 pixel-=QuantumRange;
5363 distance+=pixel*pixel*scale;
5364 if (distance > fuzz)
5365 return(MagickFalse);
5366 pixel=p->green-q->green;
5367 distance+=pixel*pixel*scale;
5368 if (distance > fuzz)
5369 return(MagickFalse);
5370 pixel=p->blue-q->blue;
5371 distance+=pixel*pixel*scale;
5372 if (distance > fuzz)
5373 return(MagickFalse);
5378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5382 % S e t P i x e l C h a n n e l M a p %
5386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5388 % SetPixelChannelMap() sets the pixel channel map from the specified channel
5391 % The format of the SetPixelChannelMap method is:
5393 % void SetPixelChannelMap(Image *image,const ChannelType channel_mask)
5395 % A description of each parameter follows:
5397 % o image: the image.
5399 % o mask: the channel mask.
5402 MagickExport void SetPixelChannelMap(Image *image,
5403 const ChannelType channel_mask)
5405 #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
5410 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5411 SetPixelChannelMapTraits(image,(PixelChannel) i,
5412 GetChannelBit(channel_mask,i) != 0 ? UpdatePixelTrait : CopyPixelTrait);
5413 for ( ; i < MaxPixelChannels; i++)
5414 SetPixelChannelMapTraits(image,(PixelChannel) i,UndefinedPixelTrait);
5415 if (image->storage_class == PseudoClass)
5416 SetPixelChannelMapTraits(image,IndexPixelChannel,CopyPixelTrait);
5417 if (image->debug != MagickFalse)
5418 LogPixelChannels(image);
5422 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5426 % S e t P i x e l C h a n n e l M a s k %
5430 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5432 % SetPixelChannelMask() sets the pixel channel mask from the specified channel
5435 % The format of the SetPixelChannelMask method is:
5437 % ChannelType SetPixelChannelMask(Image *image,
5438 % const ChannelType channel_mask)
5440 % A description of each parameter follows:
5442 % o image: the image.
5444 % o channel_mask: the channel mask.
5447 MagickExport ChannelType SetPixelChannelMask(Image *image,
5448 const ChannelType channel_mask)
5453 mask=image->channel_mask;
5454 image->channel_mask=channel_mask;
5455 SetPixelChannelMap(image,channel_mask);