1 /*
2 * RkAiqConfigTranslator.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 "isp20/Isp20Evts.h"
21 #include "isp20/Isp20StatsBuffer.h"
22 #include "common/rkisp2-config.h"
23 #include "common/rkisp21-config.h"
24 #include "RkAiqResourceTranslatorV21.h"
25 #include "PdafStreamProcUnit.h"
26 #include <fcntl.h>
27 #include <unistd.h>
28 #include <arpa/inet.h>
29
30 namespace RkCam {
31
32 XCamReturn
translateAwbStats(const SmartPtr<VideoBuffer> & from,SmartPtr<RkAiqAwbStatsProxy> & to)33 RkAiqResourceTranslatorV21::translateAwbStats (const SmartPtr<VideoBuffer> &from, SmartPtr<RkAiqAwbStatsProxy> &to)
34 {
35 XCamReturn ret = XCAM_RETURN_NO_ERROR;
36 #if defined(ISP_HW_V21)
37 Isp20StatsBuffer* buf =
38 from.get_cast_ptr<Isp20StatsBuffer>();
39 struct rkisp_isp21_stat_buffer *stats;
40 SmartPtr<RkAiqAwbStats> statsInt = to->data();
41
42 stats = (struct rkisp_isp21_stat_buffer*)(buf->get_v4l2_userptr());
43 if(stats == NULL) {
44 LOGE("fail to get stats ,ignore\n");
45 return XCAM_RETURN_BYPASS;
46 }
47 LOGI_ANALYZER("stats: frame_id: %d, meas_type; 0x%x",
48 stats->frame_id, stats->meas_type);
49
50 statsInt->awb_stats_valid = stats->meas_type >> 5 & 1;
51 if (!statsInt->awb_stats_valid) {
52 LOGE_ANALYZER("AWB stats invalid, ignore");
53 return XCAM_RETURN_BYPASS;
54 }
55
56 rkisp_effect_params_v20 ispParams;
57 memset(&ispParams, 0, sizeof(ispParams));
58 if (buf->getEffectiveIspParams(stats->frame_id, ispParams) < 0) {
59 LOGE("fail to get ispParams ,ignore\n");
60 return XCAM_RETURN_BYPASS;
61 }
62
63 // TODO: do awb/ae/af/hdr stats convert
64
65 //awb2.1
66
67 statsInt->awb_stats_v201.awb_cfg_effect_v201 = ispParams.awb_cfg_v201;
68 statsInt->awb_cfg_effect_valid = true;
69 statsInt->frame_id = stats->frame_id;
70
71 for(int i = 0; i < statsInt->awb_stats_v201.awb_cfg_effect_v201.lightNum; i++) {
72 statsInt->awb_stats_v201.light[i].xYType[RK_AIQ_AWB_XY_TYPE_NORMAL_V201].RgainValue =
73 stats->params.rawawb.ro_rawawb_sum_rgain_nor[i];
74 statsInt->awb_stats_v201.light[i].xYType[RK_AIQ_AWB_XY_TYPE_NORMAL_V201].BgainValue =
75 stats->params.rawawb.ro_rawawb_sum_bgain_nor[i];
76 statsInt->awb_stats_v201.light[i].xYType[RK_AIQ_AWB_XY_TYPE_NORMAL_V201].WpNo =
77 stats->params.rawawb.ro_rawawb_wp_num_nor[i];
78 statsInt->awb_stats_v201.light[i].xYType[RK_AIQ_AWB_XY_TYPE_BIG_V201].RgainValue =
79 stats->params.rawawb.ro_rawawb_sum_rgain_big[i];
80 statsInt->awb_stats_v201.light[i].xYType[RK_AIQ_AWB_XY_TYPE_BIG_V201].BgainValue =
81 stats->params.rawawb.ro_rawawb_sum_bgain_big[i];
82 statsInt->awb_stats_v201.light[i].xYType[RK_AIQ_AWB_XY_TYPE_BIG_V201].WpNo =
83 stats->params.rawawb.ro_rawawb_wp_num_big[i];
84
85 }
86
87 for(int i = 0; i < RK_AIQ_AWB_GRID_NUM_TOTAL; i++) {
88 statsInt->awb_stats_v201.blockResult[i].Rvalue = stats->params.rawawb.ramdata[i].r;
89 statsInt->awb_stats_v201.blockResult[i].Gvalue = stats->params.rawawb.ramdata[i].g;
90 statsInt->awb_stats_v201.blockResult[i].Bvalue = stats->params.rawawb.ramdata[i].b;
91 statsInt->awb_stats_v201.blockResult[i].WpNo = stats->params.rawawb.ramdata[i].wp;
92 }
93
94 for(int i = 0; i < RK_AIQ_AWB_WP_HIST_BIN_NUM; i++) {
95 statsInt->awb_stats_v201.WpNoHist[i] = stats->params.rawawb.ro_yhist_bin[i];
96 // move the shift code here to make WpNoHist merged by several cameras easily
97 if( stats->params.rawawb.ro_yhist_bin[i] & 0x8000 ){
98 statsInt->awb_stats_v201.WpNoHist[i] = stats->params.rawawb.ro_yhist_bin[i] & 0x7FFF;
99 statsInt->awb_stats_v201.WpNoHist[i] *= (1 << 3);
100 }
101
102 }
103
104 //statsInt->awb_stats_valid = ISP2X_STAT_RAWAWB(stats->meas_type)? true:false;
105 statsInt->awb_stats_valid = stats->meas_type >> 5 & 1;
106
107 to->set_sequence(stats->frame_id);
108 #endif
109 return ret;
110 }
111
112 #if RKAIQ_HAVE_DEHAZE_V11
113 XCamReturn
translateAdehazeStats(const SmartPtr<VideoBuffer> & from,SmartPtr<RkAiqAdehazeStatsProxy> & to)114 RkAiqResourceTranslatorV21::translateAdehazeStats (const SmartPtr<VideoBuffer> &from, SmartPtr<RkAiqAdehazeStatsProxy> &to)
115 {
116 XCamReturn ret = XCAM_RETURN_NO_ERROR;
117 Isp20StatsBuffer* buf =
118 from.get_cast_ptr<Isp20StatsBuffer>();
119 struct rkisp_isp21_stat_buffer *stats;
120 SmartPtr<RkAiqAdehazeStats> statsInt = to->data();
121
122 stats = (struct rkisp_isp21_stat_buffer*)(buf->get_v4l2_userptr());
123 if(stats == NULL) {
124 LOGE("fail to get stats ,ignore\n");
125 return XCAM_RETURN_BYPASS;
126 }
127 LOGI_ANALYZER("stats: frame_id: %d, meas_type; 0x%x",
128 stats->frame_id, stats->meas_type);
129
130 //dehaze
131 statsInt->adehaze_stats_valid = stats->meas_type >> 17 & 1;
132 statsInt->adehaze_stats.dehaze_stats_v11.dhaz_adp_air_base =
133 stats->params.dhaz.dhaz_adp_air_base;
134 statsInt->adehaze_stats.dehaze_stats_v11.dhaz_adp_wt = stats->params.dhaz.dhaz_adp_wt;
135 statsInt->adehaze_stats.dehaze_stats_v11.dhaz_adp_gratio = stats->params.dhaz.dhaz_adp_gratio;
136 statsInt->adehaze_stats.dehaze_stats_v11.dhaz_adp_wt = stats->params.dhaz.dhaz_adp_wt;
137 for(int i = 0; i < 64; i++)
138 statsInt->adehaze_stats.dehaze_stats_v11.h_rgb_iir[i] = stats->params.dhaz.h_rgb_iir[i];
139
140 to->set_sequence(stats->frame_id);
141
142 return ret;
143 }
144 #endif
145
146 } //namespace RkCam
147