1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Support for Intel Camera Imaging ISP subsystem.
4  * Copyright (c) 2015, Intel Corporation.
5  */
6 
7 #include "ia_css_types.h"
8 #include "sh_css_defs.h"
9 #ifndef IA_CSS_NO_DEBUG
10 /* FIXME: See BZ 4427 */
11 #include "ia_css_debug.h"
12 #endif
13 
14 #include "ia_css_csc.host.h"
15 
16 const struct ia_css_cc_config default_cc_config = {
17 	8,
18 	{255, 29, 120, 0, -374, -342, 0, -672, 301},
19 };
20 
21 void
ia_css_encode_cc(struct sh_css_isp_csc_params * to,const struct ia_css_cc_config * from,unsigned int size)22 ia_css_encode_cc(
23     struct sh_css_isp_csc_params *to,
24     const struct ia_css_cc_config *from,
25     unsigned int size)
26 {
27 	(void)size;
28 #ifndef IA_CSS_NO_DEBUG
29 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE, "ia_css_encode_cc() enter:\n");
30 #endif
31 
32 	to->m_shift    = (int16_t)from->fraction_bits;
33 	to->m00 = (int16_t)from->matrix[0];
34 	to->m01 = (int16_t)from->matrix[1];
35 	to->m02 = (int16_t)from->matrix[2];
36 	to->m10 = (int16_t)from->matrix[3];
37 	to->m11 = (int16_t)from->matrix[4];
38 	to->m12 = (int16_t)from->matrix[5];
39 	to->m20 = (int16_t)from->matrix[6];
40 	to->m21 = (int16_t)from->matrix[7];
41 	to->m22 = (int16_t)from->matrix[8];
42 
43 #ifndef IA_CSS_NO_DEBUG
44 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE, "ia_css_encode_cc() leave:\n");
45 #endif
46 }
47 
48 void
ia_css_csc_encode(struct sh_css_isp_csc_params * to,const struct ia_css_cc_config * from,unsigned int size)49 ia_css_csc_encode(
50     struct sh_css_isp_csc_params *to,
51     const struct ia_css_cc_config *from,
52     unsigned int size)
53 {
54 	ia_css_encode_cc(to, from, size);
55 }
56 
57 #ifndef IA_CSS_NO_DEBUG
58 void
ia_css_cc_dump(const struct sh_css_isp_csc_params * csc,unsigned int level,const char * name)59 ia_css_cc_dump(
60     const struct sh_css_isp_csc_params *csc,
61     unsigned int level,
62     const char *name)
63 {
64 	if (!csc) return;
65 	ia_css_debug_dtrace(level, "%s\n", name);
66 	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
67 			    "m_shift",
68 			    csc->m_shift);
69 	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
70 			    "m00",
71 			    csc->m00);
72 	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
73 			    "m01",
74 			    csc->m01);
75 	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
76 			    "m02",
77 			    csc->m02);
78 	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
79 			    "m10",
80 			    csc->m10);
81 	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
82 			    "m11",
83 			    csc->m11);
84 	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
85 			    "m12",
86 			    csc->m12);
87 	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
88 			    "m20",
89 			    csc->m20);
90 	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
91 			    "m21",
92 			    csc->m21);
93 	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
94 			    "m22",
95 			    csc->m22);
96 }
97 
98 void
ia_css_csc_dump(const struct sh_css_isp_csc_params * csc,unsigned int level)99 ia_css_csc_dump(
100     const struct sh_css_isp_csc_params *csc,
101     unsigned int level)
102 {
103 	ia_css_cc_dump(csc, level, "Color Space Conversion");
104 }
105 
106 void
ia_css_cc_config_debug_dtrace(const struct ia_css_cc_config * config,unsigned int level)107 ia_css_cc_config_debug_dtrace(
108     const struct ia_css_cc_config *config,
109     unsigned int level)
110 {
111 	ia_css_debug_dtrace(level,
112 			    "config.m[0]=%d, config.m[1]=%d, config.m[2]=%d, config.m[3]=%d, config.m[4]=%d, config.m[5]=%d, config.m[6]=%d, config.m[7]=%d, config.m[8]=%d\n",
113 			    config->matrix[0],
114 			    config->matrix[1], config->matrix[2],
115 			    config->matrix[3], config->matrix[4],
116 			    config->matrix[5], config->matrix[6],
117 			    config->matrix[7], config->matrix[8]);
118 }
119 #endif
120