annotate postproc/yuv2rgb.c @ 3451:e972025d1c46

dshow switched to C version
author arpi
date Mon, 10 Dec 2001 22:40:14 +0000
parents 86910f54c391
children 20806e535b96
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2732
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
1 /*
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
2 * yuv2rgb.c, Software YUV to RGB coverter
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
3 *
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
4 * Copyright (C) 1999, Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
5 * All Rights Reserved.
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
6 *
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
7 * Functions broken out from display_x11.c and several new modes
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
8 * added by Håkan Hjort <d95hjort@dtek.chalmers.se>
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
9 *
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
10 * 15 & 16 bpp support by Franck Sicard <Franck.Sicard@solsoft.fr>
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
11 *
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
12 * This file is part of mpeg2dec, a free MPEG-2 video decoder
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
13 *
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
14 * mpeg2dec is free software; you can redistribute it and/or modify
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
15 * it under the terms of the GNU General Public License as published by
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
16 * the Free Software Foundation; either version 2, or (at your option)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
17 * any later version.
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
18 *
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
19 * mpeg2dec is distributed in the hope that it will be useful,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
22 * GNU General Public License for more details.
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
23 *
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
24 * You should have received a copy of the GNU General Public License
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
25 * along with GNU Make; see the file COPYING. If not, write to
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
26 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
27 *
3143
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
28 * MMX/MMX2 Template stuff from Michael Niedermayer (michaelni@gmx.at) (needed for fast movntq support)
2732
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
29 */
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
30
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
31 #include <stdio.h>
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
32 #include <stdlib.h>
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
33 #include <inttypes.h>
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
34
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
35 #include "config.h"
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
36 //#include "video_out.h"
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
37 #include "rgb2rgb.h"
3143
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
38 #include "../cpudetect.h"
2732
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
39
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
40 #ifdef HAVE_MLIB
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
41 #include "yuv2rgb_mlib.c"
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
42 #endif
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
43
3143
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
44 #define DITHER1XBPP // only for mmx
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
45
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
46 #ifdef ARCH_X86
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
47 #define CAN_COMPILE_X86_ASM
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
48 #endif
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
49
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
50 #ifdef CAN_COMPILE_X86_ASM
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
51
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
52 /* hope these constant values are cache line aligned */
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
53 uint64_t __attribute__((aligned(8))) mmx_80w = 0x0080008000800080;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
54 uint64_t __attribute__((aligned(8))) mmx_10w = 0x1010101010101010;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
55 uint64_t __attribute__((aligned(8))) mmx_00ffw = 0x00ff00ff00ff00ff;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
56 uint64_t __attribute__((aligned(8))) mmx_Y_coeff = 0x253f253f253f253f;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
57
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
58 /* hope these constant values are cache line aligned */
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
59 uint64_t __attribute__((aligned(8))) mmx_U_green = 0xf37df37df37df37d;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
60 uint64_t __attribute__((aligned(8))) mmx_U_blue = 0x4093409340934093;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
61 uint64_t __attribute__((aligned(8))) mmx_V_red = 0x3312331233123312;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
62 uint64_t __attribute__((aligned(8))) mmx_V_green = 0xe5fce5fce5fce5fc;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
63
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
64 /* hope these constant values are cache line aligned */
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
65 uint64_t __attribute__((aligned(8))) mmx_redmask = 0xf8f8f8f8f8f8f8f8;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
66 uint64_t __attribute__((aligned(8))) mmx_grnmask = 0xfcfcfcfcfcfcfcfc;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
67
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
68 uint64_t __attribute__((aligned(8))) M24A= 0x00FF0000FF0000FFLL;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
69 uint64_t __attribute__((aligned(8))) M24B= 0xFF0000FF0000FF00LL;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
70 uint64_t __attribute__((aligned(8))) M24C= 0x0000FF0000FF0000LL;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
71
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
72 // the volatile is required because gcc otherwise optimizes some writes away not knowing that these
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
73 // are read in the asm block
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
74 volatile uint64_t __attribute__((aligned(8))) b5Dither;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
75 volatile uint64_t __attribute__((aligned(8))) g5Dither;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
76 volatile uint64_t __attribute__((aligned(8))) g6Dither;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
77 volatile uint64_t __attribute__((aligned(8))) r5Dither;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
78
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
79 uint64_t __attribute__((aligned(8))) dither4[2]={
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
80 0x0103010301030103LL,
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
81 0x0200020002000200LL,};
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
82
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
83 uint64_t __attribute__((aligned(8))) dither8[2]={
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
84 0x0602060206020602LL,
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
85 0x0004000400040004LL,};
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
86
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
87 #undef HAVE_MMX
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
88 #undef ARCH_X86
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
89
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
90 //MMX versions
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
91 #undef RENAME
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
92 #define HAVE_MMX
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
93 #undef HAVE_MMX2
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
94 #undef HAVE_3DNOW
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
95 #define ARCH_X86
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
96 #define RENAME(a) a ## _MMX
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
97 #include "yuv2rgb_template.c"
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
98
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
99 //MMX2 versions
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
100 #undef RENAME
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
101 #define HAVE_MMX
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
102 #define HAVE_MMX2
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
103 #undef HAVE_3DNOW
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
104 #define ARCH_X86
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
105 #define RENAME(a) a ## _MMX2
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
106 #include "yuv2rgb_template.c"
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
107
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
108 #endif // CAN_COMPILE_X86_ASM
2732
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
109
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
110
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
111 uint32_t matrix_coefficients = 6;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
112
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
113 const int32_t Inverse_Table_6_9[8][4] = {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
114 {117504, 138453, 13954, 34903}, /* no sequence_display_extension */
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
115 {117504, 138453, 13954, 34903}, /* ITU-R Rec. 709 (1990) */
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
116 {104597, 132201, 25675, 53279}, /* unspecified */
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
117 {104597, 132201, 25675, 53279}, /* reserved */
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
118 {104448, 132798, 24759, 53109}, /* FCC */
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
119 {104597, 132201, 25675, 53279}, /* ITU-R Rec. 624-4 System B, G */
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
120 {104597, 132201, 25675, 53279}, /* SMPTE 170M */
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
121 {117579, 136230, 16907, 35559} /* SMPTE 240M (1987) */
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
122 };
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
123
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
124 static void yuv2rgb_c_init (int bpp, int mode);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
125
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
126 yuv2rgb_fun yuv2rgb;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
127
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
128 static void (* yuv2rgb_c_internal) (uint8_t *, uint8_t *,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
129 uint8_t *, uint8_t *,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
130 void *, void *, int);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
131
3143
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
132 static void yuv2rgb_c (void * dst, uint8_t * py,
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
133 uint8_t * pu, uint8_t * pv,
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
134 int h_size, int v_size,
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
135 int rgb_stride, int y_stride, int uv_stride)
2732
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
136 {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
137 v_size >>= 1;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
138
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
139 while (v_size--) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
140 yuv2rgb_c_internal (py, py + y_stride, pu, pv, dst, dst + rgb_stride,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
141 h_size);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
142
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
143 py += 2 * y_stride;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
144 pu += uv_stride;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
145 pv += uv_stride;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
146 dst += 2 * rgb_stride;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
147 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
148 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
149
3143
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
150 void yuv2rgb_init (int bpp, int mode)
2732
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
151 {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
152 yuv2rgb = NULL;
3143
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
153 #ifdef CAN_COMPILE_X86_ASM
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
154 if(gCpuCaps.hasMMX2)
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
155 {
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
156 if (yuv2rgb == NULL /*&& (config.flags & VO_MMX_ENABLE)*/) {
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
157 yuv2rgb = yuv2rgb_init_MMX2 (bpp, mode);
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
158 if (yuv2rgb != NULL)
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
159 printf ("Using MMX2 for colorspace transform\n");
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
160 else
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
161 printf ("Cannot init MMX2 colorspace transform\n");
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
162 }
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
163 }
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
164 else if(gCpuCaps.hasMMX)
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
165 {
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
166 if (yuv2rgb == NULL /*&& (config.flags & VO_MMX_ENABLE)*/) {
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
167 yuv2rgb = yuv2rgb_init_MMX (bpp, mode);
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
168 if (yuv2rgb != NULL)
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
169 printf ("Using MMX for colorspace transform\n");
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
170 else
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
171 printf ("Cannot init MMX colorspace transform\n");
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
172 }
2732
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
173 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
174 #endif
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
175 #ifdef HAVE_MLIB
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
176 if (yuv2rgb == NULL /*&& (config.flags & VO_MLIB_ENABLE)*/) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
177 yuv2rgb = yuv2rgb_init_mlib (bpp, mode);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
178 if (yuv2rgb != NULL)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
179 printf ("Using mlib for colorspace transform\n");
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
180 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
181 #endif
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
182 if (yuv2rgb == NULL) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
183 printf ("No accelerated colorspace conversion found\n");
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
184 yuv2rgb_c_init (bpp, mode);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
185 yuv2rgb = (yuv2rgb_fun)yuv2rgb_c;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
186 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
187 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
188
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
189 void * table_rV[256];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
190 void * table_gU[256];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
191 int table_gV[256];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
192 void * table_bU[256];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
193
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
194 #define RGB(i) \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
195 U = pu[i]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
196 V = pv[i]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
197 r = table_rV[V]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
198 g = table_gU[U] + table_gV[V]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
199 b = table_bU[U];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
200
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
201 #define DST1(i) \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
202 Y = py_1[2*i]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
203 dst_1[2*i] = r[Y] + g[Y] + b[Y]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
204 Y = py_1[2*i+1]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
205 dst_1[2*i+1] = r[Y] + g[Y] + b[Y];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
206
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
207 #define DST2(i) \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
208 Y = py_2[2*i]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
209 dst_2[2*i] = r[Y] + g[Y] + b[Y]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
210 Y = py_2[2*i+1]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
211 dst_2[2*i+1] = r[Y] + g[Y] + b[Y];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
212
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
213 #define DST1RGB(i) \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
214 Y = py_1[2*i]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
215 dst_1[6*i] = r[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = b[Y]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
216 Y = py_1[2*i+1]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
217 dst_1[6*i+3] = r[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = b[Y];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
218
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
219 #define DST2RGB(i) \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
220 Y = py_2[2*i]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
221 dst_2[6*i] = r[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = b[Y]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
222 Y = py_2[2*i+1]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
223 dst_2[6*i+3] = r[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = b[Y];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
224
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
225 #define DST1BGR(i) \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
226 Y = py_1[2*i]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
227 dst_1[6*i] = b[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = r[Y]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
228 Y = py_1[2*i+1]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
229 dst_1[6*i+3] = b[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = r[Y];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
230
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
231 #define DST2BGR(i) \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
232 Y = py_2[2*i]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
233 dst_2[6*i] = b[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = r[Y]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
234 Y = py_2[2*i+1]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
235 dst_2[6*i+3] = b[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = r[Y];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
236
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
237 static void yuv2rgb_c_32 (uint8_t * py_1, uint8_t * py_2,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
238 uint8_t * pu, uint8_t * pv,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
239 void * _dst_1, void * _dst_2, int h_size)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
240 {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
241 int U, V, Y;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
242 uint32_t * r, * g, * b;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
243 uint32_t * dst_1, * dst_2;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
244
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
245 h_size >>= 3;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
246 dst_1 = _dst_1;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
247 dst_2 = _dst_2;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
248
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
249 while (h_size--) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
250 RGB(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
251 DST1(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
252 DST2(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
253
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
254 RGB(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
255 DST2(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
256 DST1(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
257
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
258 RGB(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
259 DST1(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
260 DST2(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
261
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
262 RGB(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
263 DST2(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
264 DST1(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
265
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
266 pu += 4;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
267 pv += 4;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
268 py_1 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
269 py_2 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
270 dst_1 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
271 dst_2 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
272 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
273 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
274
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
275 // This is very near from the yuv2rgb_c_32 code
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
276 static void yuv2rgb_c_24_rgb (uint8_t * py_1, uint8_t * py_2,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
277 uint8_t * pu, uint8_t * pv,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
278 void * _dst_1, void * _dst_2, int h_size)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
279 {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
280 int U, V, Y;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
281 uint8_t * r, * g, * b;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
282 uint8_t * dst_1, * dst_2;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
283
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
284 h_size >>= 3;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
285 dst_1 = _dst_1;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
286 dst_2 = _dst_2;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
287
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
288 while (h_size--) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
289 RGB(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
290 DST1RGB(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
291 DST2RGB(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
292
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
293 RGB(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
294 DST2RGB(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
295 DST1RGB(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
296
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
297 RGB(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
298 DST1RGB(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
299 DST2RGB(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
300
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
301 RGB(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
302 DST2RGB(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
303 DST1RGB(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
304
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
305 pu += 4;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
306 pv += 4;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
307 py_1 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
308 py_2 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
309 dst_1 += 24;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
310 dst_2 += 24;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
311 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
312 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
313
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
314 // only trivial mods from yuv2rgb_c_24_rgb
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
315 static void yuv2rgb_c_24_bgr (uint8_t * py_1, uint8_t * py_2,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
316 uint8_t * pu, uint8_t * pv,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
317 void * _dst_1, void * _dst_2, int h_size)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
318 {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
319 int U, V, Y;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
320 uint8_t * r, * g, * b;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
321 uint8_t * dst_1, * dst_2;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
322
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
323 h_size >>= 3;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
324 dst_1 = _dst_1;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
325 dst_2 = _dst_2;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
326
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
327 while (h_size--) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
328 RGB(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
329 DST1BGR(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
330 DST2BGR(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
331
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
332 RGB(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
333 DST2BGR(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
334 DST1BGR(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
335
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
336 RGB(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
337 DST1BGR(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
338 DST2BGR(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
339
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
340 RGB(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
341 DST2BGR(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
342 DST1BGR(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
343
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
344 pu += 4;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
345 pv += 4;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
346 py_1 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
347 py_2 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
348 dst_1 += 24;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
349 dst_2 += 24;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
350 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
351 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
352
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
353 // This is exactly the same code as yuv2rgb_c_32 except for the types of
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
354 // r, g, b, dst_1, dst_2
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
355 static void yuv2rgb_c_16 (uint8_t * py_1, uint8_t * py_2,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
356 uint8_t * pu, uint8_t * pv,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
357 void * _dst_1, void * _dst_2, int h_size)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
358 {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
359 int U, V, Y;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
360 uint16_t * r, * g, * b;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
361 uint16_t * dst_1, * dst_2;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
362
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
363 h_size >>= 3;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
364 dst_1 = _dst_1;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
365 dst_2 = _dst_2;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
366
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
367 while (h_size--) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
368 RGB(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
369 DST1(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
370 DST2(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
371
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
372 RGB(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
373 DST2(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
374 DST1(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
375
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
376 RGB(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
377 DST1(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
378 DST2(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
379
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
380 RGB(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
381 DST2(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
382 DST1(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
383
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
384 pu += 4;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
385 pv += 4;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
386 py_1 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
387 py_2 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
388 dst_1 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
389 dst_2 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
390 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
391 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
392
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
393 static int div_round (int dividend, int divisor)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
394 {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
395 if (dividend > 0)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
396 return (dividend + (divisor>>1)) / divisor;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
397 else
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
398 return -((-dividend + (divisor>>1)) / divisor);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
399 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
400
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
401 static void yuv2rgb_c_init (int bpp, int mode)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
402 {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
403 int i;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
404 uint8_t table_Y[1024];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
405 uint32_t *table_32 = 0;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
406 uint16_t *table_16 = 0;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
407 uint8_t *table_8 = 0;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
408 uint32_t entry_size = 0;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
409 void *table_r = 0, *table_g = 0, *table_b = 0;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
410
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
411 int crv = Inverse_Table_6_9[matrix_coefficients][0];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
412 int cbu = Inverse_Table_6_9[matrix_coefficients][1];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
413 int cgu = -Inverse_Table_6_9[matrix_coefficients][2];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
414 int cgv = -Inverse_Table_6_9[matrix_coefficients][3];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
415
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
416 for (i = 0; i < 1024; i++) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
417 int j;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
418
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
419 j = (76309 * (i - 384 - 16) + 32768) >> 16;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
420 j = (j < 0) ? 0 : ((j > 255) ? 255 : j);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
421 table_Y[i] = j;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
422 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
423
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
424 switch (bpp) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
425 case 32:
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
426 yuv2rgb_c_internal = yuv2rgb_c_32;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
427
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
428 table_32 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint32_t));
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
429
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
430 entry_size = sizeof (uint32_t);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
431 table_r = table_32 + 197;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
432 table_b = table_32 + 197 + 685;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
433 table_g = table_32 + 197 + 2*682;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
434
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
435 for (i = -197; i < 256+197; i++)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
436 ((uint32_t *)table_r)[i] = table_Y[i+384] << ((mode==MODE_RGB) ? 16 : 0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
437 for (i = -132; i < 256+132; i++)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
438 ((uint32_t *)table_g)[i] = table_Y[i+384] << 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
439 for (i = -232; i < 256+232; i++)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
440 ((uint32_t *)table_b)[i] = table_Y[i+384] << ((mode==MODE_RGB) ? 0 : 16);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
441 break;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
442
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
443 case 24:
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
444 // yuv2rgb_c_internal = (mode==MODE_RGB) ? yuv2rgb_c_24_rgb : yuv2rgb_c_24_bgr;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
445 yuv2rgb_c_internal = (mode!=MODE_RGB) ? yuv2rgb_c_24_rgb : yuv2rgb_c_24_bgr;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
446
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
447 table_8 = malloc ((256 + 2*232) * sizeof (uint8_t));
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
448
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
449 entry_size = sizeof (uint8_t);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
450 table_r = table_g = table_b = table_8 + 232;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
451
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
452 for (i = -232; i < 256+232; i++)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
453 ((uint8_t * )table_b)[i] = table_Y[i+384];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
454 break;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
455
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
456 case 15:
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
457 case 16:
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
458 yuv2rgb_c_internal = yuv2rgb_c_16;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
459
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
460 table_16 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t));
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
461
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
462 entry_size = sizeof (uint16_t);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
463 table_r = table_16 + 197;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
464 table_b = table_16 + 197 + 685;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
465 table_g = table_16 + 197 + 2*682;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
466
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
467 for (i = -197; i < 256+197; i++) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
468 int j = table_Y[i+384] >> 3;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
469
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
470 if (mode == MODE_RGB)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
471 j <<= ((bpp==16) ? 11 : 10);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
472
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
473 ((uint16_t *)table_r)[i] = j;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
474 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
475 for (i = -132; i < 256+132; i++) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
476 int j = table_Y[i+384] >> ((bpp==16) ? 2 : 3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
477
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
478 ((uint16_t *)table_g)[i] = j << 5;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
479 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
480 for (i = -232; i < 256+232; i++) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
481 int j = table_Y[i+384] >> 3;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
482
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
483 if (mode == MODE_BGR)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
484 j <<= ((bpp==16) ? 11 : 10);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
485
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
486 ((uint16_t *)table_b)[i] = j;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
487 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
488 break;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
489
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
490 default:
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
491 printf ("%ibpp not supported by yuv2rgb\n", bpp);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
492 //exit (1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
493 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
494
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
495 for (i = 0; i < 256; i++) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
496 table_rV[i] = table_r + entry_size * div_round (crv * (i-128), 76309);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
497 table_gU[i] = table_g + entry_size * div_round (cgu * (i-128), 76309);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
498 table_gV[i] = entry_size * div_round (cgv * (i-128), 76309);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
499 table_bU[i] = table_b + entry_size * div_round (cbu * (i-128), 76309);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
500 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
501 }