Mercurial > mplayer.hg
annotate postproc/yuv2rgb.c @ 6548:e56e991d2ee7
EvEqualeaser --> EvEqualizer, since Atmos just committed my typo fix.
author | diego |
---|---|
date | Mon, 24 Jun 2002 11:07:50 +0000 |
parents | e7635c03910f |
children | aad616b63bed |
rev | line source |
---|---|
2732 | 1 /* |
2 * yuv2rgb.c, Software YUV to RGB coverter | |
3 * | |
4 * Copyright (C) 1999, Aaron Holtzman <aholtzma@ess.engr.uvic.ca> | |
5 * All Rights Reserved. | |
6 * | |
7 * Functions broken out from display_x11.c and several new modes | |
8 * added by Håkan Hjort <d95hjort@dtek.chalmers.se> | |
9 * | |
10 * 15 & 16 bpp support by Franck Sicard <Franck.Sicard@solsoft.fr> | |
11 * | |
12 * This file is part of mpeg2dec, a free MPEG-2 video decoder | |
13 * | |
14 * mpeg2dec is free software; you can redistribute it and/or modify | |
15 * it under the terms of the GNU General Public License as published by | |
16 * the Free Software Foundation; either version 2, or (at your option) | |
17 * any later version. | |
18 * | |
19 * mpeg2dec is distributed in the hope that it will be useful, | |
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 * GNU General Public License for more details. | |
23 * | |
24 * You should have received a copy of the GNU General Public License | |
25 * along with GNU Make; see the file COPYING. If not, write to | |
26 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
27 * | |
3143 | 28 * MMX/MMX2 Template stuff from Michael Niedermayer (michaelni@gmx.at) (needed for fast movntq support) |
6456 | 29 * 1,4,8bpp support by Michael Niedermayer (michaelni@gmx.at) |
2732 | 30 */ |
31 | |
32 #include <stdio.h> | |
33 #include <stdlib.h> | |
34 #include <inttypes.h> | |
35 | |
36 #include "config.h" | |
37 //#include "video_out.h" | |
38 #include "rgb2rgb.h" | |
3143 | 39 #include "../cpudetect.h" |
4285 | 40 #include "../mangle.h" |
5937 | 41 #include "../mp_msg.h" |
2732 | 42 |
43 #ifdef HAVE_MLIB | |
44 #include "yuv2rgb_mlib.c" | |
45 #endif | |
46 | |
3143 | 47 #define DITHER1XBPP // only for mmx |
48 | |
49 #ifdef ARCH_X86 | |
50 #define CAN_COMPILE_X86_ASM | |
51 #endif | |
52 | |
6458 | 53 uint8_t __attribute__((aligned(8))) dither_8x8_32[8][8]={ |
54 { 17, 9, 23, 15, 16, 8, 22, 14, }, | |
55 { 5, 29, 3, 27, 4, 28, 2, 26, }, | |
56 { 21, 13, 19, 11, 20, 12, 18, 10, }, | |
57 { 0, 24, 6, 30, 1, 25, 7, 31, }, | |
58 { 16, 8, 22, 14, 17, 9, 23, 15, }, | |
59 { 4, 28, 2, 26, 5, 29, 3, 27, }, | |
60 { 20, 12, 18, 10, 21, 13, 19, 11, }, | |
61 { 1, 25, 7, 31, 0, 24, 6, 30, }, | |
62 }; | |
63 | |
64 uint8_t __attribute__((aligned(8))) dither_8x8_64[8][8]={ | |
65 { 0, 48, 12, 60, 3, 51, 15, 63, }, | |
66 { 32, 16, 44, 28, 35, 19, 47, 31, }, | |
67 { 8, 56, 4, 52, 11, 59, 7, 55, }, | |
68 { 40, 24, 36, 20, 43, 27, 39, 23, }, | |
69 { 2, 50, 14, 62, 1, 49, 13, 61, }, | |
70 { 34, 18, 46, 30, 33, 17, 45, 29, }, | |
71 { 10, 58, 6, 54, 9, 57, 5, 53, }, | |
72 { 42, 26, 38, 22, 41, 25, 37, 21, }, | |
73 }; | |
74 | |
75 uint8_t __attribute__((aligned(8))) dither_8x8_128[8][8]={ | |
76 { 68, 36, 92, 60, 66, 34, 90, 58, }, | |
77 { 20, 116, 12, 108, 18, 114, 10, 106, }, | |
78 { 84, 52, 76, 44, 82, 50, 74, 42, }, | |
79 { 0, 96, 24, 120, 6, 102, 30, 126, }, | |
80 { 64, 32, 88, 56, 70, 38, 94, 62, }, | |
81 { 16, 112, 8, 104, 22, 118, 14, 110, }, | |
82 { 80, 48, 72, 40, 86, 54, 78, 46, }, | |
83 { 4, 100, 28, 124, 2, 98, 26, 122, }, | |
84 }; | |
85 | |
3143 | 86 #ifdef CAN_COMPILE_X86_ASM |
87 | |
88 /* hope these constant values are cache line aligned */ | |
89 uint64_t __attribute__((aligned(8))) mmx_80w = 0x0080008000800080; | |
90 uint64_t __attribute__((aligned(8))) mmx_10w = 0x1010101010101010; | |
91 uint64_t __attribute__((aligned(8))) mmx_00ffw = 0x00ff00ff00ff00ff; | |
92 uint64_t __attribute__((aligned(8))) mmx_Y_coeff = 0x253f253f253f253f; | |
93 | |
94 /* hope these constant values are cache line aligned */ | |
95 uint64_t __attribute__((aligned(8))) mmx_U_green = 0xf37df37df37df37d; | |
96 uint64_t __attribute__((aligned(8))) mmx_U_blue = 0x4093409340934093; | |
97 uint64_t __attribute__((aligned(8))) mmx_V_red = 0x3312331233123312; | |
98 uint64_t __attribute__((aligned(8))) mmx_V_green = 0xe5fce5fce5fce5fc; | |
99 | |
100 /* hope these constant values are cache line aligned */ | |
101 uint64_t __attribute__((aligned(8))) mmx_redmask = 0xf8f8f8f8f8f8f8f8; | |
102 uint64_t __attribute__((aligned(8))) mmx_grnmask = 0xfcfcfcfcfcfcfcfc; | |
103 | |
104 uint64_t __attribute__((aligned(8))) M24A= 0x00FF0000FF0000FFLL; | |
105 uint64_t __attribute__((aligned(8))) M24B= 0xFF0000FF0000FF00LL; | |
106 uint64_t __attribute__((aligned(8))) M24C= 0x0000FF0000FF0000LL; | |
107 | |
108 // the volatile is required because gcc otherwise optimizes some writes away not knowing that these | |
109 // are read in the asm block | |
110 volatile uint64_t __attribute__((aligned(8))) b5Dither; | |
111 volatile uint64_t __attribute__((aligned(8))) g5Dither; | |
112 volatile uint64_t __attribute__((aligned(8))) g6Dither; | |
113 volatile uint64_t __attribute__((aligned(8))) r5Dither; | |
114 | |
115 uint64_t __attribute__((aligned(8))) dither4[2]={ | |
116 0x0103010301030103LL, | |
117 0x0200020002000200LL,}; | |
118 | |
119 uint64_t __attribute__((aligned(8))) dither8[2]={ | |
120 0x0602060206020602LL, | |
121 0x0004000400040004LL,}; | |
122 | |
123 #undef HAVE_MMX | |
124 #undef ARCH_X86 | |
125 | |
126 //MMX versions | |
127 #undef RENAME | |
128 #define HAVE_MMX | |
129 #undef HAVE_MMX2 | |
130 #undef HAVE_3DNOW | |
131 #define ARCH_X86 | |
132 #define RENAME(a) a ## _MMX | |
133 #include "yuv2rgb_template.c" | |
134 | |
135 //MMX2 versions | |
136 #undef RENAME | |
137 #define HAVE_MMX | |
138 #define HAVE_MMX2 | |
139 #undef HAVE_3DNOW | |
140 #define ARCH_X86 | |
141 #define RENAME(a) a ## _MMX2 | |
142 #include "yuv2rgb_template.c" | |
143 | |
144 #endif // CAN_COMPILE_X86_ASM | |
2732 | 145 |
146 uint32_t matrix_coefficients = 6; | |
147 | |
148 const int32_t Inverse_Table_6_9[8][4] = { | |
149 {117504, 138453, 13954, 34903}, /* no sequence_display_extension */ | |
150 {117504, 138453, 13954, 34903}, /* ITU-R Rec. 709 (1990) */ | |
151 {104597, 132201, 25675, 53279}, /* unspecified */ | |
152 {104597, 132201, 25675, 53279}, /* reserved */ | |
153 {104448, 132798, 24759, 53109}, /* FCC */ | |
154 {104597, 132201, 25675, 53279}, /* ITU-R Rec. 624-4 System B, G */ | |
155 {104597, 132201, 25675, 53279}, /* SMPTE 170M */ | |
156 {117579, 136230, 16907, 35559} /* SMPTE 240M (1987) */ | |
157 }; | |
158 | |
6492 | 159 static void yuv2rgb_c_init (unsigned bpp, int mode); |
2732 | 160 |
161 yuv2rgb_fun yuv2rgb; | |
162 | |
163 static void (* yuv2rgb_c_internal) (uint8_t *, uint8_t *, | |
164 uint8_t *, uint8_t *, | |
6452 | 165 void *, void *, int, int); |
2732 | 166 |
3143 | 167 static void yuv2rgb_c (void * dst, uint8_t * py, |
168 uint8_t * pu, uint8_t * pv, | |
6492 | 169 unsigned h_size, unsigned v_size, |
170 unsigned rgb_stride, unsigned y_stride, unsigned uv_stride) | |
2732 | 171 { |
172 v_size >>= 1; | |
6492 | 173 |
2732 | 174 while (v_size--) { |
175 yuv2rgb_c_internal (py, py + y_stride, pu, pv, dst, dst + rgb_stride, | |
6452 | 176 h_size, v_size<<1); |
2732 | 177 |
178 py += 2 * y_stride; | |
179 pu += uv_stride; | |
180 pv += uv_stride; | |
181 dst += 2 * rgb_stride; | |
182 } | |
183 } | |
184 | |
6492 | 185 void yuv2rgb_init (unsigned bpp, int mode) |
2732 | 186 { |
187 yuv2rgb = NULL; | |
3143 | 188 #ifdef CAN_COMPILE_X86_ASM |
189 if(gCpuCaps.hasMMX2) | |
190 { | |
191 if (yuv2rgb == NULL /*&& (config.flags & VO_MMX_ENABLE)*/) { | |
192 yuv2rgb = yuv2rgb_init_MMX2 (bpp, mode); | |
193 if (yuv2rgb != NULL) | |
5937 | 194 mp_msg(MSGT_SWS,MSGL_INFO,"Using MMX2 for colorspace transform\n"); |
3143 | 195 else |
5937 | 196 mp_msg(MSGT_SWS,MSGL_WARN,"Cannot init MMX2 colorspace transform\n"); |
3143 | 197 } |
198 } | |
199 else if(gCpuCaps.hasMMX) | |
200 { | |
201 if (yuv2rgb == NULL /*&& (config.flags & VO_MMX_ENABLE)*/) { | |
202 yuv2rgb = yuv2rgb_init_MMX (bpp, mode); | |
203 if (yuv2rgb != NULL) | |
5937 | 204 mp_msg(MSGT_SWS,MSGL_INFO,"Using MMX for colorspace transform\n"); |
3143 | 205 else |
5937 | 206 mp_msg(MSGT_SWS,MSGL_WARN,"Cannot init MMX colorspace transform\n"); |
3143 | 207 } |
2732 | 208 } |
209 #endif | |
210 #ifdef HAVE_MLIB | |
211 if (yuv2rgb == NULL /*&& (config.flags & VO_MLIB_ENABLE)*/) { | |
212 yuv2rgb = yuv2rgb_init_mlib (bpp, mode); | |
213 if (yuv2rgb != NULL) | |
5937 | 214 mp_msg(MSGT_SWS,MSGL_INFO,"Using mlib for colorspace transform\n"); |
2732 | 215 } |
216 #endif | |
217 if (yuv2rgb == NULL) { | |
5937 | 218 mp_msg(MSGT_SWS,MSGL_INFO,"No accelerated colorspace conversion found\n"); |
2732 | 219 yuv2rgb_c_init (bpp, mode); |
220 yuv2rgb = (yuv2rgb_fun)yuv2rgb_c; | |
221 } | |
222 } | |
223 | |
224 void * table_rV[256]; | |
225 void * table_gU[256]; | |
226 int table_gV[256]; | |
227 void * table_bU[256]; | |
228 | |
229 #define RGB(i) \ | |
230 U = pu[i]; \ | |
231 V = pv[i]; \ | |
232 r = table_rV[V]; \ | |
233 g = table_gU[U] + table_gV[V]; \ | |
234 b = table_bU[U]; | |
235 | |
236 #define DST1(i) \ | |
237 Y = py_1[2*i]; \ | |
238 dst_1[2*i] = r[Y] + g[Y] + b[Y]; \ | |
239 Y = py_1[2*i+1]; \ | |
240 dst_1[2*i+1] = r[Y] + g[Y] + b[Y]; | |
241 | |
242 #define DST2(i) \ | |
243 Y = py_2[2*i]; \ | |
244 dst_2[2*i] = r[Y] + g[Y] + b[Y]; \ | |
245 Y = py_2[2*i+1]; \ | |
246 dst_2[2*i+1] = r[Y] + g[Y] + b[Y]; | |
247 | |
248 #define DST1RGB(i) \ | |
249 Y = py_1[2*i]; \ | |
250 dst_1[6*i] = r[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = b[Y]; \ | |
251 Y = py_1[2*i+1]; \ | |
252 dst_1[6*i+3] = r[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = b[Y]; | |
253 | |
254 #define DST2RGB(i) \ | |
255 Y = py_2[2*i]; \ | |
256 dst_2[6*i] = r[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = b[Y]; \ | |
257 Y = py_2[2*i+1]; \ | |
258 dst_2[6*i+3] = r[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = b[Y]; | |
259 | |
260 #define DST1BGR(i) \ | |
261 Y = py_1[2*i]; \ | |
262 dst_1[6*i] = b[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = r[Y]; \ | |
263 Y = py_1[2*i+1]; \ | |
264 dst_1[6*i+3] = b[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = r[Y]; | |
265 | |
266 #define DST2BGR(i) \ | |
267 Y = py_2[2*i]; \ | |
268 dst_2[6*i] = b[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = r[Y]; \ | |
269 Y = py_2[2*i+1]; \ | |
270 dst_2[6*i+3] = b[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = r[Y]; | |
271 | |
272 static void yuv2rgb_c_32 (uint8_t * py_1, uint8_t * py_2, | |
273 uint8_t * pu, uint8_t * pv, | |
6452 | 274 void * _dst_1, void * _dst_2, int h_size, int v_pos) |
2732 | 275 { |
276 int U, V, Y; | |
277 uint32_t * r, * g, * b; | |
278 uint32_t * dst_1, * dst_2; | |
279 | |
280 h_size >>= 3; | |
281 dst_1 = _dst_1; | |
282 dst_2 = _dst_2; | |
283 | |
284 while (h_size--) { | |
285 RGB(0); | |
286 DST1(0); | |
287 DST2(0); | |
288 | |
289 RGB(1); | |
290 DST2(1); | |
291 DST1(1); | |
292 | |
293 RGB(2); | |
294 DST1(2); | |
295 DST2(2); | |
296 | |
297 RGB(3); | |
298 DST2(3); | |
299 DST1(3); | |
300 | |
301 pu += 4; | |
302 pv += 4; | |
303 py_1 += 8; | |
304 py_2 += 8; | |
305 dst_1 += 8; | |
306 dst_2 += 8; | |
307 } | |
308 } | |
309 | |
310 // This is very near from the yuv2rgb_c_32 code | |
311 static void yuv2rgb_c_24_rgb (uint8_t * py_1, uint8_t * py_2, | |
312 uint8_t * pu, uint8_t * pv, | |
6452 | 313 void * _dst_1, void * _dst_2, int h_size, int v_pos) |
2732 | 314 { |
315 int U, V, Y; | |
316 uint8_t * r, * g, * b; | |
317 uint8_t * dst_1, * dst_2; | |
318 | |
319 h_size >>= 3; | |
320 dst_1 = _dst_1; | |
321 dst_2 = _dst_2; | |
322 | |
323 while (h_size--) { | |
324 RGB(0); | |
325 DST1RGB(0); | |
326 DST2RGB(0); | |
327 | |
328 RGB(1); | |
329 DST2RGB(1); | |
330 DST1RGB(1); | |
331 | |
332 RGB(2); | |
333 DST1RGB(2); | |
334 DST2RGB(2); | |
335 | |
336 RGB(3); | |
337 DST2RGB(3); | |
338 DST1RGB(3); | |
339 | |
340 pu += 4; | |
341 pv += 4; | |
342 py_1 += 8; | |
343 py_2 += 8; | |
344 dst_1 += 24; | |
345 dst_2 += 24; | |
346 } | |
347 } | |
348 | |
349 // only trivial mods from yuv2rgb_c_24_rgb | |
350 static void yuv2rgb_c_24_bgr (uint8_t * py_1, uint8_t * py_2, | |
351 uint8_t * pu, uint8_t * pv, | |
6452 | 352 void * _dst_1, void * _dst_2, int h_size, int v_pos) |
2732 | 353 { |
354 int U, V, Y; | |
355 uint8_t * r, * g, * b; | |
356 uint8_t * dst_1, * dst_2; | |
357 | |
358 h_size >>= 3; | |
359 dst_1 = _dst_1; | |
360 dst_2 = _dst_2; | |
361 | |
362 while (h_size--) { | |
363 RGB(0); | |
364 DST1BGR(0); | |
365 DST2BGR(0); | |
366 | |
367 RGB(1); | |
368 DST2BGR(1); | |
369 DST1BGR(1); | |
370 | |
371 RGB(2); | |
372 DST1BGR(2); | |
373 DST2BGR(2); | |
374 | |
375 RGB(3); | |
376 DST2BGR(3); | |
377 DST1BGR(3); | |
378 | |
379 pu += 4; | |
380 pv += 4; | |
381 py_1 += 8; | |
382 py_2 += 8; | |
383 dst_1 += 24; | |
384 dst_2 += 24; | |
385 } | |
386 } | |
387 | |
388 // This is exactly the same code as yuv2rgb_c_32 except for the types of | |
389 // r, g, b, dst_1, dst_2 | |
390 static void yuv2rgb_c_16 (uint8_t * py_1, uint8_t * py_2, | |
391 uint8_t * pu, uint8_t * pv, | |
6452 | 392 void * _dst_1, void * _dst_2, int h_size, int v_pos) |
2732 | 393 { |
394 int U, V, Y; | |
395 uint16_t * r, * g, * b; | |
396 uint16_t * dst_1, * dst_2; | |
397 | |
398 h_size >>= 3; | |
399 dst_1 = _dst_1; | |
400 dst_2 = _dst_2; | |
401 | |
402 while (h_size--) { | |
403 RGB(0); | |
404 DST1(0); | |
405 DST2(0); | |
406 | |
407 RGB(1); | |
408 DST2(1); | |
409 DST1(1); | |
410 | |
411 RGB(2); | |
412 DST1(2); | |
413 DST2(2); | |
414 | |
415 RGB(3); | |
416 DST2(3); | |
417 DST1(3); | |
418 | |
419 pu += 4; | |
420 pv += 4; | |
421 py_1 += 8; | |
422 py_2 += 8; | |
423 dst_1 += 8; | |
424 dst_2 += 8; | |
425 } | |
426 } | |
427 | |
6451
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
428 // 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
|
429 // r, g, b, dst_1, dst_2 |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
430 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
|
431 uint8_t * pu, uint8_t * pv, |
6452 | 432 void * _dst_1, void * _dst_2, int h_size, int v_pos) |
6451
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 int U, V, Y; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
435 uint8_t * r, * g, * b; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
436 uint8_t * dst_1, * dst_2; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
437 |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
438 h_size >>= 3; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
439 dst_1 = _dst_1; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
440 dst_2 = _dst_2; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
441 |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
442 while (h_size--) { |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
443 RGB(0); |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
444 DST1(0); |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
445 DST2(0); |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
446 |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
447 RGB(1); |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
448 DST2(1); |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
449 DST1(1); |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
450 |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
451 RGB(2); |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
452 DST1(2); |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
453 DST2(2); |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
454 |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
455 RGB(3); |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
456 DST2(3); |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
457 DST1(3); |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
458 |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
459 pu += 4; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
460 pv += 4; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
461 py_1 += 8; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
462 py_2 += 8; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
463 dst_1 += 8; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
464 dst_2 += 8; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
465 } |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
466 } |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
467 |
6452 | 468 // r, g, b, dst_1, dst_2 |
469 static void yuv2rgb_c_8_ordered_dither (uint8_t * py_1, uint8_t * py_2, | |
470 uint8_t * pu, uint8_t * pv, | |
471 void * _dst_1, void * _dst_2, int h_size, int v_pos) | |
472 { | |
473 int U, V, Y; | |
474 uint8_t * r, * g, * b; | |
475 uint8_t * dst_1, * dst_2; | |
476 | |
477 h_size >>= 3; | |
478 dst_1 = _dst_1; | |
479 dst_2 = _dst_2; | |
480 | |
481 while (h_size--) { | |
6456 | 482 uint8_t *d32= dither_8x8_32[v_pos&7]; |
483 uint8_t *d64= dither_8x8_64[v_pos&7]; | |
484 #define DST1bpp8(i,o) \ | |
6452 | 485 Y = py_1[2*i]; \ |
6456 | 486 dst_1[2*i] = r[Y+d32[0+o]] + g[Y+d32[0+o]] + b[Y+d64[0+o]]; \ |
6452 | 487 Y = py_1[2*i+1]; \ |
6456 | 488 dst_1[2*i+1] = r[Y+d32[1+o]] + g[Y+d32[1+o]] + b[Y+d64[1+o]]; |
6452 | 489 |
6456 | 490 #define DST2bpp8(i,o) \ |
6452 | 491 Y = py_2[2*i]; \ |
6456 | 492 dst_2[2*i] = r[Y+d32[8+o]] + g[Y+d32[8+o]] + b[Y+d64[8+o]]; \ |
6452 | 493 Y = py_2[2*i+1]; \ |
6456 | 494 dst_2[2*i+1] = r[Y+d32[9+o]] + g[Y+d32[9+o]] + b[Y+d64[9+o]]; |
6452 | 495 |
496 | |
497 RGB(0); | |
6456 | 498 DST1bpp8(0,0); |
499 DST2bpp8(0,0); | |
6452 | 500 |
501 RGB(1); | |
6456 | 502 DST2bpp8(1,2); |
503 DST1bpp8(1,2); | |
6452 | 504 |
505 RGB(2); | |
6456 | 506 DST1bpp8(2,4); |
507 DST2bpp8(2,4); | |
6452 | 508 |
509 RGB(3); | |
6456 | 510 DST2bpp8(3,6); |
511 DST1bpp8(3,6); | |
6452 | 512 |
513 pu += 4; | |
514 pv += 4; | |
515 py_1 += 8; | |
516 py_2 += 8; | |
517 dst_1 += 8; | |
518 dst_2 += 8; | |
519 } | |
520 } | |
6451
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
521 |
6453 | 522 |
523 // This is exactly the same code as yuv2rgb_c_32 except for the types of | |
524 // r, g, b, dst_1, dst_2 | |
525 static void yuv2rgb_c_4 (uint8_t * py_1, uint8_t * py_2, | |
526 uint8_t * pu, uint8_t * pv, | |
527 void * _dst_1, void * _dst_2, int h_size, int v_pos) | |
528 { | |
529 int U, V, Y, out; | |
530 uint8_t * r, * g, * b; | |
531 uint8_t * dst_1, * dst_2; | |
532 | |
533 h_size >>= 3; | |
534 dst_1 = _dst_1; | |
535 dst_2 = _dst_2; | |
536 | |
537 while (h_size--) { | |
538 RGB(0); | |
539 DST1(0); | |
540 DST2(0); | |
541 | |
542 RGB(1); | |
543 DST2(1); | |
544 DST1(1); | |
545 | |
546 RGB(2); | |
547 DST1(2); | |
548 DST2(2); | |
549 | |
550 RGB(3); | |
551 DST2(3); | |
552 DST1(3); | |
553 | |
554 pu += 4; | |
555 pv += 4; | |
556 py_1 += 8; | |
557 py_2 += 8; | |
558 dst_1 += 8; | |
559 dst_2 += 8; | |
560 } | |
561 } | |
562 | |
563 static void yuv2rgb_c_4_ordered_dither (uint8_t * py_1, uint8_t * py_2, | |
564 uint8_t * pu, uint8_t * pv, | |
565 void * _dst_1, void * _dst_2, int h_size, int v_pos) | |
566 { | |
567 int U, V, Y; | |
568 uint8_t * r, * g, * b; | |
569 uint8_t * dst_1, * dst_2; | |
570 | |
571 h_size >>= 3; | |
572 dst_1 = _dst_1; | |
573 dst_2 = _dst_2; | |
574 | |
575 while (h_size--) { | |
576 uint8_t *d64= dither_8x8_64 [v_pos&7]; | |
577 uint8_t *d128=dither_8x8_128[v_pos&7]; | |
578 | |
579 #define DST1bpp4(i,o) \ | |
580 Y = py_1[2*i]; \ | |
581 dst_1[2*i] = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \ | |
582 Y = py_1[2*i+1]; \ | |
583 dst_1[2*i+1] = r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]]; | |
584 | |
585 #define DST2bpp4(i,o) \ | |
586 Y = py_2[2*i]; \ | |
587 dst_2[2*i] = r[Y+d128[8+o]] + g[Y+d64[8+o]] + b[Y+d128[8+o]]; \ | |
588 Y = py_2[2*i+1]; \ | |
589 dst_2[2*i+1] = r[Y+d128[9+o]] + g[Y+d64[9+o]] + b[Y+d128[9+o]]; | |
590 | |
591 | |
592 RGB(0); | |
593 DST1bpp4(0,0); | |
594 DST2bpp4(0,0); | |
595 | |
596 RGB(1); | |
597 DST2bpp4(1,2); | |
598 DST1bpp4(1,2); | |
599 | |
600 RGB(2); | |
601 DST1bpp4(2,4); | |
602 DST2bpp4(2,4); | |
603 | |
604 RGB(3); | |
605 DST2bpp4(3,6); | |
606 DST1bpp4(3,6); | |
607 | |
608 pu += 4; | |
609 pv += 4; | |
610 py_1 += 8; | |
611 py_2 += 8; | |
612 dst_1 += 8; | |
613 dst_2 += 8; | |
614 } | |
615 } | |
616 | |
6456 | 617 static void yuv2rgb_c_1_ordered_dither (uint8_t * py_1, uint8_t * py_2, |
618 uint8_t * pu, uint8_t * pv, | |
619 void * _dst_1, void * _dst_2, int h_size, int v_pos) | |
620 { | |
621 int U, V, Y; | |
622 uint8_t * r, * g, * b; | |
623 uint8_t * dst_1, * dst_2; | |
624 | |
625 h_size >>= 3; | |
626 dst_1 = _dst_1; | |
627 dst_2 = _dst_2; | |
628 g= table_gU[128] + table_gV[128]; | |
629 | |
630 while (h_size--) { | |
631 uint8_t *d128=dither_8x8_128[v_pos&7]; | |
632 char out_1=0, out_2=0; | |
633 | |
634 #define DST1bpp1(i,o) \ | |
635 Y = py_1[2*i]; \ | |
636 out_1+= out_1 + g[Y+d128[0+o]]; \ | |
637 Y = py_1[2*i+1]; \ | |
638 out_1+= out_1 + g[Y+d128[1+o]]; | |
639 | |
640 #define DST2bpp1(i,o) \ | |
641 Y = py_2[2*i]; \ | |
642 out_2+= out_2 + g[Y+d128[8+o]]; \ | |
643 Y = py_2[2*i+1]; \ | |
644 out_2+= out_2 + g[Y+d128[9+o]]; | |
645 | |
646 DST1bpp1(0,0); | |
647 DST2bpp1(0,0); | |
648 | |
649 DST2bpp1(1,2); | |
650 DST1bpp1(1,2); | |
651 | |
652 DST1bpp1(2,4); | |
653 DST2bpp1(2,4); | |
654 | |
655 DST2bpp1(3,6); | |
656 DST1bpp1(3,6); | |
657 | |
658 dst_1[0]= out_1; | |
659 dst_2[0]= out_2; | |
660 | |
661 pu += 4; | |
662 pv += 4; | |
663 py_1 += 8; | |
664 py_2 += 8; | |
665 dst_1 ++; | |
666 dst_2 ++; | |
667 } | |
668 } | |
669 | |
6453 | 670 |
2732 | 671 static int div_round (int dividend, int divisor) |
672 { | |
673 if (dividend > 0) | |
674 return (dividend + (divisor>>1)) / divisor; | |
675 else | |
676 return -((-dividend + (divisor>>1)) / divisor); | |
677 } | |
678 | |
6492 | 679 static void yuv2rgb_c_init (unsigned bpp, int mode) |
2732 | 680 { |
681 int i; | |
682 uint8_t table_Y[1024]; | |
683 uint32_t *table_32 = 0; | |
684 uint16_t *table_16 = 0; | |
685 uint8_t *table_8 = 0; | |
6451
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
686 uint8_t *table_332 = 0; |
6453 | 687 uint8_t *table_121 = 0; |
688 uint8_t *table_1 = 0; | |
6140
44dcc49a0d80
64bit incompatibility bug, patch by Artur Grabowski <art@blahonga.org>
arpi
parents:
5937
diff
changeset
|
689 int entry_size = 0; |
2732 | 690 void *table_r = 0, *table_g = 0, *table_b = 0; |
691 | |
692 int crv = Inverse_Table_6_9[matrix_coefficients][0]; | |
693 int cbu = Inverse_Table_6_9[matrix_coefficients][1]; | |
694 int cgu = -Inverse_Table_6_9[matrix_coefficients][2]; | |
695 int cgv = -Inverse_Table_6_9[matrix_coefficients][3]; | |
696 | |
697 for (i = 0; i < 1024; i++) { | |
698 int j; | |
699 | |
700 j = (76309 * (i - 384 - 16) + 32768) >> 16; | |
701 j = (j < 0) ? 0 : ((j > 255) ? 255 : j); | |
702 table_Y[i] = j; | |
703 } | |
704 | |
705 switch (bpp) { | |
706 case 32: | |
707 yuv2rgb_c_internal = yuv2rgb_c_32; | |
708 | |
709 table_32 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint32_t)); | |
710 | |
711 entry_size = sizeof (uint32_t); | |
712 table_r = table_32 + 197; | |
713 table_b = table_32 + 197 + 685; | |
714 table_g = table_32 + 197 + 2*682; | |
715 | |
716 for (i = -197; i < 256+197; i++) | |
717 ((uint32_t *)table_r)[i] = table_Y[i+384] << ((mode==MODE_RGB) ? 16 : 0); | |
718 for (i = -132; i < 256+132; i++) | |
719 ((uint32_t *)table_g)[i] = table_Y[i+384] << 8; | |
720 for (i = -232; i < 256+232; i++) | |
721 ((uint32_t *)table_b)[i] = table_Y[i+384] << ((mode==MODE_RGB) ? 0 : 16); | |
722 break; | |
723 | |
724 case 24: | |
725 // yuv2rgb_c_internal = (mode==MODE_RGB) ? yuv2rgb_c_24_rgb : yuv2rgb_c_24_bgr; | |
726 yuv2rgb_c_internal = (mode!=MODE_RGB) ? yuv2rgb_c_24_rgb : yuv2rgb_c_24_bgr; | |
727 | |
728 table_8 = malloc ((256 + 2*232) * sizeof (uint8_t)); | |
729 | |
730 entry_size = sizeof (uint8_t); | |
731 table_r = table_g = table_b = table_8 + 232; | |
732 | |
733 for (i = -232; i < 256+232; i++) | |
734 ((uint8_t * )table_b)[i] = table_Y[i+384]; | |
735 break; | |
736 | |
737 case 15: | |
738 case 16: | |
739 yuv2rgb_c_internal = yuv2rgb_c_16; | |
740 | |
741 table_16 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t)); | |
742 | |
743 entry_size = sizeof (uint16_t); | |
744 table_r = table_16 + 197; | |
745 table_b = table_16 + 197 + 685; | |
746 table_g = table_16 + 197 + 2*682; | |
747 | |
748 for (i = -197; i < 256+197; i++) { | |
749 int j = table_Y[i+384] >> 3; | |
750 | |
751 if (mode == MODE_RGB) | |
752 j <<= ((bpp==16) ? 11 : 10); | |
753 | |
754 ((uint16_t *)table_r)[i] = j; | |
755 } | |
756 for (i = -132; i < 256+132; i++) { | |
757 int j = table_Y[i+384] >> ((bpp==16) ? 2 : 3); | |
758 | |
759 ((uint16_t *)table_g)[i] = j << 5; | |
760 } | |
761 for (i = -232; i < 256+232; i++) { | |
762 int j = table_Y[i+384] >> 3; | |
763 | |
764 if (mode == MODE_BGR) | |
765 j <<= ((bpp==16) ? 11 : 10); | |
766 | |
767 ((uint16_t *)table_b)[i] = j; | |
768 } | |
769 break; | |
770 | |
6451
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
771 case 8: |
6452 | 772 yuv2rgb_c_internal = yuv2rgb_c_8_ordered_dither; //yuv2rgb_c_8; |
6451
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
773 |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
774 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
|
775 |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
776 entry_size = sizeof (uint8_t); |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
777 table_r = table_332 + 197; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
778 table_b = table_332 + 197 + 685; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
779 table_g = table_332 + 197 + 2*682; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
780 |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
781 for (i = -197; i < 256+197; i++) { |
6453 | 782 int j = (table_Y[i+384] - 16) >> 5; |
783 if(j<0) j=0; | |
6451
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
784 |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
785 if (mode == MODE_RGB) |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
786 j <<= 5; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
787 |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
788 ((uint8_t *)table_r)[i] = j; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
789 } |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
790 for (i = -132; i < 256+132; i++) { |
6453 | 791 int j = (table_Y[i+384] - 16) >> 5; |
792 if(j<0) j=0; | |
6451
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
793 |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
794 if (mode == MODE_BGR) |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
795 j <<= 1; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
796 |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
797 ((uint8_t *)table_g)[i] = j << 2; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
798 } |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
799 for (i = -232; i < 256+232; i++) { |
6453 | 800 int j = (table_Y[i+384] - 32) >> 6; |
801 if(j<0) j=0; | |
6451
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
802 |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
803 if (mode == MODE_BGR) |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
804 j <<= 6; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
805 |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
806 ((uint8_t *)table_b)[i] = j; |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
807 } |
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
808 break; |
6453 | 809 case 4: |
810 yuv2rgb_c_internal = yuv2rgb_c_4_ordered_dither; //yuv2rgb_c_4; | |
811 | |
812 table_121 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t)); | |
813 | |
814 entry_size = sizeof (uint8_t); | |
815 table_r = table_121 + 197; | |
816 table_b = table_121 + 197 + 685; | |
817 table_g = table_121 + 197 + 2*682; | |
818 | |
819 for (i = -197; i < 256+197; i++) { | |
820 int j = (table_Y[i+384] - 64) >> 7; | |
821 if(j<0) j=0; | |
822 | |
823 if (mode == MODE_RGB) | |
824 j <<= 3; | |
825 | |
826 ((uint8_t *)table_r)[i] = j; | |
827 } | |
828 for (i = -132; i < 256+132; i++) { | |
829 int j = (table_Y[i+384] - 32) >> 6; | |
830 if(j<0) j=0; | |
831 | |
832 ((uint8_t *)table_g)[i] = j << 1; | |
833 } | |
834 for (i = -232; i < 256+232; i++) { | |
835 int j =(table_Y[i+384] - 64) >> 7; | |
836 if(j<0) j=0; | |
837 | |
838 if (mode == MODE_BGR) | |
839 j <<= 3; | |
840 | |
841 ((uint8_t *)table_b)[i] = j; | |
842 } | |
843 break; | |
6451
ed906af317da
8bpp support (no dithering yet, use -vop noise for now)
michael
parents:
6140
diff
changeset
|
844 |
6456 | 845 case 1: |
846 yuv2rgb_c_internal = yuv2rgb_c_1_ordered_dither; | |
847 | |
848 table_1 = malloc ((132*2 + 256) * sizeof (uint8_t)); | |
849 | |
850 entry_size = sizeof (uint8_t); | |
851 table_g = table_1 + 132; | |
852 table_r = table_b = NULL; | |
853 | |
854 for (i = -132; i < 256+132; i++) { | |
855 int j = (table_Y[i+384] - 64) >> 7; | |
856 if(j<0) j=0; | |
857 | |
858 ((uint8_t *)table_g)[i] = j; | |
859 } | |
860 break; | |
861 | |
2732 | 862 default: |
5937 | 863 mp_msg(MSGT_SWS,MSGL_ERR,"%ibpp not supported by yuv2rgb\n", bpp); |
2732 | 864 //exit (1); |
865 } | |
866 | |
867 for (i = 0; i < 256; i++) { | |
868 table_rV[i] = table_r + entry_size * div_round (crv * (i-128), 76309); | |
869 table_gU[i] = table_g + entry_size * div_round (cgu * (i-128), 76309); | |
870 table_gV[i] = entry_size * div_round (cgv * (i-128), 76309); | |
871 table_bU[i] = table_b + entry_size * div_round (cbu * (i-128), 76309); | |
872 } | |
873 } |