41#include "MagickCore/studio.h"
42#include "MagickCore/property.h"
43#include "MagickCore/blob.h"
44#include "MagickCore/blob-private.h"
45#include "MagickCore/cache-private.h"
46#include "MagickCore/color-private.h"
47#include "MagickCore/colorspace-private.h"
48#include "MagickCore/draw.h"
49#include "MagickCore/exception.h"
50#include "MagickCore/exception-private.h"
51#include "MagickCore/cache.h"
52#include "MagickCore/constitute.h"
53#include "MagickCore/delegate.h"
54#include "MagickCore/geometry.h"
55#include "MagickCore/image-private.h"
56#include "MagickCore/list.h"
57#include "MagickCore/magick.h"
58#include "MagickCore/memory_.h"
59#include "MagickCore/memory-private.h"
60#include "MagickCore/monitor.h"
61#include "MagickCore/option.h"
62#include "MagickCore/pixel.h"
63#include "MagickCore/pixel-accessor.h"
64#include "MagickCore/pixel-private.h"
65#include "MagickCore/quantum.h"
66#include "MagickCore/quantum-private.h"
67#include "MagickCore/resource_.h"
68#include "MagickCore/semaphore.h"
69#include "MagickCore/statistic.h"
70#include "MagickCore/stream.h"
71#include "MagickCore/string_.h"
72#include "MagickCore/transform.h"
73#include "MagickCore/utility.h"
93MagickExport PixelChannelMap *AcquirePixelChannelMap(
void)
101 channel_map=(PixelChannelMap *) AcquireQuantumMemory(MaxPixelChannels+1,
102 sizeof(*channel_map));
103 if (channel_map == (PixelChannelMap *) NULL)
104 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
105 (void) memset(channel_map,0,(MaxPixelChannels+1)*
sizeof(*channel_map));
106 for (i=0; i <= MaxPixelChannels; i++)
107 channel_map[i].channel=(PixelChannel) i;
133MagickExport PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
138 assert(channel_map != (PixelChannelMap *) NULL);
139 clone_map=AcquirePixelChannelMap();
140 if (clone_map == (PixelChannelMap *) NULL)
141 return((PixelChannelMap *) NULL);
142 (void) memcpy(clone_map,channel_map,MaxPixelChannels*
sizeof(*channel_map));
169MagickExport PixelInfo *ClonePixelInfo(
const PixelInfo *pixel)
174 pixel_info=(PixelInfo *) AcquireMagickMemory(
sizeof(*pixel_info));
175 if (pixel_info == (PixelInfo *) NULL)
176 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
177 *pixel_info=(*pixel);
211MagickExport
void ConformPixelInfo(Image *image,
const PixelInfo *source,
212 PixelInfo *destination,ExceptionInfo *exception)
214 assert(image != (Image *) NULL);
215 assert(image->signature == MagickCoreSignature);
216 assert(destination != (
const PixelInfo *) NULL);
217 *destination=(*source);
218 ConformPixelInfoColorspace(image,destination,exception);
219 if (image->colorspace == CMYKColorspace)
221 if (IssRGBCompatibleColorspace(destination->colorspace) != MagickFalse)
222 ConvertRGBToCMYK(destination);
225 if (destination->colorspace == CMYKColorspace)
227 if (IssRGBCompatibleColorspace(image->colorspace) != MagickFalse)
228 ConvertCMYKToRGB(destination);
230 if ((IsPixelInfoGray(&image->background_color) == MagickFalse) &&
231 (IsGrayColorspace(image->colorspace) != MagickFalse))
232 (void) TransformImageColorspace(image,sRGBColorspace,exception);
233 if ((destination->alpha_trait != UndefinedPixelTrait) &&
234 ((image->alpha_trait & BlendPixelTrait) == 0))
235 (void) SetImageAlpha(image,OpaqueAlpha,exception);
261static inline double DecodeGamma(
const double x)
273 static const double coefficient[] =
275 1.7917488588043277509,
276 0.82045614371976854984,
277 0.027694100686325412819,
278 -0.00094244335181762134018,
279 0.000064355540911469709545,
280 -5.7224404636060757485e-06,
281 5.8767669437311184313e-07,
282 -6.6139920053589721168e-08,
283 7.9323242696227458163e-09
286 static const double powers_of_two[] =
289 2.6390158215457883983,
290 6.9644045063689921093,
291 1.8379173679952558018e+01,
292 4.8502930128332728543e+01
299 term[1]=4.0*frexp(x,&exponent)-3.0;
300 term[2]=2.0*term[1]*term[1]-term[0];
301 term[3]=2.0*term[1]*term[2]-term[1];
302 term[4]=2.0*term[1]*term[3]-term[2];
303 term[5]=2.0*term[1]*term[4]-term[3];
304 term[6]=2.0*term[1]*term[5]-term[4];
305 term[7]=2.0*term[1]*term[6]-term[5];
306 term[8]=2.0*term[1]*term[7]-term[6];
307 p=coefficient[0]*term[0]+coefficient[1]*term[1]+coefficient[2]*term[2]+
308 coefficient[3]*term[3]+coefficient[4]*term[4]+coefficient[5]*term[5]+
309 coefficient[6]*term[6]+coefficient[7]*term[7]+coefficient[8]*term[8];
310 quotient=div(exponent-1,5);
311 if (quotient.rem < 0)
316 return(x*ldexp(powers_of_two[quotient.rem]*p,7*quotient.quot));
319MagickExport MagickRealType DecodePixelGamma(
const MagickRealType pixel)
321 if (pixel <= (0.0404482362771076*(
double) QuantumRange))
323 return((MagickRealType) ((
double) QuantumRange*DecodeGamma((
double)
324 (QuantumScale*pixel+0.055)/1.055)));
350MagickExport PixelChannelMap *DestroyPixelChannelMap(
351 PixelChannelMap *channel_map)
353 assert(channel_map != (PixelChannelMap *) NULL);
354 channel_map=(PixelChannelMap *) RelinquishMagickMemory(channel_map);
355 return((PixelChannelMap *) RelinquishMagickMemory(channel_map));
381static inline double EncodeGamma(
const double x)
393 static const double coefficient[] =
395 1.1758200232996901923,
396 0.16665763094889061230,
397 -0.0083154894939042125035,
398 0.00075187976780420279038,
399 -0.000083240178519391795367,
400 0.000010229209410070008679,
401 -1.3400466409860246e-06,
402 1.8333422241635376682e-07,
403 -2.5878596761348859722e-08
406 static const double powers_of_two[] =
409 1.3348398541700343678,
410 1.7817974362806785482,
411 2.3784142300054420538,
412 3.1748021039363991669,
413 4.2378523774371812394,
414 5.6568542494923805819,
415 7.5509945014535482244,
416 1.0079368399158985525e1,
417 1.3454342644059433809e1,
418 1.7959392772949968275e1,
419 2.3972913230026907883e1
426 term[1]=4.0*frexp(x,&exponent)-3.0;
427 term[2]=2.0*term[1]*term[1]-term[0];
428 term[3]=2.0*term[1]*term[2]-term[1];
429 term[4]=2.0*term[1]*term[3]-term[2];
430 term[5]=2.0*term[1]*term[4]-term[3];
431 term[6]=2.0*term[1]*term[5]-term[4];
432 term[7]=2.0*term[1]*term[6]-term[5];
433 term[8]=2.0*term[1]*term[7]-term[6];
434 p=coefficient[0]*term[0]+coefficient[1]*term[1]+coefficient[2]*term[2]+
435 coefficient[3]*term[3]+coefficient[4]*term[4]+coefficient[5]*term[5]+
436 coefficient[6]*term[6]+coefficient[7]*term[7]+coefficient[8]*term[8];
437 quotient=div(exponent-1,12);
438 if (quotient.rem < 0)
443 return(ldexp(powers_of_two[quotient.rem]*p,5*quotient.quot));
446MagickExport MagickRealType EncodePixelGamma(
const MagickRealType pixel)
448 if (pixel <= (0.0031306684425005883*(
double) QuantumRange))
450 return((MagickRealType) QuantumRange*(1.055*EncodeGamma((
double) QuantumScale*
509static MagickBooleanType ExportCharPixel(
const Image *image,
510 const RectangleInfo *roi,
const char *magick_restrict map,
511 const QuantumType *quantum_map,
void *pixels,ExceptionInfo *exception)
528 q=(
unsigned char *) pixels;
529 if (LocaleCompare(map,
"BGR") == 0)
531 for (y=0; y < (ssize_t) roi->height; y++)
533 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
534 if (p == (
const Quantum *) NULL)
536 for (x=0; x < (ssize_t) roi->width; x++)
538 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
539 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
540 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
541 p+=(ptrdiff_t) GetPixelChannels(image);
544 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
546 if (LocaleCompare(map,
"BGRA") == 0)
548 for (y=0; y < (ssize_t) roi->height; y++)
550 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
551 if (p == (
const Quantum *) NULL)
553 for (x=0; x < (ssize_t) roi->width; x++)
555 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
556 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
557 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
558 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
559 p+=(ptrdiff_t) GetPixelChannels(image);
562 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
564 if (LocaleCompare(map,
"BGRP") == 0)
566 for (y=0; y < (ssize_t) roi->height; y++)
568 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
569 if (p == (
const Quantum *) NULL)
571 for (x=0; x < (ssize_t) roi->width; x++)
573 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
574 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
575 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
576 *q++=ScaleQuantumToChar((Quantum) 0);
577 p+=(ptrdiff_t) GetPixelChannels(image);
580 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
582 if (LocaleCompare(map,
"I") == 0)
584 for (y=0; y < (ssize_t) roi->height; y++)
586 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
587 if (p == (
const Quantum *) NULL)
589 for (x=0; x < (ssize_t) roi->width; x++)
591 *q++=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
592 p+=(ptrdiff_t) GetPixelChannels(image);
595 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
597 if (LocaleCompare(map,
"RGB") == 0)
599 for (y=0; y < (ssize_t) roi->height; y++)
601 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
602 if (p == (
const Quantum *) NULL)
604 for (x=0; x < (ssize_t) roi->width; x++)
606 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
607 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
608 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
609 p+=(ptrdiff_t) GetPixelChannels(image);
612 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
614 if (LocaleCompare(map,
"RGBA") == 0)
616 for (y=0; y < (ssize_t) roi->height; y++)
618 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
619 if (p == (
const Quantum *) NULL)
621 for (x=0; x < (ssize_t) roi->width; x++)
623 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
624 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
625 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
626 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
627 p+=(ptrdiff_t) GetPixelChannels(image);
630 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
632 if (LocaleCompare(map,
"RGBP") == 0)
634 for (y=0; y < (ssize_t) roi->height; y++)
636 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
637 if (p == (
const Quantum *) NULL)
639 for (x=0; x < (ssize_t) roi->width; x++)
641 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
642 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
643 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
644 *q++=ScaleQuantumToChar((Quantum) 0);
645 p+=(ptrdiff_t) GetPixelChannels(image);
648 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
651 for (y=0; y < (ssize_t) roi->height; y++)
653 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
654 if (p == (
const Quantum *) NULL)
656 for (x=0; x < (ssize_t) roi->width; x++)
661 for (i=0; i < (ssize_t) length; i++)
664 switch (quantum_map[i])
669 *q=ScaleQuantumToChar(GetPixelRed(image,p));
675 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
681 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
686 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
691 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
696 if (image->colorspace == CMYKColorspace)
697 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
702 *q=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
710 p+=(ptrdiff_t) GetPixelChannels(image);
713 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
716static MagickBooleanType ExportDoublePixel(
const Image *image,
717 const RectangleInfo *roi,
const char *magick_restrict map,
718 const QuantumType *quantum_map,
void *pixels,ExceptionInfo *exception)
736 if (LocaleCompare(map,
"BGR") == 0)
738 for (y=0; y < (ssize_t) roi->height; y++)
740 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
741 if (p == (
const Quantum *) NULL)
743 for (x=0; x < (ssize_t) roi->width; x++)
745 *q++=QuantumScale*(double) GetPixelBlue(image,p);
746 *q++=QuantumScale*(double) GetPixelGreen(image,p);
747 *q++=QuantumScale*(double) GetPixelRed(image,p);
748 p+=(ptrdiff_t) GetPixelChannels(image);
751 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
753 if (LocaleCompare(map,
"BGRA") == 0)
755 for (y=0; y < (ssize_t) roi->height; y++)
757 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
758 if (p == (
const Quantum *) NULL)
760 for (x=0; x < (ssize_t) roi->width; x++)
762 *q++=QuantumScale*(double) GetPixelBlue(image,p);
763 *q++=QuantumScale*(double) GetPixelGreen(image,p);
764 *q++=QuantumScale*(double) GetPixelRed(image,p);
765 *q++=QuantumScale*(double) GetPixelAlpha(image,p);
766 p+=(ptrdiff_t) GetPixelChannels(image);
769 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
771 if (LocaleCompare(map,
"BGRP") == 0)
773 for (y=0; y < (ssize_t) roi->height; y++)
775 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
776 if (p == (
const Quantum *) NULL)
778 for (x=0; x < (ssize_t) roi->width; x++)
780 *q++=QuantumScale*(double) GetPixelBlue(image,p);
781 *q++=QuantumScale*(double) GetPixelGreen(image,p);
782 *q++=QuantumScale*(double) GetPixelRed(image,p);
784 p+=(ptrdiff_t) GetPixelChannels(image);
787 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
789 if (LocaleCompare(map,
"I") == 0)
791 for (y=0; y < (ssize_t) roi->height; y++)
793 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
794 if (p == (
const Quantum *) NULL)
796 for (x=0; x < (ssize_t) roi->width; x++)
798 *q++=(double) (QuantumScale*(
double) GetPixelIntensity(image,p));
799 p+=(ptrdiff_t) GetPixelChannels(image);
802 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
804 if (LocaleCompare(map,
"RGB") == 0)
806 for (y=0; y < (ssize_t) roi->height; y++)
808 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
809 if (p == (
const Quantum *) NULL)
811 for (x=0; x < (ssize_t) roi->width; x++)
813 *q++=QuantumScale*(double) GetPixelRed(image,p);
814 *q++=QuantumScale*(double) GetPixelGreen(image,p);
815 *q++=QuantumScale*(double) GetPixelBlue(image,p);
816 p+=(ptrdiff_t) GetPixelChannels(image);
819 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
821 if (LocaleCompare(map,
"RGBA") == 0)
823 for (y=0; y < (ssize_t) roi->height; y++)
825 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
826 if (p == (
const Quantum *) NULL)
828 for (x=0; x < (ssize_t) roi->width; x++)
830 *q++=QuantumScale*(double) GetPixelRed(image,p);
831 *q++=QuantumScale*(double) GetPixelGreen(image,p);
832 *q++=QuantumScale*(double) GetPixelBlue(image,p);
833 *q++=QuantumScale*(double) GetPixelAlpha(image,p);
834 p+=(ptrdiff_t) GetPixelChannels(image);
837 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
839 if (LocaleCompare(map,
"RGBP") == 0)
841 for (y=0; y < (ssize_t) roi->height; y++)
843 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
844 if (p == (
const Quantum *) NULL)
846 for (x=0; x < (ssize_t) roi->width; x++)
848 *q++=QuantumScale*(double) GetPixelRed(image,p);
849 *q++=QuantumScale*(double) GetPixelGreen(image,p);
850 *q++=QuantumScale*(double) GetPixelBlue(image,p);
852 p+=(ptrdiff_t) GetPixelChannels(image);
855 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
858 for (y=0; y < (ssize_t) roi->height; y++)
860 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
861 if (p == (
const Quantum *) NULL)
863 for (x=0; x < (ssize_t) roi->width; x++)
868 for (i=0; i < (ssize_t) length; i++)
871 switch (quantum_map[i])
876 *q=QuantumScale*(double) GetPixelRed(image,p);
882 *q=QuantumScale*(double) GetPixelGreen(image,p);
888 *q=QuantumScale*(double) GetPixelBlue(image,p);
893 *q=QuantumScale*(double) GetPixelAlpha(image,p);
898 *q=QuantumScale*(double) GetPixelAlpha(image,p);
903 if (image->colorspace == CMYKColorspace)
904 *q=QuantumScale*(double) GetPixelBlack(image,p);
909 *q=QuantumScale*(double) GetPixelIntensity(image,p);
917 p+=(ptrdiff_t) GetPixelChannels(image);
920 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
923static MagickBooleanType ExportFloatPixel(
const Image *image,
924 const RectangleInfo *roi,
const char *magick_restrict map,
925 const QuantumType *quantum_map,
void *pixels,ExceptionInfo *exception)
943 if (LocaleCompare(map,
"BGR") == 0)
945 for (y=0; y < (ssize_t) roi->height; y++)
947 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
948 if (p == (
const Quantum *) NULL)
950 for (x=0; x < (ssize_t) roi->width; x++)
952 *q++=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
953 *q++=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
954 *q++=(float) (QuantumScale*(
double) GetPixelRed(image,p));
955 p+=(ptrdiff_t) GetPixelChannels(image);
958 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
960 if (LocaleCompare(map,
"BGRA") == 0)
962 for (y=0; y < (ssize_t) roi->height; y++)
964 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
965 if (p == (
const Quantum *) NULL)
967 for (x=0; x < (ssize_t) roi->width; x++)
969 *q++=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
970 *q++=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
971 *q++=(float) (QuantumScale*(
double) GetPixelRed(image,p));
972 *q++=(float) (QuantumScale*(
double) GetPixelAlpha(image,p));
973 p+=(ptrdiff_t) GetPixelChannels(image);
976 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
978 if (LocaleCompare(map,
"BGRP") == 0)
980 for (y=0; y < (ssize_t) roi->height; y++)
982 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
983 if (p == (
const Quantum *) NULL)
985 for (x=0; x < (ssize_t) roi->width; x++)
987 *q++=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
988 *q++=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
989 *q++=(float) (QuantumScale*(
double) GetPixelRed(image,p));
991 p+=(ptrdiff_t) GetPixelChannels(image);
994 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
996 if (LocaleCompare(map,
"I") == 0)
998 for (y=0; y < (ssize_t) roi->height; y++)
1000 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1001 if (p == (
const Quantum *) NULL)
1003 for (x=0; x < (ssize_t) roi->width; x++)
1005 *q++=(float) (QuantumScale*(
double) GetPixelIntensity(image,p));
1006 p+=(ptrdiff_t) GetPixelChannels(image);
1009 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1011 if (LocaleCompare(map,
"RGB") == 0)
1013 for (y=0; y < (ssize_t) roi->height; y++)
1015 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1016 if (p == (
const Quantum *) NULL)
1018 for (x=0; x < (ssize_t) roi->width; x++)
1020 *q++=(float) (QuantumScale*(
double) GetPixelRed(image,p));
1021 *q++=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
1022 *q++=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
1023 p+=(ptrdiff_t) GetPixelChannels(image);
1026 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1028 if (LocaleCompare(map,
"RGBA") == 0)
1030 for (y=0; y < (ssize_t) roi->height; y++)
1032 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1033 if (p == (
const Quantum *) NULL)
1035 for (x=0; x < (ssize_t) roi->width; x++)
1037 *q++=(float) (QuantumScale*(
double) GetPixelRed(image,p));
1038 *q++=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
1039 *q++=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
1040 *q++=(float) (QuantumScale*(
double) GetPixelAlpha(image,p));
1041 p+=(ptrdiff_t) GetPixelChannels(image);
1044 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1046 if (LocaleCompare(map,
"RGBP") == 0)
1048 for (y=0; y < (ssize_t) roi->height; y++)
1050 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1051 if (p == (
const Quantum *) NULL)
1053 for (x=0; x < (ssize_t) roi->width; x++)
1055 *q++=(float) (QuantumScale*(
double) GetPixelRed(image,p));
1056 *q++=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
1057 *q++=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
1059 p+=(ptrdiff_t) GetPixelChannels(image);
1062 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1065 for (y=0; y < (ssize_t) roi->height; y++)
1067 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1068 if (p == (
const Quantum *) NULL)
1070 for (x=0; x < (ssize_t) roi->width; x++)
1075 for (i=0; i < (ssize_t) length; i++)
1078 switch (quantum_map[i])
1083 *q=(float) (QuantumScale*(
double) GetPixelRed(image,p));
1087 case MagentaQuantum:
1089 *q=(float) (QuantumScale*(
double) GetPixelGreen(image,p));
1095 *q=(float) (QuantumScale*(
double) GetPixelBlue(image,p));
1100 *q=(float) (QuantumScale*((
double) (GetPixelAlpha(image,p))));
1103 case OpacityQuantum:
1105 *q=(float) (QuantumScale*(
double) GetPixelAlpha(image,p));
1110 if (image->colorspace == CMYKColorspace)
1111 *q=(float) (QuantumScale*(
double) GetPixelBlack(image,p));
1116 *q=(float) (QuantumScale*(
double) GetPixelIntensity(image,p));
1124 p+=(ptrdiff_t) GetPixelChannels(image);
1127 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1130static MagickBooleanType ExportLongPixel(
const Image *image,
1131 const RectangleInfo *roi,
const char *magick_restrict map,
1132 const QuantumType *quantum_map,
void *pixels,ExceptionInfo *exception)
1149 q=(
unsigned int *) pixels;
1150 if (LocaleCompare(map,
"BGR") == 0)
1152 for (y=0; y < (ssize_t) roi->height; y++)
1154 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1155 if (p == (
const Quantum *) NULL)
1157 for (x=0; x < (ssize_t) roi->width; x++)
1159 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1160 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1161 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1162 p+=(ptrdiff_t) GetPixelChannels(image);
1165 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1167 if (LocaleCompare(map,
"BGRA") == 0)
1169 for (y=0; y < (ssize_t) roi->height; y++)
1171 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1172 if (p == (
const Quantum *) NULL)
1174 for (x=0; x < (ssize_t) roi->width; x++)
1176 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1177 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1178 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1179 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1180 p+=(ptrdiff_t) GetPixelChannels(image);
1183 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1185 if (LocaleCompare(map,
"BGRP") == 0)
1187 for (y=0; y < (ssize_t) roi->height; y++)
1189 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1190 if (p == (
const Quantum *) NULL)
1192 for (x=0; x < (ssize_t) roi->width; x++)
1194 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1195 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1196 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1198 p+=(ptrdiff_t) GetPixelChannels(image);
1201 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1203 if (LocaleCompare(map,
"I") == 0)
1205 for (y=0; y < (ssize_t) roi->height; y++)
1207 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1208 if (p == (
const Quantum *) NULL)
1210 for (x=0; x < (ssize_t) roi->width; x++)
1212 *q++=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
1213 p+=(ptrdiff_t) GetPixelChannels(image);
1216 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1218 if (LocaleCompare(map,
"RGB") == 0)
1220 for (y=0; y < (ssize_t) roi->height; y++)
1222 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1223 if (p == (
const Quantum *) NULL)
1225 for (x=0; x < (ssize_t) roi->width; x++)
1227 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1228 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1229 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1230 p+=(ptrdiff_t) GetPixelChannels(image);
1233 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1235 if (LocaleCompare(map,
"RGBA") == 0)
1237 for (y=0; y < (ssize_t) roi->height; y++)
1239 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1240 if (p == (
const Quantum *) NULL)
1242 for (x=0; x < (ssize_t) roi->width; x++)
1244 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1245 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1246 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1247 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1248 p+=(ptrdiff_t) GetPixelChannels(image);
1251 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1253 if (LocaleCompare(map,
"RGBP") == 0)
1255 for (y=0; y < (ssize_t) roi->height; y++)
1257 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1258 if (p == (
const Quantum *) NULL)
1260 for (x=0; x < (ssize_t) roi->width; x++)
1262 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1263 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1264 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1266 p+=(ptrdiff_t) GetPixelChannels(image);
1269 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1272 for (y=0; y < (ssize_t) roi->height; y++)
1274 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1275 if (p == (
const Quantum *) NULL)
1277 for (x=0; x < (ssize_t) roi->width; x++)
1282 for (i=0; i < (ssize_t) length; i++)
1285 switch (quantum_map[i])
1290 *q=ScaleQuantumToLong(GetPixelRed(image,p));
1294 case MagentaQuantum:
1296 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
1302 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
1307 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1310 case OpacityQuantum:
1312 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1317 if (image->colorspace == CMYKColorspace)
1318 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
1323 *q=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
1331 p+=(ptrdiff_t) GetPixelChannels(image);
1334 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1337static MagickBooleanType ExportLongLongPixel(
const Image *image,
1338 const RectangleInfo *roi,
const char *magick_restrict map,
1339 const QuantumType *quantum_map,
void *pixels,ExceptionInfo *exception)
1356 q=(MagickSizeType *) pixels;
1357 if (LocaleCompare(map,
"BGR") == 0)
1359 for (y=0; y < (ssize_t) roi->height; y++)
1361 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1362 if (p == (
const Quantum *) NULL)
1364 for (x=0; x < (ssize_t) roi->width; x++)
1366 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1367 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1368 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1369 p+=(ptrdiff_t) GetPixelChannels(image);
1372 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1374 if (LocaleCompare(map,
"BGRA") == 0)
1376 for (y=0; y < (ssize_t) roi->height; y++)
1378 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1379 if (p == (
const Quantum *) NULL)
1381 for (x=0; x < (ssize_t) roi->width; x++)
1383 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1384 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1385 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1386 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1387 p+=(ptrdiff_t) GetPixelChannels(image);
1390 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1392 if (LocaleCompare(map,
"BGRP") == 0)
1394 for (y=0; y < (ssize_t) roi->height; y++)
1396 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1397 if (p == (
const Quantum *) NULL)
1399 for (x=0; x < (ssize_t) roi->width; x++)
1401 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1402 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1403 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1405 p+=(ptrdiff_t) GetPixelChannels(image);
1408 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1410 if (LocaleCompare(map,
"I") == 0)
1412 for (y=0; y < (ssize_t) roi->height; y++)
1414 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1415 if (p == (
const Quantum *) NULL)
1417 for (x=0; x < (ssize_t) roi->width; x++)
1419 *q++=ScaleQuantumToLongLong(ClampToQuantum(
1420 GetPixelIntensity(image,p)));
1421 p+=(ptrdiff_t) GetPixelChannels(image);
1424 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1426 if (LocaleCompare(map,
"RGB") == 0)
1428 for (y=0; y < (ssize_t) roi->height; y++)
1430 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1431 if (p == (
const Quantum *) NULL)
1433 for (x=0; x < (ssize_t) roi->width; x++)
1435 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1436 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1437 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1438 p+=(ptrdiff_t) GetPixelChannels(image);
1441 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1443 if (LocaleCompare(map,
"RGBA") == 0)
1445 for (y=0; y < (ssize_t) roi->height; y++)
1447 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1448 if (p == (
const Quantum *) NULL)
1450 for (x=0; x < (ssize_t) roi->width; x++)
1452 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1453 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1454 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1455 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1456 p+=(ptrdiff_t) GetPixelChannels(image);
1459 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1461 if (LocaleCompare(map,
"RGBP") == 0)
1463 for (y=0; y < (ssize_t) roi->height; y++)
1465 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1466 if (p == (
const Quantum *) NULL)
1468 for (x=0; x < (ssize_t) roi->width; x++)
1470 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1471 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1472 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1474 p+=(ptrdiff_t) GetPixelChannels(image);
1477 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1480 for (y=0; y < (ssize_t) roi->height; y++)
1482 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1483 if (p == (
const Quantum *) NULL)
1485 for (x=0; x < (ssize_t) roi->width; x++)
1490 for (i=0; i < (ssize_t) length; i++)
1493 switch (quantum_map[i])
1498 *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
1502 case MagentaQuantum:
1504 *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1510 *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1515 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1518 case OpacityQuantum:
1520 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1525 if (image->colorspace == CMYKColorspace)
1526 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
1531 *q=ScaleQuantumToLongLong(ClampToQuantum(
1532 GetPixelIntensity(image,p)));
1540 p+=(ptrdiff_t) GetPixelChannels(image);
1543 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1546static MagickBooleanType ExportQuantumPixel(
const Image *image,
1547 const RectangleInfo *roi,
const char *magick_restrict map,
1548 const QuantumType *quantum_map,
void *pixels,ExceptionInfo *exception)
1565 q=(Quantum *) pixels;
1566 if (LocaleCompare(map,
"BGR") == 0)
1568 for (y=0; y < (ssize_t) roi->height; y++)
1570 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1571 if (p == (
const Quantum *) NULL)
1573 for (x=0; x < (ssize_t) roi->width; x++)
1575 *q++=GetPixelBlue(image,p);
1576 *q++=GetPixelGreen(image,p);
1577 *q++=GetPixelRed(image,p);
1578 p+=(ptrdiff_t) GetPixelChannels(image);
1581 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1583 if (LocaleCompare(map,
"BGRA") == 0)
1585 for (y=0; y < (ssize_t) roi->height; y++)
1587 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1588 if (p == (
const Quantum *) NULL)
1590 for (x=0; x < (ssize_t) roi->width; x++)
1592 *q++=GetPixelBlue(image,p);
1593 *q++=GetPixelGreen(image,p);
1594 *q++=GetPixelRed(image,p);
1595 *q++=(Quantum) (GetPixelAlpha(image,p));
1596 p+=(ptrdiff_t) GetPixelChannels(image);
1599 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1601 if (LocaleCompare(map,
"BGRP") == 0)
1603 for (y=0; y < (ssize_t) roi->height; y++)
1605 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1606 if (p == (
const Quantum *) NULL)
1608 for (x=0; x < (ssize_t) roi->width; x++)
1610 *q++=GetPixelBlue(image,p);
1611 *q++=GetPixelGreen(image,p);
1612 *q++=GetPixelRed(image,p);
1614 p+=(ptrdiff_t) GetPixelChannels(image);
1617 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1619 if (LocaleCompare(map,
"I") == 0)
1621 for (y=0; y < (ssize_t) roi->height; y++)
1623 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1624 if (p == (
const Quantum *) NULL)
1626 for (x=0; x < (ssize_t) roi->width; x++)
1628 *q++=ClampToQuantum(GetPixelIntensity(image,p));
1629 p+=(ptrdiff_t) GetPixelChannels(image);
1632 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1634 if (LocaleCompare(map,
"RGB") == 0)
1636 for (y=0; y < (ssize_t) roi->height; y++)
1638 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1639 if (p == (
const Quantum *) NULL)
1641 for (x=0; x < (ssize_t) roi->width; x++)
1643 *q++=GetPixelRed(image,p);
1644 *q++=GetPixelGreen(image,p);
1645 *q++=GetPixelBlue(image,p);
1646 p+=(ptrdiff_t) GetPixelChannels(image);
1649 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1651 if (LocaleCompare(map,
"RGBA") == 0)
1653 for (y=0; y < (ssize_t) roi->height; y++)
1655 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1656 if (p == (
const Quantum *) NULL)
1658 for (x=0; x < (ssize_t) roi->width; x++)
1660 *q++=GetPixelRed(image,p);
1661 *q++=GetPixelGreen(image,p);
1662 *q++=GetPixelBlue(image,p);
1663 *q++=(Quantum) (GetPixelAlpha(image,p));
1664 p+=(ptrdiff_t) GetPixelChannels(image);
1667 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1669 if (LocaleCompare(map,
"RGBP") == 0)
1671 for (y=0; y < (ssize_t) roi->height; y++)
1673 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1674 if (p == (
const Quantum *) NULL)
1676 for (x=0; x < (ssize_t) roi->width; x++)
1678 *q++=GetPixelRed(image,p);
1679 *q++=GetPixelGreen(image,p);
1680 *q++=GetPixelBlue(image,p);
1682 p+=(ptrdiff_t) GetPixelChannels(image);
1685 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1688 for (y=0; y < (ssize_t) roi->height; y++)
1690 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1691 if (p == (
const Quantum *) NULL)
1693 for (x=0; x < (ssize_t) roi->width; x++)
1698 for (i=0; i < (ssize_t) length; i++)
1701 switch (quantum_map[i])
1706 *q=GetPixelRed(image,p);
1710 case MagentaQuantum:
1712 *q=GetPixelGreen(image,p);
1718 *q=GetPixelBlue(image,p);
1723 *q=GetPixelAlpha(image,p);
1726 case OpacityQuantum:
1728 *q=GetPixelAlpha(image,p);
1733 if (image->colorspace == CMYKColorspace)
1734 *q=GetPixelBlack(image,p);
1739 *q=ClampToQuantum(GetPixelIntensity(image,p));
1750 p+=(ptrdiff_t) GetPixelChannels(image);
1753 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1756static MagickBooleanType ExportShortPixel(
const Image *image,
1757 const RectangleInfo *roi,
const char *magick_restrict map,
1758 const QuantumType *quantum_map,
void *pixels,ExceptionInfo *exception)
1775 q=(
unsigned short *) pixels;
1776 if (LocaleCompare(map,
"BGR") == 0)
1778 for (y=0; y < (ssize_t) roi->height; y++)
1780 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1781 if (p == (
const Quantum *) NULL)
1783 for (x=0; x < (ssize_t) roi->width; x++)
1785 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1786 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1787 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1788 p+=(ptrdiff_t) GetPixelChannels(image);
1791 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1793 if (LocaleCompare(map,
"BGRA") == 0)
1795 for (y=0; y < (ssize_t) roi->height; y++)
1797 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1798 if (p == (
const Quantum *) NULL)
1800 for (x=0; x < (ssize_t) roi->width; x++)
1802 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1803 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1804 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1805 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1806 p+=(ptrdiff_t) GetPixelChannels(image);
1809 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1811 if (LocaleCompare(map,
"BGRP") == 0)
1813 for (y=0; y < (ssize_t) roi->height; y++)
1815 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1816 if (p == (
const Quantum *) NULL)
1818 for (x=0; x < (ssize_t) roi->width; x++)
1820 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1821 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1822 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1824 p+=(ptrdiff_t) GetPixelChannels(image);
1827 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1829 if (LocaleCompare(map,
"I") == 0)
1831 for (y=0; y < (ssize_t) roi->height; y++)
1833 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1834 if (p == (
const Quantum *) NULL)
1836 for (x=0; x < (ssize_t) roi->width; x++)
1838 *q++=ScaleQuantumToShort(ClampToQuantum(GetPixelIntensity(image,p)));
1839 p+=(ptrdiff_t) GetPixelChannels(image);
1842 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1844 if (LocaleCompare(map,
"RGB") == 0)
1846 for (y=0; y < (ssize_t) roi->height; y++)
1848 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1849 if (p == (
const Quantum *) NULL)
1851 for (x=0; x < (ssize_t) roi->width; x++)
1853 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1854 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1855 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1856 p+=(ptrdiff_t) GetPixelChannels(image);
1859 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1861 if (LocaleCompare(map,
"RGBA") == 0)
1863 for (y=0; y < (ssize_t) roi->height; y++)
1865 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1866 if (p == (
const Quantum *) NULL)
1868 for (x=0; x < (ssize_t) roi->width; x++)
1870 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1871 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1872 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1873 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1874 p+=(ptrdiff_t) GetPixelChannels(image);
1877 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1879 if (LocaleCompare(map,
"RGBP") == 0)
1881 for (y=0; y < (ssize_t) roi->height; y++)
1883 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1884 if (p == (
const Quantum *) NULL)
1886 for (x=0; x < (ssize_t) roi->width; x++)
1888 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1889 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1890 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1892 p+=(ptrdiff_t) GetPixelChannels(image);
1895 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1898 for (y=0; y < (ssize_t) roi->height; y++)
1900 p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1901 if (p == (
const Quantum *) NULL)
1903 for (x=0; x < (ssize_t) roi->width; x++)
1908 for (i=0; i < (ssize_t) length; i++)
1911 switch (quantum_map[i])
1916 *q=ScaleQuantumToShort(GetPixelRed(image,p));
1920 case MagentaQuantum:
1922 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
1928 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
1933 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1936 case OpacityQuantum:
1938 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1943 if (image->colorspace == CMYKColorspace)
1944 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
1949 *q=ScaleQuantumToShort(ClampToQuantum(GetPixelIntensity(image,p)));
1957 p+=(ptrdiff_t) GetPixelChannels(image);
1960 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1963MagickExport MagickBooleanType ExportImagePixels(
const Image *image,
1964 const ssize_t x,
const ssize_t y,
const size_t width,
const size_t height,
1965 const char *map,
const StorageType type,
void *pixels,ExceptionInfo *exception)
1982 assert(image != (Image *) NULL);
1983 assert(image->signature == MagickCoreSignature);
1984 if (IsEventLogging() != MagickFalse)
1985 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1987 quantum_map=(QuantumType *) AcquireQuantumMemory(length,
sizeof(*quantum_map));
1988 if (quantum_map == (QuantumType *) NULL)
1990 (void) ThrowMagickException(exception,GetMagickModule(),
1991 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",image->filename);
1992 return(MagickFalse);
1994 for (i=0; i < (ssize_t) length; i++)
2001 quantum_map[i]=AlphaQuantum;
2007 quantum_map[i]=BlueQuantum;
2013 quantum_map[i]=CyanQuantum;
2014 if (image->colorspace == CMYKColorspace)
2016 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2017 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2018 "ColorSeparatedImageRequired",
"`%s'",map);
2019 return(MagickFalse);
2024 quantum_map[i]=GreenQuantum;
2030 quantum_map[i]=IndexQuantum;
2036 quantum_map[i]=BlackQuantum;
2037 if (image->colorspace == CMYKColorspace)
2039 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2040 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2041 "ColorSeparatedImageRequired",
"`%s'",map);
2042 return(MagickFalse);
2047 quantum_map[i]=MagentaQuantum;
2048 if (image->colorspace == CMYKColorspace)
2050 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2051 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2052 "ColorSeparatedImageRequired",
"`%s'",map);
2053 return(MagickFalse);
2058 quantum_map[i]=OpacityQuantum;
2064 quantum_map[i]=UndefinedQuantum;
2070 quantum_map[i]=RedQuantum;
2076 quantum_map[i]=YellowQuantum;
2077 if (image->colorspace == CMYKColorspace)
2079 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2080 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2081 "ColorSeparatedImageRequired",
"`%s'",map);
2082 return(MagickFalse);
2086 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2087 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2088 "UnrecognizedPixelMap",
"`%s'",map);
2089 return(MagickFalse);
2101 status=ExportCharPixel(image,&roi,map,quantum_map,pixels,exception);
2106 status=ExportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
2111 status=ExportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
2116 status=ExportLongPixel(image,&roi,map,quantum_map,pixels,exception);
2121 status=ExportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
2126 status=ExportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
2131 status=ExportShortPixel(image,&roi,map,quantum_map,pixels,exception);
2136 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2137 "UnrecognizedPixelMap",
"`%s'",map);
2141 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2169MagickExport
void GetPixelInfo(
const Image *image,PixelInfo *pixel)
2171 (void) memset(pixel,0,
sizeof(*pixel));
2172 pixel->storage_class=DirectClass;
2173 pixel->colorspace=sRGBColorspace;
2174 pixel->depth=MAGICKCORE_QUANTUM_DEPTH;
2175 pixel->alpha_trait=UndefinedPixelTrait;
2176 pixel->alpha=(double) OpaqueAlpha;
2177 if (image == (
const Image *) NULL)
2179 pixel->storage_class=image->storage_class;
2180 pixel->colorspace=image->colorspace;
2181 pixel->alpha_trait=image->alpha_trait;
2182 pixel->depth=image->depth;
2183 pixel->fuzz=image->fuzz;
2223MagickExport MagickRealType GetPixelInfoIntensity(
2224 const Image *magick_restrict image,
const PixelInfo *magick_restrict pixel)
2232 PixelIntensityMethod
2235 method=Rec709LumaPixelIntensityMethod;
2236 if (image != (
const Image *) NULL)
2237 method=image->intensity;
2243 case AveragePixelIntensityMethod:
2245 intensity=(red+green+blue)/3.0;
2248 case BrightnessPixelIntensityMethod:
2250 intensity=MagickMax(MagickMax(red,green),blue);
2253 case LightnessPixelIntensityMethod:
2255 intensity=(MagickMin(MagickMin(red,green),blue)+
2256 MagickMax(MagickMax(red,green),blue))/2.0;
2259 case MSPixelIntensityMethod:
2261 intensity=(MagickRealType) (((
double) red*red+green*green+blue*blue)/
2262 (3.0*(
double) QuantumRange));
2265 case Rec601LumaPixelIntensityMethod:
2267 if (pixel->colorspace == RGBColorspace)
2269 red=EncodePixelGamma(red);
2270 green=EncodePixelGamma(green);
2271 blue=EncodePixelGamma(blue);
2273 intensity=0.298839*red+0.586811*green+0.114350*blue;
2276 case Rec601LuminancePixelIntensityMethod:
2278 if (pixel->colorspace == sRGBColorspace)
2280 red=DecodePixelGamma(red);
2281 green=DecodePixelGamma(green);
2282 blue=DecodePixelGamma(blue);
2284 intensity=0.298839*red+0.586811*green+0.114350*blue;
2287 case Rec709LumaPixelIntensityMethod:
2290 if (pixel->colorspace == RGBColorspace)
2292 red=EncodePixelGamma(red);
2293 green=EncodePixelGamma(green);
2294 blue=EncodePixelGamma(blue);
2296 intensity=0.212656*red+0.715158*green+0.072186*blue;
2299 case Rec709LuminancePixelIntensityMethod:
2301 if (pixel->colorspace == sRGBColorspace)
2303 red=DecodePixelGamma(red);
2304 green=DecodePixelGamma(green);
2305 blue=DecodePixelGamma(blue);
2307 intensity=0.212656*red+0.715158*green+0.072186*blue;
2310 case RMSPixelIntensityMethod:
2312 intensity=(MagickRealType) (sqrt((
double) red*red+green*green+blue*blue)/
2357MagickExport MagickRealType GetPixelIntensity(
2358 const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
2366 red=(MagickRealType) GetPixelRed(image,pixel);
2367 if (image->number_channels == 1)
2369 green=(MagickRealType) GetPixelGreen(image,pixel);
2370 blue=(MagickRealType) GetPixelBlue(image,pixel);
2371 switch (image->intensity)
2373 case AveragePixelIntensityMethod:
2375 intensity=(red+green+blue)/3.0;
2378 case BrightnessPixelIntensityMethod:
2380 intensity=MagickMax(MagickMax(red,green),blue);
2383 case LightnessPixelIntensityMethod:
2385 intensity=(MagickMin(MagickMin(red,green),blue)+
2386 MagickMax(MagickMax(red,green),blue))/2.0;
2389 case MSPixelIntensityMethod:
2391 intensity=(MagickRealType) (((
double) red*red+green*green+blue*blue)/
2392 (3.0*(
double) QuantumRange));
2395 case Rec601LumaPixelIntensityMethod:
2397 if ((image->colorspace == RGBColorspace) ||
2398 (image->colorspace == LinearGRAYColorspace))
2400 red=EncodePixelGamma(red);
2401 green=EncodePixelGamma(green);
2402 blue=EncodePixelGamma(blue);
2404 intensity=0.298839*red+0.586811*green+0.114350*blue;
2407 case Rec601LuminancePixelIntensityMethod:
2409 if ((image->colorspace == sRGBColorspace) ||
2410 (image->colorspace == GRAYColorspace))
2412 red=DecodePixelGamma(red);
2413 green=DecodePixelGamma(green);
2414 blue=DecodePixelGamma(blue);
2416 intensity=0.298839*red+0.586811*green+0.114350*blue;
2419 case Rec709LumaPixelIntensityMethod:
2422 if ((image->colorspace == RGBColorspace) ||
2423 (image->colorspace == LinearGRAYColorspace))
2425 red=EncodePixelGamma(red);
2426 green=EncodePixelGamma(green);
2427 blue=EncodePixelGamma(blue);
2429 intensity=0.212656*red+0.715158*green+0.072186*blue;
2432 case Rec709LuminancePixelIntensityMethod:
2434 if ((image->colorspace == sRGBColorspace) ||
2435 (image->colorspace == GRAYColorspace))
2437 red=DecodePixelGamma(red);
2438 green=DecodePixelGamma(green);
2439 blue=DecodePixelGamma(blue);
2441 intensity=0.212656*red+0.715158*green+0.072186*blue;
2444 case RMSPixelIntensityMethod:
2446 intensity=(MagickRealType) (sqrt((
double) red*red+green*green+blue*blue)/
2510static MagickBooleanType ImportCharPixel(Image *image,
const RectangleInfo *roi,
2511 const char *magick_restrict map,
const QuantumType *quantum_map,
2512 const void *pixels,ExceptionInfo *exception)
2529 p=(
const unsigned char *) pixels;
2530 if (LocaleCompare(map,
"BGR") == 0)
2532 for (y=0; y < (ssize_t) roi->height; y++)
2534 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2535 if (q == (Quantum *) NULL)
2537 for (x=0; x < (ssize_t) roi->width; x++)
2539 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2540 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2541 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2542 q+=(ptrdiff_t) GetPixelChannels(image);
2544 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2547 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2549 if (LocaleCompare(map,
"BGRA") == 0)
2551 for (y=0; y < (ssize_t) roi->height; y++)
2553 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2554 if (q == (Quantum *) NULL)
2556 for (x=0; x < (ssize_t) roi->width; x++)
2558 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2559 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2560 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2561 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2562 q+=(ptrdiff_t) GetPixelChannels(image);
2564 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2567 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2569 if (LocaleCompare(map,
"BGRO") == 0)
2571 for (y=0; y < (ssize_t) roi->height; y++)
2573 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2574 if (q == (Quantum *) NULL)
2576 for (x=0; x < (ssize_t) roi->width; x++)
2578 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2579 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2580 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2581 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2582 q+=(ptrdiff_t) GetPixelChannels(image);
2584 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2587 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2589 if (LocaleCompare(map,
"BGRP") == 0)
2591 for (y=0; y < (ssize_t) roi->height; y++)
2593 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2594 if (q == (Quantum *) NULL)
2596 for (x=0; x < (ssize_t) roi->width; x++)
2598 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2599 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2600 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2602 q+=(ptrdiff_t) GetPixelChannels(image);
2604 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2607 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2609 if (LocaleCompare(map,
"I") == 0)
2611 for (y=0; y < (ssize_t) roi->height; y++)
2613 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2614 if (q == (Quantum *) NULL)
2616 for (x=0; x < (ssize_t) roi->width; x++)
2618 SetPixelGray(image,ScaleCharToQuantum(*p++),q);
2619 q+=(ptrdiff_t) GetPixelChannels(image);
2621 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2624 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2626 if (LocaleCompare(map,
"RGB") == 0)
2628 for (y=0; y < (ssize_t) roi->height; y++)
2630 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2631 if (q == (Quantum *) NULL)
2633 for (x=0; x < (ssize_t) roi->width; x++)
2635 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2636 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2637 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2638 q+=(ptrdiff_t) GetPixelChannels(image);
2640 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2643 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2645 if (LocaleCompare(map,
"RGBA") == 0)
2647 for (y=0; y < (ssize_t) roi->height; y++)
2649 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2650 if (q == (Quantum *) NULL)
2652 for (x=0; x < (ssize_t) roi->width; x++)
2654 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2655 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2656 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2657 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2658 q+=(ptrdiff_t) GetPixelChannels(image);
2660 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2663 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2665 if (LocaleCompare(map,
"RGBO") == 0)
2667 for (y=0; y < (ssize_t) roi->height; y++)
2669 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2670 if (q == (Quantum *) NULL)
2672 for (x=0; x < (ssize_t) roi->width; x++)
2674 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2675 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2676 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2677 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2678 q+=(ptrdiff_t) GetPixelChannels(image);
2680 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2683 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2685 if (LocaleCompare(map,
"RGBP") == 0)
2687 for (y=0; y < (ssize_t) roi->height; y++)
2689 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2690 if (q == (Quantum *) NULL)
2692 for (x=0; x < (ssize_t) roi->width; x++)
2694 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2695 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2696 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2698 q+=(ptrdiff_t) GetPixelChannels(image);
2700 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2703 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2706 for (y=0; y < (ssize_t) roi->height; y++)
2708 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2709 if (q == (Quantum *) NULL)
2711 for (x=0; x < (ssize_t) roi->width; x++)
2716 for (i=0; i < (ssize_t) length; i++)
2718 switch (quantum_map[i])
2723 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2727 case MagentaQuantum:
2729 SetPixelGreen(image,ScaleCharToQuantum(*p),q);
2735 SetPixelBlue(image,ScaleCharToQuantum(*p),q);
2740 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2743 case OpacityQuantum:
2745 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2750 SetPixelBlack(image,ScaleCharToQuantum(*p),q);
2755 SetPixelGray(image,ScaleCharToQuantum(*p),q);
2763 q+=(ptrdiff_t) GetPixelChannels(image);
2765 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2768 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2771static MagickBooleanType ImportDoublePixel(Image *image,
2772 const RectangleInfo *roi,
const char *magick_restrict map,
2773 const QuantumType *quantum_map,
const void *pixels,ExceptionInfo *exception)
2790 p=(
const double *) pixels;
2791 if (LocaleCompare(map,
"BGR") == 0)
2793 for (y=0; y < (ssize_t) roi->height; y++)
2795 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2796 if (q == (Quantum *) NULL)
2798 for (x=0; x < (ssize_t) roi->width; x++)
2800 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2802 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2804 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2806 q+=(ptrdiff_t) GetPixelChannels(image);
2808 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2811 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2813 if (LocaleCompare(map,
"BGRA") == 0)
2815 for (y=0; y < (ssize_t) roi->height; y++)
2817 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2818 if (q == (Quantum *) NULL)
2820 for (x=0; x < (ssize_t) roi->width; x++)
2822 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2824 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2826 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2828 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2830 q+=(ptrdiff_t) GetPixelChannels(image);
2832 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2835 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2837 if (LocaleCompare(map,
"BGRP") == 0)
2839 for (y=0; y < (ssize_t) roi->height; y++)
2841 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2842 if (q == (Quantum *) NULL)
2844 for (x=0; x < (ssize_t) roi->width; x++)
2846 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2848 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2850 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2853 q+=(ptrdiff_t) GetPixelChannels(image);
2855 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2858 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2860 if (LocaleCompare(map,
"I") == 0)
2862 for (y=0; y < (ssize_t) roi->height; y++)
2864 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2865 if (q == (Quantum *) NULL)
2867 for (x=0; x < (ssize_t) roi->width; x++)
2869 SetPixelGray(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2871 q+=(ptrdiff_t) GetPixelChannels(image);
2873 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2876 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2878 if (LocaleCompare(map,
"RGB") == 0)
2880 for (y=0; y < (ssize_t) roi->height; y++)
2882 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2883 if (q == (Quantum *) NULL)
2885 for (x=0; x < (ssize_t) roi->width; x++)
2887 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2889 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2891 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2893 q+=(ptrdiff_t) GetPixelChannels(image);
2895 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2898 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2900 if (LocaleCompare(map,
"RGBA") == 0)
2902 for (y=0; y < (ssize_t) roi->height; y++)
2904 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2905 if (q == (Quantum *) NULL)
2907 for (x=0; x < (ssize_t) roi->width; x++)
2909 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2911 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2913 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2915 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2917 q+=(ptrdiff_t) GetPixelChannels(image);
2919 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2922 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2924 if (LocaleCompare(map,
"RGBP") == 0)
2926 for (y=0; y < (ssize_t) roi->height; y++)
2928 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2929 if (q == (Quantum *) NULL)
2931 for (x=0; x < (ssize_t) roi->width; x++)
2933 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2935 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2937 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2939 q+=(ptrdiff_t) GetPixelChannels(image);
2941 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2944 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2947 for (y=0; y < (ssize_t) roi->height; y++)
2949 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2950 if (q == (Quantum *) NULL)
2952 for (x=0; x < (ssize_t) roi->width; x++)
2957 for (i=0; i < (ssize_t) length; i++)
2959 switch (quantum_map[i])
2964 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2968 case MagentaQuantum:
2970 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2976 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2981 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2984 case OpacityQuantum:
2986 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2991 SetPixelBlack(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
2996 SetPixelGray(image,ClampToQuantum((
double) QuantumRange*(*p)),q);
3004 q+=(ptrdiff_t) GetPixelChannels(image);
3006 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3009 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3012static MagickBooleanType ImportFloatPixel(Image *image,
const RectangleInfo *roi,
3013 const char *magick_restrict map,
const QuantumType *quantum_map,
3014 const void *pixels,ExceptionInfo *exception)
3031 p=(
const float *) pixels;
3032 if (LocaleCompare(map,
"BGR") == 0)
3034 for (y=0; y < (ssize_t) roi->height; y++)
3036 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3037 if (q == (Quantum *) NULL)
3039 for (x=0; x < (ssize_t) roi->width; x++)
3041 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3044 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3047 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3050 q+=(ptrdiff_t) GetPixelChannels(image);
3052 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3055 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3057 if (LocaleCompare(map,
"BGRA") == 0)
3059 for (y=0; y < (ssize_t) roi->height; y++)
3061 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3062 if (q == (Quantum *) NULL)
3064 for (x=0; x < (ssize_t) roi->width; x++)
3066 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3069 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3072 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3075 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(
double)
3078 q+=(ptrdiff_t) GetPixelChannels(image);
3080 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3083 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3085 if (LocaleCompare(map,
"BGRP") == 0)
3087 for (y=0; y < (ssize_t) roi->height; y++)
3089 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3090 if (q == (Quantum *) NULL)
3092 for (x=0; x < (ssize_t) roi->width; x++)
3094 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3097 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3100 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3104 q+=(ptrdiff_t) GetPixelChannels(image);
3106 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3109 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3111 if (LocaleCompare(map,
"I") == 0)
3113 for (y=0; y < (ssize_t) roi->height; y++)
3115 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3116 if (q == (Quantum *) NULL)
3118 for (x=0; x < (ssize_t) roi->width; x++)
3120 SetPixelGray(image,ClampToQuantum((
double) QuantumRange*(
double)
3123 q+=(ptrdiff_t) GetPixelChannels(image);
3125 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3128 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3130 if (LocaleCompare(map,
"RGB") == 0)
3132 for (y=0; y < (ssize_t) roi->height; y++)
3134 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3135 if (q == (Quantum *) NULL)
3137 for (x=0; x < (ssize_t) roi->width; x++)
3139 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3142 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3145 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3148 q+=(ptrdiff_t) GetPixelChannels(image);
3150 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3153 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3155 if (LocaleCompare(map,
"RGBA") == 0)
3157 for (y=0; y < (ssize_t) roi->height; y++)
3159 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3160 if (q == (Quantum *) NULL)
3162 for (x=0; x < (ssize_t) roi->width; x++)
3164 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3167 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3170 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3173 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(
double)
3176 q+=(ptrdiff_t) GetPixelChannels(image);
3178 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3181 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3183 if (LocaleCompare(map,
"RGBP") == 0)
3185 for (y=0; y < (ssize_t) roi->height; y++)
3187 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3188 if (q == (Quantum *) NULL)
3190 for (x=0; x < (ssize_t) roi->width; x++)
3192 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3195 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3198 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3201 q+=(ptrdiff_t) GetPixelChannels(image);
3203 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3206 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3209 for (y=0; y < (ssize_t) roi->height; y++)
3211 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3212 if (q == (Quantum *) NULL)
3214 for (x=0; x < (ssize_t) roi->width; x++)
3219 for (i=0; i < (ssize_t) length; i++)
3221 switch (quantum_map[i])
3226 SetPixelRed(image,ClampToQuantum((
double) QuantumRange*(
double)
3231 case MagentaQuantum:
3233 SetPixelGreen(image,ClampToQuantum((
double) QuantumRange*(
double)
3240 SetPixelBlue(image,ClampToQuantum((
double) QuantumRange*(
double)
3246 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(
double)
3250 case OpacityQuantum:
3252 SetPixelAlpha(image,ClampToQuantum((
double) QuantumRange*(
double)
3258 SetPixelBlack(image,ClampToQuantum((
double) QuantumRange*(
double)
3264 SetPixelGray(image,ClampToQuantum((
double) QuantumRange*(
double)
3273 q+=(ptrdiff_t) GetPixelChannels(image);
3275 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3278 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3281static MagickBooleanType ImportLongPixel(Image *image,
const RectangleInfo *roi,
3282 const char *magick_restrict map,
const QuantumType *quantum_map,
3283 const void *pixels,ExceptionInfo *exception)
3300 p=(
const unsigned int *) pixels;
3301 if (LocaleCompare(map,
"BGR") == 0)
3303 for (y=0; y < (ssize_t) roi->height; y++)
3305 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3306 if (q == (Quantum *) NULL)
3308 for (x=0; x < (ssize_t) roi->width; x++)
3310 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3311 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3312 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3313 q+=(ptrdiff_t) GetPixelChannels(image);
3315 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3318 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3320 if (LocaleCompare(map,
"BGRA") == 0)
3322 for (y=0; y < (ssize_t) roi->height; y++)
3324 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3325 if (q == (Quantum *) NULL)
3327 for (x=0; x < (ssize_t) roi->width; x++)
3329 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3330 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3331 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3332 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3333 q+=(ptrdiff_t) GetPixelChannels(image);
3335 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3338 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3340 if (LocaleCompare(map,
"BGRP") == 0)
3342 for (y=0; y < (ssize_t) roi->height; y++)
3344 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3345 if (q == (Quantum *) NULL)
3347 for (x=0; x < (ssize_t) roi->width; x++)
3349 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3350 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3351 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3353 q+=(ptrdiff_t) GetPixelChannels(image);
3355 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3358 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3360 if (LocaleCompare(map,
"I") == 0)
3362 for (y=0; y < (ssize_t) roi->height; y++)
3364 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3365 if (q == (Quantum *) NULL)
3367 for (x=0; x < (ssize_t) roi->width; x++)
3369 SetPixelGray(image,ScaleLongToQuantum(*p++),q);
3370 q+=(ptrdiff_t) GetPixelChannels(image);
3372 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3375 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3377 if (LocaleCompare(map,
"RGB") == 0)
3379 for (y=0; y < (ssize_t) roi->height; y++)
3381 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3382 if (q == (Quantum *) NULL)
3384 for (x=0; x < (ssize_t) roi->width; x++)
3386 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3387 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3388 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3389 q+=(ptrdiff_t) GetPixelChannels(image);
3391 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3394 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3396 if (LocaleCompare(map,
"RGBA") == 0)
3398 for (y=0; y < (ssize_t) roi->height; y++)
3400 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3401 if (q == (Quantum *) NULL)
3403 for (x=0; x < (ssize_t) roi->width; x++)
3405 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3406 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3407 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3408 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3409 q+=(ptrdiff_t) GetPixelChannels(image);
3411 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3414 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3416 if (LocaleCompare(map,
"RGBP") == 0)
3418 for (y=0; y < (ssize_t) roi->height; y++)
3420 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3421 if (q == (Quantum *) NULL)
3423 for (x=0; x < (ssize_t) roi->width; x++)
3425 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3426 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3427 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3429 q+=(ptrdiff_t) GetPixelChannels(image);
3431 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3434 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3437 for (y=0; y < (ssize_t) roi->height; y++)
3439 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3440 if (q == (Quantum *) NULL)
3442 for (x=0; x < (ssize_t) roi->width; x++)
3447 for (i=0; i < (ssize_t) length; i++)
3449 switch (quantum_map[i])
3454 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3458 case MagentaQuantum:
3460 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
3466 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
3471 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3474 case OpacityQuantum:
3476 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3481 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
3486 SetPixelGray(image,ScaleLongToQuantum(*p),q);
3494 q+=(ptrdiff_t) GetPixelChannels(image);
3496 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3499 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3502static MagickBooleanType ImportLongLongPixel(Image *image,
3503 const RectangleInfo *roi,
const char *magick_restrict map,
3504 const QuantumType *quantum_map,
const void *pixels,ExceptionInfo *exception)
3506 const MagickSizeType
3521 p=(
const MagickSizeType *) pixels;
3522 if (LocaleCompare(map,
"BGR") == 0)
3524 for (y=0; y < (ssize_t) roi->height; y++)
3526 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3527 if (q == (Quantum *) NULL)
3529 for (x=0; x < (ssize_t) roi->width; x++)
3531 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3532 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3533 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3534 q+=(ptrdiff_t) GetPixelChannels(image);
3536 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3539 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3541 if (LocaleCompare(map,
"BGRA") == 0)
3543 for (y=0; y < (ssize_t) roi->height; y++)
3545 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3546 if (q == (Quantum *) NULL)
3548 for (x=0; x < (ssize_t) roi->width; x++)
3550 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3551 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3552 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3553 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3554 q+=(ptrdiff_t) GetPixelChannels(image);
3556 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3559 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3561 if (LocaleCompare(map,
"BGRP") == 0)
3563 for (y=0; y < (ssize_t) roi->height; y++)
3565 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3566 if (q == (Quantum *) NULL)
3568 for (x=0; x < (ssize_t) roi->width; x++)
3570 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3571 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3572 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3574 q+=(ptrdiff_t) GetPixelChannels(image);
3576 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3579 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3581 if (LocaleCompare(map,
"I") == 0)
3583 for (y=0; y < (ssize_t) roi->height; y++)
3585 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3586 if (q == (Quantum *) NULL)
3588 for (x=0; x < (ssize_t) roi->width; x++)
3590 SetPixelGray(image,ScaleLongLongToQuantum(*p++),q);
3591 q+=(ptrdiff_t) GetPixelChannels(image);
3593 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3596 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3598 if (LocaleCompare(map,
"RGB") == 0)
3600 for (y=0; y < (ssize_t) roi->height; y++)
3602 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3603 if (q == (Quantum *) NULL)
3605 for (x=0; x < (ssize_t) roi->width; x++)
3607 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3608 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3609 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3610 q+=(ptrdiff_t) GetPixelChannels(image);
3612 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3615 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3617 if (LocaleCompare(map,
"RGBA") == 0)
3619 for (y=0; y < (ssize_t) roi->height; y++)
3621 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3622 if (q == (Quantum *) NULL)
3624 for (x=0; x < (ssize_t) roi->width; x++)
3626 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3627 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3628 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3629 SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3630 q+=(ptrdiff_t) GetPixelChannels(image);
3632 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3635 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3637 if (LocaleCompare(map,
"RGBP") == 0)
3639 for (y=0; y < (ssize_t) roi->height; y++)
3641 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3642 if (q == (Quantum *) NULL)
3644 for (x=0; x < (ssize_t) roi->width; x++)
3646 SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3647 SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3648 SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3650 q+=(ptrdiff_t) GetPixelChannels(image);
3652 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3655 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3658 for (y=0; y < (ssize_t) roi->height; y++)
3660 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3661 if (q == (Quantum *) NULL)
3663 for (x=0; x < (ssize_t) roi->width; x++)
3668 for (i=0; i < (ssize_t) length; i++)
3670 switch (quantum_map[i])
3675 SetPixelRed(image,ScaleLongLongToQuantum(*p),q);
3679 case MagentaQuantum:
3681 SetPixelGreen(image,ScaleLongLongToQuantum(*p),q);
3687 SetPixelBlue(image,ScaleLongLongToQuantum(*p),q);
3692 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3695 case OpacityQuantum:
3697 SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3702 SetPixelBlack(image,ScaleLongLongToQuantum(*p),q);
3707 SetPixelGray(image,ScaleLongLongToQuantum(*p),q);
3715 q+=(ptrdiff_t) GetPixelChannels(image);
3717 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3720 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3723static MagickBooleanType ImportQuantumPixel(Image *image,
3724 const RectangleInfo *roi,
const char *magick_restrict map,
3725 const QuantumType *quantum_map,
const void *pixels,ExceptionInfo *exception)
3742 p=(
const Quantum *) pixels;
3743 if (LocaleCompare(map,
"BGR") == 0)
3745 for (y=0; y < (ssize_t) roi->height; y++)
3747 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3748 if (q == (Quantum *) NULL)
3750 for (x=0; x < (ssize_t) roi->width; x++)
3752 SetPixelBlue(image,*p++,q);
3753 SetPixelGreen(image,*p++,q);
3754 SetPixelRed(image,*p++,q);
3755 q+=(ptrdiff_t) GetPixelChannels(image);
3757 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3760 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3762 if (LocaleCompare(map,
"BGRA") == 0)
3764 for (y=0; y < (ssize_t) roi->height; y++)
3766 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3767 if (q == (Quantum *) NULL)
3769 for (x=0; x < (ssize_t) roi->width; x++)
3771 SetPixelBlue(image,*p++,q);
3772 SetPixelGreen(image,*p++,q);
3773 SetPixelRed(image,*p++,q);
3774 SetPixelAlpha(image,*p++,q);
3775 q+=(ptrdiff_t) GetPixelChannels(image);
3777 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3780 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3782 if (LocaleCompare(map,
"BGRP") == 0)
3784 for (y=0; y < (ssize_t) roi->height; y++)
3786 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3787 if (q == (Quantum *) NULL)
3789 for (x=0; x < (ssize_t) roi->width; x++)
3791 SetPixelBlue(image,*p++,q);
3792 SetPixelGreen(image,*p++,q);
3793 SetPixelRed(image,*p++,q);
3795 q+=(ptrdiff_t) GetPixelChannels(image);
3797 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3800 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3802 if (LocaleCompare(map,
"I") == 0)
3804 for (y=0; y < (ssize_t) roi->height; y++)
3806 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3807 if (q == (Quantum *) NULL)
3809 for (x=0; x < (ssize_t) roi->width; x++)
3811 SetPixelGray(image,*p++,q);
3812 q+=(ptrdiff_t) GetPixelChannels(image);
3814 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3817 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3819 if (LocaleCompare(map,
"RGB") == 0)
3821 for (y=0; y < (ssize_t) roi->height; y++)
3823 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3824 if (q == (Quantum *) NULL)
3826 for (x=0; x < (ssize_t) roi->width; x++)
3828 SetPixelRed(image,*p++,q);
3829 SetPixelGreen(image,*p++,q);
3830 SetPixelBlue(image,*p++,q);
3831 q+=(ptrdiff_t) GetPixelChannels(image);
3833 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3836 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3838 if (LocaleCompare(map,
"RGBA") == 0)
3840 for (y=0; y < (ssize_t) roi->height; y++)
3842 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3843 if (q == (Quantum *) NULL)
3845 for (x=0; x < (ssize_t) roi->width; x++)
3847 SetPixelRed(image,*p++,q);
3848 SetPixelGreen(image,*p++,q);
3849 SetPixelBlue(image,*p++,q);
3850 SetPixelAlpha(image,*p++,q);
3851 q+=(ptrdiff_t) GetPixelChannels(image);
3853 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3856 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3858 if (LocaleCompare(map,
"RGBP") == 0)
3860 for (y=0; y < (ssize_t) roi->height; y++)
3862 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3863 if (q == (Quantum *) NULL)
3865 for (x=0; x < (ssize_t) roi->width; x++)
3867 SetPixelRed(image,*p++,q);
3868 SetPixelGreen(image,*p++,q);
3869 SetPixelBlue(image,*p++,q);
3871 q+=(ptrdiff_t) GetPixelChannels(image);
3873 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3876 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3879 for (y=0; y < (ssize_t) roi->height; y++)
3881 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3882 if (q == (Quantum *) NULL)
3884 for (x=0; x < (ssize_t) roi->width; x++)
3889 for (i=0; i < (ssize_t) length; i++)
3891 switch (quantum_map[i])
3896 SetPixelRed(image,*p,q);
3900 case MagentaQuantum:
3902 SetPixelGreen(image,*p,q);
3908 SetPixelBlue(image,*p,q);
3913 SetPixelAlpha(image,*p,q);
3916 case OpacityQuantum:
3918 SetPixelAlpha(image,*p,q);
3923 SetPixelBlack(image,*p,q);
3928 SetPixelGray(image,*p,q);
3936 q+=(ptrdiff_t) GetPixelChannels(image);
3938 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3941 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3944static MagickBooleanType ImportShortPixel(Image *image,
const RectangleInfo *roi,
3945 const char *magick_restrict map,
const QuantumType *quantum_map,
3946 const void *pixels,ExceptionInfo *exception)
3948 const unsigned short
3963 p=(
const unsigned short *) pixels;
3964 if (LocaleCompare(map,
"BGR") == 0)
3966 for (y=0; y < (ssize_t) roi->height; y++)
3968 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3969 if (q == (Quantum *) NULL)
3971 for (x=0; x < (ssize_t) roi->width; x++)
3973 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3974 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3975 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3976 q+=(ptrdiff_t) GetPixelChannels(image);
3978 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3981 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3983 if (LocaleCompare(map,
"BGRA") == 0)
3985 for (y=0; y < (ssize_t) roi->height; y++)
3987 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3988 if (q == (Quantum *) NULL)
3990 for (x=0; x < (ssize_t) roi->width; x++)
3992 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3993 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3994 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3995 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3996 q+=(ptrdiff_t) GetPixelChannels(image);
3998 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4001 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4003 if (LocaleCompare(map,
"BGRP") == 0)
4005 for (y=0; y < (ssize_t) roi->height; y++)
4007 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4008 if (q == (Quantum *) NULL)
4010 for (x=0; x < (ssize_t) roi->width; x++)
4012 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4013 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4014 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4016 q+=(ptrdiff_t) GetPixelChannels(image);
4018 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4021 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4023 if (LocaleCompare(map,
"I") == 0)
4025 for (y=0; y < (ssize_t) roi->height; y++)
4027 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4028 if (q == (Quantum *) NULL)
4030 for (x=0; x < (ssize_t) roi->width; x++)
4032 SetPixelGray(image,ScaleShortToQuantum(*p++),q);
4033 q+=(ptrdiff_t) GetPixelChannels(image);
4035 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4038 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4040 if (LocaleCompare(map,
"RGB") == 0)
4042 for (y=0; y < (ssize_t) roi->height; y++)
4044 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4045 if (q == (Quantum *) NULL)
4047 for (x=0; x < (ssize_t) roi->width; x++)
4049 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4050 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4051 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4052 q+=(ptrdiff_t) GetPixelChannels(image);
4054 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4057 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4059 if (LocaleCompare(map,
"RGBA") == 0)
4061 for (y=0; y < (ssize_t) roi->height; y++)
4063 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4064 if (q == (Quantum *) NULL)
4066 for (x=0; x < (ssize_t) roi->width; x++)
4068 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4069 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4070 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4071 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
4072 q+=(ptrdiff_t) GetPixelChannels(image);
4074 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4077 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4079 if (LocaleCompare(map,
"RGBP") == 0)
4081 for (y=0; y < (ssize_t) roi->height; y++)
4083 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4084 if (q == (Quantum *) NULL)
4086 for (x=0; x < (ssize_t) roi->width; x++)
4088 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4089 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4090 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4092 q+=(ptrdiff_t) GetPixelChannels(image);
4094 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4097 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4100 for (y=0; y < (ssize_t) roi->height; y++)
4102 q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4103 if (q == (Quantum *) NULL)
4105 for (x=0; x < (ssize_t) roi->width; x++)
4110 for (i=0; i < (ssize_t) length; i++)
4112 switch (quantum_map[i])
4117 SetPixelRed(image,ScaleShortToQuantum(*p),q);
4121 case MagentaQuantum:
4123 SetPixelGreen(image,ScaleShortToQuantum(*p),q);
4129 SetPixelBlue(image,ScaleShortToQuantum(*p),q);
4134 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
4137 case OpacityQuantum:
4139 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
4144 SetPixelBlack(image,ScaleShortToQuantum(*p),q);
4149 SetPixelGray(image,ScaleShortToQuantum(*p),q);
4157 q+=(ptrdiff_t) GetPixelChannels(image);
4159 if (SyncAuthenticPixels(image,exception) == MagickFalse)
4162 return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4165MagickExport MagickBooleanType ImportImagePixels(Image *image,
const ssize_t x,
4166 const ssize_t y,
const size_t width,
const size_t height,
const char *map,
4167 const StorageType type,
const void *pixels,ExceptionInfo *exception)
4187 assert(image != (Image *) NULL);
4188 assert(image->signature == MagickCoreSignature);
4189 if (IsEventLogging() != MagickFalse)
4190 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4192 quantum_map=(QuantumType *) AcquireQuantumMemory(length,
sizeof(*quantum_map));
4193 if (quantum_map == (QuantumType *) NULL)
4194 ThrowBinaryException(ResourceLimitError,
"MemoryAllocationFailed",
4196 for (i=0; i < (ssize_t) length; i++)
4203 quantum_map[i]=AlphaQuantum;
4204 image->alpha_trait=BlendPixelTrait;
4210 quantum_map[i]=BlueQuantum;
4216 quantum_map[i]=CyanQuantum;
4217 (void) SetImageColorspace(image,CMYKColorspace,exception);
4223 quantum_map[i]=GreenQuantum;
4229 quantum_map[i]=BlackQuantum;
4230 (void) SetImageColorspace(image,CMYKColorspace,exception);
4236 quantum_map[i]=IndexQuantum;
4237 (void) SetImageColorspace(image,GRAYColorspace,exception);
4243 quantum_map[i]=MagentaQuantum;
4244 (void) SetImageColorspace(image,CMYKColorspace,exception);
4250 quantum_map[i]=OpacityQuantum;
4251 image->alpha_trait=BlendPixelTrait;
4257 quantum_map[i]=UndefinedQuantum;
4263 quantum_map[i]=RedQuantum;
4269 quantum_map[i]=YellowQuantum;
4270 (void) SetImageColorspace(image,CMYKColorspace,exception);
4275 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4276 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4277 "UnrecognizedPixelMap",
"`%s'",map);
4278 return(MagickFalse);
4282 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
4284 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4285 return(MagickFalse);
4298 status=ImportCharPixel(image,&roi,map,quantum_map,pixels,exception);
4303 status=ImportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
4308 status=ImportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
4313 status=ImportLongPixel(image,&roi,map,quantum_map,pixels,exception);
4318 status=ImportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
4323 status=ImportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
4328 status=ImportShortPixel(image,&roi,map,quantum_map,pixels,exception);
4333 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4334 "UnrecognizedStorageType",
"`%d'",type);
4338 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4384static inline void CatromWeights(
const double x,
double (*weights)[4])
4398 alpha=(double) 1.0-x;
4399 beta=(double) (-0.5)*x*alpha;
4400 (*weights)[0]=alpha*beta;
4401 (*weights)[3]=x*beta;
4406 gamma=(*weights)[3]-(*weights)[0];
4407 (*weights)[1]=alpha-(*weights)[0]+gamma;
4408 (*weights)[2]=x-(*weights)[3]-gamma;
4411static inline void SplineWeights(
const double x,
double (*weights)[4])
4423 alpha=(double) 1.0-x;
4424 (*weights)[3]=(double) (1.0/6.0)*x*x*x;
4425 (*weights)[0]=(double) (1.0/6.0)*alpha*alpha*alpha;
4426 beta=(*weights)[3]-(*weights)[0];
4427 (*weights)[1]=alpha-(*weights)[0]+beta;
4428 (*weights)[2]=x-(*weights)[3]-beta;
4431static inline double MeshInterpolate(
const PointInfo *delta,
const double p,
4432 const double x,
const double y)
4434 return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
4437MagickExport MagickBooleanType InterpolatePixelChannel(
4438 const Image *magick_restrict image,
const CacheView_ *image_view,
4439 const PixelChannel channel,
const PixelInterpolateMethod method,
const double x,
4440 const double y,
double *pixel,ExceptionInfo *exception)
4453 PixelInterpolateMethod
4464 assert(image != (Image *) NULL);
4465 assert(image->signature == MagickCoreSignature);
4466 assert(image_view != (CacheView *) NULL);
4468 if ((channel < 0) || (channel >= MaxPixelChannels))
4469 ThrowBinaryException(OptionError,
"NoSuchImageChannel",image->filename);
4470 traits=GetPixelChannelTraits(image,channel);
4471 x_offset=CastDoubleToSsizeT(floor(x));
4472 y_offset=CastDoubleToSsizeT(floor(y));
4474 if (interpolate == UndefinedInterpolatePixel)
4475 interpolate=image->interpolate;
4477 switch (interpolate)
4479 case AverageInterpolatePixel:
4480 case Average9InterpolatePixel:
4481 case Average16InterpolatePixel:
4487 if (interpolate == Average9InterpolatePixel)
4490 x_offset=CastDoubleToSsizeT(floor(x+0.5)-1.0);
4491 y_offset=CastDoubleToSsizeT(floor(y+0.5)-1.0);
4494 if (interpolate == Average16InterpolatePixel)
4500 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,(
size_t) count,
4501 (
size_t) count,exception);
4502 if (p == (
const Quantum *) NULL)
4508 if ((traits & BlendPixelTrait) == 0)
4509 for (i=0; i < (ssize_t) count; i++)
4512 pixels[i]=(double) p[i*(ssize_t) GetPixelChannels(image)+
4513 GetPixelChannelOffset(image,channel)];
4516 for (i=0; i < (ssize_t) count; i++)
4518 alpha[i]=QuantumScale*(double) GetPixelAlpha(image,p+i*
4519 (ssize_t) GetPixelChannels(image));
4520 pixels[i]=alpha[i]*(double) p[i*(ssize_t) GetPixelChannels(image)+
4521 GetPixelChannelOffset(image,channel)];
4523 for (i=0; i < (ssize_t) count; i++)
4525 gamma=MagickSafeReciprocal(alpha[i])/count;
4526 *pixel+=gamma*pixels[i];
4530 case BilinearInterpolatePixel:
4537 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4538 if (p == (
const Quantum *) NULL)
4543 if ((traits & BlendPixelTrait) == 0)
4544 for (i=0; i < 4; i++)
4547 pixels[i]=(double) p[i*(ssize_t) GetPixelChannels(image)+
4548 GetPixelChannelOffset(image,channel)];
4551 for (i=0; i < 4; i++)
4553 alpha[i]=QuantumScale*(double) GetPixelAlpha(image,p+i*
4554 (ssize_t) GetPixelChannels(image));
4555 pixels[i]=alpha[i]*(double) p[i*(ssize_t) GetPixelChannels(image)+
4556 GetPixelChannelOffset(image,channel)];
4560 epsilon.x=1.0-delta.x;
4561 epsilon.y=1.0-delta.y;
4562 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4563 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4564 gamma=MagickSafeReciprocal(gamma);
4565 *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
4566 (epsilon.x*pixels[2]+delta.x*pixels[3]));
4569 case BlendInterpolatePixel:
4571 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4572 if (p == (
const Quantum *) NULL)
4577 if ((traits & BlendPixelTrait) == 0)
4578 for (i=0; i < 4; i++)
4581 pixels[i]=(MagickRealType) p[i*(ssize_t) GetPixelChannels(image)+
4582 GetPixelChannelOffset(image,channel)];
4585 for (i=0; i < 4; i++)
4587 alpha[i]=QuantumScale*(double) GetPixelAlpha(image,p+i*
4588 (ssize_t) GetPixelChannels(image));
4589 pixels[i]=alpha[i]*(double) p[i*(ssize_t) GetPixelChannels(image)+
4590 GetPixelChannelOffset(image,channel)];
4593 for (i=0; i <= 1L; i++) {
4594 if ((y-y_offset) >= 0.75)
4596 alpha[i]=alpha[i+2];
4597 pixels[i]=pixels[i+2];
4600 if ((y-y_offset) > 0.25)
4603 alpha[i]+=alpha[i+2];
4604 pixels[i]+=pixels[i+2];
4607 if ((x-x_offset) >= 0.75)
4610 pixels[0]=pixels[1];
4613 if ((x-x_offset) > 0.25)
4617 pixels[0]+=pixels[1];
4619 if (channel != AlphaPixelChannel)
4620 gamma=MagickSafeReciprocal(alpha[0]);
4622 gamma=MagickSafeReciprocal(gamma);
4623 *pixel=gamma*pixels[0];
4626 case CatromInterpolatePixel:
4632 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4634 if (p == (
const Quantum *) NULL)
4639 if ((traits & BlendPixelTrait) == 0)
4640 for (i=0; i < 16; i++)
4643 pixels[i]=(double) p[i*(ssize_t) GetPixelChannels(image)+
4644 GetPixelChannelOffset(image,channel)];
4647 for (i=0; i < 16; i++)
4649 alpha[i]=QuantumScale*(double) GetPixelAlpha(image,p+i*
4650 (ssize_t) GetPixelChannels(image));
4651 pixels[i]=alpha[i]*(double) p[i*(ssize_t) GetPixelChannels(image)+
4652 GetPixelChannelOffset(image,channel)];
4654 CatromWeights((
double) (x-x_offset),&cx);
4655 CatromWeights((
double) (y-y_offset),&cy);
4656 gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4657 MagickSafeReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4658 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4659 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4660 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4661 cx[2]*alpha[14]+cx[3]*alpha[15])));
4662 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4663 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4664 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4665 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4666 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4669 case IntegerInterpolatePixel:
4671 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4672 if (p == (
const Quantum *) NULL)
4677 *pixel=(double) GetPixelChannel(image,channel,p);
4680 case NearestInterpolatePixel:
4682 x_offset=CastDoubleToSsizeT(floor(x+0.5));
4683 y_offset=CastDoubleToSsizeT(floor(y+0.5));
4684 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4685 if (p == (
const Quantum *) NULL)
4690 *pixel=(double) GetPixelChannel(image,channel,p);
4693 case MeshInterpolatePixel:
4699 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4700 if (p == (
const Quantum *) NULL)
4705 if ((traits & BlendPixelTrait) == 0)
4706 for (i=0; i < 4; i++)
4709 pixels[i]=(double) p[i*(ssize_t) GetPixelChannels(image)+
4710 GetPixelChannelOffset(image,channel)];
4713 for (i=0; i < 4; i++)
4715 alpha[i]=QuantumScale*(double) GetPixelAlpha(image,p+i*
4716 (ssize_t) GetPixelChannels(image));
4717 pixels[i]=alpha[i]*(double) p[i*(ssize_t) GetPixelChannels(image)+
4718 GetPixelChannelOffset(image,channel)];
4722 luminance.x=GetPixelLuma(image,p)-(double)
4723 GetPixelLuma(image,p+3*GetPixelChannels(image));
4724 luminance.y=GetPixelLuma(image,p+GetPixelChannels(image))-(double)
4725 GetPixelLuma(image,p+2*GetPixelChannels(image));
4726 if (fabs((
double) luminance.x) < fabs((
double) luminance.y))
4731 if (delta.x <= delta.y)
4736 delta.y=1.0-delta.y;
4737 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4738 gamma=MagickSafeReciprocal(gamma);
4739 *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
4747 delta.x=1.0-delta.x;
4748 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4749 gamma=MagickSafeReciprocal(gamma);
4750 *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
4759 if (delta.x <= (1.0-delta.y))
4764 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4765 gamma=MagickSafeReciprocal(gamma);
4766 *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
4774 delta.x=1.0-delta.x;
4775 delta.y=1.0-delta.y;
4776 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4777 gamma=MagickSafeReciprocal(gamma);
4778 *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
4784 case SplineInterpolatePixel:
4790 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4792 if (p == (
const Quantum *) NULL)
4797 if ((traits & BlendPixelTrait) == 0)
4798 for (i=0; i < 16; i++)
4801 pixels[i]=(double) p[i*(ssize_t) GetPixelChannels(image)+
4802 GetPixelChannelOffset(image,channel)];
4805 for (i=0; i < 16; i++)
4807 alpha[i]=QuantumScale*(double) GetPixelAlpha(image,p+i*
4808 (ssize_t) GetPixelChannels(image));
4809 pixels[i]=alpha[i]*(double) p[i*(ssize_t) GetPixelChannels(image)+
4810 GetPixelChannelOffset(image,channel)];
4812 SplineWeights((
double) (x-x_offset),&cx);
4813 SplineWeights((
double) (y-y_offset),&cy);
4814 gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4815 MagickSafeReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4816 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4817 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4818 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4819 cx[2]*alpha[14]+cx[3]*alpha[15])));
4820 *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4821 cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4822 pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4823 cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4824 pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4874MagickExport MagickBooleanType InterpolatePixelChannels(
4875 const Image *magick_restrict source,
const CacheView_ *source_view,
4876 const Image *magick_restrict destination,
const PixelInterpolateMethod method,
4877 const double x,
const double y,Quantum *pixel,ExceptionInfo *exception)
4897 PixelInterpolateMethod
4900 assert(source != (Image *) NULL);
4901 assert(source->signature == MagickCoreSignature);
4902 assert(source_view != (CacheView *) NULL);
4904 x_offset=CastDoubleToSsizeT(floor(x));
4905 y_offset=CastDoubleToSsizeT(floor(y));
4907 if (interpolate == UndefinedInterpolatePixel)
4908 interpolate=source->interpolate;
4909 switch (interpolate)
4911 case AverageInterpolatePixel:
4912 case Average9InterpolatePixel:
4913 case Average16InterpolatePixel:
4919 if (interpolate == Average9InterpolatePixel)
4922 x_offset=CastDoubleToSsizeT(floor(x+0.5)-1.0);
4923 y_offset=CastDoubleToSsizeT(floor(y+0.5)-1.0);
4926 if (interpolate == Average16InterpolatePixel)
4932 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,(
size_t) count,
4933 (
size_t) count,exception);
4934 if (p == (
const Quantum *) NULL)
4940 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4948 PixelChannel channel = GetPixelChannelChannel(source,i);
4949 PixelTrait traits = GetPixelChannelTraits(source,channel);
4950 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4952 if ((traits == UndefinedPixelTrait) ||
4953 (destination_traits == UndefinedPixelTrait))
4955 for (j=0; j < (ssize_t) count; j++)
4956 pixels[j]=(
double) p[j*(ssize_t) GetPixelChannels(source)+i];
4958 if ((traits & BlendPixelTrait) == 0)
4960 for (j=0; j < (ssize_t) count; j++)
4963 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4966 for (j=0; j < (ssize_t) count; j++)
4968 alpha[j]=QuantumScale*(double) GetPixelAlpha(source,p+j*
4969 (ssize_t) GetPixelChannels(source));
4970 pixels[j]*=alpha[j];
4971 gamma=MagickSafeReciprocal(alpha[j]);
4972 sum+=gamma*pixels[j];
4975 SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
4979 case BilinearInterpolatePixel:
4982 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4983 if (p == (
const Quantum *) NULL)
4988 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4994 PixelChannel channel = GetPixelChannelChannel(source,i);
4995 PixelTrait traits = GetPixelChannelTraits(source,channel);
4996 PixelTrait destination_traits=GetPixelChannelTraits(destination,
4998 if ((traits == UndefinedPixelTrait) ||
4999 (destination_traits == UndefinedPixelTrait))
5003 epsilon.x=1.0-delta.x;
5004 epsilon.y=1.0-delta.y;
5005 pixels[0]=(double) p[i];
5006 pixels[1]=(double) p[(ssize_t) GetPixelChannels(source)+i];
5007 pixels[2]=(double) p[2*(ssize_t) GetPixelChannels(source)+i];
5008 pixels[3]=(double) p[3*(ssize_t) GetPixelChannels(source)+i];
5009 if ((traits & BlendPixelTrait) == 0)
5011 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5012 gamma=MagickSafeReciprocal(gamma);
5013 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
5014 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*
5015 pixels[2]+delta.x*pixels[3]))),pixel);
5018 alpha[0]=QuantumScale*(double) GetPixelAlpha(source,p);
5019 alpha[1]=QuantumScale*(double) GetPixelAlpha(source,p+
5020 GetPixelChannels(source));
5021 alpha[2]=QuantumScale*(double) GetPixelAlpha(source,p+2*
5022 GetPixelChannels(source));
5023 alpha[3]=QuantumScale*(double) GetPixelAlpha(source,p+3*
5024 GetPixelChannels(source));
5025 pixels[0]*=alpha[0];
5026 pixels[1]*=alpha[1];
5027 pixels[2]*=alpha[2];
5028 pixels[3]*=alpha[3];
5029 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5030 (epsilon.x*alpha[2]+delta.x*alpha[3])));
5031 gamma=MagickSafeReciprocal(gamma);
5032 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
5033 (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+
5034 delta.x*pixels[3]))),pixel);
5038 case BlendInterpolatePixel:
5040 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
5041 if (p == (
const Quantum *) NULL)
5046 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5051 PixelChannel channel = GetPixelChannelChannel(source,i);
5052 PixelTrait traits = GetPixelChannelTraits(source,channel);
5053 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5055 if ((traits == UndefinedPixelTrait) ||
5056 (destination_traits == UndefinedPixelTrait))
5058 if (source->alpha_trait != BlendPixelTrait)
5059 for (j=0; j < 4; j++)
5062 pixels[j]=(double) p[j*(ssize_t) GetPixelChannels(source)+i];
5065 for (j=0; j < 4; j++)
5067 alpha[j]=QuantumScale*(double) GetPixelAlpha(source,p+j*
5068 (ssize_t) GetPixelChannels(source));
5069 pixels[j]=(double) p[j*(ssize_t) GetPixelChannels(source)+i];
5070 if (channel != AlphaPixelChannel)
5071 pixels[j]*=alpha[j];
5074 for (j=0; j <= 1L; j++)
5076 if ((y-y_offset) >= 0.75)
5078 alpha[j]=alpha[j+2];
5079 pixels[j]=pixels[j+2];
5082 if ((y-y_offset) > 0.25)
5085 alpha[j]+=alpha[j+2];
5086 pixels[j]+=pixels[j+2];
5089 if ((x-x_offset) >= 0.75)
5092 pixels[0]=pixels[1];
5095 if ((x-x_offset) > 0.25)
5099 pixels[0]+=pixels[1];
5101 if (channel != AlphaPixelChannel)
5102 gamma=MagickSafeReciprocal(alpha[0]);
5104 gamma=MagickSafeReciprocal(gamma);
5105 SetPixelChannel(destination,channel,ClampToQuantum(gamma*pixels[0]),
5110 case CatromInterpolatePixel:
5116 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
5118 if (p == (
const Quantum *) NULL)
5123 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5128 PixelChannel channel = GetPixelChannelChannel(source,i);
5129 PixelTrait traits = GetPixelChannelTraits(source,channel);
5130 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5132 if ((traits == UndefinedPixelTrait) ||
5133 (destination_traits == UndefinedPixelTrait))
5135 if ((traits & BlendPixelTrait) == 0)
5136 for (j=0; j < 16; j++)
5139 pixels[j]=(double) p[j*(ssize_t) GetPixelChannels(source)+i];
5142 for (j=0; j < 16; j++)
5144 alpha[j]=QuantumScale*(double) GetPixelAlpha(source,p+j*
5145 (ssize_t) GetPixelChannels(source));
5146 pixels[j]=alpha[j]*(double)
5147 p[j*(ssize_t) GetPixelChannels(source)+i];
5149 CatromWeights((
double) (x-x_offset),&cx);
5150 CatromWeights((
double) (y-y_offset),&cy);
5151 gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
5152 MagickSafeReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
5153 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
5154 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
5155 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
5156 cx[2]*alpha[14]+cx[3]*alpha[15])));
5157 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
5158 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
5159 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
5160 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
5161 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
5162 pixels[14]+cx[3]*pixels[15]))),pixel);
5166 case IntegerInterpolatePixel:
5168 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
5169 if (p == (
const Quantum *) NULL)
5174 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5176 PixelChannel channel = GetPixelChannelChannel(source,i);
5177 PixelTrait traits = GetPixelChannelTraits(source,channel);
5178 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5180 if ((traits == UndefinedPixelTrait) ||
5181 (destination_traits == UndefinedPixelTrait))
5183 SetPixelChannel(destination,channel,p[i],pixel);
5187 case NearestInterpolatePixel:
5189 x_offset=CastDoubleToSsizeT(floor(x+0.5));
5190 y_offset=CastDoubleToSsizeT(floor(y+0.5));
5191 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
5192 if (p == (
const Quantum *) NULL)
5197 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5199 PixelChannel channel = GetPixelChannelChannel(source,i);
5200 PixelTrait traits = GetPixelChannelTraits(source,channel);
5201 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5203 if ((traits == UndefinedPixelTrait) ||
5204 (destination_traits == UndefinedPixelTrait))
5206 SetPixelChannel(destination,channel,p[i],pixel);
5210 case MeshInterpolatePixel:
5212 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
5213 if (p == (
const Quantum *) NULL)
5218 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5224 PixelChannel channel = GetPixelChannelChannel(source,i);
5225 PixelTrait traits = GetPixelChannelTraits(source,channel);
5226 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5228 if ((traits == UndefinedPixelTrait) ||
5229 (destination_traits == UndefinedPixelTrait))
5231 pixels[0]=(double) p[i];
5232 pixels[1]=(double) p[(ssize_t) GetPixelChannels(source)+i];
5233 pixels[2]=(double) p[2*(ssize_t) GetPixelChannels(source)+i];
5234 pixels[3]=(double) p[3*(ssize_t) GetPixelChannels(source)+i];
5235 if ((traits & BlendPixelTrait) == 0)
5244 alpha[0]=QuantumScale*(double) GetPixelAlpha(source,p);
5245 alpha[1]=QuantumScale*(double) GetPixelAlpha(source,p+
5246 GetPixelChannels(source));
5247 alpha[2]=QuantumScale*(double) GetPixelAlpha(source,p+2*
5248 GetPixelChannels(source));
5249 alpha[3]=QuantumScale*(double) GetPixelAlpha(source,p+3*
5250 GetPixelChannels(source));
5254 luminance.x=fabs((
double) (GetPixelLuma(source,p)-
5255 GetPixelLuma(source,p+3*GetPixelChannels(source))));
5256 luminance.y=fabs((
double) (GetPixelLuma(source,p+
5257 GetPixelChannels(source))-GetPixelLuma(source,p+2*
5258 GetPixelChannels(source))));
5259 if (luminance.x < luminance.y)
5264 if (delta.x <= delta.y)
5269 delta.y=1.0-delta.y;
5270 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5271 gamma=MagickSafeReciprocal(gamma);
5272 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5273 MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel);
5280 delta.x=1.0-delta.x;
5281 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5282 gamma=MagickSafeReciprocal(gamma);
5283 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5284 MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel);
5292 if (delta.x <= (1.0-delta.y))
5297 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5298 gamma=MagickSafeReciprocal(gamma);
5299 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5300 MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel);
5307 delta.x=1.0-delta.x;
5308 delta.y=1.0-delta.y;
5309 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5310 gamma=MagickSafeReciprocal(gamma);
5311 SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5312 MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel);
5318 case SplineInterpolatePixel:
5324 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
5326 if (p == (
const Quantum *) NULL)
5331 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5336 PixelChannel channel = GetPixelChannelChannel(source,i);
5337 PixelTrait traits = GetPixelChannelTraits(source,channel);
5338 PixelTrait destination_traits=GetPixelChannelTraits(destination,
5340 if ((traits == UndefinedPixelTrait) ||
5341 (destination_traits == UndefinedPixelTrait))
5343 if ((traits & BlendPixelTrait) == 0)
5344 for (j=0; j < 16; j++)
5347 pixels[j]=(double) p[j*(ssize_t) GetPixelChannels(source)+i];
5350 for (j=0; j < 16; j++)
5352 alpha[j]=QuantumScale*(double) GetPixelAlpha(source,p+j*
5353 (ssize_t) GetPixelChannels(source));
5354 pixels[j]=alpha[j]*(double) p[j*(ssize_t) GetPixelChannels(source)+
5357 SplineWeights((
double) (x-x_offset),&cx);
5358 SplineWeights((
double) (y-y_offset),&cy);
5359 gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
5360 MagickSafeReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
5361 alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
5362 alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
5363 alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
5364 cx[2]*alpha[14]+cx[3]*alpha[15])));
5365 SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
5366 pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
5367 (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
5368 cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
5369 pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
5370 pixels[14]+cx[3]*pixels[15]))),pixel);
5418static inline void AlphaBlendPixelInfo(
const Image *image,
5419 const Quantum *pixel,PixelInfo *pixel_info,
double *alpha)
5421 if ((image->alpha_trait & BlendPixelTrait) == 0)
5424 pixel_info->red=(double) GetPixelRed(image,pixel);
5425 pixel_info->green=(double) GetPixelGreen(image,pixel);
5426 pixel_info->blue=(double) GetPixelBlue(image,pixel);
5427 pixel_info->black=0.0;
5428 if (image->colorspace == CMYKColorspace)
5429 pixel_info->black=(double) GetPixelBlack(image,pixel);
5430 pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5433 *alpha=QuantumScale*(double) GetPixelAlpha(image,pixel);
5434 pixel_info->red=(*alpha*(double) GetPixelRed(image,pixel));
5435 pixel_info->green=(*alpha*(double) GetPixelGreen(image,pixel));
5436 pixel_info->blue=(*alpha*(double) GetPixelBlue(image,pixel));
5437 pixel_info->black=0.0;
5438 if (image->colorspace == CMYKColorspace)
5439 pixel_info->black=(*alpha*(double) GetPixelBlack(image,pixel));
5440 pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5443MagickExport MagickBooleanType InterpolatePixelInfo(
const Image *image,
5444 const CacheView_ *image_view,
const PixelInterpolateMethod method,
5445 const double x,
const double y,PixelInfo *pixel,ExceptionInfo *exception)
5460 PixelInterpolateMethod
5468 assert(image != (Image *) NULL);
5469 assert(image->signature == MagickCoreSignature);
5470 assert(image_view != (CacheView *) NULL);
5472 x_offset=CastDoubleToSsizeT(floor(x));
5473 y_offset=CastDoubleToSsizeT(floor(y));
5475 if (interpolate == UndefinedInterpolatePixel)
5476 interpolate=image->interpolate;
5477 GetPixelInfoPixel(image,(
const Quantum *) NULL,pixel);
5478 (void) memset(&pixels,0,
sizeof(pixels));
5479 switch (interpolate)
5481 case AverageInterpolatePixel:
5482 case Average9InterpolatePixel:
5483 case Average16InterpolatePixel:
5489 if (interpolate == Average9InterpolatePixel)
5492 x_offset=CastDoubleToSsizeT(floor(x+0.5)-1.0);
5493 y_offset=CastDoubleToSsizeT(floor(y+0.5)-1.0);
5496 if (interpolate == Average16InterpolatePixel)
5502 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,(
size_t) count,
5503 (
size_t) count,exception);
5504 if (p == (
const Quantum *) NULL)
5515 for (i=0; i < (ssize_t) count; i++)
5517 AlphaBlendPixelInfo(image,p,pixels,alpha);
5518 gamma=MagickSafeReciprocal(alpha[0]);
5519 pixel->red+=gamma*pixels[0].red;
5520 pixel->green+=gamma*pixels[0].green;
5521 pixel->blue+=gamma*pixels[0].blue;
5522 pixel->black+=gamma*pixels[0].black;
5523 pixel->alpha+=pixels[0].alpha;
5524 p+=(ptrdiff_t) GetPixelChannels(image);
5528 pixel->green*=gamma;
5530 pixel->black*=gamma;
5531 pixel->alpha*=gamma;
5534 case BackgroundInterpolatePixel:
5536 *pixel=image->background_color;
5539 case BilinearInterpolatePixel:
5546 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5547 if (p == (
const Quantum *) NULL)
5552 for (i=0; i < 4L; i++)
5553 AlphaBlendPixelInfo(image,p+i*(ssize_t) GetPixelChannels(image),
5557 epsilon.x=1.0-delta.x;
5558 epsilon.y=1.0-delta.y;
5559 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5560 (epsilon.x*alpha[2]+delta.x*alpha[3])));
5561 gamma=MagickSafeReciprocal(gamma);
5562 pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
5563 pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red));
5564 pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x*
5565 pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x*
5567 pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x*
5568 pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x*
5570 if (image->colorspace == CMYKColorspace)
5571 pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x*
5572 pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x*
5574 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5575 gamma=MagickSafeReciprocal(gamma);
5576 pixel->alpha=gamma*(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x*
5577 pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x*
5581 case BlendInterpolatePixel:
5583 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5584 if (p == (
const Quantum *) NULL)
5589 for (i=0; i < 4L; i++)
5591 GetPixelInfoPixel(image,p+i*(ssize_t) GetPixelChannels(image),pixels+i);
5592 AlphaBlendPixelInfo(image,p+i*(ssize_t) GetPixelChannels(image),
5596 for (i=0; i <= 1L; i++)
5598 if ((y-y_offset) >= 0.75)
5600 alpha[i]=alpha[i+2];
5601 pixels[i]=pixels[i+2];
5604 if ((y-y_offset) > 0.25)
5607 alpha[i]+=alpha[i+2];
5608 pixels[i].red+=pixels[i+2].red;
5609 pixels[i].green+=pixels[i+2].green;
5610 pixels[i].blue+=pixels[i+2].blue;
5611 pixels[i].black+=pixels[i+2].black;
5612 pixels[i].alpha+=pixels[i+2].alpha;
5615 if ((x-x_offset) >= 0.75)
5618 pixels[0]=pixels[1];
5621 if ((x-x_offset) > 0.25)
5624 alpha[0]+= alpha[1];
5625 pixels[0].red+=pixels[1].red;
5626 pixels[0].green+=pixels[1].green;
5627 pixels[0].blue+=pixels[1].blue;
5628 pixels[0].black+=pixels[1].black;
5629 pixels[0].alpha+=pixels[1].alpha;
5632 alpha[0]=MagickSafeReciprocal(alpha[0]);
5633 pixel->red=alpha[0]*pixels[0].red;
5634 pixel->green=alpha[0]*pixels[0].green;
5635 pixel->blue=alpha[0]*pixels[0].blue;
5636 pixel->black=alpha[0]*pixels[0].black;
5637 pixel->alpha=gamma*pixels[0].alpha;
5640 case CatromInterpolatePixel:
5646 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5648 if (p == (
const Quantum *) NULL)
5653 for (i=0; i < 16L; i++)
5654 AlphaBlendPixelInfo(image,p+i*(ssize_t) GetPixelChannels(image),
5656 CatromWeights((
double) (x-x_offset),&cx);
5657 CatromWeights((
double) (y-y_offset),&cy);
5658 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]*
5659 pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5660 pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]*
5661 pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5662 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]*
5663 pixels[14].red+cx[3]*pixels[15].red));
5664 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]*
5665 pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+
5666 cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+
5667 cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]*
5668 pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]*
5669 pixels[12].green+cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]*
5671 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]*
5672 pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5673 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]*
5674 pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5675 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+
5676 cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5677 if (image->colorspace == CMYKColorspace)
5678 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]*
5679 pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+
5680 cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+
5681 cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]*
5682 pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]*
5683 pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]*
5685 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]*
5686 pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+
5687 cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+
5688 cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]*
5689 pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+
5690 cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5693 case IntegerInterpolatePixel:
5695 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5696 if (p == (
const Quantum *) NULL)
5701 GetPixelInfoPixel(image,p,pixel);
5704 case MeshInterpolatePixel:
5710 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5711 if (p == (
const Quantum *) NULL)
5718 luminance.x=GetPixelLuma(image,p)-(double)
5719 GetPixelLuma(image,p+3*GetPixelChannels(image));
5720 luminance.y=GetPixelLuma(image,p+GetPixelChannels(image))-(double)
5721 GetPixelLuma(image,p+2*GetPixelChannels(image));
5722 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
5723 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
5724 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5725 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5726 if (fabs((
double) luminance.x) < fabs((
double) luminance.y))
5731 if (delta.x <= delta.y)
5736 delta.y=1.0-delta.y;
5737 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5738 gamma=MagickSafeReciprocal(gamma);
5739 pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red,
5740 pixels[3].red,pixels[0].red);
5741 pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green,
5742 pixels[3].green,pixels[0].green);
5743 pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
5744 pixels[3].blue,pixels[0].blue);
5745 if (image->colorspace == CMYKColorspace)
5746 pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black,
5747 pixels[3].black,pixels[0].black);
5748 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5749 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha,
5750 pixels[3].alpha,pixels[0].alpha);
5757 delta.x=1.0-delta.x;
5758 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5759 gamma=MagickSafeReciprocal(gamma);
5760 pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red,
5761 pixels[0].red,pixels[3].red);
5762 pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green,
5763 pixels[0].green,pixels[3].green);
5764 pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
5765 pixels[0].blue,pixels[3].blue);
5766 if (image->colorspace == CMYKColorspace)
5767 pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black,
5768 pixels[0].black,pixels[3].black);
5769 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5770 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha,
5771 pixels[0].alpha,pixels[3].alpha);
5779 if (delta.x <= (1.0-delta.y))
5784 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5785 gamma=MagickSafeReciprocal(gamma);
5786 pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red,
5787 pixels[1].red,pixels[2].red);
5788 pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green,
5789 pixels[1].green,pixels[2].green);
5790 pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
5791 pixels[1].blue,pixels[2].blue);
5792 if (image->colorspace == CMYKColorspace)
5793 pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black,
5794 pixels[1].black,pixels[2].black);
5795 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5796 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha,
5797 pixels[1].alpha,pixels[2].alpha);
5804 delta.x=1.0-delta.x;
5805 delta.y=1.0-delta.y;
5806 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5807 gamma=MagickSafeReciprocal(gamma);
5808 pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red,
5809 pixels[2].red,pixels[1].red);
5810 pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green,
5811 pixels[2].green,pixels[1].green);
5812 pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
5813 pixels[2].blue,pixels[1].blue);
5814 if (image->colorspace == CMYKColorspace)
5815 pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black,
5816 pixels[2].black,pixels[1].black);
5817 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
5818 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha,
5819 pixels[2].alpha,pixels[1].alpha);
5824 case NearestInterpolatePixel:
5826 x_offset=CastDoubleToSsizeT(floor(x+0.5));
5827 y_offset=CastDoubleToSsizeT(floor(y+0.5));
5828 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
5829 if (p == (
const Quantum *) NULL)
5834 GetPixelInfoPixel(image,p,pixel);
5837 case SplineInterpolatePixel:
5843 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5845 if (p == (
const Quantum *) NULL)
5850 for (i=0; i < 16L; i++)
5851 AlphaBlendPixelInfo(image,p+i*(ssize_t) GetPixelChannels(image),
5853 SplineWeights((
double) (x-x_offset),&cx);
5854 SplineWeights((
double) (y-y_offset),&cy);
5855 pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]*
5856 pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
5857 pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]*
5858 pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]*
5859 pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]*
5860 pixels[14].red+cx[3]*pixels[15].red));
5861 pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]*
5862 pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+
5863 cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+
5864 cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]*
5865 pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]*pixels[12].green+
5866 cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]*pixels[15].green));
5867 pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]*
5868 pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
5869 pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]*
5870 pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
5871 pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+
5872 cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
5873 if (image->colorspace == CMYKColorspace)
5874 pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]*
5875 pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+
5876 cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+
5877 cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]*
5878 pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]*
5879 pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]*
5881 pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]*
5882 pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+
5883 cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+
5884 cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]*
5885 pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+
5886 cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
5924MagickExport MagickBooleanType IsFuzzyEquivalencePixel(
const Image *image,
5925 const Quantum *p,
const Image *target_image,
const Quantum *q)
5928 alpha = QuantumScale*(double) GetPixelAlpha(image,p),
5929 fuzz = GetFuzzyColorDistance(image,target_image),
5930 target_alpha = QuantumScale*(double) GetPixelAlpha(target_image,q);
5938 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5943 PixelChannel channel = GetPixelChannelChannel(image,i);
5944 PixelTrait traits = GetPixelChannelTraits(image,channel);
5945 PixelTrait target_traits = GetPixelChannelTraits(target_image,channel);
5946 if (((traits & UpdatePixelTrait) == 0) ||
5947 ((target_traits & UpdatePixelTrait) == 0))
5949 if (channel == AlphaPixelChannel)
5950 error=(double) p[i]-(
double) GetPixelChannel(target_image,channel,q);
5952 error=alpha*(double) p[i]-target_alpha*
5953 GetPixelChannel(target_image,channel,q);
5954 if (MagickSafeSignificantError(error*error,fuzz) != MagickFalse)
5955 return(MagickFalse);
6004MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(
const PixelInfo *p,
6013 fuzz=p->fuzz*p->fuzz+q->fuzz*q->fuzz;
6016 if ((p->alpha_trait != UndefinedPixelTrait) ||
6017 (q->alpha_trait != UndefinedPixelTrait))
6022 pixel=(p->alpha_trait != UndefinedPixelTrait ? p->alpha :
6023 (double) OpaqueAlpha)-(q->alpha_trait != UndefinedPixelTrait ?
6024 q->alpha : (
double) OpaqueAlpha);
6025 distance=pixel*pixel;
6026 if (MagickSafeSignificantError(distance,fuzz) != MagickFalse)
6027 return(MagickFalse);
6032 if (p->alpha_trait != UndefinedPixelTrait)
6033 scale=(QuantumScale*p->alpha);
6034 if (q->alpha_trait != UndefinedPixelTrait)
6035 scale*=(QuantumScale*q->alpha);
6036 if (scale <= MagickEpsilon)
6042 if (p->colorspace == CMYKColorspace)
6044 pixel=p->black-q->black;
6045 distance+=pixel*pixel*scale;
6046 if (MagickSafeSignificantError(distance,fuzz) != MagickFalse)
6047 return(MagickFalse);
6048 scale*=QuantumScale*((double) QuantumRange-(double) p->black);
6049 scale*=QuantumScale*((double) QuantumRange-(double) q->black);
6056 pixel=p->red-q->red;
6057 if (IsHueCompatibleColorspace(p->colorspace) != MagickFalse)
6064 if (fabs((
double) pixel) > ((
double) QuantumRange/2.0))
6065 pixel-=(double) QuantumRange;
6068 distance+=pixel*pixel*scale;
6069 if (MagickSafeSignificantError(distance,fuzz) != MagickFalse)
6070 return(MagickFalse);
6071 pixel=p->green-q->green;
6072 distance+=pixel*pixel*scale;
6073 if (MagickSafeSignificantError(distance,fuzz) != MagickFalse)
6074 return(MagickFalse);
6075 pixel=p->blue-q->blue;
6076 distance+=pixel*pixel*scale;
6077 if (MagickSafeSignificantError(distance,fuzz) != MagickFalse)
6078 return(MagickFalse);
6106MagickPrivate MagickBooleanType ResetPixelChannelMap(Image *image,
6107 ExceptionInfo *exception)
6115 assert(image != (Image *) NULL);
6116 assert(image->signature == MagickCoreSignature);
6117 (void) memset(image->channel_map,0,MaxPixelChannels*
6118 sizeof(*image->channel_map));
6119 trait=UpdatePixelTrait;
6120 if (image->alpha_trait != UndefinedPixelTrait)
6121 trait=(PixelTrait) (trait | BlendPixelTrait);
6123 if ((image->colorspace == LinearGRAYColorspace) ||
6124 (image->colorspace == GRAYColorspace))
6126 SetPixelChannelAttributes(image,BluePixelChannel,trait,n);
6127 SetPixelChannelAttributes(image,GreenPixelChannel,trait,n);
6128 SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
6132 SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
6133 SetPixelChannelAttributes(image,GreenPixelChannel,trait,n++);
6134 SetPixelChannelAttributes(image,BluePixelChannel,trait,n++);
6136 if (image->colorspace == CMYKColorspace)
6137 SetPixelChannelAttributes(image,BlackPixelChannel,trait,n++);
6138 if (image->alpha_trait != UndefinedPixelTrait)
6139 SetPixelChannelAttributes(image,AlphaPixelChannel,CopyPixelTrait,n++);
6140 if (image->storage_class == PseudoClass)
6141 SetPixelChannelAttributes(image,IndexPixelChannel,CopyPixelTrait,n++);
6142 if ((image->channels & ReadMaskChannel) != 0)
6143 SetPixelChannelAttributes(image,ReadMaskPixelChannel,CopyPixelTrait,n++);
6144 if ((image->channels & WriteMaskChannel) != 0)
6145 SetPixelChannelAttributes(image,WriteMaskPixelChannel,CopyPixelTrait,n++);
6146 if ((image->channels & CompositeMaskChannel) != 0)
6147 SetPixelChannelAttributes(image,CompositeMaskPixelChannel,CopyPixelTrait,
6149 if (image->number_meta_channels != 0)
6157 if (image->number_meta_channels >= (
size_t) (MaxPixelChannels-MetaPixelChannels))
6159 image->number_channels=(size_t) n;
6160 image->number_meta_channels=0;
6161 (void) SetPixelChannelMask(image,image->channel_mask);
6162 ThrowBinaryException(CorruptImageError,
"MaximumChannelsExceeded",
6165 meta_channel=MetaPixelChannels;
6166 for (i=0; i < (ssize_t) image->number_meta_channels; i++)
6168 SetPixelChannelAttributes(image,meta_channel,UpdatePixelTrait,n);
6169 meta_channel=(PixelChannel) (meta_channel+1);
6173 image->number_channels=(size_t) n;
6174 (void) SetPixelChannelMask(image,image->channel_mask);
6205static void LogPixelChannels(
const Image *image)
6210 (void) LogMagickEvent(PixelEvent,GetMagickModule(),
"%s[0x%08llx]",
6211 image->filename,(MagickOffsetType) image->channel_mask);
6212 for (i=0; i < (ssize_t) image->number_channels; i++)
6215 channel_name[MagickPathExtent],
6216 traits[MagickPathExtent];
6224 channel=GetPixelChannelChannel(image,i);
6227 case RedPixelChannel:
6230 if (image->colorspace == CMYKColorspace)
6232 if ((image->colorspace == LinearGRAYColorspace) ||
6233 (image->colorspace == GRAYColorspace))
6237 case GreenPixelChannel:
6240 if (image->colorspace == CMYKColorspace)
6244 case BluePixelChannel:
6247 if (image->colorspace == CMYKColorspace)
6251 case BlackPixelChannel:
6254 if (image->storage_class == PseudoClass)
6258 case IndexPixelChannel:
6263 case AlphaPixelChannel:
6268 case ReadMaskPixelChannel:
6273 case WriteMaskPixelChannel:
6278 case CompositeMaskPixelChannel:
6280 name=
"composite-mask";
6283 case MetaPixelChannels:
6291 if (image->colorspace == UndefinedColorspace)
6293 (void) FormatLocaleString(channel_name,MagickPathExtent,
"%.17g",
6295 name=(
const char *) channel_name;
6298 if ((GetPixelChannelTraits(image,channel) & UpdatePixelTrait) != 0)
6299 (void) ConcatenateMagickString(traits,
"update,",MagickPathExtent);
6300 if ((GetPixelChannelTraits(image,channel) & BlendPixelTrait) != 0)
6301 (void) ConcatenateMagickString(traits,
"blend,",MagickPathExtent);
6302 if ((GetPixelChannelTraits(image,channel) & CopyPixelTrait) != 0)
6303 (void) ConcatenateMagickString(traits,
"copy,",MagickPathExtent);
6304 if (*traits ==
'\0')
6305 (void) ConcatenateMagickString(traits,
"undefined,",MagickPathExtent);
6306 traits[strlen(traits)-1]=
'\0';
6307 (void) LogMagickEvent(PixelEvent,GetMagickModule(),
" %.17g: %s (%s)",
6308 (
double) i,name,traits);
6312MagickExport ChannelType SetPixelChannelMask(Image *image,
6313 const ChannelType channel_mask)
6315#define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
6323 assert(image != (Image *) NULL);
6324 assert(image->signature == MagickCoreSignature);
6325 if (image->debug != MagickFalse)
6326 (void) LogMagickEvent(PixelEvent,GetMagickModule(),
"%s[0x%08llx]",
6327 image->filename,(MagickOffsetType) channel_mask);
6328 mask=image->channel_mask;
6329 image->channel_mask=channel_mask;
6330 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
6332 PixelChannel channel = GetPixelChannelChannel(image,i);
6333 if (GetChannelBit(channel_mask,channel) == 0)
6335 SetPixelChannelTraits(image,channel,CopyPixelTrait);
6338 if (channel == AlphaPixelChannel)
6340 if ((image->alpha_trait & CopyPixelTrait) != 0)
6342 SetPixelChannelTraits(image,channel,CopyPixelTrait);
6345 SetPixelChannelTraits(image,channel,UpdatePixelTrait);
6348 if (image->alpha_trait != UndefinedPixelTrait)
6350 SetPixelChannelTraits(image,channel,(PixelTrait) (UpdatePixelTrait |
6354 SetPixelChannelTraits(image,channel,UpdatePixelTrait);
6356 if (image->storage_class == PseudoClass)
6357 SetPixelChannelTraits(image,IndexPixelChannel,CopyPixelTrait);
6358 if ((image->channels & ReadMaskChannel) != 0)
6359 SetPixelChannelTraits(image,ReadMaskPixelChannel,CopyPixelTrait);
6360 if ((image->channels & WriteMaskChannel) != 0)
6361 SetPixelChannelTraits(image,WriteMaskPixelChannel,CopyPixelTrait);
6362 if ((image->channels & CompositeMaskChannel) != 0)
6363 SetPixelChannelTraits(image,CompositeMaskPixelChannel,CopyPixelTrait);
6364 if ((GetLogEventMask() & PixelEvent) != 0)
6365 LogPixelChannels(image);
6396MagickExport MagickBooleanType SetPixelMetaChannels(Image *image,
6397 const size_t number_meta_channels,ExceptionInfo *exception)
6402 if (number_meta_channels >= (
size_t) (MaxPixelChannels-MetaPixelChannels))
6403 ThrowBinaryException(CorruptImageError,
"MaximumChannelsExceeded",
6405 image->number_meta_channels=number_meta_channels;
6406 status=ResetPixelChannelMap(image,exception);
6407 if (status == MagickFalse)
6408 return(MagickFalse);
6409 return(SyncImagePixelCache(image,exception));
6437MagickExport MagickBooleanType SortImagePixels(Image *image,
6438 ExceptionInfo *exception)
6440#define SolarizeImageTag "Solarize/Image"
6457 assert(image != (Image *) NULL);
6458 assert(image->signature == MagickCoreSignature);
6459 if (IsEventLogging() != MagickFalse)
6460 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
6463 image_view=AcquireAuthenticCacheView(image,exception);
6464#if defined(MAGICKCORE_OPENMP_SUPPORT)
6465 #pragma omp parallel for schedule(static) shared(progress,status) \
6466 magick_number_threads(image,image,image->rows,1)
6468 for (y=0; y < (ssize_t) image->rows; y++)
6476 if (status == MagickFalse)
6478 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
6479 if (q == (Quantum *) NULL)
6484 for (x=0; x < (ssize_t) image->columns-1; x++)
6493 previous=GetPixelIntensity(image,q);
6494 for (j=0; j < ((ssize_t) image->columns-x-1); j++)
6496 current=GetPixelIntensity(image,q+(j+1)*(ssize_t)
6497 GetPixelChannels(image));
6498 if (previous > current)
6501 pixel[MaxPixelChannels];
6506 (void) memcpy(pixel,q+j*(ssize_t) GetPixelChannels(image),
6507 GetPixelChannels(image)*
sizeof(Quantum));
6508 (void) memcpy(q+j*(ssize_t) GetPixelChannels(image),q+(j+1)*
6509 (ssize_t) GetPixelChannels(image),GetPixelChannels(image)*
6511 (void) memcpy(q+(j+1)*(ssize_t) GetPixelChannels(image),pixel,
6512 GetPixelChannels(image)*
sizeof(Quantum));
6518 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
6520 if (image->progress_monitor != (MagickProgressMonitor) NULL)
6525#if defined(MAGICKCORE_OPENMP_SUPPORT)
6529 proceed=SetImageProgress(image,SolarizeImageTag,progress,image->rows);
6530 if (proceed == MagickFalse)
6534 image_view=DestroyCacheView(image_view);