annotate libvo/csputils.c @ 31254:e888e262e3f0

Remove colorspace conversion code from -vo yuv4mpeg, -vf scale should be able to handle this just as well (or better) including interlaced. If not, this needs to be fixed there instead of duplicating code.
author reimar
date Sat, 05 Jun 2010 06:45:01 +0000
parents aeab18b1923d
children 4b888c2d2a1d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30108
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
1 /*
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
2 * Common code related to colorspaces and conversion
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
3 *
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
4 * Copyleft (C) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
5 *
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
6 * This file is part of MPlayer.
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
7 *
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
8 * MPlayer is free software; you can redistribute it and/or modify
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
11 * (at your option) any later version.
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
12 *
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
13 * MPlayer is distributed in the hope that it will be useful,
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
16 * GNU General Public License for more details.
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
17 *
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License along
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
21 */
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
22
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
23 #include <stdint.h>
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
24 #include <math.h>
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
25 #include "libavutil/common.h"
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
26 #include "csputils.h"
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
27
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
28 /**
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
29 * \brief little helper function to create a lookup table for gamma
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
30 * \param map buffer to create map into
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
31 * \param size size of buffer
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
32 * \param gamma gamma value
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
33 */
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
34 void mp_gen_gamma_map(uint8_t *map, int size, float gamma) {
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
35 int i;
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
36 if (gamma == 1.0) {
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
37 for (i = 0; i < size; i++)
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
38 map[i] = 255 * i / (size - 1);
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
39 return;
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
40 }
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
41 gamma = 1.0 / gamma;
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
42 for (i = 0; i < size; i++) {
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
43 float tmp = (float)i / (size - 1.0);
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
44 tmp = pow(tmp, gamma);
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
45 if (tmp > 1.0) tmp = 1.0;
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
46 if (tmp < 0.0) tmp = 0.0;
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
47 map[i] = 255 * tmp;
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
48 }
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
49 }
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
50
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
51 /**
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
52 * \brief get the coefficients of the yuv -> rgb conversion matrix
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
53 * \param params struct specifying the properties of the conversion like brightness, ...
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
54 * \param yuv2rgb array to store coefficients into
30121
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
55 *
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
56 * Note: contrast, hue and saturation will only work as expected with YUV formats,
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
57 * not with e.g. MP_CSP_XYZ
30108
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
58 */
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
59 void mp_get_yuv2rgb_coeffs(struct mp_csp_params *params, float yuv2rgb[3][4]) {
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
60 float uvcos = params->saturation * cos(params->hue);
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
61 float uvsin = params->saturation * sin(params->hue);
30109
0f25d3062987 First steps to supporting different YUV->RGB conversion definitions.
reimar
parents: 30108
diff changeset
62 int format = params->format;
30293
aeab18b1923d Add support for adjustable TV <-> PC level conversion.
reimar
parents: 30164
diff changeset
63 int levelconv = params->levelconv;
30108
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
64 int i;
30121
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
65 const float (*uv_coeffs)[3];
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
66 const float *level_adjust;
30293
aeab18b1923d Add support for adjustable TV <-> PC level conversion.
reimar
parents: 30164
diff changeset
67 static const float yuv_level_adjust[MP_CSP_LEVELCONV_COUNT][4] = {
aeab18b1923d Add support for adjustable TV <-> PC level conversion.
reimar
parents: 30164
diff changeset
68 {-16 / 255.0, -128 / 255.0, -128 / 255.0, 1.164},
aeab18b1923d Add support for adjustable TV <-> PC level conversion.
reimar
parents: 30164
diff changeset
69 { 16 / 255.0 * 1.164, -128 / 255.0, -128 / 255.0, 1.0/1.164},
aeab18b1923d Add support for adjustable TV <-> PC level conversion.
reimar
parents: 30164
diff changeset
70 { 0, -128 / 255.0, -128 / 255.0, 1},
aeab18b1923d Add support for adjustable TV <-> PC level conversion.
reimar
parents: 30164
diff changeset
71 };
30121
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
72 static const float xyz_level_adjust[4] = {0, 0, 0, 0};
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
73 static const float uv_coeffs_table[MP_CSP_COUNT][3][3] = {
30109
0f25d3062987 First steps to supporting different YUV->RGB conversion definitions.
reimar
parents: 30108
diff changeset
74 [MP_CSP_DEFAULT] = {
30121
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
75 {1, 0.000, 1.596},
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
76 {1, -0.391, -0.813},
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
77 {1, 2.018, 0.000}
30109
0f25d3062987 First steps to supporting different YUV->RGB conversion definitions.
reimar
parents: 30108
diff changeset
78 },
0f25d3062987 First steps to supporting different YUV->RGB conversion definitions.
reimar
parents: 30108
diff changeset
79 [MP_CSP_BT_601] = {
30121
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
80 {1, 0.000, 1.403},
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
81 {1, -0.344, -0.714},
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
82 {1, 1.773, 0.000}
30109
0f25d3062987 First steps to supporting different YUV->RGB conversion definitions.
reimar
parents: 30108
diff changeset
83 },
0f25d3062987 First steps to supporting different YUV->RGB conversion definitions.
reimar
parents: 30108
diff changeset
84 [MP_CSP_BT_709] = {
30121
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
85 {1, 0.0000, 1.5701},
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
86 {1, -0.1870, -0.4664},
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
87 {1, 1.8556, 0.0000}
30109
0f25d3062987 First steps to supporting different YUV->RGB conversion definitions.
reimar
parents: 30108
diff changeset
88 },
0f25d3062987 First steps to supporting different YUV->RGB conversion definitions.
reimar
parents: 30108
diff changeset
89 [MP_CSP_SMPTE_240M] = {
30121
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
90 {1, 0.0000, 1.5756},
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
91 {1, -0.2253, -0.5000},
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
92 {1, 1.8270, 0.0000}
30109
0f25d3062987 First steps to supporting different YUV->RGB conversion definitions.
reimar
parents: 30108
diff changeset
93 },
0f25d3062987 First steps to supporting different YUV->RGB conversion definitions.
reimar
parents: 30108
diff changeset
94 [MP_CSP_EBU] = {
30121
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
95 {1, 0.000, 1.140},
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
96 {1, -0.396, -0.581},
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
97 {1, 2.029, 0.000}
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
98 },
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
99 [MP_CSP_XYZ] = {
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
100 { 3.2404542, -1.5371385, -0.4985314},
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
101 {-0.9692660, 1.8760108, 0.0415560},
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
102 { 0.0556434, -0.2040259, 1.0572252}
30109
0f25d3062987 First steps to supporting different YUV->RGB conversion definitions.
reimar
parents: 30108
diff changeset
103 },
30108
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
104 };
30109
0f25d3062987 First steps to supporting different YUV->RGB conversion definitions.
reimar
parents: 30108
diff changeset
105
0f25d3062987 First steps to supporting different YUV->RGB conversion definitions.
reimar
parents: 30108
diff changeset
106 if (format < 0 || format >= MP_CSP_COUNT)
0f25d3062987 First steps to supporting different YUV->RGB conversion definitions.
reimar
parents: 30108
diff changeset
107 format = MP_CSP_DEFAULT;
0f25d3062987 First steps to supporting different YUV->RGB conversion definitions.
reimar
parents: 30108
diff changeset
108 uv_coeffs = uv_coeffs_table[format];
30293
aeab18b1923d Add support for adjustable TV <-> PC level conversion.
reimar
parents: 30164
diff changeset
109 if (levelconv < 0 || levelconv >= MP_CSP_LEVELCONV_COUNT)
aeab18b1923d Add support for adjustable TV <-> PC level conversion.
reimar
parents: 30164
diff changeset
110 levelconv = MP_CSP_LEVELCONV_TV_TO_PC;
aeab18b1923d Add support for adjustable TV <-> PC level conversion.
reimar
parents: 30164
diff changeset
111 level_adjust = yuv_level_adjust[levelconv];
30121
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
112 if (format == MP_CSP_XYZ)
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
113 level_adjust = xyz_level_adjust;
30109
0f25d3062987 First steps to supporting different YUV->RGB conversion definitions.
reimar
parents: 30108
diff changeset
114
30108
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
115 for (i = 0; i < 3; i++) {
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
116 yuv2rgb[i][COL_C] = params->brightness;
30121
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
117 yuv2rgb[i][COL_Y] = uv_coeffs[i][COL_Y] * level_adjust[COL_C] * params->contrast;
30109
0f25d3062987 First steps to supporting different YUV->RGB conversion definitions.
reimar
parents: 30108
diff changeset
118 yuv2rgb[i][COL_C] += level_adjust[COL_Y] * yuv2rgb[i][COL_Y];
30121
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
119 yuv2rgb[i][COL_U] = uv_coeffs[i][COL_U] * uvcos + uv_coeffs[i][COL_V] * uvsin;
30109
0f25d3062987 First steps to supporting different YUV->RGB conversion definitions.
reimar
parents: 30108
diff changeset
120 yuv2rgb[i][COL_C] += level_adjust[COL_U] * yuv2rgb[i][COL_U];
30121
28cbec606cbb Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents: 30109
diff changeset
121 yuv2rgb[i][COL_V] = uv_coeffs[i][COL_U] * uvsin + uv_coeffs[i][COL_V] * uvcos;
30109
0f25d3062987 First steps to supporting different YUV->RGB conversion definitions.
reimar
parents: 30108
diff changeset
122 yuv2rgb[i][COL_C] += level_adjust[COL_V] * yuv2rgb[i][COL_V];
30108
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
123 // this "centers" contrast control so that e.g. a contrast of 0
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
124 // leads to a grey image, not a black one
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
125 yuv2rgb[i][COL_C] += 0.5 - params->contrast / 2.0;
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
126 }
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
127 }
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
128
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
129 //! size of gamma map use to avoid slow exp function in gen_yuv2rgb_map
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
130 #define GMAP_SIZE (1024)
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
131 /**
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
132 * \brief generate a 3D YUV -> RGB map
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
133 * \param params struct containing parameters like brightness, gamma, ...
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
134 * \param map where to store map. Must provide space for (size + 2)^3 elements
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
135 * \param size size of the map, excluding border
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
136 */
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
137 void mp_gen_yuv2rgb_map(struct mp_csp_params *params, unsigned char *map, int size) {
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
138 int i, j, k, l;
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
139 float step = 1.0 / size;
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
140 float y, u, v;
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
141 float yuv2rgb[3][4];
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
142 unsigned char gmaps[3][GMAP_SIZE];
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
143 mp_gen_gamma_map(gmaps[0], GMAP_SIZE, params->rgamma);
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
144 mp_gen_gamma_map(gmaps[1], GMAP_SIZE, params->ggamma);
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
145 mp_gen_gamma_map(gmaps[2], GMAP_SIZE, params->bgamma);
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
146 mp_get_yuv2rgb_coeffs(params, yuv2rgb);
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
147 for (i = 0; i < 3; i++)
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
148 for (j = 0; j < 4; j++)
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
149 yuv2rgb[i][j] *= GMAP_SIZE - 1;
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
150 v = 0;
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
151 for (i = -1; i <= size; i++) {
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
152 u = 0;
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
153 for (j = -1; j <= size; j++) {
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
154 y = 0;
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
155 for (k = -1; k <= size; k++) {
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
156 for (l = 0; l < 3; l++) {
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
157 float rgb = yuv2rgb[l][COL_Y] * y + yuv2rgb[l][COL_U] * u + yuv2rgb[l][COL_V] * v + yuv2rgb[l][COL_C];
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
158 *map++ = gmaps[l][av_clip(rgb, 0, GMAP_SIZE - 1)];
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
159 }
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
160 y += (k == -1 || k == size - 1) ? step / 2 : step;
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
161 }
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
162 u += (j == -1 || j == size - 1) ? step / 2 : step;
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
163 }
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
164 v += (i == -1 || i == size - 1) ? step / 2 : step;
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
165 }
0898adc64a6f Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff changeset
166 }