1 /*
2 * rk_aiq_uapi_aldch_int.cpp
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 #include "xcam_log.h"
21 #include "aldch/rk_aiq_uapi_aldch_v21_int.h"
22 #include "aldch/rk_aiq_types_aldch_algo_prvt.h"
23
24 #define DISABLE_HANDLE_ATTRIB
25
26 XCamReturn
rk_aiq_uapi_aldch_v21_SetAttrib(RkAiqAlgoContext * ctx,rk_aiq_ldch_v21_attrib_t attr,bool)27 rk_aiq_uapi_aldch_v21_SetAttrib(RkAiqAlgoContext *ctx,
28 rk_aiq_ldch_v21_attrib_t attr,
29 bool /* need_sync */)
30 {
31 LDCHHandle_t ldch_contex = (LDCHHandle_t)ctx->hLDCH;
32
33 LOGD_ALDCH("%s, attr en:%d, level:%d, bic_en:%d, zero_interp_en:%d, sample_avr_en:%d",
34 __FUNCTION__,
35 attr.en,
36 attr.correct_level,
37 attr.bic_mode_en,
38 attr.zero_interp_en,
39 attr.sample_avr_en);
40
41 LOGD_ALDCH("%s, attr custom lut: mode %d, flag %d",
42 __FUNCTION__,
43 attr.update_lut_mode,
44 attr.lut.update_flag);
45
46 if (attr.update_lut_mode == RK_AIQ_LDCH_UPDATE_LUT_FROM_EXTERNAL_FILE) {
47 LOGD_ALDCH("%s, attr custom lut file name: %s/%s",
48 __FUNCTION__,
49 attr.lut.u.file.config_file_dir,
50 attr.lut.u.file.mesh_file_name);
51 } else if (attr.update_lut_mode == RK_AIQ_LDCH_UPDATE_LUT_FROM_EXTERNAL_BUFFER) {
52 LOGD_ALDCH("%s, attr custom lut buffer %p, size %zu",
53 __FUNCTION__,
54 attr.lut.u.buffer.addr,
55 attr.lut.u.buffer.size);
56 if (attr.lut.u.buffer.size == 0) {
57 LOGE_ALDCH("Invalid lut buffer size %zu", attr.lut.u.buffer.size);
58 return XCAM_RETURN_ERROR_FAILED;
59 }
60 }
61
62 if (!ldch_contex->ldch_en && !attr.en) {
63 LOGE_ALDCH("uapi want to disalbe ldch, but ldch has been disalbed!");
64 return XCAM_RETURN_NO_ERROR;
65 }
66
67 if (0 != memcmp(&ldch_contex->user_config, &attr, sizeof(rk_aiq_ldch_v21_attrib_t))) {
68 #ifdef DISABLE_HANDLE_ATTRIB
69 if (attr.update_lut_mode == RK_AIQ_LDCH_UPDATE_LUT_FROM_EXTERNAL_BUFFER && \
70 attr.lut.update_flag) {
71 if (!ldch_contex->_lutCache.ptr()) {
72 ldch_contex->_lutCache = new LutCache(attr.lut.u.buffer.size);
73 } else if (attr.lut.u.buffer.size != ldch_contex->_lutCache->GetSize()) {
74 ldch_contex->_lutCache.release();
75 ldch_contex->_lutCache = new LutCache(attr.lut.u.buffer.size);
76 }
77
78 if (ldch_contex->_lutCache.ptr()) {
79 if (ldch_contex->_lutCache->GetBuffer()) {
80 memcpy(ldch_contex->_lutCache->GetBuffer(), attr.lut.u.buffer.addr, attr.lut.u.buffer.size);
81 }
82 } else {
83 LOGE_ALDCH("Failed to malloc ldch cache!");
84 return XCAM_RETURN_ERROR_MEM;
85 }
86 }
87 #endif
88
89 memcpy(&ldch_contex->user_config, &attr, sizeof(attr));
90 ldch_contex->isAttribUpdated = true;
91 }
92
93 return XCAM_RETURN_NO_ERROR;
94 }
95
96 XCamReturn
rk_aiq_uapi_aldch_v21_GetAttrib(const RkAiqAlgoContext * ctx,rk_aiq_ldch_v21_attrib_t * attr)97 rk_aiq_uapi_aldch_v21_GetAttrib(const RkAiqAlgoContext *ctx,
98 rk_aiq_ldch_v21_attrib_t *attr)
99 {
100 LDCHHandle_t ldch_contex = (LDCHHandle_t)ctx->hLDCH;
101
102 memcpy(attr, &ldch_contex->user_config, sizeof(*attr));
103
104 LOGD_ALDCH("%s, attr en:%d, level:%d, bic_en:%d, zero_interp_en:%d, sample_avr_en:%d",
105 __FUNCTION__,
106 attr->en,
107 attr->correct_level,
108 attr->bic_mode_en,
109 attr->zero_interp_en,
110 attr->sample_avr_en);
111
112 LOGD_ALDCH("%s, attr custom lut: mode %d, flag %d",
113 __FUNCTION__,
114 attr->update_lut_mode,
115 attr->lut.update_flag);
116
117 if (attr->update_lut_mode == RK_AIQ_LDCH_UPDATE_LUT_FROM_EXTERNAL_FILE) {
118 LOGD_ALDCH("%s, attr custom lut file name: %s/%s",
119 __FUNCTION__,
120 attr->lut.u.file.config_file_dir,
121 attr->lut.u.file.mesh_file_name);
122 } else if (attr->update_lut_mode == RK_AIQ_LDCH_UPDATE_LUT_FROM_EXTERNAL_BUFFER) {
123 LOGD_ALDCH("%s, attr custom lut buffer %p, size %zu",
124 __FUNCTION__,
125 attr->lut.u.buffer.addr,
126 attr->lut.u.buffer.size);
127 }
128
129 return XCAM_RETURN_NO_ERROR;
130 }
131