1
我有示例代碼,但它完全遺漏了我的(void *)should_be!如何在OpenCL中表示圖像
我設置一個cl_image_desc,cl_image_format,緩存,產地,以及區域:
cl_image_desc desc;
desc.image_type = CL_MEM_OBJECT_IMAGE2D;
desc.image_width = width;
desc.image_height = height;
desc.image_depth = 0;
desc.image_array_size = 0;
desc.image_row_pitch = 0;
desc.image_slice_pitch = 0;
desc.num_mip_levels = 0;
desc.num_samples = 0;
desc.buffer = NULL;
cl_image_format format;
format.image_channel_order = CL_R;
format.image_channel_data_type = CL_FLOAT;
cl_mem bufferSourceImage = clCreateImage(context, CL_MEM_READ_ONLY, &format, &desc, NULL, NULL);
size_t origin[3] = {0, 0, 0};
size_t region[3] = {width, height,1};
在接下來的片段sourceImage是一個空指針,以我的形象。但是我的形象是什麼?對於每個像素有r,g,b,a,x和y值。
clEnqueueWriteImage(queue, bufferSourceImage, CL_TRUE, origin, region, 0, 0, sourceImage, 0, NULL, NULL);
如何將我的圖像(一堆(r,g,b,a,x,y))轉換爲合適的數組?
這是他們所提供的內核:
__kernel void convolution(__read_only image2d_t sourceImage, __write_only image2d_t outputImage, int rows, int cols, __constant float* filter, int filterWidth, sampler_t sampler)
{
int column = get_global_id(0);
int row = get_global_id(1);
int halfWidth = (int)(filterWidth/2);
float4 sum = {0.0f, 0.0f, 0.0f, 0.0f};
int filterIdx = 0;
int2 coords;
for(int i = -halfWidth; i <= halfWidth; i++)
{
coords.y = row + i;
for(int i2 = -halfWidth; i2 <= halfWidth; i2++)
{
coords.x = column + i2;
float4 pixel;
pixel = read_imagef(sourceImage, sampler, coords);
sum.x += pixel.x * filter[filterIdx++];
}
}
if(myRow < rows && myCol < cols)
{
coords.x = column;
coords.y = row;
write_imagef(outputImage, coords, sum);
}
}
好了,所以根據這個表格http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/read_imagef2d.html會我(將圖像轉換爲數組的術語是什麼?)將圖像轉換爲看起來像{{r,g,b,1},{r,g,b,1}等}的數組,其中每個元素被映射到圖像的行* w + col? – user1873073
對此沒有單一術語。我猜你讀了一張圖片,你的頻道長8位。 CL_R表示三個顏色通道中只有一個通道。示例代碼來自哪裏? –
'clCreateImage'爲您創建了正確的維度矢量數組,您必須填寫R通道。 –