xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkaiq/algos/aldch/rk_aiq_types_aldch_algo_prvt.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *rk_aiq_types_afec_algo_prvt.h
3  *
4  *  Copyright (c) 2019 Rockchip 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  */
19 
20 #ifndef _RK_AIQ_TYPES_AFEC_ALGO_PRVT_H_
21 #define _RK_AIQ_TYPES_AFEC_ALGO_PRVT_H_
22 
23 #include "RkAiqCalibDbTypes.h"
24 #include <xcam_mutex.h>
25 #include "xcam_thread.h"
26 #include "smartptr.h"
27 #include "safe_list.h"
28 #include "xcam_log.h"
29 #include "gen_mesh/genMesh.h"
30 #include "aldch/rk_aiq_types_aldch_algo_int.h"
31 #include "rk_aiq_types_priv.h"
32 RKAIQ_BEGIN_DECLARE
33 
34 using namespace XCam;
35 
36 #define MAP_TO_255LEVEL(level, level_max) \
37     ((float)(level) / 255 * (level_max));
38 
39 typedef enum {
40     LDCH_CORRECT_LEVEL0,        // 100%
41     LDCH_CORRECT_LEVEL1,        // 75%
42     LDCH_CORRECT_LEVEL2,        // 100%
43     LDCH_CORRECT_LEVEL3,        // 75%
44     LDCH_BYPASS
45 } LDCHCorrectLevel;
46 
47 typedef enum LDCHState_e {
48     LDCH_STATE_INVALID           = 0,                   /**< initialization value */
49     LDCH_STATE_INITIALIZED       = 1,                   /**< instance is created, but not initialized */
50     LDCH_STATE_STOPPED           = 2,                   /**< instance is confiured (ready to start) or stopped */
51     LDCH_STATE_RUNNING           = 3,                   /**< instance is running (processes frames) */
52     LDCH_STATE_MAX                                      /**< max */
53 } LDCHState_t;
54 
55 class LutCache {
56  public:
57     LutCache() = delete;
LutCache(size_t size)58     explicit LutCache(size_t size)
59         : _addr(nullptr), _size(size) {}
60     LutCache(const LutCache&) = delete;
61     LutCache& operator=(const LutCache&) = delete;
~LutCache()62     ~LutCache() {
63         ReleaseBuffer();
64     }
65 
ReleaseBuffer()66     void ReleaseBuffer() {
67         if (_addr) {
68             LOGV_ALDCH("release lut cache size: %d", _size);
69             xcam_free(_addr);
70             _addr = nullptr;
71         }
72     }
73 
GetBuffer()74     void* GetBuffer() {
75         if (!_addr) {
76             LOGV_ALDCH("malloc lut cache size: %d", _size);
77             _addr = xcam_malloc(_size);
78         }
79 
80         return _addr;
81     }
82 
GetSize()83     size_t GetSize() {
84         LOGV_ALDCH("get lut cache size: %d", _size);
85         return _size;
86     }
87 
88  private:
89     void*   _addr;
90     size_t  _size;
91 };
92 
93 class RKAiqAldchThread;
94 
95 typedef struct LDCHContext_s {
96     bool ldch_en;
97     uint32_t src_width;
98     uint32_t src_height;
99     uint32_t dst_width;
100     uint32_t dst_height;
101     uint32_t lut_h_size;
102     uint32_t lut_v_size;
103     uint32_t lut_mapxy_size;
104     uint16_t* lut_mapxy;
105     char meshfile[256];
106     int correct_level;
107     int correct_level_max;
108     const char* resource_path;
109     std::atomic<bool> genLdchMeshInit;
110     int32_t update_lut_mem_fd;
111     int32_t ready_lut_mem_fd;
112 
113     struct CameraCoeff camCoeff;
114     LdchParams ldchParams;
115     LDCHState_t eState;
116     bool isAttribUpdated;
117     std::atomic<bool> isLutUpdated;
118 #if (RKAIQ_HAVE_LDCH_V21)
119     rk_aiq_ldch_v21_cfg_t user_config;
120 #else
121     rk_aiq_ldch_cfg_t user_config;
122 #endif
123     SmartPtr<RKAiqAldchThread> aldchReadMeshThread;
124     isp_drv_share_mem_ops_t *share_mem_ops;
125     rk_aiq_ldch_share_mem_info_t *ldch_mem_info;
126     void* share_mem_ctx;
127 
128     uint8_t frm_end_dis;
129     uint8_t zero_interp_en;
130     uint8_t sample_avr_en;
131     uint8_t bic_mode_en;
132     uint8_t force_map_en;
133     uint8_t map13p3_en;
134     uint8_t bicubic[ISP32_LDCH_BIC_NUM];
135 
136     std::atomic<bool> hasAllocShareMem;
137     SmartPtr<LutCache> _lutCache;
138 } LDCHContext_t;
139 
140 typedef struct LDCHContext_s* LDCHHandle_t;
141 
142 typedef struct _RkAiqAlgoContext {
143     LDCHHandle_t hLDCH;
144     void* place_holder[0];
145 } RkAiqAlgoContext;
146 
147 RKAIQ_END_DECLARE
148 
149 class RKAiqAldchThread
150     : public Thread {
151 public:
RKAiqAldchThread(LDCHHandle_t ldchHandle)152     RKAiqAldchThread(LDCHHandle_t ldchHandle)
153         : Thread("ldchThread")
154           , hLDCH(ldchHandle) {};
~RKAiqAldchThread()155     ~RKAiqAldchThread() {
156         mAttrQueue.clear ();
157     };
158 
triger_stop()159     void triger_stop() {
160         mAttrQueue.pause_pop ();
161     };
162 
triger_start()163     void triger_start() {
164         mAttrQueue.resume_pop ();
165     };
166 
167 #if (RKAIQ_HAVE_LDCH_V21)
push_attr(const SmartPtr<rk_aiq_ldch_v21_cfg_t> buffer)168     bool push_attr (const SmartPtr<rk_aiq_ldch_v21_cfg_t> buffer) {
169         mAttrQueue.push (buffer);
170         return true;
171     };
172 #else
push_attr(const SmartPtr<rk_aiq_ldch_cfg_t> buffer)173     bool push_attr (const SmartPtr<rk_aiq_ldch_cfg_t> buffer) {
174         mAttrQueue.push (buffer);
175         return true;
176     };
177 #endif
178 
is_empty()179     bool is_empty () {
180         return mAttrQueue.is_empty();
181     };
182 
clear_attr()183     void clear_attr () {
184         mAttrQueue.clear ();
185     };
186 
187 protected:
188     //virtual bool started ();
stopped()189     virtual void stopped () {
190         mAttrQueue.clear ();
191     };
192     virtual bool loop ();
193 private:
194     LDCHHandle_t hLDCH;
195 #if (RKAIQ_HAVE_LDCH_V21)
196     SafeList<rk_aiq_ldch_v21_cfg_t> mAttrQueue;
197 #else
198     SafeList<rk_aiq_ldch_cfg_t> mAttrQueue;
199 #endif
200 };
201 
202 #endif
203 
204