1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
|
/*
* Copyright (C) ST-Ericsson SA 2012
*
* ST-Ericsson B2R2 node splitter
*
* Author: Jorgen Nilsson <jorgen.nilsson@stericsson.com>
* for ST-Ericsson.
*
* License terms: GNU General Public License (GPL), version 2.
*/
#include "b2r2_hw_convert.h"
#include "b2r2_internal.h"
#include "b2r2_utils.h"
/*
* Macros and constants
*/
/* VMX register values for RGB to YUV color conversion */
/* Magic numbers from 27.11 in DB8500_DesignSpecification_v2.5.pdf */
/* 601 Full range conversion matrix */
#define B2R2_VMX0_RGB_TO_YUV_601_FULL_RANGE 0x107e4beb
#define B2R2_VMX1_RGB_TO_YUV_601_FULL_RANGE 0x0982581d
#define B2R2_VMX2_RGB_TO_YUV_601_FULL_RANGE 0xfa9ea483
#define B2R2_VMX3_RGB_TO_YUV_601_FULL_RANGE 0x08000080
/* 601 Standard (clamped) conversion matrix */
#define B2R2_VMX0_RGB_TO_YUV_601_STANDARD 0x0e1e8bee
#define B2R2_VMX1_RGB_TO_YUV_601_STANDARD 0x08420419
#define B2R2_VMX2_RGB_TO_YUV_601_STANDARD 0xfb5ed471
#define B2R2_VMX3_RGB_TO_YUV_601_STANDARD 0x08004080
/* 709 Full range conversion matrix */
#define B2R2_VMX0_RGB_TO_YUV_709_FULL_RANGE 0x107e27f4
#define B2R2_VMX1_RGB_TO_YUV_709_FULL_RANGE 0x06e2dc13
#define B2R2_VMX2_RGB_TO_YUV_709_FULL_RANGE 0xfc5e6c83
#define B2R2_VMX3_RGB_TO_YUV_709_FULL_RANGE 0x08000080
/* 709 Standard (clamped) conversion matrix */
#define B2R2_VMX0_RGB_TO_YUV_709_STANDARD 0x0e3e6bf5
#define B2R2_VMX1_RGB_TO_YUV_709_STANDARD 0x05e27410
#define B2R2_VMX2_RGB_TO_YUV_709_STANDARD 0xfcdea471
#define B2R2_VMX3_RGB_TO_YUV_709_STANDARD 0x08004080
/* VMX register values for YUV to RGB color conversion */
/* 601 Full range conversion matrix */
#define B2R2_VMX0_YUV_TO_RGB_601_FULL_RANGE 0x2c440000
#define B2R2_VMX1_YUV_TO_RGB_601_FULL_RANGE 0xe9a403aa
#define B2R2_VMX2_YUV_TO_RGB_601_FULL_RANGE 0x0004013f
#define B2R2_VMX3_YUV_TO_RGB_601_FULL_RANGE 0x34f21322
/* 601 Standard (clamped) conversion matrix */
#define B2R2_VMX0_YUV_TO_RGB_601_STANDARD 0x3324a800
#define B2R2_VMX1_YUV_TO_RGB_601_STANDARD 0xe604ab9c
#define B2R2_VMX2_YUV_TO_RGB_601_STANDARD 0x0004a957
#define B2R2_VMX3_YUV_TO_RGB_601_STANDARD 0x32121eeb
/* 709 Full range conversion matrix */
#define B2R2_VMX0_YUV_TO_RGB_709_FULL_RANGE 0x31440000
#define B2R2_VMX1_YUV_TO_RGB_709_FULL_RANGE 0xf16403d1
#define B2R2_VMX2_YUV_TO_RGB_709_FULL_RANGE 0x00040145
#define B2R2_VMX3_YUV_TO_RGB_709_FULL_RANGE 0x33b14b18
/* 709 Standard (clamped) conversion matrix */
#define B2R2_VMX0_YUV_TO_RGB_709_STANDARD 0x3964a800
#define B2R2_VMX1_YUV_TO_RGB_709_STANDARD 0xef04abc9
#define B2R2_VMX2_YUV_TO_RGB_709_STANDARD 0x0004a95f
#define B2R2_VMX3_YUV_TO_RGB_709_STANDARD 0x307132df
/* VMX register values for RGB to BGR conversion */
#define B2R2_VMX0_RGB_TO_BGR 0x00000100
#define B2R2_VMX1_RGB_TO_BGR 0x00040000
#define B2R2_VMX2_RGB_TO_BGR 0x20000000
#define B2R2_VMX3_RGB_TO_BGR 0x00000000
/* VMX register values for BGR to YUV color conversion */
/* Note: All BGR -> YUV values are calculated by multiplying
* the RGB -> YUV matrices [A], with [S] to form [A]x[S] where
* |0 0 1|
* S = |0 1 0|
* |1 0 0|
* Essentially swapping first and third columns in
* the matrices (VMX0, VMX1 and VMX2 values).
* The offset vector VMX3 remains untouched.
* Put another way, the value of bits 0 through 9
* is swapped with the value of
* bits 20 through 31 in VMX0, VMX1 and VMX2,
* taking into consideration the compression
* that is used on bits 0 through 9. Bit 0 being LSB.
*/
/* 601 Full range conversion matrix */
#define B2R2_VMX0_BGR_TO_YUV_601_FULL_RANGE 0xfd7e4883
#define B2R2_VMX1_BGR_TO_YUV_601_FULL_RANGE 0x03a2584c
#define B2R2_VMX2_BGR_TO_YUV_601_FULL_RANGE 0x107ea7d4
#define B2R2_VMX3_BGR_TO_YUV_601_FULL_RANGE 0x08000080
/* 601 Standard (clamped) conversion matrix */
#define B2R2_VMX0_BGR_TO_YUV_601_STANDARD 0xfdde8870
#define B2R2_VMX1_BGR_TO_YUV_601_STANDARD 0x03220442
#define B2R2_VMX2_BGR_TO_YUV_601_STANDARD 0x0e3ed7da
#define B2R2_VMX3_BGR_TO_YUV_601_STANDARD 0x08004080
/* 709 Full range conversion matrix */
#define B2R2_VMX0_BGR_TO_YUV_709_FULL_RANGE 0xfe9e2483
#define B2R2_VMX1_BGR_TO_YUV_709_FULL_RANGE 0x0262dc37
#define B2R2_VMX2_BGR_TO_YUV_709_FULL_RANGE 0x107e6fe2
#define B2R2_VMX3_BGR_TO_YUV_709_FULL_RANGE 0x08000080
/* 709 Standard (clamped) conversion matrix */
#define B2R2_VMX0_BGR_TO_YUV_709_STANDARD 0xfebe6871
#define B2R2_VMX1_BGR_TO_YUV_709_STANDARD 0x0202742f
#define B2R2_VMX2_BGR_TO_YUV_709_STANDARD 0x0e3ea7e6
#define B2R2_VMX3_BGR_TO_YUV_709_STANDARD 0x08004080
/* VMX register values for YUV to BGR conversion */
/* Note: All YUV -> BGR values are constructed
* from the YUV -> RGB ones, by swapping
* first and third rows in the matrix
* (VMX0 and VMX2 values). Further, the first and
* third values in the offset vector need to be
* swapped as well, i.e. bits 0 through 9 are swapped
* with bits 20 through 29 in the VMX3 value.
* Bit 0 being LSB.
*/
/* 601 Full range conversion matrix */
#define B2R2_VMX0_YUV_TO_BGR_601_FULL_RANGE (B2R2_VMX2_YUV_TO_RGB_601_FULL_RANGE)
#define B2R2_VMX1_YUV_TO_BGR_601_FULL_RANGE (B2R2_VMX1_YUV_TO_RGB_601_FULL_RANGE)
#define B2R2_VMX2_YUV_TO_BGR_601_FULL_RANGE (B2R2_VMX0_YUV_TO_RGB_601_FULL_RANGE)
#define B2R2_VMX3_YUV_TO_BGR_601_FULL_RANGE 0x3222134f
/* 601 Standard (clamped) conversion matrix */
#define B2R2_VMX0_YUV_TO_BGR_601_STANDARD (B2R2_VMX2_YUV_TO_RGB_601_STANDARD)
#define B2R2_VMX1_YUV_TO_BGR_601_STANDARD (B2R2_VMX1_YUV_TO_RGB_601_STANDARD)
#define B2R2_VMX2_YUV_TO_BGR_601_STANDARD (B2R2_VMX0_YUV_TO_RGB_601_STANDARD)
#define B2R2_VMX3_YUV_TO_BGR_601_STANDARD 0x2eb21f21
/* 709 Full range conversion matrix */
#define B2R2_VMX0_YUV_TO_BGR_709_FULL_RANGE (B2R2_VMX2_YUV_TO_RGB_709_FULL_RANGE)
#define B2R2_VMX1_YUV_TO_BGR_709_FULL_RANGE (B2R2_VMX1_YUV_TO_RGB_709_FULL_RANGE)
#define B2R2_VMX2_YUV_TO_BGR_709_FULL_RANGE (B2R2_VMX0_YUV_TO_RGB_709_FULL_RANGE)
#define B2R2_VMX3_YUV_TO_BGR_709_FULL_RANGE 0x31814b3b
/* 709 Standard (clamped) conversion matrix */
#define B2R2_VMX0_YUV_TO_BGR_709_STANDARD (B2R2_VMX2_YUV_TO_RGB_709_STANDARD)
#define B2R2_VMX1_YUV_TO_BGR_709_STANDARD (B2R2_VMX1_YUV_TO_RGB_709_STANDARD)
#define B2R2_VMX2_YUV_TO_BGR_709_STANDARD (B2R2_VMX0_YUV_TO_RGB_709_STANDARD)
#define B2R2_VMX3_YUV_TO_BGR_709_STANDARD 0x2df13307
/* VMX register values for YVU to RGB conversion */
/* 601 Full range conversion matrix */
#define B2R2_VMX0_YVU_TO_RGB_601_FULL_RANGE 0x00040120
#define B2R2_VMX1_YVU_TO_RGB_601_FULL_RANGE 0xF544034D
#define B2R2_VMX2_YVU_TO_RGB_601_FULL_RANGE 0x37840000
#define B2R2_VMX3_YVU_TO_RGB_601_FULL_RANGE (B2R2_VMX3_YUV_TO_RGB_601_FULL_RANGE)
/* 601 Standard (clamped) conversion matrix */
#define B2R2_VMX0_YVU_TO_RGB_601_STANDARD 0x0004A999
#define B2R2_VMX1_YVU_TO_RGB_601_STANDARD 0xF384AB30
#define B2R2_VMX2_YVU_TO_RGB_601_STANDARD 0x40A4A800
#define B2R2_VMX3_YVU_TO_RGB_601_STANDARD (B2R2_VMX3_YUV_TO_RGB_601_STANDARD)
/* VMX register values for RGB to YVU conversion */
/* 601 Full range conversion matrix */
#define B2R2_VMX0_RGB_TO_YVU_601_FULL_RANGE (B2R2_VMX2_RGB_TO_YUV_601_FULL_RANGE)
#define B2R2_VMX1_RGB_TO_YVU_601_FULL_RANGE (B2R2_VMX1_RGB_TO_YUV_601_FULL_RANGE)
#define B2R2_VMX2_RGB_TO_YVU_601_FULL_RANGE (B2R2_VMX0_RGB_TO_YUV_601_FULL_RANGE)
#define B2R2_VMX3_RGB_TO_YVU_601_FULL_RANGE (B2R2_VMX3_RGB_TO_YUV_601_FULL_RANGE)
/* 601 Standard (clamped) conversion matrix */
#define B2R2_VMX0_RGB_TO_YVU_601_STANDARD (B2R2_VMX2_RGB_TO_YUV_601_STANDARD)
#define B2R2_VMX1_RGB_TO_YVU_601_STANDARD (B2R2_VMX1_RGB_TO_YUV_601_STANDARD)
#define B2R2_VMX2_RGB_TO_YVU_601_STANDARD (B2R2_VMX0_RGB_TO_YUV_601_STANDARD)
#define B2R2_VMX3_RGB_TO_YVU_601_STANDARD (B2R2_VMX3_RGB_TO_YUV_601_STANDARD)
/* VMX register values for YVU to BGR conversion */
/* 601 Full range conversion matrix */
#define B2R2_VMX0_YVU_TO_BGR_601_FULL_RANGE (B2R2_VMX2_YVU_TO_RGB_601_FULL_RANGE)
#define B2R2_VMX1_YVU_TO_BGR_601_FULL_RANGE (B2R2_VMX1_YVU_TO_RGB_601_FULL_RANGE)
#define B2R2_VMX2_YVU_TO_BGR_601_FULL_RANGE (B2R2_VMX0_YVU_TO_RGB_601_FULL_RANGE)
#define B2R2_VMX3_YVU_TO_BGR_601_FULL_RANGE 0x3222134F
/* 601 Standard (clamped) conversion matrix */
#define B2R2_VMX0_YVU_TO_BGR_601_STANDARD (B2R2_VMX2_YVU_TO_RGB_601_STANDARD)
#define B2R2_VMX1_YVU_TO_BGR_601_STANDARD (B2R2_VMX1_YVU_TO_RGB_601_STANDARD)
#define B2R2_VMX2_YVU_TO_BGR_601_STANDARD (B2R2_VMX0_YVU_TO_RGB_601_STANDARD)
#define B2R2_VMX3_YVU_TO_BGR_601_STANDARD 0x3222134F
/* VMX register values for BGR to YVU conversion */
/* 601 Full range conversion matrix */
#define B2R2_VMX0_BGR_TO_YVU_601_FULL_RANGE (B2R2_VMX2_BGR_TO_YUV_601_FULL_RANGE)
#define B2R2_VMX1_BGR_TO_YVU_601_FULL_RANGE (B2R2_VMX1_BGR_TO_YUV_601_FULL_RANGE)
#define B2R2_VMX2_BGR_TO_YVU_601_FULL_RANGE (B2R2_VMX0_BGR_TO_YUV_601_FULL_RANGE)
#define B2R2_VMX3_BGR_TO_YVU_601_FULL_RANGE (B2R2_VMX3_BGR_TO_YUV_601_FULL_RANGE)
/* 601 Standard (clamped) conversion matrix */
#define B2R2_VMX0_BGR_TO_YVU_601_STANDARD (B2R2_VMX2_BGR_TO_YUV_601_STANDARD)
#define B2R2_VMX1_BGR_TO_YVU_601_STANDARD (B2R2_VMX1_BGR_TO_YUV_601_STANDARD)
#define B2R2_VMX2_BGR_TO_YVU_601_STANDARD (B2R2_VMX0_BGR_TO_YUV_601_STANDARD)
#define B2R2_VMX3_BGR_TO_YVU_601_STANDARD (B2R2_VMX3_BGR_TO_YUV_601_STANDARD)
/* VMX register values for YVU to YUV conversion */
/* 601 Video Matrix (standard 601 conversion) */
/* Internally, the components are in fact stored
* with luma in the middle, i.e. UYV, which is why
* the values are just like for RGB->BGR conversion.
*/
#define B2R2_VMX0_YVU_TO_YUV 0x00000100
#define B2R2_VMX1_YVU_TO_YUV 0x00040000
#define B2R2_VMX2_YVU_TO_YUV 0x20000000
#define B2R2_VMX3_YVU_TO_YUV 0x00000000
/* VMX register values for RGB to BLT_YUV888 conversion */
/*
* BLT_YUV888 has color components laid out in memory as V, U, Y, (Alpha)
* with V at the first byte (due to little endian addressing).
* B2R2 expects them to be as U, Y, V, (A)
* with U at the first byte.
* Note: RGB -> BLT_YUV888 values are calculated by multiplying
* the RGB -> YUV matrix [A], with [S] to form [S]x[A] where
* |0 1 0|
* S = |0 0 1|
* |1 0 0|
* Essentially changing the order of rows in the original
* matrix [A].
* row1 -> row3
* row2 -> row1
* row3 -> row2
* Values in the offset vector are swapped in the same manner.
*/
/* 601 Full range conversion matrix */
#define B2R2_VMX0_RGB_TO_BLT_YUV888_601_FULL_RANGE (B2R2_VMX1_RGB_TO_YUV_601_FULL_RANGE)
#define B2R2_VMX1_RGB_TO_BLT_YUV888_601_FULL_RANGE (B2R2_VMX2_RGB_TO_YUV_601_FULL_RANGE)
#define B2R2_VMX2_RGB_TO_BLT_YUV888_601_FULL_RANGE (B2R2_VMX0_RGB_TO_YUV_601_FULL_RANGE)
#define B2R2_VMX3_RGB_TO_BLT_YUV888_601_FULL_RANGE 0x00020080
/* 601 Standard (clamped) conversion matrix */
#define B2R2_VMX0_RGB_TO_BLT_YUV888_601_STANDARD (B2R2_VMX1_RGB_TO_YUV_601_STANDARD)
#define B2R2_VMX1_RGB_TO_BLT_YUV888_601_STANDARD (B2R2_VMX2_RGB_TO_YUV_601_STANDARD)
#define B2R2_VMX2_RGB_TO_BLT_YUV888_601_STANDARD (B2R2_VMX0_RGB_TO_YUV_601_STANDARD)
#define B2R2_VMX3_RGB_TO_BLT_YUV888_601_STANDARD 0x00020080
/* VMX register values for BLT_YUV888 to RGB conversion */
/*
* Note: BLT_YUV888 -> RGB values are calculated by multiplying
* the YUV -> RGB matrix [A], with [S] to form [A]x[S] where
* |0 0 1|
* S = |1 0 0|
* |0 1 0|
* Essentially changing the order of columns in the original
* matrix [A].
* col1 -> col3
* col2 -> col1
* col3 -> col2
* Values in the offset vector remain unchanged.
*/
/* 601 Full range conversion matrix */
#define B2R2_VMX0_BLT_YUV888_TO_RGB_601_FULL_RANGE 0x20000121
#define B2R2_VMX1_BLT_YUV888_TO_RGB_601_FULL_RANGE 0x201ea74c
#define B2R2_VMX2_BLT_YUV888_TO_RGB_601_FULL_RANGE 0x2006f000
#define B2R2_VMX3_BLT_YUV888_TO_RGB_601_FULL_RANGE (B2R2_VMX3_YUV_TO_RGB_601_FULL_RANGE)
/* 601 Standard (clamped) conversion matrix */
#define B2R2_VMX0_BLT_YUV888_TO_RGB_601_STANDARD 0x25400133
#define B2R2_VMX1_BLT_YUV888_TO_RGB_601_STANDARD 0x255E7330
#define B2R2_VMX2_BLT_YUV888_TO_RGB_601_STANDARD 0x25481400
#define B2R2_VMX3_BLT_YUV888_TO_RGB_601_STANDARD (B2R2_VMX3_YUV_TO_RGB_601_FULL_RANGE)
/* VMX register values for YUV to BLT_YUV888 conversion */
#define B2R2_VMX0_YUV_TO_BLT_YUV888 0x00040000
#define B2R2_VMX1_YUV_TO_BLT_YUV888 0x00000100
#define B2R2_VMX2_YUV_TO_BLT_YUV888 0x20000000
#define B2R2_VMX3_YUV_TO_BLT_YUV888 0x00000000
/* VMX register values for BLT_YUV888 to YUV conversion */
#define B2R2_VMX0_BLT_YUV888_TO_YUV 0x00000100
#define B2R2_VMX1_BLT_YUV888_TO_YUV 0x20000000
#define B2R2_VMX2_BLT_YUV888_TO_YUV 0x00040000
#define B2R2_VMX3_BLT_YUV888_TO_YUV 0x00000000
/* VMX register values for YVU to BLT_YUV888 conversion */
#define B2R2_VMX0_YVU_TO_BLT_YUV888 0x00040000
#define B2R2_VMX1_YVU_TO_BLT_YUV888 0x20000000
#define B2R2_VMX2_YVU_TO_BLT_YUV888 0x00000100
#define B2R2_VMX3_YVU_TO_BLT_YUV888 0x00000000
/* VMX register values for BLT_YUV888 to YVU conversion */
#define B2R2_VMX0_BLT_YUV888_TO_YVU 0x00040000
#define B2R2_VMX1_BLT_YUV888_TO_YVU 0x20000000
#define B2R2_VMX2_BLT_YUV888_TO_YVU 0x00000100
#define B2R2_VMX3_BLT_YUV888_TO_YVU 0x00000000
/*
* Internal types
*/
/*
* Global variables
*/
/**
* VMx values for color space conversion
* (component swap)
*/
static const u32 vmx_yuv_to_blt_yuv888[] = {
B2R2_VMX0_YUV_TO_BLT_YUV888,
B2R2_VMX1_YUV_TO_BLT_YUV888,
B2R2_VMX2_YUV_TO_BLT_YUV888,
B2R2_VMX3_YUV_TO_BLT_YUV888,
};
static const u32 vmx_blt_yuv888_to_yuv[] = {
B2R2_VMX0_BLT_YUV888_TO_YUV,
B2R2_VMX1_BLT_YUV888_TO_YUV,
B2R2_VMX2_BLT_YUV888_TO_YUV,
B2R2_VMX3_BLT_YUV888_TO_YUV,
};
static const u32 vmx_yvu_to_blt_yuv888[] = {
B2R2_VMX0_YVU_TO_BLT_YUV888,
B2R2_VMX1_YVU_TO_BLT_YUV888,
B2R2_VMX2_YVU_TO_BLT_YUV888,
B2R2_VMX3_YVU_TO_BLT_YUV888,
};
static const u32 vmx_blt_yuv888_to_yvu[] = {
B2R2_VMX0_BLT_YUV888_TO_YVU,
B2R2_VMX1_BLT_YUV888_TO_YVU,
B2R2_VMX2_BLT_YUV888_TO_YVU,
B2R2_VMX3_BLT_YUV888_TO_YVU,
};
static const u32 vmx_rgb_to_bgr[] = {
B2R2_VMX0_RGB_TO_BGR,
B2R2_VMX1_RGB_TO_BGR,
B2R2_VMX2_RGB_TO_BGR,
B2R2_VMX3_RGB_TO_BGR,
};
static const u32 vmx_yvu_to_yuv[] = {
B2R2_VMX0_YVU_TO_YUV,
B2R2_VMX1_YVU_TO_YUV,
B2R2_VMX2_YVU_TO_YUV,
B2R2_VMX3_YVU_TO_YUV,
};
/**
* VMx values for color space conversions
* (standard 601 conversions)
*/
static const u32 vmx_rgb_to_yuv[] = {
B2R2_VMX0_RGB_TO_YUV_601_STANDARD,
B2R2_VMX1_RGB_TO_YUV_601_STANDARD,
B2R2_VMX2_RGB_TO_YUV_601_STANDARD,
B2R2_VMX3_RGB_TO_YUV_601_STANDARD,
};
static const u32 vmx_yuv_to_rgb[] = {
B2R2_VMX0_YUV_TO_RGB_601_STANDARD,
B2R2_VMX1_YUV_TO_RGB_601_STANDARD,
B2R2_VMX2_YUV_TO_RGB_601_STANDARD,
B2R2_VMX3_YUV_TO_RGB_601_STANDARD,
};
static const u32 vmx_rgb_to_blt_yuv888[] = {
B2R2_VMX0_RGB_TO_BLT_YUV888_601_STANDARD,
B2R2_VMX1_RGB_TO_BLT_YUV888_601_STANDARD,
B2R2_VMX2_RGB_TO_BLT_YUV888_601_STANDARD,
B2R2_VMX3_RGB_TO_BLT_YUV888_601_STANDARD,
};
static const u32 vmx_blt_yuv888_to_rgb[] = {
B2R2_VMX0_BLT_YUV888_TO_RGB_601_STANDARD,
B2R2_VMX1_BLT_YUV888_TO_RGB_601_STANDARD,
B2R2_VMX2_BLT_YUV888_TO_RGB_601_STANDARD,
B2R2_VMX3_BLT_YUV888_TO_RGB_601_STANDARD,
};
static const u32 vmx_rgb_to_yvu[] = {
B2R2_VMX0_RGB_TO_YVU_601_STANDARD,
B2R2_VMX1_RGB_TO_YVU_601_STANDARD,
B2R2_VMX2_RGB_TO_YVU_601_STANDARD,
B2R2_VMX3_RGB_TO_YVU_601_STANDARD,
};
static const u32 vmx_yvu_to_rgb[] = {
B2R2_VMX0_YVU_TO_RGB_601_STANDARD,
B2R2_VMX1_YVU_TO_RGB_601_STANDARD,
B2R2_VMX2_YVU_TO_RGB_601_STANDARD,
B2R2_VMX3_YVU_TO_RGB_601_STANDARD,
};
static const u32 vmx_bgr_to_yuv[] = {
B2R2_VMX0_BGR_TO_YUV_601_STANDARD,
B2R2_VMX1_BGR_TO_YUV_601_STANDARD,
B2R2_VMX2_BGR_TO_YUV_601_STANDARD,
B2R2_VMX3_BGR_TO_YUV_601_STANDARD,
};
static const u32 vmx_yuv_to_bgr[] = {
B2R2_VMX0_YUV_TO_BGR_601_STANDARD,
B2R2_VMX1_YUV_TO_BGR_601_STANDARD,
B2R2_VMX2_YUV_TO_BGR_601_STANDARD,
B2R2_VMX3_YUV_TO_BGR_601_STANDARD,
};
static const u32 vmx_bgr_to_yvu[] = {
B2R2_VMX0_BGR_TO_YVU_601_STANDARD,
B2R2_VMX1_BGR_TO_YVU_601_STANDARD,
B2R2_VMX2_BGR_TO_YVU_601_STANDARD,
B2R2_VMX3_BGR_TO_YVU_601_STANDARD,
};
static const u32 vmx_yvu_to_bgr[] = {
B2R2_VMX0_YVU_TO_BGR_601_STANDARD,
B2R2_VMX1_YVU_TO_BGR_601_STANDARD,
B2R2_VMX2_YVU_TO_BGR_601_STANDARD,
B2R2_VMX3_YVU_TO_BGR_601_STANDARD,
};
/**
* VMx values for color space conversions
* (full range conversions)
*/
static const u32 vmx_full_rgb_to_yuv[] = {
B2R2_VMX0_RGB_TO_YUV_601_FULL_RANGE,
B2R2_VMX1_RGB_TO_YUV_601_FULL_RANGE,
B2R2_VMX2_RGB_TO_YUV_601_FULL_RANGE,
B2R2_VMX3_RGB_TO_YUV_601_FULL_RANGE,
};
static const u32 vmx_full_yuv_to_rgb[] = {
B2R2_VMX0_YUV_TO_RGB_601_FULL_RANGE,
B2R2_VMX1_YUV_TO_RGB_601_FULL_RANGE,
B2R2_VMX2_YUV_TO_RGB_601_FULL_RANGE,
B2R2_VMX3_YUV_TO_RGB_601_FULL_RANGE,
};
static const u32 vmx_full_rgb_to_blt_yuv888[] = {
B2R2_VMX0_RGB_TO_BLT_YUV888_601_FULL_RANGE,
B2R2_VMX1_RGB_TO_BLT_YUV888_601_FULL_RANGE,
B2R2_VMX2_RGB_TO_BLT_YUV888_601_FULL_RANGE,
B2R2_VMX3_RGB_TO_BLT_YUV888_601_FULL_RANGE,
};
static const u32 vmx_full_blt_yuv888_to_rgb[] = {
B2R2_VMX0_BLT_YUV888_TO_RGB_601_FULL_RANGE,
B2R2_VMX1_BLT_YUV888_TO_RGB_601_FULL_RANGE,
B2R2_VMX2_BLT_YUV888_TO_RGB_601_FULL_RANGE,
B2R2_VMX3_BLT_YUV888_TO_RGB_601_FULL_RANGE,
};
static const u32 vmx_full_yvu_to_rgb[] = {
B2R2_VMX0_YVU_TO_RGB_601_FULL_RANGE,
B2R2_VMX1_YVU_TO_RGB_601_FULL_RANGE,
B2R2_VMX2_YVU_TO_RGB_601_FULL_RANGE,
B2R2_VMX3_YVU_TO_RGB_601_FULL_RANGE,
};
static const u32 vmx_full_rgb_to_yvu[] = {
B2R2_VMX0_RGB_TO_YVU_601_FULL_RANGE,
B2R2_VMX1_RGB_TO_YVU_601_FULL_RANGE,
B2R2_VMX2_RGB_TO_YVU_601_FULL_RANGE,
B2R2_VMX3_RGB_TO_YVU_601_FULL_RANGE,
};
static const u32 vmx_full_bgr_to_yuv[] = {
B2R2_VMX0_BGR_TO_YUV_601_FULL_RANGE,
B2R2_VMX1_BGR_TO_YUV_601_FULL_RANGE,
B2R2_VMX2_BGR_TO_YUV_601_FULL_RANGE,
B2R2_VMX3_BGR_TO_YUV_601_FULL_RANGE,
};
static const u32 vmx_full_yuv_to_bgr[] = {
B2R2_VMX0_YUV_TO_BGR_601_FULL_RANGE,
B2R2_VMX1_YUV_TO_BGR_601_FULL_RANGE,
B2R2_VMX2_YUV_TO_BGR_601_FULL_RANGE,
B2R2_VMX3_YUV_TO_BGR_601_FULL_RANGE,
};
static const u32 vmx_full_bgr_to_yvu[] = {
B2R2_VMX0_BGR_TO_YVU_601_FULL_RANGE,
B2R2_VMX1_BGR_TO_YVU_601_FULL_RANGE,
B2R2_VMX2_BGR_TO_YVU_601_FULL_RANGE,
B2R2_VMX3_BGR_TO_YVU_601_FULL_RANGE,
};
static const u32 vmx_full_yvu_to_bgr[] = {
B2R2_VMX0_YVU_TO_BGR_601_FULL_RANGE,
B2R2_VMX1_YVU_TO_BGR_601_FULL_RANGE,
B2R2_VMX2_YVU_TO_BGR_601_FULL_RANGE,
B2R2_VMX3_YVU_TO_BGR_601_FULL_RANGE,
};
/*
* Forward declaration of private functions
*/
/*
* Public functions
*/
/**
* Setup input versatile matrix for color space conversion
*/
int b2r2_setup_ivmx(struct b2r2_node *node, enum b2r2_color_conversion cc)
{
const u32 *vmx = NULL;
if (b2r2_get_vmx(cc, &vmx) < 0 || vmx == NULL)
return -1;
node->node.GROUP0.B2R2_INS |= B2R2_INS_IVMX_ENABLED;
node->node.GROUP0.B2R2_CIC |= B2R2_CIC_IVMX;
node->node.GROUP15.B2R2_VMX0 = vmx[0];
node->node.GROUP15.B2R2_VMX1 = vmx[1];
node->node.GROUP15.B2R2_VMX2 = vmx[2];
node->node.GROUP15.B2R2_VMX3 = vmx[3];
return 0;
}
/**
* Setup output versatile matrix for color space conversion
*/
int b2r2_setup_ovmx(struct b2r2_node *node, enum b2r2_color_conversion cc)
{
const u32 *vmx = NULL;
if (b2r2_get_vmx(cc, &vmx) < 0 || vmx == NULL)
return -1;
node->node.GROUP0.B2R2_INS |= B2R2_INS_OVMX_ENABLED;
node->node.GROUP0.B2R2_CIC |= B2R2_CIC_OVMX;
node->node.GROUP16.B2R2_VMX0 = vmx[0];
node->node.GROUP16.B2R2_VMX1 = vmx[1];
node->node.GROUP16.B2R2_VMX2 = vmx[2];
node->node.GROUP16.B2R2_VMX3 = vmx[3];
return 0;
}
enum b2r2_color_conversion b2r2_get_color_conversion(enum b2r2_blt_fmt src_fmt,
enum b2r2_blt_fmt dst_fmt, bool fullrange)
{
if (b2r2_is_rgb_fmt(src_fmt)) {
if (b2r2_is_yvu_fmt(dst_fmt))
return fullrange ? B2R2_CC_RGB_TO_YVU_FULL :
B2R2_CC_RGB_TO_YVU;
else if (dst_fmt == B2R2_BLT_FMT_24_BIT_YUV888 ||
dst_fmt == B2R2_BLT_FMT_32_BIT_AYUV8888 ||
dst_fmt == B2R2_BLT_FMT_24_BIT_VUY888 ||
dst_fmt == B2R2_BLT_FMT_32_BIT_VUYA8888)
/*
* (A)YUV/VUY(A) formats differ only in component
* order. This is handled by the endianness bit
* in B2R2_STY/TTY registers when src/target are set.
*/
return fullrange ? B2R2_CC_RGB_TO_BLT_YUV888_FULL :
B2R2_CC_RGB_TO_BLT_YUV888;
else if (b2r2_is_yuv_fmt(dst_fmt))
return fullrange ? B2R2_CC_RGB_TO_YUV_FULL :
B2R2_CC_RGB_TO_YUV;
else if (b2r2_is_bgr_fmt(dst_fmt))
return B2R2_CC_RGB_TO_BGR;
} else if (b2r2_is_yvu_fmt(src_fmt)) {
if (b2r2_is_rgb_fmt(dst_fmt))
return fullrange ? B2R2_CC_YVU_FULL_TO_RGB :
B2R2_CC_YVU_TO_RGB;
else if (b2r2_is_bgr_fmt(dst_fmt))
return fullrange ? B2R2_CC_YVU_FULL_TO_BGR :
B2R2_CC_YVU_TO_BGR;
else if (dst_fmt == B2R2_BLT_FMT_24_BIT_YUV888 ||
dst_fmt == B2R2_BLT_FMT_32_BIT_AYUV8888 ||
dst_fmt == B2R2_BLT_FMT_24_BIT_VUY888 ||
dst_fmt == B2R2_BLT_FMT_32_BIT_VUYA8888)
return B2R2_CC_YVU_TO_BLT_YUV888;
else if (b2r2_is_yuv_fmt(dst_fmt) &&
!b2r2_is_yvu_fmt(dst_fmt))
return B2R2_CC_YVU_TO_YUV;
} else if (src_fmt == B2R2_BLT_FMT_24_BIT_YUV888 ||
src_fmt == B2R2_BLT_FMT_32_BIT_AYUV8888 ||
src_fmt == B2R2_BLT_FMT_24_BIT_VUY888 ||
src_fmt == B2R2_BLT_FMT_32_BIT_VUYA8888) {
/*
* (A)YUV/VUY(A) formats differ only in component
* order. This is handled by the endianness bit
* in B2R2_STY/TTY registers when src/target are set.
*/
if (b2r2_is_rgb_fmt(dst_fmt))
return fullrange ? B2R2_CC_BLT_YUV888_FULL_TO_RGB :
B2R2_CC_BLT_YUV888_TO_RGB;
else if (b2r2_is_yvu_fmt(dst_fmt))
return B2R2_CC_BLT_YUV888_TO_YVU;
else if (b2r2_is_yuv_fmt(dst_fmt)) {
switch (dst_fmt) {
case B2R2_BLT_FMT_24_BIT_YUV888:
case B2R2_BLT_FMT_32_BIT_AYUV8888:
case B2R2_BLT_FMT_24_BIT_VUY888:
case B2R2_BLT_FMT_32_BIT_VUYA8888:
return B2R2_CC_NOTHING;
default:
return B2R2_CC_BLT_YUV888_TO_YUV;
}
}
} else if (b2r2_is_yuv_fmt(src_fmt)) {
if (b2r2_is_rgb_fmt(dst_fmt))
return fullrange ? B2R2_CC_YUV_FULL_TO_RGB :
B2R2_CC_YUV_TO_RGB;
else if (b2r2_is_bgr_fmt(dst_fmt))
return fullrange ? B2R2_CC_YUV_FULL_TO_BGR :
B2R2_CC_YUV_TO_BGR;
else if (dst_fmt == B2R2_BLT_FMT_24_BIT_YUV888 ||
dst_fmt == B2R2_BLT_FMT_32_BIT_AYUV8888 ||
dst_fmt == B2R2_BLT_FMT_24_BIT_VUY888 ||
dst_fmt == B2R2_BLT_FMT_32_BIT_VUYA8888)
return B2R2_CC_YUV_TO_BLT_YUV888;
else if (b2r2_is_yvu_fmt(dst_fmt))
return B2R2_CC_YVU_TO_YUV;
} else if (b2r2_is_bgr_fmt(src_fmt)) {
if (b2r2_is_rgb_fmt(dst_fmt))
return B2R2_CC_RGB_TO_BGR;
else if (b2r2_is_yvu_fmt(dst_fmt))
return fullrange ? B2R2_CC_BGR_TO_YVU_FULL :
B2R2_CC_BGR_TO_YVU;
else if (dst_fmt == B2R2_BLT_FMT_24_BIT_YUV888 ||
dst_fmt == B2R2_BLT_FMT_32_BIT_AYUV8888 ||
dst_fmt == B2R2_BLT_FMT_24_BIT_VUY888 ||
dst_fmt == B2R2_BLT_FMT_32_BIT_VUYA8888)
BUG_ON(1);
else if (b2r2_is_yuv_fmt(dst_fmt))
return fullrange ? B2R2_CC_BGR_TO_YUV_FULL :
B2R2_CC_BGR_TO_YUV;
}
return B2R2_CC_NOTHING;
}
int b2r2_get_vmx(enum b2r2_color_conversion cc, const u32 **vmx)
{
if (vmx == NULL)
return -1;
switch (cc) {
case B2R2_CC_RGB_TO_BGR:
*vmx = &vmx_rgb_to_bgr[0];
break;
case B2R2_CC_BLT_YUV888_TO_YVU:
*vmx = &vmx_blt_yuv888_to_yvu[0];
break;
case B2R2_CC_BLT_YUV888_TO_YUV:
*vmx = &vmx_blt_yuv888_to_yuv[0];
break;
case B2R2_CC_YVU_TO_YUV:
*vmx = &vmx_yvu_to_yuv[0];
break;
case B2R2_CC_YVU_TO_BLT_YUV888:
*vmx = &vmx_yvu_to_blt_yuv888[0];
break;
case B2R2_CC_YUV_TO_BLT_YUV888:
*vmx = &vmx_yuv_to_blt_yuv888[0];
break;
case B2R2_CC_RGB_TO_YUV:
*vmx = &vmx_rgb_to_yuv[0];
break;
case B2R2_CC_RGB_TO_YUV_FULL:
*vmx = &vmx_full_rgb_to_yuv[0];
break;
case B2R2_CC_RGB_TO_YVU:
*vmx = &vmx_rgb_to_yvu[0];
break;
case B2R2_CC_RGB_TO_YVU_FULL:
*vmx = &vmx_full_rgb_to_yvu[0];
break;
case B2R2_CC_RGB_TO_BLT_YUV888:
*vmx = &vmx_rgb_to_blt_yuv888[0];
break;
case B2R2_CC_RGB_TO_BLT_YUV888_FULL:
*vmx = &vmx_full_rgb_to_blt_yuv888[0];
break;
case B2R2_CC_BGR_TO_YVU:
*vmx = &vmx_bgr_to_yvu[0];
break;
case B2R2_CC_BGR_TO_YVU_FULL:
*vmx = &vmx_full_bgr_to_yvu[0];
break;
case B2R2_CC_BGR_TO_YUV:
*vmx = &vmx_bgr_to_yuv[0];
break;
case B2R2_CC_BGR_TO_YUV_FULL:
*vmx = &vmx_full_bgr_to_yuv[0];
break;
case B2R2_CC_YUV_TO_RGB:
*vmx = &vmx_yuv_to_rgb[0];
break;
case B2R2_CC_YUV_FULL_TO_RGB:
*vmx = &vmx_full_yuv_to_rgb[0];
break;
case B2R2_CC_YUV_TO_BGR:
*vmx = &vmx_yuv_to_bgr[0];
break;
case B2R2_CC_YUV_FULL_TO_BGR:
*vmx = &vmx_full_yuv_to_bgr[0];
break;
case B2R2_CC_YVU_TO_RGB:
*vmx = &vmx_yvu_to_rgb[0];
break;
case B2R2_CC_YVU_FULL_TO_RGB:
*vmx = &vmx_full_yvu_to_rgb[0];
break;
case B2R2_CC_YVU_TO_BGR:
*vmx = &vmx_yvu_to_bgr[0];
break;
case B2R2_CC_YVU_FULL_TO_BGR:
*vmx = &vmx_full_yvu_to_bgr[0];
break;
case B2R2_CC_BLT_YUV888_TO_RGB:
*vmx = &vmx_blt_yuv888_to_rgb[0];
break;
case B2R2_CC_BLT_YUV888_FULL_TO_RGB:
*vmx = &vmx_full_blt_yuv888_to_rgb[0];
break;
case B2R2_CC_NOTHING:
default:
break;
}
return 0;
}
|