blob: b4e992ac0bca108c6eccb7ff5a5a561b4888b802 [file] [log] [blame]
ShincyTu5710f972015-03-23 23:20:44 +08001/*
2 * cl_blc_handler.cpp - CL black level correction 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: Shincy Tu <shincy.tu@intel.com>
19 */
20#include "xcam_utils.h"
21#include "cl_blc_handler.h"
22
23namespace XCam {
24
25CLBlcImageKernel::CLBlcImageKernel (SmartPtr<CLContext> &context)
26 : CLImageKernel (context, "kernel_blc")
27{
28}
29
30XCamReturn
31CLBlcImageKernel::prepare_arguments (
32 SmartPtr<DrmBoBuffer> &input, SmartPtr<DrmBoBuffer> &output,
33 CLArgument args[], uint32_t &arg_count,
34 CLWorkSize &work_size)
35{
36 SmartPtr<CLContext> context = get_context ();
37 const VideoBufferInfo & video_info = input->get_video_info ();
38 cl_libva_image image_info;
39 uint32_t channel_bits = XCAM_ALIGN_UP (video_info.color_bits, 8);
40
41 xcam_mem_clear (&image_info);
42 image_info.fmt.image_channel_order = CL_R;
43 if (channel_bits == 8)
44 image_info.fmt.image_channel_data_type = CL_UNSIGNED_INT8;
45 else if (channel_bits == 16)
46 image_info.fmt.image_channel_data_type = CL_UNSIGNED_INT16;
47 image_info.offset = 0;
48 image_info.width = video_info.width;
49 image_info.height = (video_info.size / video_info.strides[0]) / 4 * 4;
50 image_info.row_pitch = video_info.strides[0];
51
52 _image_in = new CLVaImage (context, input, &image_info);
53 _image_out = new CLVaImage (context, output, &image_info);
54
55 XCAM_ASSERT (_image_in->is_valid () && _image_out->is_valid ());
56 XCAM_FAIL_RETURN (
57 WARNING,
58 _image_in->is_valid () && _image_out->is_valid (),
59 XCAM_RETURN_ERROR_MEM,
60 "cl image kernel(%s) in/out memory not available", get_kernel_name ());
61
62 _blc_config.level_b = (cl_float)XCAM_CL_BLACK_LEVEL / XCAM_CL_10BIT_NOR;
63 _blc_config.level_gr = (cl_float)XCAM_CL_BLACK_LEVEL / XCAM_CL_10BIT_NOR;
64 _blc_config.level_gb = (cl_float)XCAM_CL_BLACK_LEVEL / XCAM_CL_10BIT_NOR;
65 _blc_config.level_r = (cl_float)XCAM_CL_BLACK_LEVEL / XCAM_CL_10BIT_NOR;
66
67 //set args;
68 args[0].arg_adress = &_image_in->get_mem_id ();
69 args[0].arg_size = sizeof (cl_mem);
70 args[1].arg_adress = &_image_out->get_mem_id ();
71 args[1].arg_size = sizeof (cl_mem);
72 args[2].arg_adress = &_blc_config;
73 args[2].arg_size = sizeof (BLCConfig);
74 arg_count = 3;
75
76 work_size.dim = XCAM_DEFAULT_IMAGE_DIM;
77 work_size.global[0] = image_info.width / 2;
78 work_size.global[1] = image_info.height / 2;
79 work_size.local[0] = 8;
80 work_size.local[1] = 4;
81
82 return XCAM_RETURN_NO_ERROR;
83}
84
85SmartPtr<CLImageHandler>
86create_cl_blc_image_handler (SmartPtr<CLContext> &context)
87{
88 SmartPtr<CLImageHandler> blc_handler;
89 SmartPtr<CLImageKernel> blc_kernel;
90 XCamReturn ret = XCAM_RETURN_NO_ERROR;
91
92 blc_kernel = new CLBlcImageKernel (context);
93 {
94 XCAM_CL_KERNEL_FUNC_SOURCE_BEGIN(kernel_blc)
95#include "kernel_blc.cl"
96 XCAM_CL_KERNEL_FUNC_END;
97 ret = blc_kernel->load_from_source (kernel_blc_body, strlen (kernel_blc_body));
98 XCAM_FAIL_RETURN (
99 WARNING,
100 ret == XCAM_RETURN_NO_ERROR,
101 NULL,
102 "CL image handler(%s) load source failed", blc_kernel->get_kernel_name());
103 }
104 XCAM_ASSERT (blc_kernel->is_valid ());
105 blc_handler = new CLImageHandler ("cl_handler_blc");
106 blc_handler->add_kernel (blc_kernel);
107
108 return blc_handler;
109}
110
111}