Esempio n. 1
0
File: ocl.c Progetto: aosp/dvp
DVP_Error_e ocl_Scharr8(ocl_t *ocl, DVP_Image_t *pInput, DVP_Image_t *pOutput)
{
    DVP_PRINT(DVP_ZONE_API, "OCL:  %p (env=%p) SCHARR in %p out %p\n", ocl, ocl->env, pInput, pOutput);
    if (ocl && ocl->env)
    {
        cl_char operator[2][3][3] = { { {3,10,3}, {0,0,0}, {-3,-10,-3} }, { {3,0,-3}, {10,0,-10}, {3,0,-3} } };
        cl_uint limit = 255;
        cl_uint range = range_of_operator((cl_char *)operator, 3, limit);
        cl_int err = imgfilter1d_opt(ocl->env,
                                     pInput->width,
                                     pInput->height,
                                     pInput->pData[0],
                                     pInput->y_stride,
                                     pOutput->pData[0],
                                     pOutput->y_stride,
                                     (cl_char *)operator,
                                     3,
                                     range,limit);
        return DVP_SUCCESS;
    }
    return DVP_ERROR_INVALID_PARAMETER;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
    if (argc >= 5)
    {
        FILE *fi = NULL;
        FILE *fo = NULL;
        cl_uint width = atoi(argv[2]);
        cl_uint height = atoi(argv[3]);
        cl_int err = CL_SUCCESS;

#ifdef CL_BUILD_RUNTIME
		cl_environment_t *pEnv = clCreateEnvironment(KDIR"kernel_imgfilter.cl", CL_DEVICE_TYPE_GPU, 2, notify, CL_ARGS);
#else
        cl_environment_t *pEnv = clCreateEnvironmentFromBins(&gKernelBins, notify, CL_ARGS);
#endif
        if (!pEnv)
        {
            clDeleteEnvironment(pEnv);
            return -1;
        }

        clPrintAllKernelInfo(pEnv->kernels[0]);

        fi = fopen(argv[1], "rb");
        fo = fopen(argv[4], "wb+");
        if (fi && fo)
        {
            cl_char sobel[2][3][3] = { { {1,2,1}, {0,0,0}, {-1,-2,-1} }, { {-1,0,1}, {-2,0,2}, {-1,0,1} } };
            size_t numBytes = width * height * sizeof(unsigned char);
            cl_uchar *input_image = (cl_uchar *)malloc(numBytes);
            cl_uchar *output_image = (cl_uchar *)malloc(numBytes);
            clock_t c_start, c_diff;
            cl_uint limit = 255;
            cl_uint range = range_of_operator((cl_char *)sobel, 3, limit);
            printf("Range of Sobel = %u, Limit = %u\n",range,limit);
            do {
                numBytes = fread(input_image, 1, numBytes, fi);
                if (numBytes == 0)
                    break;
                c_start = clock();
                err = imgfilter1d_opt(pEnv, width, height,
                                  input_image, width,
                                  output_image, width,
                                  (cl_char *)sobel, 3,
                                  range, limit);
                c_diff = clock() - c_start;
                printf("Sobel took %lu ticks\n", c_diff);
                numBytes = fwrite(output_image, 1, numBytes, fo);
            } while (err == CL_SUCCESS);

            free(input_image);
            free(output_image);

            fclose(fi);
            fclose(fo);
        }
        clDeleteEnvironment(pEnv);
    }
    else
    {
        printf("%s <filename> <width> <height> <outfile>\n",argv[0]);
    }
    return 0;
}