annotate postproc/yuv2rgb.c @ 6451:ed906af317da

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