Mercurial > mplayer.hg
annotate libvo/csputils.c @ 32663:83c490a2e9f3
Replace mp_path_is_absolute with mp_path_join.
author | cboesch |
---|---|
date | Mon, 03 Jan 2011 18:37:45 +0000 |
parents | 4b888c2d2a1d |
children | 9bc9e1851a13 |
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. |
31310
4b888c2d2a1d
Allow LGPL for csputils as well, they were previously part of gl_common
reimar
parents:
30293
diff
changeset
|
21 * |
4b888c2d2a1d
Allow LGPL for csputils as well, they were previously part of gl_common
reimar
parents:
30293
diff
changeset
|
22 * You can alternatively redistribute this file and/or |
4b888c2d2a1d
Allow LGPL for csputils as well, they were previously part of gl_common
reimar
parents:
30293
diff
changeset
|
23 * modify it under the terms of the GNU Lesser General Public |
4b888c2d2a1d
Allow LGPL for csputils as well, they were previously part of gl_common
reimar
parents:
30293
diff
changeset
|
24 * License as published by the Free Software Foundation; either |
4b888c2d2a1d
Allow LGPL for csputils as well, they were previously part of gl_common
reimar
parents:
30293
diff
changeset
|
25 * version 2.1 of the License, or (at your option) any later version. |
30108
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
26 */ |
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 #include <stdint.h> |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
29 #include <math.h> |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
30 #include "libavutil/common.h" |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
31 #include "csputils.h" |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
32 |
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 * \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
|
35 * \param map buffer to create map into |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
36 * \param size size of buffer |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
37 * \param gamma gamma value |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
38 */ |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
39 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
|
40 int i; |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
41 if (gamma == 1.0) { |
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 map[i] = 255 * i / (size - 1); |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
44 return; |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
45 } |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
46 gamma = 1.0 / gamma; |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
47 for (i = 0; i < size; i++) { |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
48 float tmp = (float)i / (size - 1.0); |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
49 tmp = pow(tmp, gamma); |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
50 if (tmp > 1.0) tmp = 1.0; |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
51 if (tmp < 0.0) tmp = 0.0; |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
52 map[i] = 255 * tmp; |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
53 } |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
54 } |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
55 |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
56 /** |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
57 * \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
|
58 * \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
|
59 * \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
|
60 * |
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
61 * 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
|
62 * 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
|
63 */ |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
64 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
|
65 float uvcos = params->saturation * cos(params->hue); |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
66 float uvsin = params->saturation * sin(params->hue); |
30109
0f25d3062987
First steps to supporting different YUV->RGB conversion definitions.
reimar
parents:
30108
diff
changeset
|
67 int format = params->format; |
30293
aeab18b1923d
Add support for adjustable TV <-> PC level conversion.
reimar
parents:
30164
diff
changeset
|
68 int levelconv = params->levelconv; |
30108
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
69 int i; |
30121
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
70 const float (*uv_coeffs)[3]; |
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
71 const float *level_adjust; |
30293
aeab18b1923d
Add support for adjustable TV <-> PC level conversion.
reimar
parents:
30164
diff
changeset
|
72 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
|
73 {-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
|
74 { 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
|
75 { 0, -128 / 255.0, -128 / 255.0, 1}, |
aeab18b1923d
Add support for adjustable TV <-> PC level conversion.
reimar
parents:
30164
diff
changeset
|
76 }; |
30121
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
77 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
|
78 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
|
79 [MP_CSP_DEFAULT] = { |
30121
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
80 {1, 0.000, 1.596}, |
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
81 {1, -0.391, -0.813}, |
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
82 {1, 2.018, 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_601] = { |
30121
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
85 {1, 0.000, 1.403}, |
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
86 {1, -0.344, -0.714}, |
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
87 {1, 1.773, 0.000} |
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_BT_709] = { |
30121
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
90 {1, 0.0000, 1.5701}, |
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
91 {1, -0.1870, -0.4664}, |
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
92 {1, 1.8556, 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_SMPTE_240M] = { |
30121
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
95 {1, 0.0000, 1.5756}, |
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
96 {1, -0.2253, -0.5000}, |
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
97 {1, 1.8270, 0.0000} |
30109
0f25d3062987
First steps to supporting different YUV->RGB conversion definitions.
reimar
parents:
30108
diff
changeset
|
98 }, |
0f25d3062987
First steps to supporting different YUV->RGB conversion definitions.
reimar
parents:
30108
diff
changeset
|
99 [MP_CSP_EBU] = { |
30121
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
100 {1, 0.000, 1.140}, |
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
101 {1, -0.396, -0.581}, |
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
102 {1, 2.029, 0.000} |
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
103 }, |
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
104 [MP_CSP_XYZ] = { |
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
105 { 3.2404542, -1.5371385, -0.4985314}, |
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
106 {-0.9692660, 1.8760108, 0.0415560}, |
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
107 { 0.0556434, -0.2040259, 1.0572252} |
30109
0f25d3062987
First steps to supporting different YUV->RGB conversion definitions.
reimar
parents:
30108
diff
changeset
|
108 }, |
30108
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
109 }; |
30109
0f25d3062987
First steps to supporting different YUV->RGB conversion definitions.
reimar
parents:
30108
diff
changeset
|
110 |
0f25d3062987
First steps to supporting different YUV->RGB conversion definitions.
reimar
parents:
30108
diff
changeset
|
111 if (format < 0 || format >= MP_CSP_COUNT) |
0f25d3062987
First steps to supporting different YUV->RGB conversion definitions.
reimar
parents:
30108
diff
changeset
|
112 format = MP_CSP_DEFAULT; |
0f25d3062987
First steps to supporting different YUV->RGB conversion definitions.
reimar
parents:
30108
diff
changeset
|
113 uv_coeffs = uv_coeffs_table[format]; |
30293
aeab18b1923d
Add support for adjustable TV <-> PC level conversion.
reimar
parents:
30164
diff
changeset
|
114 if (levelconv < 0 || levelconv >= MP_CSP_LEVELCONV_COUNT) |
aeab18b1923d
Add support for adjustable TV <-> PC level conversion.
reimar
parents:
30164
diff
changeset
|
115 levelconv = MP_CSP_LEVELCONV_TV_TO_PC; |
aeab18b1923d
Add support for adjustable TV <-> PC level conversion.
reimar
parents:
30164
diff
changeset
|
116 level_adjust = yuv_level_adjust[levelconv]; |
30121
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
117 if (format == MP_CSP_XYZ) |
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
118 level_adjust = xyz_level_adjust; |
30109
0f25d3062987
First steps to supporting different YUV->RGB conversion definitions.
reimar
parents:
30108
diff
changeset
|
119 |
30108
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
120 for (i = 0; i < 3; i++) { |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
121 yuv2rgb[i][COL_C] = params->brightness; |
30121
28cbec606cbb
Slightly generalize code to generate YUV->RGB conversion table and add
reimar
parents:
30109
diff
changeset
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 // 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
|
129 // 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
|
130 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
|
131 } |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
132 } |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
133 |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
134 //! 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
|
135 #define GMAP_SIZE (1024) |
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 * \brief generate a 3D YUV -> RGB map |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
138 * \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
|
139 * \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
|
140 * \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
|
141 */ |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
142 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
|
143 int i, j, k, l; |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
144 float step = 1.0 / size; |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
145 float y, u, v; |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
146 float yuv2rgb[3][4]; |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
147 unsigned char gmaps[3][GMAP_SIZE]; |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
148 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
|
149 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
|
150 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
|
151 mp_get_yuv2rgb_coeffs(params, yuv2rgb); |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
152 for (i = 0; i < 3; i++) |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
153 for (j = 0; j < 4; j++) |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
154 yuv2rgb[i][j] *= GMAP_SIZE - 1; |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
155 v = 0; |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
156 for (i = -1; i <= size; i++) { |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
157 u = 0; |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
158 for (j = -1; j <= size; j++) { |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
159 y = 0; |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
160 for (k = -1; k <= size; k++) { |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
161 for (l = 0; l < 3; l++) { |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
162 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
|
163 *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
|
164 } |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
165 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
|
166 } |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
167 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
|
168 } |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
169 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
|
170 } |
0898adc64a6f
Extract functions to generate yuv->rgb matrices and lookup tables into a
reimar
parents:
diff
changeset
|
171 } |