3 /*#define TARKIN_YUV_EXACT*/
8 uint8_t CLAMP(int16_t x
)
10 return ((x
> 255) ? 255 : (x
< 0) ? 0 : x
);
15 void rgb24_to_yuv (uint8_t *rgb
, Wavelet3DBuf
*yuv
[], uint32_t frame
)
17 int count
= yuv
[0]->width
* yuv
[0]->height
;
18 int16_t *y
= yuv
[0]->data
+ frame
* count
;
19 int16_t *u
= yuv
[1]->data
+ frame
* count
;
20 int16_t *v
= yuv
[2]->data
+ frame
* count
;
23 #if defined(TARKIN_YUV_EXACT)
24 for (i
=0; i
<count
; i
++, rgb
+=3) {
25 y
[i
] = ((int16_t) 77 * rgb
[0] + 150 * rgb
[1] + 29 * rgb
[2]) / 256;
26 u
[i
] = ((int16_t) -44 * rgb
[0] - 87 * rgb
[1] + 131 * rgb
[2]) / 256;
27 v
[i
] = ((int16_t) 131 * rgb
[0] - 110 * rgb
[1] - 21 * rgb
[2]) / 256;
29 #elif defined(TARKIN_YUV_LXY)
30 for (i
=0; i
<count
; i
++, rgb
+=3) {
31 y
[i
] = ((int16_t) 55 * rgb
[0] + 183 * rgb
[1] + 18 * rgb
[2]) / 256;
32 u
[i
] = rgb
[0] - y
[i
];
33 v
[i
] = rgb
[2] - y
[i
];
36 for (i
=0; i
<count
; i
++, rgb
+=3) {
37 v
[i
] = rgb
[0] - rgb
[1];
38 u
[i
] = rgb
[2] - rgb
[1];
39 y
[i
] = rgb
[1] + (u
[i
] + v
[i
]) / 4;
45 void yuv_to_rgb24 (Wavelet3DBuf
*yuv
[], uint8_t *rgb
, uint32_t frame
)
47 int count
= yuv
[0]->width
* yuv
[0]->height
;
48 int16_t *y
= yuv
[0]->data
+ frame
* count
;
49 int16_t *u
= yuv
[1]->data
+ frame
* count
;
50 int16_t *v
= yuv
[2]->data
+ frame
* count
;
53 #if defined(TARKIN_YUV_EXACT)
54 for (i
=0; i
<count
; i
++, rgb
+=3) {
55 rgb
[0] = CLAMP(y
[i
] + 1.371 * v
[i
]);
56 rgb
[1] = CLAMP(y
[i
] - 0.698 * v
[i
] - 0.336 * u
[i
]);
57 rgb
[2] = CLAMP(y
[i
] + 1.732 * u
[i
]);
59 #elif defined(TARKIN_YUV_LXY)
60 for (i
=0; i
<count
; i
++, rgb
+=3) {
61 rgb
[1] = CLAMP(y
[i
] - (77 * u
[i
] + 25 * v
[i
]) / 256);
62 rgb
[0] = CLAMP(y
[i
] + u
[i
]);
63 rgb
[2] = CLAMP(y
[i
] + v
[i
]);
66 for (i
=0; i
<count
; i
++, rgb
+=3) {
67 rgb
[1] = CLAMP(y
[i
] - (u
[i
] + v
[i
]) / 4);
68 rgb
[2] = CLAMP(u
[i
] + rgb
[1]);
69 rgb
[0] = CLAMP(v
[i
] + rgb
[1]);
75 void rgb32_to_yuv (uint8_t *rgb
, Wavelet3DBuf
*yuv
[], uint32_t frame
)
77 int count
= yuv
[0]->width
* yuv
[0]->height
;
78 int16_t *y
= yuv
[0]->data
+ frame
* count
;
79 int16_t *u
= yuv
[1]->data
+ frame
* count
;
80 int16_t *v
= yuv
[2]->data
+ frame
* count
;
83 #if defined(TARKIN_YUV_EXACT)
84 for (i
=0; i
<count
; i
++, rgb
+=4) {
85 y
[i
] = ((int16_t) 77 * rgb
[0] + 150 * rgb
[1] + 29 * rgb
[2]) / 256;
86 u
[i
] = ((int16_t) -44 * rgb
[0] - 87 * rgb
[1] + 131 * rgb
[2]) / 256;
87 v
[i
] = ((int16_t) 131 * rgb
[0] - 110 * rgb
[1] - 21 * rgb
[2]) / 256;
89 #elif defined(TARKIN_YUV_LXY)
90 for (i
=0; i
<count
; i
++, rgb
+=4) {
91 y
[i
] = ((int16_t) 55 * rgb
[0] + 183 * rgb
[1] + 18 * rgb
[2]) / 256;
92 u
[i
] = rgb
[0] - y
[i
];
93 v
[i
] = rgb
[2] - y
[i
];
96 for (i
=0; i
<count
; i
++, rgb
+=4) {
97 v
[i
] = rgb
[0] - rgb
[1];
98 u
[i
] = rgb
[2] - rgb
[1];
99 y
[i
] = rgb
[1] + (u
[i
] + v
[i
]) / 4;
105 void yuv_to_rgb32 (Wavelet3DBuf
*yuv
[], uint8_t *rgb
, uint32_t frame
)
107 int count
= yuv
[0]->width
* yuv
[0]->height
;
108 int16_t *y
= yuv
[0]->data
+ frame
* count
;
109 int16_t *u
= yuv
[1]->data
+ frame
* count
;
110 int16_t *v
= yuv
[2]->data
+ frame
* count
;
113 #if defined(TARKIN_YUV_EXACT)
114 for (i
=0; i
<count
; i
++, rgb
+=4) {
115 rgb
[0] = CLAMP(y
[i
] + 1.371 * v
[i
]);
116 rgb
[1] = CLAMP(y
[i
] - 0.698 * v
[i
] - 0.336 * u
[i
]);
117 rgb
[2] = CLAMP(y
[i
] + 1.732 * u
[i
]);
119 #elif defined(TARKIN_YUV_LXY)
120 for (i
=0; i
<count
; i
++, rgb
+=4) {
121 rgb
[1] = CLAMP(y
[i
] - (77 * u
[i
] + 25 * v
[i
]) / 256);
122 rgb
[0] = CLAMP(y
[i
] + u
[i
]);
123 rgb
[2] = CLAMP(y
[i
] + v
[i
]);
126 for (i
=0; i
<count
; i
++, rgb
+=4) {
127 rgb
[1] = CLAMP(y
[i
] - (u
[i
] + v
[i
]) / 4);
128 rgb
[2] = CLAMP(u
[i
] + rgb
[1]);
129 rgb
[0] = CLAMP(v
[i
] + rgb
[1]);
135 void rgba_to_yuv (uint8_t *rgba
, Wavelet3DBuf
*yuva
[], uint32_t frame
)
137 int count
= yuva
[0]->width
* yuva
[0]->height
;
138 int16_t *y
= yuva
[0]->data
+ frame
* count
;
139 int16_t *u
= yuva
[1]->data
+ frame
* count
;
140 int16_t *v
= yuva
[2]->data
+ frame
* count
;
141 int16_t *a
= yuva
[3]->data
+ frame
* count
;
144 #if defined(TARKIN_YUV_EXACT)
145 for (i
=0; i
<count
; i
++, rgba
+=4) {
146 y
[i
] = ((int16_t) 77 * rgba
[0] + 150 * rgba
[1] + 29 * rgba
[2]) / 256;
147 u
[i
] = ((int16_t) -44 * rgba
[0] - 87 * rgba
[1] + 131 * rgba
[2]) / 256;
148 v
[i
] = ((int16_t) 131 * rgba
[0] - 110 * rgba
[1] - 21 * rgba
[2]) / 256;
151 #elif defined(TARKIN_YUV_LXY)
152 for (i
=0; i
<count
; i
++, rgba
+=4) {
153 y
[i
] = ((int16_t) 55 * rgba
[0] + 183 * rgba
[1] + 18 * rgba
[2]) / 256;
154 u
[i
] = rgba
[0] - y
[i
];
155 v
[i
] = rgba
[2] - y
[i
];
159 for (i
=0; i
<count
; i
++, rgba
+=4) {
160 v
[i
] = rgba
[0] - rgba
[1];
161 u
[i
] = rgba
[2] - rgba
[1];
162 y
[i
] = rgba
[1] + (u
[i
] + v
[i
]) / 4;
169 void yuv_to_rgba (Wavelet3DBuf
*yuva
[], uint8_t *rgba
, uint32_t frame
)
171 int count
= yuva
[0]->width
* yuva
[0]->height
;
172 int16_t *y
= yuva
[0]->data
+ frame
* count
;
173 int16_t *u
= yuva
[1]->data
+ frame
* count
;
174 int16_t *v
= yuva
[2]->data
+ frame
* count
;
175 int16_t *a
= yuva
[3]->data
+ frame
* count
;
178 #if defined(TARKIN_YUV_EXACT)
179 for (i
=0; i
<count
; i
++, rgba
+=4) {
180 rgba
[0] = CLAMP(y
[i
] + 1.371 * v
[i
]);
181 rgba
[1] = CLAMP(y
[i
] - 0.698 * v
[i
] - 0.336 * u
[i
]);
182 rgba
[2] = CLAMP(y
[i
] + 1.732 * u
[i
]);
185 #elif defined(TARKIN_YUV_LXY)
186 for (i
=0; i
<count
; i
++, rgba
+=4) {
187 rgba
[1] = CLAMP(y
[i
] - (77 * u
[i
] + 25 * v
[i
]) / 256);
188 rgba
[0] = CLAMP(y
[i
] + u
[i
]);
189 rgba
[2] = CLAMP(y
[i
] + v
[i
]);
193 for (i
=0; i
<count
; i
++, rgba
+=4) {
194 rgba
[1] = CLAMP(y
[i
] - (u
[i
] + v
[i
]) / 4);
195 rgba
[2] = CLAMP(u
[i
] + rgba
[1]);
196 rgba
[0] = CLAMP(v
[i
] + rgba
[1]);
202 void grayscale_to_y (uint8_t *rgba
, Wavelet3DBuf
*y
[], uint32_t frame
)
204 int count
= y
[0]->width
* y
[0]->height
;
205 int16_t *_y
= y
[0]->data
+ frame
* count
;
208 for (i
=0; i
<count
; i
++)
213 void y_to_grayscale (Wavelet3DBuf
*y
[], uint8_t *rgba
, uint32_t frame
)
215 int count
= y
[0]->width
* y
[0]->height
;
216 int16_t *_y
= y
[0]->data
+ frame
* count
;
219 for (i
=0; i
<count
; i
++)
220 rgba
[i
] = CLAMP(_y
[i
]);