blob: 9ef43bb904db805e5ea9cc185ccc95560630b5c4 [file] [log] [blame]
wangfei6ea22212015-03-23 19:10:26 +08001/*
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 Yuande4c6362015-03-25 17:34:22 +080019 * Author: Wind Yuan <feng.yuan@intel.com>
wangfei6ea22212015-03-23 19:10:26 +080020 */
21#include "xcam_utils.h"
22#include "cl_csc_handler.h"
23
24namespace XCam {
25
wangfei1a7d9f32015-03-26 18:30:00 +080026CLCscImageKernel::CLCscImageKernel (SmartPtr<CLContext> &context, const char *name)
27 : CLImageKernel (context, name)
Wind Yuande4c6362015-03-25 17:34:22 +080028 , _vertical_offset (0)
wangfei6ea22212015-03-23 19:10:26 +080029{
30}
31
32XCamReturn
33CLCscImageKernel::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 Yuana2cdd112015-04-08 18:32:12 +080041 _image_in = new CLVaImage (context, input);
42 _image_out = new CLVaImage (context, output);
Wind Yuande4c6362015-03-25 17:34:22 +080043 _vertical_offset = video_info.aligned_height;
wangfei6ea22212015-03-23 19:10:26 +080044
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 Yuande4c6362015-03-25 17:34:22 +080057 args[2].arg_adress = &_vertical_offset;
58 args[2].arg_size = sizeof (_vertical_offset);
wangfei1a7d9f32015-03-26 18:30:00 +080059
wangfei6ea22212015-03-23 19:10:26 +080060
61 work_size.dim = XCAM_DEFAULT_IMAGE_DIM;
wangfei1a7d9f32015-03-26 18:30:00 +080062 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 }
wangfei227ba272015-04-16 20:58:45 +080067 else if ((video_info.format == XCAM_PIX_FMT_LAB) || (video_info.format == V4L2_PIX_FMT_RGBA32)) {
wangfei1a7d9f32015-03-26 18:30:00 +080068 work_size.global[0] = video_info.width;
69 work_size.global[1] = video_info.height;
70 arg_count = 2;
71 }
wangfei6ea22212015-03-23 19:10:26 +080072 work_size.local[0] = 4;
73 work_size.local[1] = 4;
74
75 return XCAM_RETURN_NO_ERROR;
76}
77
wangfeia1a5ff42015-03-30 11:22:52 +080078CLCscImageHandler::CLCscImageHandler (const char *name, CLCscType type)
wangfei6ea22212015-03-23 19:10:26 +080079 : CLImageHandler (name)
wangfeia1a5ff42015-03-30 11:22:52 +080080 , _output_format (V4L2_PIX_FMT_NV12)
81 , _csc_type (type)
wangfei6ea22212015-03-23 19:10:26 +080082{
wangfeia1a5ff42015-03-30 11:22:52 +080083 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;
wangfei227ba272015-04-16 20:58:45 +080090 case CL_CSC_TYPE_RGBA64TORGBA:
91 _output_format = V4L2_PIX_FMT_RGBA32;
92 break;
wangfeia1a5ff42015-03-30 11:22:52 +080093 default:
94 break;
95 }
wangfei6ea22212015-03-23 19:10:26 +080096}
97
wangfei6ea22212015-03-23 19:10:26 +080098XCamReturn
wangfei1a7d9f32015-03-26 18:30:00 +080099CLCscImageHandler::prepare_buffer_pool_video_info (
wangfei6ea22212015-03-23 19:10:26 +0800100 const VideoBufferInfo &input,
101 VideoBufferInfo &output)
102{
Wind Yuana2cdd112015-04-08 18:32:12 +0800103 bool format_inited = output.init (_output_format, input.width, input.height);
wangfei6ea22212015-03-23 19:10:26 +0800104
105 XCAM_FAIL_RETURN (
106 WARNING,
107 format_inited,
108 XCAM_RETURN_ERROR_PARAM,
109 "CL image handler(%s) ouput format(%s) unsupported",
wangfei1a7d9f32015-03-26 18:30:00 +0800110 get_name (), xcam_fourcc_to_string (_output_format));
wangfei6ea22212015-03-23 19:10:26 +0800111
112 return XCAM_RETURN_NO_ERROR;
113}
114
115SmartPtr<CLImageHandler>
wangfei1a7d9f32015-03-26 18:30:00 +0800116create_cl_csc_image_handler (SmartPtr<CLContext> &context, CLCscType type)
wangfei6ea22212015-03-23 19:10:26 +0800117{
118 SmartPtr<CLImageHandler> csc_handler;
119 SmartPtr<CLImageKernel> csc_kernel;
120 XCamReturn ret = XCAM_RETURN_NO_ERROR;
121
wangfei1a7d9f32015-03-26 18:30:00 +0800122
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
wangfei227ba272015-04-16 20:58:45 +0800131 XCAM_CL_KERNEL_FUNC_SOURCE_BEGIN(kernel_csc_rgba64torgba)
132#include "kernel_csc_rgba64torgba.cl"
133 XCAM_CL_KERNEL_FUNC_END;
134
135
wangfei1a7d9f32015-03-26 18:30:00 +0800136 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));
wangfei6ea22212015-03-23 19:10:26 +0800139 }
wangfei1a7d9f32015-03-26 18:30:00 +0800140 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 }
wangfei227ba272015-04-16 20:58:45 +0800144 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 }
wangfei1a7d9f32015-03-26 18:30:00 +0800148
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
wangfei6ea22212015-03-23 19:10:26 +0800155 XCAM_ASSERT (csc_kernel->is_valid ());
wangfeia1a5ff42015-03-30 11:22:52 +0800156
157 csc_handler = new CLCscImageHandler ("cl_handler_csc", type);
wangfei6ea22212015-03-23 19:10:26 +0800158 csc_handler->add_kernel (csc_kernel);
159
160 return csc_handler;
161}
162
163};