1 #include "gfx_conv_c.h"
8 gfx_conv_null(AVFrame
*in
, AVFrame
*out
, int width
, int height
)
10 memcpy(out
->data
[0], in
->data
[0], height
* in
->linesize
[0]);
15 gfx_conv_yuv410p_ycbcr422_c(AVFrame
*in
, AVFrame
*out
, int width
, int height
)
19 unsigned long *po_eol
;
20 register unsigned long *p
;
21 register unsigned long y1
;
22 register unsigned long y2
;
23 register unsigned short u
;
24 register unsigned short v
;
25 register unsigned long a
;
26 register unsigned long b
;
27 register unsigned long c
;
28 register unsigned long d
;
29 // printf("[%ld, %ld, %ld] -> [%ld, %ld, %ld]\n", in->linesize[0],
30 // in->linesize[1], in->linesize[2], out->linesize[0], out->linesize[1],
32 // memcpy(out->data[0], in->data[0], height * in->linesize[0]);
33 unsigned long *po
= (unsigned long *)out
->data
[0];
34 unsigned long *pi
= (unsigned long *)in
->data
[0];
35 unsigned short *pi2
= (unsigned short *)in
->data
[1];
36 unsigned short *pi3
= (unsigned short *)in
->data
[2];
37 for (i
= 0; i
< height
; i
++) {
39 po_eol
= (unsigned long *)(((char *)po
) + out
->linesize
[0]);
41 // *(((long *)po) + j) = (long)(*(pi + j) + (*(pi2 + j) << 8)
42 // + (*(pi + j + 3) << 16) + (*(pi3 + j) << 24));
47 a
= (long)((y1
& 0x0FF) | ((u
& 0x0FF) << 8) | ((y1
& 0x0FF00) << 8)
48 | ((v
& 0x0FF) << 24));
49 b
= (long)(((y1
& 0x0FF0000) >> 16) | ((u
& 0x0FF) << 8)
50 | ((y1
& 0x0FF000000) >> 8) | ((v
& 0x0FF) << 24));
51 c
= (long)((y2
& 0x0FF) | (u
& 0x0FF00) | ((y2
& 0x0FF00) << 8)
52 | ((v
& 0x0FF00) << 16));
53 d
= (long)(((y2
& 0x0FF0000) >> 16) | ((u
& 0x0FF00))
54 | ((y2
& 0x0FF000000) >> 8) | ((v
& 0x0FF00) << 16));
67 po
= (unsigned long *)((char *)po
+ out
->linesize
[0]);
68 pi
= (unsigned long *)(in
->data
[0] + i
* in
->linesize
[0]);
69 pi2
= (unsigned short *)(in
->data
[1] + ((i
+ 2) / 4)
71 pi3
= (unsigned short *)(in
->data
[2] + ((i
+ 3) / 4)
78 gfx_conv_yuv411p_ycbcr422_c(AVFrame
*in
, AVFrame
*out
, int width
, int height
)
80 // this one is for cyuv
81 // TODO: (== yuv410p atm)
82 gfx_conv_yuv410p_ycbcr422_c(in
, out
, width
, height
);
87 gfx_conv_yuv420p_ycbcr422_c(AVFrame
*in
, AVFrame
*out
, int width
, int height
)
89 unsigned long *po_eol
;
90 register unsigned long *p
;
91 register unsigned long y1
;
92 register unsigned long y2
;
93 register unsigned long u
;
94 register unsigned long v
;
95 register unsigned long a
;
96 register unsigned long b
;
97 register unsigned long c
;
98 register unsigned long d
;
99 // printf("[%ld, %ld, %ld] -> [%ld, %ld, %ld]\n", in->linesize[0],
100 // in->linesize[1], in->linesize[2], out->linesize[0], out->linesize[1],
101 // out->linesize[2]);
102 // memcpy(out->data[0], in->data[0], height * in->linesize[0]);
103 unsigned long *po
= (unsigned long *)out
->data
[0];
104 unsigned long *pi
= (unsigned long *)in
->data
[0];
105 unsigned long *pi2
= (unsigned long *)in
->data
[1];
106 unsigned long *pi3
= (unsigned long *)in
->data
[2];
107 for (int i
= 0; i
< height
; i
++) {
108 for (p
= po
, po_eol
= (unsigned long *)(((char *)po
)+out
->linesize
[0]);
110 // *(((long *)po) + j) = (long)(*(pi + j) + (*(pi2 + j) << 8)
111 // + (*(pi + j + 3) << 16) + (*(pi3 + j) << 24));
116 a
= (long)((y1
& 0x0FF) | ((u
& 0x0FF) << 8) | ((y1
& 0x0FF00) << 8)
117 | ((v
& 0x0FF) << 24));
118 b
= (long)(((y1
& 0x0FF0000) >> 16) | ((u
& 0x0FF00))
119 | ((y1
& 0x0FF000000) >> 8) | ((v
& 0x0FF00) << 16));
120 c
= (long)((y2
& 0x0FF) | ((u
& 0x0FF0000) >> 8)
121 | ((y2
& 0x0FF00) << 8) | ((v
& 0x0FF0000) << 8));
122 d
= (long)(((y2
& 0x0FF0000) >> 16) | ((u
& 0x0FF000000) >> 16)
123 | ((y2
& 0x0FF000000) >> 8) | ((v
& 0x0FF000000)));
130 po
= (unsigned long *)((char *)po
+ out
->linesize
[0]);
131 pi
= (unsigned long *)(in
->data
[0] + i
* in
->linesize
[0]);
132 pi2
= (unsigned long *)(in
->data
[1] + ((i
+ 1) / 2) * in
->linesize
[1]);
133 pi3
= (unsigned long *)(in
->data
[2] + (i
/ 2) * in
->linesize
[2]);
138 #define CLIP(a) if (0xffffff00 & (uint32)a) { if (a < 0) a = 0; else a = 255; }
141 YUV10TORGBA8888(uint16 y
, uint16 u
, uint16 v
)
147 int32 r
= (298 * c
+ 409 * e
+ 512) >> 10;
148 int32 g
= (298 * c
- 100 * d
- 208 * e
+ 512) >> 10;
149 int32 b
= (298 * c
+ 516 * d
+ 512) >> 10;
155 return (uint32
)((255 << 24) | (r
<< 16) | (g
<< 8) | b
);
160 gfx_conv_yuv420p10le_rgb32_c(AVFrame
*in
, AVFrame
*out
, int width
, int height
)
162 uint16
*yBase
= (uint16
*)in
->data
[0];
163 uint16
*uBase
= (uint16
*)in
->data
[1];
164 uint16
*vBase
= (uint16
*)in
->data
[2];
166 uint32
*rgbBase
= (uint32
*)out
->data
[0];
170 for (int32 i
= 0; i
< height
; i
++) {
172 for (int32 j
=0; j
< width
; j
+= 2) {
173 rgbBase
[j
] = YUV10TORGBA8888(yBase
[j
], uBase
[uvIndex
],
175 rgbBase
[j
+ 1] = YUV10TORGBA8888(yBase
[j
+ 1], uBase
[uvIndex
],
180 // Advance pointers to next line
181 yBase
+= in
->linesize
[0] / 2;
184 // These are the same for 2 lines
185 uBase
+= in
->linesize
[1] / 2;
186 vBase
+= in
->linesize
[2] / 2;
189 rgbBase
+= out
->linesize
[0] / 4;
194 // http://en.wikipedia.org/wiki/YUV
196 YUV444TORGBA8888(uint8 y
, uint8 u
, uint8 v
)
202 int32 r
= (298 * c
+ 409 * e
+ 128) >> 8;
203 int32 g
= (298 * c
- 100 * d
- 208 * e
+ 128) >> 8;
204 int32 b
= (298 * c
+ 516 * d
+ 128) >> 8;
210 return (uint32
)((255 << 24) | (r
<< 16) | (g
<< 8) | b
);
215 gfx_conv_yuv410p_rgb32_c(AVFrame
*in
, AVFrame
*out
, int width
, int height
)
217 uint8
*yBase
= (uint8
*)in
->data
[0];
218 uint8
*uBase
= (uint8
*)in
->data
[1];
219 uint8
*vBase
= (uint8
*)in
->data
[2];
221 uint32
*rgbBase
= (uint32
*)out
->data
[0];
225 for (int32 i
= 0; i
< height
; i
++) {
227 for (int32 j
=0; j
< width
; j
+=4) {
228 rgbBase
[j
] = YUV444TORGBA8888(yBase
[j
], uBase
[uvIndex
],
230 rgbBase
[j
+ 1] = YUV444TORGBA8888(yBase
[j
+ 1], uBase
[uvIndex
],
232 rgbBase
[j
+ 2] = YUV444TORGBA8888(yBase
[j
+ 2], uBase
[uvIndex
],
234 rgbBase
[j
+ 3] = YUV444TORGBA8888(yBase
[j
+ 3], uBase
[uvIndex
],
239 // Advance pointers to next line
240 yBase
+= in
->linesize
[0];
243 // These are the same for 4 lines
244 uBase
+= in
->linesize
[1];
245 vBase
+= in
->linesize
[2];
248 rgbBase
+= out
->linesize
[0] / 4;
254 gfx_conv_yuv411p_rgb32_c(AVFrame
*in
, AVFrame
*out
, int width
, int height
)
256 gfx_conv_null(in
, out
, width
, height
);
261 gfx_conv_YCbCr422_RGB32_c(AVFrame
*in
, AVFrame
*out
, int width
, int height
)
263 uint8
*yBase
= (uint8
*)in
->data
[0];
264 uint8
*uBase
= (uint8
*)in
->data
[1];
265 uint8
*vBase
= (uint8
*)in
->data
[2];
267 uint32
*rgbBase
= (uint32
*)out
->data
[0];
271 for (int32 i
= 0; i
< height
; i
++) {
275 for (int32 j
= 0; j
< width
; j
+= 2) {
276 rgbBase
[j
] = YUV444TORGBA8888(yBase
[j
], uBase
[uvIndex
],
278 rgbBase
[j
+ 1] = YUV444TORGBA8888(yBase
[j
+ 1], uBase
[uvIndex
],
284 yBase
+= in
->linesize
[0];
285 uBase
+= in
->linesize
[1];
286 vBase
+= in
->linesize
[2];
288 rgbBase
+= out
->linesize
[0] / 4;
292 // XXX special case for last line if height not multiple of 2 goes here
293 memset((height
- 1) * out
->linesize
[0] + (uint8
*)out
->data
[0], 0,
301 gfx_conv_GBRP_RGB32_c(AVFrame
*in
, AVFrame
*out
, int width
, int height
)
303 uint8
*bBase
= (uint8
*)in
->data
[0];
304 uint8
*gBase
= (uint8
*)in
->data
[1];
305 uint8
*rBase
= (uint8
*)in
->data
[2];
307 uint32
*rgbBase
= (uint32
*)out
->data
[0];
309 for (int32 i
= 0; i
< height
; i
++) {
311 for (int32 j
= 0; j
< width
; j
++) {
312 rgbBase
[j
] = gBase
[j
] | (bBase
[j
] << 8) | (rBase
[j
] << 16);
315 bBase
+= in
->linesize
[0];
316 gBase
+= in
->linesize
[1];
317 rBase
+= in
->linesize
[2];
319 rgbBase
+= out
->linesize
[0] / 4;