该程序是Android应用程序,需要进行mp4图像处理。初始化可以在这个问题中找到:init code
但我发现init代码适用于不使用for
循环的内核。
当我在帖子底部的示例中有一个嵌套的for循环时,只会处理第一个图像而所有其他图像都将是黑色。
简单示例:
1)
init function
execute kernel with for loops
remove opencl function
=>一切顺利
2)
init function
execute kernel **without** for loops
execute kernel **without** for loops on next frame
remove opencl function
=>一切顺利
3)
init function
execute kernel **with** for loops
execute kernel **with** for loops on next frame
remove opencl function
=>第一帧被处理,第二帧是黑色
边缘内核:
__kernel void edgeKernel(__read_only image2d_t srcImage,
__write_only image2d_t dstImage)
{
const sampler_t sampler = CLK_NORMALIZED_COORDS_TRUE |
CLK_ADDRESS_REPEAT |
CLK_FILTER_NEAREST;
int x = get_global_id(0);
int y = get_global_id(1);
int2 coords = (int2) (x,y);
int i = 0;
int j = 0;
float4 bufferPixel,currentPixel;
float sum = 0;
int counter = 0;
const float edgeKernel[9] = {0.0f,1.0f,0.0f,1.0f,-4.0f,1.0f,0.0f,1.0f,0.0f};
currentPixel = read_imagef(srcImage,sampler,coords);
for(i=-1;i<=1;i++)
{
for(j=-1;j<=1;j++)
{
coords = (int2)((x+i),(y+j));
bufferPixel = read_imagef(srcImage,sampler,coords);
//sum = sum + (bufferPixel.y * edgeKernel[counter]);
sum = mad(bufferPixel.y,edgeKernel[counter],sum);
counter++;
}
}
if(sum>255) sum=255;
if(sum<0) sum=0;
currentPixel.x=sum;
currentPixel.y=sum;
currentPixel.z=sum;
write_imagef(dstImage,coords,currentPixel);
}
我看不出有什么不对,我猜它是内存分配重叠的东西,但我对解决方案可能是什么一无所知。
EDIT1:
OpenCL code是OpenCL代码的链接。查找initOpenCL
和nativeImage2DOpenCL
函数。你应该能够找到你需要的一切。