Fix oggplay-dump-first-frame
[liboggplay.git] / src / liboggplay / oggplay_yuv2rgb_template.h
blobc32e7035d80e3267794465a2d2b004f97a7c23cb
1 #ifndef __OGGPLAY_YUV2RGB_TEMPLATE_H__
2 #define __OGGPLAY_YUV2RGB_TEMPLATE_H__
4 #if defined(WIN32)
5 #define restrict
6 #else
7 #ifndef restrict
8 #define restrict __restrict__
9 #endif
10 #endif
12 /**
13 * Template for YUV to RGB conversion
15 * @param FUNC function name
16 * @param CONVERT a macro that defines the actual conversion function
17 * @param VANILLA_OUT
18 * @param NUM_PIXELS number of pixels processed in one iteration
19 * @param OUT_SHIFT number of pixels to shift after one iteration in rgb data stream
20 * @param Y_SHIFT number of pixels to shift after one iteration in Y data stream
21 * @param UV_SHIFT
22 * @param UV_VERT_SUB
24 #define YUV_CONVERT(FUNC, CONVERT, VANILLA_OUT, NUM_PIXELS, OUT_SHIFT, Y_SHIFT, UV_SHIFT, UV_VERT_SUB)\
25 static void \
26 (FUNC)(const OggPlayYUVChannels* yuv, OggPlayRGBChannels* rgb) \
27 { \
28 int i,j, w, h, r; \
29 unsigned char* restrict ptry; \
30 unsigned char* restrict ptru; \
31 unsigned char* restrict ptrv; \
32 unsigned char* restrict ptro; \
33 unsigned char *dst, *py, *pu, *pv; \
35 ptro = rgb->ptro; \
36 ptry = yuv->ptry; \
37 ptru = yuv->ptru; \
38 ptrv = yuv->ptrv; \
40 w = yuv->y_width / NUM_PIXELS; \
41 h = yuv->y_height; \
42 r = yuv->y_width % NUM_PIXELS; \
43 for (i = 0; i < h; ++i) \
44 { \
45 py = ptry; \
46 pu = ptru; \
47 pv = ptrv; \
48 dst = ptro; \
49 for (j = 0; j < w; ++j, \
50 dst += OUT_SHIFT, \
51 py += Y_SHIFT, \
52 pu += UV_SHIFT, \
53 pv += UV_SHIFT) \
54 { \
55 /* use the given conversion function */ \
56 CONVERT \
57 } \
58 /* \
59 * the video frame is not the multiple of NUM_PIXELS, \
60 * thus we have to deal with remaning pixels using \
61 * vanilla implementation. \
62 */ \
63 if (r) { \
64 if (r==1 && yuv->y_width&1) { \
65 pu -= 1; pv -= 1; \
66 } \
68 for \
69 ( \
70 j=(yuv->y_width-r); j < yuv->y_width; \
71 ++j, \
72 dst += 4, \
73 py += 1 \
74 ) \
75 { \
76 LOOKUP_COEFFS \
77 VANILLA_YUV2RGB_PIXEL(py[0], ruv, guv, buv) \
78 VANILLA_OUT(dst, r, g, b) \
79 if \
80 ( \
81 (j%2 && !(j+1==yuv->y_width-1 && yuv->y_width&1)) \
82 || \
83 UV_VERT_SUB==1 \
84 ) { \
85 pu += 1; pv += 1; \
86 } \
87 } \
88 } \
90 ptro += rgb->rgb_width * 4; \
91 ptry += yuv->y_width; \
93 if \
94 ( \
95 (i & 0x1 && !(i+1==h-1 && h&1)) \
96 || \
97 UV_VERT_SUB==1 \
98 ) \
99 { \
100 ptru += yuv->uv_width; \
101 ptrv += yuv->uv_width; \
104 CLEANUP \
107 #endif