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 #include "ia_css_types.h"
16 #include "sh_css_defs.h"
17 #include "ia_css_debug.h"
18 #include "assert_support.h"
20 #include "ctc/ctc_1.0/ia_css_ctc.host.h"
21 #include "ia_css_ctc1_5.host.h"
23 static void ctc_gradient(
24 int *dydx, int *shift,
25 int y1, int y0, int x1, int x0)
27 int frc_bits = max(IA_CSS_CTC_COEF_SHIFT, 16);
33 /* max_dydx = the maxinum gradient = the maximum y (gain) */
34 int max_dydx = (1 << IA_CSS_CTC_COEF_SHIFT) - 1;
37 ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE, "ctc_gradient() error, illegal division operation\n");
41 dydx_frc = ((dy - dydx_int * dx) << frc_bits) / dx;
44 assert(y0 >= 0 && y0 <= max_dydx);
45 assert(y1 >= 0 && y1 <= max_dydx);
48 assert(shift != NULL);
50 ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE, "ctc_gradient() enter:\n");
52 /* search "sft" which meets this condition:
53 (1 << (IA_CSS_CTC_COEF_SHIFT - 1))
54 <= (((float)dy / (float)dx) * (1 << sft))
55 <= ((1 << IA_CSS_CTC_COEF_SHIFT) - 1) */
56 for (sft = 0; sft <= IA_CSS_CTC_COEF_SHIFT; sft++) {
57 int tmp_dydx = (dydx_int << sft)
58 + (dydx_frc >> (frc_bits - sft));
59 if (tmp_dydx <= max_dydx) {
63 if (tmp_dydx >= max_dydx)
67 ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE, "ctc_gradient() leave:\n");
72 struct sh_css_isp_ctc_params *to,
73 const struct ia_css_ctc_config *from,
84 to->ce_gain_exp = from->ce_gain_exp;
91 ctc_gradient(&(to->dydx0),
96 ctc_gradient(&(to->dydx1),
101 ctc_gradient(&to->dydx2,
106 ctc_gradient(&to->dydx3,
111 ctc_gradient(&(to->dydx4),
114 SH_CSS_BAYER_MAXVAL, from->x4);
119 const struct sh_css_isp_ctc_params *ctc,