2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % PPPP IIIII X X EEEEE L %
10 % P IIIII X X EEEEE LLLLL %
12 % MagickCore Methods to Import/Export Pixels %
19 % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
20 % dedicated to making software imaging solutions freely available. %
22 % You may not use this file except in compliance with the License. You may %
23 % obtain a copy of the License at %
25 % http://www.imagemagick.org/script/license.php %
27 % Unless required by applicable law or agreed to in writing, software %
28 % distributed under the License is distributed on an "AS IS" BASIS, %
29 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
30 % See the License for the specific language governing permissions and %
31 % limitations under the License. %
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 #include "MagickCore/studio.h"
42 #include "MagickCore/property.h"
43 #include "MagickCore/blob.h"
44 #include "MagickCore/blob-private.h"
45 #include "MagickCore/color-private.h"
46 #include "MagickCore/draw.h"
47 #include "MagickCore/exception.h"
48 #include "MagickCore/exception-private.h"
49 #include "MagickCore/cache.h"
50 #include "MagickCore/constitute.h"
51 #include "MagickCore/delegate.h"
52 #include "MagickCore/geometry.h"
53 #include "MagickCore/image-private.h"
54 #include "MagickCore/list.h"
55 #include "MagickCore/magick.h"
56 #include "MagickCore/memory_.h"
57 #include "MagickCore/monitor.h"
58 #include "MagickCore/option.h"
59 #include "MagickCore/pixel.h"
60 #include "MagickCore/pixel-accessor.h"
61 #include "MagickCore/quantum.h"
62 #include "MagickCore/quantum-private.h"
63 #include "MagickCore/resource_.h"
64 #include "MagickCore/semaphore.h"
65 #include "MagickCore/statistic.h"
66 #include "MagickCore/stream.h"
67 #include "MagickCore/string_.h"
68 #include "MagickCore/transform.h"
69 #include "MagickCore/utility.h"
71 #define LogPixelChannels(image) \
76 (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%.20g]", \
77 image->filename,(double) image->number_channels); \
78 for (i=0; i < (ssize_t) image->number_channels; i++) \
81 traits[MaxTextExtent]; \
89 switch (GetPixelChannelMapChannel(image,i)) \
91 case RedPixelChannel: \
94 if (image->colorspace == CMYKColorspace) \
96 if (image->colorspace == GRAYColorspace) \
100 case GreenPixelChannel: \
103 if (image->colorspace == CMYKColorspace) \
107 case BluePixelChannel: \
110 if (image->colorspace == CMYKColorspace) \
114 case BlackPixelChannel: \
117 if (image->storage_class == PseudoClass) \
121 case IndexPixelChannel: \
126 case AlphaPixelChannel: \
131 case MaskPixelChannel: \
136 case MetaPixelChannel: \
144 channel=GetPixelChannelMapChannel(image,i); \
146 if ((GetPixelChannelMapTraits(image,channel) & UpdatePixelTrait) != 0) \
147 (void) ConcatenateMagickString(traits,"update,",MaxTextExtent); \
148 if ((GetPixelChannelMapTraits(image,channel) & BlendPixelTrait) != 0) \
149 (void) ConcatenateMagickString(traits,"blend,",MaxTextExtent); \
150 if ((GetPixelChannelMapTraits(image,channel) & CopyPixelTrait) != 0) \
151 (void) ConcatenateMagickString(traits,"copy,",MaxTextExtent); \
152 if (*traits == '\0') \
153 (void) ConcatenateMagickString(traits,"undefined,",MaxTextExtent); \
154 traits[strlen(traits)-1]='\0'; \
155 (void) LogMagickEvent(PixelEvent,GetMagickModule()," %.20g: %s (%s)", \
156 (double) i,name,traits); \
161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165 + A c q u i r e P i x e l C h a n n e l M a p %
169 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171 % AcquirePixelChannelMap() acquires a pixel component map.
173 % The format of the AcquirePixelChannelMap() method is:
175 % PixelChannelMap *AcquirePixelChannelMap(void)
178 MagickExport PixelChannelMap *AcquirePixelChannelMap(void)
186 channel_map=(PixelChannelMap *) AcquireQuantumMemory(MaxPixelChannels,
187 sizeof(*channel_map));
188 if (channel_map == (PixelChannelMap *) NULL)
189 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
190 (void) ResetMagickMemory(channel_map,0,MaxPixelChannels*sizeof(*channel_map));
191 for (i=0; i < MaxPixelChannels; i++)
192 channel_map[i].channel=(PixelChannel) i;
197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 + C l o n e P i x e l C h a n n e l M a p %
205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
207 % ClonePixelChannelMap() clones a pixel component map.
209 % The format of the ClonePixelChannelMap() method is:
211 % PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
213 % A description of each parameter follows:
215 % o channel_map: the pixel component map.
218 MagickExport PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
223 assert(channel_map != (PixelChannelMap *) NULL);
224 clone_map=AcquirePixelChannelMap();
225 if (clone_map == (PixelChannelMap *) NULL)
226 return((PixelChannelMap *) NULL);
227 (void) CopyMagickMemory(clone_map,channel_map,MaxPixelChannels*
228 sizeof(*channel_map));
233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
237 + C l o n e P i x e l I n f o %
241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243 % ClonePixelInfo() makes a duplicate of the given pixel info structure, or if
244 % pixel info is NULL, a new one.
246 % The format of the ClonePixelInfo method is:
248 % PixelInfo *ClonePixelInfo(const PixelInfo *pixel_info)
250 % A description of each parameter follows:
252 % o pixel_info: the pixel info.
255 MagickExport PixelInfo *ClonePixelInfo(const PixelInfo *pixel)
260 pixel_info=(PixelInfo *) AcquireQuantumMemory(1,sizeof(*pixel_info));
261 if (pixel_info == (PixelInfo *) NULL)
262 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
263 *pixel_info=(*pixel);
268 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
272 + D e s t r o y P i x e l C h a n n e l M a p %
276 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278 % DestroyPixelChannelMap() deallocates memory associated with the pixel
281 % The format of the DestroyPixelChannelMap() method is:
283 % PixelChannelMap *DestroyPixelChannelMap(PixelChannelMap *channel_map)
285 % A description of each parameter follows:
287 % o channel_map: the pixel component map.
290 MagickExport PixelChannelMap *DestroyPixelChannelMap(
291 PixelChannelMap *channel_map)
293 assert(channel_map != (PixelChannelMap *) NULL);
294 channel_map=(PixelChannelMap *) RelinquishMagickMemory(channel_map);
295 return((PixelChannelMap *) RelinquishMagickMemory(channel_map));
299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
303 % E x p o r t I m a g e P i x e l s %
307 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309 % ExportImagePixels() extracts pixel data from an image and returns it to you.
310 % The method returns MagickTrue on success otherwise MagickFalse if an error is
311 % encountered. The data is returned as char, short int, int, ssize_t, float,
312 % or double in the order specified by map.
314 % Suppose you want to extract the first scanline of a 640x480 image as
315 % character data in red-green-blue order:
317 % ExportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels,exception);
319 % The format of the ExportImagePixels method is:
321 % MagickBooleanType ExportImagePixels(const Image *image,
322 % const ssize_t x_offset,const ssize_t y_offset,const size_t columns,
323 % const size_t rows,const char *map,const StorageType type,
324 % void *pixels,ExceptionInfo *exception)
326 % A description of each parameter follows:
328 % o image: the image.
330 % o x_offset,y_offset,columns,rows: These values define the perimeter
331 % of a region of pixels you want to extract.
333 % o map: This string reflects the expected ordering of the pixel array.
334 % It can be any combination or order of R = red, G = green, B = blue,
335 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
336 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
339 % o type: Define the data type of the pixels. Float and double types are
340 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
341 % types: CharPixel, DoublePixel, FloatPixel, IntegerPixel, LongPixel,
342 % QuantumPixel, or ShortPixel.
344 % o pixels: This array of values contain the pixel components as defined by
345 % map and type. You must preallocate this array where the expected
346 % length varies depending on the values of width, height, map, and type.
348 % o exception: return any errors or warnings in this structure.
352 static void ExportCharPixel(const Image *image,const ssize_t x_offset,
353 const ssize_t y_offset,const size_t columns,const size_t rows,
354 const char *restrict map,const QuantumType *quantum_map,
355 unsigned char *restrict pixels,ExceptionInfo *exception)
357 register const Quantum
363 register unsigned char
370 if (LocaleCompare(map,"BGR") == 0)
372 for (y=0; y < (ssize_t) rows; y++)
374 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
375 if (p == (const Quantum *) NULL)
377 for (x=0; x < (ssize_t) columns; x++)
379 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
380 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
381 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
382 p+=GetPixelChannels(image);
387 if (LocaleCompare(map,"BGRA") == 0)
389 for (y=0; y < (ssize_t) rows; y++)
391 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
392 if (p == (const Quantum *) NULL)
394 for (x=0; x < (ssize_t) columns; x++)
396 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
397 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
398 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
399 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
400 p+=GetPixelChannels(image);
405 if (LocaleCompare(map,"BGRP") == 0)
407 for (y=0; y < (ssize_t) rows; y++)
409 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
410 if (p == (const Quantum *) NULL)
412 for (x=0; x < (ssize_t) columns; x++)
414 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
415 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
416 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
417 *q++=ScaleQuantumToChar((Quantum) 0);
418 p+=GetPixelChannels(image);
423 if (LocaleCompare(map,"I") == 0)
425 for (y=0; y < (ssize_t) rows; y++)
427 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
428 if (p == (const Quantum *) NULL)
430 for (x=0; x < (ssize_t) columns; x++)
432 *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
433 p+=GetPixelChannels(image);
438 if (LocaleCompare(map,"RGB") == 0)
440 for (y=0; y < (ssize_t) rows; y++)
442 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
443 if (p == (const Quantum *) NULL)
445 for (x=0; x < (ssize_t) columns; x++)
447 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
448 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
449 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
450 p+=GetPixelChannels(image);
455 if (LocaleCompare(map,"RGBA") == 0)
457 for (y=0; y < (ssize_t) rows; y++)
459 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
460 if (p == (const Quantum *) NULL)
462 for (x=0; x < (ssize_t) columns; x++)
464 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
465 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
466 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
467 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
468 p+=GetPixelChannels(image);
473 if (LocaleCompare(map,"RGBP") == 0)
475 for (y=0; y < (ssize_t) rows; y++)
477 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
478 if (p == (const Quantum *) NULL)
480 for (x=0; x < (ssize_t) columns; x++)
482 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
483 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
484 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
485 *q++=ScaleQuantumToChar((Quantum) 0);
486 p+=GetPixelChannels(image);
491 for (y=0; y < (ssize_t) rows; y++)
493 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
494 if (p == (const Quantum *) NULL)
496 for (x=0; x < (ssize_t) columns; x++)
501 for (i=0; i < (ssize_t) strlen(map); i++)
504 switch (quantum_map[i])
509 *q=ScaleQuantumToChar(GetPixelRed(image,p));
515 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
521 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
526 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
531 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
536 if (image->colorspace == CMYKColorspace)
537 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
542 *q=ScaleQuantumToChar(GetPixelIntensity(image,p));
550 p+=GetPixelChannels(image);
555 static void ExportDoublePixel(const Image *image,const ssize_t x_offset,
556 const ssize_t y_offset,const size_t columns,const size_t rows,
557 const char *restrict map,const QuantumType *quantum_map,
558 unsigned char *restrict pixels,ExceptionInfo *exception)
560 register const Quantum
573 if (LocaleCompare(map,"BGR") == 0)
575 for (y=0; y < (ssize_t) rows; y++)
577 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
578 if (p == (const Quantum *) NULL)
580 for (x=0; x < (ssize_t) columns; x++)
582 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
583 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
584 *q++=(double) (QuantumScale*GetPixelRed(image,p));
585 p+=GetPixelChannels(image);
590 if (LocaleCompare(map,"BGRA") == 0)
592 for (y=0; y < (ssize_t) rows; y++)
594 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
595 if (p == (const Quantum *) NULL)
597 for (x=0; x < (ssize_t) columns; x++)
599 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
600 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
601 *q++=(double) (QuantumScale*GetPixelRed(image,p));
602 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
603 p+=GetPixelChannels(image);
608 if (LocaleCompare(map,"BGRP") == 0)
610 for (y=0; y < (ssize_t) rows; y++)
612 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
613 if (p == (const Quantum *) NULL)
615 for (x=0; x < (ssize_t) columns; x++)
617 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
618 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
619 *q++=(double) (QuantumScale*GetPixelRed(image,p));
621 p+=GetPixelChannels(image);
626 if (LocaleCompare(map,"I") == 0)
628 for (y=0; y < (ssize_t) rows; y++)
630 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
631 if (p == (const Quantum *) NULL)
633 for (x=0; x < (ssize_t) columns; x++)
635 *q++=(double) (QuantumScale*GetPixelIntensity(image,p));
636 p+=GetPixelChannels(image);
641 if (LocaleCompare(map,"RGB") == 0)
643 for (y=0; y < (ssize_t) rows; y++)
645 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
646 if (p == (const Quantum *) NULL)
648 for (x=0; x < (ssize_t) columns; x++)
650 *q++=(double) (QuantumScale*GetPixelRed(image,p));
651 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
652 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
653 p+=GetPixelChannels(image);
658 if (LocaleCompare(map,"RGBA") == 0)
660 for (y=0; y < (ssize_t) rows; y++)
662 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
663 if (p == (const Quantum *) NULL)
665 for (x=0; x < (ssize_t) columns; x++)
667 *q++=(double) (QuantumScale*GetPixelRed(image,p));
668 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
669 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
670 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
671 p+=GetPixelChannels(image);
676 if (LocaleCompare(map,"RGBP") == 0)
678 for (y=0; y < (ssize_t) rows; y++)
680 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
681 if (p == (const Quantum *) NULL)
683 for (x=0; x < (ssize_t) columns; x++)
685 *q++=(double) (QuantumScale*GetPixelRed(image,p));
686 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
687 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
689 p+=GetPixelChannels(image);
694 for (y=0; y < (ssize_t) rows; y++)
696 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
697 if (p == (const Quantum *) NULL)
699 for (x=0; x < (ssize_t) columns; x++)
704 for (i=0; i < (ssize_t) strlen(map); i++)
707 switch (quantum_map[i])
712 *q=(double) (QuantumScale*GetPixelRed(image,p));
718 *q=(double) (QuantumScale*GetPixelGreen(image,p));
724 *q=(double) (QuantumScale*GetPixelBlue(image,p));
729 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
734 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
739 if (image->colorspace == CMYKColorspace)
740 *q=(double) (QuantumScale*
741 GetPixelBlack(image,p));
746 *q=(double) (QuantumScale*GetPixelIntensity(image,p));
754 p+=GetPixelChannels(image);
759 static void ExportFloatPixel(const Image *image,const ssize_t x_offset,
760 const ssize_t y_offset,const size_t columns,const size_t rows,
761 const char *restrict map,const QuantumType *quantum_map,
762 unsigned char *restrict pixels,ExceptionInfo *exception)
764 register const Quantum
777 if (LocaleCompare(map,"BGR") == 0)
779 for (y=0; y < (ssize_t) rows; y++)
781 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
782 if (p == (const Quantum *) NULL)
784 for (x=0; x < (ssize_t) columns; x++)
786 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
787 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
788 *q++=(float) (QuantumScale*GetPixelRed(image,p));
789 p+=GetPixelChannels(image);
794 if (LocaleCompare(map,"BGRA") == 0)
796 for (y=0; y < (ssize_t) rows; y++)
798 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
799 if (p == (const Quantum *) NULL)
801 for (x=0; x < (ssize_t) columns; x++)
803 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
804 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
805 *q++=(float) (QuantumScale*GetPixelRed(image,p));
806 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
807 p+=GetPixelChannels(image);
812 if (LocaleCompare(map,"BGRP") == 0)
814 for (y=0; y < (ssize_t) rows; y++)
816 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
817 if (p == (const Quantum *) NULL)
819 for (x=0; x < (ssize_t) columns; x++)
821 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
822 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
823 *q++=(float) (QuantumScale*GetPixelRed(image,p));
825 p+=GetPixelChannels(image);
830 if (LocaleCompare(map,"I") == 0)
832 for (y=0; y < (ssize_t) rows; y++)
834 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
835 if (p == (const Quantum *) NULL)
837 for (x=0; x < (ssize_t) columns; x++)
839 *q++=(float) (QuantumScale*GetPixelIntensity(image,p));
840 p+=GetPixelChannels(image);
845 if (LocaleCompare(map,"RGB") == 0)
847 for (y=0; y < (ssize_t) rows; y++)
849 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
850 if (p == (const Quantum *) NULL)
852 for (x=0; x < (ssize_t) columns; x++)
854 *q++=(float) (QuantumScale*GetPixelRed(image,p));
855 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
856 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
857 p+=GetPixelChannels(image);
862 if (LocaleCompare(map,"RGBA") == 0)
864 for (y=0; y < (ssize_t) rows; y++)
866 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
867 if (p == (const Quantum *) NULL)
869 for (x=0; x < (ssize_t) columns; x++)
871 *q++=(float) (QuantumScale*GetPixelRed(image,p));
872 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
873 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
874 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
875 p+=GetPixelChannels(image);
880 if (LocaleCompare(map,"RGBP") == 0)
882 for (y=0; y < (ssize_t) rows; y++)
884 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
885 if (p == (const Quantum *) NULL)
887 for (x=0; x < (ssize_t) columns; x++)
889 *q++=(float) (QuantumScale*GetPixelRed(image,p));
890 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
891 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
893 p+=GetPixelChannels(image);
898 for (y=0; y < (ssize_t) rows; y++)
900 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
901 if (p == (const Quantum *) NULL)
903 for (x=0; x < (ssize_t) columns; x++)
908 for (i=0; i < (ssize_t) strlen(map); i++)
911 switch (quantum_map[i])
916 *q=(float) (QuantumScale*GetPixelRed(image,p));
922 *q=(float) (QuantumScale*GetPixelGreen(image,p));
928 *q=(float) (QuantumScale*GetPixelBlue(image,p));
933 *q=(float) (QuantumScale*((Quantum) (GetPixelAlpha(image,p))));
938 *q=(float) (QuantumScale*GetPixelAlpha(image,p));
943 if (image->colorspace == CMYKColorspace)
944 *q=(float) (QuantumScale* GetPixelBlack(image,p));
949 *q=(float) (QuantumScale*GetPixelIntensity(image,p));
957 p+=GetPixelChannels(image);
962 static void ExportIntegerPixel(const Image *image,const ssize_t x_offset,
963 const ssize_t y_offset,const size_t columns,const size_t rows,
964 const char *restrict map,const QuantumType *quantum_map,
965 unsigned char *restrict pixels,ExceptionInfo *exception)
967 register const Quantum
973 register unsigned int
979 q=(unsigned int *) pixels;
980 if (LocaleCompare(map,"BGR") == 0)
982 for (y=0; y < (ssize_t) rows; y++)
984 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
985 if (p == (const Quantum *) NULL)
987 for (x=0; x < (ssize_t) columns; x++)
989 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
990 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
991 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
992 p+=GetPixelChannels(image);
997 if (LocaleCompare(map,"BGRA") == 0)
999 for (y=0; y < (ssize_t) rows; y++)
1001 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1002 if (p == (const Quantum *) NULL)
1004 for (x=0; x < (ssize_t) columns; x++)
1006 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1007 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1008 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1009 *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
1010 p+=GetPixelChannels(image);
1015 if (LocaleCompare(map,"BGRP") == 0)
1017 for (y=0; y < (ssize_t) rows; y++)
1019 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1020 if (p == (const Quantum *) NULL)
1022 for (x=0; x < (ssize_t) columns; x++)
1024 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1025 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1026 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1028 p+=GetPixelChannels(image);
1033 if (LocaleCompare(map,"I") == 0)
1035 for (y=0; y < (ssize_t) rows; y++)
1037 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1038 if (p == (const Quantum *) NULL)
1040 for (x=0; x < (ssize_t) columns; x++)
1042 *q++=(unsigned int) ScaleQuantumToLong(
1043 GetPixelIntensity(image,p));
1044 p+=GetPixelChannels(image);
1049 if (LocaleCompare(map,"RGB") == 0)
1051 for (y=0; y < (ssize_t) rows; y++)
1053 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1054 if (p == (const Quantum *) NULL)
1056 for (x=0; x < (ssize_t) columns; x++)
1058 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1059 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1060 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1061 p+=GetPixelChannels(image);
1066 if (LocaleCompare(map,"RGBA") == 0)
1068 for (y=0; y < (ssize_t) rows; y++)
1070 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1071 if (p == (const Quantum *) NULL)
1073 for (x=0; x < (ssize_t) columns; x++)
1075 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1076 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1077 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1078 *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
1079 p+=GetPixelChannels(image);
1084 if (LocaleCompare(map,"RGBP") == 0)
1086 for (y=0; y < (ssize_t) rows; y++)
1088 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1089 if (p == (const Quantum *) NULL)
1091 for (x=0; x < (ssize_t) columns; x++)
1093 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1094 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1095 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1097 p+=GetPixelChannels(image);
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++)
1112 for (i=0; i < (ssize_t) strlen(map); i++)
1115 switch (quantum_map[i])
1120 *q=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1124 case MagentaQuantum:
1126 *q=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1132 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1137 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
1140 case OpacityQuantum:
1142 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
1147 if (image->colorspace == CMYKColorspace)
1148 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlack(image,p));
1153 *q=(unsigned int) ScaleQuantumToLong(
1154 GetPixelIntensity(image,p));
1162 p+=GetPixelChannels(image);
1167 static void ExportLongPixel(const Image *image,const ssize_t x_offset,
1168 const ssize_t y_offset,const size_t columns,const size_t rows,
1169 const char *restrict map,const QuantumType *quantum_map,
1170 unsigned char *restrict pixels,ExceptionInfo *exception)
1172 register const Quantum
1178 register MagickSizeType
1184 q=(MagickSizeType *) pixels;
1185 if (LocaleCompare(map,"BGR") == 0)
1187 for (y=0; y < (ssize_t) rows; y++)
1189 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1190 if (p == (const Quantum *) NULL)
1192 for (x=0; x < (ssize_t) columns; x++)
1194 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1195 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1196 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1197 p+=GetPixelChannels(image);
1202 if (LocaleCompare(map,"BGRA") == 0)
1204 for (y=0; y < (ssize_t) rows; y++)
1206 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1207 if (p == (const Quantum *) NULL)
1209 for (x=0; x < (ssize_t) columns; x++)
1211 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1212 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1213 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1214 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1215 p+=GetPixelChannels(image);
1220 if (LocaleCompare(map,"BGRP") == 0)
1222 for (y=0; y < (ssize_t) rows; y++)
1224 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1225 if (p == (const Quantum *) NULL)
1227 for (x=0; x < (ssize_t) columns; x++)
1229 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1230 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1231 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1233 p+=GetPixelChannels(image);
1238 if (LocaleCompare(map,"I") == 0)
1240 for (y=0; y < (ssize_t) rows; y++)
1242 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1243 if (p == (const Quantum *) NULL)
1245 for (x=0; x < (ssize_t) columns; x++)
1247 *q++=ScaleQuantumToLongLong(GetPixelIntensity(image,p));
1248 p+=GetPixelChannels(image);
1253 if (LocaleCompare(map,"RGB") == 0)
1255 for (y=0; y < (ssize_t) rows; y++)
1257 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1258 if (p == (const Quantum *) NULL)
1260 for (x=0; x < (ssize_t) columns; x++)
1262 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1263 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1264 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1265 p+=GetPixelChannels(image);
1270 if (LocaleCompare(map,"RGBA") == 0)
1272 for (y=0; y < (ssize_t) rows; y++)
1274 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1275 if (p == (const Quantum *) NULL)
1277 for (x=0; x < (ssize_t) columns; x++)
1279 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1280 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1281 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1282 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1283 p+=GetPixelChannels(image);
1288 if (LocaleCompare(map,"RGBP") == 0)
1290 for (y=0; y < (ssize_t) rows; y++)
1292 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1293 if (p == (const Quantum *) NULL)
1295 for (x=0; x < (ssize_t) columns; x++)
1297 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1298 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1299 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1301 p+=GetPixelChannels(image);
1306 for (y=0; y < (ssize_t) rows; y++)
1308 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1309 if (p == (const Quantum *) NULL)
1311 for (x=0; x < (ssize_t) columns; x++)
1316 for (i=0; i < (ssize_t) strlen(map); i++)
1319 switch (quantum_map[i])
1324 *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
1328 case MagentaQuantum:
1330 *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1336 *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1341 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1344 case OpacityQuantum:
1346 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1351 if (image->colorspace == CMYKColorspace)
1352 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
1357 *q=ScaleQuantumToLongLong(GetPixelIntensity(image,p));
1365 p+=GetPixelChannels(image);
1370 static void ExportQuantumPixel(const Image *image,const ssize_t x_offset,
1371 const ssize_t y_offset,const size_t columns,const size_t rows,
1372 const char *restrict map,const QuantumType *quantum_map,
1373 unsigned char *restrict pixels,ExceptionInfo *exception)
1375 register const Quantum
1387 q=(Quantum *) pixels;
1388 if (LocaleCompare(map,"BGR") == 0)
1390 for (y=0; y < (ssize_t) rows; y++)
1392 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1393 if (p == (const Quantum *) NULL)
1395 for (x=0; x < (ssize_t) columns; x++)
1397 *q++=GetPixelBlue(image,p);
1398 *q++=GetPixelGreen(image,p);
1399 *q++=GetPixelRed(image,p);
1400 p+=GetPixelChannels(image);
1405 if (LocaleCompare(map,"BGRA") == 0)
1407 for (y=0; y < (ssize_t) rows; y++)
1409 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1410 if (p == (const Quantum *) NULL)
1412 for (x=0; x < (ssize_t) columns; x++)
1414 *q++=GetPixelBlue(image,p);
1415 *q++=GetPixelGreen(image,p);
1416 *q++=GetPixelRed(image,p);
1417 *q++=(Quantum) (GetPixelAlpha(image,p));
1418 p+=GetPixelChannels(image);
1423 if (LocaleCompare(map,"BGRP") == 0)
1425 for (y=0; y < (ssize_t) rows; y++)
1427 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1428 if (p == (const Quantum *) NULL)
1430 for (x=0; x < (ssize_t) columns; x++)
1432 *q++=GetPixelBlue(image,p);
1433 *q++=GetPixelGreen(image,p);
1434 *q++=GetPixelRed(image,p);
1436 p+=GetPixelChannels(image);
1441 if (LocaleCompare(map,"I") == 0)
1443 for (y=0; y < (ssize_t) rows; y++)
1445 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1446 if (p == (const Quantum *) NULL)
1448 for (x=0; x < (ssize_t) columns; x++)
1450 *q++=GetPixelIntensity(image,p);
1451 p+=GetPixelChannels(image);
1456 if (LocaleCompare(map,"RGB") == 0)
1458 for (y=0; y < (ssize_t) rows; y++)
1460 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1461 if (p == (const Quantum *) NULL)
1463 for (x=0; x < (ssize_t) columns; x++)
1465 *q++=GetPixelRed(image,p);
1466 *q++=GetPixelGreen(image,p);
1467 *q++=GetPixelBlue(image,p);
1468 p+=GetPixelChannels(image);
1473 if (LocaleCompare(map,"RGBA") == 0)
1475 for (y=0; y < (ssize_t) rows; y++)
1477 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1478 if (p == (const Quantum *) NULL)
1480 for (x=0; x < (ssize_t) columns; x++)
1482 *q++=GetPixelRed(image,p);
1483 *q++=GetPixelGreen(image,p);
1484 *q++=GetPixelBlue(image,p);
1485 *q++=(Quantum) (GetPixelAlpha(image,p));
1486 p+=GetPixelChannels(image);
1491 if (LocaleCompare(map,"RGBP") == 0)
1493 for (y=0; y < (ssize_t) rows; y++)
1495 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1496 if (p == (const Quantum *) NULL)
1498 for (x=0; x < (ssize_t) columns; x++)
1500 *q++=GetPixelRed(image,p);
1501 *q++=GetPixelGreen(image,p);
1502 *q++=GetPixelBlue(image,p);
1504 p+=GetPixelChannels(image);
1509 for (y=0; y < (ssize_t) rows; y++)
1511 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1512 if (p == (const Quantum *) NULL)
1514 for (x=0; x < (ssize_t) columns; x++)
1519 for (i=0; i < (ssize_t) strlen(map); i++)
1522 switch (quantum_map[i])
1527 *q=GetPixelRed(image,p);
1531 case MagentaQuantum:
1533 *q=GetPixelGreen(image,p);
1539 *q=GetPixelBlue(image,p);
1544 *q=GetPixelAlpha(image,p);
1547 case OpacityQuantum:
1549 *q=GetPixelAlpha(image,p);
1554 if (image->colorspace == CMYKColorspace)
1555 *q=GetPixelBlack(image,p);
1560 *q=(GetPixelIntensity(image,p));
1571 p+=GetPixelChannels(image);
1576 static void ExportShortPixel(const Image *image,const ssize_t x_offset,
1577 const ssize_t y_offset,const size_t columns,const size_t rows,
1578 const char *restrict map,const QuantumType *quantum_map,
1579 unsigned char *restrict pixels,ExceptionInfo *exception)
1581 register const Quantum
1590 register unsigned short
1593 q=(unsigned short *) pixels;
1594 if (LocaleCompare(map,"BGR") == 0)
1596 for (y=0; y < (ssize_t) rows; y++)
1598 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1599 if (p == (const Quantum *) NULL)
1601 for (x=0; x < (ssize_t) columns; x++)
1603 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1604 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1605 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1606 p+=GetPixelChannels(image);
1611 if (LocaleCompare(map,"BGRA") == 0)
1613 for (y=0; y < (ssize_t) rows; y++)
1615 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1616 if (p == (const Quantum *) NULL)
1618 for (x=0; x < (ssize_t) columns; x++)
1620 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1621 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1622 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1623 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1624 p+=GetPixelChannels(image);
1629 if (LocaleCompare(map,"BGRP") == 0)
1631 for (y=0; y < (ssize_t) rows; y++)
1633 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1634 if (p == (const Quantum *) NULL)
1636 for (x=0; x < (ssize_t) columns; x++)
1638 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1639 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1640 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1642 p+=GetPixelChannels(image);
1647 if (LocaleCompare(map,"I") == 0)
1649 for (y=0; y < (ssize_t) rows; y++)
1651 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1652 if (p == (const Quantum *) NULL)
1654 for (x=0; x < (ssize_t) columns; x++)
1656 *q++=ScaleQuantumToShort(GetPixelIntensity(image,p));
1657 p+=GetPixelChannels(image);
1662 if (LocaleCompare(map,"RGB") == 0)
1664 for (y=0; y < (ssize_t) rows; y++)
1666 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1667 if (p == (const Quantum *) NULL)
1669 for (x=0; x < (ssize_t) columns; x++)
1671 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1672 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1673 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1674 p+=GetPixelChannels(image);
1679 if (LocaleCompare(map,"RGBA") == 0)
1681 for (y=0; y < (ssize_t) rows; y++)
1683 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1684 if (p == (const Quantum *) NULL)
1686 for (x=0; x < (ssize_t) columns; x++)
1688 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1689 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1690 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1691 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1692 p+=GetPixelChannels(image);
1697 if (LocaleCompare(map,"RGBP") == 0)
1699 for (y=0; y < (ssize_t) rows; y++)
1701 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1702 if (p == (const Quantum *) NULL)
1704 for (x=0; x < (ssize_t) columns; x++)
1706 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1707 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1708 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1710 p+=GetPixelChannels(image);
1715 for (y=0; y < (ssize_t) rows; y++)
1717 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1718 if (p == (const Quantum *) NULL)
1720 for (x=0; x < (ssize_t) columns; x++)
1725 for (i=0; i < (ssize_t) strlen(map); i++)
1728 switch (quantum_map[i])
1733 *q=ScaleQuantumToShort(GetPixelRed(image,p));
1737 case MagentaQuantum:
1739 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
1745 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
1750 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1753 case OpacityQuantum:
1755 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1760 if (image->colorspace == CMYKColorspace)
1761 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
1766 *q=ScaleQuantumToShort(GetPixelIntensity(image,p));
1774 p+=GetPixelChannels(image);
1779 MagickExport MagickBooleanType ExportImagePixels(const Image *image,
1780 const ssize_t x_offset,const ssize_t y_offset,const size_t columns,
1781 const size_t rows,const char *map,const StorageType type,void *pixels,
1782 ExceptionInfo *exception)
1790 assert(image != (Image *) NULL);
1791 assert(image->signature == MagickSignature);
1792 if (image->debug != MagickFalse)
1793 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1794 quantum_map=(QuantumType *) AcquireQuantumMemory(strlen(map),
1795 sizeof(*quantum_map));
1796 if (quantum_map == (QuantumType *) NULL)
1798 (void) ThrowMagickException(exception,GetMagickModule(),
1799 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1800 return(MagickFalse);
1802 for (i=0; i < (ssize_t) strlen(map); i++)
1809 quantum_map[i]=AlphaQuantum;
1815 quantum_map[i]=BlueQuantum;
1821 quantum_map[i]=CyanQuantum;
1822 if (image->colorspace == CMYKColorspace)
1824 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1825 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1826 "ColorSeparatedImageRequired","`%s'",map);
1827 return(MagickFalse);
1832 quantum_map[i]=GreenQuantum;
1838 quantum_map[i]=IndexQuantum;
1844 quantum_map[i]=BlackQuantum;
1845 if (image->colorspace == CMYKColorspace)
1847 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1848 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1849 "ColorSeparatedImageRequired","`%s'",map);
1850 return(MagickFalse);
1855 quantum_map[i]=MagentaQuantum;
1856 if (image->colorspace == CMYKColorspace)
1858 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1859 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1860 "ColorSeparatedImageRequired","`%s'",map);
1861 return(MagickFalse);
1866 quantum_map[i]=OpacityQuantum;
1872 quantum_map[i]=UndefinedQuantum;
1878 quantum_map[i]=RedQuantum;
1884 quantum_map[i]=YellowQuantum;
1885 if (image->colorspace == CMYKColorspace)
1887 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1888 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1889 "ColorSeparatedImageRequired","`%s'",map);
1890 return(MagickFalse);
1894 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1895 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1896 "UnrecognizedPixelMap","`%s'",map);
1897 return(MagickFalse);
1905 ExportCharPixel(image,x_offset,y_offset,columns,rows,map,quantum_map,
1911 ExportDoublePixel(image,x_offset,y_offset,columns,rows,map,quantum_map,
1917 ExportFloatPixel(image,x_offset,y_offset,columns,rows,map,quantum_map,
1923 ExportIntegerPixel(image,x_offset,y_offset,columns,rows,map,quantum_map,
1929 ExportLongPixel(image,x_offset,y_offset,columns,rows,map,quantum_map,
1935 ExportQuantumPixel(image,x_offset,y_offset,columns,rows,map,quantum_map,
1941 ExportShortPixel(image,x_offset,y_offset,columns,rows,map,quantum_map,
1947 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1948 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1949 "UnrecognizedPixelMap","`%s'",map);
1953 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1958 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1962 % G e t P i x e l I n f o %
1966 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1968 % GetPixelInfo() initializes the PixelInfo structure.
1970 % The format of the GetPixelInfo method is:
1972 % GetPixelInfo(const Image *image,PixelInfo *pixel)
1974 % A description of each parameter follows:
1976 % o image: the image.
1978 % o pixel: Specifies a pointer to a PixelInfo structure.
1981 MagickExport void GetPixelInfo(const Image *image,PixelInfo *pixel)
1983 pixel->storage_class=DirectClass;
1984 pixel->colorspace=RGBColorspace;
1985 pixel->matte=MagickFalse;
1987 pixel->depth=MAGICKCORE_QUANTUM_DEPTH;
1992 pixel->alpha=(MagickRealType) OpaqueAlpha;
1994 if (image == (const Image *) NULL)
1996 pixel->storage_class=image->storage_class;
1997 pixel->colorspace=image->colorspace;
1998 pixel->matte=image->matte;
1999 pixel->depth=image->depth;
2000 pixel->fuzz=image->fuzz;
2004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2008 % I m p o r t I m a g e P i x e l s %
2012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2014 % ImportImagePixels() accepts pixel data and stores in the image at the
2015 % location you specify. The method returns MagickTrue on success otherwise
2016 % MagickFalse if an error is encountered. The pixel data can be either char,
2017 % short int, int, ssize_t, float, or double in the order specified by map.
2019 % Suppose your want to upload the first scanline of a 640x480 image from
2020 % character data in red-green-blue order:
2022 % ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels);
2024 % The format of the ImportImagePixels method is:
2026 % MagickBooleanType ImportImagePixels(Image *image,const ssize_t x_offset,
2027 % const ssize_t y_offset,const size_t columns,
2028 % const size_t rows,const char *map,const StorageType type,
2029 % const void *pixels,ExceptionInfo *exception)
2031 % A description of each parameter follows:
2033 % o image: the image.
2035 % o x_offset,y_offset,columns,rows: These values define the perimeter
2036 % of a region of pixels you want to define.
2038 % o map: This string reflects the expected ordering of the pixel array.
2039 % It can be any combination or order of R = red, G = green, B = blue,
2040 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
2041 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
2044 % o type: Define the data type of the pixels. Float and double types are
2045 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
2046 % types: CharPixel, ShortPixel, IntegerPixel, LongPixel, FloatPixel, or
2049 % o pixels: This array of values contain the pixel components as defined by
2050 % map and type. You must preallocate this array where the expected
2051 % length varies depending on the values of width, height, map, and type.
2053 % o exception: return any errors or warnings in this structure.
2057 static void ImportCharPixel(Image *image,const ssize_t x_offset,
2058 const ssize_t y_offset,const size_t columns,const size_t rows,
2059 const char *restrict map,const QuantumType *quantum_map,
2060 const unsigned char *restrict pixels,ExceptionInfo *exception)
2062 register const unsigned char
2074 p=(const unsigned char *) pixels;
2075 if (LocaleCompare(map,"BGR") == 0)
2077 for (y=0; y < (ssize_t) rows; y++)
2079 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2080 if (q == (Quantum *) NULL)
2082 for (x=0; x < (ssize_t) columns; x++)
2084 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2085 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2086 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2087 q+=GetPixelChannels(image);
2089 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2094 if (LocaleCompare(map,"BGRA") == 0)
2096 for (y=0; y < (ssize_t) rows; y++)
2098 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2099 if (q == (Quantum *) NULL)
2101 for (x=0; x < (ssize_t) columns; x++)
2103 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2104 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2105 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2106 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2107 q+=GetPixelChannels(image);
2109 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2114 if (LocaleCompare(map,"BGRO") == 0)
2116 for (y=0; y < (ssize_t) rows; y++)
2118 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2119 if (q == (Quantum *) NULL)
2121 for (x=0; x < (ssize_t) columns; x++)
2123 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2124 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2125 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2126 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2127 q+=GetPixelChannels(image);
2129 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2134 if (LocaleCompare(map,"BGRP") == 0)
2136 for (y=0; y < (ssize_t) rows; y++)
2138 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2139 if (q == (Quantum *) NULL)
2141 for (x=0; x < (ssize_t) columns; x++)
2143 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2144 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2145 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2147 q+=GetPixelChannels(image);
2149 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2154 if (LocaleCompare(map,"I") == 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 SetPixelGray(image,ScaleCharToQuantum(*p++),q);
2164 q+=GetPixelChannels(image);
2166 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2171 if (LocaleCompare(map,"RGB") == 0)
2173 for (y=0; y < (ssize_t) rows; y++)
2175 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2176 if (q == (Quantum *) NULL)
2178 for (x=0; x < (ssize_t) columns; x++)
2180 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2181 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2182 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2183 q+=GetPixelChannels(image);
2185 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2190 if (LocaleCompare(map,"RGBA") == 0)
2192 for (y=0; y < (ssize_t) rows; y++)
2194 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2195 if (q == (Quantum *) NULL)
2197 for (x=0; x < (ssize_t) columns; x++)
2199 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2200 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2201 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2202 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2203 q+=GetPixelChannels(image);
2205 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2210 if (LocaleCompare(map,"RGBO") == 0)
2212 for (y=0; y < (ssize_t) rows; y++)
2214 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2215 if (q == (Quantum *) NULL)
2217 for (x=0; x < (ssize_t) columns; x++)
2219 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2220 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2221 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2222 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2223 q+=GetPixelChannels(image);
2225 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2230 if (LocaleCompare(map,"RGBP") == 0)
2232 for (y=0; y < (ssize_t) rows; y++)
2234 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2235 if (q == (Quantum *) NULL)
2237 for (x=0; x < (ssize_t) columns; x++)
2239 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2240 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2241 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2243 q+=GetPixelChannels(image);
2245 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2250 for (y=0; y < (ssize_t) rows; y++)
2252 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2253 if (q == (Quantum *) NULL)
2255 for (x=0; x < (ssize_t) columns; x++)
2260 for (i=0; i < (ssize_t) strlen(map); i++)
2262 switch (quantum_map[i])
2267 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2271 case MagentaQuantum:
2273 SetPixelGreen(image,ScaleCharToQuantum(*p),q);
2279 SetPixelBlue(image,ScaleCharToQuantum(*p),q);
2284 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2287 case OpacityQuantum:
2289 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2294 SetPixelBlack(image,ScaleCharToQuantum(*p),q);
2299 SetPixelGray(image,ScaleCharToQuantum(*p),q);
2307 q+=GetPixelChannels(image);
2309 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2314 static void ImportDoublePixel(Image *image,const ssize_t x_offset,
2315 const ssize_t y_offset,const size_t columns,const size_t rows,
2316 const char *restrict map,const QuantumType *quantum_map,
2317 const unsigned char *restrict pixels,ExceptionInfo *exception)
2319 register const double
2331 p=(const double *) pixels;
2332 if (LocaleCompare(map,"BGR") == 0)
2334 for (y=0; y < (ssize_t) rows; y++)
2336 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2337 if (q == (Quantum *) NULL)
2339 for (x=0; x < (ssize_t) columns; x++)
2341 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2344 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2347 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2350 q+=GetPixelChannels(image);
2352 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2357 if (LocaleCompare(map,"BGRA") == 0)
2359 for (y=0; y < (ssize_t) rows; y++)
2361 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2362 if (q == (Quantum *) NULL)
2364 for (x=0; x < (ssize_t) columns; x++)
2366 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2369 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2372 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2375 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2378 q+=GetPixelChannels(image);
2380 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2385 if (LocaleCompare(map,"BGRP") == 0)
2387 for (y=0; y < (ssize_t) rows; y++)
2389 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2390 if (q == (Quantum *) NULL)
2392 for (x=0; x < (ssize_t) columns; x++)
2394 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2397 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2400 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2404 q+=GetPixelChannels(image);
2406 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2411 if (LocaleCompare(map,"I") == 0)
2413 for (y=0; y < (ssize_t) rows; y++)
2415 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2416 if (q == (Quantum *) NULL)
2418 for (x=0; x < (ssize_t) columns; x++)
2420 SetPixelGray(image,ClampToQuantum((MagickRealType) QuantumRange*
2423 q+=GetPixelChannels(image);
2425 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2430 if (LocaleCompare(map,"RGB") == 0)
2432 for (y=0; y < (ssize_t) rows; y++)
2434 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2435 if (q == (Quantum *) NULL)
2437 for (x=0; x < (ssize_t) columns; x++)
2439 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2442 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2445 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2448 q+=GetPixelChannels(image);
2450 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2455 if (LocaleCompare(map,"RGBA") == 0)
2457 for (y=0; y < (ssize_t) rows; y++)
2459 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2460 if (q == (Quantum *) NULL)
2462 for (x=0; x < (ssize_t) columns; x++)
2464 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2467 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2470 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2473 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2476 q+=GetPixelChannels(image);
2478 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2483 if (LocaleCompare(map,"RGBP") == 0)
2485 for (y=0; y < (ssize_t) rows; y++)
2487 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2488 if (q == (Quantum *) NULL)
2490 for (x=0; x < (ssize_t) columns; x++)
2492 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2495 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2498 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2501 q+=GetPixelChannels(image);
2503 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2508 for (y=0; y < (ssize_t) rows; y++)
2510 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2511 if (q == (Quantum *) NULL)
2513 for (x=0; x < (ssize_t) columns; x++)
2518 for (i=0; i < (ssize_t) strlen(map); i++)
2520 switch (quantum_map[i])
2525 SetPixelRed(image,ClampToQuantum((MagickRealType)
2526 QuantumRange*(*p)),q);
2530 case MagentaQuantum:
2532 SetPixelGreen(image,ClampToQuantum((MagickRealType)
2533 QuantumRange*(*p)),q);
2539 SetPixelBlue(image,ClampToQuantum((MagickRealType)
2540 QuantumRange*(*p)),q);
2545 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2546 QuantumRange*(*p)),q);
2549 case OpacityQuantum:
2551 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2552 QuantumRange*(*p)),q);
2557 SetPixelBlack(image,ClampToQuantum((MagickRealType)
2558 QuantumRange*(*p)),q);
2563 SetPixelGray(image,ClampToQuantum((MagickRealType)
2564 QuantumRange*(*p)),q);
2572 q+=GetPixelChannels(image);
2574 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2579 static void ImportFloatPixel(Image *image,const ssize_t x_offset,
2580 const ssize_t y_offset,const size_t columns,const size_t rows,
2581 const char *restrict map,const QuantumType *quantum_map,
2582 const unsigned char *restrict pixels,ExceptionInfo *exception)
2584 register const float
2596 p=(const float *) pixels;
2597 if (LocaleCompare(map,"BGR") == 0)
2599 for (y=0; y < (ssize_t) rows; y++)
2601 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2602 if (q == (Quantum *) NULL)
2604 for (x=0; x < (ssize_t) columns; x++)
2606 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2609 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2612 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2615 q+=GetPixelChannels(image);
2617 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2622 if (LocaleCompare(map,"BGRA") == 0)
2624 for (y=0; y < (ssize_t) rows; y++)
2626 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2627 if (q == (Quantum *) NULL)
2629 for (x=0; x < (ssize_t) columns; x++)
2631 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2634 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2637 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2640 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2643 q+=GetPixelChannels(image);
2645 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2650 if (LocaleCompare(map,"BGRP") == 0)
2652 for (y=0; y < (ssize_t) rows; y++)
2654 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2655 if (q == (Quantum *) NULL)
2657 for (x=0; x < (ssize_t) columns; x++)
2659 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2662 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2665 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2669 q+=GetPixelChannels(image);
2671 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2676 if (LocaleCompare(map,"I") == 0)
2678 for (y=0; y < (ssize_t) rows; y++)
2680 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2681 if (q == (Quantum *) NULL)
2683 for (x=0; x < (ssize_t) columns; x++)
2685 SetPixelGray(image,ClampToQuantum((MagickRealType) QuantumRange*
2688 q+=GetPixelChannels(image);
2690 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2695 if (LocaleCompare(map,"RGB") == 0)
2697 for (y=0; y < (ssize_t) rows; y++)
2699 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2700 if (q == (Quantum *) NULL)
2702 for (x=0; x < (ssize_t) columns; x++)
2704 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2707 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2710 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2713 q+=GetPixelChannels(image);
2715 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2720 if (LocaleCompare(map,"RGBA") == 0)
2722 for (y=0; y < (ssize_t) rows; y++)
2724 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2725 if (q == (Quantum *) NULL)
2727 for (x=0; x < (ssize_t) columns; x++)
2729 SetPixelRed(image,ClampToQuantum((MagickRealType)
2730 QuantumRange*(*p)),q);
2732 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2735 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2738 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2741 q+=GetPixelChannels(image);
2743 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2748 if (LocaleCompare(map,"RGBP") == 0)
2750 for (y=0; y < (ssize_t) rows; y++)
2752 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2753 if (q == (Quantum *) NULL)
2755 for (x=0; x < (ssize_t) columns; x++)
2757 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2760 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2763 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2766 q+=GetPixelChannels(image);
2768 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2773 for (y=0; y < (ssize_t) rows; y++)
2775 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2776 if (q == (Quantum *) NULL)
2778 for (x=0; x < (ssize_t) columns; x++)
2783 for (i=0; i < (ssize_t) strlen(map); i++)
2785 switch (quantum_map[i])
2790 SetPixelRed(image,ClampToQuantum((MagickRealType)
2791 QuantumRange*(*p)),q);
2795 case MagentaQuantum:
2797 SetPixelGreen(image,ClampToQuantum((MagickRealType)
2798 QuantumRange*(*p)),q);
2804 SetPixelBlue(image,ClampToQuantum((MagickRealType)
2805 QuantumRange*(*p)),q);
2810 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2811 QuantumRange*(*p)),q);
2814 case OpacityQuantum:
2816 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2817 QuantumRange*(*p)),q);
2822 SetPixelBlack(image,ClampToQuantum((MagickRealType)
2823 QuantumRange*(*p)),q);
2828 SetPixelGray(image,ClampToQuantum((MagickRealType)
2829 QuantumRange*(*p)),q);
2837 q+=GetPixelChannels(image);
2839 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2844 static void ImportIntegerPixel(Image *image,const ssize_t x_offset,
2845 const ssize_t y_offset,const size_t columns,const size_t rows,
2846 const char *restrict map,const QuantumType *quantum_map,
2847 const unsigned char *restrict pixels,ExceptionInfo *exception)
2849 register const unsigned int
2861 p=(const unsigned int *) pixels;
2862 if (LocaleCompare(map,"BGR") == 0)
2864 for (y=0; y < (ssize_t) rows; y++)
2866 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2867 if (q == (Quantum *) NULL)
2869 for (x=0; x < (ssize_t) columns; x++)
2871 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2872 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2873 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2874 q+=GetPixelChannels(image);
2876 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2881 if (LocaleCompare(map,"BGRA") == 0)
2883 for (y=0; y < (ssize_t) rows; y++)
2885 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2886 if (q == (Quantum *) NULL)
2888 for (x=0; x < (ssize_t) columns; x++)
2890 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2891 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2892 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2893 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
2894 q+=GetPixelChannels(image);
2896 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2901 if (LocaleCompare(map,"BGRP") == 0)
2903 for (y=0; y < (ssize_t) rows; y++)
2905 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2906 if (q == (Quantum *) NULL)
2908 for (x=0; x < (ssize_t) columns; x++)
2910 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2911 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2912 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2914 q+=GetPixelChannels(image);
2916 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2921 if (LocaleCompare(map,"I") == 0)
2923 for (y=0; y < (ssize_t) rows; y++)
2925 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2926 if (q == (Quantum *) NULL)
2928 for (x=0; x < (ssize_t) columns; x++)
2930 SetPixelGray(image,ScaleLongToQuantum(*p++),q);
2931 q+=GetPixelChannels(image);
2933 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2938 if (LocaleCompare(map,"RGB") == 0)
2940 for (y=0; y < (ssize_t) rows; y++)
2942 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2943 if (q == (Quantum *) NULL)
2945 for (x=0; x < (ssize_t) columns; x++)
2947 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2948 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2949 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2950 q+=GetPixelChannels(image);
2952 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2957 if (LocaleCompare(map,"RGBA") == 0)
2959 for (y=0; y < (ssize_t) rows; y++)
2961 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2962 if (q == (Quantum *) NULL)
2964 for (x=0; x < (ssize_t) columns; x++)
2966 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2967 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2968 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2969 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
2970 q+=GetPixelChannels(image);
2972 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2977 if (LocaleCompare(map,"RGBP") == 0)
2979 for (y=0; y < (ssize_t) rows; y++)
2981 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2982 if (q == (Quantum *) NULL)
2984 for (x=0; x < (ssize_t) columns; x++)
2986 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2987 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2988 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2990 q+=GetPixelChannels(image);
2992 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2997 for (y=0; y < (ssize_t) rows; y++)
2999 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3000 if (q == (Quantum *) NULL)
3002 for (x=0; x < (ssize_t) columns; x++)
3007 for (i=0; i < (ssize_t) strlen(map); i++)
3009 switch (quantum_map[i])
3014 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3018 case MagentaQuantum:
3020 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
3026 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
3031 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3034 case OpacityQuantum:
3036 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3041 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
3046 SetPixelGray(image,ScaleLongToQuantum(*p),q);
3054 q+=GetPixelChannels(image);
3056 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3061 static void ImportLongPixel(Image *image,const ssize_t x_offset,
3062 const ssize_t y_offset,const size_t columns,const size_t rows,
3063 const char *restrict map,const QuantumType *quantum_map,
3064 const unsigned char *restrict pixels,ExceptionInfo *exception)
3066 register const MagickSizeType
3078 p=(const MagickSizeType *) pixels;
3079 if (LocaleCompare(map,"BGR") == 0)
3081 for (y=0; y < (ssize_t) rows; y++)
3083 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3084 if (q == (Quantum *) NULL)
3086 for (x=0; x < (ssize_t) columns; x++)
3088 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3089 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3090 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3091 q+=GetPixelChannels(image);
3093 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3098 if (LocaleCompare(map,"BGRA") == 0)
3100 for (y=0; y < (ssize_t) rows; y++)
3102 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3103 if (q == (Quantum *) NULL)
3105 for (x=0; x < (ssize_t) columns; x++)
3107 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3108 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3109 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3110 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3111 q+=GetPixelChannels(image);
3113 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3118 if (LocaleCompare(map,"BGRP") == 0)
3120 for (y=0; y < (ssize_t) rows; y++)
3122 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3123 if (q == (Quantum *) NULL)
3125 for (x=0; x < (ssize_t) columns; x++)
3127 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3128 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3129 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3131 q+=GetPixelChannels(image);
3133 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3138 if (LocaleCompare(map,"I") == 0)
3140 for (y=0; y < (ssize_t) rows; y++)
3142 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3143 if (q == (Quantum *) NULL)
3145 for (x=0; x < (ssize_t) columns; x++)
3147 SetPixelGray(image,ScaleLongLongToQuantum(*p++),q);
3148 q+=GetPixelChannels(image);
3150 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3155 if (LocaleCompare(map,"RGB") == 0)
3157 for (y=0; y < (ssize_t) rows; y++)
3159 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3160 if (q == (Quantum *) NULL)
3162 for (x=0; x < (ssize_t) columns; x++)
3164 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3165 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3166 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3167 q+=GetPixelChannels(image);
3169 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3174 if (LocaleCompare(map,"RGBA") == 0)
3176 for (y=0; y < (ssize_t) rows; y++)
3178 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3179 if (q == (Quantum *) NULL)
3181 for (x=0; x < (ssize_t) columns; x++)
3183 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3184 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3185 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3186 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3187 q+=GetPixelChannels(image);
3189 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3194 if (LocaleCompare(map,"RGBP") == 0)
3196 for (y=0; y < (ssize_t) rows; y++)
3198 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3199 if (q == (Quantum *) NULL)
3201 for (x=0; x < (ssize_t) columns; x++)
3203 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3204 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3205 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3207 q+=GetPixelChannels(image);
3209 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3214 for (y=0; y < (ssize_t) rows; y++)
3216 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3217 if (q == (Quantum *) NULL)
3219 for (x=0; x < (ssize_t) columns; x++)
3224 for (i=0; i < (ssize_t) strlen(map); i++)
3226 switch (quantum_map[i])
3231 SetPixelRed(image,ScaleLongLongToQuantum(*p),q);
3235 case MagentaQuantum:
3237 SetPixelGreen(image,ScaleLongLongToQuantum(*p),q);
3243 SetPixelBlue(image,ScaleLongLongToQuantum(*p),q);
3248 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3251 case OpacityQuantum:
3253 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3258 SetPixelBlack(image,ScaleLongLongToQuantum(*p),q);
3263 SetPixelGray(image,ScaleLongLongToQuantum(*p),q);
3271 q+=GetPixelChannels(image);
3273 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3278 static void ImportQuantumPixel(Image *image,const ssize_t x_offset,
3279 const ssize_t y_offset,const size_t columns,const size_t rows,
3280 const char *restrict map,const QuantumType *quantum_map,
3281 const unsigned char *restrict pixels,ExceptionInfo *exception)
3283 register const Quantum
3295 p=(const Quantum *) pixels;
3296 if (LocaleCompare(map,"BGR") == 0)
3298 for (y=0; y < (ssize_t) rows; y++)
3300 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3301 if (q == (Quantum *) NULL)
3303 for (x=0; x < (ssize_t) columns; x++)
3305 SetPixelBlue(image,*p++,q);
3306 SetPixelGreen(image,*p++,q);
3307 SetPixelRed(image,*p++,q);
3308 q+=GetPixelChannels(image);
3310 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3315 if (LocaleCompare(map,"BGRA") == 0)
3317 for (y=0; y < (ssize_t) rows; y++)
3319 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3320 if (q == (Quantum *) NULL)
3322 for (x=0; x < (ssize_t) columns; x++)
3324 SetPixelBlue(image,*p++,q);
3325 SetPixelGreen(image,*p++,q);
3326 SetPixelRed(image,*p++,q);
3327 SetPixelAlpha(image,*p++,q);
3328 q+=GetPixelChannels(image);
3330 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3335 if (LocaleCompare(map,"BGRP") == 0)
3337 for (y=0; y < (ssize_t) rows; y++)
3339 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3340 if (q == (Quantum *) NULL)
3342 for (x=0; x < (ssize_t) columns; x++)
3344 SetPixelBlue(image,*p++,q);
3345 SetPixelGreen(image,*p++,q);
3346 SetPixelRed(image,*p++,q);
3348 q+=GetPixelChannels(image);
3350 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3355 if (LocaleCompare(map,"I") == 0)
3357 for (y=0; y < (ssize_t) rows; y++)
3359 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3360 if (q == (Quantum *) NULL)
3362 for (x=0; x < (ssize_t) columns; x++)
3364 SetPixelGray(image,*p++,q);
3365 q+=GetPixelChannels(image);
3367 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3372 if (LocaleCompare(map,"RGB") == 0)
3374 for (y=0; y < (ssize_t) rows; y++)
3376 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3377 if (q == (Quantum *) NULL)
3379 for (x=0; x < (ssize_t) columns; x++)
3381 SetPixelRed(image,*p++,q);
3382 SetPixelGreen(image,*p++,q);
3383 SetPixelBlue(image,*p++,q);
3384 q+=GetPixelChannels(image);
3386 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3391 if (LocaleCompare(map,"RGBA") == 0)
3393 for (y=0; y < (ssize_t) rows; y++)
3395 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3396 if (q == (Quantum *) NULL)
3398 for (x=0; x < (ssize_t) columns; x++)
3400 SetPixelRed(image,*p++,q);
3401 SetPixelGreen(image,*p++,q);
3402 SetPixelBlue(image,*p++,q);
3403 SetPixelAlpha(image,*p++,q);
3404 q+=GetPixelChannels(image);
3406 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3411 if (LocaleCompare(map,"RGBP") == 0)
3413 for (y=0; y < (ssize_t) rows; y++)
3415 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3416 if (q == (Quantum *) NULL)
3418 for (x=0; x < (ssize_t) columns; x++)
3420 SetPixelRed(image,*p++,q);
3421 SetPixelGreen(image,*p++,q);
3422 SetPixelBlue(image,*p++,q);
3424 q+=GetPixelChannels(image);
3426 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3431 for (y=0; y < (ssize_t) rows; y++)
3433 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3434 if (q == (Quantum *) NULL)
3436 for (x=0; x < (ssize_t) columns; x++)
3441 for (i=0; i < (ssize_t) strlen(map); i++)
3443 switch (quantum_map[i])
3448 SetPixelRed(image,*p,q);
3452 case MagentaQuantum:
3454 SetPixelGreen(image,*p,q);
3460 SetPixelBlue(image,*p,q);
3465 SetPixelAlpha(image,*p,q);
3468 case OpacityQuantum:
3470 SetPixelAlpha(image,*p,q);
3475 SetPixelBlack(image,*p,q);
3480 SetPixelGray(image,*p,q);
3488 q+=GetPixelChannels(image);
3490 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3495 static void ImportShortPixel(Image *image,const ssize_t x_offset,
3496 const ssize_t y_offset,const size_t columns,const size_t rows,
3497 const char *restrict map,const QuantumType *quantum_map,
3498 const unsigned char *restrict pixels,ExceptionInfo *exception)
3500 register const unsigned short
3512 p=(const unsigned short *) pixels;
3513 if (LocaleCompare(map,"BGR") == 0)
3515 for (y=0; y < (ssize_t) rows; y++)
3517 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3518 if (q == (Quantum *) NULL)
3520 for (x=0; x < (ssize_t) columns; x++)
3522 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3523 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3524 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3525 q+=GetPixelChannels(image);
3527 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3532 if (LocaleCompare(map,"BGRA") == 0)
3534 for (y=0; y < (ssize_t) rows; y++)
3536 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3537 if (q == (Quantum *) NULL)
3539 for (x=0; x < (ssize_t) columns; x++)
3541 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3542 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3543 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3544 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3545 q+=GetPixelChannels(image);
3547 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3552 if (LocaleCompare(map,"BGRP") == 0)
3554 for (y=0; y < (ssize_t) rows; y++)
3556 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3557 if (q == (Quantum *) NULL)
3559 for (x=0; x < (ssize_t) columns; x++)
3561 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3562 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3563 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3565 q+=GetPixelChannels(image);
3567 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3572 if (LocaleCompare(map,"I") == 0)
3574 for (y=0; y < (ssize_t) rows; y++)
3576 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3577 if (q == (Quantum *) NULL)
3579 for (x=0; x < (ssize_t) columns; x++)
3581 SetPixelGray(image,ScaleShortToQuantum(*p++),q);
3582 q+=GetPixelChannels(image);
3584 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3589 if (LocaleCompare(map,"RGB") == 0)
3591 for (y=0; y < (ssize_t) rows; y++)
3593 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3594 if (q == (Quantum *) NULL)
3596 for (x=0; x < (ssize_t) columns; x++)
3598 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3599 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3600 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3601 q+=GetPixelChannels(image);
3603 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3608 if (LocaleCompare(map,"RGBA") == 0)
3610 for (y=0; y < (ssize_t) rows; y++)
3612 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3613 if (q == (Quantum *) NULL)
3615 for (x=0; x < (ssize_t) columns; x++)
3617 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3618 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3619 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3620 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3621 q+=GetPixelChannels(image);
3623 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3628 if (LocaleCompare(map,"RGBP") == 0)
3630 for (y=0; y < (ssize_t) rows; y++)
3632 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3633 if (q == (Quantum *) NULL)
3635 for (x=0; x < (ssize_t) columns; x++)
3637 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3638 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3639 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3641 q+=GetPixelChannels(image);
3643 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3648 for (y=0; y < (ssize_t) rows; y++)
3650 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3651 if (q == (Quantum *) NULL)
3653 for (x=0; x < (ssize_t) columns; x++)
3658 for (i=0; i < (ssize_t) strlen(map); i++)
3660 switch (quantum_map[i])
3665 SetPixelRed(image,ScaleShortToQuantum(*p),q);
3669 case MagentaQuantum:
3671 SetPixelGreen(image,ScaleShortToQuantum(*p),q);
3677 SetPixelBlue(image,ScaleShortToQuantum(*p),q);
3682 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3685 case OpacityQuantum:
3687 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3692 SetPixelBlack(image,ScaleShortToQuantum(*p),q);
3697 SetPixelGray(image,ScaleShortToQuantum(*p),q);
3705 q+=GetPixelChannels(image);
3707 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3712 MagickExport MagickBooleanType ImportImagePixels(Image *image,
3713 const ssize_t x_offset,const ssize_t y_offset,const size_t columns,
3714 const size_t rows,const char *map,const StorageType type,
3715 const void *pixels,ExceptionInfo *exception)
3724 Allocate image structure.
3726 assert(image != (Image *) NULL);
3727 assert(image->signature == MagickSignature);
3728 if (image->debug != MagickFalse)
3729 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3730 quantum_map=(QuantumType *) AcquireQuantumMemory(strlen(map),
3731 sizeof(*quantum_map));
3732 if (quantum_map == (QuantumType *) NULL)
3733 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
3735 for (i=0; i < (ssize_t) strlen(map); i++)
3742 quantum_map[i]=AlphaQuantum;
3743 image->matte=MagickTrue;
3749 quantum_map[i]=BlueQuantum;
3755 quantum_map[i]=CyanQuantum;
3756 (void) SetImageColorspace(image,CMYKColorspace,exception);
3762 quantum_map[i]=GreenQuantum;
3768 quantum_map[i]=BlackQuantum;
3769 (void) SetImageColorspace(image,CMYKColorspace,exception);
3775 quantum_map[i]=IndexQuantum;
3781 quantum_map[i]=MagentaQuantum;
3782 (void) SetImageColorspace(image,CMYKColorspace,exception);
3788 quantum_map[i]=OpacityQuantum;
3789 image->matte=MagickTrue;
3795 quantum_map[i]=UndefinedQuantum;
3801 quantum_map[i]=RedQuantum;
3807 quantum_map[i]=YellowQuantum;
3808 (void) SetImageColorspace(image,CMYKColorspace,exception);
3813 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3814 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3815 "UnrecognizedPixelMap","`%s'",map);
3816 return(MagickFalse);
3820 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
3821 return(MagickFalse);
3823 Transfer the pixels from the pixel data to the image.
3829 ImportCharPixel(image,x_offset,y_offset,columns,rows,map,quantum_map,
3835 ImportDoublePixel(image,x_offset,y_offset,columns,rows,map,quantum_map,
3841 ImportFloatPixel(image,x_offset,y_offset,columns,rows,map,quantum_map,
3847 ImportIntegerPixel(image,x_offset,y_offset,columns,rows,map,quantum_map,
3853 ImportLongPixel(image,x_offset,y_offset,columns,rows,map,quantum_map,
3859 ImportQuantumPixel(image,x_offset,y_offset,columns,rows,map,quantum_map,
3865 ImportShortPixel(image,x_offset,y_offset,columns,rows,map,quantum_map,
3871 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3872 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3873 "UnrecognizedPixelMap","`%s'",map);
3877 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3882 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3886 + 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 %
3890 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3892 % InitializePixelChannelMap() defines the standard pixel component map.
3894 % The format of the InitializePixelChannelMap() method is:
3896 % void InitializePixelChannelMap(Image *image)
3898 % A description of each parameter follows:
3900 % o image: the image.
3903 MagickExport void InitializePixelChannelMap(Image *image)
3914 assert(image != (Image *) NULL);
3915 assert(image->signature == MagickSignature);
3916 (void) ResetMagickMemory(image->channel_map,0,MaxPixelChannels*
3917 sizeof(*image->channel_map));
3918 trait=UpdatePixelTrait;
3919 if (image->matte != MagickFalse)
3920 trait=(PixelTrait) (trait | BlendPixelTrait);
3922 if (image->colorspace == GRAYColorspace)
3924 SetPixelChannelMap(image,BluePixelChannel,trait,n);
3925 SetPixelChannelMap(image,GreenPixelChannel,trait,n);
3926 SetPixelChannelMap(image,RedPixelChannel,trait,n++);
3930 SetPixelChannelMap(image,RedPixelChannel,trait,n++);
3931 SetPixelChannelMap(image,GreenPixelChannel,trait,n++);
3932 SetPixelChannelMap(image,BluePixelChannel,trait,n++);
3934 if (image->colorspace == CMYKColorspace)
3935 SetPixelChannelMap(image,BlackPixelChannel,trait,n++);
3936 if (image->matte != MagickFalse)
3937 SetPixelChannelMap(image,AlphaPixelChannel,CopyPixelTrait,n++);
3938 if (image->storage_class == PseudoClass)
3939 SetPixelChannelMap(image,IndexPixelChannel,CopyPixelTrait,n++);
3940 assert((n+image->number_meta_channels) < MaxPixelChannels);
3941 for (i=0; i < (ssize_t) image->number_meta_channels; i++)
3942 SetPixelChannelMap(image,(PixelChannel) (MetaPixelChannel+i),CopyPixelTrait,
3944 image->number_channels=(size_t) n;
3945 if (image->debug != MagickFalse)
3946 LogPixelChannels(image);
3947 (void) SetPixelChannelMask(image,image->channel_mask);
3951 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3955 % I n t e r p o l a t e P i x e l C h a n n e l %
3959 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3961 % InterpolatePixelChannel() applies a pixel interpolation method between a
3962 % floating point coordinate and the pixels surrounding that coordinate. No
3963 % pixel area resampling, or scaling of the result is performed.
3965 % The format of the InterpolatePixelChannel method is:
3967 % MagickBooleanType InterpolatePixelChannel(const Image *image,
3968 % const CacheView *image_view,const PixelChannel channel,
3969 % const PixelInterpolateMethod method,const double x,const double y,
3970 % double *pixel,ExceptionInfo *exception)
3972 % A description of each parameter follows:
3974 % o image: the image.
3976 % o image_view: the image view.
3978 % o channel: the pixel channel to interpolate.
3980 % o method: the pixel color interpolation method.
3982 % o x,y: A double representing the current (x,y) position of the pixel.
3984 % o pixel: return the interpolated pixel here.
3986 % o exception: return any errors or warnings in this structure.
3990 static inline double MagickMax(const MagickRealType x,const MagickRealType y)
3997 static inline MagickRealType CubicWeightingFunction(const MagickRealType x)
4003 alpha=MagickMax(x+2.0,0.0);
4004 gamma=1.0*alpha*alpha*alpha;
4005 alpha=MagickMax(x+1.0,0.0);
4006 gamma-=4.0*alpha*alpha*alpha;
4007 alpha=MagickMax(x+0.0,0.0);
4008 gamma+=6.0*alpha*alpha*alpha;
4009 alpha=MagickMax(x-1.0,0.0);
4010 gamma-=4.0*alpha*alpha*alpha;
4014 static inline double MeshInterpolate(const PointInfo *delta,const double p,
4015 const double x,const double y)
4017 return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
4020 static inline ssize_t NearestNeighbor(const MagickRealType x)
4023 return((ssize_t) (x+0.5));
4024 return((ssize_t) (x-0.5));
4027 MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
4028 const CacheView *image_view,const PixelChannel channel,
4029 const PixelInterpolateMethod method,const double x,const double y,
4030 double *pixel,ExceptionInfo *exception)
4043 register const Quantum
4053 assert(image != (Image *) NULL);
4054 assert(image != (Image *) NULL);
4055 assert(image->signature == MagickSignature);
4056 assert(image_view != (CacheView *) NULL);
4059 traits=GetPixelChannelMapTraits(image,channel);
4060 x_offset=(ssize_t) floor(x);
4061 y_offset=(ssize_t) floor(y);
4062 switch (method == UndefinedInterpolatePixel ? image->interpolate : method)
4064 case AverageInterpolatePixel:
4066 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4068 if (p == (const Quantum *) NULL)
4073 if ((traits & BlendPixelTrait) == 0)
4074 for (i=0; i < 16; i++)
4077 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4080 for (i=0; i < 16; i++)
4082 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4083 GetPixelChannels(image));
4084 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4086 for (i=0; i < 16; i++)
4088 gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]);
4089 *pixel+=gamma*0.0625*pixels[i];
4093 case BicubicInterpolatePixel:
4102 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4104 if (p == (const Quantum *) NULL)
4109 if ((traits & BlendPixelTrait) == 0)
4110 for (i=0; i < 16; i++)
4113 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4116 for (i=0; i < 16; i++)
4118 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4119 GetPixelChannels(image));
4120 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4124 for (i=0; i < 4; i++)
4126 u[0]=(pixels[4*i+3]-pixels[4*i+2])-(pixels[4*i+0]-pixels[4*i+1]);
4127 u[1]=(pixels[4*i+0]-pixels[4*i+1])-u[0];
4128 u[2]=pixels[4*i+2]-pixels[4*i+0];
4130 v[i]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x*
4133 u[0]=(v[3]-v[2])-(v[0]-v[1]);
4134 u[1]=(v[0]-v[1])-u[0];
4137 *pixel=(delta.y*delta.y*delta.y*u[0])+(delta.y*delta.y*u[1])+(delta.y*
4141 case BilinearInterpolatePixel:
4148 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4149 if (p == (const Quantum *) NULL)
4154 if ((traits & BlendPixelTrait) == 0)
4155 for (i=0; i < 4; i++)
4158 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4161 for (i=0; i < 4; i++)
4163 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4164 GetPixelChannels(image));
4165 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4169 epsilon.x=1.0-delta.x;
4170 epsilon.y=1.0-delta.y;
4171 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4172 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4173 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4174 *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
4175 (epsilon.x*pixels[2]+delta.x*pixels[3]));
4178 case FilterInterpolatePixel:
4192 geometry.x=x_offset-1;
4193 geometry.y=y_offset-1;
4194 excerpt_image=ExcerptImage(image,&geometry,exception);
4195 if (excerpt_image == (Image *) NULL)
4200 filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur,
4202 excerpt_image=DestroyImage(excerpt_image);
4203 if (filter_image == (Image *) NULL)
4205 filter_view=AcquireCacheView(filter_image);
4206 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4207 if (p == (const Quantum *) NULL)
4210 *pixel=(double) GetPixelChannel(image,channel,p);
4211 filter_view=DestroyCacheView(filter_view);
4212 filter_image=DestroyImage(filter_image);
4215 case IntegerInterpolatePixel:
4217 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4218 if (p == (const Quantum *) NULL)
4223 *pixel=(double) GetPixelChannel(image,channel,p);
4226 case NearestNeighborInterpolatePixel:
4228 p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
4229 NearestNeighbor(y),1,1,exception);
4230 if (p == (const Quantum *) NULL)
4235 *pixel=(double) GetPixelChannel(image,channel,p);
4238 case MeshInterpolatePixel:
4244 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4245 if (p == (const Quantum *) NULL)
4250 if ((traits & BlendPixelTrait) == 0)
4251 for (i=0; i < 4; i++)
4254 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4257 for (i=0; i < 4; i++)
4259 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4260 GetPixelChannels(image));
4261 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4265 luminance.x=GetPixelLuminance(image,p)-(double)
4266 GetPixelLuminance(image,p+3*GetPixelChannels(image));
4267 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
4268 GetPixelLuminance(image,p+2*GetPixelChannels(image));
4269 if (fabs(luminance.x) < fabs(luminance.y))
4274 if (delta.x <= delta.y)
4277 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4279 delta.y=1.0-delta.y;
4280 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4281 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4282 *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
4288 Top-right triangle (pixel: 1, diagonal: 0-3).
4290 delta.x=1.0-delta.x;
4291 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4292 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4293 *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
4302 if (delta.x <= (1.0-delta.y))
4305 Top-left triangle (pixel: 0, diagonal: 1-2).
4307 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4308 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4309 *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
4315 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4317 delta.x=1.0-delta.x;
4318 delta.y=1.0-delta.y;
4319 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4320 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4321 *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
4327 case SplineInterpolatePixel:
4340 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4342 if (p == (const Quantum *) NULL)
4347 if ((traits & BlendPixelTrait) == 0)
4348 for (i=0; i < 16; i++)
4351 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4354 for (i=0; i < 16; i++)
4356 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4357 GetPixelChannels(image));
4358 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4363 for (i=(-1); i < 3L; i++)
4365 dy=CubicWeightingFunction((MagickRealType) i-delta.y);
4366 for (j=(-1); j < 3L; j++)
4368 dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
4369 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]);
4370 *pixel+=gamma*dx*dy*pixels[n];
4381 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4385 % I n t e r p o l a t e P i x e l C h a n n e l s %
4389 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4391 % InterpolatePixelChannels() applies a pixel interpolation method between a
4392 % floating point coordinate and the pixels surrounding that coordinate. No
4393 % pixel area resampling, or scaling of the result is performed.
4395 % The format of the InterpolatePixelChannels method is:
4397 % MagickBooleanType InterpolatePixelChannels(const Image *source,
4398 % const CacheView *source_view,const Image *destination,
4399 % const PixelInterpolateMethod method,const double x,const double y,
4400 % Quantum *pixel,ExceptionInfo *exception)
4402 % A description of each parameter follows:
4404 % o source: the source.
4406 % o source_view: the source view.
4408 % o destination: the destination image.
4410 % o method: the pixel color interpolation method.
4412 % o x,y: A double representing the current (x,y) position of the pixel.
4414 % o pixel: return the interpolated pixel here.
4416 % o exception: return any errors or warnings in this structure.
4419 MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
4420 const CacheView *source_view,const Image *destination,
4421 const PixelInterpolateMethod method,const double x,const double y,
4422 Quantum *pixel,ExceptionInfo *exception)
4439 register const Quantum
4449 assert(source != (Image *) NULL);
4450 assert(source != (Image *) NULL);
4451 assert(source->signature == MagickSignature);
4452 assert(source_view != (CacheView *) NULL);
4454 x_offset=(ssize_t) floor(x);
4455 y_offset=(ssize_t) floor(y);
4456 switch (method == UndefinedInterpolatePixel ? source->interpolate : method)
4458 case AverageInterpolatePixel:
4460 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4462 if (p == (const Quantum *) NULL)
4467 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4475 channel=GetPixelChannelMapChannel(source,i);
4476 traits=GetPixelChannelMapTraits(source,channel);
4477 destination_traits=GetPixelChannelMapTraits(destination,channel);
4478 if ((traits == UndefinedPixelTrait) ||
4479 (destination_traits == UndefinedPixelTrait))
4481 for (j=0; j < 16; j++)
4482 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4484 if ((traits & BlendPixelTrait) == 0)
4486 for (j=0; j < 16; j++)
4487 sum+=0.0625*pixels[j];
4488 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4491 for (j=0; j < 16; j++)
4493 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4494 GetPixelChannels(source));
4495 pixels[j]*=alpha[j];
4496 gamma=1.0/(fabs((double) alpha[j]) <= MagickEpsilon ? 1.0 : alpha[j]);
4497 sum+=gamma*0.0625*pixels[j];
4499 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4503 case BicubicInterpolatePixel:
4512 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4514 if (p == (const Quantum *) NULL)
4519 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4524 channel=GetPixelChannelMapChannel(source,i);
4525 traits=GetPixelChannelMapTraits(source,channel);
4526 destination_traits=GetPixelChannelMapTraits(destination,channel);
4527 if ((traits == UndefinedPixelTrait) ||
4528 (destination_traits == UndefinedPixelTrait))
4530 if ((traits & BlendPixelTrait) == 0)
4531 for (j=0; j < 16; j++)
4534 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4537 for (j=0; j < 16; j++)
4539 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4540 GetPixelChannels(source));
4541 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4545 for (j=0; j < 4; j++)
4547 u[0]=(pixels[4*j+3]-pixels[4*j+2])-(pixels[4*j+0]-pixels[4*j+1]);
4548 u[1]=(pixels[4*j+0]-pixels[4*j+1])-u[0];
4549 u[2]=pixels[4*j+2]-pixels[4*j+0];
4551 v[j]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x*
4554 u[0]=(v[3]-v[2])-(v[0]-v[1]);
4555 u[1]=(v[0]-v[1])-u[0];
4558 SetPixelChannel(destination,channel,ClampToQuantum((delta.y*delta.y*
4559 delta.y*u[0])+(delta.y*delta.y*u[1])+(delta.y*u[2])+u[3]),pixel);
4563 case BilinearInterpolatePixel:
4566 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4567 if (p == (const Quantum *) NULL)
4572 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4578 channel=GetPixelChannelMapChannel(source,i);
4579 traits=GetPixelChannelMapTraits(source,channel);
4580 destination_traits=GetPixelChannelMapTraits(destination,channel);
4581 if ((traits == UndefinedPixelTrait) ||
4582 (destination_traits == UndefinedPixelTrait))
4586 epsilon.x=1.0-delta.x;
4587 epsilon.y=1.0-delta.y;
4588 pixels[0]=(MagickRealType) p[i];
4589 pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i];
4590 pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i];
4591 pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i];
4592 if ((traits & BlendPixelTrait) == 0)
4594 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
4595 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4596 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4597 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*
4598 pixels[2]+delta.x*pixels[3]))),pixel);
4601 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4602 alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source));
4603 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4604 GetPixelChannels(source));
4605 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4606 GetPixelChannels(source));
4607 pixels[0]*=alpha[0];
4608 pixels[1]*=alpha[1];
4609 pixels[2]*=alpha[2];
4610 pixels[3]*=alpha[3];
4611 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4612 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4613 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4614 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
4615 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+
4616 delta.x*pixels[3]))),pixel);
4620 case FilterInterpolatePixel:
4622 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4634 channel=GetPixelChannelMapChannel(source,i);
4635 traits=GetPixelChannelMapTraits(source,channel);
4636 destination_traits=GetPixelChannelMapTraits(destination,channel);
4637 if ((traits == UndefinedPixelTrait) ||
4638 (destination_traits == UndefinedPixelTrait))
4642 geometry.x=x_offset-1;
4643 geometry.y=y_offset-1;
4644 excerpt_source=ExcerptImage(source,&geometry,exception);
4645 if (excerpt_source == (Image *) NULL)
4650 filter_source=ResizeImage(excerpt_source,1,1,source->filter,
4651 source->blur,exception);
4652 excerpt_source=DestroyImage(excerpt_source);
4653 if (filter_source == (Image *) NULL)
4655 filter_view=AcquireCacheView(filter_source);
4656 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4657 if (p == (const Quantum *) NULL)
4661 SetPixelChannel(destination,channel,p[i],pixel);
4663 filter_view=DestroyCacheView(filter_view);
4664 filter_source=DestroyImage(filter_source);
4668 case IntegerInterpolatePixel:
4670 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
4671 if (p == (const Quantum *) NULL)
4676 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4678 channel=GetPixelChannelMapChannel(source,i);
4679 traits=GetPixelChannelMapTraits(source,channel);
4680 destination_traits=GetPixelChannelMapTraits(destination,channel);
4681 if ((traits == UndefinedPixelTrait) ||
4682 (destination_traits == UndefinedPixelTrait))
4684 SetPixelChannel(destination,channel,p[i],pixel);
4688 case NearestNeighborInterpolatePixel:
4690 p=GetCacheViewVirtualPixels(source_view,NearestNeighbor(x),
4691 NearestNeighbor(y),1,1,exception);
4692 if (p == (const Quantum *) NULL)
4697 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4699 channel=GetPixelChannelMapChannel(source,i);
4700 traits=GetPixelChannelMapTraits(source,channel);
4701 destination_traits=GetPixelChannelMapTraits(destination,channel);
4702 if ((traits == UndefinedPixelTrait) ||
4703 (destination_traits == UndefinedPixelTrait))
4705 SetPixelChannel(destination,channel,p[i],pixel);
4709 case MeshInterpolatePixel:
4711 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4712 if (p == (const Quantum *) NULL)
4717 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4723 channel=GetPixelChannelMapChannel(source,i);
4724 traits=GetPixelChannelMapTraits(source,channel);
4725 destination_traits=GetPixelChannelMapTraits(destination,channel);
4726 if ((traits == UndefinedPixelTrait) ||
4727 (destination_traits == UndefinedPixelTrait))
4729 pixels[0]=(MagickRealType) p[i];
4730 pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i];
4731 pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i];
4732 pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i];
4733 if ((traits & BlendPixelTrait) == 0)
4742 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4743 alpha[1]=QuantumScale*GetPixelAlpha(source,p+
4744 GetPixelChannels(source));
4745 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4746 GetPixelChannels(source));
4747 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4748 GetPixelChannels(source));
4752 luminance.x=GetPixelLuminance(source,p)-(double)
4753 GetPixelLuminance(source,p+3*GetPixelChannels(source));
4754 luminance.y=GetPixelLuminance(source,p+GetPixelChannels(source))-
4755 (double) GetPixelLuminance(source,p+2*GetPixelChannels(source));
4756 if (fabs(luminance.x) < fabs(luminance.y))
4761 if (delta.x <= delta.y)
4764 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4766 delta.y=1.0-delta.y;
4767 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4768 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4769 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4770 MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel);
4775 Top-right triangle (pixel: 1, diagonal: 0-3).
4777 delta.x=1.0-delta.x;
4778 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4779 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4780 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4781 MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel);
4789 if (delta.x <= (1.0-delta.y))
4792 Top-left triangle (pixel: 0, diagonal: 1-2).
4794 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4795 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4796 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4797 MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel);
4802 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4804 delta.x=1.0-delta.x;
4805 delta.y=1.0-delta.y;
4806 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4807 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4808 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
4809 MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel);
4815 case SplineInterpolatePixel:
4817 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4819 if (p == (const Quantum *) NULL)
4824 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4843 channel=GetPixelChannelMapChannel(source,i);
4844 traits=GetPixelChannelMapTraits(source,channel);
4845 destination_traits=GetPixelChannelMapTraits(destination,channel);
4846 if ((traits == UndefinedPixelTrait) ||
4847 (destination_traits == UndefinedPixelTrait))
4849 if ((traits & BlendPixelTrait) == 0)
4850 for (j=0; j < 16; j++)
4853 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4856 for (j=0; j < 16; j++)
4858 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4859 GetPixelChannels(source));
4860 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4866 for (j=(-1); j < 3L; j++)
4868 dy=CubicWeightingFunction((MagickRealType) j-delta.y);
4869 for (k=(-1); k < 3L; k++)
4871 dx=CubicWeightingFunction(delta.x-(MagickRealType) k);
4872 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 :
4874 sum+=gamma*dx*dy*pixels[n];
4878 SetPixelChannel(destination,channel,p[i],pixel);
4887 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4891 % I n t e r p o l a t e P i x e l I n f o %
4895 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4897 % InterpolatePixelInfo() applies a pixel interpolation method between a
4898 % floating point coordinate and the pixels surrounding that coordinate. No
4899 % pixel area resampling, or scaling of the result is performed.
4901 % The format of the InterpolatePixelInfo method is:
4903 % MagickBooleanType InterpolatePixelInfo(const Image *image,
4904 % const CacheView *image_view,const PixelInterpolateMethod method,
4905 % const double x,const double y,PixelInfo *pixel,
4906 % ExceptionInfo *exception)
4908 % A description of each parameter follows:
4910 % o image: the image.
4912 % o image_view: the image view.
4914 % o method: the pixel color interpolation method.
4916 % o x,y: A double representing the current (x,y) position of the pixel.
4918 % o pixel: return the interpolated pixel here.
4920 % o exception: return any errors or warnings in this structure.
4924 static inline void AlphaBlendPixelInfo(const Image *image,
4925 const Quantum *pixel,PixelInfo *pixel_info,MagickRealType *alpha)
4927 if (image->matte == MagickFalse)
4930 pixel_info->red=(MagickRealType) GetPixelRed(image,pixel);
4931 pixel_info->green=(MagickRealType) GetPixelGreen(image,pixel);
4932 pixel_info->blue=(MagickRealType) GetPixelBlue(image,pixel);
4933 pixel_info->black=0.0;
4934 if (image->colorspace == CMYKColorspace)
4935 pixel_info->black=(MagickRealType) GetPixelBlack(image,pixel);
4936 pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
4939 *alpha=QuantumScale*GetPixelAlpha(image,pixel);
4940 pixel_info->red=(*alpha*GetPixelRed(image,pixel));
4941 pixel_info->green=(*alpha*GetPixelGreen(image,pixel));
4942 pixel_info->blue=(*alpha*GetPixelBlue(image,pixel));
4943 pixel_info->black=0.0;
4944 if (image->colorspace == CMYKColorspace)
4945 pixel_info->black=(*alpha*GetPixelBlack(image,pixel));
4946 pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
4949 static void BicubicInterpolate(const PixelInfo *pixels,const double dx,
4960 p=(pixels[3].red-pixels[2].red)-(pixels[0].red-pixels[1].red);
4961 q=(pixels[0].red-pixels[1].red)-p;
4962 r=pixels[2].red-pixels[0].red;
4964 pixel->red=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4965 p=(pixels[3].green-pixels[2].green)-(pixels[0].green-pixels[1].green);
4966 q=(pixels[0].green-pixels[1].green)-p;
4967 r=pixels[2].green-pixels[0].green;
4969 pixel->green=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4970 p=(pixels[3].blue-pixels[2].blue)-(pixels[0].blue-pixels[1].blue);
4971 q=(pixels[0].blue-pixels[1].blue)-p;
4972 r=pixels[2].blue-pixels[0].blue;
4974 pixel->blue=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4975 p=(pixels[3].alpha-pixels[2].alpha)-(pixels[0].alpha-pixels[1].alpha);
4976 q=(pixels[0].alpha-pixels[1].alpha)-p;
4977 r=pixels[2].alpha-pixels[0].alpha;
4979 pixel->alpha=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4980 if (pixel->colorspace == CMYKColorspace)
4982 p=(pixels[3].black-pixels[2].black)-(pixels[0].black-pixels[1].black);
4983 q=(pixels[0].black-pixels[1].black)-p;
4984 r=pixels[2].black-pixels[0].black;
4986 pixel->black=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4990 MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
4991 const CacheView *image_view,const PixelInterpolateMethod method,
4992 const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception)
5004 register const Quantum
5014 assert(image != (Image *) NULL);
5015 assert(image->signature == MagickSignature);
5016 assert(image_view != (CacheView *) NULL);
5018 x_offset=(ssize_t) floor(x);
5019 y_offset=(ssize_t) floor(y);
5020 switch (method == UndefinedInterpolatePixel ? image->interpolate : method)
5022 case AverageInterpolatePixel:
5024 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5026 if (p == (const Quantum *) NULL)
5031 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5032 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5033 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5034 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5035 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
5036 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
5037 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
5038 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
5039 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
5040 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
5041 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
5043 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
5045 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
5047 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
5049 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
5051 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
5058 for (i=0; i < 16L; i++)
5060 gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]);
5061 pixel->red+=gamma*0.0625*pixels[i].red;
5062 pixel->green+=gamma*0.0625*pixels[i].green;
5063 pixel->blue+=gamma*0.0625*pixels[i].blue;
5064 if (image->colorspace == CMYKColorspace)
5065 pixel->black+=gamma*0.0625*pixels[i].black;
5066 pixel->alpha+=0.0625*pixels[i].alpha;
5070 case BicubicInterpolatePixel:
5078 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5080 if (p == (const Quantum *) NULL)
5085 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5086 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5087 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5088 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5089 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
5090 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
5091 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
5092 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
5093 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
5094 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
5095 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
5097 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
5099 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
5101 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
5103 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
5105 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
5109 for (i=0; i < 4L; i++)
5110 BicubicInterpolate(pixels+4*i,delta.x,u+i);
5111 BicubicInterpolate(u,delta.y,pixel);
5114 case BilinearInterpolatePixel:
5121 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5122 if (p == (const Quantum *) NULL)
5127 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5128 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5129 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5130 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5133 epsilon.x=1.0-delta.x;
5134 epsilon.y=1.0-delta.y;
5135 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5136 (epsilon.x*alpha[2]+delta.x*alpha[3])));
5137 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5138 pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
5139 pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red));
5140 pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x*
5141 pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x*
5143 pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x*
5144 pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x*
5146 if (image->colorspace == CMYKColorspace)
5147 pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x*
5148 pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x*
5150 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5151 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5152 pixel->alpha=(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x*
5153 pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x*
5157 case FilterInterpolatePixel:
5171 geometry.x=x_offset-1;
5172 geometry.y=y_offset-1;
5173 excerpt_image=ExcerptImage(image,&geometry,exception);
5174 if (excerpt_image == (Image *) NULL)
5179 filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur,
5181 excerpt_image=DestroyImage(excerpt_image);
5182 if (filter_image == (Image *) NULL)
5184 filter_view=AcquireCacheView(filter_image);
5185 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
5186 if (p != (const Quantum *) NULL)
5187 GetPixelInfoPixel(image,p,pixel);
5188 filter_view=DestroyCacheView(filter_view);
5189 filter_image=DestroyImage(filter_image);
5192 case IntegerInterpolatePixel:
5194 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5195 if (p == (const Quantum *) NULL)
5200 GetPixelInfoPixel(image,p,pixel);
5203 case MeshInterpolatePixel:
5209 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5210 if (p == (const Quantum *) NULL)
5217 luminance.x=GetPixelLuminance(image,p)-(double)
5218 GetPixelLuminance(image,p+3*GetPixelChannels(image));
5219 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
5220 GetPixelLuminance(image,p+2*GetPixelChannels(image));
5221 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5222 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5223 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5224 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5225 if (fabs(luminance.x) < fabs(luminance.y))
5230 if (delta.x <= delta.y)
5233 Bottom-left triangle (pixel: 2, diagonal: 0-3).
5235 delta.y=1.0-delta.y;
5236 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5237 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5238 pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red,
5239 pixels[3].red,pixels[0].red);
5240 pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green,
5241 pixels[3].green,pixels[0].green);
5242 pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
5243 pixels[3].blue,pixels[0].blue);
5244 if (image->colorspace == CMYKColorspace)
5245 pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black,
5246 pixels[3].black,pixels[0].black);
5247 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5248 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha,
5249 pixels[3].alpha,pixels[0].alpha);
5254 Top-right triangle (pixel:1 , diagonal: 0-3).
5256 delta.x=1.0-delta.x;
5257 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5258 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5259 pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red,
5260 pixels[0].red,pixels[3].red);
5261 pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green,
5262 pixels[0].green,pixels[3].green);
5263 pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
5264 pixels[0].blue,pixels[3].blue);
5265 if (image->colorspace == CMYKColorspace)
5266 pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black,
5267 pixels[0].black,pixels[3].black);
5268 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5269 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha,
5270 pixels[0].alpha,pixels[3].alpha);
5278 if (delta.x <= (1.0-delta.y))
5281 Top-left triangle (pixel: 0, diagonal: 1-2).
5283 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5284 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5285 pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red,
5286 pixels[1].red,pixels[2].red);
5287 pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green,
5288 pixels[1].green,pixels[2].green);
5289 pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
5290 pixels[1].blue,pixels[2].blue);
5291 if (image->colorspace == CMYKColorspace)
5292 pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black,
5293 pixels[1].black,pixels[2].black);
5294 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5295 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha,
5296 pixels[1].alpha,pixels[2].alpha);
5301 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5303 delta.x=1.0-delta.x;
5304 delta.y=1.0-delta.y;
5305 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5306 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5307 pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red,
5308 pixels[2].red,pixels[1].red);
5309 pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green,
5310 pixels[2].green,pixels[1].green);
5311 pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
5312 pixels[2].blue,pixels[1].blue);
5313 if (image->colorspace == CMYKColorspace)
5314 pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black,
5315 pixels[2].black,pixels[1].black);
5316 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5317 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha,
5318 pixels[2].alpha,pixels[1].alpha);
5323 case NearestNeighborInterpolatePixel:
5325 p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
5326 NearestNeighbor(y),1,1,exception);
5327 if (p == (const Quantum *) NULL)
5332 GetPixelInfoPixel(image,p,pixel);
5335 case SplineInterpolatePixel:
5348 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5350 if (p == (const Quantum *) NULL)
5355 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5356 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5357 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5358 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5359 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
5360 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
5361 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
5362 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
5363 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
5364 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
5365 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
5367 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
5369 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
5371 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
5373 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
5375 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
5385 for (i=(-1); i < 3L; i++)
5387 dy=CubicWeightingFunction((MagickRealType) i-delta.y);
5388 for (j=(-1); j < 3L; j++)
5390 dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
5391 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]);
5392 pixel->red+=gamma*dx*dy*pixels[n].red;
5393 pixel->green+=gamma*dx*dy*pixels[n].green;
5394 pixel->blue+=gamma*dx*dy*pixels[n].blue;
5395 if (image->colorspace == CMYKColorspace)
5396 pixel->black+=gamma*dx*dy*pixels[n].black;
5397 pixel->alpha+=dx*dy*pixels[n].alpha;
5408 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5412 + I s F u z z y E q u i v a l e n c e P i x e l %
5416 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5418 % IsFuzzyEquivalencePixel() returns MagickTrue if the distance between two
5419 % pixels is less than the specified distance in a linear three (or four)u
5420 % dimensional color space.
5422 % The format of the IsFuzzyEquivalencePixel method is:
5424 % void IsFuzzyEquivalencePixel(const Image *source,const Quantum *p,
5425 % const Image *destination,const Quantum *q)
5427 % A description of each parameter follows:
5429 % o source: the source image.
5433 % o destination: the destination image.
5438 MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *source,
5439 const Quantum *p,const Image *destination,const Quantum *q)
5445 register MagickRealType
5449 fuzz=MagickMax(source->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(
5450 destination->fuzz,(MagickRealType) MagickSQ1_2);
5453 if (source->matte != MagickFalse)
5456 Transparencies are involved - set alpha distance
5458 pixel=GetPixelAlpha(source,p)-(MagickRealType)
5459 GetPixelAlpha(destination,q);
5460 distance=pixel*pixel;
5461 if (distance > fuzz)
5462 return(MagickFalse);
5464 Generate a alpha scaling factor to generate a 4D cone on colorspace
5465 Note that if one color is transparent, distance has no color component.
5467 scale=QuantumScale*GetPixelAlpha(source,p);
5468 scale*=QuantumScale*GetPixelAlpha(destination,q);
5469 if (scale <= MagickEpsilon)
5473 RGB or CMY color cube
5475 distance*=3.0; /* rescale appropriately */
5477 pixel=GetPixelRed(source,p)-(MagickRealType) GetPixelRed(destination,q);
5478 if ((source->colorspace == HSLColorspace) ||
5479 (source->colorspace == HSBColorspace) ||
5480 (source->colorspace == HWBColorspace))
5483 Compute an arc distance for hue. It should be a vector angle of
5484 'S'/'W' length with 'L'/'B' forming appropriate cones.
5486 if (fabs((double) pixel) > (QuantumRange/2))
5487 pixel-=QuantumRange;
5490 distance+=scale*pixel*pixel;
5491 if (distance > fuzz)
5492 return(MagickFalse);
5493 pixel=GetPixelGreen(source,p)-(MagickRealType) GetPixelGreen(destination,q);
5494 distance+=scale*pixel*pixel;
5495 if (distance > fuzz)
5496 return(MagickFalse);
5497 pixel=GetPixelBlue(source,p)-(MagickRealType) GetPixelBlue(destination,q);
5498 distance+=scale*pixel*pixel;
5499 if (distance > fuzz)
5500 return(MagickFalse);
5505 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5509 + 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 %
5513 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5515 % IsFuzzyEquivalencePixelInfo() returns true if the distance between two
5516 % colors is less than the specified distance in a linear three (or four)
5517 % dimensional color space.
5519 % This implements the equivalent of:
5520 % fuzz < sqrt(color_distance^2 * u.a*v.a + alpha_distance^2)
5522 % Which produces a multi-dimensional cone for that colorspace along the
5523 % transparency vector.
5525 % For example for an RGB:
5526 % color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3
5528 % See http://www.imagemagick.org/Usage/bugs/fuzz_distance/
5530 % Hue colorspace distances need more work. Hue is not a distance, it is an
5533 % A check that q is in the same color space as p should be made and the
5534 % appropriate mapping made. -- Anthony Thyssen 8 December 2010
5536 % The format of the IsFuzzyEquivalencePixelInfo method is:
5538 % MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5539 % const PixelInfo *q)
5541 % A description of each parameter follows:
5548 MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5555 register MagickRealType
5559 if ((p->fuzz == 0.0) && (q->fuzz == 0.0))
5560 return(IsPixelInfoEquivalent(p,q));
5562 fuzz=MagickMax(q->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz,
5563 (MagickRealType) MagickSQ1_2);
5564 else if (q->fuzz == 0.0)
5565 fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(p->fuzz,
5566 (MagickRealType) MagickSQ1_2);
5568 fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz,
5569 (MagickRealType) MagickSQ1_2);
5572 if ((p->matte != MagickFalse) || (q->matte != MagickFalse))
5575 Transparencies are involved - set alpha distance.
5577 pixel=(p->matte != MagickFalse ? p->alpha : OpaqueAlpha)-
5578 (q->matte != MagickFalse ? q->alpha : OpaqueAlpha);
5579 distance=pixel*pixel;
5580 if (distance > fuzz)
5581 return(MagickFalse);
5583 Generate a alpha scaling factor to generate a 4D cone on colorspace.
5584 If one color is transparent, distance has no color component.
5586 if (p->matte != MagickFalse)
5587 scale=(QuantumScale*p->alpha);
5588 if (q->matte != MagickFalse)
5589 scale*=(QuantumScale*q->alpha);
5590 if (scale <= MagickEpsilon )
5594 CMYK create a CMY cube with a multi-dimensional cone toward black.
5596 if (p->colorspace == CMYKColorspace)
5598 pixel=p->black-q->black;
5599 distance+=pixel*pixel*scale;
5600 if (distance > fuzz)
5601 return(MagickFalse);
5602 scale*=(MagickRealType) (QuantumScale*(QuantumRange-p->black));
5603 scale*=(MagickRealType) (QuantumScale*(QuantumRange-q->black));
5606 RGB or CMY color cube.
5608 distance*=3.0; /* rescale appropriately */
5610 pixel=p->red-q->red;
5611 if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) ||
5612 (p->colorspace == HWBColorspace))
5615 This calculates a arc distance for hue-- it should be a vector angle
5616 of 'S'/'W' length with 'L'/'B' forming appropriate cones. In other
5617 words this is a hack - Anthony.
5619 if (fabs((double) pixel) > (QuantumRange/2))
5620 pixel-=QuantumRange;
5623 distance+=pixel*pixel*scale;
5624 if (distance > fuzz)
5625 return(MagickFalse);
5626 pixel=p->green-q->green;
5627 distance+=pixel*pixel*scale;
5628 if (distance > fuzz)
5629 return(MagickFalse);
5630 pixel=p->blue-q->blue;
5631 distance+=pixel*pixel*scale;
5632 if (distance > fuzz)
5633 return(MagickFalse);
5638 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5642 % S e t P i x e l C h a n n e l M a p M a s k %
5646 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5648 % SetPixelChannelMapMask() sets the pixel channel map from the specified
5651 % The format of the SetPixelChannelMapMask method is:
5653 % void SetPixelChannelMapMask(Image *image,const ChannelType channel_mask)
5655 % A description of each parameter follows:
5657 % o image: the image.
5659 % o mask: the channel mask.
5662 MagickExport void SetPixelChannelMapMask(Image *image,
5663 const ChannelType channel_mask)
5665 #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
5670 image->channel_mask=channel_mask;
5671 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5676 channel=GetPixelChannelMapChannel(image,i);
5677 SetPixelChannelMapTraits(image,channel,
5678 GetChannelBit(channel_mask,channel) == 0 ? CopyPixelTrait :
5679 image->matte == MagickFalse || (channel == AlphaPixelChannel) ?
5680 UpdatePixelTrait : (PixelTrait) (UpdatePixelTrait | BlendPixelTrait));
5682 if (image->storage_class == PseudoClass)
5683 SetPixelChannelMapTraits(image,IndexPixelChannel,CopyPixelTrait);
5684 if (image->debug != MagickFalse)
5685 LogPixelChannels(image);
5689 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5693 % S e t P i x e l C h a n n e l M a s k %
5697 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5699 % SetPixelChannelMask() sets the pixel channel mask from the specified channel
5702 % The format of the SetPixelChannelMask method is:
5704 % ChannelType SetPixelChannelMask(Image *image,
5705 % const ChannelType channel_mask)
5707 % A description of each parameter follows:
5709 % o image: the image.
5711 % o channel_mask: the channel mask.
5714 MagickExport ChannelType SetPixelChannelMask(Image *image,
5715 const ChannelType channel_mask)
5720 mask=image->channel_mask;
5721 image->channel_mask=channel_mask;
5722 SetPixelChannelMapMask(image,channel_mask);