inline float getAlphaF4(float4 p) { return p.w; }
inline void setAlphaF4(float4* p, float value) { (*p).w = value; }
- inline float GetPixelIntensity(const int method, const int colorspace, CLPixelType p)
+ inline float GetPixelIntensity(const unsigned int colorspace,
+ const unsigned int method,float red,float green,float blue)
{
- float red = getRed(p);
- float green = getGreen(p);
- float blue = getBlue(p);
-
float intensity;
if (colorspace == GRAYColorspace)
}
}
- return intensity;
-
+ return intensity;
}
)
*/
__kernel void Histogram(__global CLPixelType * restrict im,
const ChannelType channel,
- const int method,
- const int colorspace,
+ const unsigned int colorspace,
+ const unsigned int method,
__global uint4 * restrict histogram)
{
const int x = get_global_id(0);
const int c = x + y * columns;
if ((channel & SyncChannels) != 0)
{
- float intensity = GetPixelIntensity(method, colorspace,im[c]);
+ float red=(float)getRed(im[c]);
+ float green=(float)getGreen(im[c]);
+ float blue=(float)getBlue(im[c]);
+
+ float intensity = GetPixelIntensity(colorspace, method, red, green, blue);
uint pos = ScaleQuantumToMap(ClampToQuantum(intensity));
atomic_inc((__global uint *)(&(histogram[pos]))+2); //red position
}
STRINGIFY(
__kernel void Grayscale(__global CLQuantum *im,const int number_channels,
- const int method,const int colorspace)
+ const unsigned int colorspace,const unsigned int method)
{
const int x = get_global_id(0);
const int y = get_global_id(1);
green=(float)im[c+1];
blue=(float)im[c+2];
- intensity=0.0;
-
- switch (method)
- {
- case AveragePixelIntensityMethod:
- {
- intensity=(red+green+blue)/3.0;
- break;
- }
- case BrightnessPixelIntensityMethod:
- {
- intensity=MagickMax(MagickMax(red,green),blue);
- break;
- }
- case LightnessPixelIntensityMethod:
- {
- intensity=(MagickMin(MagickMin(red,green),blue)+
- MagickMax(MagickMax(red,green),blue))/2.0;
- break;
- }
- case MSPixelIntensityMethod:
- {
- intensity=(float) (((float) red*red+green*green+
- blue*blue)/(3.0*QuantumRange));
- break;
- }
- case Rec601LumaPixelIntensityMethod:
- {
- /*
- if (colorspace == RGBColorspace)
- {
- red=EncodePixelGamma(red);
- green=EncodePixelGamma(green);
- blue=EncodePixelGamma(blue);
- }
- */
- intensity=0.298839*red+0.586811*green+0.114350*blue;
- break;
- }
- case Rec601LuminancePixelIntensityMethod:
- {
- /*
- if (image->colorspace == sRGBColorspace)
- {
- red=DecodePixelGamma(red);
- green=DecodePixelGamma(green);
- blue=DecodePixelGamma(blue);
- }
- */
- intensity=0.298839*red+0.586811*green+0.114350*blue;
- break;
- }
- case Rec709LumaPixelIntensityMethod:
- default:
- {
- /*
- if (image->colorspace == RGBColorspace)
- {
- red=EncodePixelGamma(red);
- green=EncodePixelGamma(green);
- blue=EncodePixelGamma(blue);
- }
- */
- intensity=0.212656*red+0.715158*green+0.072186*blue;
- break;
- }
- case Rec709LuminancePixelIntensityMethod:
- {
- /*
- if (image->colorspace == sRGBColorspace)
- {
- red=DecodePixelGamma(red);
- green=DecodePixelGamma(green);
- blue=DecodePixelGamma(blue);
- }
- */
- intensity=0.212656*red+0.715158*green+0.072186*blue;
- break;
- }
- case RMSPixelIntensityMethod:
- {
- intensity=(float) (sqrt((float) red*red+green*green+
- blue*blue)/sqrt(3.0));
- break;
- }
-
- }
-
+ intensity = GetPixelIntensity(colorspace, method, red, green, blue);
im[c] = im[c+1] = im[c+2] = ClampToQuantum(intensity);
}
)
return(MagickTrue);
}
-static MagickBooleanType checkHistogramCondition(Image *image)
+static MagickBooleanType checkPixelIntensity(const Image *image,
+ const PixelIntensityMethod method)
{
- /* ensure this is the only pass get in for now. */
- if ((image->channel_mask & SyncChannels) == 0)
- return MagickFalse;
+ /* EncodePixelGamma and DecodePixelGamma are not supported */
+ if ((method == Rec601LumaPixelIntensityMethod) ||
+ (method == Rec709LumaPixelIntensityMethod))
+ {
+ if (image->colorspace == RGBColorspace)
+ return(MagickFalse);
+ }
- if (image->intensity == Rec601LuminancePixelIntensityMethod ||
- image->intensity == Rec709LuminancePixelIntensityMethod)
- return MagickFalse;
+ if ((method == Rec601LuminancePixelIntensityMethod) ||
+ (method == Rec709LuminancePixelIntensityMethod))
+ {
+ if (image->colorspace == sRGBColorspace)
+ return(MagickFalse);
+ }
+
+ return(MagickTrue);
+}
- if (image->colorspace != sRGBColorspace)
+static MagickBooleanType checkHistogramCondition(const Image *image,
+ const PixelIntensityMethod method)
+{
+ /* ensure this is the only pass get in for now. */
+ if ((image->channel_mask & SyncChannels) == 0)
return MagickFalse;
- return MagickTrue;
+ return(checkPixelIntensity(image,method));
}
static MagickBooleanType checkOpenCLEnvironment(ExceptionInfo* exception)
outputReady;
cl_int
- clStatus,
- colorspace,
- method;
+ clStatus;
cl_kernel
histogramKernel;
cl_event
event;
+ cl_uint
+ colorspace,
+ method;
+
register ssize_t
i;
histogramKernel = NULL;
outputReady = MagickFalse;
- method = image->intensity;
colorspace = image->colorspace;
+ method = image->intensity;
/* get the OpenCL kernel */
histogramKernel = AcquireOpenCLKernel(clEnv, MAGICK_OPENCL_ACCELERATE, "Histogram");
i = 0;
clStatus=clEnv->library->clSetKernelArg(histogramKernel,i++,sizeof(cl_mem),(void *)&imageBuffer);
clStatus|=clEnv->library->clSetKernelArg(histogramKernel,i++,sizeof(ChannelType),&channel);
- clStatus|=clEnv->library->clSetKernelArg(histogramKernel,i++,sizeof(cl_int),&method);
- clStatus|=clEnv->library->clSetKernelArg(histogramKernel,i++,sizeof(cl_int),&colorspace);
+ clStatus|=clEnv->library->clSetKernelArg(histogramKernel,i++,sizeof(cl_uint),&colorspace);
+ clStatus|=clEnv->library->clSetKernelArg(histogramKernel,i++,sizeof(cl_uint),&method);
clStatus|=clEnv->library->clSetKernelArg(histogramKernel,i++,sizeof(cl_mem),(void *)&histogramBuffer);
if (clStatus != CL_SUCCESS)
{
assert(exception != (ExceptionInfo *) NULL);
if ((checkAccelerateConditionRGBA(image) == MagickFalse) ||
- (checkHistogramCondition(image) == MagickFalse) ||
+ (checkHistogramCondition(image,image->intensity) == MagickFalse) ||
(checkOpenCLEnvironment(exception) == MagickFalse))
return(MagickFalse);
assert(exception != (ExceptionInfo *) NULL);
if ((checkAccelerateConditionRGBA(image) == MagickFalse) ||
- (checkHistogramCondition(image) == MagickFalse) ||
+ (checkHistogramCondition(image,image->intensity) == MagickFalse) ||
(checkOpenCLEnvironment(exception) == MagickFalse))
return(MagickFalse);
context;
cl_int
- clStatus,
- number_channels,
- colorspace,
- intensityMethod;
+ clStatus;
cl_kernel
grayscaleKernel;
cl_mem_flags
mem_flags;
+ cl_uint
+ number_channels,
+ colorspace,
+ intensityMethod;
+
MagickBooleanType
outputReady;
goto cleanup;
}
- number_channels = (cl_int) image->number_channels;
- intensityMethod = (cl_int) method;
- colorspace = (cl_int) image->colorspace;
+ number_channels = (cl_uint) image->number_channels;
+ intensityMethod = (cl_uint) method;
+ colorspace = (cl_uint) image->colorspace;
i = 0;
clStatus=clEnv->library->clSetKernelArg(grayscaleKernel,i++,sizeof(cl_mem),(void *)&imageBuffer);
- clStatus|=clEnv->library->clSetKernelArg(grayscaleKernel,i++,sizeof(cl_int),&number_channels);
- clStatus|=clEnv->library->clSetKernelArg(grayscaleKernel,i++,sizeof(cl_int),&intensityMethod);
- clStatus|=clEnv->library->clSetKernelArg(grayscaleKernel,i++,sizeof(cl_int),&colorspace);
+ clStatus|=clEnv->library->clSetKernelArg(grayscaleKernel,i++,sizeof(cl_uint),&number_channels);
+ clStatus|=clEnv->library->clSetKernelArg(grayscaleKernel,i++,sizeof(cl_uint),&colorspace);
+ clStatus|=clEnv->library->clSetKernelArg(grayscaleKernel,i++,sizeof(cl_uint),&intensityMethod);
if (clStatus != CL_SUCCESS)
{
(void) OpenCLThrowMagickException(exception, GetMagickModule(), ResourceLimitWarning, "clEnv->library->clSetKernelArg failed.", "'%s'", ".");
assert(exception != (ExceptionInfo *) NULL);
if ((checkAccelerateCondition(image) == MagickFalse) ||
+ (checkPixelIntensity(image,method) == MagickFalse) ||
(checkOpenCLEnvironment(exception) == MagickFalse))
return(MagickFalse);
- if ((method == Rec601LuminancePixelIntensityMethod) ||
- (method == Rec709LuminancePixelIntensityMethod))
- return(MagickFalse);
-
- if (image->colorspace != sRGBColorspace)
- return(MagickFalse);
-
if (image->number_channels < 3)
return(MagickFalse);