java - how to know if the pixel color is black from a float 4 -
i ask question how know pixel color using t_sampler in jocl in different way want konw if pixel black or white knowing using t_sampler in kernel
const sampler_t smp = clk_normalized_coords_false | //natural coordinates clk_address_clamp | //clamp zeros clk_filter_nearest; //don't interpolate
then used
int2 coord = (int2)(get_global_id(0), get_global_id(1)); float4 pixel = read_imageui(input, smp, coord);
my question is: how use value pixel know color of concerned pixel?
i stuck few days , tried many solutions solve problem, if need clarifications respond. here kernel code
const sampler_t smp = clk_normalized_coords_false | //natural coordinates clk_address_clamp | //clamp zeros clk_filter_nearest; //don't interpolate __kernel void basic(__read_only image2d_t input,__global float *result) { int gidx = get_global_id(0); int gidy = get_global_id(1); int2 coord = (int2)(get_global_id(0), get_global_id(1)); int2 posin = {gidx, gidy}; float4 pixel = read_imagef(input, smp, posin); if ((pixel.x==0.0) && (pixel.y==0.0) && (pixel.z==0.0) ){ result[gidx]=1; } else result[gidx]=0; }
read pixel using read_imagef
(i recommend instead of read_imageui
, depending on image format, since in example assigning float4 variable; check specification appropriate each image format). float4 components returned can checked. pixel.x
red, pixel.y
green, pixel.z
blue, , pixel.w
alpha (1.0f if source format doesn't have alpha). check black (as ask in subject of question), check .x , .y , .z 0.0.
Comments
Post a Comment