int av_opencl_buffer_write_image(cl_mem dst_cl_buf, size_t cl_buffer_size, int dst_cl_offset,

                                                    uint8_t **src_data, int *plane_size, int plane_num)

{

    int i, buffer_size = 0;

    uint8_t *temp;

    cl_int status;

    void *mapped;

    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 OpenCL buffer: buffer too small\n");

        return AVERROR(EINVAL);

    }

    mapped = clEnqueueMapBuffer(gpu_env.command_queue, dst_cl_buf,

                                      CL_TRUE,CL_MAP_WRITE, 0, buffer_size + dst_cl_offset,

                                      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;

    temp += dst_cl_offset;

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

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

        temp += plane_size[i];

    }

    status = clEnqueueUnmapMemObject(gpu_env.command_queue, dst_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_write_image(cl_mem dst_cl_buf, size_t cl_buffer_size, int dst_cl_offset,

                                                    uint8_t **src_data, int *plane_size, int plane_num)

{

    int i, buffer_size = 0;

    uint8_t *temp;

    cl_int status;

    void *mapped;

    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 OpenCL buffer: buffer too small\n");

        return AVERROR(EINVAL);

    }

    mapped = clEnqueueMapBuffer(gpu_env.command_queue, dst_cl_buf,

                                      CL_TRUE,CL_MAP_WRITE, 0, buffer_size + dst_cl_offset,

                                      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;

    temp += dst_cl_offset;

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

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

        temp += plane_size[i];

    }

    status = clEnqueueUnmapMemObject(gpu_env.command_queue, dst_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(cl_mem VAR_0, size_t VAR_1, int VAR_2,

                                                    uint8_t **VAR_3, int *VAR_4, int VAR_5)

{

    int VAR_6, VAR_7 = 0;

    uint8_t *temp;

    cl_int status;

    void *VAR_8;

    if ((unsigned int)VAR_5 > 8) {

        return AVERROR(EINVAL);

    }

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

        VAR_7 += VAR_4[VAR_6];

    }

    if (VAR_7 > VAR_1) {

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

        return AVERROR(EINVAL);

    }

    VAR_8 = clEnqueueMapBuffer(gpu_env.command_queue, VAR_0,

                                      CL_TRUE,CL_MAP_WRITE, 0, VAR_7 + VAR_2,

                                      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;

    temp += VAR_2;

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

        memcpy(temp, VAR_3[VAR_6], VAR_4[VAR_6]);

        temp += VAR_4[VAR_6];

    }

    status = clEnqueueUnmapMemObject(gpu_env.command_queue, VAR_0, 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(cl_mem VAR_0, size_t VAR_1, int VAR_2,
uint8_t **VAR_3, int *VAR_4, int VAR_5)
{ int VAR_6, VAR_7 = 0; uint8_t *temp; cl_int status; void *VAR_8; if ((unsigned int)VAR_5 > 8) { return AVERROR(EINVAL); } for (VAR_6 = 0;VAR_6 < VAR_5;VAR_6++) { VAR_7 += VAR_4[VAR_6]; } if (VAR_7 > VAR_1) { av_log(&openclutils, AV_LOG_ERROR, "Cannot write image to OpenCL buffer: buffer too small\n"); return AVERROR(EINVAL); } VAR_8 = clEnqueueMapBuffer(gpu_env.command_queue, VAR_0,
CL_TRUE,CL_MAP_WRITE, 0, VAR_7 + VAR_2,
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; temp += VAR_2; for (VAR_6 = 0; VAR_6 < VAR_5; VAR_6++) { memcpy(temp, VAR_3[VAR_6], VAR_4[VAR_6]); temp += VAR_4[VAR_6]; } status = clEnqueueUnmapMemObject(gpu_env.command_queue, VAR_0, 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; }