• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * cl_image_scaler.h - CL image scaler
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: Zong Wei <wei.zong@intel.com>
19  */
20 
21 #ifndef XCAM_CL_IMAGE_SCALER_H
22 #define XCAM_CL_IMAGE_SCALER_H
23 
24 #include <xcam_std.h>
25 #include <ocl/cl_image_handler.h>
26 #include <ocl/cl_memory.h>
27 #include <stats_callback_interface.h>
28 
29 namespace XCam {
30 
31 enum CLImageScalerMemoryLayout {
32     CL_IMAGE_SCALER_NV12_Y = 0,
33     CL_IMAGE_SCALER_NV12_UV = 1,
34     CL_IMAGE_SCALER_RGBA = 2,
35 };
36 
37 #define XCAM_CL_IMAGE_SCALER_KERNEL_LOCAL_WORK_SIZE0 8
38 #define XCAM_CL_IMAGE_SCALER_KERNEL_LOCAL_WORK_SIZE1 4
39 
40 class CLImageScaler;
41 
42 class CLScalerKernel
43     : public CLImageKernel
44 {
45 public:
46     explicit CLScalerKernel (
47         const SmartPtr<CLContext> &context, CLImageScalerMemoryLayout mem_layout);
48 
49 public:
get_mem_layout()50     CLImageScalerMemoryLayout get_mem_layout () const {
51         return _mem_layout;
52     };
53 
54 protected:
55     virtual XCamReturn prepare_arguments (CLArgList &args, CLWorkSize &work_size);
56 
57     //new virtual functions
58     virtual SmartPtr<VideoBuffer> get_input_buffer () = 0;
59     virtual SmartPtr<VideoBuffer> get_output_buffer () = 0;
60 
61 protected:
62     CLImageScalerMemoryLayout _mem_layout;
63 };
64 
65 class CLImageScalerKernel
66     : public CLScalerKernel
67 {
68 public:
69     explicit CLImageScalerKernel (
70         const SmartPtr<CLContext> &context, CLImageScalerMemoryLayout mem_layout, SmartPtr<CLImageScaler> &scaler);
71 
72 protected:
73     virtual SmartPtr<VideoBuffer> get_input_buffer ();
74     virtual SmartPtr<VideoBuffer> get_output_buffer ();
75 
76 private:
77     XCAM_DEAD_COPY (CLImageScalerKernel);
78 
79 private:
80     SmartPtr<CLImageScaler> _scaler;
81 };
82 
83 class CLImageScaler
84     : public CLImageHandler
85 {
86     friend class CLImageScalerKernel;
87 public:
88     explicit CLImageScaler (const SmartPtr<CLContext> &context);
set_buffer_callback(SmartPtr<StatsCallback> & callback)89     void set_buffer_callback (SmartPtr<StatsCallback> &callback) {
90         _scaler_callback = callback;
91     }
92 
93     bool set_scaler_factor (const double h_factor, const double v_factor);
94     bool get_scaler_factor (double &h_factor, double &v_factor) const;
get_scaler_buf()95     SmartPtr<VideoBuffer> &get_scaler_buf () {
96         return _scaler_buf;
97     };
98 
99     void emit_stop ();
100 
101 protected:
102     virtual XCamReturn prepare_output_buf (SmartPtr<VideoBuffer> &input, SmartPtr<VideoBuffer> &output);
103     virtual XCamReturn execute_done (SmartPtr<VideoBuffer> &output);
104 
105 private:
106     XCamReturn prepare_scaler_buf (const VideoBufferInfo &video_info, SmartPtr<VideoBuffer> &output);
107     XCamReturn post_buffer (const SmartPtr<VideoBuffer> &buffer);
108 
109 private:
110     double                     _h_scaler_factor;
111     double                     _v_scaler_factor;
112     SmartPtr<BufferPool>       _scaler_buf_pool;
113     SmartPtr<VideoBuffer>      _scaler_buf;
114     SmartPtr<StatsCallback>    _scaler_callback;
115 };
116 
117 SmartPtr<CLImageHandler>
118 create_cl_image_scaler_handler (const SmartPtr<CLContext> &context, uint32_t format);
119 
120 };
121 
122 #endif // XCAM_CL_IMAGE_SCALER_H
123