annotate postproc/yuv2rgb.c @ 5483:d2fbd113008e

global var for option -slices
author arpi
date Thu, 04 Apr 2002 00:00:23 +0000
parents 20806e535b96
children 4b18bf35f153
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"
4285
20806e535b96 add mangling
atmos4
parents: 3143
diff changeset
39 #include "../mangle.h"
2732
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
40
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
41 #ifdef HAVE_MLIB
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
42 #include "yuv2rgb_mlib.c"
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
43 #endif
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
44
3143
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
45 #define DITHER1XBPP // only for mmx
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
46
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
47 #ifdef ARCH_X86
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
48 #define CAN_COMPILE_X86_ASM
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
49 #endif
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
50
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
51 #ifdef CAN_COMPILE_X86_ASM
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
52
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
53 /* hope these constant values are cache line aligned */
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
54 uint64_t __attribute__((aligned(8))) mmx_80w = 0x0080008000800080;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
55 uint64_t __attribute__((aligned(8))) mmx_10w = 0x1010101010101010;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
56 uint64_t __attribute__((aligned(8))) mmx_00ffw = 0x00ff00ff00ff00ff;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
57 uint64_t __attribute__((aligned(8))) mmx_Y_coeff = 0x253f253f253f253f;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
58
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
59 /* hope these constant values are cache line aligned */
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
60 uint64_t __attribute__((aligned(8))) mmx_U_green = 0xf37df37df37df37d;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
61 uint64_t __attribute__((aligned(8))) mmx_U_blue = 0x4093409340934093;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
62 uint64_t __attribute__((aligned(8))) mmx_V_red = 0x3312331233123312;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
63 uint64_t __attribute__((aligned(8))) mmx_V_green = 0xe5fce5fce5fce5fc;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
64
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
65 /* hope these constant values are cache line aligned */
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
66 uint64_t __attribute__((aligned(8))) mmx_redmask = 0xf8f8f8f8f8f8f8f8;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
67 uint64_t __attribute__((aligned(8))) mmx_grnmask = 0xfcfcfcfcfcfcfcfc;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
68
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
69 uint64_t __attribute__((aligned(8))) M24A= 0x00FF0000FF0000FFLL;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
70 uint64_t __attribute__((aligned(8))) M24B= 0xFF0000FF0000FF00LL;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
71 uint64_t __attribute__((aligned(8))) M24C= 0x0000FF0000FF0000LL;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
72
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
73 // the volatile is required because gcc otherwise optimizes some writes away not knowing that these
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
74 // are read in the asm block
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
75 volatile uint64_t __attribute__((aligned(8))) b5Dither;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
76 volatile uint64_t __attribute__((aligned(8))) g5Dither;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
77 volatile uint64_t __attribute__((aligned(8))) g6Dither;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
78 volatile uint64_t __attribute__((aligned(8))) r5Dither;
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
79
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
80 uint64_t __attribute__((aligned(8))) dither4[2]={
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
81 0x0103010301030103LL,
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
82 0x0200020002000200LL,};
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
83
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
84 uint64_t __attribute__((aligned(8))) dither8[2]={
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
85 0x0602060206020602LL,
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
86 0x0004000400040004LL,};
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
87
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
88 #undef HAVE_MMX
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
89 #undef ARCH_X86
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
90
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
91 //MMX versions
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
92 #undef RENAME
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
93 #define HAVE_MMX
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
94 #undef HAVE_MMX2
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
95 #undef HAVE_3DNOW
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
96 #define ARCH_X86
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
97 #define RENAME(a) a ## _MMX
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
98 #include "yuv2rgb_template.c"
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
99
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
100 //MMX2 versions
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
101 #undef RENAME
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
102 #define HAVE_MMX
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
103 #define HAVE_MMX2
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
104 #undef HAVE_3DNOW
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
105 #define ARCH_X86
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
106 #define RENAME(a) a ## _MMX2
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
107 #include "yuv2rgb_template.c"
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
108
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
109 #endif // CAN_COMPILE_X86_ASM
2732
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
110
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
111
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
112 uint32_t matrix_coefficients = 6;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
113
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
114 const int32_t Inverse_Table_6_9[8][4] = {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
115 {117504, 138453, 13954, 34903}, /* no sequence_display_extension */
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
116 {117504, 138453, 13954, 34903}, /* ITU-R Rec. 709 (1990) */
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
117 {104597, 132201, 25675, 53279}, /* unspecified */
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
118 {104597, 132201, 25675, 53279}, /* reserved */
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
119 {104448, 132798, 24759, 53109}, /* FCC */
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
120 {104597, 132201, 25675, 53279}, /* ITU-R Rec. 624-4 System B, G */
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
121 {104597, 132201, 25675, 53279}, /* SMPTE 170M */
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
122 {117579, 136230, 16907, 35559} /* SMPTE 240M (1987) */
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
123 };
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
124
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
125 static void yuv2rgb_c_init (int bpp, int mode);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
126
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
127 yuv2rgb_fun yuv2rgb;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
128
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
129 static void (* yuv2rgb_c_internal) (uint8_t *, uint8_t *,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
130 uint8_t *, uint8_t *,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
131 void *, void *, int);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
132
3143
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
133 static void yuv2rgb_c (void * dst, uint8_t * py,
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
134 uint8_t * pu, uint8_t * pv,
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
135 int h_size, int v_size,
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
136 int rgb_stride, int y_stride, int uv_stride)
2732
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
137 {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
138 v_size >>= 1;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
139
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
140 while (v_size--) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
141 yuv2rgb_c_internal (py, py + y_stride, pu, pv, dst, dst + rgb_stride,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
142 h_size);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
143
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
144 py += 2 * y_stride;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
145 pu += uv_stride;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
146 pv += uv_stride;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
147 dst += 2 * rgb_stride;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
148 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
149 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
150
3143
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
151 void yuv2rgb_init (int bpp, int mode)
2732
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
152 {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
153 yuv2rgb = NULL;
3143
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
154 #ifdef CAN_COMPILE_X86_ASM
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
155 if(gCpuCaps.hasMMX2)
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
156 {
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
157 if (yuv2rgb == NULL /*&& (config.flags & VO_MMX_ENABLE)*/) {
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
158 yuv2rgb = yuv2rgb_init_MMX2 (bpp, mode);
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
159 if (yuv2rgb != NULL)
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
160 printf ("Using MMX2 for colorspace transform\n");
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
161 else
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
162 printf ("Cannot init MMX2 colorspace transform\n");
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
163 }
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
164 }
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
165 else if(gCpuCaps.hasMMX)
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
166 {
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
167 if (yuv2rgb == NULL /*&& (config.flags & VO_MMX_ENABLE)*/) {
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
168 yuv2rgb = yuv2rgb_init_MMX (bpp, mode);
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
169 if (yuv2rgb != NULL)
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
170 printf ("Using MMX for colorspace transform\n");
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
171 else
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
172 printf ("Cannot init MMX colorspace transform\n");
86910f54c391 runtime cpu detection
michael
parents: 2732
diff changeset
173 }
2732
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
174 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
175 #endif
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
176 #ifdef HAVE_MLIB
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
177 if (yuv2rgb == NULL /*&& (config.flags & VO_MLIB_ENABLE)*/) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
178 yuv2rgb = yuv2rgb_init_mlib (bpp, mode);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
179 if (yuv2rgb != NULL)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
180 printf ("Using mlib for colorspace transform\n");
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
181 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
182 #endif
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
183 if (yuv2rgb == NULL) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
184 printf ("No accelerated colorspace conversion found\n");
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
185 yuv2rgb_c_init (bpp, mode);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
186 yuv2rgb = (yuv2rgb_fun)yuv2rgb_c;
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
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
190 void * table_rV[256];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
191 void * table_gU[256];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
192 int table_gV[256];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
193 void * table_bU[256];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
194
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
195 #define RGB(i) \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
196 U = pu[i]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
197 V = pv[i]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
198 r = table_rV[V]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
199 g = table_gU[U] + table_gV[V]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
200 b = table_bU[U];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
201
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
202 #define DST1(i) \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
203 Y = py_1[2*i]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
204 dst_1[2*i] = r[Y] + g[Y] + b[Y]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
205 Y = py_1[2*i+1]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
206 dst_1[2*i+1] = r[Y] + g[Y] + b[Y];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
207
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
208 #define DST2(i) \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
209 Y = py_2[2*i]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
210 dst_2[2*i] = r[Y] + g[Y] + b[Y]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
211 Y = py_2[2*i+1]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
212 dst_2[2*i+1] = r[Y] + g[Y] + b[Y];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
213
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
214 #define DST1RGB(i) \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
215 Y = py_1[2*i]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
216 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
217 Y = py_1[2*i+1]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
218 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
219
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
220 #define DST2RGB(i) \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
221 Y = py_2[2*i]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
222 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
223 Y = py_2[2*i+1]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
224 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
225
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
226 #define DST1BGR(i) \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
227 Y = py_1[2*i]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
228 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
229 Y = py_1[2*i+1]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
230 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
231
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
232 #define DST2BGR(i) \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
233 Y = py_2[2*i]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
234 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
235 Y = py_2[2*i+1]; \
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
236 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
237
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
238 static void yuv2rgb_c_32 (uint8_t * py_1, uint8_t * py_2,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
239 uint8_t * pu, uint8_t * pv,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
240 void * _dst_1, void * _dst_2, int h_size)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
241 {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
242 int U, V, Y;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
243 uint32_t * r, * g, * b;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
244 uint32_t * dst_1, * dst_2;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
245
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
246 h_size >>= 3;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
247 dst_1 = _dst_1;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
248 dst_2 = _dst_2;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
249
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
250 while (h_size--) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
251 RGB(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
252 DST1(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
253 DST2(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
254
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
255 RGB(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
256 DST2(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
257 DST1(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
258
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
259 RGB(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
260 DST1(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
261 DST2(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
262
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
263 RGB(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
264 DST2(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
265 DST1(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
266
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
267 pu += 4;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
268 pv += 4;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
269 py_1 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
270 py_2 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
271 dst_1 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
272 dst_2 += 8;
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
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
276 // This is very near from the yuv2rgb_c_32 code
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
277 static void yuv2rgb_c_24_rgb (uint8_t * py_1, uint8_t * py_2,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
278 uint8_t * pu, uint8_t * pv,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
279 void * _dst_1, void * _dst_2, int h_size)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
280 {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
281 int U, V, Y;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
282 uint8_t * r, * g, * b;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
283 uint8_t * dst_1, * dst_2;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
284
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
285 h_size >>= 3;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
286 dst_1 = _dst_1;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
287 dst_2 = _dst_2;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
288
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
289 while (h_size--) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
290 RGB(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
291 DST1RGB(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
292 DST2RGB(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
293
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
294 RGB(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
295 DST2RGB(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
296 DST1RGB(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
297
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
298 RGB(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
299 DST1RGB(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
300 DST2RGB(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
301
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
302 RGB(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
303 DST2RGB(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
304 DST1RGB(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
305
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
306 pu += 4;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
307 pv += 4;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
308 py_1 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
309 py_2 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
310 dst_1 += 24;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
311 dst_2 += 24;
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
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
315 // only trivial mods from yuv2rgb_c_24_rgb
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
316 static void yuv2rgb_c_24_bgr (uint8_t * py_1, uint8_t * py_2,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
317 uint8_t * pu, uint8_t * pv,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
318 void * _dst_1, void * _dst_2, int h_size)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
319 {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
320 int U, V, Y;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
321 uint8_t * r, * g, * b;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
322 uint8_t * dst_1, * dst_2;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
323
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
324 h_size >>= 3;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
325 dst_1 = _dst_1;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
326 dst_2 = _dst_2;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
327
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
328 while (h_size--) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
329 RGB(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
330 DST1BGR(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
331 DST2BGR(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
332
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
333 RGB(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
334 DST2BGR(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
335 DST1BGR(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
336
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
337 RGB(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
338 DST1BGR(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
339 DST2BGR(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
340
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
341 RGB(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
342 DST2BGR(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
343 DST1BGR(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
344
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
345 pu += 4;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
346 pv += 4;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
347 py_1 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
348 py_2 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
349 dst_1 += 24;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
350 dst_2 += 24;
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
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
354 // This is exactly the same code as yuv2rgb_c_32 except for the types of
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
355 // r, g, b, dst_1, dst_2
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
356 static void yuv2rgb_c_16 (uint8_t * py_1, uint8_t * py_2,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
357 uint8_t * pu, uint8_t * pv,
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
358 void * _dst_1, void * _dst_2, int h_size)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
359 {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
360 int U, V, Y;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
361 uint16_t * r, * g, * b;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
362 uint16_t * dst_1, * dst_2;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
363
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
364 h_size >>= 3;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
365 dst_1 = _dst_1;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
366 dst_2 = _dst_2;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
367
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
368 while (h_size--) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
369 RGB(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
370 DST1(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
371 DST2(0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
372
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
373 RGB(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
374 DST2(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
375 DST1(1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
376
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
377 RGB(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
378 DST1(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
379 DST2(2);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
380
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
381 RGB(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
382 DST2(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
383 DST1(3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
384
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
385 pu += 4;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
386 pv += 4;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
387 py_1 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
388 py_2 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
389 dst_1 += 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
390 dst_2 += 8;
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
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
394 static int div_round (int dividend, int divisor)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
395 {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
396 if (dividend > 0)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
397 return (dividend + (divisor>>1)) / divisor;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
398 else
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
399 return -((-dividend + (divisor>>1)) / divisor);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
400 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
401
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
402 static void yuv2rgb_c_init (int bpp, int mode)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
403 {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
404 int i;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
405 uint8_t table_Y[1024];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
406 uint32_t *table_32 = 0;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
407 uint16_t *table_16 = 0;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
408 uint8_t *table_8 = 0;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
409 uint32_t entry_size = 0;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
410 void *table_r = 0, *table_g = 0, *table_b = 0;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
411
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
412 int crv = Inverse_Table_6_9[matrix_coefficients][0];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
413 int cbu = Inverse_Table_6_9[matrix_coefficients][1];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
414 int cgu = -Inverse_Table_6_9[matrix_coefficients][2];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
415 int cgv = -Inverse_Table_6_9[matrix_coefficients][3];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
416
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
417 for (i = 0; i < 1024; i++) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
418 int j;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
419
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
420 j = (76309 * (i - 384 - 16) + 32768) >> 16;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
421 j = (j < 0) ? 0 : ((j > 255) ? 255 : j);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
422 table_Y[i] = j;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
423 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
424
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
425 switch (bpp) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
426 case 32:
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
427 yuv2rgb_c_internal = yuv2rgb_c_32;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
428
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
429 table_32 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint32_t));
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
430
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
431 entry_size = sizeof (uint32_t);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
432 table_r = table_32 + 197;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
433 table_b = table_32 + 197 + 685;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
434 table_g = table_32 + 197 + 2*682;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
435
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
436 for (i = -197; i < 256+197; i++)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
437 ((uint32_t *)table_r)[i] = table_Y[i+384] << ((mode==MODE_RGB) ? 16 : 0);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
438 for (i = -132; i < 256+132; i++)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
439 ((uint32_t *)table_g)[i] = table_Y[i+384] << 8;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
440 for (i = -232; i < 256+232; i++)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
441 ((uint32_t *)table_b)[i] = table_Y[i+384] << ((mode==MODE_RGB) ? 0 : 16);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
442 break;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
443
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
444 case 24:
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 yuv2rgb_c_internal = (mode!=MODE_RGB) ? yuv2rgb_c_24_rgb : yuv2rgb_c_24_bgr;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
447
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
448 table_8 = malloc ((256 + 2*232) * sizeof (uint8_t));
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
449
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
450 entry_size = sizeof (uint8_t);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
451 table_r = table_g = table_b = table_8 + 232;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
452
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
453 for (i = -232; i < 256+232; i++)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
454 ((uint8_t * )table_b)[i] = table_Y[i+384];
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
455 break;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
456
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
457 case 15:
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
458 case 16:
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
459 yuv2rgb_c_internal = yuv2rgb_c_16;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
460
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
461 table_16 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t));
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
462
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
463 entry_size = sizeof (uint16_t);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
464 table_r = table_16 + 197;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
465 table_b = table_16 + 197 + 685;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
466 table_g = table_16 + 197 + 2*682;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
467
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
468 for (i = -197; i < 256+197; i++) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
469 int j = table_Y[i+384] >> 3;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
470
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
471 if (mode == MODE_RGB)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
472 j <<= ((bpp==16) ? 11 : 10);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
473
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
474 ((uint16_t *)table_r)[i] = j;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
475 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
476 for (i = -132; i < 256+132; i++) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
477 int j = table_Y[i+384] >> ((bpp==16) ? 2 : 3);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
478
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
479 ((uint16_t *)table_g)[i] = j << 5;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
480 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
481 for (i = -232; i < 256+232; i++) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
482 int j = table_Y[i+384] >> 3;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
483
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
484 if (mode == MODE_BGR)
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
485 j <<= ((bpp==16) ? 11 : 10);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
486
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
487 ((uint16_t *)table_b)[i] = j;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
488 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
489 break;
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
490
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
491 default:
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
492 printf ("%ibpp not supported by yuv2rgb\n", bpp);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
493 //exit (1);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
494 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
495
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
496 for (i = 0; i < 256; i++) {
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
497 table_rV[i] = table_r + entry_size * div_round (crv * (i-128), 76309);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
498 table_gU[i] = table_g + entry_size * div_round (cgu * (i-128), 76309);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
499 table_gV[i] = entry_size * div_round (cgv * (i-128), 76309);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
500 table_bU[i] = table_b + entry_size * div_round (cbu * (i-128), 76309);
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
501 }
ae79207a3055 Move yuv2rgb to postprocess
nick
parents:
diff changeset
502 }