2 * Support for Intel Camera Imaging ISP subsystem.
3 * Copyright (c) 2015, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 #ifndef IA_CSS_NO_DEBUG
16 #include "ia_css_debug.h"
19 #include "type_support.h"
20 #include "assert_support.h"
21 #include "math_support.h" /* for min and max */
23 #include "ia_css_eed1_8.host.h"
25 /* WARNING1: Number of inv points should be less or equal to 16,
26 * due to implementation limitation. See kernel design document
28 * WARNING2: Do not modify the number of inv points without correcting
29 * the EED1_8 kernel implementation assumptions.
31 #define NUMBER_OF_CHGRINV_POINTS 15
32 #define NUMBER_OF_TCINV_POINTS 9
33 #define NUMBER_OF_FCINV_POINTS 9
35 static const s16 chgrinv_x[NUMBER_OF_CHGRINV_POINTS] = {
36 0, 16, 64, 144, 272, 448, 672, 976,
37 1376, 1888, 2528, 3312, 4256, 5376, 6688
40 static const s16 chgrinv_a[NUMBER_OF_CHGRINV_POINTS] = {
41 -7171, -256, -29, -3456, -1071, -475, -189, -102,
42 -48, -38, -10, -9, -7, -6, 0
45 static const s16 chgrinv_b[NUMBER_OF_CHGRINV_POINTS] = {
46 8191, 1021, 256, 114, 60, 37, 24, 17,
50 static const s16 chgrinv_c[NUMBER_OF_CHGRINV_POINTS] = {
51 1, 1, 1, 0, 0, 0, 0, 0,
55 static const s16 tcinv_x[NUMBER_OF_TCINV_POINTS] = {
56 0, 4, 11, 23, 42, 68, 102, 148, 205
59 static const s16 tcinv_a[NUMBER_OF_TCINV_POINTS] = {
60 -6364, -631, -126, -34, -13, -6, -4452, -2156, 0
63 static const s16 tcinv_b[NUMBER_OF_TCINV_POINTS] = {
64 8191, 1828, 726, 352, 197, 121, 80, 55, 40
67 static const s16 tcinv_c[NUMBER_OF_TCINV_POINTS] = {
68 1, 1, 1, 1, 1, 1, 0, 0, 0
71 static const s16 fcinv_x[NUMBER_OF_FCINV_POINTS] = {
72 0, 80, 216, 456, 824, 1344, 2040, 2952, 4096
75 static const s16 fcinv_a[NUMBER_OF_FCINV_POINTS] = {
76 -5244, -486, -86, -2849, -961, -400, -180, -86, 0
79 static const s16 fcinv_b[NUMBER_OF_FCINV_POINTS] = {
80 8191, 1637, 607, 287, 159, 98, 64, 44, 32
83 static const s16 fcinv_c[NUMBER_OF_FCINV_POINTS] = {
84 1, 1, 1, 0, 0, 0, 0, 0, 0
88 ia_css_eed1_8_vmem_encode(
89 struct eed1_8_vmem_params *to,
90 const struct ia_css_eed1_8_config *from,
93 unsigned int i, j, base;
94 const unsigned int total_blocks = 4;
95 const unsigned int shuffle_block = 16;
100 for (i = 0; i < ISP_VEC_NELEMS; i++) {
101 to->e_dew_enh_x[0][i] = 0;
102 to->e_dew_enh_y[0][i] = 0;
103 to->e_dew_enh_a[0][i] = 0;
104 to->e_dew_enh_f[0][i] = 0;
105 to->chgrinv_x[0][i] = 0;
106 to->chgrinv_a[0][i] = 0;
107 to->chgrinv_b[0][i] = 0;
108 to->chgrinv_c[0][i] = 0;
109 to->tcinv_x[0][i] = 0;
110 to->tcinv_a[0][i] = 0;
111 to->tcinv_b[0][i] = 0;
112 to->tcinv_c[0][i] = 0;
113 to->fcinv_x[0][i] = 0;
114 to->fcinv_a[0][i] = 0;
115 to->fcinv_b[0][i] = 0;
116 to->fcinv_c[0][i] = 0;
119 /* Constraints on dew_enhance_seg_x and dew_enhance_seg_y:
120 * - values should be greater or equal to 0.
121 * - values should be ascending.
122 * - value of index zero is equal to 0.
125 /* Checking constraints: */
126 /* TODO: investigate if an assert is the right way to report that
127 * the constraints are violated.
129 for (j = 0; j < IA_CSS_NUMBER_OF_DEW_ENHANCE_SEGMENTS; j++) {
130 assert(from->dew_enhance_seg_x[j] > -1);
131 assert(from->dew_enhance_seg_y[j] > -1);
134 for (j = 1; j < IA_CSS_NUMBER_OF_DEW_ENHANCE_SEGMENTS; j++) {
135 assert(from->dew_enhance_seg_x[j] > from->dew_enhance_seg_x[j - 1]);
136 assert(from->dew_enhance_seg_y[j] > from->dew_enhance_seg_y[j - 1]);
139 assert(from->dew_enhance_seg_x[0] == 0);
140 assert(from->dew_enhance_seg_y[0] == 0);
142 /* Constraints on chgrinv_x, tcinv_x and fcinv_x:
143 * - values should be greater or equal to 0.
144 * - values should be ascending.
145 * - value of index zero is equal to 0.
147 assert(chgrinv_x[0] == 0);
148 assert(tcinv_x[0] == 0);
149 assert(fcinv_x[0] == 0);
151 for (j = 1; j < NUMBER_OF_CHGRINV_POINTS; j++) {
152 assert(chgrinv_x[j] > chgrinv_x[j - 1]);
155 for (j = 1; j < NUMBER_OF_TCINV_POINTS; j++) {
156 assert(tcinv_x[j] > tcinv_x[j - 1]);
159 for (j = 1; j < NUMBER_OF_FCINV_POINTS; j++) {
160 assert(fcinv_x[j] > fcinv_x[j - 1]);
163 /* The implementation of the calulating 1/x is based on the availability
164 * of the OP_vec_shuffle16 operation.
165 * A 64 element vector is split up in 4 blocks of 16 element. Each array is copied to
166 * a vector 4 times, (starting at 0, 16, 32 and 48). All array elements are copied or
167 * initialised as described in the KFS. The remaining elements of a vector are set to 0.
169 /* TODO: guard this code with above assumptions */
170 for (i = 0; i < total_blocks; i++) {
171 base = shuffle_block * i;
173 for (j = 0; j < IA_CSS_NUMBER_OF_DEW_ENHANCE_SEGMENTS; j++) {
174 to->e_dew_enh_x[0][base + j] = min_t(int, max_t(int,
175 from->dew_enhance_seg_x[j], 0),
177 to->e_dew_enh_y[0][base + j] = min_t(int, max_t(int,
178 from->dew_enhance_seg_y[j], -8192),
182 for (j = 0; j < (IA_CSS_NUMBER_OF_DEW_ENHANCE_SEGMENTS - 1); j++) {
183 to->e_dew_enh_a[0][base + j] = min_t(int, max_t(int,
184 from->dew_enhance_seg_slope[j],
186 /* Convert dew_enhance_seg_exp to flag:
190 to->e_dew_enh_f[0][base + j] = (min_t(int, max_t(int,
191 from->dew_enhance_seg_exp[j],
195 /* Hard-coded to 0, in order to be able to handle out of
196 * range input in the same way as the other segments.
197 * See KFS for more details.
199 to->e_dew_enh_a[0][base + (IA_CSS_NUMBER_OF_DEW_ENHANCE_SEGMENTS - 1)] = 0;
200 to->e_dew_enh_f[0][base + (IA_CSS_NUMBER_OF_DEW_ENHANCE_SEGMENTS - 1)] = 0;
202 for (j = 0; j < NUMBER_OF_CHGRINV_POINTS; j++) {
203 to->chgrinv_x[0][base + j] = chgrinv_x[j];
204 to->chgrinv_a[0][base + j] = chgrinv_a[j];
205 to->chgrinv_b[0][base + j] = chgrinv_b[j];
206 to->chgrinv_c[0][base + j] = chgrinv_c[j];
209 for (j = 0; j < NUMBER_OF_TCINV_POINTS; j++) {
210 to->tcinv_x[0][base + j] = tcinv_x[j];
211 to->tcinv_a[0][base + j] = tcinv_a[j];
212 to->tcinv_b[0][base + j] = tcinv_b[j];
213 to->tcinv_c[0][base + j] = tcinv_c[j];
216 for (j = 0; j < NUMBER_OF_FCINV_POINTS; j++) {
217 to->fcinv_x[0][base + j] = fcinv_x[j];
218 to->fcinv_a[0][base + j] = fcinv_a[j];
219 to->fcinv_b[0][base + j] = fcinv_b[j];
220 to->fcinv_c[0][base + j] = fcinv_c[j];
226 ia_css_eed1_8_encode(
227 struct eed1_8_dmem_params *to,
228 const struct ia_css_eed1_8_config *from,
236 to->rbzp_strength = from->rbzp_strength;
238 to->fcstrength = from->fcstrength;
239 to->fcthres_0 = from->fcthres_0;
240 to->fc_sat_coef = from->fc_sat_coef;
241 to->fc_coring_prm = from->fc_coring_prm;
242 to->fc_slope = from->fcthres_1 - from->fcthres_0;
244 to->aerel_thres0 = from->aerel_thres0;
245 to->aerel_gain0 = from->aerel_gain0;
246 to->aerel_thres_diff = from->aerel_thres1 - from->aerel_thres0;
247 to->aerel_gain_diff = from->aerel_gain1 - from->aerel_gain0;
249 to->derel_thres0 = from->derel_thres0;
250 to->derel_gain0 = from->derel_gain0;
251 to->derel_thres_diff = (from->derel_thres1 - from->derel_thres0);
252 to->derel_gain_diff = (from->derel_gain1 - from->derel_gain0);
254 to->coring_pos0 = from->coring_pos0;
255 to->coring_pos_diff = (from->coring_pos1 - from->coring_pos0);
256 to->coring_neg0 = from->coring_neg0;
257 to->coring_neg_diff = (from->coring_neg1 - from->coring_neg0);
259 /* Note: (ISP_VEC_ELEMBITS -1)
260 * TODO: currently the testbench does not support to use
261 * ISP_VEC_ELEMBITS. Investigate how to fix this
263 to->gain_exp = (13 - from->gain_exp);
264 to->gain_pos0 = from->gain_pos0;
265 to->gain_pos_diff = (from->gain_pos1 - from->gain_pos0);
266 to->gain_neg0 = from->gain_neg0;
267 to->gain_neg_diff = (from->gain_neg1 - from->gain_neg0);
269 to->margin_pos0 = from->pos_margin0;
270 to->margin_pos_diff = (from->pos_margin1 - from->pos_margin0);
271 to->margin_neg0 = from->neg_margin0;
272 to->margin_neg_diff = (from->neg_margin1 - from->neg_margin0);
274 /* Encode DEWEnhance exp (e_dew_enh_asr) */
275 for (i = 0; i < (IA_CSS_NUMBER_OF_DEW_ENHANCE_SEGMENTS - 1); i++) {
276 min_exp = max(min_exp, from->dew_enhance_seg_exp[i]);
278 to->e_dew_enh_asr = 13 - min(max(min_exp, 0), 13);
280 to->dedgew_max = from->dedgew_max;
284 ia_css_init_eed1_8_state(
288 memset(state, 0, size);
291 #ifndef IA_CSS_NO_DEBUG
293 ia_css_eed1_8_debug_dtrace(
294 const struct ia_css_eed1_8_config *eed,
300 ia_css_debug_dtrace(level, "Edge Enhancing Demosaic 1.8:\n");
301 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "rbzp_strength",
303 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "fcstrength", eed->fcstrength);
304 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "fcthres_0", eed->fcthres_0);
305 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "fcthres_1", eed->fcthres_1);
306 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "fc_sat_coef", eed->fc_sat_coef);
307 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "fc_coring_prm",
310 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "aerel_thres0", eed->aerel_thres0);
311 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "aerel_gain0", eed->aerel_gain0);
312 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "aerel_thres1", eed->aerel_thres1);
313 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "aerel_gain1", eed->aerel_gain1);
315 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "derel_thres0", eed->derel_thres0);
316 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "derel_gain0", eed->derel_gain0);
317 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "derel_thres1", eed->derel_thres1);
318 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "derel_gain1", eed->derel_gain1);
320 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "coring_pos0", eed->coring_pos0);
321 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "coring_pos1", eed->coring_pos1);
322 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "coring_neg0", eed->coring_neg0);
323 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "coring_neg1", eed->coring_neg1);
325 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "gain_exp", eed->gain_exp);
326 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "gain_pos0", eed->gain_pos0);
327 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "gain_pos1", eed->gain_pos1);
328 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "gain_neg0", eed->gain_neg0);
329 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "gain_neg1", eed->gain_neg1);
331 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "pos_margin0", eed->pos_margin0);
332 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "pos_margin1", eed->pos_margin1);
333 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "neg_margin0", eed->neg_margin0);
334 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "neg_margin1", eed->neg_margin1);
336 ia_css_debug_dtrace(level, "\t%-32s = %d\n", "dedgew_max", eed->dedgew_max);