Debian Codegraph @

src/imagination/common/pvr_ycbcr.c

raw
1 /*
2 * Copyright © 2026 Imagination Technologies Ltd.
3 * SPDX-License-Identifier: MIT
4 */
5 #include "pvr_ycbcr.h"
6
7 #include "util/macros.h"
8
9 /* number of slots occupied */
10 #define PVR_YCBCR_SLOTS 9
11
12 struct pvr_ycbcr_csc_table_entry {
13 uint16_t value[32];
14 } PACKED;
15
16 struct pvr_ycbcr_csc_table {
17 struct pvr_ycbcr_csc_table_entry slots[PVR_YCBCR_SLOTS];
18 } PACKED;
19
20 /* clang-format off */
21 static const uint16_t RGB_IDENTITY[] = {
22 0x0000, 0x1ffc, 0x0000,
23 0x0000, 0x0000, 0x1ffc,
24 0x1ffc, 0x0000, 0x0000,
25 0x0000, 0x0000, 0x0000,
26 };
27
28 static const uint16_t YCBCR_IDENTITY_FULL[] = {
29 0x0000, 0x1ffc, 0x0000,
30 0x0000, 0x0000, 0x1ffc,
31 0x1ffc, 0x0000, 0x0000,
32 0xfff0, 0x0000, 0xfff0,
33 };
34
35 static const uint16_t YCBCR_IDENTITY[] = {
36 0x0000, 0x253e, 0x0000,
37 0x0000, 0x0000, 0x2469,
38 0x2469, 0x0000, 0x0000,
39 0xfdb9, 0xfdac, 0xfdb9,
40 };
41
42 static const uint16_t YCBCR_709_FULL[] = {
43 0x1ffc, 0x1ffc, 0x1ffc,
44 0x0000, 0xfa02, 0x3b5a,
45 0x325e, 0xf107, 0x0000,
46 0xe6d1, 0x0a7b, 0xe253,
47 };
48
49 static const uint16_t YCBCR_709[] = {
50 0x253e, 0x253e, 0x253e,
51 0x0000, 0xf92e, 0x4390,
52 0x3957, 0xeef5, 0x0000,
53 0xe101, 0x099b, 0xdbe4,
54 };
55
56 static const uint16_t YCBCR_601_FULL[] = {
57 0x1ffc, 0x1ffc, 0x1ffc,
58 0x0000, 0xf4fe, 0x38ad,
59 0x2cd8, 0xe929, 0x0000,
60 0xe994, 0x10ed, 0xe3a9,
61 };
62
63 static const uint16_t YCBCR_601[] = {
64 0x253e, 0x253e, 0x253e,
65 0x0000, 0xf378, 0x4085,
66 0x330c, 0xe5ff, 0x0000,
67 0xe426, 0x10f0, 0xdd6a,
68 };
69
70 static const uint16_t YCBCR_2020_FULL[] = {
71 0x1ffc, 0x1ffc, 0x1ffc,
72 0x0000, 0xfabd, 0x3c2d,
73 0x2f2a, 0xedba, 0x0000,
74 0xe86b, 0x0bc5, 0xe1ea,
75 };
76
77 static const uint16_t YCBCR_2020[] = {
78 0x253e, 0x253e, 0x253e,
79 0x0000, 0xfa02, 0x4481,
80 0x35b1, 0xeb32, 0x0000,
81 0xe2d4, 0x0b12, 0xdb6c,
82 };
83 /* clang-format on */
84
85 #define fill_slot(table, entry) \
86 memcpy(&table->slots[PVR_YCBCR_SLOT_##entry].value, entry, sizeof(entry))
87
88 void pvr_setup_static_yuv_csc_table(uint8_t *map, uint64_t offset)
89 {
90 struct pvr_ycbcr_csc_table *table =
91 (struct pvr_ycbcr_csc_table *)(&map[offset]);
92 fill_slot(table, RGB_IDENTITY);
93 fill_slot(table, YCBCR_IDENTITY_FULL);
94 fill_slot(table, YCBCR_IDENTITY);
95 fill_slot(table, YCBCR_709_FULL);
96 fill_slot(table, YCBCR_709);
97 fill_slot(table, YCBCR_601_FULL);
98 fill_slot(table, YCBCR_601);
99 fill_slot(table, YCBCR_2020_FULL);
100 fill_slot(table, YCBCR_2020);
101 }