int av_opencl_buffer_read_image(uint8_t **dst_data, int *plane_size, int plane_num,

                                       cl_mem src_cl_buf, size_t cl_buffer_size)

{

    int i,buffer_size = 0,ret = 0;

    uint8_t *temp;

    void *mapped;

    cl_int status;

    if ((unsigned int)plane_num > 8) {

        return AVERROR(EINVAL);

    }

    for (i = 0;i < plane_num;i++) {

        buffer_size += plane_size[i];

    }

    if (buffer_size > cl_buffer_size) {

        av_log(&openclutils, AV_LOG_ERROR, "Cannot write image to CPU buffer: OpenCL buffer too small\n");

        return AVERROR(EINVAL);

    }

    mapped = clEnqueueMapBuffer(gpu_env.command_queue, src_cl_buf,

                                      CL_TRUE,CL_MAP_READ, 0, buffer_size,

                                      0, NULL, NULL, &status);



    if (status != CL_SUCCESS) {

        av_log(&openclutils, AV_LOG_ERROR, "Could not map OpenCL buffer: %s\n", opencl_errstr(status));

        return AVERROR_EXTERNAL;

    }

    temp = mapped;

    if (ret >= 0) {

        for (i = 0;i < plane_num;i++) {

            memcpy(dst_data[i], temp, plane_size[i]);

            temp += plane_size[i];

        }

    }

    status = clEnqueueUnmapMemObject(gpu_env.command_queue, src_cl_buf, mapped, 0, NULL, NULL);

    if (status != CL_SUCCESS) {

        av_log(&openclutils, AV_LOG_ERROR, "Could not unmap OpenCL buffer: %s\n", opencl_errstr(status));

        return AVERROR_EXTERNAL;

    }

    return 0;

}

int av_opencl_buffer_read_image(uint8_t **dst_data, int *plane_size, int plane_num,

                                       cl_mem src_cl_buf, size_t cl_buffer_size)

{

    int i,buffer_size = 0,ret = 0;

    uint8_t *temp;

    void *mapped;

    cl_int status;

    if ((unsigned int)plane_num > 8) {

        return AVERROR(EINVAL);

    }

    for (i = 0;i < plane_num;i++) {

        buffer_size += plane_size[i];

    }

    if (buffer_size > cl_buffer_size) {

        av_log(&openclutils, AV_LOG_ERROR, "Cannot write image to CPU buffer: OpenCL buffer too small\n");

        return AVERROR(EINVAL);

    }

    mapped = clEnqueueMapBuffer(gpu_env.command_queue, src_cl_buf,

                                      CL_TRUE,CL_MAP_READ, 0, buffer_size,

                                      0, NULL, NULL, &status);



    if (status != CL_SUCCESS) {

        av_log(&openclutils, AV_LOG_ERROR, "Could not map OpenCL buffer: %s\n", opencl_errstr(status));

        return AVERROR_EXTERNAL;

    }

    temp = mapped;

    if (ret >= 0) {

        for (i = 0;i < plane_num;i++) {

            memcpy(dst_data[i], temp, plane_size[i]);

            temp += plane_size[i];

        }

    }

    status = clEnqueueUnmapMemObject(gpu_env.command_queue, src_cl_buf, mapped, 0, NULL, NULL);

    if (status != CL_SUCCESS) {

        av_log(&openclutils, AV_LOG_ERROR, "Could not unmap OpenCL buffer: %s\n", opencl_errstr(status));

        return AVERROR_EXTERNAL;

    }

    return 0;

}

int FUNC_0(uint8_t **VAR_0, int *VAR_1, int VAR_2,

                                       cl_mem VAR_3, size_t VAR_4)

{

    int VAR_5,VAR_6 = 0,VAR_7 = 0;

    uint8_t *temp;

    void *VAR_8;

    cl_int status;

    if ((unsigned int)VAR_2 > 8) {

        return AVERROR(EINVAL);

    }

    for (VAR_5 = 0;VAR_5 < VAR_2;VAR_5++) {

        VAR_6 += VAR_1[VAR_5];

    }

    if (VAR_6 > VAR_4) {

        av_log(&openclutils, AV_LOG_ERROR, "Cannot write image to CPU buffer: OpenCL buffer too small\n");

        return AVERROR(EINVAL);

    }

    VAR_8 = clEnqueueMapBuffer(gpu_env.command_queue, VAR_3,

                                      CL_TRUE,CL_MAP_READ, 0, VAR_6,

                                      0, NULL, NULL, &status);



    if (status != CL_SUCCESS) {

        av_log(&openclutils, AV_LOG_ERROR, "Could not map OpenCL buffer: %s\n", opencl_errstr(status));

        return AVERROR_EXTERNAL;

    }

    temp = VAR_8;

    if (VAR_7 >= 0) {

        for (VAR_5 = 0;VAR_5 < VAR_2;VAR_5++) {

            memcpy(VAR_0[VAR_5], temp, VAR_1[VAR_5]);

            temp += VAR_1[VAR_5];

        }

    }

    status = clEnqueueUnmapMemObject(gpu_env.command_queue, VAR_3, VAR_8, 0, NULL, NULL);

    if (status != CL_SUCCESS) {

        av_log(&openclutils, AV_LOG_ERROR, "Could not unmap OpenCL buffer: %s\n", opencl_errstr(status));

        return AVERROR_EXTERNAL;

    }

    return 0;

}

int FUNC_0(uint8_t **VAR_0, int *VAR_1, int VAR_2,
cl_mem VAR_3, size_t VAR_4)
{ int VAR_5,VAR_6 = 0,VAR_7 = 0; uint8_t *temp; void *VAR_8; cl_int status; if ((unsigned int)VAR_2 > 8) { return AVERROR(EINVAL); } for (VAR_5 = 0;VAR_5 < VAR_2;VAR_5++) { VAR_6 += VAR_1[VAR_5]; } if (VAR_6 > VAR_4) { av_log(&openclutils, AV_LOG_ERROR, "Cannot write image to CPU buffer: OpenCL buffer too small\n"); return AVERROR(EINVAL); } VAR_8 = clEnqueueMapBuffer(gpu_env.command_queue, VAR_3,
CL_TRUE,CL_MAP_READ, 0, VAR_6,
0, NULL, NULL, &status); if (status != CL_SUCCESS) { av_log(&openclutils, AV_LOG_ERROR, "Could not map OpenCL buffer: %s\n", opencl_errstr(status)); return AVERROR_EXTERNAL; } temp = VAR_8; if (VAR_7 >= 0) { for (VAR_5 = 0;VAR_5 < VAR_2;VAR_5++) { memcpy(VAR_0[VAR_5], temp, VAR_1[VAR_5]); temp += VAR_1[VAR_5]; } } status = clEnqueueUnmapMemObject(gpu_env.command_queue, VAR_3, VAR_8, 0, NULL, NULL); if (status != CL_SUCCESS) { av_log(&openclutils, AV_LOG_ERROR, "Could not unmap OpenCL buffer: %s\n", opencl_errstr(status)); return AVERROR_EXTERNAL; } return 0; }