annotate libvo/yuv2rgb.c @ 579:256f3d32a4af

Added maintainer info and disclaimer.
author atmosfear
date Sun, 22 Apr 2001 17:03:26 +0000
parents 3b5f5d1c5041
children f83ec60bce49
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2 * yuv2rgb.c, Software YUV to RGB coverter
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 * Copyright (C) 1999, Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 * All Rights Reserved.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7 * Functions broken out from display_x11.c and several new modes
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 * added by Håkan Hjort <d95hjort@dtek.chalmers.se>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 * 15 & 16 bpp support by Franck Sicard <Franck.Sicard@solsoft.fr>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 * This file is part of mpeg2dec, a free MPEG-2 video decoder
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 * mpeg2dec is free software; you can redistribute it and/or modify
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 * it under the terms of the GNU General Public License as published by
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 * the Free Software Foundation; either version 2, or (at your option)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 * any later version.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 * mpeg2dec is distributed in the hope that it will be useful,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 * GNU General Public License for more details.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 * You should have received a copy of the GNU General Public License
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 * along with GNU Make; see the file COPYING. If not, write to
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 #include <stdio.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 #include <stdlib.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 #include "config.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 #include "video_out.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 #include "yuv2rgb.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 uint32_t matrix_coefficients = 6;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 const int32_t Inverse_Table_6_9[8][4] = {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 {117504, 138453, 13954, 34903}, /* no sequence_display_extension */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 {117504, 138453, 13954, 34903}, /* ITU-R Rec. 709 (1990) */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 {104597, 132201, 25675, 53279}, /* unspecified */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 {104597, 132201, 25675, 53279}, /* reserved */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 {104448, 132798, 24759, 53109}, /* FCC */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 {104597, 132201, 25675, 53279}, /* ITU-R Rec. 624-4 System B, G */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 {104597, 132201, 25675, 53279}, /* SMPTE 170M */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 {117579, 136230, 16907, 35559} /* SMPTE 240M (1987) */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 static void yuv2rgb_c_init (int bpp, int mode);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 yuv2rgb_fun yuv2rgb;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 static void (* yuv2rgb_c_internal) (uint8_t *, uint8_t *,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 uint8_t *, uint8_t *,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 void *, void *, int);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 static void yuv2rgb_c (void * dst, uint8_t * py,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 uint8_t * pu, uint8_t * pv,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 int h_size, int v_size,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 int rgb_stride, int y_stride, int uv_stride)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 v_size >>= 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 while (v_size--) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 yuv2rgb_c_internal (py, py + y_stride, pu, pv, dst, dst + rgb_stride,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 h_size);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 py += 2 * y_stride;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 pu += uv_stride;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 pv += uv_stride;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 dst += 2 * rgb_stride;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 void yuv2rgb_init (int bpp, int mode)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 yuv2rgb = NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 #ifdef HAVE_MMX
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 if (yuv2rgb == NULL /*&& (config.flags & VO_MMX_ENABLE)*/) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 yuv2rgb = yuv2rgb_init_mmx (bpp, mode);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 if (yuv2rgb != NULL)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 fprintf (stderr, "Using MMX for colorspace transform\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 fprintf (stderr, "Cannot init MMX colorspace transform\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 #ifdef HAVE_MLIB
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 if (yuv2rgb == NULL /*&& (config.flags & VO_MLIB_ENABLE)*/) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 yuv2rgb = yuv2rgb_init_mlib (bpp, mode);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 if (yuv2rgb != NULL)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 fprintf (stderr, "Using mlib for colorspace transform\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 if (yuv2rgb == NULL) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 fprintf (stderr, "No accelerated colorspace conversion found\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 yuv2rgb_c_init (bpp, mode);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 yuv2rgb = (yuv2rgb_fun)yuv2rgb_c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 void * table_rV[256];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 void * table_gU[256];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 int table_gV[256];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 void * table_bU[256];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 #define RGB(i) \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 U = pu[i]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 V = pv[i]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 r = table_rV[V]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 g = table_gU[U] + table_gV[V]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 b = table_bU[U];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 #define DST1(i) \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 Y = py_1[2*i]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 dst_1[2*i] = r[Y] + g[Y] + b[Y]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 Y = py_1[2*i+1]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 dst_1[2*i+1] = r[Y] + g[Y] + b[Y];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 #define DST2(i) \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 Y = py_2[2*i]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122 dst_2[2*i] = r[Y] + g[Y] + b[Y]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 Y = py_2[2*i+1]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124 dst_2[2*i+1] = r[Y] + g[Y] + b[Y];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126 #define DST1RGB(i) \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127 Y = py_1[2*i]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 dst_1[6*i] = r[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = b[Y]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129 Y = py_1[2*i+1]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130 dst_1[6*i+3] = r[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = b[Y];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 #define DST2RGB(i) \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 Y = py_2[2*i]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 dst_2[6*i] = r[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = b[Y]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 Y = py_2[2*i+1]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 dst_2[6*i+3] = r[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = b[Y];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 #define DST1BGR(i) \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 Y = py_1[2*i]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 dst_1[6*i] = b[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = r[Y]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 Y = py_1[2*i+1]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142 dst_1[6*i+3] = b[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = r[Y];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144 #define DST2BGR(i) \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145 Y = py_2[2*i]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146 dst_2[6*i] = b[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = r[Y]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 Y = py_2[2*i+1]; \
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 dst_2[6*i+3] = b[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = r[Y];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 static void yuv2rgb_c_32 (uint8_t * py_1, uint8_t * py_2,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 uint8_t * pu, uint8_t * pv,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 void * _dst_1, void * _dst_2, int h_size)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154 int U, V, Y;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155 uint32_t * r, * g, * b;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
156 uint32_t * dst_1, * dst_2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158 h_size >>= 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159 dst_1 = _dst_1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 dst_2 = _dst_2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162 while (h_size--) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 RGB(0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164 DST1(0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
165 DST2(0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
166
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167 RGB(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168 DST2(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
169 DST1(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
171 RGB(2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172 DST1(2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173 DST2(2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175 RGB(3);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
176 DST2(3);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177 DST1(3);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179 pu += 4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180 pv += 4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181 py_1 += 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 py_2 += 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
183 dst_1 += 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
184 dst_2 += 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
185 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
186 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188 // This is very near from the yuv2rgb_c_32 code
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
189 static void yuv2rgb_c_24_rgb (uint8_t * py_1, uint8_t * py_2,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
190 uint8_t * pu, uint8_t * pv,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
191 void * _dst_1, void * _dst_2, int h_size)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
192 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
193 int U, V, Y;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
194 uint8_t * r, * g, * b;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
195 uint8_t * dst_1, * dst_2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
196
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
197 h_size >>= 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
198 dst_1 = _dst_1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
199 dst_2 = _dst_2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
200
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
201 while (h_size--) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
202 RGB(0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
203 DST1RGB(0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
204 DST2RGB(0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
205
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
206 RGB(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
207 DST2RGB(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
208 DST1RGB(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
210 RGB(2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211 DST1RGB(2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
212 DST2RGB(2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
213
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
214 RGB(3);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
215 DST2RGB(3);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
216 DST1RGB(3);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
217
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
218 pu += 4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
219 pv += 4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
220 py_1 += 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
221 py_2 += 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
222 dst_1 += 24;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
223 dst_2 += 24;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
224 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
225 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
226
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
227 // only trivial mods from yuv2rgb_c_24_rgb
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
228 static void yuv2rgb_c_24_bgr (uint8_t * py_1, uint8_t * py_2,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
229 uint8_t * pu, uint8_t * pv,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
230 void * _dst_1, void * _dst_2, int h_size)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
231 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
232 int U, V, Y;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
233 uint8_t * r, * g, * b;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
234 uint8_t * dst_1, * dst_2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
235
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
236 h_size >>= 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
237 dst_1 = _dst_1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
238 dst_2 = _dst_2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
239
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
240 while (h_size--) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
241 RGB(0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
242 DST1BGR(0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
243 DST2BGR(0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
244
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
245 RGB(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
246 DST2BGR(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
247 DST1BGR(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
248
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
249 RGB(2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
250 DST1BGR(2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
251 DST2BGR(2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
252
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
253 RGB(3);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
254 DST2BGR(3);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
255 DST1BGR(3);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
256
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
257 pu += 4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
258 pv += 4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
259 py_1 += 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
260 py_2 += 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
261 dst_1 += 24;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
262 dst_2 += 24;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
263 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
264 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
265
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
266 // This is exactly the same code as yuv2rgb_c_32 except for the types of
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
267 // r, g, b, dst_1, dst_2
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
268 static void yuv2rgb_c_16 (uint8_t * py_1, uint8_t * py_2,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
269 uint8_t * pu, uint8_t * pv,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
270 void * _dst_1, void * _dst_2, int h_size)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
271 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
272 int U, V, Y;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
273 uint16_t * r, * g, * b;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
274 uint16_t * dst_1, * dst_2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
275
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
276 h_size >>= 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
277 dst_1 = _dst_1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
278 dst_2 = _dst_2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
279
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
280 while (h_size--) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
281 RGB(0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
282 DST1(0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
283 DST2(0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
284
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
285 RGB(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
286 DST2(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
287 DST1(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
288
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
289 RGB(2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
290 DST1(2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
291 DST2(2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
292
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
293 RGB(3);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
294 DST2(3);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
295 DST1(3);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
296
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
297 pu += 4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
298 pv += 4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
299 py_1 += 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
300 py_2 += 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
301 dst_1 += 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
302 dst_2 += 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
303 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
304 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
305
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
306 static int div_round (int dividend, int divisor)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
307 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
308 if (dividend > 0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
309 return (dividend + (divisor>>1)) / divisor;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
310 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
311 return -((-dividend + (divisor>>1)) / divisor);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
312 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
313
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
314 static void yuv2rgb_c_init (int bpp, int mode)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
315 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
316 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
317 uint8_t table_Y[1024];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
318 uint32_t *table_32 = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
319 uint16_t *table_16 = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
320 uint8_t *table_8 = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
321 uint32_t entry_size = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
322 void *table_r = 0, *table_g = 0, *table_b = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
323
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
324 int crv = Inverse_Table_6_9[matrix_coefficients][0];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
325 int cbu = Inverse_Table_6_9[matrix_coefficients][1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
326 int cgu = -Inverse_Table_6_9[matrix_coefficients][2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
327 int cgv = -Inverse_Table_6_9[matrix_coefficients][3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
328
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
329 for (i = 0; i < 1024; i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
330 int j;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
331
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
332 j = (76309 * (i - 384 - 16) + 32768) >> 16;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
333 j = (j < 0) ? 0 : ((j > 255) ? 255 : j);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
334 table_Y[i] = j;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
335 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
336
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
337 switch (bpp) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
338 case 32:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
339 yuv2rgb_c_internal = yuv2rgb_c_32;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
340
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
341 table_32 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint32_t));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
342
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
343 entry_size = sizeof (uint32_t);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
344 table_r = table_32 + 197;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
345 table_b = table_32 + 197 + 685;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
346 table_g = table_32 + 197 + 2*682;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
347
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
348 for (i = -197; i < 256+197; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
349 ((uint32_t *)table_r)[i] = table_Y[i+384] << ((mode==MODE_RGB) ? 16 : 0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
350 for (i = -132; i < 256+132; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
351 ((uint32_t *)table_g)[i] = table_Y[i+384] << 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
352 for (i = -232; i < 256+232; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
353 ((uint32_t *)table_b)[i] = table_Y[i+384] << ((mode==MODE_RGB) ? 0 : 16);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
354 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
355
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
356 case 24:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
357 // yuv2rgb_c_internal = (mode==MODE_RGB) ? yuv2rgb_c_24_rgb : yuv2rgb_c_24_bgr;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
358 yuv2rgb_c_internal = (mode!=MODE_RGB) ? yuv2rgb_c_24_rgb : yuv2rgb_c_24_bgr;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
359
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
360 table_8 = malloc ((256 + 2*232) * sizeof (uint8_t));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
361
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
362 entry_size = sizeof (uint8_t);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
363 table_r = table_g = table_b = table_8 + 232;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
364
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
365 for (i = -232; i < 256+232; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
366 ((uint8_t * )table_b)[i] = table_Y[i+384];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
367 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
368
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
369 case 15:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
370 case 16:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
371 yuv2rgb_c_internal = yuv2rgb_c_16;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
372
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
373 table_16 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
374
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
375 entry_size = sizeof (uint16_t);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
376 table_r = table_16 + 197;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
377 table_b = table_16 + 197 + 685;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
378 table_g = table_16 + 197 + 2*682;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
379
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
380 for (i = -197; i < 256+197; i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
381 int j = table_Y[i+384] >> 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
382
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
383 if (mode == MODE_RGB)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
384 j <<= ((bpp==16) ? 11 : 10);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
385
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
386 ((uint16_t *)table_r)[i] = j;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
387 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
388 for (i = -132; i < 256+132; i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
389 int j = table_Y[i+384] >> ((bpp==16) ? 2 : 3);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
390
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
391 ((uint16_t *)table_g)[i] = j << 5;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
392 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
393 for (i = -232; i < 256+232; i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
394 int j = table_Y[i+384] >> 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
395
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
396 if (mode == MODE_BGR)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
397 j <<= ((bpp==16) ? 11 : 10);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
398
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
399 ((uint16_t *)table_b)[i] = j;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
400 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
401 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
402
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
403 default:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
404 fprintf (stderr, "%ibpp not supported by yuv2rgb\n", bpp);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
405 exit (1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
406 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
407
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
408 for (i = 0; i < 256; i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
409 table_rV[i] = table_r + entry_size * div_round (crv * (i-128), 76309);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
410 table_gU[i] = table_g + entry_size * div_round (cgu * (i-128), 76309);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
411 table_gV[i] = entry_size * div_round (cgv * (i-128), 76309);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
412 table_bU[i] = table_b + entry_size * div_round (cbu * (i-128), 76309);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
413 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
414 }