I am writing my first OpenCL imaging application. It opens up an image, runs a kernel on it and then saves the image back to file.
I can create the Input image, but I can not create the output image. I get -10: Image format not supported. I tried using the same image format as was used for the input image, but that doesn’t work. I tried other combinations, but none of them have worked. If I don’t set one of the CL_MEM_*_HOST_PTR, then I get -37: Invalid host ptr. The following is the code snippet. Any suggestions?
System: MacBookPro 8600M GT
if (pInImage->triplet_type == TT_GRAY) {
// grayscale image. just create image objects
// one for input and the other for output
cl_image_format imageFormat = { CL_R, CL_UNORM_INT8}; // Not supported by outputImage for some strange reason
// my system does not support luminance or intensity !!!
// cl_image_format imageFormat = { CL_LUMINANCE, CL_UNORM_INT8}; // Not supported by inputImage
// cl_image_format imageFormat = { CL_INTENSITY, CL_UNORM_INT8}; // Not supported by inputImage
cl_image_format imageFormat2 = { CL_R, CL_UNSIGNED_INT8}; // test format for output image
// cl_image_format imageFormat2 = { CL_R, CL_UNORM_INT8}; // test format for output image
// create input image
// not sure if CL_MEM_COPY_HOST_PTR is necessary or beneficial
// IT IS necessary (CL_MEM_COPY_HOST_PTR)
inputImage = clCreateImage2D(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, &imageFormat, pInImage->width, pInImage->height, pInImage->stride, pInImage->image, &err);
if (err != CL_SUCCESS) {
printf(“Error creating input imgage rc=%d\n”,err);
rc=9;
goto cleanup;
}
//create output image
pOutImage = DapAllocAnotherImage(pInImage);
if (!pOutImage)
{
printf(“Error allocating output image\n”);
rc=10;
goto cleanup;
}
// outputImage = clCreateImage2D(context, CL_MEM_WRITE_ONLY | CL_MEM_COPY_HOST_PTR, &imageFormat, pOutImage->width, pOutImage->height, pOutImage->stride, pOutImage->image, &err);
// outputImage = clCreateImage2D(context, CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR, &imageFormat, pOutImage->width, pOutImage->height, pOutImage->stride, pOutImage->image, &err);
// outputImage = clCreateImage2D(context, CL_MEM_WRITE_ONLY, &imageFormat2, pOutImage->width, pOutImage->height, pOutImage->stride, NULL, &err);
outputImage = clCreateImage2D(context, CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR, &imageFormat2, pOutImage->width, pOutImage->height, pOutImage->stride, NULL, &err);
if (err != CL_SUCCESS) {
printf(“Error creating output image rc=%d\n”,err);
rc=11;
goto cleanup;
}