csputils: move image_params -> csp_params into a function

Although the line count increases, this is better for making sure
everything is handled consistently for all users of the mp_csp_params
stuff.

This also makes sure mp_csp_params is always initialized with
MP_CSP_PARAMS_DEFAULTS (for consistency).
This commit is contained in:
wm4 2015-01-06 15:21:26 +01:00
parent a52ca8a2b0
commit 5410a5b2c5
7 changed files with 25 additions and 20 deletions

View File

@ -289,8 +289,7 @@ static void draw_ass(struct mp_draw_sub_cache *cache, struct mp_rect bb,
struct mp_image *temp, int bits, struct sub_bitmaps *sbs)
{
struct mp_csp_params cspar = MP_CSP_PARAMS_DEFAULTS;
cspar.colorspace = temp->params.colorspace;
cspar.levels_in = temp->params.colorlevels;
mp_csp_set_image_params(&cspar, &temp->params);
cspar.levels_out = MP_CSP_LEVELS_PC; // RGB (libass.color)
cspar.int_bits_in = bits;
cspar.int_bits_out = 8;

View File

@ -35,6 +35,7 @@
#include <libavutil/common.h>
#include <libavcodec/avcodec.h>
#include "mp_image.h"
#include "csputils.h"
const char *const mp_csp_names[MP_CSP_COUNT] = {
@ -682,6 +683,17 @@ void mp_gen_yuv2rgb_map(struct mp_csp_params *params, unsigned char *map, int si
}
}
// Set colorspace related fields in p from f. Don't touch other fields.
void mp_csp_set_image_params(struct mp_csp_params *params,
const struct mp_image_params *imgparams)
{
struct mp_image_params p = *imgparams;
mp_image_params_guess_csp(&p); // ensure consistency
params->colorspace = p.colorspace;
params->levels_in = p.colorlevels;
params->levels_out = p.outputlevels;
}
// Copy settings from eq into params.
void mp_csp_copy_equalizer_values(struct mp_csp_params *params,
const struct mp_csp_equalizer *eq)

View File

@ -133,6 +133,10 @@ struct mp_csp_params {
.rgamma = 1, .ggamma = 1, .bgamma = 1, \
.texture_bits = 8, .input_bits = 8}
struct mp_image_params;
void mp_csp_set_image_params(struct mp_csp_params *params,
const struct mp_image_params *imgparams);
enum mp_chroma_location {
MP_CHROMA_AUTO,
MP_CHROMA_LEFT, // mpeg2/4, h264

View File

@ -638,13 +638,10 @@ static void update_uniforms(struct gl_video *p, GLuint program)
gl->UseProgram(program);
struct mp_csp_params cparams = {
.colorspace = p->image_params.colorspace,
.levels_in = p->image_params.colorlevels,
.levels_out = p->image_params.outputlevels,
.input_bits = p->plane_bits,
.texture_bits = (p->plane_bits + 7) & ~7,
};
struct mp_csp_params cparams = MP_CSP_PARAMS_DEFAULTS;
cparams.input_bits = p->plane_bits;
cparams.texture_bits = (p->plane_bits + 7) & ~7;
mp_csp_set_image_params(&cparams, &p->image_params);
mp_csp_copy_equalizer_values(&cparams, &p->video_eq);
if (p->image_desc.flags & MP_IMGFLAG_XYZ) {
cparams.colorspace = MP_CSP_XYZ;

View File

@ -1152,9 +1152,7 @@ static void update_colorspace(d3d_priv *priv)
{
float coeff[3][4];
struct mp_csp_params csp = MP_CSP_PARAMS_DEFAULTS;
csp.colorspace = priv->params.colorspace;
csp.levels_in = priv->params.colorlevels;
csp.levels_out = priv->params.outputlevels;
mp_csp_set_image_params(&csp, &priv->params);
mp_csp_copy_equalizer_values(&csp, &priv->video_eq);
if (priv->use_shaders) {

View File

@ -1346,11 +1346,8 @@ static void update_yuvconv(struct vo *vo)
if (!vo->params)
return;
struct mp_csp_params cparams = {
.colorspace = vo->params->colorspace,
.levels_in = vo->params->colorlevels,
.levels_out = vo->params->outputlevels,
};
struct mp_csp_params cparams = MP_CSP_PARAMS_DEFAULTS;
mp_csp_set_image_params(&cparams, vo->params);
mp_csp_copy_equalizer_values(&cparams, &p->video_eq);
gl_conversion_params_t params = {
p->target, p->yuvconvtype, cparams,

View File

@ -197,9 +197,7 @@ static int create_vdp_mixer(struct mp_vdpau_mixer *mixer)
VdpCSCMatrix matrix;
struct mp_csp_params cparams = MP_CSP_PARAMS_DEFAULTS;
cparams.colorspace = mixer->image_params.colorspace;
cparams.levels_in = mixer->image_params.colorlevels;
cparams.levels_out = mixer->image_params.outputlevels;
mp_csp_set_image_params(&cparams, &mixer->image_params);
mp_csp_copy_equalizer_values(&cparams, &mixer->video_eq);
mp_get_yuv2rgb_coeffs(&cparams, matrix);