This source file includes following definitions.
- calc_csc_coeffs
- __ipu_ic_calc_csc
- ipu_ic_calc_csc
1
2
3
4
5
6 #include <linux/types.h>
7 #include <linux/init.h>
8 #include <linux/errno.h>
9 #include <linux/err.h>
10 #include <linux/sizes.h>
11 #include "ipu-prv.h"
12
13 #define QUANT_MAP(q) \
14 ((q) == V4L2_QUANTIZATION_FULL_RANGE || \
15 (q) == V4L2_QUANTIZATION_DEFAULT ? 0 : 1)
16
17
18 static const struct ipu_ic_csc_params identity = {
19 .coeff = {
20 { 128, 0, 0, },
21 { 0, 128, 0, },
22 { 0, 0, 128, },
23 },
24 .offset = { 0, 0, 0, },
25 .scale = 2,
26 };
27
28
29
30
31
32
33
34
35 static const struct ipu_ic_csc_params rgbf2rgbl = {
36 .coeff = {
37 { 220, 0, 0, },
38 { 0, 220, 0, },
39 { 0, 0, 220, },
40 },
41 .offset = { 64, 64, 64, },
42 .scale = 1,
43 };
44
45
46
47
48
49
50
51
52 static const struct ipu_ic_csc_params rgbl2rgbf = {
53 .coeff = {
54 { 149, 0, 0, },
55 { 0, 149, 0, },
56 { 0, 0, 149, },
57 },
58 .offset = { -37, -37, -37, },
59 .scale = 2,
60 };
61
62
63
64
65
66
67
68
69 static const struct ipu_ic_csc_params yuvf2yuvl = {
70 .coeff = {
71 { 220, 0, 0, },
72 { 0, 225, 0, },
73 { 0, 0, 225, },
74 },
75 .offset = { 64, 62, 62, },
76 .scale = 1,
77 .sat = true,
78 };
79
80
81
82
83
84
85
86
87 static const struct ipu_ic_csc_params yuvl2yuvf = {
88 .coeff = {
89 { 149, 0, 0, },
90 { 0, 146, 0, },
91 { 0, 0, 146, },
92 },
93 .offset = { -37, -35, -35, },
94 .scale = 2,
95 };
96
97 static const struct ipu_ic_csc_params *rgb2rgb[] = {
98 &identity,
99 &rgbf2rgbl,
100 &rgbl2rgbf,
101 &identity,
102 };
103
104 static const struct ipu_ic_csc_params *yuv2yuv[] = {
105 &identity,
106 &yuvf2yuvl,
107 &yuvl2yuvf,
108 &identity,
109 };
110
111
112
113
114
115
116
117
118 static const struct ipu_ic_csc_params rgbf2yuvf_601 = {
119 .coeff = {
120 { 77, 150, 29, },
121 { -43, -85, 128, },
122 { 128, -107, -21, },
123 },
124 .offset = { 0, 512, 512, },
125 .scale = 1,
126 };
127
128
129 static const struct ipu_ic_csc_params rgbf2yuvl_601 = {
130 .coeff = {
131 { 66, 129, 25, },
132 { -38, -74, 112, },
133 { 112, -94, -18, },
134 },
135 .offset = { 64, 512, 512, },
136 .scale = 1,
137 .sat = true,
138 };
139
140
141 static const struct ipu_ic_csc_params rgbl2yuvf_601 = {
142 .coeff = {
143 { 89, 175, 34, },
144 { -50, -99, 149, },
145 { 149, -125, -24, },
146 },
147 .offset = { -75, 512, 512, },
148 .scale = 1,
149 };
150
151
152 static const struct ipu_ic_csc_params rgbl2yuvl_601 = {
153 .coeff = {
154 { 77, 150, 29, },
155 { -44, -87, 131, },
156 { 131, -110, -21, },
157 },
158 .offset = { 0, 512, 512, },
159 .scale = 1,
160 .sat = true,
161 };
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176 static const struct ipu_ic_csc_params yuvf2rgbf_601 = {
177 .coeff = {
178 { 128, 0, 179, },
179 { 128, -44, -91, },
180 { 128, 227, 0, },
181 },
182 .offset = { -359, 271, -454, },
183 .scale = 2,
184 };
185
186
187 static const struct ipu_ic_csc_params yuvf2rgbl_601 = {
188 .coeff = {
189 { 110, 0, 154, },
190 { 110, -38, -78, },
191 { 110, 195, 0, },
192 },
193 .offset = { -276, 265, -358, },
194 .scale = 2,
195 };
196
197
198 static const struct ipu_ic_csc_params yuvl2rgbf_601 = {
199 .coeff = {
200 { 75, 0, 102, },
201 { 75, -25, -52, },
202 { 75, 129, 0, },
203 },
204 .offset = { -223, 136, -277, },
205 .scale = 3,
206 };
207
208
209 static const struct ipu_ic_csc_params yuvl2rgbl_601 = {
210 .coeff = {
211 { 128, 0, 175, },
212 { 128, -43, -89, },
213 { 128, 222, 0, },
214 },
215 .offset = { -351, 265, -443, },
216 .scale = 2,
217 };
218
219 static const struct ipu_ic_csc_params *rgb2yuv_601[] = {
220 &rgbf2yuvf_601,
221 &rgbf2yuvl_601,
222 &rgbl2yuvf_601,
223 &rgbl2yuvl_601,
224 };
225
226 static const struct ipu_ic_csc_params *yuv2rgb_601[] = {
227 &yuvf2rgbf_601,
228 &yuvf2rgbl_601,
229 &yuvl2rgbf_601,
230 &yuvl2rgbl_601,
231 };
232
233
234
235
236
237
238
239
240 static const struct ipu_ic_csc_params rgbf2yuvf_709 = {
241 .coeff = {
242 { 54, 183, 19 },
243 { -29, -99, 128 },
244 { 128, -116, -12 },
245 },
246 .offset = { 0, 512, 512 },
247 .scale = 1,
248 };
249
250
251 static const struct ipu_ic_csc_params rgbf2yuvl_709 = {
252 .coeff = {
253 { 47, 157, 16, },
254 { -26, -87, 112, },
255 { 112, -102, -10, },
256 },
257 .offset = { 64, 512, 512, },
258 .scale = 1,
259 .sat = true,
260 };
261
262
263 static const struct ipu_ic_csc_params rgbl2yuvf_709 = {
264 .coeff = {
265 { 63, 213, 22, },
266 { -34, -115, 149, },
267 { 149, -135, -14, },
268 },
269 .offset = { -75, 512, 512, },
270 .scale = 1,
271 };
272
273
274 static const struct ipu_ic_csc_params rgbl2yuvl_709 = {
275 .coeff = {
276 { 54, 183, 18, },
277 { -30, -101, 131, },
278 { 131, -119, -12, },
279 },
280 .offset = { 0, 512, 512, },
281 .scale = 1,
282 .sat = true,
283 };
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298 static const struct ipu_ic_csc_params yuvf2rgbf_709 = {
299 .coeff = {
300 { 128, 0, 202 },
301 { 128, -24, -60 },
302 { 128, 238, 0 },
303 },
304 .offset = { -403, 168, -475 },
305 .scale = 2,
306 };
307
308
309 static const struct ipu_ic_csc_params yuvf2rgbl_709 = {
310 .coeff = {
311 { 110, 0, 173, },
312 { 110, -21, -51, },
313 { 110, 204, 0, },
314 },
315 .offset = { -314, 176, -376, },
316 .scale = 2,
317 };
318
319
320 static const struct ipu_ic_csc_params yuvl2rgbf_709 = {
321 .coeff = {
322 { 75, 0, 115, },
323 { 75, -14, -34, },
324 { 75, 135, 0, },
325 },
326 .offset = { -248, 77, -289, },
327 .scale = 3,
328 };
329
330
331 static const struct ipu_ic_csc_params yuvl2rgbl_709 = {
332 .coeff = {
333 { 128, 0, 197, },
334 { 128, -23, -59, },
335 { 128, 232, 0, },
336 },
337 .offset = { -394, 164, -464, },
338 .scale = 2,
339 };
340
341 static const struct ipu_ic_csc_params *rgb2yuv_709[] = {
342 &rgbf2yuvf_709,
343 &rgbf2yuvl_709,
344 &rgbl2yuvf_709,
345 &rgbl2yuvl_709,
346 };
347
348 static const struct ipu_ic_csc_params *yuv2rgb_709[] = {
349 &yuvf2rgbf_709,
350 &yuvf2rgbl_709,
351 &yuvl2rgbf_709,
352 &yuvl2rgbl_709,
353 };
354
355 static int calc_csc_coeffs(struct ipu_ic_csc *csc)
356 {
357 const struct ipu_ic_csc_params **params_tbl;
358 int tbl_idx;
359
360 tbl_idx = (QUANT_MAP(csc->in_cs.quant) << 1) |
361 QUANT_MAP(csc->out_cs.quant);
362
363 if (csc->in_cs.cs == csc->out_cs.cs) {
364 csc->params = (csc->in_cs.cs == IPUV3_COLORSPACE_YUV) ?
365 *yuv2yuv[tbl_idx] : *rgb2rgb[tbl_idx];
366
367 return 0;
368 }
369
370
371
372 switch (csc->out_cs.enc) {
373 case V4L2_YCBCR_ENC_601:
374 params_tbl = (csc->in_cs.cs == IPUV3_COLORSPACE_YUV) ?
375 yuv2rgb_601 : rgb2yuv_601;
376 break;
377 case V4L2_YCBCR_ENC_709:
378 params_tbl = (csc->in_cs.cs == IPUV3_COLORSPACE_YUV) ?
379 yuv2rgb_709 : rgb2yuv_709;
380 break;
381 default:
382 return -ENOTSUPP;
383 }
384
385 csc->params = *params_tbl[tbl_idx];
386
387 return 0;
388 }
389
390 int __ipu_ic_calc_csc(struct ipu_ic_csc *csc)
391 {
392 return calc_csc_coeffs(csc);
393 }
394 EXPORT_SYMBOL_GPL(__ipu_ic_calc_csc);
395
396 int ipu_ic_calc_csc(struct ipu_ic_csc *csc,
397 enum v4l2_ycbcr_encoding in_enc,
398 enum v4l2_quantization in_quant,
399 enum ipu_color_space in_cs,
400 enum v4l2_ycbcr_encoding out_enc,
401 enum v4l2_quantization out_quant,
402 enum ipu_color_space out_cs)
403 {
404 ipu_ic_fill_colorspace(&csc->in_cs, in_enc, in_quant, in_cs);
405 ipu_ic_fill_colorspace(&csc->out_cs, out_enc, out_quant, out_cs);
406
407 return __ipu_ic_calc_csc(csc);
408 }
409 EXPORT_SYMBOL_GPL(ipu_ic_calc_csc);