41#include "MagickCore/studio.h"
42#include "MagickCore/property.h"
43#include "MagickCore/blob.h"
44#include "MagickCore/blob-private.h"
45#include "MagickCore/cache-private.h"
46#include "MagickCore/color-private.h"
47#include "MagickCore/colorspace-private.h"
48#include "MagickCore/draw.h"
49#include "MagickCore/exception.h"
50#include "MagickCore/exception-private.h"
51#include "MagickCore/cache.h"
52#include "MagickCore/constitute.h"
53#include "MagickCore/delegate.h"
54#include "MagickCore/geometry.h"
55#include "MagickCore/image-private.h"
56#include "MagickCore/list.h"
57#include "MagickCore/magick.h"
58#include "MagickCore/memory_.h"
59#include "MagickCore/memory-private.h"
60#include "MagickCore/monitor.h"
61#include "MagickCore/option.h"
62#include "MagickCore/pixel.h"
63#include "MagickCore/pixel-accessor.h"
64#include "MagickCore/pixel-private.h"
65#include "MagickCore/quantum.h"
66#include "MagickCore/quantum-private.h"
67#include "MagickCore/resource_.h"
68#include "MagickCore/semaphore.h"
69#include "MagickCore/statistic.h"
70#include "MagickCore/stream.h"
71#include "MagickCore/string_.h"
72#include "MagickCore/transform.h"
73#include "MagickCore/utility.h"
93MagickExport PixelChannelMap *AcquirePixelChannelMap(
void)
101 channel_map=(PixelChannelMap *) AcquireQuantumMemory(MaxPixelChannels+1,
102 sizeof(*channel_map));
103 if (channel_map == (PixelChannelMap *) NULL)
104 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
105 (void) memset(channel_map,0,(MaxPixelChannels+1)*
sizeof(*channel_map));
106 for (i=0; i <= MaxPixelChannels; i++)
107 channel_map[i].channel=(PixelChannel) i;
133MagickExport PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
138 assert(channel_map != (PixelChannelMap *) NULL);
139 clone_map=AcquirePixelChannelMap();
140 if (clone_map == (PixelChannelMap *) NULL)
141 return((PixelChannelMap *) NULL);
142 (void) memcpy(clone_map,channel_map,MaxPixelChannels*
sizeof(*channel_map));
169MagickExport PixelInfo *ClonePixelInfo(
const PixelInfo *pixel)
174 pixel_info=(PixelInfo *) AcquireMagickMemory(
sizeof(*pixel_info));
175 if (pixel_info == (PixelInfo *) NULL)
176 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
177 *pixel_info=(*pixel);
211MagickExport
void ConformPixelInfo(Image *image,
const PixelInfo *source,
212 PixelInfo *destination,ExceptionInfo *exception)
214 assert(image != (Image *) NULL);
215 assert(image->signature == MagickCoreSignature);
216 assert(destination != (
const PixelInfo *) NULL);
217 *destination=(*source);
218 ConformPixelInfoColorspace(image,destination,exception);
219 if (image->colorspace == CMYKColorspace)
221 if (IssRGBCompatibleColorspace(destination->colorspace) != MagickFalse)
222 ConvertRGBToCMYK(destination);
225 if (destination->colorspace == CMYKColorspace)
227 if (IssRGBCompatibleColorspace(image->colorspace) != MagickFalse)
228 ConvertCMYKToRGB(destination);
230 if ((IsPixelInfoGray(&image->background_color) == MagickFalse) &&
231 (IsGrayColorspace(image->colorspace) != MagickFalse))
232 (void) TransformImageColorspace(image,sRGBColorspace,exception);
233 if ((destination->alpha_trait != UndefinedPixelTrait) &&
234 ((image->alpha_trait & BlendPixelTrait) == 0))
235 (void) SetImageAlpha(image,OpaqueAlpha,exception);
261static inline double DecodeGamma(
const double x)
273 static const double coefficient[] =
275 1.7917488588043277509,
276 0.82045614371976854984,
277 0.027694100686325412819,
278 -0.00094244335181762134018,
279 0.000064355540911469709545,
280 -5.7224404636060757485e-06,
281 5.8767669437311184313e-07,
282 -6.6139920053589721168e-08,
283 7.9323242696227458163e-09
286 static const double powers_of_two[] =
289 2.6390158215457883983,
290 6.9644045063689921093,
291 1.8379173679952558018e+01,
292 4.8502930128332728543e+01
299 term[1]=4.0*frexp(x,&exponent)-3.0;
300 term[2]=2.0*term[1]*term[1]-term[0];
301 term[3]=2.0*term[1]*term[2]-term[1];
302 term[4]=2.0*term[1]*term[3]-term[2];
303 term[5]=2.0*term[1]*term[4]-term[3];
304 term[6]=2.0*term[1]*term[5]-term[4];
305 term[7]=2.0*term[1]*term[6]-term[5];
306 term[8]=2.0*term[1]*term[7]-term[6];
307 p=coefficient[0]*term[0]+coefficient[1]*term[1]+coefficient[2]*term[2]+
308 coefficient[3]*term[3]+coefficient[4]*term[4]+coefficient[5]*term[5]+
309 coefficient[6]*term[6]+coefficient[7]*term[7]+coefficient[8]*term[8];
310 quotient=div(exponent-1,5);
311 if (quotient.rem < 0)
316 return(x*ldexp(powers_of_two[quotient.rem]*p,7*quotient.quot));
319MagickExport MagickRealType DecodePixelGamma(
const MagickRealType pixel)
321 if (pixel <= (0.0404482362771076*(
double) QuantumRange))
323 return((MagickRealType) ((
double) QuantumRange*DecodeGamma((
double)
324 (QuantumScale*pixel+0.055)/1.055)));
350MagickExport PixelChannelMap *DestroyPixelChannelMap(
351 PixelChannelMap *channel_map)
353 assert(channel_map != (PixelChannelMap *) NULL);
354 channel_map=(PixelChannelMap *) RelinquishMagickMemory(channel_map);
355 return((PixelChannelMap *) RelinquishMagickMemory(channel_map));
381static inline double EncodeGamma(
const double x)
393 static const double coefficient[] =
395 1.1758200232996901923,
396 0.16665763094889061230,
397 -0.0083154894939042125035,
398 0.00075187976780420279038,
399 -0.000083240178519391795367,
400 0.000010229209410070008679,
401 -1.3400466409860246e-06,
402 1.8333422241635376682e-07,
403 -2.5878596761348859722e-08
406 static const double powers_of_two[] =
409 1.3348398541700343678,
410 1.7817974362806785482,
411 2.3784142300054420538,
412 3.1748021039363991669,
413 4.2378523774371812394,
414 5.6568542494923805819,
415 7.5509945014535482244,
416 1.0079368399158985525e1,
417 1.3454342644059433809e1,
418 1.7959392772949968275e1,
419 2.3972913230026907883e1
426 term[1]=4.0*frexp(x,&exponent)-3.0;
427 term[2]=2.0*term[1]*term[1]-term[0];
428 term[3]=2.0*term[1]*term[2]-term[1];
429 term[4]=2.0*term[1]*term[3]-term[2];
430 term[5]=2.0*term[1]*term[4]-term[3];
431 term[6]=2.0*term[1]*term[5]-term[4];
432 term[7]=2.0*term[1]*term[6]-term[5];
433 term[8]=2.0*term[1]*term[7]-term[6];
434 p=coefficient[0]*term[0]+coefficient[1]*term[1]+coefficient[2]*term[2]+
435 coefficient[3]*term[3]+coefficient[4]*term[4]+coefficient[5]*term[5]+
436 coefficient[6]*term[6]+coefficient[7]*term[7]+coefficient[8]*term[8];
437 quotient=div(exponent-1,12);
438 if (quotient.rem < 0)
443 return(ldexp(powers_of_two[quotient.rem]*p,5*quotient.quot));
446MagickExport MagickRealType EncodePixelGamma(
const MagickRealType pixel)
448 if (pixel <= (0.0031306684425005883*(
double) QuantumRange))
450 return((MagickRealType) QuantumRange*(1.055*EncodeGamma((
double) QuantumScale*
509static MagickBooleanType ExportCharPixel(
const Image *image,
510 const RectangleInfo *roi,
const char *magick_restrict map,
511 const QuantumType *quantum_map,
void *pixels,ExceptionInfo *exception)
528 q=(
unsigned char *) pixels;
529 if (LocaleCompare(map,
"BGR") == 0)
531 for (y=0; y < (ssize_t) roi->height; y++)
533 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
534 if (p == (
const Quantum *) NULL)
536 for (x=0; x < (ssize_t) roi->width; x++)
538 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
539 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
540 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
541 p+=(ptrdiff_t) GetPixelChannels(image);
544 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
546 if (LocaleCompare(map,
"BGRA") == 0)
548 for (y=0; y < (ssize_t) roi->height; y++)
550 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
551 if (p == (
const Quantum *) NULL)
553 for (x=0; x < (ssize_t) roi->width; x++)
555 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
556 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
557 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
558 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
559 p+=(ptrdiff_t) GetPixelChannels(image);
562 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
564 if (LocaleCompare(map,
"BGRP") == 0)
566 for (y=0; y < (ssize_t) roi->height; y++)
568 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
569 if (p == (
const Quantum *) NULL)
571 for (x=0; x < (ssize_t) roi->width; x++)
573 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
574 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
575 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
576 *q++=ScaleQuantumToChar((Quantum) 0);
577 p+=(ptrdiff_t) GetPixelChannels(image);
580 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
582 if (LocaleCompare(map,
"I") == 0)
584 for (y=0; y < (ssize_t) roi->height; y++)
586 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
587 if (p == (
const Quantum *) NULL)
589 for (x=0; x < (ssize_t) roi->width; x++)
591 *q++=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
592 p+=(ptrdiff_t) GetPixelChannels(image);
595 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
597 if (LocaleCompare(map,
"RGB") == 0)
599 for (y=0; y < (ssize_t) roi->height; y++)
601 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
602 if (p == (
const Quantum *) NULL)
604 for (x=0; x < (ssize_t) roi->width; x++)
606 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
607 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
608 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
609 p+=(ptrdiff_t) GetPixelChannels(image);
612 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
614 if (LocaleCompare(map,
"RGBA") == 0)
616 for (y=0; y < (ssize_t) roi->height; y++)
618 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
619 if (p == (
const Quantum *) NULL)
621 for (x=0; x < (ssize_t) roi->width; x++)
623 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
624 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
625 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
626 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
627 p+=(ptrdiff_t) GetPixelChannels(image);
630 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
632 if (LocaleCompare(map,
"RGBP") == 0)
634 for (y=0; y < (ssize_t) roi->height; y++)
636 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
637 if (p == (
const Quantum *) NULL)
639 for (x=0; x < (ssize_t) roi->width; x++)
641 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
642 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
643 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
644 *q++=ScaleQuantumToChar((Quantum) 0);
645 p+=(ptrdiff_t) GetPixelChannels(image);
648 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
651 for (y=0; y < (ssize_t) roi->height; y++)
653 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
654 if (p == (
const Quantum *) NULL)
656 for (x=0; x < (ssize_t) roi->width; x++)
661 for (i=0; i < (ssize_t) length; i++)
664 switch (quantum_map[i])
669 *q=ScaleQuantumToChar(GetPixelRed(image,p));
675 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
681 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
686 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
691 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
696 if (image->colorspace == CMYKColorspace)
697 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
702 *q=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
710 p+=(ptrdiff_t) GetPixelChannels(image);
713 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
716static MagickBooleanType ExportDoublePixel(
const Image *image,
717 const RectangleInfo *roi,
const char *magick_restrict map,
718 const QuantumType *quantum_map,
void *pixels,ExceptionInfo *exception)
736 if (LocaleCompare(map,
"BGR") == 0)
738 for (y=0; y < (ssize_t) roi->height; y++)
740 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
741 if (p == (
const Quantum *) NULL)
743 for (x=0; x < (ssize_t) roi->width; x++)
745 *q++=QuantumScale*(double) GetPixelBlue(image,p);
746 *q++=QuantumScale*(double) GetPixelGreen(image,p);
747 *q++=QuantumScale*(double) GetPixelRed(image,p);
748 p+=(ptrdiff_t) GetPixelChannels(image);
751 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
753 if (LocaleCompare(map,
"BGRA") == 0)
755 for (y=0; y < (ssize_t) roi->height; y++)
757 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
758 if (p == (
const Quantum *) NULL)
760 for (x=0; x < (ssize_t) roi->width; x++)
762 *q++=QuantumScale*(double) GetPixelBlue(image,p);
763 *q++=QuantumScale*(double) GetPixelGreen(image,p);
764 *q++=QuantumScale*(double) GetPixelRed(image,p);
765 *q++=QuantumScale*(double) GetPixelAlpha(image,p);
766 p+=(ptrdiff_t) GetPixelChannels(image);
769 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
771 if (LocaleCompare(map,
"BGRP") == 0)
773 for (y=0; y < (ssize_t) roi->height; y++)
775 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
776 if (p == (
const Quantum *) NULL)
778 for (x=0; x < (ssize_t) roi->width; x++)
780 *q++=QuantumScale*(double) GetPixelBlue(image,p);
781 *q++=QuantumScale*(double) GetPixelGreen(image,p);
782 *q++=QuantumScale*(double) GetPixelRed(image,p);
784 p+=(ptrdiff_t) GetPixelChannels(image);
787 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
789 if (LocaleCompare(map,
"I") == 0)
791 for (y=0; y < (ssize_t) roi->height; y++)
793 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
794 if (p == (
const Quantum *) NULL)
796 for (x=0; x < (ssize_t) roi->width; x++)
798 *q++=(double) (QuantumScale*(
double) GetPixelIntensity(image,p));
799 p+=(ptrdiff_t) GetPixelChannels(image);
802 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
804 if (LocaleCompare(map,
"RGB") == 0)
806 for (y=0; y < (ssize_t) roi->height; y++)
808 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
809 if (p == (
const Quantum *) NULL)
811 for (x=0; x < (ssize_t) roi->width; x++)
813 *q++=QuantumScale*(double) GetPixelRed(image,p);
814 *q++=QuantumScale*(double) GetPixelGreen(image,p);
815 *q++=QuantumScale*(double) GetPixelBlue(image,p);
816 p+=(ptrdiff_t) GetPixelChannels(image);
819 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
821 if (LocaleCompare(map,
"RGBA") == 0)
823 for (y=0; y < (ssize_t) roi->height; y++)
825 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
826 if (p == (
const Quantum *) NULL)
828 for (x=0; x < (ssize_t) roi->width; x++)
830 *q++=QuantumScale*(double) GetPixelRed(image,p);
831 *q++=QuantumScale*(double) GetPixelGreen(image,p);
832 *q++=QuantumScale*(double) GetPixelBlue(image,p);
833 *q++=QuantumScale*(double) GetPixelAlpha(image,p);
834 p+=(ptrdiff_t) GetPixelChannels(image);
837 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
839 if (LocaleCompare(map,
"RGBP") == 0)
841 for (y=0; y < (ssize_t) roi->height; y++)
843 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
844 if (p == (
const Quantum *) NULL)
846 for (x=0; x < (ssize_t) roi->width; x++)
848 *q++=QuantumScale*(double) GetPixelRed(image,p);
849 *q++=QuantumScale*(double) GetPixelGreen(image,p);
850 *q++=QuantumScale*(double) GetPixelBlue(image,p);
852 p+=(ptrdiff_t) GetPixelChannels(image);
855 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
858 for (y=0; y < (ssize_t) roi->height; y++)
860 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
861 if (p == (
const Quantum *) NULL)
863 for (x=0; x < (ssize_t) roi->width; x++)
868 for (i=0; i < (ssize_t) length; i++)
871 switch (quantum_map[i])
876 *q=QuantumScale*(double) GetPixelRed(image,p);
882 *q=QuantumScale*(double) GetPixelGreen(image,p);
888 *q=QuantumScale*(double) GetPixelBlue(image,p);
893 *q=QuantumScale*(double) GetPixelAlpha(image,p);
898 *q=QuantumScale*(double) GetPixelAlpha(image,p);
903 if (image->colorspace == CMYKColorspace)
904 *q=QuantumScale*(double) GetPixelBlack(image,p);
909 *q=QuantumScale*(double) GetPixelIntensity(image,p);
917 p+=(ptrdiff_t) GetPixelChannels(image);
920 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
923static MagickBooleanType ExportFloatPixel(
const Image *image,
924 const RectangleInfo *roi,
const char *magick_restrict map,
925 const QuantumType *quantum_map,
void *pixels,ExceptionInfo *exception)
943 if (LocaleCompare(map,
"BGR") == 0)
945 for (y=0; y < (ssize_t) roi->height; y++)
947 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
948 if (p == (
const Quantum *) NULL)
950 for (x=0; x < (ssize_t) roi->width; x++)
952 *q++=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
953 *q++=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
954 *q++=(float) (QuantumScale*(
double) GetPixelRed(image,p));
955 p+=(ptrdiff_t) GetPixelChannels(image);
958 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
960 if (LocaleCompare(map,
"BGRA") == 0)
962 for (y=0; y < (ssize_t) roi->height; y++)
964 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
965 if (p == (
const Quantum *) NULL)
967 for (x=0; x < (ssize_t) roi->width; x++)
969 *q++=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
970 *q++=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
971 *q++=(float) (QuantumScale*(
double) GetPixelRed(image,p));
972 *q++=(float) (QuantumScale*(
double) GetPixelAlpha(image,p));
973 p+=(ptrdiff_t) GetPixelChannels(image);
976 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
978 if (LocaleCompare(map,
"BGRP") == 0)
980 for (y=0; y < (ssize_t) roi->height; y++)
982 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
983 if (p == (
const Quantum *) NULL)
985 for (x=0; x < (ssize_t) roi->width; x++)
987 *q++=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
988 *q++=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
989 *q++=(float) (QuantumScale*(
double) GetPixelRed(image,p));
991 p+=(ptrdiff_t) GetPixelChannels(image);
994 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
996 if (LocaleCompare(map,
"I") == 0)
998 for (y=0; y < (ssize_t) roi->height; y++)
1000 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1001 if (p == (
const Quantum *) NULL)
1003 for (x=0; x < (ssize_t) roi->width; x++)
1005 *q++=(float) (QuantumScale*(
double) GetPixelIntensity(image,p));
1006 p+=(ptrdiff_t) GetPixelChannels(image);
1009 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1011 if (LocaleCompare(map,
"RGB") == 0)
1013 for (y=0; y < (ssize_t) roi->height; y++)
1015 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1016 if (p == (
const Quantum *) NULL)
1018 for (x=0; x < (ssize_t) roi->width; x++)
1020 *q++=(float) (QuantumScale*(
double) GetPixelRed(image,p));
1021 *q++=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
1022 *q++=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
1023 p+=(ptrdiff_t) GetPixelChannels(image);
1026 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1028 if (LocaleCompare(map,
"RGBA") == 0)
1030 for (y=0; y < (ssize_t) roi->height; y++)
1032 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1033 if (p == (
const Quantum *) NULL)
1035 for (x=0; x < (ssize_t) roi->width; x++)
1037 *q++=(float) (QuantumScale*(
double) GetPixelRed(image,p));
1038 *q++=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
1039 *q++=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
1040 *q++=(float) (QuantumScale*(
double) GetPixelAlpha(image,p));
1041 p+=(ptrdiff_t) GetPixelChannels(image);
1044 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1046 if (LocaleCompare(map,
"RGBP") == 0)
1048 for (y=0; y < (ssize_t) roi->height; y++)
1050 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1051 if (p == (
const Quantum *) NULL)
1053 for (x=0; x < (ssize_t) roi->width; x++)
1055 *q++=(float) (QuantumScale*(
double) GetPixelRed(image,p));
1056 *q++=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
1057 *q++=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
1059 p+=(ptrdiff_t) GetPixelChannels(image);
1062 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1065 for (y=0; y < (ssize_t) roi->height; y++)
1067 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1068 if (p == (
const Quantum *) NULL)
1070 for (x=0; x < (ssize_t) roi->width; x++)
1075 for (i=0; i < (ssize_t) length; i++)
1078 switch (quantum_map[i])
1083 *q=(float) (QuantumScale*(
double) GetPixelRed(image,p));
1087 case MagentaQuantum:
1089 *q=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
1095 *q=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
1100 *q=(float) (QuantumScale*((
double) (GetPixelAlpha(image,p))));
1103 case OpacityQuantum:
1105 *q=(float) (QuantumScale*(
double) GetPixelAlpha(image,p));
1110 if (image->colorspace == CMYKColorspace)
1111 *q=(float) (QuantumScale*(
double) GetPixelBlack(image,p));
1116 *q=(float) (QuantumScale*(
double) GetPixelIntensity(image,p));
1124 p+=(ptrdiff_t) GetPixelChannels(image);
1127 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1130static MagickBooleanType ExportLongPixel(
const Image *image,
1131 const RectangleInfo *roi,
const char *magick_restrict map,
1132 const QuantumType *quantum_map,
void *pixels,ExceptionInfo *exception)
1149 q=(
unsigned int *) pixels;
1150 if (LocaleCompare(map,
"BGR") == 0)
1152 for (y=0; y < (ssize_t) roi->height; y++)
1154 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1155 if (p == (
const Quantum *) NULL)
1157 for (x=0; x < (ssize_t) roi->width; x++)
1159 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1160 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1161 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1162 p+=(ptrdiff_t) GetPixelChannels(image);
1165 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1167 if (LocaleCompare(map,
"BGRA") == 0)
1169 for (y=0; y < (ssize_t) roi->height; y++)
1171 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1172 if (p == (
const Quantum *) NULL)
1174 for (x=0; x < (ssize_t) roi->width; x++)
1176 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1177 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1178 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1179 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1180 p+=(ptrdiff_t) GetPixelChannels(image);
1183 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1185 if (LocaleCompare(map,
"BGRP") == 0)
1187 for (y=0; y < (ssize_t) roi->height; y++)
1189 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1190 if (p == (
const Quantum *) NULL)
1192 for (x=0; x < (ssize_t) roi->width; x++)
1194 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1195 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1196 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1198 p+=(ptrdiff_t) GetPixelChannels(image);
1201 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1203 if (LocaleCompare(map,
"I") == 0)
1205 for (y=0; y < (ssize_t) roi->height; y++)
1207 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1208 if (p == (
const Quantum *) NULL)
1210 for (x=0; x < (ssize_t) roi->width; x++)
1212 *q++=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
1213 p+=(ptrdiff_t) GetPixelChannels(image);
1216 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1218 if (LocaleCompare(map,
"RGB") == 0)
1220 for (y=0; y < (ssize_t) roi->height; y++)
1222 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1223 if (p == (
const Quantum *) NULL)
1225 for (x=0; x < (ssize_t) roi->width; x++)
1227 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1228 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1229 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1230 p+=(ptrdiff_t) GetPixelChannels(image);
1233 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1235 if (LocaleCompare(map,
"RGBA") == 0)
1237 for (y=0; y < (ssize_t) roi->height; y++)
1239 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1240 if (p == (
const Quantum *) NULL)
1242 for (x=0; x < (ssize_t) roi->width; x++)
1244 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1245 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1246 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1247 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1248 p+=(ptrdiff_t) GetPixelChannels(image);
1251 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1253 if (LocaleCompare(map,
"RGBP") == 0)
1255 for (y=0; y < (ssize_t) roi->height; y++)
1257 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1258 if (p == (
const Quantum *) NULL)
1260 for (x=0; x < (ssize_t) roi->width; x++)
1262 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1263 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1264 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1266 p+=(ptrdiff_t) GetPixelChannels(image);
1269 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1272 for (y=0; y < (ssize_t) roi->height; y++)
1274 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1275 if (p == (
const Quantum *) NULL)
1277 for (x=0; x < (ssize_t) roi->width; x++)
1282 for (i=0; i < (ssize_t) length; i++)
1285 switch (quantum_map[i])
1290 *q=ScaleQuantumToLong(GetPixelRed(image,p));
1294 case MagentaQuantum:
1296 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
1302 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
1307 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1310 case OpacityQuantum:
1312 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1317 if (image->colorspace == CMYKColorspace)
1318 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
1323 *q=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
1331 p+=(ptrdiff_t) GetPixelChannels(image);
1334 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1337static MagickBooleanType ExportLongLongPixel(
const Image *image,
1338 const RectangleInfo *roi,
const char *magick_restrict map,
1339 const QuantumType *quantum_map,
void *pixels,ExceptionInfo *exception)
1356 q=(MagickSizeType *) pixels;
1357 if (LocaleCompare(map,
"BGR") == 0)
1359 for (y=0; y < (ssize_t) roi->height; y++)
1361 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1362 if (p == (
const Quantum *) NULL)
1364 for (x=0; x < (ssize_t) roi->width; x++)
1366 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1367 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1368 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1369 p+=(ptrdiff_t) GetPixelChannels(image);
1372 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1374 if (LocaleCompare(map,
"BGRA") == 0)
1376 for (y=0; y < (ssize_t) roi->height; y++)
1378 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1379 if (p == (
const Quantum *) NULL)
1381 for (x=0; x < (ssize_t) roi->width; x++)
1383 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1384 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1385 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1386 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1387 p+=(ptrdiff_t) GetPixelChannels(image);
1390 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1392 if (LocaleCompare(map,
"BGRP") == 0)
1394 for (y=0; y < (ssize_t) roi->height; y++)
1396 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1397 if (p == (
const Quantum *) NULL)
1399 for (x=0; x < (ssize_t) roi->width; x++)
1401 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1402 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1403 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1405 p+=(ptrdiff_t) GetPixelChannels(image);
1408 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1410 if (LocaleCompare(map,
"I") == 0)
1412 for (y=0; y < (ssize_t) roi->height; y++)
1414 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1415 if (p == (
const Quantum *) NULL)
1417 for (x=0; x < (ssize_t) roi->width; x++)
1419 *q++=ScaleQuantumToLongLong(ClampToQuantum(
1420 GetPixelIntensity(image,p)));
1421 p+=(ptrdiff_t) GetPixelChannels(image);
1424 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1426 if (LocaleCompare(map,
"RGB") == 0)
1428 for (y=0; y < (ssize_t) roi->height; y++)
1430 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1431 if (p == (
const Quantum *) NULL)
1433 for (x=0; x < (ssize_t) roi->width; x++)
1435 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1436 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1437 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1438 p+=(ptrdiff_t) GetPixelChannels(image);
1441 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1443 if (LocaleCompare(map,
"RGBA") == 0)
1445 for (y=0; y < (ssize_t) roi->height; y++)
1447 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1448 if (p == (
const Quantum *) NULL)
1450 for (x=0; x < (ssize_t) roi->width; x++)
1452 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1453 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1454 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1455 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1456 p+=(ptrdiff_t) GetPixelChannels(image);
1459 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1461 if (LocaleCompare(map,
"RGBP") == 0)
1463 for (y=0; y < (ssize_t) roi->height; y++)
1465 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1466 if (p == (
const Quantum *) NULL)
1468 for (x=0; x < (ssize_t) roi->width; x++)
1470 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1471 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1472 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1474 p+=(ptrdiff_t) GetPixelChannels(image);
1477 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1480 for (y=0; y < (ssize_t) roi->height; y++)
1482 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1483 if (p == (
const Quantum *) NULL)
1485 for (x=0; x < (ssize_t) roi->width; x++)
1490 for (i=0; i < (ssize_t) length; i++)
1493 switch (quantum_map[i])
1498 *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
1502 case MagentaQuantum:
1504 *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1510 *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1515 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1518 case OpacityQuantum:
1520 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1525 if (image->colorspace == CMYKColorspace)
1526 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
1531 *q=ScaleQuantumToLongLong(ClampToQuantum(
1532 GetPixelIntensity(image,p)));
1540 p+=(ptrdiff_t) GetPixelChannels(image);
1543 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1546static MagickBooleanType ExportQuantumPixel(
const Image *image,
1547 const RectangleInfo *roi,
const char *magick_restrict map,
1548 const QuantumType *quantum_map,
void *pixels,ExceptionInfo *exception)
1565 q=(Quantum *) pixels;
1566 if (LocaleCompare(map,
"BGR") == 0)
1568 for (y=0; y < (ssize_t) roi->height; y++)
1570 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1571 if (p == (
const Quantum *) NULL)
1573 for (x=0; x < (ssize_t) roi->width; x++)
1575 *q++=GetPixelBlue(image,p);
1576 *q++=GetPixelGreen(image,p);
1577 *q++=GetPixelRed(image,p);
1578 p+=(ptrdiff_t) GetPixelChannels(image);
1581 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1583 if (LocaleCompare(map,
"BGRA") == 0)
1585 for (y=0; y < (ssize_t) roi->height; y++)
1587 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1588 if (p == (
const Quantum *) NULL)
1590 for (x=0; x < (ssize_t) roi->width; x++)
1592 *q++=GetPixelBlue(image,p);
1593 *q++=GetPixelGreen(image,p);
1594 *q++=GetPixelRed(image,p);
1595 *q++=(Quantum) (GetPixelAlpha(image,p));
1596 p+=(ptrdiff_t) GetPixelChannels(image);
1599 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1601 if (LocaleCompare(map,
"BGRP") == 0)
1603 for (y=0; y < (ssize_t) roi->height; y++)
1605 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1606 if (p == (
const Quantum *) NULL)
1608 for (x=0; x < (ssize_t) roi->width; x++)
1610 *q++=GetPixelBlue(image,p);
1611 *q++=GetPixelGreen(image,p);
1612 *q++=GetPixelRed(image,p);
1614 p+=(ptrdiff_t) GetPixelChannels(image);
1617 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1619 if (LocaleCompare(map,
"I") == 0)
1621 for (y=0; y < (ssize_t) roi->height; y++)
1623 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1624 if (p == (
const Quantum *) NULL)
1626 for (x=0; x < (ssize_t) roi->width; x++)
1628 *q++=ClampToQuantum(GetPixelIntensity(image,p));
1629 p+=(ptrdiff_t) GetPixelChannels(image);
1632 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1634 if (LocaleCompare(map,
"RGB") == 0)
1636 for (y=0; y < (ssize_t) roi->height; y++)
1638 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1639 if (p == (
const Quantum *) NULL)
1641 for (x=0; x < (ssize_t) roi->width; x++)
1643 *q++=GetPixelRed(image,p);
1644 *q++=GetPixelGreen(image,p);
1645 *q++=GetPixelBlue(image,p);
1646 p+=(ptrdiff_t) GetPixelChannels(image);
1649 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1651 if (LocaleCompare(map,
"RGBA") == 0)
1653 for (y=0; y < (ssize_t) roi->height; y++)
1655 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1656 if (p == (
const Quantum *) NULL)
1658 for (x=0; x < (ssize_t) roi->width; x++)
1660 *q++=GetPixelRed(image,p);
1661 *q++=GetPixelGreen(image,p);
1662 *q++=GetPixelBlue(image,p);
1663 *q++=(Quantum) (GetPixelAlpha(image,p));
1664 p+=(ptrdiff_t) GetPixelChannels(image);
1667 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1669 if (LocaleCompare(map,
"RGBP") == 0)
1671 for (y=0; y < (ssize_t) roi->height; y++)
1673 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1674 if (p == (
const Quantum *) NULL)
1676 for (x=0; x < (ssize_t) roi->width; x++)
1678 *q++=GetPixelRed(image,p);
1679 *q++=GetPixelGreen(image,p);
1680 *q++=GetPixelBlue(image,p);
1682 p+=(ptrdiff_t) GetPixelChannels(image);
1685 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1688 for (y=0; y < (ssize_t) roi->height; y++)
1690 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1691 if (p == (
const Quantum *) NULL)
1693 for (x=0; x < (ssize_t) roi->width; x++)
1698 for (i=0; i < (ssize_t) length; i++)
1701 switch (quantum_map[i])
1706 *q=GetPixelRed(image,p);
1710 case MagentaQuantum:
1712 *q=GetPixelGreen(image,p);
1718 *q=GetPixelBlue(image,p);
1723 *q=GetPixelAlpha(image,p);
1726 case OpacityQuantum:
1728 *q=GetPixelAlpha(image,p);
1733 if (image->colorspace == CMYKColorspace)
1734 *q=GetPixelBlack(image,p);
1739 *q=ClampToQuantum(GetPixelIntensity(image,p));
1750 p+=(ptrdiff_t) GetPixelChannels(image);
1753 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1756static MagickBooleanType ExportShortPixel(
const Image *image,
1757 const RectangleInfo *roi,
const char *magick_restrict map,
1758 const QuantumType *quantum_map,
void *pixels,ExceptionInfo *exception)
1775 q=(
unsigned short *) pixels;
1776 if (LocaleCompare(map,
"BGR") == 0)
1778 for (y=0; y < (ssize_t) roi->height; y++)
1780 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1781 if (p == (
const Quantum *) NULL)
1783 for (x=0; x < (ssize_t) roi->width; x++)
1785 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1786 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1787 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1788 p+=(ptrdiff_t) GetPixelChannels(image);
1791 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1793 if (LocaleCompare(map,
"BGRA") == 0)
1795 for (y=0; y < (ssize_t) roi->height; y++)
1797 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1798 if (p == (
const Quantum *) NULL)
1800 for (x=0; x < (ssize_t) roi->width; x++)
1802 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1803 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1804 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1805 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1806 p+=(ptrdiff_t) GetPixelChannels(image);
1809 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1811 if (LocaleCompare(map,
"BGRP") == 0)
1813 for (y=0; y < (ssize_t) roi->height; y++)
1815 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1816 if (p == (
const Quantum *) NULL)
1818 for (x=0; x < (ssize_t) roi->width; x++)
1820 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1821 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1822 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1824 p+=(ptrdiff_t) GetPixelChannels(image);
1827 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1829 if (LocaleCompare(map,
"I") == 0)
1831 for (y=0; y < (ssize_t) roi->height; y++)
1833 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1834 if (p == (
const Quantum *) NULL)
1836 for (x=0; x < (ssize_t) roi->width; x++)
1838 *q++=ScaleQuantumToShort(ClampToQuantum(GetPixelIntensity(image,p)));
1839 p+=(ptrdiff_t) GetPixelChannels(image);
1842 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1844 if (LocaleCompare(map,
"RGB") == 0)
1846 for (y=0; y < (ssize_t) roi->height; y++)
1848 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1849 if (p == (
const Quantum *) NULL)
1851 for (x=0; x < (ssize_t) roi->width; x++)
1853 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1854 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1855 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1856 p+=(ptrdiff_t) GetPixelChannels(image);
1859 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1861 if (LocaleCompare(map,
"RGBA") == 0)
1863 for (y=0; y < (ssize_t) roi->height; y++)
1865 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1866 if (p == (
const Quantum *) NULL)
1868 for (x=0; x < (ssize_t) roi->width; x++)
1870 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1871 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1872 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1873 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1874 p+=(ptrdiff_t) GetPixelChannels(image);
1877 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1879 if (LocaleCompare(map,
"RGBP") == 0)
1881 for (y=0; y < (ssize_t) roi->height; y++)
1883 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1884 if (p == (
const Quantum *) NULL)
1886 for (x=0; x < (ssize_t) roi->width; x++)
1888 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1889 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1890 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1892 p+=(ptrdiff_t) GetPixelChannels(image);
1895 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1898 for (y=0; y < (ssize_t) roi->height; y++)
1900 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1901 if (p == (
const Quantum *) NULL)
1903 for (x=0; x < (ssize_t) roi->width; x++)
1908 for (i=0; i < (ssize_t) length; i++)
1911 switch (quantum_map[i])
1916 *q=ScaleQuantumToShort(GetPixelRed(image,p));
1920 case MagentaQuantum:
1922 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
1928 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
1933 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1936 case OpacityQuantum:
1938 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1943 if (image->colorspace == CMYKColorspace)
1944 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
1949 *q=ScaleQuantumToShort(ClampToQuantum(GetPixelIntensity(image,p)));
1957 p+=(ptrdiff_t) GetPixelChannels(image);
1960 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1963MagickExport MagickBooleanType ExportImagePixels(
const Image *image,
1964 const ssize_t x,
const ssize_t y,
const size_t width,
const size_t height,
1965 const char *map,
const StorageType type,
void *pixels,ExceptionInfo *exception)
1982 assert(image != (Image *) NULL);
1983 assert(image->signature == MagickCoreSignature);
1984 if (IsEventLogging() != MagickFalse)
1985 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1987 quantum_map=(QuantumType *) AcquireQuantumMemory(length,
sizeof(*quantum_map));
1988 if (quantum_map == (QuantumType *) NULL)
1990 (void) ThrowMagickException(exception,GetMagickModule(),
1991 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",image->filename);
1992 return(MagickFalse);
1994 for (i=0; i < (ssize_t) length; i++)
2001 quantum_map[i]=AlphaQuantum;
2007 quantum_map[i]=BlueQuantum;
2013 quantum_map[i]=CyanQuantum;
2014 if (image->colorspace == CMYKColorspace)
2016 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2017 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2018 "ColorSeparatedImageRequired",
"`%s'",map);
2019 return(MagickFalse);
2024 quantum_map[i]=GreenQuantum;
2030 quantum_map[i]=IndexQuantum;
2036 quantum_map[i]=BlackQuantum;
2037 if (image->colorspace == CMYKColorspace)
2039 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2040 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2041 "ColorSeparatedImageRequired",
"`%s'",map);
2042 return(MagickFalse);
2047 quantum_map[i]=MagentaQuantum;
2048 if (image->colorspace == CMYKColorspace)
2050 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2051 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2052 "ColorSeparatedImageRequired",
"`%s'",map);
2053 return(MagickFalse);
2058 quantum_map[i]=OpacityQuantum;
2064 quantum_map[i]=UndefinedQuantum;
2070 quantum_map[i]=RedQuantum;
2076 quantum_map[i]=YellowQuantum;
2077 if (image->colorspace == CMYKColorspace)
2079 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2080 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2081 "ColorSeparatedImageRequired",
"`%s'",map);
2082 return(MagickFalse);
2086 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2087 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2088 "UnrecognizedPixelMap",
"`%s'",map);
2089 return(MagickFalse);
2101 status=ExportCharPixel(image,&roi,map,quantum_map,pixels,exception);
2106 status=ExportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
2111 status=ExportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
2116 status=ExportLongPixel(image,&roi,map,quantum_map,pixels,exception);
2121 status=ExportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
2126 status=ExportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
2131 status=ExportShortPixel(image,&roi,map,quantum_map,pixels,exception);
2136 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2137 "UnrecognizedPixelMap",
"`%s'",map);
2141 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2169MagickExport
void GetPixelInfo(
const Image *image,PixelInfo *pixel)
2171 (void) memset(pixel,0,
sizeof(*pixel));
2172 pixel->storage_class=DirectClass;
2173 pixel->colorspace=sRGBColorspace;
2174 pixel->depth=MAGICKCORE_QUANTUM_DEPTH;
2175 pixel->alpha_trait=UndefinedPixelTrait;
2176 pixel->alpha=(double) OpaqueAlpha;
2177 if (image == (
const Image *) NULL)
2179 pixel->storage_class=image->storage_class;
2180 pixel->colorspace=image->colorspace;
2181 pixel->alpha_trait=image->alpha_trait;
2182 pixel->depth=image->depth;
2183 pixel->fuzz=image->fuzz;
2223MagickExport MagickRealType GetPixelInfoIntensity(
2224 const Image *magick_restrict image,
const PixelInfo *magick_restrict pixel)
2232 PixelIntensityMethod
2235 method=Rec709LumaPixelIntensityMethod;
2236 if (image != (
const Image *) NULL)
2237 method=image->intensity;
2243 case AveragePixelIntensityMethod:
2245 intensity=(red+green+blue)/3.0;
2248 case BrightnessPixelIntensityMethod:
2250 intensity=MagickMax(MagickMax(red,green),blue);
2253 case LightnessPixelIntensityMethod:
2255 intensity=(MagickMin(MagickMin(red,green),blue)+
2256 MagickMax(MagickMax(red,green),blue))/2.0;
2259 case MSPixelIntensityMethod:
2261 intensity=(MagickRealType) (((
double) red*red+green*green+blue*blue)/
2262 (3.0*(
double) QuantumRange));
2265 case Rec601LumaPixelIntensityMethod:
2267 if (pixel->colorspace == RGBColorspace)
2269 red=EncodePixelGamma(red);
2270 green=EncodePixelGamma(green);
2271 blue=EncodePixelGamma(blue);
2273 intensity=0.298839*red+0.586811*green+0.114350*blue;
2276 case Rec601LuminancePixelIntensityMethod:
2278 if (pixel->colorspace == sRGBColorspace)
2280 red=DecodePixelGamma(red);
2281 green=DecodePixelGamma(green);
2282 blue=DecodePixelGamma(blue);
2284 intensity=0.298839*red+0.586811*green+0.114350*blue;
2287 case Rec709LumaPixelIntensityMethod:
2290 if (pixel->colorspace == RGBColorspace)
2292 red=EncodePixelGamma(red);
2293 green=EncodePixelGamma(green);
2294 blue=EncodePixelGamma(blue);
2296 intensity=0.212656*red+0.715158*green+0.072186*blue;
2299 case Rec709LuminancePixelIntensityMethod:
2301 if (pixel->colorspace == sRGBColorspace)
2303 red=DecodePixelGamma(red);
2304 green=DecodePixelGamma(green);
2305 blue=DecodePixelGamma(blue);
2307 intensity=0.212656*red+0.715158*green+0.072186*blue;
2310 case RMSPixelIntensityMethod:
2312 intensity=(MagickRealType) (sqrt((
double) red*red+green*green+blue*blue)/
2357MagickExport MagickRealType GetPixelIntensity(
2358 const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
2366 red=(MagickRealType) GetPixelRed(image,pixel);
2367 if (image->number_channels == 1)
2369 green=(MagickRealType) GetPixelGreen(image,pixel);
2370 blue=(MagickRealType) GetPixelBlue(image,pixel);
2371 switch (image->intensity)
2373 case AveragePixelIntensityMethod:
2375 intensity=(red+green+blue)/3.0;
2378 case BrightnessPixelIntensityMethod:
2380 intensity=MagickMax(MagickMax(red,green),blue);
2383 case LightnessPixelIntensityMethod:
2385 intensity=(MagickMin(MagickMin(red,green),blue)+
2386 MagickMax(MagickMax(red,green),blue))/2.0;
2389 case MSPixelIntensityMethod:
2391 intensity=(MagickRealType) (((
double) red*red+green*green+blue*blue)/
2392 (3.0*(
double) QuantumRange));
2395 case Rec601LumaPixelIntensityMethod:
2397 if ((image->colorspace == RGBColorspace) ||
2398 (image->colorspace == LinearGRAYColorspace))
2400 red=EncodePixelGamma(red);
2401 green=EncodePixelGamma(green);
2402 blue=EncodePixelGamma(blue);
2404 intensity=0.298839*red+0.586811*green+0.114350*blue;
2407 case Rec601LuminancePixelIntensityMethod:
2409 if ((image->colorspace == sRGBColorspace) ||
2410 (image->colorspace == GRAYColorspace))
2412 red=DecodePixelGamma(red);
2413 green=DecodePixelGamma(green);
2414 blue=DecodePixelGamma(blue);
2416 intensity=0.298839*red+0.586811*green+0.114350*blue;
2419 case Rec709LumaPixelIntensityMethod:
2422 if ((image->colorspace == RGBColorspace) ||
2423 (image->colorspace == LinearGRAYColorspace))
2425 red=EncodePixelGamma(red);
2426 green=EncodePixelGamma(green);
2427 blue=EncodePixelGamma(blue);
2429 intensity=0.212656*red+0.715158*green+0.072186*blue;
2432 case Rec709LuminancePixelIntensityMethod:
2434 if ((image->colorspace == sRGBColorspace) ||
2435 (image->colorspace == GRAYColorspace))
2437 red=DecodePixelGamma(red);
2438 green=DecodePixelGamma(green);
2439 blue=DecodePixelGamma(blue);
2441 intensity=0.212656*red+0.715158*green+0.072186*blue;
2444 case RMSPixelIntensityMethod:
2446 intensity=(MagickRealType) (sqrt((
double) red*red+green*green+blue*blue)/
2510static MagickBooleanType ImportCharPixel(Image *image,
const RectangleInfo *roi,
2511 const char *magick_restrict map,
const QuantumType *quantum_map,
2512 const void *pixels,ExceptionInfo *exception)
2529 p=(
const unsigned char *) pixels;
2530 if (LocaleCompare(map,
"BGR") == 0)
2532 for (y=0; y < (ssize_t) roi->height; y++)
2534 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2535 if (q == (Quantum *) NULL)
2537 for (x=0; x < (ssize_t) roi->width; x++)
2539 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2540 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2541 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2542 q+=(ptrdiff_t) GetPixelChannels(image);
2544 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2547 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2549 if (LocaleCompare(map,
"BGRA") == 0)
2551 for (y=0; y < (ssize_t) roi->height; y++)
2553 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2554 if (q == (Quantum *) NULL)
2556 for (x=0; x < (ssize_t) roi->width; x++)
2558 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2559 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2560 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2561 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2562 q+=(ptrdiff_t) GetPixelChannels(image);
2564 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2567 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2569 if (LocaleCompare(map,
"BGRO") == 0)
2571 for (y=0; y < (ssize_t) roi->height; y++)
2573 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2574 if (q == (Quantum *) NULL)
2576 for (x=0; x < (ssize_t) roi->width; x++)
2578 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2579 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2580 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2581 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2582 q+=(ptrdiff_t) GetPixelChannels(image);
2584 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2587 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2589 if (LocaleCompare(map,
"BGRP") == 0)
2591 for (y=0; y < (ssize_t) roi->height; y++)
2593 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2594 if (q == (Quantum *) NULL)
2596 for (x=0; x < (ssize_t) roi->width; x++)
2598 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2599 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2600 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2602 q+=(ptrdiff_t) GetPixelChannels(image);
2604 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2607 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2609 if (LocaleCompare(map,
"I") == 0)
2611 for (y=0; y < (ssize_t) roi->height; y++)
2613 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2614 if (q == (Quantum *) NULL)
2616 for (x=0; x < (ssize_t) roi->width; x++)
2618 SetPixelGray(image,ScaleCharToQuantum(*p++),q);
2619 q+=(ptrdiff_t) GetPixelChannels(image);
2621 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2624 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2626 if (LocaleCompare(map,
"RGB") == 0)
2628 for (y=0; y < (ssize_t) roi->height; y++)
2630 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2631 if (q == (Quantum *) NULL)
2633 for (x=0; x < (ssize_t) roi->width; x++)
2635 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2636 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2637 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2638 q+=(ptrdiff_t) GetPixelChannels(image);
2640 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2643 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2645 if (LocaleCompare(map,
"RGBA") == 0)
2647 for (y=0; y < (ssize_t) roi->height; y++)
2649 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2650 if (q == (Quantum *) NULL)
2652 for (x=0; x < (ssize_t) roi->width; x++)
2654 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2655 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2656 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2657 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2658 q+=(ptrdiff_t) GetPixelChannels(image);
2660 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2663 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2665 if (LocaleCompare(map,
"RGBO") == 0)
2667 for (y=0; y < (ssize_t) roi->height; y++)
2669 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2670 if (q == (Quantum *) NULL)
2672 for (x=0; x < (ssize_t) roi->width; x++)
2674 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2675 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2676 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2677 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2678 q+=(ptrdiff_t) GetPixelChannels(image);
2680 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2683 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2685 if (LocaleCompare(map,
"RGBP") == 0)
2687 for (y=0; y < (ssize_t) roi->height; y++)
2689 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2690 if (q == (Quantum *) NULL)
2692 for (x=0; x < (ssize_t) roi->width; x++)
2694 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2695 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2696 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2698 q+=(ptrdiff_t) GetPixelChannels(image);
2700 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2703 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2706 for (y=0; y < (ssize_t) roi->height; y++)
2708 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2709 if (q == (Quantum *) NULL)
2711 for (x=0; x < (ssize_t) roi->width; x++)
2716 for (i=0; i < (ssize_t) length; i++)
2718 switch (quantum_map[i])
2723 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2727 case MagentaQuantum:
2729 SetPixelGreen(image,ScaleCharToQuantum(*p),q);
2735 SetPixelBlue(image,ScaleCharToQuantum(*p),q);
2740 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2743 case OpacityQuantum:
2745 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2750 SetPixelBlack(image,ScaleCharToQuantum(*p),q);
2755 SetPixelGray(image,ScaleCharToQuantum(*p),q);
2763 q+=(ptrdiff_t) GetPixelChannels(image);
2765 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2768 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2771static MagickBooleanType ImportDoublePixel(Image *image,
2772 const RectangleInfo *roi,
const char *magick_restrict map,
2773 const QuantumType *quantum_map,
const void *pixels,ExceptionInfo *exception)
2790 p=(
const double *) pixels;
2791 if (LocaleCompare(map,
"BGR") == 0)
2793 for (y=0; y < (ssize_t) roi->height; y++)
2795 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2796 if (q == (Quantum *) NULL)
2798 for (x=0; x < (ssize_t) roi->width; x++)
2800 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2802 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2804 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2806 q+=(ptrdiff_t) GetPixelChannels(image);
2808 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2811 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2813 if (LocaleCompare(map,
"BGRA") == 0)
2815 for (y=0; y < (ssize_t) roi->height; y++)
2817 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2818 if (q == (Quantum *) NULL)
2820 for (x=0; x < (ssize_t) roi->width; x++)
2822 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2824 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2826 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2828 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2830 q+=(ptrdiff_t) GetPixelChannels(image);
2832 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2835 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2837 if (LocaleCompare(map,
"BGRP") == 0)
2839 for (y=0; y < (ssize_t) roi->height; y++)
2841 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2842 if (q == (Quantum *) NULL)
2844 for (x=0; x < (ssize_t) roi->width; x++)
2846 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2848 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2850 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2853 q+=(ptrdiff_t) GetPixelChannels(image);
2855 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2858 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2860 if (LocaleCompare(map,
"I") == 0)
2862 for (y=0; y < (ssize_t) roi->height; y++)
2864 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2865 if (q == (Quantum *) NULL)
2867 for (x=0; x < (ssize_t) roi->width; x++)
2869 SetPixelGray(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2871 q+=(ptrdiff_t) GetPixelChannels(image);
2873 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2876 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2878 if (LocaleCompare(map,
"RGB") == 0)
2880 for (y=0; y < (ssize_t) roi->height; y++)
2882 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2883 if (q == (Quantum *) NULL)
2885 for (x=0; x < (ssize_t) roi->width; x++)
2887 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2889 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2891 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2893 q+=(ptrdiff_t) GetPixelChannels(image);
2895 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2898 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2900 if (LocaleCompare(map,
"RGBA") == 0)
2902 for (y=0; y < (ssize_t) roi->height; y++)
2904 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2905 if (q == (Quantum *) NULL)
2907 for (x=0; x < (ssize_t) roi->width; x++)
2909 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2911 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2913 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2915 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2917 q+=(ptrdiff_t) GetPixelChannels(image);
2919 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2922 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2924 if (LocaleCompare(map,
"RGBP") == 0)
2926 for (y=0; y < (ssize_t) roi->height; y++)
2928 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2929 if (q == (Quantum *) NULL)
2931 for (x=0; x < (ssize_t) roi->width; x++)
2933 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2935 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2937 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2939 q+=(ptrdiff_t) GetPixelChannels(image);
2941 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2944 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2947 for (y=0; y < (ssize_t) roi->height; y++)
2949 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2950 if (q == (Quantum *) NULL)
2952 for (x=0; x < (ssize_t) roi->width; x++)
2957 for (i=0; i < (ssize_t) length; i++)
2959 switch (quantum_map[i])
2964 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2968 case MagentaQuantum:
2970 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2976 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2981 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2984 case OpacityQuantum:
2986 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2991 SetPixelBlack(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2996 SetPixelGray(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
3004 q+=(ptrdiff_t) GetPixelChannels(image);
3006 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3009 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3012static MagickBooleanType ImportFloatPixel(Image *image,
const RectangleInfo *roi,
3013 const char *magick_restrict map,
const QuantumType *quantum_map,
3014 const void *pixels,ExceptionInfo *exception)
3031 p=(
const float *) pixels;
3032 if (LocaleCompare(map,
"BGR") == 0)
3034 for (y=0; y < (ssize_t) roi->height; y++)
3036 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3037 if (q == (Quantum *) NULL)
3039 for (x=0; x < (ssize_t) roi->width; x++)
3041 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3044 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3047 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3050 q+=(ptrdiff_t) GetPixelChannels(image);
3052 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3055 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3057 if (LocaleCompare(map,
"BGRA") == 0)
3059 for (y=0; y < (ssize_t) roi->height; y++)
3061 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3062 if (q == (Quantum *) NULL)
3064 for (x=0; x < (ssize_t) roi->width; x++)
3066 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3069 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3072 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3075 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(
double)
3078 q+=(ptrdiff_t) GetPixelChannels(image);
3080 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3083 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3085 if (LocaleCompare(map,
"BGRP") == 0)
3087 for (y=0; y < (ssize_t) roi->height; y++)
3089 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3090 if (q == (Quantum *) NULL)
3092 for (x=0; x < (ssize_t) roi->width; x++)
3094 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3097 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3100 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3104 q+=(ptrdiff_t) GetPixelChannels(image);
3106 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3109 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3111 if (LocaleCompare(map,
"I") == 0)
3113 for (y=0; y < (ssize_t) roi->height; y++)
3115 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3116 if (q == (Quantum *) NULL)
3118 for (x=0; x < (ssize_t) roi->width; x++)
3120 SetPixelGray(image,ClampToQuantum((
double) QuantumRange*(
double)
3123 q+=(ptrdiff_t) GetPixelChannels(image);
3125 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3128 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3130 if (LocaleCompare(map,
"RGB") == 0)
3132 for (y=0; y < (ssize_t) roi->height; y++)
3134 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3135 if (q == (Quantum *) NULL)
3137 for (x=0; x < (ssize_t) roi->width; x++)
3139 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3142 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3145 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3148 q+=(ptrdiff_t) GetPixelChannels(image);
3150 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3153 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3155 if (LocaleCompare(map,
"RGBA") == 0)
3157 for (y=0; y < (ssize_t) roi->height; y++)
3159 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3160 if (q == (Quantum *) NULL)
3162 for (x=0; x < (ssize_t) roi->width; x++)
3164 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3167 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3170 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3173 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(
double)
3176 q+=(ptrdiff_t) GetPixelChannels(image);
3178 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3181 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3183 if (LocaleCompare(map,
"RGBP") == 0)
3185 for (y=0; y < (ssize_t) roi->height; y++)
3187 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3188 if (q == (Quantum *) NULL)
3190 for (x=0; x < (ssize_t) roi->width; x++)
3192 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3195 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3198 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3201 q+=(ptrdiff_t) GetPixelChannels(image);
3203 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3206 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3209 for (y=0; y < (ssize_t) roi->height; y++)
3211 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3212 if (q == (Quantum *) NULL)
3214 for (x=0; x < (ssize_t) roi->width; x++)
3219 for (i=0; i < (ssize_t) length; i++)
3221 switch (quantum_map[i])
3226 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3231 case MagentaQuantum:
3233 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3240 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3246 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(
double)
3250 case OpacityQuantum:
3252 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(
double)
3258 SetPixelBlack(image,ClampToQuantum((
double) QuantumRange*(
double)
3264 SetPixelGray(image,ClampToQuantum((
double) QuantumRange*(
double)
3273 q+=(ptrdiff_t) GetPixelChannels(image);
3275 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3278 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3281static MagickBooleanType ImportLongPixel(Image *image,
const RectangleInfo *roi,
3282 const char *magick_restrict map,
const QuantumType *quantum_map,
3283 const void *pixels,ExceptionInfo *exception)
3300 p=(
const unsigned int *) pixels;
3301 if (LocaleCompare(map,
"BGR") == 0)
3303 for (y=0; y < (ssize_t) roi->height; y++)
3305 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3306 if (q == (Quantum *) NULL)
3308 for (x=0; x < (ssize_t) roi->width; x++)
3310 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3311 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3312 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3313 q+=(ptrdiff_t) GetPixelChannels(image);
3315 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3318 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3320 if (LocaleCompare(map,
"BGRA") == 0)
3322 for (y=0; y < (ssize_t) roi->height; y++)
3324 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3325 if (q == (Quantum *) NULL)
3327 for (x=0; x < (ssize_t) roi->width; x++)
3329 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3330 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3331 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3332 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3333 q+=(ptrdiff_t) GetPixelChannels(image);
3335 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3338 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3340 if (LocaleCompare(map,
"BGRP") == 0)
3342 for (y=0; y < (ssize_t) roi->height; y++)
3344 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3345 if (q == (Quantum *) NULL)
3347 for (x=0; x < (ssize_t) roi->width; x++)
3349 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3350 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3351 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3353 q+=(ptrdiff_t) GetPixelChannels(image);
3355 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3358 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3360 if (LocaleCompare(map,
"I") == 0)
3362 for (y=0; y < (ssize_t) roi->height; y++)
3364 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3365 if (q == (Quantum *) NULL)
3367 for (x=0; x < (ssize_t) roi->width; x++)
3369 SetPixelGray(image,ScaleLongToQuantum(*p++),q);
3370 q+=(ptrdiff_t) GetPixelChannels(image);
3372 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3375 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3377 if (LocaleCompare(map,
"RGB") == 0)
3379 for (y=0; y < (ssize_t) roi->height; y++)
3381 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3382 if (q == (Quantum *) NULL)
3384 for (x=0; x < (ssize_t) roi->width; x++)
3386 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3387 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3388 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3389 q+=(ptrdiff_t) GetPixelChannels(image);
3391 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3394 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3396 if (LocaleCompare(map,
"RGBA") == 0)
3398 for (y=0; y < (ssize_t) roi->height; y++)
3400 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3401 if (q == (Quantum *) NULL)
3403 for (x=0; x < (ssize_t) roi->width; x++)
3405 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3406 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3407 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3408 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3409 q+=(ptrdiff_t) GetPixelChannels(image);
3411 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3414 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3416 if (LocaleCompare(map,
"RGBP") == 0)
3418 for (y=0; y < (ssize_t) roi->height; y++)
3420 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3421 if (q == (Quantum *) NULL)
3423 for (x=0; x < (ssize_t) roi->width; x++)
3425 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3426 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3427 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3429 q+=(ptrdiff_t) GetPixelChannels(image);
3431 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3434 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3437 for (y=0; y < (ssize_t) roi->height; y++)
3439 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3440 if (q == (Quantum *) NULL)
3442 for (x=0; x < (ssize_t) roi->width; x++)
3447 for (i=0; i < (ssize_t) length; i++)
3449 switch (quantum_map[i])
3454 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3458 case MagentaQuantum:
3460 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
3466 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
3471 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3474 case OpacityQuantum:
3476 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3481 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
3486 SetPixelGray(image,ScaleLongToQuantum(*p),q);
3494 q+=(ptrdiff_t) GetPixelChannels(image);
3496 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3499 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3502static MagickBooleanType ImportLongLongPixel(Image *image,
3503 const RectangleInfo *roi,
const char *magick_restrict map,
3504 const QuantumType *quantum_map,
const void *pixels,ExceptionInfo *exception)
3506 const MagickSizeType
3521 p=(
const MagickSizeType *) pixels;
3522 if (LocaleCompare(map,
"BGR") == 0)
3524 for (y=0; y < (ssize_t) roi->height; y++)
3526 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3527 if (q == (Quantum *) NULL)
3529 for (x=0; x < (ssize_t) roi->width; x++)
3531 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3532 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3533 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3534 q+=(ptrdiff_t) GetPixelChannels(image);
3536 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3539 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3541 if (LocaleCompare(map,
"BGRA") == 0)
3543 for (y=0; y < (ssize_t) roi->height; y++)
3545 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3546 if (q == (Quantum *) NULL)
3548 for (x=0; x < (ssize_t) roi->width; x++)
3550 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3551 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3552 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3553 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3554 q+=(ptrdiff_t) GetPixelChannels(image);
3556 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3559 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3561 if (LocaleCompare(map,
"BGRP") == 0)
3563 for (y=0; y < (ssize_t) roi->height; y++)
3565 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3566 if (q == (Quantum *) NULL)
3568 for (x=0; x < (ssize_t) roi->width; x++)
3570 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3571 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3572 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3574 q+=(ptrdiff_t) GetPixelChannels(image);
3576 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3579 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3581 if (LocaleCompare(map,
"I") == 0)
3583 for (y=0; y < (ssize_t) roi->height; y++)
3585 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3586 if (q == (Quantum *) NULL)
3588 for (x=0; x < (ssize_t) roi->width; x++)
3590 SetPixelGray(image,ScaleLongLongToQuantum(*p++),q);
3591 q+=(ptrdiff_t) GetPixelChannels(image);
3593 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3596 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3598 if (LocaleCompare(map,
"RGB") == 0)
3600 for (y=0; y < (ssize_t) roi->height; y++)
3602 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3603 if (q == (Quantum *) NULL)
3605 for (x=0; x < (ssize_t) roi->width; x++)
3607 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3608 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3609 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3610 q+=(ptrdiff_t) GetPixelChannels(image);
3612 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3615 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3617 if (LocaleCompare(map,
"RGBA") == 0)
3619 for (y=0; y < (ssize_t) roi->height; y++)
3621 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3622 if (q == (Quantum *) NULL)
3624 for (x=0; x < (ssize_t) roi->width; x++)
3626 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3627 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3628 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3629 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3630 q+=(ptrdiff_t) GetPixelChannels(image);
3632 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3635 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3637 if (LocaleCompare(map,
"RGBP") == 0)
3639 for (y=0; y < (ssize_t) roi->height; y++)
3641 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3642 if (q == (Quantum *) NULL)
3644 for (x=0; x < (ssize_t) roi->width; x++)
3646 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3647 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3648 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3650 q+=(ptrdiff_t) GetPixelChannels(image);
3652 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3655 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3658 for (y=0; y < (ssize_t) roi->height; y++)
3660 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3661 if (q == (Quantum *) NULL)
3663 for (x=0; x < (ssize_t) roi->width; x++)
3668 for (i=0; i < (ssize_t) length; i++)
3670 switch (quantum_map[i])
3675 SetPixelRed(image,ScaleLongLongToQuantum(*p),q);
3679 case MagentaQuantum:
3681 SetPixelGreen(image,ScaleLongLongToQuantum(*p),q);
3687 SetPixelBlue(image,ScaleLongLongToQuantum(*p),q);
3692 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3695 case OpacityQuantum:
3697 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3702 SetPixelBlack(image,ScaleLongLongToQuantum(*p),q);
3707 SetPixelGray(image,ScaleLongLongToQuantum(*p),q);
3715 q+=(ptrdiff_t) GetPixelChannels(image);
3717 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3720 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3723static MagickBooleanType ImportQuantumPixel(Image *image,
3724 const RectangleInfo *roi,
const char *magick_restrict map,
3725 const QuantumType *quantum_map,
const void *pixels,ExceptionInfo *exception)
3742 p=(
const Quantum *) pixels;
3743 if (LocaleCompare(map,
"BGR") == 0)
3745 for (y=0; y < (ssize_t) roi->height; y++)
3747 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3748 if (q == (Quantum *) NULL)
3750 for (x=0; x < (ssize_t) roi->width; x++)
3752 SetPixelBlue(image,*p++,q);
3753 SetPixelGreen(image,*p++,q);
3754 SetPixelRed(image,*p++,q);
3755 q+=(ptrdiff_t) GetPixelChannels(image);
3757 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3760 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3762 if (LocaleCompare(map,
"BGRA") == 0)
3764 for (y=0; y < (ssize_t) roi->height; y++)
3766 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3767 if (q == (Quantum *) NULL)
3769 for (x=0; x < (ssize_t) roi->width; x++)
3771 SetPixelBlue(image,*p++,q);
3772 SetPixelGreen(image,*p++,q);
3773 SetPixelRed(image,*p++,q);
3774 SetPixelAlpha(image,*p++,q);
3775 q+=(ptrdiff_t) GetPixelChannels(image);
3777 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3780 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3782 if (LocaleCompare(map,
"BGRP") == 0)
3784 for (y=0; y < (ssize_t) roi->height; y++)
3786 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3787 if (q == (Quantum *) NULL)
3789 for (x=0; x < (ssize_t) roi->width; x++)
3791 SetPixelBlue(image,*p++,q);
3792 SetPixelGreen(image,*p++,q);
3793 SetPixelRed(image,*p++,q);
3795 q+=(ptrdiff_t) GetPixelChannels(image);
3797 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3800 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3802 if (LocaleCompare(map,
"I") == 0)
3804 for (y=0; y < (ssize_t) roi->height; y++)
3806 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3807 if (q == (Quantum *) NULL)
3809 for (x=0; x < (ssize_t) roi->width; x++)
3811 SetPixelGray(image,*p++,q);
3812 q+=(ptrdiff_t) GetPixelChannels(image);
3814 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3817 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3819 if (LocaleCompare(map,
"RGB") == 0)
3821 for (y=0; y < (ssize_t) roi->height; y++)
3823 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3824 if (q == (Quantum *) NULL)
3826 for (x=0; x < (ssize_t) roi->width; x++)
3828 SetPixelRed(image,*p++,q);
3829 SetPixelGreen(image,*p++,q);
3830 SetPixelBlue(image,*p++,q);
3831 q+=(ptrdiff_t) GetPixelChannels(image);
3833 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3836 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3838 if (LocaleCompare(map,
"RGBA") == 0)
3840 for (y=0; y < (ssize_t) roi->height; y++)
3842 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3843 if (q == (Quantum *) NULL)
3845 for (x=0; x < (ssize_t) roi->width; x++)
3847 SetPixelRed(image,*p++,q);
3848 SetPixelGreen(image,*p++,q);
3849 SetPixelBlue(image,*p++,q);
3850 SetPixelAlpha(image,*p++,q);
3851 q+=(ptrdiff_t) GetPixelChannels(image);
3853 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3856 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3858 if (LocaleCompare(map,
"RGBP") == 0)
3860 for (y=0; y < (ssize_t) roi->height; y++)
3862 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3863 if (q == (Quantum *) NULL)
3865 for (x=0; x < (ssize_t) roi->width; x++)
3867 SetPixelRed(image,*p++,q);
3868 SetPixelGreen(image,*p++,q);
3869 SetPixelBlue(image,*p++,q);
3871 q+=(ptrdiff_t) GetPixelChannels(image);
3873 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3876 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3879 for (y=0; y < (ssize_t) roi->height; y++)
3881 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3882 if (q == (Quantum *) NULL)
3884 for (x=0; x < (ssize_t) roi->width; x++)
3889 for (i=0; i < (ssize_t) length; i++)
3891 switch (quantum_map[i])
3896 SetPixelRed(image,*p,q);
3900 case MagentaQuantum:
3902 SetPixelGreen(image,*p,q);
3908 SetPixelBlue(image,*p,q);
3913 SetPixelAlpha(image,*p,q);
3916 case OpacityQuantum:
3918 SetPixelAlpha(image,*p,q);
3923 SetPixelBlack(image,*p,q);
3928 SetPixelGray(image,*p,q);
3936 q+=(ptrdiff_t) GetPixelChannels(image);
3938 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3941 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3944static MagickBooleanType ImportShortPixel(Image *image,
const RectangleInfo *roi,
3945 const char *magick_restrict map,
const QuantumType *quantum_map,
3946 const void *pixels,ExceptionInfo *exception)
3948 const unsigned short
3963 p=(
const unsigned short *) pixels;
3964 if (LocaleCompare(map,
"BGR") == 0)
3966 for (y=0; y < (ssize_t) roi->height; y++)
3968 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3969 if (q == (Quantum *) NULL)
3971 for (x=0; x < (ssize_t) roi->width; x++)
3973 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3974 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3975 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3976 q+=(ptrdiff_t) GetPixelChannels(image);
3978 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3981 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3983 if (LocaleCompare(map,
"BGRA") == 0)
3985 for (y=0; y < (ssize_t) roi->height; y++)
3987 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3988 if (q == (Quantum *) NULL)
3990 for (x=0; x < (ssize_t) roi->width; x++)
3992 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3993 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3994 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3995 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3996 q+=(ptrdiff_t) GetPixelChannels(image);
3998 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4001 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4003 if (LocaleCompare(map,
"BGRP") == 0)
4005 for (y=0; y < (ssize_t) roi->height; y++)
4007 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4008 if (q == (Quantum *) NULL)
4010 for (x=0; x < (ssize_t) roi->width; x++)
4012 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4013 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4014 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4016 q+=(ptrdiff_t) GetPixelChannels(image);
4018 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4021 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4023 if (LocaleCompare(map,
"I") == 0)
4025 for (y=0; y < (ssize_t) roi->height; y++)
4027 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4028 if (q == (Quantum *) NULL)
4030 for (x=0; x < (ssize_t) roi->width; x++)
4032 SetPixelGray(image,ScaleShortToQuantum(*p++),q);
4033 q+=(ptrdiff_t) GetPixelChannels(image);
4035 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4038 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4040 if (LocaleCompare(map,
"RGB") == 0)
4042 for (y=0; y < (ssize_t) roi->height; y++)
4044 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4045 if (q == (Quantum *) NULL)
4047 for (x=0; x < (ssize_t) roi->width; x++)
4049 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4050 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4051 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4052 q+=(ptrdiff_t) GetPixelChannels(image);
4054 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4057 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4059 if (LocaleCompare(map,
"RGBA") == 0)
4061 for (y=0; y < (ssize_t) roi->height; y++)
4063 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4064 if (q == (Quantum *) NULL)
4066 for (x=0; x < (ssize_t) roi->width; x++)
4068 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4069 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4070 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4071 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
4072 q+=(ptrdiff_t) GetPixelChannels(image);
4074 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4077 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4079 if (LocaleCompare(map,
"RGBP") == 0)
4081 for (y=0; y < (ssize_t) roi->height; y++)
4083 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4084 if (q == (Quantum *) NULL)
4086 for (x=0; x < (ssize_t) roi->width; x++)
4088 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4089 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4090 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4092 q+=(ptrdiff_t) GetPixelChannels(image);
4094 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4097 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4100 for (y=0; y < (ssize_t) roi->height; y++)
4102 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4103 if (q == (Quantum *) NULL)
4105 for (x=0; x < (ssize_t) roi->width; x++)
4110 for (i=0; i < (ssize_t) length; i++)
4112 switch (quantum_map[i])
4117 SetPixelRed(image,ScaleShortToQuantum(*p),q);
4121 case MagentaQuantum:
4123 SetPixelGreen(image,ScaleShortToQuantum(*p),q);
4129 SetPixelBlue(image,ScaleShortToQuantum(*p),q);
4134 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
4137 case OpacityQuantum:
4139 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
4144 SetPixelBlack(image,ScaleShortToQuantum(*p),q);
4149 SetPixelGray(image,ScaleShortToQuantum(*p),q);
4157 q+=(ptrdiff_t) GetPixelChannels(image);
4159 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4162 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4165MagickExport MagickBooleanType ImportImagePixels(Image *image,
const ssize_t x,
4166 const ssize_t y,
const size_t width,
const size_t height,
const char *map,
4167 const StorageType type,
const void *pixels,ExceptionInfo *exception)
4187 assert(image != (Image *) NULL);
4188 assert(image->signature == MagickCoreSignature);
4189 if (IsEventLogging() != MagickFalse)
4190 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4192 quantum_map=(QuantumType *) AcquireQuantumMemory(length,
sizeof(*quantum_map));
4193 if (quantum_map == (QuantumType *) NULL)
4194 ThrowBinaryException(ResourceLimitError,
"MemoryAllocationFailed",
4196 for (i=0; i < (ssize_t) length; i++)
4203 quantum_map[i]=AlphaQuantum;
4204 image->alpha_trait=BlendPixelTrait;
4210 quantum_map[i]=BlueQuantum;
4216 quantum_map[i]=CyanQuantum;
4217 (void) SetImageColorspace(image,CMYKColorspace,exception);
4223 quantum_map[i]=GreenQuantum;
4229 quantum_map[i]=BlackQuantum;
4230 (void) SetImageColorspace(image,CMYKColorspace,exception);
4236 quantum_map[i]=IndexQuantum;
4237 (void) SetImageColorspace(image,GRAYColorspace,exception);
4243 quantum_map[i]=MagentaQuantum;
4244 (void) SetImageColorspace(image,CMYKColorspace,exception);
4250 quantum_map[i]=OpacityQuantum;
4251 image->alpha_trait=BlendPixelTrait;
4257 quantum_map[i]=UndefinedQuantum;
4263 quantum_map[i]=RedQuantum;
4269 quantum_map[i]=YellowQuantum;
4270 (void) SetImageColorspace(image,CMYKColorspace,exception);
4275 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4276 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4277 "UnrecognizedPixelMap",
"`%s'",map);
4278 return(MagickFalse);
4282 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
4283 return(MagickFalse);
4295 status=ImportCharPixel(image,&roi,map,quantum_map,pixels,exception);
4300 status=ImportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
4305 status=ImportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
4310 status=ImportLongPixel(image,&roi,map,quantum_map,pixels,exception);
4315 status=ImportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
4320 status=ImportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
4325 status=ImportShortPixel(image,&roi,map,quantum_map,pixels,exception);
4330 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4331 "UnrecognizedStorageType",
"`%d'",type);
4335 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4381static inline void CatromWeights(
const double x,
double (*weights)[4])
4395 alpha=(double) 1.0-x;
4396 beta=(double) (-0.5)*x*alpha;
4397 (*weights)[0]=alpha*beta;
4398 (*weights)[3]=x*beta;
4403 gamma=(*weights)[3]-(*weights)[0];
4404 (*weights)[1]=alpha-(*weights)[0]+gamma;
4405 (*weights)[2]=x-(*weights)[3]-gamma;
4408static inline void SplineWeights(
const double x,
double (*weights)[4])
4420 alpha=(double) 1.0-x;
4421 (*weights)[3]=(double) (1.0/6.0)*x*x*x;
4422 (*weights)[0]=(double) (1.0/6.0)*alpha*alpha*alpha;
4423 beta=(*weights)[3]-(*weights)[0];
4424 (*weights)[1]=alpha-(*weights)[0]+beta;
4425 (*weights)[2]=x-(*weights)[3]-beta;
4428static inline double MeshInterpolate(
const PointInfo *delta,
const double p,
4429 const double x,
const double y)
4431 return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
4434MagickExport MagickBooleanType InterpolatePixelChannel(
4435 const Image *magick_restrict image,
const CacheView_ *image_view,
4436 const PixelChannel channel,
const PixelInterpolateMethod method,
const double x,
4437 const double y,
double *pixel,ExceptionInfo *exception)
4450 PixelInterpolateMethod
4461 assert(image != (Image *) NULL);
4462 assert(image->signature == MagickCoreSignature);
4463 assert(image_view != (CacheView *) NULL);
4465 if ((channel < 0) || (channel >= MaxPixelChannels))
4466 ThrowBinaryException(OptionError,
"NoSuchImageChannel",image->filename);
4467 traits=GetPixelChannelTraits(image,channel);
4468 x_offset=CastDoubleToSsizeT(floor(x));
4469 y_offset=CastDoubleToSsizeT(floor(y));
4471 if (interpolate == UndefinedInterpolatePixel)
4472 interpolate=image->interpolate;
4474 switch (interpolate)
4476 case AverageInterpolatePixel:
4477 case Average9InterpolatePixel:
4478 case Average16InterpolatePixel:
4484 if (interpolate == Average9InterpolatePixel)
4487 x_offset=CastDoubleToSsizeT(floor(x+0.5)-1.0);
4488 y_offset=CastDoubleToSsizeT(floor(y+0.5)-1.0);
4491 if (interpolate == Average16InterpolatePixel)
4497 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,(
size_t) count,
4498 (
size_t) count,exception);
4499 if (p == (
const Quantum *) NULL)
4505 if ((traits & BlendPixelTrait) == 0)
4506 for (i=0; i < (ssize_t) count; i++)
4509 pixels[i]=(double) p[i*(ssize_t) GetPixelChannels(image)+
4510 GetPixelChannelOffset(image,channel)];
4513 for (i=0; i < (ssize_t) count; i++)
4515 alpha[i]=QuantumScale*(double) GetPixelAlpha(image,p+i*
4516 (ssize_t) GetPixelChannels(image));
4517 pixels[i]=alpha[i]*(double) p[i*(ssize_t) GetPixelChannels(image)+
4518 GetPixelChannelOffset(image,channel)];
4520 for (i=0; i < (ssize_t) count; i++)
4522 gamma=MagickSafeReciprocal(alpha[i])/count;
4523 *pixel+=gamma*pixels[i];
4527 case BilinearInterpolatePixel:
4534 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4535 if (p == (
const Quantum *) NULL)
4540 if ((traits & BlendPixelTrait) == 0)
4541 for (i=0; i < 4; i++)
4544 pixels[i]=(double) p[i*(ssize_t) GetPixelChannels(image)+
4545 GetPixelChannelOffset(image,channel)];
4548 for (i=0; i < 4; i++)
4550 alpha[i]=QuantumScale*(double) GetPixelAlpha(image,p+i*
4551 (ssize_t) GetPixelChannels(image));
4552 pixels[i]=alpha[i]*(double) p[i*(ssize_t) GetPixelChannels(image)+
4553 GetPixelChannelOffset(image,channel)];
4557 epsilon.x=1.0-delta.x;
4558 epsilon.y=1.0-delta.y;
4559 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4560 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4561 gamma=MagickSafeReciprocal(gamma);
4562 *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
4563 (epsilon.x*pixels[2]+delta.x*pixels[3]));
4566 case BlendInterpolatePixel:
4568 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4569 if (p == (
const Quantum *) NULL)
4574 if ((traits & BlendPixelTrait) == 0)
4575 for (i=0; i < 4; i++)
4578 pixels[i]=(MagickRealType) p[i*(ssize_t) GetPixelChannels(image)+
4579 GetPixelChannelOffset(image,channel)];
4582 for (i=0; i < 4; i++)
4584 alpha[i]=QuantumScale*(double) GetPixelAlpha(image,p+i*
4585 (ssize_t) GetPixelChannels(image));
4586 pixels[i]=alpha[i]*(double) p[i*(ssize_t) GetPixelChannels(image)+
4587 GetPixelChannelOffset(image,channel)];
4590 for (i=0; i <= 1L; i++) {
4591 if ((y-y_offset) >= 0.75)
4593 alpha[i]=alpha[i+2];
4594 pixels[i]=pixels[i+2];
4597 if ((y-y_offset) > 0.25)
4600 alpha[i]+=alpha[i+2];
4601 pixels[i]+=pixels[i+2];
4604 if ((x-x_offset) >= 0.75)
4607 pixels[0]=pixels[1];
4610 if ((x-x_offset) > 0.25)
4614 pixels[0]+=pixels[1];
4616 if (channel != AlphaPixelChannel)
4617 gamma=MagickSafeReciprocal(alpha[0]);
4619 gamma=MagickSafeReciprocal(gamma);
4620 *pixel=gamma*pixels[0];
4623 case CatromInterpolatePixel:
4629 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4631 if (p == (
const Quantum *) NULL)
4636 if ((traits & BlendPixelTrait) == 0)
4637 for (i=0; i < 16; i++)
4640 pixels[i]=(double) p[i*(ssize_t) GetPixelChannels(image)+
4641 GetPixelChannelOffset(image,channel)];
4644 for (i=0; i < 16; i++)
4646 alpha[i]=QuantumScale*(double) GetPixelAlpha(image,p+i*
4647 (ssize_t) GetPixelChannels(image));
4648 pixels[i]=alpha[i]*(double) p[i*(ssize_t) GetPixelChannels(image)+
4649 GetPixelChannelOffset(image,channel)];
4651 CatromWeights((
double) (x-x_offset),&cx);
4652 CatromWeights((
double) (y-y_offset),&cy);
4653 gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4654 MagickSafeReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4655 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4656 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4657 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4658 cx[2]*alpha[14]+cx[3]*alpha[15])));
4659 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4660 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4661 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4662 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4663 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4666 case IntegerInterpolatePixel:
4668 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4669 if (p == (
const Quantum *) NULL)
4674 *pixel=(double) GetPixelChannel(image,channel,p);
4677 case NearestInterpolatePixel:
4679 x_offset=CastDoubleToSsizeT(floor(x+0.5));
4680 y_offset=CastDoubleToSsizeT(floor(y+0.5));
4681 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4682 if (p == (
const Quantum *) NULL)
4687 *pixel=(double) GetPixelChannel(image,channel,p);
4690 case MeshInterpolatePixel:
4696 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4697 if (p == (
const Quantum *) NULL)
4702 if ((traits & BlendPixelTrait) == 0)
4703 for (i=0; i < 4; i++)
4706 pixels[i]=(double) p[i*(ssize_t) GetPixelChannels(image)+
4707 GetPixelChannelOffset(image,channel)];
4710 for (i=0; i < 4; i++)
4712 alpha[i]=QuantumScale*(double) GetPixelAlpha(image,p+i*
4713 (ssize_t) GetPixelChannels(image));
4714 pixels[i]=alpha[i]*(double) p[i*(ssize_t) GetPixelChannels(image)+
4715 GetPixelChannelOffset(image,channel)];
4719 luminance.x=GetPixelLuma(image,p)-(double)
4720 GetPixelLuma(image,p+3*GetPixelChannels(image));
4721 luminance.y=GetPixelLuma(image,p+GetPixelChannels(image))-(double)
4722 GetPixelLuma(image,p+2*GetPixelChannels(image));
4723 if (fabs((
double) luminance.x) < fabs((
double) luminance.y))
4728 if (delta.x <= delta.y)
4733 delta.y=1.0-delta.y;
4734 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4735 gamma=MagickSafeReciprocal(gamma);
4736 *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
4744 delta.x=1.0-delta.x;
4745 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4746 gamma=MagickSafeReciprocal(gamma);
4747 *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
4756 if (delta.x <= (1.0-delta.y))
4761 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4762 gamma=MagickSafeReciprocal(gamma);
4763 *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
4771 delta.x=1.0-delta.x;
4772 delta.y=1.0-delta.y;
4773 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4774 gamma=MagickSafeReciprocal(gamma);
4775 *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
4781 case SplineInterpolatePixel:
4787 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4789 if (p == (
const Quantum *) NULL)
4794 if ((traits & BlendPixelTrait) == 0)
4795 for (i=0; i < 16; i++)
4798 pixels[i]=(double) p[i*(ssize_t) GetPixelChannels(image)+
4799 GetPixelChannelOffset(image,channel)];
4802 for (i=0; i < 16; i++)
4804 alpha[i]=QuantumScale*(double) GetPixelAlpha(image,p+i*
4805 (ssize_t) GetPixelChannels(image));
4806 pixels[i]=alpha[i]*(double) p[i*(ssize_t) GetPixelChannels(image)+
4807 GetPixelChannelOffset(image,channel)];
4809 SplineWeights((
double) (x-x_offset),&cx);
4810 SplineWeights((
double) (y-y_offset),&cy);
4811 gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4812 MagickSafeReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4813 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4814 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4815 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4816 cx[2]*alpha[14]+cx[3]*alpha[15])));
4817 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4818 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4819 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4820 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4821 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4871MagickExport MagickBooleanType InterpolatePixelChannels(
4872 const Image *magick_restrict source,
const CacheView_ *source_view,
4873 const Image *magick_restrict destination,
const PixelInterpolateMethod method,
4874 const double x,
const double y,Quantum *pixel,ExceptionInfo *exception)
4894 PixelInterpolateMethod
4897 assert(source != (Image *) NULL);
4898 assert(source->signature == MagickCoreSignature);
4899 assert(source_view != (CacheView *) NULL);
4901 x_offset=CastDoubleToSsizeT(floor(x));
4902 y_offset=CastDoubleToSsizeT(floor(y));
4904 if (interpolate == UndefinedInterpolatePixel)
4905 interpolate=source->interpolate;
4906 switch (interpolate)
4908 case AverageInterpolatePixel:
4909 case Average9InterpolatePixel:
4910 case Average16InterpolatePixel:
4916 if (interpolate == Average9InterpolatePixel)
4919 x_offset=CastDoubleToSsizeT(floor(x+0.5)-1.0);
4920 y_offset=CastDoubleToSsizeT(floor(y+0.5)-1.0);
4923 if (interpolate == Average16InterpolatePixel)
4929 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,(
size_t) count,
4930 (
size_t) count,exception);
4931 if (p == (
const Quantum *) NULL)
4937 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4945 PixelChannel channel = GetPixelChannelChannel(source,i);
4946 PixelTrait traits = GetPixelChannelTraits(source,channel);
4947 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4949 if ((traits == UndefinedPixelTrait) ||
4950 (destination_traits == UndefinedPixelTrait))
4952 for (j=0; j < (ssize_t) count; j++)
4953 pixels[j]=(
double) p[j*(ssize_t) GetPixelChannels(source)+i];
4955 if ((traits & BlendPixelTrait) == 0)
4957 for (j=0; j < (ssize_t) count; j++)
4960 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4963 for (j=0; j < (ssize_t) count; j++)
4965 alpha[j]=QuantumScale*(double) GetPixelAlpha(source,p+j*
4966 (ssize_t) GetPixelChannels(source));
4967 pixels[j]*=alpha[j];
4968 gamma=MagickSafeReciprocal(alpha[j]);
4969 sum+=gamma*pixels[j];
4972 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4976 case BilinearInterpolatePixel:
4979 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4980 if (p == (
const Quantum *) NULL)
4985 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4991 PixelChannel channel = GetPixelChannelChannel(source,i);
4992 PixelTrait traits = GetPixelChannelTraits(source,channel);
4993 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4995 if ((traits == UndefinedPixelTrait) ||
4996 (destination_traits == UndefinedPixelTrait))
5000 epsilon.x=1.0-delta.x;
5001 epsilon.y=1.0-delta.y;
5002 pixels[0]=(double) p[i];
5003 pixels[1]=(double) p[(ssize_t) GetPixelChannels(source)+i];
5004 pixels[2]=(double) p[2*(ssize_t) GetPixelChannels(source)+i];
5005 pixels[3]=(double) p[3*(ssize_t) GetPixelChannels(source)+i];
5006 if ((traits & BlendPixelTrait) == 0)
5008 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5009 gamma=MagickSafeReciprocal(gamma);
5010 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
5011 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*
5012 pixels[2]+delta.x*pixels[3]))),pixel);
5015 alpha[0]=QuantumScale*(double) GetPixelAlpha(source,p);
5016 alpha[1]=QuantumScale*(double) GetPixelAlpha(source,p+
5017 GetPixelChannels(source));
5018 alpha[2]=QuantumScale*(double) GetPixelAlpha(source,p+2*
5019 GetPixelChannels(source));
5020 alpha[3]=QuantumScale*(double) GetPixelAlpha(source,p+3*
5021 GetPixelChannels(source));
5022 pixels[0]*=alpha[0];
5023 pixels[1]*=alpha[1];
5024 pixels[2]*=alpha[2];
5025 pixels[3]*=alpha[3];
5026 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5027 (epsilon.x*alpha[2]+delta.x*alpha[3])));
5028 gamma=MagickSafeReciprocal(gamma);
5029 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
5030 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+
5031 delta.x*pixels[3]))),pixel);
5035 case BlendInterpolatePixel:
5037 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
5038 if (p == (
const Quantum *) NULL)
5043 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5048 PixelChannel channel = GetPixelChannelChannel(source,i);
5049 PixelTrait traits = GetPixelChannelTraits(source,channel);
5050 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5052 if ((traits == UndefinedPixelTrait) ||
5053 (destination_traits == UndefinedPixelTrait))
5055 if (source->alpha_trait != BlendPixelTrait)
5056 for (j=0; j < 4; j++)
5059 pixels[j]=(double) p[j*(ssize_t) GetPixelChannels(source)+i];
5062 for (j=0; j < 4; j++)
5064 alpha[j]=QuantumScale*(double) GetPixelAlpha(source,p+j*
5065 (ssize_t) GetPixelChannels(source));
5066 pixels[j]=(double) p[j*(ssize_t) GetPixelChannels(source)+i];
5067 if (channel != AlphaPixelChannel)
5068 pixels[j]*=alpha[j];
5071 for (j=0; j <= 1L; j++)
5073 if ((y-y_offset) >= 0.75)
5075 alpha[j]=alpha[j+2];
5076 pixels[j]=pixels[j+2];
5079 if ((y-y_offset) > 0.25)
5082 alpha[j]+=alpha[j+2];
5083 pixels[j]+=pixels[j+2];
5086 if ((x-x_offset) >= 0.75)
5089 pixels[0]=pixels[1];
5092 if ((x-x_offset) > 0.25)
5096 pixels[0]+=pixels[1];
5098 if (channel != AlphaPixelChannel)
5099 gamma=MagickSafeReciprocal(alpha[0]);
5101 gamma=MagickSafeReciprocal(gamma);
5102 SetPixelChannel(destination,channel,ClampToQuantum(gamma*pixels[0]),
5107 case CatromInterpolatePixel:
5113 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
5115 if (p == (
const Quantum *) NULL)
5120 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5125 PixelChannel channel = GetPixelChannelChannel(source,i);
5126 PixelTrait traits = GetPixelChannelTraits(source,channel);
5127 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5129 if ((traits == UndefinedPixelTrait) ||
5130 (destination_traits == UndefinedPixelTrait))
5132 if ((traits & BlendPixelTrait) == 0)
5133 for (j=0; j < 16; j++)
5136 pixels[j]=(double) p[j*(ssize_t) GetPixelChannels(source)+i];
5139 for (j=0; j < 16; j++)
5141 alpha[j]=QuantumScale*(double) GetPixelAlpha(source,p+j*
5142 (ssize_t) GetPixelChannels(source));
5143 pixels[j]=alpha[j]*(double)
5144 p[j*(ssize_t) GetPixelChannels(source)+i];
5146 CatromWeights((
double) (x-x_offset),&cx);
5147 CatromWeights((
double) (y-y_offset),&cy);
5148 gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
5149 MagickSafeReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
5150 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
5151 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
5152 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
5153 cx[2]*alpha[14]+cx[3]*alpha[15])));
5154 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
5155 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
5156 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
5157 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
5158 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
5159 pixels[14]+cx[3]*pixels[15]))),pixel);
5163 case IntegerInterpolatePixel:
5165 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
5166 if (p == (
const Quantum *) NULL)
5171 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5173 PixelChannel channel = GetPixelChannelChannel(source,i);
5174 PixelTrait traits = GetPixelChannelTraits(source,channel);
5175 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5177 if ((traits == UndefinedPixelTrait) ||
5178 (destination_traits == UndefinedPixelTrait))
5180 SetPixelChannel(destination,channel,p[i],pixel);
5184 case NearestInterpolatePixel:
5186 x_offset=CastDoubleToSsizeT(floor(x+0.5));
5187 y_offset=CastDoubleToSsizeT(floor(y+0.5));
5188 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
5189 if (p == (
const Quantum *) NULL)
5194 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5196 PixelChannel channel = GetPixelChannelChannel(source,i);
5197 PixelTrait traits = GetPixelChannelTraits(source,channel);
5198 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5200 if ((traits == UndefinedPixelTrait) ||
5201 (destination_traits == UndefinedPixelTrait))
5203 SetPixelChannel(destination,channel,p[i],pixel);
5207 case MeshInterpolatePixel:
5209 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
5210 if (p == (
const Quantum *) NULL)
5215 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5221 PixelChannel channel = GetPixelChannelChannel(source,i);
5222 PixelTrait traits = GetPixelChannelTraits(source,channel);
5223 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5225 if ((traits == UndefinedPixelTrait) ||
5226 (destination_traits == UndefinedPixelTrait))
5228 pixels[0]=(double) p[i];
5229 pixels[1]=(double) p[(ssize_t) GetPixelChannels(source)+i];
5230 pixels[2]=(double) p[2*(ssize_t) GetPixelChannels(source)+i];
5231 pixels[3]=(double) p[3*(ssize_t) GetPixelChannels(source)+i];
5232 if ((traits & BlendPixelTrait) == 0)
5241 alpha[0]=QuantumScale*(double) GetPixelAlpha(source,p);
5242 alpha[1]=QuantumScale*(double) GetPixelAlpha(source,p+
5243 GetPixelChannels(source));
5244 alpha[2]=QuantumScale*(double) GetPixelAlpha(source,p+2*
5245 GetPixelChannels(source));
5246 alpha[3]=QuantumScale*(double) GetPixelAlpha(source,p+3*
5247 GetPixelChannels(source));
5251 luminance.x=fabs((
double) (GetPixelLuma(source,p)-
5252 GetPixelLuma(source,p+3*GetPixelChannels(source))));
5253 luminance.y=fabs((
double) (GetPixelLuma(source,p+
5254 GetPixelChannels(source))-GetPixelLuma(source,p+2*
5255 GetPixelChannels(source))));
5256 if (luminance.x < luminance.y)
5261 if (delta.x <= delta.y)
5266 delta.y=1.0-delta.y;
5267 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5268 gamma=MagickSafeReciprocal(gamma);
5269 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5270 MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel);
5277 delta.x=1.0-delta.x;
5278 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5279 gamma=MagickSafeReciprocal(gamma);
5280 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5281 MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel);
5289 if (delta.x <= (1.0-delta.y))
5294 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5295 gamma=MagickSafeReciprocal(gamma);
5296 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5297 MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel);
5304 delta.x=1.0-delta.x;
5305 delta.y=1.0-delta.y;
5306 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5307 gamma=MagickSafeReciprocal(gamma);
5308 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5309 MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel);
5315 case SplineInterpolatePixel:
5321 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
5323 if (p == (
const Quantum *) NULL)
5328 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5333 PixelChannel channel = GetPixelChannelChannel(source,i);
5334 PixelTrait traits = GetPixelChannelTraits(source,channel);
5335 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5337 if ((traits == UndefinedPixelTrait) ||
5338 (destination_traits == UndefinedPixelTrait))
5340 if ((traits & BlendPixelTrait) == 0)
5341 for (j=0; j < 16; j++)
5344 pixels[j]=(double) p[j*(ssize_t) GetPixelChannels(source)+i];
5347 for (j=0; j < 16; j++)
5349 alpha[j]=QuantumScale*(double) GetPixelAlpha(source,p+j*
5350 (ssize_t) GetPixelChannels(source));
5351 pixels[j]=alpha[j]*(double) p[j*(ssize_t) GetPixelChannels(source)+
5354 SplineWeights((
double) (x-x_offset),&cx);
5355 SplineWeights((
double) (y-y_offset),&cy);
5356 gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
5357 MagickSafeReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
5358 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
5359 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
5360 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
5361 cx[2]*alpha[14]+cx[3]*alpha[15])));
5362 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
5363 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
5364 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
5365 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
5366 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
5367 pixels[14]+cx[3]*pixels[15]))),pixel);
5415static inline void AlphaBlendPixelInfo(
const Image *image,
5416 const Quantum *pixel,PixelInfo *pixel_info,
double *alpha)
5418 if ((image->alpha_trait & BlendPixelTrait) == 0)
5421 pixel_info->red=(double) GetPixelRed(image,pixel);
5422 pixel_info->green=(double) GetPixelGreen(image,pixel);
5423 pixel_info->blue=(double) GetPixelBlue(image,pixel);
5424 pixel_info->black=0.0;
5425 if (image->colorspace == CMYKColorspace)
5426 pixel_info->black=(double) GetPixelBlack(image,pixel);
5427 pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5430 *alpha=QuantumScale*(double) GetPixelAlpha(image,pixel);
5431 pixel_info->red=(*alpha*(double) GetPixelRed(image,pixel));
5432 pixel_info->green=(*alpha*(double) GetPixelGreen(image,pixel));
5433 pixel_info->blue=(*alpha*(double) GetPixelBlue(image,pixel));
5434 pixel_info->black=0.0;
5435 if (image->colorspace == CMYKColorspace)
5436 pixel_info->black=(*alpha*(double) GetPixelBlack(image,pixel));
5437 pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5440MagickExport MagickBooleanType InterpolatePixelInfo(
const Image *image,
5441 const CacheView_ *image_view,
const PixelInterpolateMethod method,
5442 const double x,
const double y,PixelInfo *pixel,ExceptionInfo *exception)
5457 PixelInterpolateMethod
5465 assert(image != (Image *) NULL);
5466 assert(image->signature == MagickCoreSignature);
5467 assert(image_view != (CacheView *) NULL);
5469 x_offset=CastDoubleToSsizeT(floor(x));
5470 y_offset=CastDoubleToSsizeT(floor(y));
5472 if (interpolate == UndefinedInterpolatePixel)
5473 interpolate=image->interpolate;
5474 GetPixelInfoPixel(image,(
const Quantum *) NULL,pixel);
5475 (void) memset(&pixels,0,
sizeof(pixels));
5476 switch (interpolate)
5478 case AverageInterpolatePixel:
5479 case Average9InterpolatePixel:
5480 case Average16InterpolatePixel:
5486 if (interpolate == Average9InterpolatePixel)
5489 x_offset=CastDoubleToSsizeT(floor(x+0.5)-1.0);
5490 y_offset=CastDoubleToSsizeT(floor(y+0.5)-1.0);
5493 if (interpolate == Average16InterpolatePixel)
5499 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,(
size_t) count,
5500 (
size_t) count,exception);
5501 if (p == (
const Quantum *) NULL)
5512 for (i=0; i < (ssize_t) count; i++)
5514 AlphaBlendPixelInfo(image,p,pixels,alpha);
5515 gamma=MagickSafeReciprocal(alpha[0]);
5516 pixel->red+=gamma*pixels[0].red;
5517 pixel->green+=gamma*pixels[0].green;
5518 pixel->blue+=gamma*pixels[0].blue;
5519 pixel->black+=gamma*pixels[0].black;
5520 pixel->alpha+=pixels[0].alpha;
5521 p+=(ptrdiff_t) GetPixelChannels(image);
5525 pixel->green*=gamma;
5527 pixel->black*=gamma;
5528 pixel->alpha*=gamma;
5531 case BackgroundInterpolatePixel:
5533 *pixel=image->background_color;
5536 case BilinearInterpolatePixel:
5543 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5544 if (p == (
const Quantum *) NULL)
5549 for (i=0; i < 4L; i++)
5550 AlphaBlendPixelInfo(image,p+i*(ssize_t) GetPixelChannels(image),
5554 epsilon.x=1.0-delta.x;
5555 epsilon.y=1.0-delta.y;
5556 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5557 (epsilon.x*alpha[2]+delta.x*alpha[3])));
5558 gamma=MagickSafeReciprocal(gamma);
5559 pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
5560 pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red));
5561 pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x*
5562 pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x*
5564 pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x*
5565 pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x*
5567 if (image->colorspace == CMYKColorspace)
5568 pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x*
5569 pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x*
5571 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5572 gamma=MagickSafeReciprocal(gamma);
5573 pixel->alpha=gamma*(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x*
5574 pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x*
5578 case BlendInterpolatePixel:
5580 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5581 if (p == (
const Quantum *) NULL)
5586 for (i=0; i < 4L; i++)
5588 GetPixelInfoPixel(image,p+i*(ssize_t) GetPixelChannels(image),pixels+i);
5589 AlphaBlendPixelInfo(image,p+i*(ssize_t) GetPixelChannels(image),
5593 for (i=0; i <= 1L; i++)
5595 if ((y-y_offset) >= 0.75)
5597 alpha[i]=alpha[i+2];
5598 pixels[i]=pixels[i+2];
5601 if ((y-y_offset) > 0.25)
5604 alpha[i]+=alpha[i+2];
5605 pixels[i].red+=pixels[i+2].red;
5606 pixels[i].green+=pixels[i+2].green;
5607 pixels[i].blue+=pixels[i+2].blue;
5608 pixels[i].black+=pixels[i+2].black;
5609 pixels[i].alpha+=pixels[i+2].alpha;
5612 if ((x-x_offset) >= 0.75)
5615 pixels[0]=pixels[1];
5618 if ((x-x_offset) > 0.25)
5621 alpha[0]+= alpha[1];
5622 pixels[0].red+=pixels[1].red;
5623 pixels[0].green+=pixels[1].green;
5624 pixels[0].blue+=pixels[1].blue;
5625 pixels[0].black+=pixels[1].black;
5626 pixels[0].alpha+=pixels[1].alpha;
5629 alpha[0]=MagickSafeReciprocal(alpha[0]);
5630 pixel->red=alpha[0]*pixels[0].red;
5631 pixel->green=alpha[0]*pixels[0].green;
5632 pixel->blue=alpha[0]*pixels[0].blue;
5633 pixel->black=alpha[0]*pixels[0].black;
5634 pixel->alpha=gamma*pixels[0].alpha;
5637 case CatromInterpolatePixel:
5643 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5645 if (p == (
const Quantum *) NULL)
5650 for (i=0; i < 16L; i++)
5651 AlphaBlendPixelInfo(image,p+i*(ssize_t) GetPixelChannels(image),
5653 CatromWeights((
double) (x-x_offset),&cx);
5654 CatromWeights((
double) (y-y_offset),&cy);
5655 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]*
5656 pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5657 pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]*
5658 pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5659 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]*
5660 pixels[14].red+cx[3]*pixels[15].red));
5661 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]*
5662 pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+
5663 cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+
5664 cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]*
5665 pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]*
5666 pixels[12].green+cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]*
5668 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]*
5669 pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5670 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]*
5671 pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5672 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+
5673 cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5674 if (image->colorspace == CMYKColorspace)
5675 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]*
5676 pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+
5677 cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+
5678 cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]*
5679 pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]*
5680 pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]*
5682 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]*
5683 pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+
5684 cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+
5685 cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]*
5686 pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+
5687 cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5690 case IntegerInterpolatePixel:
5692 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5693 if (p == (
const Quantum *) NULL)
5698 GetPixelInfoPixel(image,p,pixel);
5701 case MeshInterpolatePixel:
5707 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5708 if (p == (
const Quantum *) NULL)
5715 luminance.x=GetPixelLuma(image,p)-(double)
5716 GetPixelLuma(image,p+3*GetPixelChannels(image));
5717 luminance.y=GetPixelLuma(image,p+GetPixelChannels(image))-(double)
5718 GetPixelLuma(image,p+2*GetPixelChannels(image));
5719 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5720 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5721 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5722 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5723 if (fabs((
double) luminance.x) < fabs((
double) luminance.y))
5728 if (delta.x <= delta.y)
5733 delta.y=1.0-delta.y;
5734 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5735 gamma=MagickSafeReciprocal(gamma);
5736 pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red,
5737 pixels[3].red,pixels[0].red);
5738 pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green,
5739 pixels[3].green,pixels[0].green);
5740 pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
5741 pixels[3].blue,pixels[0].blue);
5742 if (image->colorspace == CMYKColorspace)
5743 pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black,
5744 pixels[3].black,pixels[0].black);
5745 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5746 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha,
5747 pixels[3].alpha,pixels[0].alpha);
5754 delta.x=1.0-delta.x;
5755 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5756 gamma=MagickSafeReciprocal(gamma);
5757 pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red,
5758 pixels[0].red,pixels[3].red);
5759 pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green,
5760 pixels[0].green,pixels[3].green);
5761 pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
5762 pixels[0].blue,pixels[3].blue);
5763 if (image->colorspace == CMYKColorspace)
5764 pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black,
5765 pixels[0].black,pixels[3].black);
5766 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5767 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha,
5768 pixels[0].alpha,pixels[3].alpha);
5776 if (delta.x <= (1.0-delta.y))
5781 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5782 gamma=MagickSafeReciprocal(gamma);
5783 pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red,
5784 pixels[1].red,pixels[2].red);
5785 pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green,
5786 pixels[1].green,pixels[2].green);
5787 pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
5788 pixels[1].blue,pixels[2].blue);
5789 if (image->colorspace == CMYKColorspace)
5790 pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black,
5791 pixels[1].black,pixels[2].black);
5792 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5793 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha,
5794 pixels[1].alpha,pixels[2].alpha);
5801 delta.x=1.0-delta.x;
5802 delta.y=1.0-delta.y;
5803 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5804 gamma=MagickSafeReciprocal(gamma);
5805 pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red,
5806 pixels[2].red,pixels[1].red);
5807 pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green,
5808 pixels[2].green,pixels[1].green);
5809 pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
5810 pixels[2].blue,pixels[1].blue);
5811 if (image->colorspace == CMYKColorspace)
5812 pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black,
5813 pixels[2].black,pixels[1].black);
5814 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5815 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha,
5816 pixels[2].alpha,pixels[1].alpha);
5821 case NearestInterpolatePixel:
5823 x_offset=CastDoubleToSsizeT(floor(x+0.5));
5824 y_offset=CastDoubleToSsizeT(floor(y+0.5));
5825 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5826 if (p == (
const Quantum *) NULL)
5831 GetPixelInfoPixel(image,p,pixel);
5834 case SplineInterpolatePixel:
5840 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5842 if (p == (
const Quantum *) NULL)
5847 for (i=0; i < 16L; i++)
5848 AlphaBlendPixelInfo(image,p+i*(ssize_t) GetPixelChannels(image),
5850 SplineWeights((
double) (x-x_offset),&cx);
5851 SplineWeights((
double) (y-y_offset),&cy);
5852 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]*
5853 pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5854 pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]*
5855 pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5856 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]*
5857 pixels[14].red+cx[3]*pixels[15].red));
5858 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]*
5859 pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+
5860 cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+
5861 cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]*
5862 pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]*pixels[12].green+
5863 cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]*pixels[15].green));
5864 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]*
5865 pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5866 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]*
5867 pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5868 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+
5869 cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5870 if (image->colorspace == CMYKColorspace)
5871 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]*
5872 pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+
5873 cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+
5874 cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]*
5875 pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]*
5876 pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]*
5878 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]*
5879 pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+
5880 cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+
5881 cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]*
5882 pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+
5883 cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5921MagickExport MagickBooleanType IsFuzzyEquivalencePixel(
const Image *image,
5922 const Quantum *p,
const Image *target_image,
const Quantum *q)
5925 alpha = QuantumScale*(double) GetPixelAlpha(image,p),
5926 fuzz = GetFuzzyColorDistance(image,target_image),
5927 target_alpha = QuantumScale*(double) GetPixelAlpha(target_image,q);
5935 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5940 PixelChannel channel = GetPixelChannelChannel(image,i);
5941 PixelTrait traits = GetPixelChannelTraits(image,channel);
5942 PixelTrait target_traits = GetPixelChannelTraits(target_image,channel);
5943 if (((traits & UpdatePixelTrait) == 0) ||
5944 ((target_traits & UpdatePixelTrait) == 0))
5946 if (channel == AlphaPixelChannel)
5947 error=(double) p[i]-(
double) GetPixelChannel(target_image,channel,q);
5949 error=alpha*(double) p[i]-target_alpha*
5950 GetPixelChannel(target_image,channel,q);
5951 if (MagickSafeSignificantError(error*error,fuzz) != MagickFalse)
5952 return(MagickFalse);
6001MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(
const PixelInfo *p,
6010 fuzz=p->fuzz*p->fuzz+q->fuzz*q->fuzz;
6013 if ((p->alpha_trait != UndefinedPixelTrait) ||
6014 (q->alpha_trait != UndefinedPixelTrait))
6019 pixel=(p->alpha_trait != UndefinedPixelTrait ? p->alpha :
6020 (double) OpaqueAlpha)-(q->alpha_trait != UndefinedPixelTrait ?
6021 q->alpha : (
double) OpaqueAlpha);
6022 distance=pixel*pixel;
6023 if (MagickSafeSignificantError(distance,fuzz) != MagickFalse)
6024 return(MagickFalse);
6029 if (p->alpha_trait != UndefinedPixelTrait)
6030 scale=(QuantumScale*p->alpha);
6031 if (q->alpha_trait != UndefinedPixelTrait)
6032 scale*=(QuantumScale*q->alpha);
6033 if (scale <= MagickEpsilon)
6039 if (p->colorspace == CMYKColorspace)
6041 pixel=p->black-q->black;
6042 distance+=pixel*pixel*scale;
6043 if (MagickSafeSignificantError(distance,fuzz) != MagickFalse)
6044 return(MagickFalse);
6045 scale*=QuantumScale*((double) QuantumRange-(double) p->black);
6046 scale*=QuantumScale*((double) QuantumRange-(double) q->black);
6053 pixel=p->red-q->red;
6054 if (IsHueCompatibleColorspace(p->colorspace) != MagickFalse)
6061 if (fabs((
double) pixel) > ((
double) QuantumRange/2.0))
6062 pixel-=(double) QuantumRange;
6065 distance+=pixel*pixel*scale;
6066 if (MagickSafeSignificantError(distance,fuzz) != MagickFalse)
6067 return(MagickFalse);
6068 pixel=p->green-q->green;
6069 distance+=pixel*pixel*scale;
6070 if (MagickSafeSignificantError(distance,fuzz) != MagickFalse)
6071 return(MagickFalse);
6072 pixel=p->blue-q->blue;
6073 distance+=pixel*pixel*scale;
6074 if (MagickSafeSignificantError(distance,fuzz) != MagickFalse)
6075 return(MagickFalse);
6103MagickPrivate MagickBooleanType ResetPixelChannelMap(Image *image,
6104 ExceptionInfo *exception)
6112 assert(image != (Image *) NULL);
6113 assert(image->signature == MagickCoreSignature);
6114 (void) memset(image->channel_map,0,MaxPixelChannels*
6115 sizeof(*image->channel_map));
6116 trait=UpdatePixelTrait;
6117 if (image->alpha_trait != UndefinedPixelTrait)
6118 trait=(PixelTrait) (trait | BlendPixelTrait);
6120 if ((image->colorspace == LinearGRAYColorspace) ||
6121 (image->colorspace == GRAYColorspace))
6123 SetPixelChannelAttributes(image,BluePixelChannel,trait,n);
6124 SetPixelChannelAttributes(image,GreenPixelChannel,trait,n);
6125 SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
6129 SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
6130 SetPixelChannelAttributes(image,GreenPixelChannel,trait,n++);
6131 SetPixelChannelAttributes(image,BluePixelChannel,trait,n++);
6133 if (image->colorspace == CMYKColorspace)
6134 SetPixelChannelAttributes(image,BlackPixelChannel,trait,n++);
6135 if (image->alpha_trait != UndefinedPixelTrait)
6136 SetPixelChannelAttributes(image,AlphaPixelChannel,CopyPixelTrait,n++);
6137 if (image->storage_class == PseudoClass)
6138 SetPixelChannelAttributes(image,IndexPixelChannel,CopyPixelTrait,n++);
6139 if ((image->channels & ReadMaskChannel) != 0)
6140 SetPixelChannelAttributes(image,ReadMaskPixelChannel,CopyPixelTrait,n++);
6141 if ((image->channels & WriteMaskChannel) != 0)
6142 SetPixelChannelAttributes(image,WriteMaskPixelChannel,CopyPixelTrait,n++);
6143 if ((image->channels & CompositeMaskChannel) != 0)
6144 SetPixelChannelAttributes(image,CompositeMaskPixelChannel,CopyPixelTrait,
6146 if (image->number_meta_channels != 0)
6154 if (image->number_meta_channels >= (
size_t) (MaxPixelChannels-MetaPixelChannels))
6156 image->number_channels=(size_t) n;
6157 image->number_meta_channels=0;
6158 (void) SetPixelChannelMask(image,image->channel_mask);
6159 ThrowBinaryException(CorruptImageError,
"MaximumChannelsExceeded",
6162 meta_channel=MetaPixelChannels;
6163 for (i=0; i < (ssize_t) image->number_meta_channels; i++)
6165 SetPixelChannelAttributes(image,meta_channel,UpdatePixelTrait,n);
6166 meta_channel=(PixelChannel) (meta_channel+1);
6170 image->number_channels=(size_t) n;
6171 (void) SetPixelChannelMask(image,image->channel_mask);
6202static void LogPixelChannels(
const Image *image)
6207 (void) LogMagickEvent(PixelEvent,GetMagickModule(),
"%s[0x%08llx]",
6208 image->filename,(MagickOffsetType) image->channel_mask);
6209 for (i=0; i < (ssize_t) image->number_channels; i++)
6212 channel_name[MagickPathExtent],
6213 traits[MagickPathExtent];
6221 channel=GetPixelChannelChannel(image,i);
6224 case RedPixelChannel:
6227 if (image->colorspace == CMYKColorspace)
6229 if ((image->colorspace == LinearGRAYColorspace) ||
6230 (image->colorspace == GRAYColorspace))
6234 case GreenPixelChannel:
6237 if (image->colorspace == CMYKColorspace)
6241 case BluePixelChannel:
6244 if (image->colorspace == CMYKColorspace)
6248 case BlackPixelChannel:
6251 if (image->storage_class == PseudoClass)
6255 case IndexPixelChannel:
6260 case AlphaPixelChannel:
6265 case ReadMaskPixelChannel:
6270 case WriteMaskPixelChannel:
6275 case CompositeMaskPixelChannel:
6277 name=
"composite-mask";
6280 case MetaPixelChannels:
6288 if (image->colorspace == UndefinedColorspace)
6290 (void) FormatLocaleString(channel_name,MagickPathExtent,
"%.17g",
6292 name=(
const char *) channel_name;
6295 if ((GetPixelChannelTraits(image,channel) & UpdatePixelTrait) != 0)
6296 (void) ConcatenateMagickString(traits,
"update,",MagickPathExtent);
6297 if ((GetPixelChannelTraits(image,channel) & BlendPixelTrait) != 0)
6298 (void) ConcatenateMagickString(traits,
"blend,",MagickPathExtent);
6299 if ((GetPixelChannelTraits(image,channel) & CopyPixelTrait) != 0)
6300 (void) ConcatenateMagickString(traits,
"copy,",MagickPathExtent);
6301 if (*traits ==
'\0')
6302 (void) ConcatenateMagickString(traits,
"undefined,",MagickPathExtent);
6303 traits[strlen(traits)-1]=
'\0';
6304 (void) LogMagickEvent(PixelEvent,GetMagickModule(),
" %.17g: %s (%s)",
6305 (
double) i,name,traits);
6309MagickExport ChannelType SetPixelChannelMask(Image *image,
6310 const ChannelType channel_mask)
6312#define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
6320 assert(image != (Image *) NULL);
6321 assert(image->signature == MagickCoreSignature);
6322 if (image->debug != MagickFalse)
6323 (void) LogMagickEvent(PixelEvent,GetMagickModule(),
"%s[0x%08llx]",
6324 image->filename,(MagickOffsetType) channel_mask);
6325 mask=image->channel_mask;
6326 image->channel_mask=channel_mask;
6327 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
6329 PixelChannel channel = GetPixelChannelChannel(image,i);
6330 if (GetChannelBit(channel_mask,channel) == 0)
6332 SetPixelChannelTraits(image,channel,CopyPixelTrait);
6335 if (channel == AlphaPixelChannel)
6337 if ((image->alpha_trait & CopyPixelTrait) != 0)
6339 SetPixelChannelTraits(image,channel,CopyPixelTrait);
6342 SetPixelChannelTraits(image,channel,UpdatePixelTrait);
6345 if (image->alpha_trait != UndefinedPixelTrait)
6347 SetPixelChannelTraits(image,channel,(PixelTrait) (UpdatePixelTrait |
6351 SetPixelChannelTraits(image,channel,UpdatePixelTrait);
6353 if (image->storage_class == PseudoClass)
6354 SetPixelChannelTraits(image,IndexPixelChannel,CopyPixelTrait);
6355 if ((image->channels & ReadMaskChannel) != 0)
6356 SetPixelChannelTraits(image,ReadMaskPixelChannel,CopyPixelTrait);
6357 if ((image->channels & WriteMaskChannel) != 0)
6358 SetPixelChannelTraits(image,WriteMaskPixelChannel,CopyPixelTrait);
6359 if ((image->channels & CompositeMaskChannel) != 0)
6360 SetPixelChannelTraits(image,CompositeMaskPixelChannel,CopyPixelTrait);
6361 if ((GetLogEventMask() & PixelEvent) != 0)
6362 LogPixelChannels(image);
6393MagickExport MagickBooleanType SetPixelMetaChannels(Image *image,
6394 const size_t number_meta_channels,ExceptionInfo *exception)
6399 if (number_meta_channels >= (
size_t) (MaxPixelChannels-MetaPixelChannels))
6400 ThrowBinaryException(CorruptImageError,
"MaximumChannelsExceeded",
6402 image->number_meta_channels=number_meta_channels;
6403 status=ResetPixelChannelMap(image,exception);
6404 if (status == MagickFalse)
6405 return(MagickFalse);
6406 return(SyncImagePixelCache(image,exception));
6434MagickExport MagickBooleanType SortImagePixels(Image *image,
6435 ExceptionInfo *exception)
6437#define SolarizeImageTag "Solarize/Image"
6454 assert(image != (Image *) NULL);
6455 assert(image->signature == MagickCoreSignature);
6456 if (IsEventLogging() != MagickFalse)
6457 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
6460 image_view=AcquireAuthenticCacheView(image,exception);
6461#if defined(MAGICKCORE_OPENMP_SUPPORT)
6462 #pragma omp parallel for schedule(static) shared(progress,status) \
6463 magick_number_threads(image,image,image->rows,1)
6465 for (y=0; y < (ssize_t) image->rows; y++)
6473 if (status == MagickFalse)
6475 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
6476 if (q == (Quantum *) NULL)
6481 for (x=0; x < (ssize_t) image->columns-1; x++)
6490 previous=GetPixelIntensity(image,q);
6491 for (j=0; j < ((ssize_t) image->columns-x-1); j++)
6493 current=GetPixelIntensity(image,q+(j+1)*(ssize_t)
6494 GetPixelChannels(image));
6495 if (previous > current)
6498 pixel[MaxPixelChannels];
6503 (void) memcpy(pixel,q+j*(ssize_t) GetPixelChannels(image),
6504 GetPixelChannels(image)*
sizeof(Quantum));
6505 (void) memcpy(q+j*(ssize_t) GetPixelChannels(image),q+(j+1)*
6506 (ssize_t) GetPixelChannels(image),GetPixelChannels(image)*
6508 (void) memcpy(q+(j+1)*(ssize_t) GetPixelChannels(image),pixel,
6509 GetPixelChannels(image)*
sizeof(Quantum));
6515 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
6517 if (image->progress_monitor != (MagickProgressMonitor) NULL)
6522#if defined(MAGICKCORE_OPENMP_SUPPORT)
6526 proceed=SetImageProgress(image,SolarizeImageTag,progress,image->rows);
6527 if (proceed == MagickFalse)
6531 image_view=DestroyCacheView(image_view);