wangfei | 6ea2221 | 2015-03-23 19:10:26 +0800 | [diff] [blame] | 1 | /* |
| 2 | * cl_csc_handler.cpp - CL csc handler |
| 3 | * |
| 4 | * Copyright (c) 2015 Intel Corporation |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * |
| 18 | * Author: wangfei <feix.w.wang@intel.com> |
Wind Yuan | de4c636 | 2015-03-25 17:34:22 +0800 | [diff] [blame] | 19 | * Author: Wind Yuan <feng.yuan@intel.com> |
wangfei | 6ea2221 | 2015-03-23 19:10:26 +0800 | [diff] [blame] | 20 | */ |
| 21 | #include "xcam_utils.h" |
| 22 | #include "cl_csc_handler.h" |
| 23 | |
| 24 | namespace XCam { |
| 25 | |
wangfei | 1a7d9f3 | 2015-03-26 18:30:00 +0800 | [diff] [blame] | 26 | CLCscImageKernel::CLCscImageKernel (SmartPtr<CLContext> &context, const char *name) |
| 27 | : CLImageKernel (context, name) |
Wind Yuan | de4c636 | 2015-03-25 17:34:22 +0800 | [diff] [blame] | 28 | , _vertical_offset (0) |
wangfei | 6ea2221 | 2015-03-23 19:10:26 +0800 | [diff] [blame] | 29 | { |
| 30 | } |
| 31 | |
| 32 | XCamReturn |
| 33 | CLCscImageKernel::prepare_arguments ( |
| 34 | SmartPtr<DrmBoBuffer> &input, SmartPtr<DrmBoBuffer> &output, |
| 35 | CLArgument args[], uint32_t &arg_count, |
| 36 | CLWorkSize &work_size) |
| 37 | { |
| 38 | SmartPtr<CLContext> context = get_context (); |
| 39 | const VideoBufferInfo & video_info = output->get_video_info (); |
| 40 | |
Wind Yuan | a2cdd11 | 2015-04-08 18:32:12 +0800 | [diff] [blame] | 41 | _image_in = new CLVaImage (context, input); |
| 42 | _image_out = new CLVaImage (context, output); |
Wind Yuan | de4c636 | 2015-03-25 17:34:22 +0800 | [diff] [blame] | 43 | _vertical_offset = video_info.aligned_height; |
wangfei | 6ea2221 | 2015-03-23 19:10:26 +0800 | [diff] [blame] | 44 | |
| 45 | XCAM_ASSERT (_image_in->is_valid () && _image_out->is_valid ()); |
| 46 | XCAM_FAIL_RETURN ( |
| 47 | WARNING, |
| 48 | _image_in->is_valid () && _image_out->is_valid (), |
| 49 | XCAM_RETURN_ERROR_MEM, |
| 50 | "cl image kernel(%s) in/out memory not available", get_kernel_name ()); |
| 51 | |
| 52 | //set args; |
| 53 | args[0].arg_adress = &_image_in->get_mem_id (); |
| 54 | args[0].arg_size = sizeof (cl_mem); |
| 55 | args[1].arg_adress = &_image_out->get_mem_id (); |
| 56 | args[1].arg_size = sizeof (cl_mem); |
Wind Yuan | de4c636 | 2015-03-25 17:34:22 +0800 | [diff] [blame] | 57 | args[2].arg_adress = &_vertical_offset; |
| 58 | args[2].arg_size = sizeof (_vertical_offset); |
wangfei | 1a7d9f3 | 2015-03-26 18:30:00 +0800 | [diff] [blame] | 59 | |
wangfei | 6ea2221 | 2015-03-23 19:10:26 +0800 | [diff] [blame] | 60 | |
| 61 | work_size.dim = XCAM_DEFAULT_IMAGE_DIM; |
wangfei | 1a7d9f3 | 2015-03-26 18:30:00 +0800 | [diff] [blame] | 62 | if (video_info.format == V4L2_PIX_FMT_NV12) { |
| 63 | work_size.global[0] = video_info.width / 2; |
| 64 | work_size.global[1] = video_info.height / 2; |
| 65 | arg_count = 3; |
| 66 | } |
wangfei | 227ba27 | 2015-04-16 20:58:45 +0800 | [diff] [blame] | 67 | else if ((video_info.format == XCAM_PIX_FMT_LAB) || (video_info.format == V4L2_PIX_FMT_RGBA32)) { |
wangfei | 1a7d9f3 | 2015-03-26 18:30:00 +0800 | [diff] [blame] | 68 | work_size.global[0] = video_info.width; |
| 69 | work_size.global[1] = video_info.height; |
| 70 | arg_count = 2; |
| 71 | } |
wangfei | 6ea2221 | 2015-03-23 19:10:26 +0800 | [diff] [blame] | 72 | work_size.local[0] = 4; |
| 73 | work_size.local[1] = 4; |
| 74 | |
| 75 | return XCAM_RETURN_NO_ERROR; |
| 76 | } |
| 77 | |
wangfei | a1a5ff4 | 2015-03-30 11:22:52 +0800 | [diff] [blame] | 78 | CLCscImageHandler::CLCscImageHandler (const char *name, CLCscType type) |
wangfei | 6ea2221 | 2015-03-23 19:10:26 +0800 | [diff] [blame] | 79 | : CLImageHandler (name) |
wangfei | a1a5ff4 | 2015-03-30 11:22:52 +0800 | [diff] [blame] | 80 | , _output_format (V4L2_PIX_FMT_NV12) |
| 81 | , _csc_type (type) |
wangfei | 6ea2221 | 2015-03-23 19:10:26 +0800 | [diff] [blame] | 82 | { |
wangfei | a1a5ff4 | 2015-03-30 11:22:52 +0800 | [diff] [blame] | 83 | switch (type) { |
| 84 | case CL_CSC_TYPE_RGBATONV12: |
| 85 | _output_format = V4L2_PIX_FMT_NV12; |
| 86 | break; |
| 87 | case CL_CSC_TYPE_RGBATOLAB: |
| 88 | _output_format = XCAM_PIX_FMT_LAB; |
| 89 | break; |
wangfei | 227ba27 | 2015-04-16 20:58:45 +0800 | [diff] [blame] | 90 | case CL_CSC_TYPE_RGBA64TORGBA: |
| 91 | _output_format = V4L2_PIX_FMT_RGBA32; |
| 92 | break; |
wangfei | a1a5ff4 | 2015-03-30 11:22:52 +0800 | [diff] [blame] | 93 | default: |
| 94 | break; |
| 95 | } |
wangfei | 6ea2221 | 2015-03-23 19:10:26 +0800 | [diff] [blame] | 96 | } |
| 97 | |
wangfei | 6ea2221 | 2015-03-23 19:10:26 +0800 | [diff] [blame] | 98 | XCamReturn |
wangfei | 1a7d9f3 | 2015-03-26 18:30:00 +0800 | [diff] [blame] | 99 | CLCscImageHandler::prepare_buffer_pool_video_info ( |
wangfei | 6ea2221 | 2015-03-23 19:10:26 +0800 | [diff] [blame] | 100 | const VideoBufferInfo &input, |
| 101 | VideoBufferInfo &output) |
| 102 | { |
Wind Yuan | a2cdd11 | 2015-04-08 18:32:12 +0800 | [diff] [blame] | 103 | bool format_inited = output.init (_output_format, input.width, input.height); |
wangfei | 6ea2221 | 2015-03-23 19:10:26 +0800 | [diff] [blame] | 104 | |
| 105 | XCAM_FAIL_RETURN ( |
| 106 | WARNING, |
| 107 | format_inited, |
| 108 | XCAM_RETURN_ERROR_PARAM, |
| 109 | "CL image handler(%s) ouput format(%s) unsupported", |
wangfei | 1a7d9f3 | 2015-03-26 18:30:00 +0800 | [diff] [blame] | 110 | get_name (), xcam_fourcc_to_string (_output_format)); |
wangfei | 6ea2221 | 2015-03-23 19:10:26 +0800 | [diff] [blame] | 111 | |
| 112 | return XCAM_RETURN_NO_ERROR; |
| 113 | } |
| 114 | |
| 115 | SmartPtr<CLImageHandler> |
wangfei | 1a7d9f3 | 2015-03-26 18:30:00 +0800 | [diff] [blame] | 116 | create_cl_csc_image_handler (SmartPtr<CLContext> &context, CLCscType type) |
wangfei | 6ea2221 | 2015-03-23 19:10:26 +0800 | [diff] [blame] | 117 | { |
| 118 | SmartPtr<CLImageHandler> csc_handler; |
| 119 | SmartPtr<CLImageKernel> csc_kernel; |
| 120 | XCamReturn ret = XCAM_RETURN_NO_ERROR; |
| 121 | |
wangfei | 1a7d9f3 | 2015-03-26 18:30:00 +0800 | [diff] [blame] | 122 | |
| 123 | XCAM_CL_KERNEL_FUNC_SOURCE_BEGIN(kernel_csc_rgbatonv12) |
| 124 | #include "kernel_csc_rgbatonv12.cl" |
| 125 | XCAM_CL_KERNEL_FUNC_END; |
| 126 | |
| 127 | XCAM_CL_KERNEL_FUNC_SOURCE_BEGIN(kernel_csc_rgbatolab) |
| 128 | #include "kernel_csc_rgbatolab.cl" |
| 129 | XCAM_CL_KERNEL_FUNC_END; |
| 130 | |
wangfei | 227ba27 | 2015-04-16 20:58:45 +0800 | [diff] [blame] | 131 | XCAM_CL_KERNEL_FUNC_SOURCE_BEGIN(kernel_csc_rgba64torgba) |
| 132 | #include "kernel_csc_rgba64torgba.cl" |
| 133 | XCAM_CL_KERNEL_FUNC_END; |
| 134 | |
| 135 | |
wangfei | 1a7d9f3 | 2015-03-26 18:30:00 +0800 | [diff] [blame] | 136 | if (type == CL_CSC_TYPE_RGBATONV12) { |
| 137 | csc_kernel = new CLCscImageKernel (context, "kernel_csc_rgbatonv12"); |
| 138 | ret = csc_kernel->load_from_source (kernel_csc_rgbatonv12_body, strlen (kernel_csc_rgbatonv12_body)); |
wangfei | 6ea2221 | 2015-03-23 19:10:26 +0800 | [diff] [blame] | 139 | } |
wangfei | 1a7d9f3 | 2015-03-26 18:30:00 +0800 | [diff] [blame] | 140 | else if (type == CL_CSC_TYPE_RGBATOLAB) { |
| 141 | csc_kernel = new CLCscImageKernel (context, "kernel_csc_rgbatolab"); |
| 142 | ret = csc_kernel->load_from_source (kernel_csc_rgbatolab_body, strlen (kernel_csc_rgbatolab_body)); |
| 143 | } |
wangfei | 227ba27 | 2015-04-16 20:58:45 +0800 | [diff] [blame] | 144 | else if (type == CL_CSC_TYPE_RGBA64TORGBA) { |
| 145 | csc_kernel = new CLCscImageKernel (context, "kernel_csc_rgba64torgba"); |
| 146 | ret = csc_kernel->load_from_source (kernel_csc_rgba64torgba_body, strlen (kernel_csc_rgba64torgba_body)); |
| 147 | } |
wangfei | 1a7d9f3 | 2015-03-26 18:30:00 +0800 | [diff] [blame] | 148 | |
| 149 | XCAM_FAIL_RETURN ( |
| 150 | WARNING, |
| 151 | ret == XCAM_RETURN_NO_ERROR, |
| 152 | NULL, |
| 153 | "CL image handler(%s) load source failed", csc_kernel->get_kernel_name()); |
| 154 | |
wangfei | 6ea2221 | 2015-03-23 19:10:26 +0800 | [diff] [blame] | 155 | XCAM_ASSERT (csc_kernel->is_valid ()); |
wangfei | a1a5ff4 | 2015-03-30 11:22:52 +0800 | [diff] [blame] | 156 | |
| 157 | csc_handler = new CLCscImageHandler ("cl_handler_csc", type); |
wangfei | 6ea2221 | 2015-03-23 19:10:26 +0800 | [diff] [blame] | 158 | csc_handler->add_kernel (csc_kernel); |
| 159 | |
| 160 | return csc_handler; |
| 161 | } |
| 162 | |
| 163 | }; |