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"
101 channel_map=(
PixelChannelMap *) AcquireQuantumMemory(MaxPixelChannels+1,
102 sizeof(*channel_map));
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;
139 clone_map=AcquirePixelChannelMap();
142 (void) memcpy(clone_map,channel_map,MaxPixelChannels*
sizeof(*channel_map));
174 pixel_info=(
PixelInfo *) AcquireMagickMemory(
sizeof(*pixel_info));
176 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
177 *pixel_info=(*pixel);
211MagickExport
void ConformPixelInfo(
Image *image,
const PixelInfo *source,
214 assert(image != (
Image *) NULL);
215 assert(image->signature == MagickCoreSignature);
216 assert(destination != (
const PixelInfo *) NULL);
217 *destination=(*source);
218 if (image->colorspace == CMYKColorspace)
220 if (IssRGBCompatibleColorspace(destination->colorspace) != MagickFalse)
221 ConvertRGBToCMYK(destination);
224 if (destination->colorspace == CMYKColorspace)
226 if (IssRGBCompatibleColorspace(image->colorspace) != MagickFalse)
227 ConvertCMYKToRGB(destination);
229 if ((IsPixelInfoGray(&image->background_color) == MagickFalse) &&
230 (IsGrayColorspace(image->colorspace) != MagickFalse))
231 (void) TransformImageColorspace(image,sRGBColorspace,exception);
232 if ((destination->alpha_trait != UndefinedPixelTrait) &&
233 ((image->alpha_trait & BlendPixelTrait) == 0))
234 (void) SetImageAlpha(image,OpaqueAlpha,exception);
260static inline double DecodeGamma(
const double x)
272 static const double coefficient[] =
274 1.7917488588043277509,
275 0.82045614371976854984,
276 0.027694100686325412819,
277 -0.00094244335181762134018,
278 0.000064355540911469709545,
279 -5.7224404636060757485e-06,
280 5.8767669437311184313e-07,
281 -6.6139920053589721168e-08,
282 7.9323242696227458163e-09
285 static const double powers_of_two[] =
288 2.6390158215457883983,
289 6.9644045063689921093,
290 1.8379173679952558018e+01,
291 4.8502930128332728543e+01
298 term[1]=4.0*frexp(x,&exponent)-3.0;
299 term[2]=2.0*term[1]*term[1]-term[0];
300 term[3]=2.0*term[1]*term[2]-term[1];
301 term[4]=2.0*term[1]*term[3]-term[2];
302 term[5]=2.0*term[1]*term[4]-term[3];
303 term[6]=2.0*term[1]*term[5]-term[4];
304 term[7]=2.0*term[1]*term[6]-term[5];
305 term[8]=2.0*term[1]*term[7]-term[6];
306 p=coefficient[0]*term[0]+coefficient[1]*term[1]+coefficient[2]*term[2]+
307 coefficient[3]*term[3]+coefficient[4]*term[4]+coefficient[5]*term[5]+
308 coefficient[6]*term[6]+coefficient[7]*term[7]+coefficient[8]*term[8];
309 quotient=div(exponent-1,5);
310 if (quotient.rem < 0)
315 return(x*ldexp(powers_of_two[quotient.rem]*p,7*quotient.quot));
318MagickExport MagickRealType DecodePixelGamma(
const MagickRealType pixel)
320 if (pixel <= (0.0404482362771076*(
double) QuantumRange))
322 return((MagickRealType) ((
double) QuantumRange*DecodeGamma((
double)
323 (QuantumScale*pixel+0.055)/1.055)));
380static inline double EncodeGamma(
const double x)
392 static const double coefficient[] =
394 1.1758200232996901923,
395 0.16665763094889061230,
396 -0.0083154894939042125035,
397 0.00075187976780420279038,
398 -0.000083240178519391795367,
399 0.000010229209410070008679,
400 -1.3400466409860246e-06,
401 1.8333422241635376682e-07,
402 -2.5878596761348859722e-08
405 static const double powers_of_two[] =
408 1.3348398541700343678,
409 1.7817974362806785482,
410 2.3784142300054420538,
411 3.1748021039363991669,
412 4.2378523774371812394,
413 5.6568542494923805819,
414 7.5509945014535482244,
415 1.0079368399158985525e1,
416 1.3454342644059433809e1,
417 1.7959392772949968275e1,
418 2.3972913230026907883e1
425 term[1]=4.0*frexp(x,&exponent)-3.0;
426 term[2]=2.0*term[1]*term[1]-term[0];
427 term[3]=2.0*term[1]*term[2]-term[1];
428 term[4]=2.0*term[1]*term[3]-term[2];
429 term[5]=2.0*term[1]*term[4]-term[3];
430 term[6]=2.0*term[1]*term[5]-term[4];
431 term[7]=2.0*term[1]*term[6]-term[5];
432 term[8]=2.0*term[1]*term[7]-term[6];
433 p=coefficient[0]*term[0]+coefficient[1]*term[1]+coefficient[2]*term[2]+
434 coefficient[3]*term[3]+coefficient[4]*term[4]+coefficient[5]*term[5]+
435 coefficient[6]*term[6]+coefficient[7]*term[7]+coefficient[8]*term[8];
436 quotient=div(exponent-1,12);
437 if (quotient.rem < 0)
442 return(ldexp(powers_of_two[quotient.rem]*p,5*quotient.quot));
445MagickExport MagickRealType EncodePixelGamma(
const MagickRealType pixel)
447 if (pixel <= (0.0031306684425005883*(
double) QuantumRange))
449 return((MagickRealType) QuantumRange*(1.055*EncodeGamma((
double) QuantumScale*
508static MagickBooleanType ExportCharPixel(
const Image *image,
510 const QuantumType *quantum_map,
void *pixels,
ExceptionInfo *exception)
527 q=(
unsigned char *) pixels;
528 if (LocaleCompare(map,
"BGR") == 0)
530 for (y=0; y < (ssize_t) roi->height; y++)
532 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
533 if (p == (
const Quantum *) NULL)
535 for (x=0; x < (ssize_t) roi->width; x++)
537 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
538 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
539 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
540 p+=(ptrdiff_t) GetPixelChannels(image);
543 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
545 if (LocaleCompare(map,
"BGRA") == 0)
547 for (y=0; y < (ssize_t) roi->height; y++)
549 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
550 if (p == (
const Quantum *) NULL)
552 for (x=0; x < (ssize_t) roi->width; x++)
554 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
555 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
556 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
557 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
558 p+=(ptrdiff_t) GetPixelChannels(image);
561 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
563 if (LocaleCompare(map,
"BGRP") == 0)
565 for (y=0; y < (ssize_t) roi->height; y++)
567 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
568 if (p == (
const Quantum *) NULL)
570 for (x=0; x < (ssize_t) roi->width; x++)
572 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
573 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
574 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
575 *q++=ScaleQuantumToChar((Quantum) 0);
576 p+=(ptrdiff_t) GetPixelChannels(image);
579 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
581 if (LocaleCompare(map,
"I") == 0)
583 for (y=0; y < (ssize_t) roi->height; y++)
585 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
586 if (p == (
const Quantum *) NULL)
588 for (x=0; x < (ssize_t) roi->width; x++)
590 *q++=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
591 p+=(ptrdiff_t) GetPixelChannels(image);
594 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
596 if (LocaleCompare(map,
"RGB") == 0)
598 for (y=0; y < (ssize_t) roi->height; y++)
600 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
601 if (p == (
const Quantum *) NULL)
603 for (x=0; x < (ssize_t) roi->width; x++)
605 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
606 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
607 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
608 p+=(ptrdiff_t) GetPixelChannels(image);
611 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
613 if (LocaleCompare(map,
"RGBA") == 0)
615 for (y=0; y < (ssize_t) roi->height; y++)
617 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
618 if (p == (
const Quantum *) NULL)
620 for (x=0; x < (ssize_t) roi->width; x++)
622 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
623 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
624 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
625 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
626 p+=(ptrdiff_t) GetPixelChannels(image);
629 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
631 if (LocaleCompare(map,
"RGBP") == 0)
633 for (y=0; y < (ssize_t) roi->height; y++)
635 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
636 if (p == (
const Quantum *) NULL)
638 for (x=0; x < (ssize_t) roi->width; x++)
640 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
641 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
642 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
643 *q++=ScaleQuantumToChar((Quantum) 0);
644 p+=(ptrdiff_t) GetPixelChannels(image);
647 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
650 for (y=0; y < (ssize_t) roi->height; y++)
652 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
653 if (p == (
const Quantum *) NULL)
655 for (x=0; x < (ssize_t) roi->width; x++)
660 for (i=0; i < (ssize_t) length; i++)
663 switch (quantum_map[i])
668 *q=ScaleQuantumToChar(GetPixelRed(image,p));
674 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
680 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
685 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
690 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
695 if (image->colorspace == CMYKColorspace)
696 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
701 *q=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
709 p+=(ptrdiff_t) GetPixelChannels(image);
712 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
715static MagickBooleanType ExportDoublePixel(
const Image *image,
717 const QuantumType *quantum_map,
void *pixels,
ExceptionInfo *exception)
735 if (LocaleCompare(map,
"BGR") == 0)
737 for (y=0; y < (ssize_t) roi->height; y++)
739 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
740 if (p == (
const Quantum *) NULL)
742 for (x=0; x < (ssize_t) roi->width; x++)
744 *q++=QuantumScale*(double) GetPixelBlue(image,p);
745 *q++=QuantumScale*(double) GetPixelGreen(image,p);
746 *q++=QuantumScale*(double) GetPixelRed(image,p);
747 p+=(ptrdiff_t) GetPixelChannels(image);
750 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
752 if (LocaleCompare(map,
"BGRA") == 0)
754 for (y=0; y < (ssize_t) roi->height; y++)
756 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
757 if (p == (
const Quantum *) NULL)
759 for (x=0; x < (ssize_t) roi->width; x++)
761 *q++=QuantumScale*(double) GetPixelBlue(image,p);
762 *q++=QuantumScale*(double) GetPixelGreen(image,p);
763 *q++=QuantumScale*(double) GetPixelRed(image,p);
764 *q++=QuantumScale*(double) GetPixelAlpha(image,p);
765 p+=(ptrdiff_t) GetPixelChannels(image);
768 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
770 if (LocaleCompare(map,
"BGRP") == 0)
772 for (y=0; y < (ssize_t) roi->height; y++)
774 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
775 if (p == (
const Quantum *) NULL)
777 for (x=0; x < (ssize_t) roi->width; x++)
779 *q++=QuantumScale*(double) GetPixelBlue(image,p);
780 *q++=QuantumScale*(double) GetPixelGreen(image,p);
781 *q++=QuantumScale*(double) GetPixelRed(image,p);
783 p+=(ptrdiff_t) GetPixelChannels(image);
786 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
788 if (LocaleCompare(map,
"I") == 0)
790 for (y=0; y < (ssize_t) roi->height; y++)
792 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
793 if (p == (
const Quantum *) NULL)
795 for (x=0; x < (ssize_t) roi->width; x++)
797 *q++=(double) (QuantumScale*(
double) GetPixelIntensity(image,p));
798 p+=(ptrdiff_t) GetPixelChannels(image);
801 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
803 if (LocaleCompare(map,
"RGB") == 0)
805 for (y=0; y < (ssize_t) roi->height; y++)
807 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
808 if (p == (
const Quantum *) NULL)
810 for (x=0; x < (ssize_t) roi->width; x++)
812 *q++=QuantumScale*(double) GetPixelRed(image,p);
813 *q++=QuantumScale*(double) GetPixelGreen(image,p);
814 *q++=QuantumScale*(double) GetPixelBlue(image,p);
815 p+=(ptrdiff_t) GetPixelChannels(image);
818 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
820 if (LocaleCompare(map,
"RGBA") == 0)
822 for (y=0; y < (ssize_t) roi->height; y++)
824 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
825 if (p == (
const Quantum *) NULL)
827 for (x=0; x < (ssize_t) roi->width; x++)
829 *q++=QuantumScale*(double) GetPixelRed(image,p);
830 *q++=QuantumScale*(double) GetPixelGreen(image,p);
831 *q++=QuantumScale*(double) GetPixelBlue(image,p);
832 *q++=QuantumScale*(double) GetPixelAlpha(image,p);
833 p+=(ptrdiff_t) GetPixelChannels(image);
836 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
838 if (LocaleCompare(map,
"RGBP") == 0)
840 for (y=0; y < (ssize_t) roi->height; y++)
842 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
843 if (p == (
const Quantum *) NULL)
845 for (x=0; x < (ssize_t) roi->width; x++)
847 *q++=QuantumScale*(double) GetPixelRed(image,p);
848 *q++=QuantumScale*(double) GetPixelGreen(image,p);
849 *q++=QuantumScale*(double) GetPixelBlue(image,p);
851 p+=(ptrdiff_t) GetPixelChannels(image);
854 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
857 for (y=0; y < (ssize_t) roi->height; y++)
859 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
860 if (p == (
const Quantum *) NULL)
862 for (x=0; x < (ssize_t) roi->width; x++)
867 for (i=0; i < (ssize_t) length; i++)
870 switch (quantum_map[i])
875 *q=QuantumScale*(double) GetPixelRed(image,p);
881 *q=QuantumScale*(double) GetPixelGreen(image,p);
887 *q=QuantumScale*(double) GetPixelBlue(image,p);
892 *q=QuantumScale*(double) GetPixelAlpha(image,p);
897 *q=QuantumScale*(double) GetPixelAlpha(image,p);
902 if (image->colorspace == CMYKColorspace)
903 *q=QuantumScale*(double) GetPixelBlack(image,p);
908 *q=QuantumScale*(double) GetPixelIntensity(image,p);
916 p+=(ptrdiff_t) GetPixelChannels(image);
919 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
922static MagickBooleanType ExportFloatPixel(
const Image *image,
924 const QuantumType *quantum_map,
void *pixels,
ExceptionInfo *exception)
942 if (LocaleCompare(map,
"BGR") == 0)
944 for (y=0; y < (ssize_t) roi->height; y++)
946 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
947 if (p == (
const Quantum *) NULL)
949 for (x=0; x < (ssize_t) roi->width; x++)
951 *q++=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
952 *q++=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
953 *q++=(float) (QuantumScale*(
double) GetPixelRed(image,p));
954 p+=(ptrdiff_t) GetPixelChannels(image);
957 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
959 if (LocaleCompare(map,
"BGRA") == 0)
961 for (y=0; y < (ssize_t) roi->height; y++)
963 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
964 if (p == (
const Quantum *) NULL)
966 for (x=0; x < (ssize_t) roi->width; x++)
968 *q++=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
969 *q++=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
970 *q++=(float) (QuantumScale*(
double) GetPixelRed(image,p));
971 *q++=(float) (QuantumScale*(
double) GetPixelAlpha(image,p));
972 p+=(ptrdiff_t) GetPixelChannels(image);
975 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
977 if (LocaleCompare(map,
"BGRP") == 0)
979 for (y=0; y < (ssize_t) roi->height; y++)
981 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
982 if (p == (
const Quantum *) NULL)
984 for (x=0; x < (ssize_t) roi->width; x++)
986 *q++=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
987 *q++=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
988 *q++=(float) (QuantumScale*(
double) GetPixelRed(image,p));
990 p+=(ptrdiff_t) GetPixelChannels(image);
993 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
995 if (LocaleCompare(map,
"I") == 0)
997 for (y=0; y < (ssize_t) roi->height; y++)
999 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1000 if (p == (
const Quantum *) NULL)
1002 for (x=0; x < (ssize_t) roi->width; x++)
1004 *q++=(float) (QuantumScale*(
double) GetPixelIntensity(image,p));
1005 p+=(ptrdiff_t) GetPixelChannels(image);
1008 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1010 if (LocaleCompare(map,
"RGB") == 0)
1012 for (y=0; y < (ssize_t) roi->height; y++)
1014 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1015 if (p == (
const Quantum *) NULL)
1017 for (x=0; x < (ssize_t) roi->width; x++)
1019 *q++=(float) (QuantumScale*(
double) GetPixelRed(image,p));
1020 *q++=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
1021 *q++=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
1022 p+=(ptrdiff_t) GetPixelChannels(image);
1025 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1027 if (LocaleCompare(map,
"RGBA") == 0)
1029 for (y=0; y < (ssize_t) roi->height; y++)
1031 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1032 if (p == (
const Quantum *) NULL)
1034 for (x=0; x < (ssize_t) roi->width; x++)
1036 *q++=(float) (QuantumScale*(
double) GetPixelRed(image,p));
1037 *q++=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
1038 *q++=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
1039 *q++=(float) (QuantumScale*(
double) GetPixelAlpha(image,p));
1040 p+=(ptrdiff_t) GetPixelChannels(image);
1043 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1045 if (LocaleCompare(map,
"RGBP") == 0)
1047 for (y=0; y < (ssize_t) roi->height; y++)
1049 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1050 if (p == (
const Quantum *) NULL)
1052 for (x=0; x < (ssize_t) roi->width; x++)
1054 *q++=(float) (QuantumScale*(
double) GetPixelRed(image,p));
1055 *q++=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
1056 *q++=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
1058 p+=(ptrdiff_t) GetPixelChannels(image);
1061 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1064 for (y=0; y < (ssize_t) roi->height; y++)
1066 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1067 if (p == (
const Quantum *) NULL)
1069 for (x=0; x < (ssize_t) roi->width; x++)
1074 for (i=0; i < (ssize_t) length; i++)
1077 switch (quantum_map[i])
1082 *q=(float) (QuantumScale*(
double) GetPixelRed(image,p));
1086 case MagentaQuantum:
1088 *q=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
1094 *q=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
1099 *q=(float) (QuantumScale*((
double) (GetPixelAlpha(image,p))));
1102 case OpacityQuantum:
1104 *q=(float) (QuantumScale*(
double) GetPixelAlpha(image,p));
1109 if (image->colorspace == CMYKColorspace)
1110 *q=(float) (QuantumScale*(
double) GetPixelBlack(image,p));
1115 *q=(float) (QuantumScale*(
double) GetPixelIntensity(image,p));
1123 p+=(ptrdiff_t) GetPixelChannels(image);
1126 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1129static MagickBooleanType ExportLongPixel(
const Image *image,
1131 const QuantumType *quantum_map,
void *pixels,
ExceptionInfo *exception)
1148 q=(
unsigned int *) pixels;
1149 if (LocaleCompare(map,
"BGR") == 0)
1151 for (y=0; y < (ssize_t) roi->height; y++)
1153 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1154 if (p == (
const Quantum *) NULL)
1156 for (x=0; x < (ssize_t) roi->width; x++)
1158 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1159 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1160 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1161 p+=(ptrdiff_t) GetPixelChannels(image);
1164 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1166 if (LocaleCompare(map,
"BGRA") == 0)
1168 for (y=0; y < (ssize_t) roi->height; y++)
1170 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1171 if (p == (
const Quantum *) NULL)
1173 for (x=0; x < (ssize_t) roi->width; x++)
1175 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1176 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1177 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1178 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1179 p+=(ptrdiff_t) GetPixelChannels(image);
1182 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1184 if (LocaleCompare(map,
"BGRP") == 0)
1186 for (y=0; y < (ssize_t) roi->height; y++)
1188 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1189 if (p == (
const Quantum *) NULL)
1191 for (x=0; x < (ssize_t) roi->width; x++)
1193 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1194 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1195 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1197 p+=(ptrdiff_t) GetPixelChannels(image);
1200 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1202 if (LocaleCompare(map,
"I") == 0)
1204 for (y=0; y < (ssize_t) roi->height; y++)
1206 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1207 if (p == (
const Quantum *) NULL)
1209 for (x=0; x < (ssize_t) roi->width; x++)
1211 *q++=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
1212 p+=(ptrdiff_t) GetPixelChannels(image);
1215 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1217 if (LocaleCompare(map,
"RGB") == 0)
1219 for (y=0; y < (ssize_t) roi->height; y++)
1221 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1222 if (p == (
const Quantum *) NULL)
1224 for (x=0; x < (ssize_t) roi->width; x++)
1226 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1227 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1228 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1229 p+=(ptrdiff_t) GetPixelChannels(image);
1232 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1234 if (LocaleCompare(map,
"RGBA") == 0)
1236 for (y=0; y < (ssize_t) roi->height; y++)
1238 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1239 if (p == (
const Quantum *) NULL)
1241 for (x=0; x < (ssize_t) roi->width; x++)
1243 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1244 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1245 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1246 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1247 p+=(ptrdiff_t) GetPixelChannels(image);
1250 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1252 if (LocaleCompare(map,
"RGBP") == 0)
1254 for (y=0; y < (ssize_t) roi->height; y++)
1256 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1257 if (p == (
const Quantum *) NULL)
1259 for (x=0; x < (ssize_t) roi->width; x++)
1261 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1262 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1263 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1265 p+=(ptrdiff_t) GetPixelChannels(image);
1268 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1271 for (y=0; y < (ssize_t) roi->height; y++)
1273 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1274 if (p == (
const Quantum *) NULL)
1276 for (x=0; x < (ssize_t) roi->width; x++)
1281 for (i=0; i < (ssize_t) length; i++)
1284 switch (quantum_map[i])
1289 *q=ScaleQuantumToLong(GetPixelRed(image,p));
1293 case MagentaQuantum:
1295 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
1301 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
1306 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1309 case OpacityQuantum:
1311 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1316 if (image->colorspace == CMYKColorspace)
1317 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
1322 *q=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
1330 p+=(ptrdiff_t) GetPixelChannels(image);
1333 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1336static MagickBooleanType ExportLongLongPixel(
const Image *image,
1338 const QuantumType *quantum_map,
void *pixels,
ExceptionInfo *exception)
1355 q=(MagickSizeType *) pixels;
1356 if (LocaleCompare(map,
"BGR") == 0)
1358 for (y=0; y < (ssize_t) roi->height; y++)
1360 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1361 if (p == (
const Quantum *) NULL)
1363 for (x=0; x < (ssize_t) roi->width; x++)
1365 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1366 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1367 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1368 p+=(ptrdiff_t) GetPixelChannels(image);
1371 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1373 if (LocaleCompare(map,
"BGRA") == 0)
1375 for (y=0; y < (ssize_t) roi->height; y++)
1377 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1378 if (p == (
const Quantum *) NULL)
1380 for (x=0; x < (ssize_t) roi->width; x++)
1382 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1383 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1384 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1385 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1386 p+=(ptrdiff_t) GetPixelChannels(image);
1389 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1391 if (LocaleCompare(map,
"BGRP") == 0)
1393 for (y=0; y < (ssize_t) roi->height; y++)
1395 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1396 if (p == (
const Quantum *) NULL)
1398 for (x=0; x < (ssize_t) roi->width; x++)
1400 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1401 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1402 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1404 p+=(ptrdiff_t) GetPixelChannels(image);
1407 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1409 if (LocaleCompare(map,
"I") == 0)
1411 for (y=0; y < (ssize_t) roi->height; y++)
1413 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1414 if (p == (
const Quantum *) NULL)
1416 for (x=0; x < (ssize_t) roi->width; x++)
1418 *q++=ScaleQuantumToLongLong(ClampToQuantum(
1419 GetPixelIntensity(image,p)));
1420 p+=(ptrdiff_t) GetPixelChannels(image);
1423 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1425 if (LocaleCompare(map,
"RGB") == 0)
1427 for (y=0; y < (ssize_t) roi->height; y++)
1429 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1430 if (p == (
const Quantum *) NULL)
1432 for (x=0; x < (ssize_t) roi->width; x++)
1434 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1435 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1436 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1437 p+=(ptrdiff_t) GetPixelChannels(image);
1440 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1442 if (LocaleCompare(map,
"RGBA") == 0)
1444 for (y=0; y < (ssize_t) roi->height; y++)
1446 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1447 if (p == (
const Quantum *) NULL)
1449 for (x=0; x < (ssize_t) roi->width; x++)
1451 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1452 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1453 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1454 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1455 p+=(ptrdiff_t) GetPixelChannels(image);
1458 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1460 if (LocaleCompare(map,
"RGBP") == 0)
1462 for (y=0; y < (ssize_t) roi->height; y++)
1464 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1465 if (p == (
const Quantum *) NULL)
1467 for (x=0; x < (ssize_t) roi->width; x++)
1469 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1470 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1471 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1473 p+=(ptrdiff_t) GetPixelChannels(image);
1476 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1479 for (y=0; y < (ssize_t) roi->height; y++)
1481 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1482 if (p == (
const Quantum *) NULL)
1484 for (x=0; x < (ssize_t) roi->width; x++)
1489 for (i=0; i < (ssize_t) length; i++)
1492 switch (quantum_map[i])
1497 *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
1501 case MagentaQuantum:
1503 *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1509 *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1514 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1517 case OpacityQuantum:
1519 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1524 if (image->colorspace == CMYKColorspace)
1525 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
1530 *q=ScaleQuantumToLongLong(ClampToQuantum(
1531 GetPixelIntensity(image,p)));
1539 p+=(ptrdiff_t) GetPixelChannels(image);
1542 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1545static MagickBooleanType ExportQuantumPixel(
const Image *image,
1547 const QuantumType *quantum_map,
void *pixels,
ExceptionInfo *exception)
1564 q=(Quantum *) pixels;
1565 if (LocaleCompare(map,
"BGR") == 0)
1567 for (y=0; y < (ssize_t) roi->height; y++)
1569 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1570 if (p == (
const Quantum *) NULL)
1572 for (x=0; x < (ssize_t) roi->width; x++)
1574 *q++=GetPixelBlue(image,p);
1575 *q++=GetPixelGreen(image,p);
1576 *q++=GetPixelRed(image,p);
1577 p+=(ptrdiff_t) GetPixelChannels(image);
1580 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1582 if (LocaleCompare(map,
"BGRA") == 0)
1584 for (y=0; y < (ssize_t) roi->height; y++)
1586 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1587 if (p == (
const Quantum *) NULL)
1589 for (x=0; x < (ssize_t) roi->width; x++)
1591 *q++=GetPixelBlue(image,p);
1592 *q++=GetPixelGreen(image,p);
1593 *q++=GetPixelRed(image,p);
1594 *q++=(Quantum) (GetPixelAlpha(image,p));
1595 p+=(ptrdiff_t) GetPixelChannels(image);
1598 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1600 if (LocaleCompare(map,
"BGRP") == 0)
1602 for (y=0; y < (ssize_t) roi->height; y++)
1604 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1605 if (p == (
const Quantum *) NULL)
1607 for (x=0; x < (ssize_t) roi->width; x++)
1609 *q++=GetPixelBlue(image,p);
1610 *q++=GetPixelGreen(image,p);
1611 *q++=GetPixelRed(image,p);
1613 p+=(ptrdiff_t) GetPixelChannels(image);
1616 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1618 if (LocaleCompare(map,
"I") == 0)
1620 for (y=0; y < (ssize_t) roi->height; y++)
1622 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1623 if (p == (
const Quantum *) NULL)
1625 for (x=0; x < (ssize_t) roi->width; x++)
1627 *q++=ClampToQuantum(GetPixelIntensity(image,p));
1628 p+=(ptrdiff_t) GetPixelChannels(image);
1631 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1633 if (LocaleCompare(map,
"RGB") == 0)
1635 for (y=0; y < (ssize_t) roi->height; y++)
1637 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1638 if (p == (
const Quantum *) NULL)
1640 for (x=0; x < (ssize_t) roi->width; x++)
1642 *q++=GetPixelRed(image,p);
1643 *q++=GetPixelGreen(image,p);
1644 *q++=GetPixelBlue(image,p);
1645 p+=(ptrdiff_t) GetPixelChannels(image);
1648 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1650 if (LocaleCompare(map,
"RGBA") == 0)
1652 for (y=0; y < (ssize_t) roi->height; y++)
1654 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1655 if (p == (
const Quantum *) NULL)
1657 for (x=0; x < (ssize_t) roi->width; x++)
1659 *q++=GetPixelRed(image,p);
1660 *q++=GetPixelGreen(image,p);
1661 *q++=GetPixelBlue(image,p);
1662 *q++=(Quantum) (GetPixelAlpha(image,p));
1663 p+=(ptrdiff_t) GetPixelChannels(image);
1666 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1668 if (LocaleCompare(map,
"RGBP") == 0)
1670 for (y=0; y < (ssize_t) roi->height; y++)
1672 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1673 if (p == (
const Quantum *) NULL)
1675 for (x=0; x < (ssize_t) roi->width; x++)
1677 *q++=GetPixelRed(image,p);
1678 *q++=GetPixelGreen(image,p);
1679 *q++=GetPixelBlue(image,p);
1681 p+=(ptrdiff_t) GetPixelChannels(image);
1684 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1687 for (y=0; y < (ssize_t) roi->height; y++)
1689 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1690 if (p == (
const Quantum *) NULL)
1692 for (x=0; x < (ssize_t) roi->width; x++)
1697 for (i=0; i < (ssize_t) length; i++)
1700 switch (quantum_map[i])
1705 *q=GetPixelRed(image,p);
1709 case MagentaQuantum:
1711 *q=GetPixelGreen(image,p);
1717 *q=GetPixelBlue(image,p);
1722 *q=GetPixelAlpha(image,p);
1725 case OpacityQuantum:
1727 *q=GetPixelAlpha(image,p);
1732 if (image->colorspace == CMYKColorspace)
1733 *q=GetPixelBlack(image,p);
1738 *q=ClampToQuantum(GetPixelIntensity(image,p));
1749 p+=(ptrdiff_t) GetPixelChannels(image);
1752 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1755static MagickBooleanType ExportShortPixel(
const Image *image,
1757 const QuantumType *quantum_map,
void *pixels,
ExceptionInfo *exception)
1774 q=(
unsigned short *) pixels;
1775 if (LocaleCompare(map,
"BGR") == 0)
1777 for (y=0; y < (ssize_t) roi->height; y++)
1779 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1780 if (p == (
const Quantum *) NULL)
1782 for (x=0; x < (ssize_t) roi->width; x++)
1784 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1785 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1786 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1787 p+=(ptrdiff_t) GetPixelChannels(image);
1790 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1792 if (LocaleCompare(map,
"BGRA") == 0)
1794 for (y=0; y < (ssize_t) roi->height; y++)
1796 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1797 if (p == (
const Quantum *) NULL)
1799 for (x=0; x < (ssize_t) roi->width; x++)
1801 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1802 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1803 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1804 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1805 p+=(ptrdiff_t) GetPixelChannels(image);
1808 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1810 if (LocaleCompare(map,
"BGRP") == 0)
1812 for (y=0; y < (ssize_t) roi->height; y++)
1814 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1815 if (p == (
const Quantum *) NULL)
1817 for (x=0; x < (ssize_t) roi->width; x++)
1819 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1820 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1821 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1823 p+=(ptrdiff_t) GetPixelChannels(image);
1826 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1828 if (LocaleCompare(map,
"I") == 0)
1830 for (y=0; y < (ssize_t) roi->height; y++)
1832 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1833 if (p == (
const Quantum *) NULL)
1835 for (x=0; x < (ssize_t) roi->width; x++)
1837 *q++=ScaleQuantumToShort(ClampToQuantum(GetPixelIntensity(image,p)));
1838 p+=(ptrdiff_t) GetPixelChannels(image);
1841 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1843 if (LocaleCompare(map,
"RGB") == 0)
1845 for (y=0; y < (ssize_t) roi->height; y++)
1847 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1848 if (p == (
const Quantum *) NULL)
1850 for (x=0; x < (ssize_t) roi->width; x++)
1852 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1853 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1854 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1855 p+=(ptrdiff_t) GetPixelChannels(image);
1858 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1860 if (LocaleCompare(map,
"RGBA") == 0)
1862 for (y=0; y < (ssize_t) roi->height; y++)
1864 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1865 if (p == (
const Quantum *) NULL)
1867 for (x=0; x < (ssize_t) roi->width; x++)
1869 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1870 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1871 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1872 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1873 p+=(ptrdiff_t) GetPixelChannels(image);
1876 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1878 if (LocaleCompare(map,
"RGBP") == 0)
1880 for (y=0; y < (ssize_t) roi->height; y++)
1882 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1883 if (p == (
const Quantum *) NULL)
1885 for (x=0; x < (ssize_t) roi->width; x++)
1887 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1888 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1889 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1891 p+=(ptrdiff_t) GetPixelChannels(image);
1894 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1897 for (y=0; y < (ssize_t) roi->height; y++)
1899 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1900 if (p == (
const Quantum *) NULL)
1902 for (x=0; x < (ssize_t) roi->width; x++)
1907 for (i=0; i < (ssize_t) length; i++)
1910 switch (quantum_map[i])
1915 *q=ScaleQuantumToShort(GetPixelRed(image,p));
1919 case MagentaQuantum:
1921 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
1927 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
1932 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1935 case OpacityQuantum:
1937 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1942 if (image->colorspace == CMYKColorspace)
1943 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
1948 *q=ScaleQuantumToShort(ClampToQuantum(GetPixelIntensity(image,p)));
1956 p+=(ptrdiff_t) GetPixelChannels(image);
1959 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1962MagickExport MagickBooleanType ExportImagePixels(
const Image *image,
1963 const ssize_t x,
const ssize_t y,
const size_t width,
const size_t height,
1964 const char *map,
const StorageType type,
void *pixels,
ExceptionInfo *exception)
1981 assert(image != (
Image *) NULL);
1982 assert(image->signature == MagickCoreSignature);
1983 if (IsEventLogging() != MagickFalse)
1984 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1986 quantum_map=(QuantumType *) AcquireQuantumMemory(length,
sizeof(*quantum_map));
1987 if (quantum_map == (QuantumType *) NULL)
1989 (void) ThrowMagickException(exception,GetMagickModule(),
1990 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",image->filename);
1991 return(MagickFalse);
1993 for (i=0; i < (ssize_t) length; i++)
2000 quantum_map[i]=AlphaQuantum;
2006 quantum_map[i]=BlueQuantum;
2012 quantum_map[i]=CyanQuantum;
2013 if (image->colorspace == CMYKColorspace)
2015 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2016 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2017 "ColorSeparatedImageRequired",
"`%s'",map);
2018 return(MagickFalse);
2023 quantum_map[i]=GreenQuantum;
2029 quantum_map[i]=IndexQuantum;
2035 quantum_map[i]=BlackQuantum;
2036 if (image->colorspace == CMYKColorspace)
2038 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2039 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2040 "ColorSeparatedImageRequired",
"`%s'",map);
2041 return(MagickFalse);
2046 quantum_map[i]=MagentaQuantum;
2047 if (image->colorspace == CMYKColorspace)
2049 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2050 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2051 "ColorSeparatedImageRequired",
"`%s'",map);
2052 return(MagickFalse);
2057 quantum_map[i]=OpacityQuantum;
2063 quantum_map[i]=UndefinedQuantum;
2069 quantum_map[i]=RedQuantum;
2075 quantum_map[i]=YellowQuantum;
2076 if (image->colorspace == CMYKColorspace)
2078 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2079 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2080 "ColorSeparatedImageRequired",
"`%s'",map);
2081 return(MagickFalse);
2085 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2086 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2087 "UnrecognizedPixelMap",
"`%s'",map);
2088 return(MagickFalse);
2100 status=ExportCharPixel(image,&roi,map,quantum_map,pixels,exception);
2105 status=ExportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
2110 status=ExportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
2115 status=ExportLongPixel(image,&roi,map,quantum_map,pixels,exception);
2120 status=ExportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
2125 status=ExportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
2130 status=ExportShortPixel(image,&roi,map,quantum_map,pixels,exception);
2135 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2136 "UnrecognizedPixelMap",
"`%s'",map);
2140 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2168MagickExport
void GetPixelInfo(
const Image *image,
PixelInfo *pixel)
2170 (void) memset(pixel,0,
sizeof(*pixel));
2171 pixel->storage_class=DirectClass;
2172 pixel->colorspace=sRGBColorspace;
2173 pixel->depth=MAGICKCORE_QUANTUM_DEPTH;
2174 pixel->alpha_trait=UndefinedPixelTrait;
2175 pixel->alpha=(double) OpaqueAlpha;
2176 if (image == (
const Image *) NULL)
2178 pixel->storage_class=image->storage_class;
2179 pixel->colorspace=image->colorspace;
2180 pixel->alpha_trait=image->alpha_trait;
2181 pixel->depth=image->depth;
2182 pixel->fuzz=image->fuzz;
2222MagickExport MagickRealType GetPixelInfoIntensity(
2223 const Image *magick_restrict image,
const PixelInfo *magick_restrict pixel)
2231 PixelIntensityMethod
2234 method=Rec709LumaPixelIntensityMethod;
2235 if (image != (
const Image *) NULL)
2236 method=image->intensity;
2242 case AveragePixelIntensityMethod:
2244 intensity=(red+green+blue)/3.0;
2247 case BrightnessPixelIntensityMethod:
2249 intensity=MagickMax(MagickMax(red,green),blue);
2252 case LightnessPixelIntensityMethod:
2254 intensity=(MagickMin(MagickMin(red,green),blue)+
2255 MagickMax(MagickMax(red,green),blue))/2.0;
2258 case MSPixelIntensityMethod:
2260 intensity=(MagickRealType) (((
double) red*red+green*green+blue*blue)/
2261 (3.0*(
double) QuantumRange));
2264 case Rec601LumaPixelIntensityMethod:
2266 if (pixel->colorspace == RGBColorspace)
2268 red=EncodePixelGamma(red);
2269 green=EncodePixelGamma(green);
2270 blue=EncodePixelGamma(blue);
2272 intensity=0.298839*red+0.586811*green+0.114350*blue;
2275 case Rec601LuminancePixelIntensityMethod:
2277 if (pixel->colorspace == sRGBColorspace)
2279 red=DecodePixelGamma(red);
2280 green=DecodePixelGamma(green);
2281 blue=DecodePixelGamma(blue);
2283 intensity=0.298839*red+0.586811*green+0.114350*blue;
2286 case Rec709LumaPixelIntensityMethod:
2289 if (pixel->colorspace == RGBColorspace)
2291 red=EncodePixelGamma(red);
2292 green=EncodePixelGamma(green);
2293 blue=EncodePixelGamma(blue);
2295 intensity=0.212656*red+0.715158*green+0.072186*blue;
2298 case Rec709LuminancePixelIntensityMethod:
2300 if (pixel->colorspace == sRGBColorspace)
2302 red=DecodePixelGamma(red);
2303 green=DecodePixelGamma(green);
2304 blue=DecodePixelGamma(blue);
2306 intensity=0.212656*red+0.715158*green+0.072186*blue;
2309 case RMSPixelIntensityMethod:
2311 intensity=(MagickRealType) (sqrt((
double) red*red+green*green+blue*blue)/
2356MagickExport MagickRealType GetPixelIntensity(
2357 const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
2365 red=(MagickRealType) GetPixelRed(image,pixel);
2366 if (image->number_channels == 1)
2368 green=(MagickRealType) GetPixelGreen(image,pixel);
2369 blue=(MagickRealType) GetPixelBlue(image,pixel);
2370 switch (image->intensity)
2372 case AveragePixelIntensityMethod:
2374 intensity=(red+green+blue)/3.0;
2377 case BrightnessPixelIntensityMethod:
2379 intensity=MagickMax(MagickMax(red,green),blue);
2382 case LightnessPixelIntensityMethod:
2384 intensity=(MagickMin(MagickMin(red,green),blue)+
2385 MagickMax(MagickMax(red,green),blue))/2.0;
2388 case MSPixelIntensityMethod:
2390 intensity=(MagickRealType) (((
double) red*red+green*green+blue*blue)/
2391 (3.0*(
double) QuantumRange));
2394 case Rec601LumaPixelIntensityMethod:
2396 if ((image->colorspace == RGBColorspace) ||
2397 (image->colorspace == LinearGRAYColorspace))
2399 red=EncodePixelGamma(red);
2400 green=EncodePixelGamma(green);
2401 blue=EncodePixelGamma(blue);
2403 intensity=0.298839*red+0.586811*green+0.114350*blue;
2406 case Rec601LuminancePixelIntensityMethod:
2408 if ((image->colorspace == sRGBColorspace) ||
2409 (image->colorspace == GRAYColorspace))
2411 red=DecodePixelGamma(red);
2412 green=DecodePixelGamma(green);
2413 blue=DecodePixelGamma(blue);
2415 intensity=0.298839*red+0.586811*green+0.114350*blue;
2418 case Rec709LumaPixelIntensityMethod:
2421 if ((image->colorspace == RGBColorspace) ||
2422 (image->colorspace == LinearGRAYColorspace))
2424 red=EncodePixelGamma(red);
2425 green=EncodePixelGamma(green);
2426 blue=EncodePixelGamma(blue);
2428 intensity=0.212656*red+0.715158*green+0.072186*blue;
2431 case Rec709LuminancePixelIntensityMethod:
2433 if ((image->colorspace == sRGBColorspace) ||
2434 (image->colorspace == GRAYColorspace))
2436 red=DecodePixelGamma(red);
2437 green=DecodePixelGamma(green);
2438 blue=DecodePixelGamma(blue);
2440 intensity=0.212656*red+0.715158*green+0.072186*blue;
2443 case RMSPixelIntensityMethod:
2445 intensity=(MagickRealType) (sqrt((
double) red*red+green*green+blue*blue)/
2510 const char *magick_restrict map,
const QuantumType *quantum_map,
2528 p=(
const unsigned char *) pixels;
2529 if (LocaleCompare(map,
"BGR") == 0)
2531 for (y=0; y < (ssize_t) roi->height; y++)
2533 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2534 if (q == (Quantum *) NULL)
2536 for (x=0; x < (ssize_t) roi->width; x++)
2538 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2539 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2540 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2541 q+=(ptrdiff_t) GetPixelChannels(image);
2543 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2546 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2548 if (LocaleCompare(map,
"BGRA") == 0)
2550 for (y=0; y < (ssize_t) roi->height; y++)
2552 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2553 if (q == (Quantum *) NULL)
2555 for (x=0; x < (ssize_t) roi->width; x++)
2557 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2558 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2559 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2560 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2561 q+=(ptrdiff_t) GetPixelChannels(image);
2563 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2566 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2568 if (LocaleCompare(map,
"BGRO") == 0)
2570 for (y=0; y < (ssize_t) roi->height; y++)
2572 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2573 if (q == (Quantum *) NULL)
2575 for (x=0; x < (ssize_t) roi->width; x++)
2577 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2578 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2579 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2580 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2581 q+=(ptrdiff_t) GetPixelChannels(image);
2583 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2586 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2588 if (LocaleCompare(map,
"BGRP") == 0)
2590 for (y=0; y < (ssize_t) roi->height; y++)
2592 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2593 if (q == (Quantum *) NULL)
2595 for (x=0; x < (ssize_t) roi->width; x++)
2597 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2598 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2599 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2601 q+=(ptrdiff_t) GetPixelChannels(image);
2603 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2606 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2608 if (LocaleCompare(map,
"I") == 0)
2610 for (y=0; y < (ssize_t) roi->height; y++)
2612 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2613 if (q == (Quantum *) NULL)
2615 for (x=0; x < (ssize_t) roi->width; x++)
2617 SetPixelGray(image,ScaleCharToQuantum(*p++),q);
2618 q+=(ptrdiff_t) GetPixelChannels(image);
2620 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2623 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2625 if (LocaleCompare(map,
"RGB") == 0)
2627 for (y=0; y < (ssize_t) roi->height; y++)
2629 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2630 if (q == (Quantum *) NULL)
2632 for (x=0; x < (ssize_t) roi->width; x++)
2634 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2635 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2636 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2637 q+=(ptrdiff_t) GetPixelChannels(image);
2639 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2642 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2644 if (LocaleCompare(map,
"RGBA") == 0)
2646 for (y=0; y < (ssize_t) roi->height; y++)
2648 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2649 if (q == (Quantum *) NULL)
2651 for (x=0; x < (ssize_t) roi->width; x++)
2653 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2654 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2655 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2656 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2657 q+=(ptrdiff_t) GetPixelChannels(image);
2659 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2662 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2664 if (LocaleCompare(map,
"RGBO") == 0)
2666 for (y=0; y < (ssize_t) roi->height; y++)
2668 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2669 if (q == (Quantum *) NULL)
2671 for (x=0; x < (ssize_t) roi->width; x++)
2673 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2674 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2675 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2676 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2677 q+=(ptrdiff_t) GetPixelChannels(image);
2679 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2682 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2684 if (LocaleCompare(map,
"RGBP") == 0)
2686 for (y=0; y < (ssize_t) roi->height; y++)
2688 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2689 if (q == (Quantum *) NULL)
2691 for (x=0; x < (ssize_t) roi->width; x++)
2693 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2694 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2695 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2697 q+=(ptrdiff_t) GetPixelChannels(image);
2699 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2702 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2705 for (y=0; y < (ssize_t) roi->height; y++)
2707 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2708 if (q == (Quantum *) NULL)
2710 for (x=0; x < (ssize_t) roi->width; x++)
2715 for (i=0; i < (ssize_t) length; i++)
2717 switch (quantum_map[i])
2722 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2726 case MagentaQuantum:
2728 SetPixelGreen(image,ScaleCharToQuantum(*p),q);
2734 SetPixelBlue(image,ScaleCharToQuantum(*p),q);
2739 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2742 case OpacityQuantum:
2744 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2749 SetPixelBlack(image,ScaleCharToQuantum(*p),q);
2754 SetPixelGray(image,ScaleCharToQuantum(*p),q);
2762 q+=(ptrdiff_t) GetPixelChannels(image);
2764 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2767 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2770static MagickBooleanType ImportDoublePixel(
Image *image,
2772 const QuantumType *quantum_map,
const void *pixels,
ExceptionInfo *exception)
2789 p=(
const double *) pixels;
2790 if (LocaleCompare(map,
"BGR") == 0)
2792 for (y=0; y < (ssize_t) roi->height; y++)
2794 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2795 if (q == (Quantum *) NULL)
2797 for (x=0; x < (ssize_t) roi->width; x++)
2799 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2801 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2803 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2805 q+=(ptrdiff_t) GetPixelChannels(image);
2807 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2810 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2812 if (LocaleCompare(map,
"BGRA") == 0)
2814 for (y=0; y < (ssize_t) roi->height; y++)
2816 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2817 if (q == (Quantum *) NULL)
2819 for (x=0; x < (ssize_t) roi->width; x++)
2821 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2823 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2825 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2827 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2829 q+=(ptrdiff_t) GetPixelChannels(image);
2831 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2834 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2836 if (LocaleCompare(map,
"BGRP") == 0)
2838 for (y=0; y < (ssize_t) roi->height; y++)
2840 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2841 if (q == (Quantum *) NULL)
2843 for (x=0; x < (ssize_t) roi->width; x++)
2845 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2847 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2849 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2852 q+=(ptrdiff_t) GetPixelChannels(image);
2854 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2857 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2859 if (LocaleCompare(map,
"I") == 0)
2861 for (y=0; y < (ssize_t) roi->height; y++)
2863 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2864 if (q == (Quantum *) NULL)
2866 for (x=0; x < (ssize_t) roi->width; x++)
2868 SetPixelGray(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2870 q+=(ptrdiff_t) GetPixelChannels(image);
2872 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2875 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2877 if (LocaleCompare(map,
"RGB") == 0)
2879 for (y=0; y < (ssize_t) roi->height; y++)
2881 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2882 if (q == (Quantum *) NULL)
2884 for (x=0; x < (ssize_t) roi->width; x++)
2886 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2888 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2890 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2892 q+=(ptrdiff_t) GetPixelChannels(image);
2894 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2897 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2899 if (LocaleCompare(map,
"RGBA") == 0)
2901 for (y=0; y < (ssize_t) roi->height; y++)
2903 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2904 if (q == (Quantum *) NULL)
2906 for (x=0; x < (ssize_t) roi->width; x++)
2908 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2910 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2912 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2914 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2916 q+=(ptrdiff_t) GetPixelChannels(image);
2918 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2921 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2923 if (LocaleCompare(map,
"RGBP") == 0)
2925 for (y=0; y < (ssize_t) roi->height; y++)
2927 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2928 if (q == (Quantum *) NULL)
2930 for (x=0; x < (ssize_t) roi->width; x++)
2932 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2934 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2936 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2938 q+=(ptrdiff_t) GetPixelChannels(image);
2940 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2943 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2946 for (y=0; y < (ssize_t) roi->height; y++)
2948 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2949 if (q == (Quantum *) NULL)
2951 for (x=0; x < (ssize_t) roi->width; x++)
2956 for (i=0; i < (ssize_t) length; i++)
2958 switch (quantum_map[i])
2963 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2967 case MagentaQuantum:
2969 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2975 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2980 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2983 case OpacityQuantum:
2985 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2990 SetPixelBlack(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2995 SetPixelGray(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
3003 q+=(ptrdiff_t) GetPixelChannels(image);
3005 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3008 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3012 const char *magick_restrict map,
const QuantumType *quantum_map,
3030 p=(
const float *) pixels;
3031 if (LocaleCompare(map,
"BGR") == 0)
3033 for (y=0; y < (ssize_t) roi->height; y++)
3035 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3036 if (q == (Quantum *) NULL)
3038 for (x=0; x < (ssize_t) roi->width; x++)
3040 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3043 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3046 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3049 q+=(ptrdiff_t) GetPixelChannels(image);
3051 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3054 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3056 if (LocaleCompare(map,
"BGRA") == 0)
3058 for (y=0; y < (ssize_t) roi->height; y++)
3060 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3061 if (q == (Quantum *) NULL)
3063 for (x=0; x < (ssize_t) roi->width; x++)
3065 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3068 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3071 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3074 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(
double)
3077 q+=(ptrdiff_t) GetPixelChannels(image);
3079 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3082 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3084 if (LocaleCompare(map,
"BGRP") == 0)
3086 for (y=0; y < (ssize_t) roi->height; y++)
3088 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3089 if (q == (Quantum *) NULL)
3091 for (x=0; x < (ssize_t) roi->width; x++)
3093 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3096 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3099 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3103 q+=(ptrdiff_t) GetPixelChannels(image);
3105 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3108 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3110 if (LocaleCompare(map,
"I") == 0)
3112 for (y=0; y < (ssize_t) roi->height; y++)
3114 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3115 if (q == (Quantum *) NULL)
3117 for (x=0; x < (ssize_t) roi->width; x++)
3119 SetPixelGray(image,ClampToQuantum((
double) QuantumRange*(
double)
3122 q+=(ptrdiff_t) GetPixelChannels(image);
3124 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3127 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3129 if (LocaleCompare(map,
"RGB") == 0)
3131 for (y=0; y < (ssize_t) roi->height; y++)
3133 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3134 if (q == (Quantum *) NULL)
3136 for (x=0; x < (ssize_t) roi->width; x++)
3138 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3141 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3144 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3147 q+=(ptrdiff_t) GetPixelChannels(image);
3149 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3152 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3154 if (LocaleCompare(map,
"RGBA") == 0)
3156 for (y=0; y < (ssize_t) roi->height; y++)
3158 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3159 if (q == (Quantum *) NULL)
3161 for (x=0; x < (ssize_t) roi->width; x++)
3163 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3166 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3169 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3172 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(
double)
3175 q+=(ptrdiff_t) GetPixelChannels(image);
3177 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3180 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3182 if (LocaleCompare(map,
"RGBP") == 0)
3184 for (y=0; y < (ssize_t) roi->height; y++)
3186 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3187 if (q == (Quantum *) NULL)
3189 for (x=0; x < (ssize_t) roi->width; x++)
3191 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3194 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3197 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3200 q+=(ptrdiff_t) GetPixelChannels(image);
3202 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3205 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3208 for (y=0; y < (ssize_t) roi->height; y++)
3210 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3211 if (q == (Quantum *) NULL)
3213 for (x=0; x < (ssize_t) roi->width; x++)
3218 for (i=0; i < (ssize_t) length; i++)
3220 switch (quantum_map[i])
3225 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3230 case MagentaQuantum:
3232 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3239 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3245 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(
double)
3249 case OpacityQuantum:
3251 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(
double)
3257 SetPixelBlack(image,ClampToQuantum((
double) QuantumRange*(
double)
3263 SetPixelGray(image,ClampToQuantum((
double) QuantumRange*(
double)
3272 q+=(ptrdiff_t) GetPixelChannels(image);
3274 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3277 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3281 const char *magick_restrict map,
const QuantumType *quantum_map,
3299 p=(
const unsigned int *) pixels;
3300 if (LocaleCompare(map,
"BGR") == 0)
3302 for (y=0; y < (ssize_t) roi->height; y++)
3304 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3305 if (q == (Quantum *) NULL)
3307 for (x=0; x < (ssize_t) roi->width; x++)
3309 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3310 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3311 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3312 q+=(ptrdiff_t) GetPixelChannels(image);
3314 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3317 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3319 if (LocaleCompare(map,
"BGRA") == 0)
3321 for (y=0; y < (ssize_t) roi->height; y++)
3323 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3324 if (q == (Quantum *) NULL)
3326 for (x=0; x < (ssize_t) roi->width; x++)
3328 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3329 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3330 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3331 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3332 q+=(ptrdiff_t) GetPixelChannels(image);
3334 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3337 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3339 if (LocaleCompare(map,
"BGRP") == 0)
3341 for (y=0; y < (ssize_t) roi->height; y++)
3343 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3344 if (q == (Quantum *) NULL)
3346 for (x=0; x < (ssize_t) roi->width; x++)
3348 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3349 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3350 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3352 q+=(ptrdiff_t) GetPixelChannels(image);
3354 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3357 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3359 if (LocaleCompare(map,
"I") == 0)
3361 for (y=0; y < (ssize_t) roi->height; y++)
3363 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3364 if (q == (Quantum *) NULL)
3366 for (x=0; x < (ssize_t) roi->width; x++)
3368 SetPixelGray(image,ScaleLongToQuantum(*p++),q);
3369 q+=(ptrdiff_t) GetPixelChannels(image);
3371 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3374 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3376 if (LocaleCompare(map,
"RGB") == 0)
3378 for (y=0; y < (ssize_t) roi->height; y++)
3380 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3381 if (q == (Quantum *) NULL)
3383 for (x=0; x < (ssize_t) roi->width; x++)
3385 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3386 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3387 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3388 q+=(ptrdiff_t) GetPixelChannels(image);
3390 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3393 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3395 if (LocaleCompare(map,
"RGBA") == 0)
3397 for (y=0; y < (ssize_t) roi->height; y++)
3399 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3400 if (q == (Quantum *) NULL)
3402 for (x=0; x < (ssize_t) roi->width; x++)
3404 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3405 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3406 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3407 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3408 q+=(ptrdiff_t) GetPixelChannels(image);
3410 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3413 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3415 if (LocaleCompare(map,
"RGBP") == 0)
3417 for (y=0; y < (ssize_t) roi->height; y++)
3419 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3420 if (q == (Quantum *) NULL)
3422 for (x=0; x < (ssize_t) roi->width; x++)
3424 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3425 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3426 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3428 q+=(ptrdiff_t) GetPixelChannels(image);
3430 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3433 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3436 for (y=0; y < (ssize_t) roi->height; y++)
3438 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3439 if (q == (Quantum *) NULL)
3441 for (x=0; x < (ssize_t) roi->width; x++)
3446 for (i=0; i < (ssize_t) length; i++)
3448 switch (quantum_map[i])
3453 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3457 case MagentaQuantum:
3459 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
3465 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
3470 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3473 case OpacityQuantum:
3475 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3480 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
3485 SetPixelGray(image,ScaleLongToQuantum(*p),q);
3493 q+=(ptrdiff_t) GetPixelChannels(image);
3495 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3498 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3501static MagickBooleanType ImportLongLongPixel(
Image *image,
3503 const QuantumType *quantum_map,
const void *pixels,
ExceptionInfo *exception)
3505 const MagickSizeType
3520 p=(
const MagickSizeType *) pixels;
3521 if (LocaleCompare(map,
"BGR") == 0)
3523 for (y=0; y < (ssize_t) roi->height; y++)
3525 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3526 if (q == (Quantum *) NULL)
3528 for (x=0; x < (ssize_t) roi->width; x++)
3530 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3531 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3532 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3533 q+=(ptrdiff_t) GetPixelChannels(image);
3535 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3538 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3540 if (LocaleCompare(map,
"BGRA") == 0)
3542 for (y=0; y < (ssize_t) roi->height; y++)
3544 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3545 if (q == (Quantum *) NULL)
3547 for (x=0; x < (ssize_t) roi->width; x++)
3549 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3550 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3551 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3552 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3553 q+=(ptrdiff_t) GetPixelChannels(image);
3555 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3558 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3560 if (LocaleCompare(map,
"BGRP") == 0)
3562 for (y=0; y < (ssize_t) roi->height; y++)
3564 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3565 if (q == (Quantum *) NULL)
3567 for (x=0; x < (ssize_t) roi->width; x++)
3569 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3570 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3571 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3573 q+=(ptrdiff_t) GetPixelChannels(image);
3575 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3578 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3580 if (LocaleCompare(map,
"I") == 0)
3582 for (y=0; y < (ssize_t) roi->height; y++)
3584 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3585 if (q == (Quantum *) NULL)
3587 for (x=0; x < (ssize_t) roi->width; x++)
3589 SetPixelGray(image,ScaleLongLongToQuantum(*p++),q);
3590 q+=(ptrdiff_t) GetPixelChannels(image);
3592 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3595 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3597 if (LocaleCompare(map,
"RGB") == 0)
3599 for (y=0; y < (ssize_t) roi->height; y++)
3601 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3602 if (q == (Quantum *) NULL)
3604 for (x=0; x < (ssize_t) roi->width; x++)
3606 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3607 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3608 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3609 q+=(ptrdiff_t) GetPixelChannels(image);
3611 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3614 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3616 if (LocaleCompare(map,
"RGBA") == 0)
3618 for (y=0; y < (ssize_t) roi->height; y++)
3620 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3621 if (q == (Quantum *) NULL)
3623 for (x=0; x < (ssize_t) roi->width; x++)
3625 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3626 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3627 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3628 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3629 q+=(ptrdiff_t) GetPixelChannels(image);
3631 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3634 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3636 if (LocaleCompare(map,
"RGBP") == 0)
3638 for (y=0; y < (ssize_t) roi->height; y++)
3640 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3641 if (q == (Quantum *) NULL)
3643 for (x=0; x < (ssize_t) roi->width; x++)
3645 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3646 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3647 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3649 q+=(ptrdiff_t) GetPixelChannels(image);
3651 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3654 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3657 for (y=0; y < (ssize_t) roi->height; y++)
3659 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3660 if (q == (Quantum *) NULL)
3662 for (x=0; x < (ssize_t) roi->width; x++)
3667 for (i=0; i < (ssize_t) length; i++)
3669 switch (quantum_map[i])
3674 SetPixelRed(image,ScaleLongLongToQuantum(*p),q);
3678 case MagentaQuantum:
3680 SetPixelGreen(image,ScaleLongLongToQuantum(*p),q);
3686 SetPixelBlue(image,ScaleLongLongToQuantum(*p),q);
3691 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3694 case OpacityQuantum:
3696 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3701 SetPixelBlack(image,ScaleLongLongToQuantum(*p),q);
3706 SetPixelGray(image,ScaleLongLongToQuantum(*p),q);
3714 q+=(ptrdiff_t) GetPixelChannels(image);
3716 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3719 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3722static MagickBooleanType ImportQuantumPixel(
Image *image,
3724 const QuantumType *quantum_map,
const void *pixels,
ExceptionInfo *exception)
3741 p=(
const Quantum *) pixels;
3742 if (LocaleCompare(map,
"BGR") == 0)
3744 for (y=0; y < (ssize_t) roi->height; y++)
3746 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3747 if (q == (Quantum *) NULL)
3749 for (x=0; x < (ssize_t) roi->width; x++)
3751 SetPixelBlue(image,*p++,q);
3752 SetPixelGreen(image,*p++,q);
3753 SetPixelRed(image,*p++,q);
3754 q+=(ptrdiff_t) GetPixelChannels(image);
3756 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3759 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3761 if (LocaleCompare(map,
"BGRA") == 0)
3763 for (y=0; y < (ssize_t) roi->height; y++)
3765 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3766 if (q == (Quantum *) NULL)
3768 for (x=0; x < (ssize_t) roi->width; x++)
3770 SetPixelBlue(image,*p++,q);
3771 SetPixelGreen(image,*p++,q);
3772 SetPixelRed(image,*p++,q);
3773 SetPixelAlpha(image,*p++,q);
3774 q+=(ptrdiff_t) GetPixelChannels(image);
3776 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3779 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3781 if (LocaleCompare(map,
"BGRP") == 0)
3783 for (y=0; y < (ssize_t) roi->height; y++)
3785 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3786 if (q == (Quantum *) NULL)
3788 for (x=0; x < (ssize_t) roi->width; x++)
3790 SetPixelBlue(image,*p++,q);
3791 SetPixelGreen(image,*p++,q);
3792 SetPixelRed(image,*p++,q);
3794 q+=(ptrdiff_t) GetPixelChannels(image);
3796 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3799 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3801 if (LocaleCompare(map,
"I") == 0)
3803 for (y=0; y < (ssize_t) roi->height; y++)
3805 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3806 if (q == (Quantum *) NULL)
3808 for (x=0; x < (ssize_t) roi->width; x++)
3810 SetPixelGray(image,*p++,q);
3811 q+=(ptrdiff_t) GetPixelChannels(image);
3813 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3816 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3818 if (LocaleCompare(map,
"RGB") == 0)
3820 for (y=0; y < (ssize_t) roi->height; y++)
3822 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3823 if (q == (Quantum *) NULL)
3825 for (x=0; x < (ssize_t) roi->width; x++)
3827 SetPixelRed(image,*p++,q);
3828 SetPixelGreen(image,*p++,q);
3829 SetPixelBlue(image,*p++,q);
3830 q+=(ptrdiff_t) GetPixelChannels(image);
3832 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3835 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3837 if (LocaleCompare(map,
"RGBA") == 0)
3839 for (y=0; y < (ssize_t) roi->height; y++)
3841 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3842 if (q == (Quantum *) NULL)
3844 for (x=0; x < (ssize_t) roi->width; x++)
3846 SetPixelRed(image,*p++,q);
3847 SetPixelGreen(image,*p++,q);
3848 SetPixelBlue(image,*p++,q);
3849 SetPixelAlpha(image,*p++,q);
3850 q+=(ptrdiff_t) GetPixelChannels(image);
3852 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3855 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3857 if (LocaleCompare(map,
"RGBP") == 0)
3859 for (y=0; y < (ssize_t) roi->height; y++)
3861 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3862 if (q == (Quantum *) NULL)
3864 for (x=0; x < (ssize_t) roi->width; x++)
3866 SetPixelRed(image,*p++,q);
3867 SetPixelGreen(image,*p++,q);
3868 SetPixelBlue(image,*p++,q);
3870 q+=(ptrdiff_t) GetPixelChannels(image);
3872 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3875 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3878 for (y=0; y < (ssize_t) roi->height; y++)
3880 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3881 if (q == (Quantum *) NULL)
3883 for (x=0; x < (ssize_t) roi->width; x++)
3888 for (i=0; i < (ssize_t) length; i++)
3890 switch (quantum_map[i])
3895 SetPixelRed(image,*p,q);
3899 case MagentaQuantum:
3901 SetPixelGreen(image,*p,q);
3907 SetPixelBlue(image,*p,q);
3912 SetPixelAlpha(image,*p,q);
3915 case OpacityQuantum:
3917 SetPixelAlpha(image,*p,q);
3922 SetPixelBlack(image,*p,q);
3927 SetPixelGray(image,*p,q);
3935 q+=(ptrdiff_t) GetPixelChannels(image);
3937 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3940 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3944 const char *magick_restrict map,
const QuantumType *quantum_map,
3947 const unsigned short
3962 p=(
const unsigned short *) pixels;
3963 if (LocaleCompare(map,
"BGR") == 0)
3965 for (y=0; y < (ssize_t) roi->height; y++)
3967 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3968 if (q == (Quantum *) NULL)
3970 for (x=0; x < (ssize_t) roi->width; x++)
3972 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3973 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3974 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3975 q+=(ptrdiff_t) GetPixelChannels(image);
3977 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3980 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3982 if (LocaleCompare(map,
"BGRA") == 0)
3984 for (y=0; y < (ssize_t) roi->height; y++)
3986 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3987 if (q == (Quantum *) NULL)
3989 for (x=0; x < (ssize_t) roi->width; x++)
3991 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3992 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3993 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3994 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3995 q+=(ptrdiff_t) GetPixelChannels(image);
3997 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4000 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4002 if (LocaleCompare(map,
"BGRP") == 0)
4004 for (y=0; y < (ssize_t) roi->height; y++)
4006 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4007 if (q == (Quantum *) NULL)
4009 for (x=0; x < (ssize_t) roi->width; x++)
4011 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4012 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4013 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4015 q+=(ptrdiff_t) GetPixelChannels(image);
4017 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4020 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4022 if (LocaleCompare(map,
"I") == 0)
4024 for (y=0; y < (ssize_t) roi->height; y++)
4026 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4027 if (q == (Quantum *) NULL)
4029 for (x=0; x < (ssize_t) roi->width; x++)
4031 SetPixelGray(image,ScaleShortToQuantum(*p++),q);
4032 q+=(ptrdiff_t) GetPixelChannels(image);
4034 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4037 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4039 if (LocaleCompare(map,
"RGB") == 0)
4041 for (y=0; y < (ssize_t) roi->height; y++)
4043 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4044 if (q == (Quantum *) NULL)
4046 for (x=0; x < (ssize_t) roi->width; x++)
4048 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4049 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4050 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4051 q+=(ptrdiff_t) GetPixelChannels(image);
4053 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4056 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4058 if (LocaleCompare(map,
"RGBA") == 0)
4060 for (y=0; y < (ssize_t) roi->height; y++)
4062 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4063 if (q == (Quantum *) NULL)
4065 for (x=0; x < (ssize_t) roi->width; x++)
4067 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4068 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4069 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4070 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
4071 q+=(ptrdiff_t) GetPixelChannels(image);
4073 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4076 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4078 if (LocaleCompare(map,
"RGBP") == 0)
4080 for (y=0; y < (ssize_t) roi->height; y++)
4082 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4083 if (q == (Quantum *) NULL)
4085 for (x=0; x < (ssize_t) roi->width; x++)
4087 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4088 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4089 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4091 q+=(ptrdiff_t) GetPixelChannels(image);
4093 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4096 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4099 for (y=0; y < (ssize_t) roi->height; y++)
4101 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4102 if (q == (Quantum *) NULL)
4104 for (x=0; x < (ssize_t) roi->width; x++)
4109 for (i=0; i < (ssize_t) length; i++)
4111 switch (quantum_map[i])
4116 SetPixelRed(image,ScaleShortToQuantum(*p),q);
4120 case MagentaQuantum:
4122 SetPixelGreen(image,ScaleShortToQuantum(*p),q);
4128 SetPixelBlue(image,ScaleShortToQuantum(*p),q);
4133 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
4136 case OpacityQuantum:
4138 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
4143 SetPixelBlack(image,ScaleShortToQuantum(*p),q);
4148 SetPixelGray(image,ScaleShortToQuantum(*p),q);
4156 q+=(ptrdiff_t) GetPixelChannels(image);
4158 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4161 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4164MagickExport MagickBooleanType ImportImagePixels(
Image *image,
const ssize_t x,
4165 const ssize_t y,
const size_t width,
const size_t height,
const char *map,
4166 const StorageType type,
const void *pixels,
ExceptionInfo *exception)
4186 assert(image != (
Image *) NULL);
4187 assert(image->signature == MagickCoreSignature);
4188 if (IsEventLogging() != MagickFalse)
4189 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4191 quantum_map=(QuantumType *) AcquireQuantumMemory(length,
sizeof(*quantum_map));
4192 if (quantum_map == (QuantumType *) NULL)
4193 ThrowBinaryException(ResourceLimitError,
"MemoryAllocationFailed",
4195 for (i=0; i < (ssize_t) length; i++)
4202 quantum_map[i]=AlphaQuantum;
4203 image->alpha_trait=BlendPixelTrait;
4209 quantum_map[i]=BlueQuantum;
4215 quantum_map[i]=CyanQuantum;
4216 (void) SetImageColorspace(image,CMYKColorspace,exception);
4222 quantum_map[i]=GreenQuantum;
4228 quantum_map[i]=BlackQuantum;
4229 (void) SetImageColorspace(image,CMYKColorspace,exception);
4235 quantum_map[i]=IndexQuantum;
4236 (void) SetImageColorspace(image,GRAYColorspace,exception);
4242 quantum_map[i]=MagentaQuantum;
4243 (void) SetImageColorspace(image,CMYKColorspace,exception);
4249 quantum_map[i]=OpacityQuantum;
4250 image->alpha_trait=BlendPixelTrait;
4256 quantum_map[i]=UndefinedQuantum;
4262 quantum_map[i]=RedQuantum;
4268 quantum_map[i]=YellowQuantum;
4269 (void) SetImageColorspace(image,CMYKColorspace,exception);
4274 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4275 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4276 "UnrecognizedPixelMap",
"`%s'",map);
4277 return(MagickFalse);
4281 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
4282 return(MagickFalse);
4294 status=ImportCharPixel(image,&roi,map,quantum_map,pixels,exception);
4299 status=ImportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
4304 status=ImportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
4309 status=ImportLongPixel(image,&roi,map,quantum_map,pixels,exception);
4314 status=ImportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
4319 status=ImportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
4324 status=ImportShortPixel(image,&roi,map,quantum_map,pixels,exception);
4329 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4330 "UnrecognizedStorageType",
"`%d'",type);
4334 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4380static inline void CatromWeights(
const double x,
double (*weights)[4])
4394 alpha=(double) 1.0-x;
4395 beta=(double) (-0.5)*x*alpha;
4396 (*weights)[0]=alpha*beta;
4397 (*weights)[3]=x*beta;
4402 gamma=(*weights)[3]-(*weights)[0];
4403 (*weights)[1]=alpha-(*weights)[0]+gamma;
4404 (*weights)[2]=x-(*weights)[3]-gamma;
4407static inline void SplineWeights(
const double x,
double (*weights)[4])
4419 alpha=(double) 1.0-x;
4420 (*weights)[3]=(double) (1.0/6.0)*x*x*x;
4421 (*weights)[0]=(double) (1.0/6.0)*alpha*alpha*alpha;
4422 beta=(*weights)[3]-(*weights)[0];
4423 (*weights)[1]=alpha-(*weights)[0]+beta;
4424 (*weights)[2]=x-(*weights)[3]-beta;
4427static inline double MeshInterpolate(
const PointInfo *delta,
const double p,
4428 const double x,
const double y)
4430 return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
4433MagickExport MagickBooleanType InterpolatePixelChannel(
4435 const PixelChannel channel,
const PixelInterpolateMethod method,
const double x,
4449 PixelInterpolateMethod
4460 assert(image != (
Image *) NULL);
4461 assert(image->signature == MagickCoreSignature);
4462 assert(image_view != (
CacheView *) NULL);
4464 if ((channel < 0) || (channel >= MaxPixelChannels))
4465 ThrowBinaryException(OptionError,
"NoSuchImageChannel",image->filename);
4466 traits=GetPixelChannelTraits(image,channel);
4467 x_offset=CastDoubleToLong(floor(x));
4468 y_offset=CastDoubleToLong(floor(y));
4470 if (interpolate == UndefinedInterpolatePixel)
4471 interpolate=image->interpolate;
4473 switch (interpolate)
4475 case AverageInterpolatePixel:
4476 case Average9InterpolatePixel:
4477 case Average16InterpolatePixel:
4483 if (interpolate == Average9InterpolatePixel)
4486 x_offset=CastDoubleToLong(floor(x+0.5)-1.0);
4487 y_offset=CastDoubleToLong(floor(y+0.5)-1.0);
4490 if (interpolate == Average16InterpolatePixel)
4496 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,(
size_t) count,
4497 (
size_t) count,exception);
4498 if (p == (
const Quantum *) NULL)
4504 if ((traits & BlendPixelTrait) == 0)
4505 for (i=0; i < (ssize_t) count; i++)
4508 pixels[i]=(double) p[i*(ssize_t) GetPixelChannels(image)+
4509 GetPixelChannelOffset(image,channel)];
4512 for (i=0; i < (ssize_t) count; i++)
4514 alpha[i]=QuantumScale*(double) GetPixelAlpha(image,p+i*
4515 (ssize_t) GetPixelChannels(image));
4516 pixels[i]=alpha[i]*(double) p[i*(ssize_t) GetPixelChannels(image)+
4517 GetPixelChannelOffset(image,channel)];
4519 for (i=0; i < (ssize_t) count; i++)
4521 gamma=PerceptibleReciprocal(alpha[i])/count;
4522 *pixel+=gamma*pixels[i];
4526 case BilinearInterpolatePixel:
4533 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4534 if (p == (
const Quantum *) NULL)
4539 if ((traits & BlendPixelTrait) == 0)
4540 for (i=0; i < 4; i++)
4543 pixels[i]=(double) p[i*(ssize_t) GetPixelChannels(image)+
4544 GetPixelChannelOffset(image,channel)];
4547 for (i=0; i < 4; i++)
4549 alpha[i]=QuantumScale*(double) GetPixelAlpha(image,p+i*
4550 (ssize_t) GetPixelChannels(image));
4551 pixels[i]=alpha[i]*(double) p[i*(ssize_t) GetPixelChannels(image)+
4552 GetPixelChannelOffset(image,channel)];
4556 epsilon.x=1.0-delta.x;
4557 epsilon.y=1.0-delta.y;
4558 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4559 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4560 gamma=PerceptibleReciprocal(gamma);
4561 *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
4562 (epsilon.x*pixels[2]+delta.x*pixels[3]));
4565 case BlendInterpolatePixel:
4567 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4568 if (p == (
const Quantum *) NULL)
4573 if ((traits & BlendPixelTrait) == 0)
4574 for (i=0; i < 4; i++)
4577 pixels[i]=(MagickRealType) p[i*(ssize_t) GetPixelChannels(image)+
4578 GetPixelChannelOffset(image,channel)];
4581 for (i=0; i < 4; i++)
4583 alpha[i]=QuantumScale*(double) GetPixelAlpha(image,p+i*
4584 (ssize_t) GetPixelChannels(image));
4585 pixels[i]=alpha[i]*(double) p[i*(ssize_t) GetPixelChannels(image)+
4586 GetPixelChannelOffset(image,channel)];
4589 for (i=0; i <= 1L; i++) {
4590 if ((y-y_offset) >= 0.75)
4592 alpha[i]=alpha[i+2];
4593 pixels[i]=pixels[i+2];
4596 if ((y-y_offset) > 0.25)
4599 alpha[i]+=alpha[i+2];
4600 pixels[i]+=pixels[i+2];
4603 if ((x-x_offset) >= 0.75)
4606 pixels[0]=pixels[1];
4609 if ((x-x_offset) > 0.25)
4613 pixels[0]+=pixels[1];
4615 if (channel != AlphaPixelChannel)
4616 gamma=PerceptibleReciprocal(alpha[0]);
4618 gamma=PerceptibleReciprocal(gamma);
4619 *pixel=gamma*pixels[0];
4622 case CatromInterpolatePixel:
4628 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4630 if (p == (
const Quantum *) NULL)
4635 if ((traits & BlendPixelTrait) == 0)
4636 for (i=0; i < 16; i++)
4639 pixels[i]=(double) p[i*(ssize_t) GetPixelChannels(image)+
4640 GetPixelChannelOffset(image,channel)];
4643 for (i=0; i < 16; i++)
4645 alpha[i]=QuantumScale*(double) GetPixelAlpha(image,p+i*
4646 (ssize_t) GetPixelChannels(image));
4647 pixels[i]=alpha[i]*(double) p[i*(ssize_t) GetPixelChannels(image)+
4648 GetPixelChannelOffset(image,channel)];
4650 CatromWeights((
double) (x-x_offset),&cx);
4651 CatromWeights((
double) (y-y_offset),&cy);
4652 gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4653 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4654 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4655 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4656 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4657 cx[2]*alpha[14]+cx[3]*alpha[15])));
4658 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4659 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4660 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4661 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4662 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4665 case IntegerInterpolatePixel:
4667 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4668 if (p == (
const Quantum *) NULL)
4673 *pixel=(double) GetPixelChannel(image,channel,p);
4676 case NearestInterpolatePixel:
4678 x_offset=CastDoubleToLong(floor(x+0.5));
4679 y_offset=CastDoubleToLong(floor(y+0.5));
4680 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4681 if (p == (
const Quantum *) NULL)
4686 *pixel=(double) GetPixelChannel(image,channel,p);
4689 case MeshInterpolatePixel:
4695 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4696 if (p == (
const Quantum *) NULL)
4701 if ((traits & BlendPixelTrait) == 0)
4702 for (i=0; i < 4; i++)
4705 pixels[i]=(double) p[i*(ssize_t) GetPixelChannels(image)+
4706 GetPixelChannelOffset(image,channel)];
4709 for (i=0; i < 4; i++)
4711 alpha[i]=QuantumScale*(double) GetPixelAlpha(image,p+i*
4712 (ssize_t) GetPixelChannels(image));
4713 pixels[i]=alpha[i]*(double) p[i*(ssize_t) GetPixelChannels(image)+
4714 GetPixelChannelOffset(image,channel)];
4718 luminance.x=GetPixelLuma(image,p)-(double)
4719 GetPixelLuma(image,p+3*GetPixelChannels(image));
4720 luminance.y=GetPixelLuma(image,p+GetPixelChannels(image))-(double)
4721 GetPixelLuma(image,p+2*GetPixelChannels(image));
4722 if (fabs((
double) luminance.x) < fabs((
double) luminance.y))
4727 if (delta.x <= delta.y)
4732 delta.y=1.0-delta.y;
4733 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4734 gamma=PerceptibleReciprocal(gamma);
4735 *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
4743 delta.x=1.0-delta.x;
4744 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4745 gamma=PerceptibleReciprocal(gamma);
4746 *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
4755 if (delta.x <= (1.0-delta.y))
4760 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4761 gamma=PerceptibleReciprocal(gamma);
4762 *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
4770 delta.x=1.0-delta.x;
4771 delta.y=1.0-delta.y;
4772 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4773 gamma=PerceptibleReciprocal(gamma);
4774 *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
4780 case SplineInterpolatePixel:
4786 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4788 if (p == (
const Quantum *) NULL)
4793 if ((traits & BlendPixelTrait) == 0)
4794 for (i=0; i < 16; i++)
4797 pixels[i]=(double) p[i*(ssize_t) GetPixelChannels(image)+
4798 GetPixelChannelOffset(image,channel)];
4801 for (i=0; i < 16; i++)
4803 alpha[i]=QuantumScale*(double) GetPixelAlpha(image,p+i*
4804 (ssize_t) GetPixelChannels(image));
4805 pixels[i]=alpha[i]*(double) p[i*(ssize_t) GetPixelChannels(image)+
4806 GetPixelChannelOffset(image,channel)];
4808 SplineWeights((
double) (x-x_offset),&cx);
4809 SplineWeights((
double) (y-y_offset),&cy);
4810 gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4811 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4812 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4813 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4814 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4815 cx[2]*alpha[14]+cx[3]*alpha[15])));
4816 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4817 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4818 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4819 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4820 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4870MagickExport MagickBooleanType InterpolatePixelChannels(
4872 const Image *magick_restrict destination,
const PixelInterpolateMethod method,
4873 const double x,
const double y,Quantum *pixel,
ExceptionInfo *exception)
4893 PixelInterpolateMethod
4896 assert(source != (
Image *) NULL);
4897 assert(source->signature == MagickCoreSignature);
4898 assert(source_view != (
CacheView *) NULL);
4900 x_offset=CastDoubleToLong(floor(x));
4901 y_offset=CastDoubleToLong(floor(y));
4903 if (interpolate == UndefinedInterpolatePixel)
4904 interpolate=source->interpolate;
4905 switch (interpolate)
4907 case AverageInterpolatePixel:
4908 case Average9InterpolatePixel:
4909 case Average16InterpolatePixel:
4915 if (interpolate == Average9InterpolatePixel)
4918 x_offset=CastDoubleToLong(floor(x+0.5)-1.0);
4919 y_offset=CastDoubleToLong(floor(y+0.5)-1.0);
4922 if (interpolate == Average16InterpolatePixel)
4928 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,(
size_t) count,
4929 (
size_t) count,exception);
4930 if (p == (
const Quantum *) NULL)
4936 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4944 PixelChannel channel = GetPixelChannelChannel(source,i);
4945 PixelTrait traits = GetPixelChannelTraits(source,channel);
4946 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4948 if ((traits == UndefinedPixelTrait) ||
4949 (destination_traits == UndefinedPixelTrait))
4951 for (j=0; j < (ssize_t) count; j++)
4952 pixels[j]=(
double) p[j*(ssize_t) GetPixelChannels(source)+i];
4954 if ((traits & BlendPixelTrait) == 0)
4956 for (j=0; j < (ssize_t) count; j++)
4959 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4962 for (j=0; j < (ssize_t) count; j++)
4964 alpha[j]=QuantumScale*(double) GetPixelAlpha(source,p+j*
4965 (ssize_t) GetPixelChannels(source));
4966 pixels[j]*=alpha[j];
4967 gamma=PerceptibleReciprocal(alpha[j]);
4968 sum+=gamma*pixels[j];
4971 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4975 case BilinearInterpolatePixel:
4978 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4979 if (p == (
const Quantum *) NULL)
4984 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4990 PixelChannel channel = GetPixelChannelChannel(source,i);
4991 PixelTrait traits = GetPixelChannelTraits(source,channel);
4992 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4994 if ((traits == UndefinedPixelTrait) ||
4995 (destination_traits == UndefinedPixelTrait))
4999 epsilon.x=1.0-delta.x;
5000 epsilon.y=1.0-delta.y;
5001 pixels[0]=(double) p[i];
5002 pixels[1]=(double) p[(ssize_t) GetPixelChannels(source)+i];
5003 pixels[2]=(double) p[2*(ssize_t) GetPixelChannels(source)+i];
5004 pixels[3]=(double) p[3*(ssize_t) GetPixelChannels(source)+i];
5005 if ((traits & BlendPixelTrait) == 0)
5007 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5008 gamma=PerceptibleReciprocal(gamma);
5009 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
5010 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*
5011 pixels[2]+delta.x*pixels[3]))),pixel);
5014 alpha[0]=QuantumScale*(double) GetPixelAlpha(source,p);
5015 alpha[1]=QuantumScale*(double) GetPixelAlpha(source,p+
5016 GetPixelChannels(source));
5017 alpha[2]=QuantumScale*(double) GetPixelAlpha(source,p+2*
5018 GetPixelChannels(source));
5019 alpha[3]=QuantumScale*(double) GetPixelAlpha(source,p+3*
5020 GetPixelChannels(source));
5021 pixels[0]*=alpha[0];
5022 pixels[1]*=alpha[1];
5023 pixels[2]*=alpha[2];
5024 pixels[3]*=alpha[3];
5025 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5026 (epsilon.x*alpha[2]+delta.x*alpha[3])));
5027 gamma=PerceptibleReciprocal(gamma);
5028 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
5029 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+
5030 delta.x*pixels[3]))),pixel);
5034 case BlendInterpolatePixel:
5036 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
5037 if (p == (
const Quantum *) NULL)
5042 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5047 PixelChannel channel = GetPixelChannelChannel(source,i);
5048 PixelTrait traits = GetPixelChannelTraits(source,channel);
5049 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5051 if ((traits == UndefinedPixelTrait) ||
5052 (destination_traits == UndefinedPixelTrait))
5054 if (source->alpha_trait != BlendPixelTrait)
5055 for (j=0; j < 4; j++)
5058 pixels[j]=(double) p[j*(ssize_t) GetPixelChannels(source)+i];
5061 for (j=0; j < 4; j++)
5063 alpha[j]=QuantumScale*(double) GetPixelAlpha(source,p+j*
5064 (ssize_t) GetPixelChannels(source));
5065 pixels[j]=(double) p[j*(ssize_t) GetPixelChannels(source)+i];
5066 if (channel != AlphaPixelChannel)
5067 pixels[j]*=alpha[j];
5070 for (j=0; j <= 1L; j++)
5072 if ((y-y_offset) >= 0.75)
5074 alpha[j]=alpha[j+2];
5075 pixels[j]=pixels[j+2];
5078 if ((y-y_offset) > 0.25)
5081 alpha[j]+=alpha[j+2];
5082 pixels[j]+=pixels[j+2];
5085 if ((x-x_offset) >= 0.75)
5088 pixels[0]=pixels[1];
5091 if ((x-x_offset) > 0.25)
5095 pixels[0]+=pixels[1];
5097 if (channel != AlphaPixelChannel)
5098 gamma=PerceptibleReciprocal(alpha[0]);
5100 gamma=PerceptibleReciprocal(gamma);
5101 SetPixelChannel(destination,channel,ClampToQuantum(gamma*pixels[0]),
5106 case CatromInterpolatePixel:
5112 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
5114 if (p == (
const Quantum *) NULL)
5119 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5124 PixelChannel channel = GetPixelChannelChannel(source,i);
5125 PixelTrait traits = GetPixelChannelTraits(source,channel);
5126 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5128 if ((traits == UndefinedPixelTrait) ||
5129 (destination_traits == UndefinedPixelTrait))
5131 if ((traits & BlendPixelTrait) == 0)
5132 for (j=0; j < 16; j++)
5135 pixels[j]=(double) p[j*(ssize_t) GetPixelChannels(source)+i];
5138 for (j=0; j < 16; j++)
5140 alpha[j]=QuantumScale*(double) GetPixelAlpha(source,p+j*
5141 (ssize_t) GetPixelChannels(source));
5142 pixels[j]=alpha[j]*(double)
5143 p[j*(ssize_t) GetPixelChannels(source)+i];
5145 CatromWeights((
double) (x-x_offset),&cx);
5146 CatromWeights((
double) (y-y_offset),&cy);
5147 gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
5148 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
5149 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
5150 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
5151 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
5152 cx[2]*alpha[14]+cx[3]*alpha[15])));
5153 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
5154 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
5155 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
5156 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
5157 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
5158 pixels[14]+cx[3]*pixels[15]))),pixel);
5162 case IntegerInterpolatePixel:
5164 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
5165 if (p == (
const Quantum *) NULL)
5170 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5172 PixelChannel channel = GetPixelChannelChannel(source,i);
5173 PixelTrait traits = GetPixelChannelTraits(source,channel);
5174 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5176 if ((traits == UndefinedPixelTrait) ||
5177 (destination_traits == UndefinedPixelTrait))
5179 SetPixelChannel(destination,channel,p[i],pixel);
5183 case NearestInterpolatePixel:
5185 x_offset=CastDoubleToLong(floor(x+0.5));
5186 y_offset=CastDoubleToLong(floor(y+0.5));
5187 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
5188 if (p == (
const Quantum *) NULL)
5193 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5195 PixelChannel channel = GetPixelChannelChannel(source,i);
5196 PixelTrait traits = GetPixelChannelTraits(source,channel);
5197 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5199 if ((traits == UndefinedPixelTrait) ||
5200 (destination_traits == UndefinedPixelTrait))
5202 SetPixelChannel(destination,channel,p[i],pixel);
5206 case MeshInterpolatePixel:
5208 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
5209 if (p == (
const Quantum *) NULL)
5214 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5220 PixelChannel channel = GetPixelChannelChannel(source,i);
5221 PixelTrait traits = GetPixelChannelTraits(source,channel);
5222 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5224 if ((traits == UndefinedPixelTrait) ||
5225 (destination_traits == UndefinedPixelTrait))
5227 pixels[0]=(double) p[i];
5228 pixels[1]=(double) p[(ssize_t) GetPixelChannels(source)+i];
5229 pixels[2]=(double) p[2*(ssize_t) GetPixelChannels(source)+i];
5230 pixels[3]=(double) p[3*(ssize_t) GetPixelChannels(source)+i];
5231 if ((traits & BlendPixelTrait) == 0)
5240 alpha[0]=QuantumScale*(double) GetPixelAlpha(source,p);
5241 alpha[1]=QuantumScale*(double) GetPixelAlpha(source,p+
5242 GetPixelChannels(source));
5243 alpha[2]=QuantumScale*(double) GetPixelAlpha(source,p+2*
5244 GetPixelChannels(source));
5245 alpha[3]=QuantumScale*(double) GetPixelAlpha(source,p+3*
5246 GetPixelChannels(source));
5250 luminance.x=fabs((
double) (GetPixelLuma(source,p)-
5251 GetPixelLuma(source,p+3*GetPixelChannels(source))));
5252 luminance.y=fabs((
double) (GetPixelLuma(source,p+
5253 GetPixelChannels(source))-GetPixelLuma(source,p+2*
5254 GetPixelChannels(source))));
5255 if (luminance.x < luminance.y)
5260 if (delta.x <= delta.y)
5265 delta.y=1.0-delta.y;
5266 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5267 gamma=PerceptibleReciprocal(gamma);
5268 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5269 MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel);
5276 delta.x=1.0-delta.x;
5277 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5278 gamma=PerceptibleReciprocal(gamma);
5279 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5280 MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel);
5288 if (delta.x <= (1.0-delta.y))
5293 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5294 gamma=PerceptibleReciprocal(gamma);
5295 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5296 MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel);
5303 delta.x=1.0-delta.x;
5304 delta.y=1.0-delta.y;
5305 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5306 gamma=PerceptibleReciprocal(gamma);
5307 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5308 MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel);
5314 case SplineInterpolatePixel:
5320 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
5322 if (p == (
const Quantum *) NULL)
5327 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5332 PixelChannel channel = GetPixelChannelChannel(source,i);
5333 PixelTrait traits = GetPixelChannelTraits(source,channel);
5334 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5336 if ((traits == UndefinedPixelTrait) ||
5337 (destination_traits == UndefinedPixelTrait))
5339 if ((traits & BlendPixelTrait) == 0)
5340 for (j=0; j < 16; j++)
5343 pixels[j]=(double) p[j*(ssize_t) GetPixelChannels(source)+i];
5346 for (j=0; j < 16; j++)
5348 alpha[j]=QuantumScale*(double) GetPixelAlpha(source,p+j*
5349 (ssize_t) GetPixelChannels(source));
5350 pixels[j]=alpha[j]*(double) p[j*(ssize_t) GetPixelChannels(source)+
5353 SplineWeights((
double) (x-x_offset),&cx);
5354 SplineWeights((
double) (y-y_offset),&cy);
5355 gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
5356 PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
5357 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
5358 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
5359 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
5360 cx[2]*alpha[14]+cx[3]*alpha[15])));
5361 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
5362 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
5363 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
5364 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
5365 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
5366 pixels[14]+cx[3]*pixels[15]))),pixel);
5414static inline void AlphaBlendPixelInfo(
const Image *image,
5415 const Quantum *pixel,
PixelInfo *pixel_info,
double *alpha)
5417 if ((image->alpha_trait & BlendPixelTrait) == 0)
5420 pixel_info->red=(double) GetPixelRed(image,pixel);
5421 pixel_info->green=(double) GetPixelGreen(image,pixel);
5422 pixel_info->blue=(double) GetPixelBlue(image,pixel);
5423 pixel_info->black=0.0;
5424 if (image->colorspace == CMYKColorspace)
5425 pixel_info->black=(double) GetPixelBlack(image,pixel);
5426 pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5429 *alpha=QuantumScale*(double) GetPixelAlpha(image,pixel);
5430 pixel_info->red=(*alpha*(double) GetPixelRed(image,pixel));
5431 pixel_info->green=(*alpha*(double) GetPixelGreen(image,pixel));
5432 pixel_info->blue=(*alpha*(double) GetPixelBlue(image,pixel));
5433 pixel_info->black=0.0;
5434 if (image->colorspace == CMYKColorspace)
5435 pixel_info->black=(*alpha*(double) GetPixelBlack(image,pixel));
5436 pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5439MagickExport MagickBooleanType InterpolatePixelInfo(
const Image *image,
5440 const CacheView_ *image_view,
const PixelInterpolateMethod method,
5456 PixelInterpolateMethod
5464 assert(image != (
Image *) NULL);
5465 assert(image->signature == MagickCoreSignature);
5466 assert(image_view != (
CacheView *) NULL);
5468 x_offset=CastDoubleToLong(floor(x));
5469 y_offset=CastDoubleToLong(floor(y));
5471 if (interpolate == UndefinedInterpolatePixel)
5472 interpolate=image->interpolate;
5473 GetPixelInfoPixel(image,(
const Quantum *) NULL,pixel);
5474 (void) memset(&pixels,0,
sizeof(pixels));
5475 switch (interpolate)
5477 case AverageInterpolatePixel:
5478 case Average9InterpolatePixel:
5479 case Average16InterpolatePixel:
5485 if (interpolate == Average9InterpolatePixel)
5488 x_offset=CastDoubleToLong(floor(x+0.5)-1.0);
5489 y_offset=CastDoubleToLong(floor(y+0.5)-1.0);
5492 if (interpolate == Average16InterpolatePixel)
5498 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,(
size_t) count,
5499 (
size_t) count,exception);
5500 if (p == (
const Quantum *) NULL)
5511 for (i=0; i < (ssize_t) count; i++)
5513 AlphaBlendPixelInfo(image,p,pixels,alpha);
5514 gamma=PerceptibleReciprocal(alpha[0]);
5515 pixel->red+=gamma*pixels[0].red;
5516 pixel->green+=gamma*pixels[0].green;
5517 pixel->blue+=gamma*pixels[0].blue;
5518 pixel->black+=gamma*pixels[0].black;
5519 pixel->alpha+=pixels[0].alpha;
5520 p+=(ptrdiff_t) GetPixelChannels(image);
5524 pixel->green*=gamma;
5526 pixel->black*=gamma;
5527 pixel->alpha*=gamma;
5530 case BackgroundInterpolatePixel:
5532 *pixel=image->background_color;
5535 case BilinearInterpolatePixel:
5542 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5543 if (p == (
const Quantum *) NULL)
5548 for (i=0; i < 4L; i++)
5549 AlphaBlendPixelInfo(image,p+i*(ssize_t) GetPixelChannels(image),
5553 epsilon.x=1.0-delta.x;
5554 epsilon.y=1.0-delta.y;
5555 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5556 (epsilon.x*alpha[2]+delta.x*alpha[3])));
5557 gamma=PerceptibleReciprocal(gamma);
5558 pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
5559 pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red));
5560 pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x*
5561 pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x*
5563 pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x*
5564 pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x*
5566 if (image->colorspace == CMYKColorspace)
5567 pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x*
5568 pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x*
5570 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5571 gamma=PerceptibleReciprocal(gamma);
5572 pixel->alpha=gamma*(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x*
5573 pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x*
5577 case BlendInterpolatePixel:
5579 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5580 if (p == (
const Quantum *) NULL)
5585 for (i=0; i < 4L; i++)
5587 GetPixelInfoPixel(image,p+i*(ssize_t) GetPixelChannels(image),pixels+i);
5588 AlphaBlendPixelInfo(image,p+i*(ssize_t) GetPixelChannels(image),
5592 for (i=0; i <= 1L; i++)
5594 if ((y-y_offset) >= 0.75)
5596 alpha[i]=alpha[i+2];
5597 pixels[i]=pixels[i+2];
5600 if ((y-y_offset) > 0.25)
5603 alpha[i]+=alpha[i+2];
5604 pixels[i].red+=pixels[i+2].red;
5605 pixels[i].green+=pixels[i+2].green;
5606 pixels[i].blue+=pixels[i+2].blue;
5607 pixels[i].black+=pixels[i+2].black;
5608 pixels[i].alpha+=pixels[i+2].alpha;
5611 if ((x-x_offset) >= 0.75)
5614 pixels[0]=pixels[1];
5617 if ((x-x_offset) > 0.25)
5620 alpha[0]+= alpha[1];
5621 pixels[0].red+=pixels[1].red;
5622 pixels[0].green+=pixels[1].green;
5623 pixels[0].blue+=pixels[1].blue;
5624 pixels[0].black+=pixels[1].black;
5625 pixels[0].alpha+=pixels[1].alpha;
5628 alpha[0]=PerceptibleReciprocal(alpha[0]);
5629 pixel->red=alpha[0]*pixels[0].red;
5630 pixel->green=alpha[0]*pixels[0].green;
5631 pixel->blue=alpha[0]*pixels[0].blue;
5632 pixel->black=alpha[0]*pixels[0].black;
5633 pixel->alpha=gamma*pixels[0].alpha;
5636 case CatromInterpolatePixel:
5642 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5644 if (p == (
const Quantum *) NULL)
5649 for (i=0; i < 16L; i++)
5650 AlphaBlendPixelInfo(image,p+i*(ssize_t) GetPixelChannels(image),
5652 CatromWeights((
double) (x-x_offset),&cx);
5653 CatromWeights((
double) (y-y_offset),&cy);
5654 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]*
5655 pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5656 pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]*
5657 pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5658 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]*
5659 pixels[14].red+cx[3]*pixels[15].red));
5660 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]*
5661 pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+
5662 cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+
5663 cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]*
5664 pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]*
5665 pixels[12].green+cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]*
5667 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]*
5668 pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5669 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]*
5670 pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5671 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+
5672 cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5673 if (image->colorspace == CMYKColorspace)
5674 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]*
5675 pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+
5676 cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+
5677 cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]*
5678 pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]*
5679 pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]*
5681 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]*
5682 pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+
5683 cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+
5684 cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]*
5685 pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+
5686 cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5689 case IntegerInterpolatePixel:
5691 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5692 if (p == (
const Quantum *) NULL)
5697 GetPixelInfoPixel(image,p,pixel);
5700 case MeshInterpolatePixel:
5706 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5707 if (p == (
const Quantum *) NULL)
5714 luminance.x=GetPixelLuma(image,p)-(double)
5715 GetPixelLuma(image,p+3*GetPixelChannels(image));
5716 luminance.y=GetPixelLuma(image,p+GetPixelChannels(image))-(double)
5717 GetPixelLuma(image,p+2*GetPixelChannels(image));
5718 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5719 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5720 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5721 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5722 if (fabs((
double) luminance.x) < fabs((
double) luminance.y))
5727 if (delta.x <= delta.y)
5732 delta.y=1.0-delta.y;
5733 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5734 gamma=PerceptibleReciprocal(gamma);
5735 pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red,
5736 pixels[3].red,pixels[0].red);
5737 pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green,
5738 pixels[3].green,pixels[0].green);
5739 pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
5740 pixels[3].blue,pixels[0].blue);
5741 if (image->colorspace == CMYKColorspace)
5742 pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black,
5743 pixels[3].black,pixels[0].black);
5744 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5745 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha,
5746 pixels[3].alpha,pixels[0].alpha);
5753 delta.x=1.0-delta.x;
5754 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5755 gamma=PerceptibleReciprocal(gamma);
5756 pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red,
5757 pixels[0].red,pixels[3].red);
5758 pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green,
5759 pixels[0].green,pixels[3].green);
5760 pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
5761 pixels[0].blue,pixels[3].blue);
5762 if (image->colorspace == CMYKColorspace)
5763 pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black,
5764 pixels[0].black,pixels[3].black);
5765 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5766 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha,
5767 pixels[0].alpha,pixels[3].alpha);
5775 if (delta.x <= (1.0-delta.y))
5780 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5781 gamma=PerceptibleReciprocal(gamma);
5782 pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red,
5783 pixels[1].red,pixels[2].red);
5784 pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green,
5785 pixels[1].green,pixels[2].green);
5786 pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
5787 pixels[1].blue,pixels[2].blue);
5788 if (image->colorspace == CMYKColorspace)
5789 pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black,
5790 pixels[1].black,pixels[2].black);
5791 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5792 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha,
5793 pixels[1].alpha,pixels[2].alpha);
5800 delta.x=1.0-delta.x;
5801 delta.y=1.0-delta.y;
5802 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5803 gamma=PerceptibleReciprocal(gamma);
5804 pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red,
5805 pixels[2].red,pixels[1].red);
5806 pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green,
5807 pixels[2].green,pixels[1].green);
5808 pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
5809 pixels[2].blue,pixels[1].blue);
5810 if (image->colorspace == CMYKColorspace)
5811 pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black,
5812 pixels[2].black,pixels[1].black);
5813 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5814 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha,
5815 pixels[2].alpha,pixels[1].alpha);
5820 case NearestInterpolatePixel:
5822 x_offset=CastDoubleToLong(floor(x+0.5));
5823 y_offset=CastDoubleToLong(floor(y+0.5));
5824 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5825 if (p == (
const Quantum *) NULL)
5830 GetPixelInfoPixel(image,p,pixel);
5833 case SplineInterpolatePixel:
5839 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5841 if (p == (
const Quantum *) NULL)
5846 for (i=0; i < 16L; i++)
5847 AlphaBlendPixelInfo(image,p+i*(ssize_t) GetPixelChannels(image),
5849 SplineWeights((
double) (x-x_offset),&cx);
5850 SplineWeights((
double) (y-y_offset),&cy);
5851 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]*
5852 pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5853 pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]*
5854 pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5855 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]*
5856 pixels[14].red+cx[3]*pixels[15].red));
5857 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]*
5858 pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+
5859 cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+
5860 cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]*
5861 pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]*pixels[12].green+
5862 cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]*pixels[15].green));
5863 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]*
5864 pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5865 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]*
5866 pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5867 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+
5868 cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5869 if (image->colorspace == CMYKColorspace)
5870 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]*
5871 pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+
5872 cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+
5873 cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]*
5874 pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]*
5875 pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]*
5877 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]*
5878 pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+
5879 cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+
5880 cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]*
5881 pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+
5882 cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5920MagickExport MagickBooleanType IsFuzzyEquivalencePixel(
const Image *source,
5921 const Quantum *p,
const Image *destination,
const Quantum *q)
5929 fuzz=GetFuzzyColorDistance(source,destination);
5932 if ((source->alpha_trait != UndefinedPixelTrait) ||
5933 (destination->alpha_trait != UndefinedPixelTrait))
5938 pixel=(double) GetPixelAlpha(source,p)-(double)
5939 GetPixelAlpha(destination,q);
5940 distance=pixel*pixel;
5941 if (distance > fuzz)
5942 return(MagickFalse);
5947 if (source->alpha_trait != UndefinedPixelTrait)
5948 scale*=QuantumScale*(double) GetPixelAlpha(source,p);
5949 if (destination->alpha_trait != UndefinedPixelTrait)
5950 scale*=QuantumScale*(double) GetPixelAlpha(destination,q);
5951 if (scale <= MagickEpsilon)
5959 pixel=(double) GetPixelRed(source,p)-(double) GetPixelRed(destination,q);
5960 if (IsHueCompatibleColorspace(source->colorspace) != MagickFalse)
5966 if (fabs((
double) pixel) > ((
double) QuantumRange/2.0))
5967 pixel-=(double) QuantumRange;
5970 distance+=scale*pixel*pixel;
5971 if (distance > fuzz)
5972 return(MagickFalse);
5973 pixel=(double) GetPixelGreen(source,p)-(double) GetPixelGreen(destination,q);
5974 distance+=scale*pixel*pixel;
5975 if (distance > fuzz)
5976 return(MagickFalse);
5977 pixel=(double) GetPixelBlue(source,p)-(double) GetPixelBlue(destination,q);
5978 distance+=scale*pixel*pixel;
5979 if (distance > fuzz)
5980 return(MagickFalse);
6028MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(
const PixelInfo *p,
6037 fuzz=(double) MagickMax(MagickMax(p->fuzz,q->fuzz),(MagickRealType)
6042 if ((p->alpha_trait != UndefinedPixelTrait) ||
6043 (q->alpha_trait != UndefinedPixelTrait))
6048 pixel=(p->alpha_trait != UndefinedPixelTrait ? p->alpha :
6049 (double) OpaqueAlpha)-(q->alpha_trait != UndefinedPixelTrait ?
6050 q->alpha : (
double) OpaqueAlpha);
6051 distance=pixel*pixel;
6052 if (distance > fuzz)
6053 return(MagickFalse);
6058 if (p->alpha_trait != UndefinedPixelTrait)
6059 scale=(QuantumScale*p->alpha);
6060 if (q->alpha_trait != UndefinedPixelTrait)
6061 scale*=(QuantumScale*q->alpha);
6062 if (scale <= MagickEpsilon)
6068 if (p->colorspace == CMYKColorspace)
6070 pixel=p->black-q->black;
6071 distance+=pixel*pixel*scale;
6072 if (distance > fuzz)
6073 return(MagickFalse);
6074 scale*=QuantumScale*((double) QuantumRange-(double) p->black);
6075 scale*=QuantumScale*((double) QuantumRange-(double) q->black);
6082 pixel=p->red-q->red;
6083 if (IsHueCompatibleColorspace(p->colorspace) != MagickFalse)
6090 if (fabs((
double) pixel) > ((
double) QuantumRange/2.0))
6091 pixel-=(double) QuantumRange;
6094 distance+=pixel*pixel*scale;
6095 if (distance > fuzz)
6096 return(MagickFalse);
6097 pixel=p->green-q->green;
6098 distance+=pixel*pixel*scale;
6099 if (distance > fuzz)
6100 return(MagickFalse);
6101 pixel=p->blue-q->blue;
6102 distance+=pixel*pixel*scale;
6103 if (distance > fuzz)
6104 return(MagickFalse);
6132MagickPrivate MagickBooleanType ResetPixelChannelMap(
Image *image,
6141 assert(image != (
Image *) NULL);
6142 assert(image->signature == MagickCoreSignature);
6143 (void) memset(image->channel_map,0,MaxPixelChannels*
6144 sizeof(*image->channel_map));
6145 trait=UpdatePixelTrait;
6146 if (image->alpha_trait != UndefinedPixelTrait)
6147 trait=(PixelTrait) (trait | BlendPixelTrait);
6149 if ((image->colorspace == LinearGRAYColorspace) ||
6150 (image->colorspace == GRAYColorspace))
6152 SetPixelChannelAttributes(image,BluePixelChannel,trait,n);
6153 SetPixelChannelAttributes(image,GreenPixelChannel,trait,n);
6154 SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
6158 SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
6159 SetPixelChannelAttributes(image,GreenPixelChannel,trait,n++);
6160 SetPixelChannelAttributes(image,BluePixelChannel,trait,n++);
6162 if (image->colorspace == CMYKColorspace)
6163 SetPixelChannelAttributes(image,BlackPixelChannel,trait,n++);
6164 if (image->alpha_trait != UndefinedPixelTrait)
6165 SetPixelChannelAttributes(image,AlphaPixelChannel,CopyPixelTrait,n++);
6166 if (image->storage_class == PseudoClass)
6167 SetPixelChannelAttributes(image,IndexPixelChannel,CopyPixelTrait,n++);
6168 if ((image->channels & ReadMaskChannel) != 0)
6169 SetPixelChannelAttributes(image,ReadMaskPixelChannel,CopyPixelTrait,n++);
6170 if ((image->channels & WriteMaskChannel) != 0)
6171 SetPixelChannelAttributes(image,WriteMaskPixelChannel,CopyPixelTrait,n++);
6172 if ((image->channels & CompositeMaskChannel) != 0)
6173 SetPixelChannelAttributes(image,CompositeMaskPixelChannel,CopyPixelTrait,
6175 if (image->number_meta_channels != 0)
6183 if (image->number_meta_channels >= (MaxPixelChannels-MetaPixelChannels))
6185 image->number_channels=(size_t) n;
6186 image->number_meta_channels=0;
6187 (void) SetPixelChannelMask(image,image->channel_mask);
6188 ThrowBinaryException(CorruptImageError,
"MaximumChannelsExceeded",
6191 meta_channel=MetaPixelChannels;
6192 for (i=0; i < (ssize_t) image->number_meta_channels; i++)
6194 SetPixelChannelAttributes(image,meta_channel,UpdatePixelTrait,n);
6195 meta_channel=(PixelChannel) (meta_channel+1);
6199 image->number_channels=(size_t) n;
6200 (void) SetPixelChannelMask(image,image->channel_mask);
6231static void LogPixelChannels(
const Image *image)
6236 (void) LogMagickEvent(PixelEvent,GetMagickModule(),
"%s[0x%08llx]",
6237 image->filename,(MagickOffsetType) image->channel_mask);
6238 for (i=0; i < (ssize_t) image->number_channels; i++)
6241 channel_name[MagickPathExtent],
6242 traits[MagickPathExtent];
6250 channel=GetPixelChannelChannel(image,i);
6253 case RedPixelChannel:
6256 if (image->colorspace == CMYKColorspace)
6258 if ((image->colorspace == LinearGRAYColorspace) ||
6259 (image->colorspace == GRAYColorspace))
6263 case GreenPixelChannel:
6266 if (image->colorspace == CMYKColorspace)
6270 case BluePixelChannel:
6273 if (image->colorspace == CMYKColorspace)
6277 case BlackPixelChannel:
6280 if (image->storage_class == PseudoClass)
6284 case IndexPixelChannel:
6289 case AlphaPixelChannel:
6294 case ReadMaskPixelChannel:
6299 case WriteMaskPixelChannel:
6304 case CompositeMaskPixelChannel:
6306 name=
"composite-mask";
6309 case MetaPixelChannels:
6317 if (image->colorspace == UndefinedColorspace)
6319 (void) FormatLocaleString(channel_name,MagickPathExtent,
"%.20g",
6321 name=(
const char *) channel_name;
6324 if ((GetPixelChannelTraits(image,channel) & UpdatePixelTrait) != 0)
6325 (void) ConcatenateMagickString(traits,
"update,",MagickPathExtent);
6326 if ((GetPixelChannelTraits(image,channel) & BlendPixelTrait) != 0)
6327 (void) ConcatenateMagickString(traits,
"blend,",MagickPathExtent);
6328 if ((GetPixelChannelTraits(image,channel) & CopyPixelTrait) != 0)
6329 (void) ConcatenateMagickString(traits,
"copy,",MagickPathExtent);
6330 if (*traits ==
'\0')
6331 (void) ConcatenateMagickString(traits,
"undefined,",MagickPathExtent);
6332 traits[strlen(traits)-1]=
'\0';
6333 (void) LogMagickEvent(PixelEvent,GetMagickModule(),
" %.20g: %s (%s)",
6334 (
double) i,name,traits);
6338MagickExport ChannelType SetPixelChannelMask(
Image *image,
6339 const ChannelType channel_mask)
6341#define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
6349 assert(image != (
Image *) NULL);
6350 assert(image->signature == MagickCoreSignature);
6351 if (image->debug != MagickFalse)
6352 (void) LogMagickEvent(PixelEvent,GetMagickModule(),
"%s[0x%08llx]",
6353 image->filename,(MagickOffsetType) channel_mask);
6354 mask=image->channel_mask;
6355 image->channel_mask=channel_mask;
6356 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
6358 PixelChannel channel = GetPixelChannelChannel(image,i);
6359 if (GetChannelBit(channel_mask,channel) == 0)
6361 SetPixelChannelTraits(image,channel,CopyPixelTrait);
6364 if (channel == AlphaPixelChannel)
6366 if ((image->alpha_trait & CopyPixelTrait) != 0)
6368 SetPixelChannelTraits(image,channel,CopyPixelTrait);
6371 SetPixelChannelTraits(image,channel,UpdatePixelTrait);
6374 if (image->alpha_trait != UndefinedPixelTrait)
6376 SetPixelChannelTraits(image,channel,(PixelTrait) (UpdatePixelTrait |
6380 SetPixelChannelTraits(image,channel,UpdatePixelTrait);
6382 if (image->storage_class == PseudoClass)
6383 SetPixelChannelTraits(image,IndexPixelChannel,CopyPixelTrait);
6384 if ((image->channels & ReadMaskChannel) != 0)
6385 SetPixelChannelTraits(image,ReadMaskPixelChannel,CopyPixelTrait);
6386 if ((image->channels & WriteMaskChannel) != 0)
6387 SetPixelChannelTraits(image,WriteMaskPixelChannel,CopyPixelTrait);
6388 if ((image->channels & CompositeMaskChannel) != 0)
6389 SetPixelChannelTraits(image,CompositeMaskPixelChannel,CopyPixelTrait);
6390 if ((GetLogEventMask() & PixelEvent) != 0)
6391 LogPixelChannels(image);
6422MagickExport MagickBooleanType SetPixelMetaChannels(
Image *image,
6428 if (number_meta_channels >= (MaxPixelChannels-MetaPixelChannels))
6429 ThrowBinaryException(CorruptImageError,
"MaximumChannelsExceeded",
6431 image->number_meta_channels=number_meta_channels;
6432 status=ResetPixelChannelMap(image,exception);
6433 if (status == MagickFalse)
6434 return(MagickFalse);
6435 return(SyncImagePixelCache(image,exception));
6463MagickExport MagickBooleanType SortImagePixels(
Image *image,
6466#define SolarizeImageTag "Solarize/Image"
6483 assert(image != (
Image *) NULL);
6484 assert(image->signature == MagickCoreSignature);
6485 if (IsEventLogging() != MagickFalse)
6486 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
6489 image_view=AcquireAuthenticCacheView(image,exception);
6490#if defined(MAGICKCORE_OPENMP_SUPPORT)
6491 #pragma omp parallel for schedule(static) shared(progress,status) \
6492 magick_number_threads(image,image,image->rows,1)
6494 for (y=0; y < (ssize_t) image->rows; y++)
6502 if (status == MagickFalse)
6504 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
6505 if (q == (Quantum *) NULL)
6510 for (x=0; x < (ssize_t) image->columns-1; x++)
6519 previous=GetPixelIntensity(image,q);
6520 for (j=0; j < ((ssize_t) image->columns-x-1); j++)
6522 current=GetPixelIntensity(image,q+(j+1)*(ssize_t)
6523 GetPixelChannels(image));
6524 if (previous > current)
6527 pixel[MaxPixelChannels];
6532 (void) memcpy(pixel,q+j*(ssize_t) GetPixelChannels(image),
6533 GetPixelChannels(image)*
sizeof(Quantum));
6534 (void) memcpy(q+j*(ssize_t) GetPixelChannels(image),q+(j+1)*
6535 (ssize_t) GetPixelChannels(image),GetPixelChannels(image)*
6537 (void) memcpy(q+(j+1)*(ssize_t) GetPixelChannels(image),pixel,
6538 GetPixelChannels(image)*
sizeof(Quantum));
6544 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
6546 if (image->progress_monitor != (MagickProgressMonitor) NULL)
6551#if defined(MAGICKCORE_OPENMP_SUPPORT)
6555 proceed=SetImageProgress(image,SolarizeImageTag,progress,image->rows);
6556 if (proceed == MagickFalse)
6560 image_view=DestroyCacheView(image_view);