return(MagickFalse);
return(status);
}
+ case HSIColorspace:
+ {
+ /*
+ Transform image from sRGB to HSI.
+ */
+ if (image->storage_class == PseudoClass)
+ {
+ if (SyncImage(image,exception) == MagickFalse)
+ return(MagickFalse);
+ if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
+ return(MagickFalse);
+ }
+ image_view=AcquireAuthenticCacheView(image,exception);
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(static,4) shared(status) \
+ magick_threads(image,image,image->rows,1)
+#endif
+ for (y=0; y < (ssize_t) image->rows; y++)
+ {
+ MagickBooleanType
+ sync;
+
+ register ssize_t
+ x;
+
+ register Quantum
+ *restrict q;
+
+ if (status == MagickFalse)
+ continue;
+ q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
+ exception);
+ if (q == (Quantum *) NULL)
+ {
+ status=MagickFalse;
+ continue;
+ }
+ for (x=0; x < (ssize_t) image->columns; x++)
+ {
+ double
+ blue,
+ green,
+ hue,
+ intensity,
+ red,
+ saturation;
+
+ red=DecodePixelGamma((MagickRealType) GetPixelRed(image,q));
+ green=DecodePixelGamma((MagickRealType) GetPixelGreen(image,q));
+ blue=DecodePixelGamma((MagickRealType) GetPixelBlue(image,q));
+ ConvertRGBToHSI(red,green,blue,&hue,&saturation,&intensity);
+ SetPixelRed(image,ClampToQuantum(QuantumRange*hue),q);
+ SetPixelGreen(image,ClampToQuantum(QuantumRange*saturation),q);
+ SetPixelBlue(image,ClampToQuantum(QuantumRange*intensity),q);
+ q+=GetPixelChannels(image);
+ }
+ sync=SyncCacheViewAuthenticPixels(image_view,exception);
+ if (sync == MagickFalse)
+ status=MagickFalse;
+ }
+ image_view=DestroyCacheView(image_view);
+ if (SetImageColorspace(image,colorspace,exception) == MagickFalse)
+ return(MagickFalse);
+ return(status);
+ }
case HSLColorspace:
{
/*
return(MagickFalse);
return(status);
}
+ case HSIColorspace:
+ {
+ /*
+ Transform image from HSI to sRGB.
+ */
+ if (image->storage_class == PseudoClass)
+ {
+ if (SyncImage(image,exception) == MagickFalse)
+ return(MagickFalse);
+ if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
+ return(MagickFalse);
+ }
+ image_view=AcquireAuthenticCacheView(image,exception);
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(static,4) shared(status) \
+ magick_threads(image,image,image->rows,1)
+#endif
+ for (y=0; y < (ssize_t) image->rows; y++)
+ {
+ MagickBooleanType
+ sync;
+
+ register ssize_t
+ x;
+
+ register Quantum
+ *restrict q;
+
+ if (status == MagickFalse)
+ continue;
+ q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
+ exception);
+ if (q == (Quantum *) NULL)
+ {
+ status=MagickFalse;
+ continue;
+ }
+ for (x=0; x < (ssize_t) image->columns; x++)
+ {
+ double
+ blue,
+ green,
+ hue,
+ intensity,
+ red,
+ saturation;
+
+ hue=(double) (QuantumScale*GetPixelRed(image,q));
+ saturation=(double) (QuantumScale*GetPixelGreen(image,q));
+ intensity=(double) (QuantumScale*GetPixelBlue(image,q));
+ ConvertHSIToRGB(hue,saturation,intensity,&red,&green,&blue);
+ SetPixelRed(image,ClampToQuantum(EncodePixelGamma(red)),q);
+ SetPixelGreen(image,ClampToQuantum(EncodePixelGamma(green)),q);
+ SetPixelBlue(image,ClampToQuantum(EncodePixelGamma(blue)),q);
+ q+=GetPixelChannels(image);
+ }
+ sync=SyncCacheViewAuthenticPixels(image_view,exception);
+ if (sync == MagickFalse)
+ status=MagickFalse;
+ }
+ image_view=DestroyCacheView(image_view);
+ if (SetImageColorspace(image,sRGBColorspace,exception) == MagickFalse)
+ return(MagickFalse);
+ return(status);
+ }
case HSLColorspace:
{
/*
GRAYColorspace,
HCLColorspace,
HSBColorspace,
+ HSIColorspace,
HSLColorspace,
HWBColorspace,
LabColorspace,
ConvertHSBToRGB(hue,saturation,brightness,red,green,blue);
}
+static inline void ModulateHSI(const double percent_hue,
+ const double percent_saturation,const double percent_intensity,double *red,
+ double *green,double *blue)
+{
+ double
+ intensity,
+ hue,
+ saturation;
+
+ /*
+ Increase or decrease color intensity, saturation, or hue.
+ */
+ ConvertRGBToHSI(*red,*green,*blue,&hue,&saturation,&intensity);
+ hue+=0.5*(0.01*percent_hue-1.0);
+ while (hue < 0.0)
+ hue+=1.0;
+ while (hue > 1.0)
+ hue-=1.0;
+ saturation*=0.01*percent_saturation;
+ intensity*=0.01*percent_intensity;
+ ConvertHSIToRGB(hue,saturation,intensity,red,green,blue);
+}
+
static inline void ModulateHSL(const double percent_hue,
const double percent_saturation,const double percent_lightness,double *red,
double *green,double *blue)
&red,&green,&blue);
break;
}
+ case HSIColorspace:
+ {
+ ModulateHSI(percent_hue,percent_saturation,percent_brightness,
+ &red,&green,&blue);
+ break;
+ }
case HSLColorspace:
default:
{
double *),
ConvertHSBToRGB(const double,const double,const double,double *,double *,
double *),
+ ConvertHSIToRGB(const double,const double,const double,double *,double *,
+ double *),
ConvertHWBToRGB(const double,const double,const double,double *,double *,
double *),
ConvertLCHabToRGB(const double,const double,const double,double *,double *,
double *),
ConvertRGBToHSB(const double,const double,const double,double *,double *,
double *),
+ ConvertRGBToHSI(const double,const double,const double,double *,double *,
+ double *),
ConvertRGBToHWB(const double,const double,const double,double *,double *,
double *),
ConvertRGBToLCHab(const double,const double,const double,double *,double *,
% %
% %
% %
+% C o n v e r t H S I T o R G B %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% ConvertHSIToRGB() transforms a (hue, saturation, intensity) to a (red,
+% green, blue) triple.
+%
+% The format of the ConvertHSIToRGBImage method is:
+%
+% void ConvertHSIToRGB(const double hue,const double saturation,
+% const double intensity,double *red,double *green,double *blue)
+%
+% A description of each parameter follows:
+%
+% o hue, saturation, intensity: A double value representing a
+% component of the HSI color space.
+%
+% o red, green, blue: A pointer to a pixel component of type Quantum.
+%
+*/
+MagickPrivate void ConvertHSIToRGB(const double hue,const double saturation,
+ const double intensity,double *red,double *green,double *blue)
+{
+ double
+ h;
+
+ /*
+ Convert HSI to RGB colorspace.
+ */
+ assert(red != (double *) NULL);
+ assert(green != (double *) NULL);
+ assert(blue != (double *) NULL);
+ h=360.0*hue;
+ h-=360.0*floor(h/360.0);
+ if (h < 120.0)
+ {
+ *blue=intensity*(1.0-saturation);
+ *red=intensity*(1.0+saturation*cos(h*(MagickPI/180.0))/cos((60.0-h)*
+ (MagickPI/180.0)));
+ *green=3.0*intensity-*red-*blue;
+ }
+ else
+ if (h < 240.0)
+ {
+ h-=120.0;
+ *red=intensity*(1.0-saturation);
+ *green=intensity*(1.0+saturation*cos(h*(MagickPI/180.0))/cos((60.0-h)*
+ (MagickPI/180.0)));
+ *blue=3.0*intensity-*red-*green;
+ }
+ else
+ {
+ h-=240.0;
+ *green=intensity*(1.0-saturation);
+ *blue=intensity*(1.0+saturation*cos(h*(MagickPI/180.0))/cos((60.0-h)*
+ (MagickPI/180.0)));
+ *red=3.0*intensity-*green-*blue;
+ }
+ *red*=QuantumRange;
+ *green*=QuantumRange;
+ *blue*=QuantumRange;
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
% C o n v e r t H S L T o R G B %
% %
% %
% %
% %
% %
+% C o n v e r t R G B T o H S I %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% ConvertRGBToHSI() transforms a (red, green, blue) to a (hue, saturation,
+% intensity) triple.
+%
+% The format of the ConvertRGBToHSI method is:
+%
+% void ConvertRGBToHSI(const double red,const double green,
+% const double blue,double *hue,double *saturation,double *intensity)
+%
+% A description of each parameter follows:
+%
+% o red, green, blue: A Quantum value representing the red, green, and
+% blue component of a pixel..
+%
+% o hue, saturation, intensity: A pointer to a double value representing a
+% component of the HSI color space.
+%
+*/
+MagickPrivate void ConvertRGBToHSI(const double red,const double green,
+ const double blue,double *hue,double *saturation,double *intensity)
+{
+ double
+ alpha,
+ beta;
+
+ /*
+ Convert RGB to HSI colorspace.
+ */
+ assert(hue != (double *) NULL);
+ assert(saturation != (double *) NULL);
+ assert(intensity != (double *) NULL);
+ *intensity=(QuantumScale*red+QuantumScale*green+QuantumScale*blue)/3.0;
+ if (*intensity <= 0.0)
+ {
+ *hue=0.0;
+ *saturation=0.0;
+ }
+ else
+ {
+ *saturation=1.0-MagickMin(QuantumScale*red,MagickMin(QuantumScale*green,
+ QuantumScale*blue))/(*intensity);
+ alpha=0.5*(2.0*QuantumScale*red-QuantumScale*green-QuantumScale*blue);
+ beta=0.866025403784439*(QuantumScale*green-QuantumScale*blue);
+ *hue=atan2(beta,alpha)*(180.0/MagickPI)/360.0;
+ if (*hue < 0.0)
+ *hue+=1.0;
+ }
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
% C o n v e r t R G B T o H S L %
% %
% %
{ "Gray", GRAYColorspace, UndefinedOptionFlag, MagickFalse },
{ "HCL", HCLColorspace, UndefinedOptionFlag, MagickFalse },
{ "HSB", HSBColorspace, UndefinedOptionFlag, MagickFalse },
+ { "HSI", HSIColorspace, UndefinedOptionFlag, MagickFalse },
{ "HSL", HSLColorspace, UndefinedOptionFlag, MagickFalse },
{ "HWB", HWBColorspace, UndefinedOptionFlag, MagickFalse },
{ "Lab", LabColorspace, UndefinedOptionFlag, MagickFalse },