mirror of https://github.com/mpv-player/mpv
csputils: replace mp_chroma_location with pl_chroma_location
This commit is contained in:
parent
0ac7a40dac
commit
47be5ad4aa
|
@ -2352,7 +2352,7 @@ static int property_imgparams(const struct mp_image_params *p, int action, void
|
|||
{"light",
|
||||
SUB_PROP_STR(m_opt_choice_str(mp_csp_light_names, p->light))},
|
||||
{"chroma-location",
|
||||
SUB_PROP_STR(m_opt_choice_str(mp_chroma_names, p->chroma_location))},
|
||||
SUB_PROP_STR(m_opt_choice_str(pl_chroma_names, p->chroma_location))},
|
||||
{"stereo-in",
|
||||
SUB_PROP_STR(m_opt_choice_str(mp_stereo3d_names, p->stereo3d))},
|
||||
{"rotate", SUB_PROP_INT(p->rotate)},
|
||||
|
|
|
@ -680,7 +680,7 @@ static bool reinit_to_video(struct mp_draw_sub_cache *p)
|
|||
p->video_overlay->params.repr.alpha = PL_ALPHA_PREMULTIPLIED;
|
||||
|
||||
if (p->scale_in_tiles)
|
||||
p->video_overlay->params.chroma_location = MP_CHROMA_CENTER;
|
||||
p->video_overlay->params.chroma_location = PL_CHROMA_CENTER;
|
||||
|
||||
p->rgba_to_overlay = alloc_scaler(p);
|
||||
p->rgba_to_overlay->allow_zimg = true;
|
||||
|
|
|
@ -104,11 +104,14 @@ const struct m_opt_choice_alternatives mp_csp_light_names[] = {
|
|||
{0}
|
||||
};
|
||||
|
||||
const struct m_opt_choice_alternatives mp_chroma_names[] = {
|
||||
{"unknown", MP_CHROMA_AUTO},
|
||||
{"uhd", MP_CHROMA_TOPLEFT},
|
||||
{"mpeg2/4/h264",MP_CHROMA_LEFT},
|
||||
{"mpeg1/jpeg", MP_CHROMA_CENTER},
|
||||
const struct m_opt_choice_alternatives pl_chroma_names[] = {
|
||||
{"unknown", PL_CHROMA_UNKNOWN},
|
||||
{"uhd", PL_CHROMA_TOP_LEFT},
|
||||
{"mpeg2/4/h264",PL_CHROMA_LEFT},
|
||||
{"mpeg1/jpeg", PL_CHROMA_CENTER},
|
||||
{"top", PL_CHROMA_TOP_CENTER},
|
||||
{"bottom left", PL_CHROMA_BOTTOM_LEFT},
|
||||
{"bottom", PL_CHROMA_BOTTOM_CENTER},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
@ -167,38 +170,6 @@ enum pl_color_primaries mp_csp_guess_primaries(int width, int height)
|
|||
}
|
||||
}
|
||||
|
||||
enum mp_chroma_location avchroma_location_to_mp(int avloc)
|
||||
{
|
||||
switch (avloc) {
|
||||
case AVCHROMA_LOC_TOPLEFT: return MP_CHROMA_TOPLEFT;
|
||||
case AVCHROMA_LOC_LEFT: return MP_CHROMA_LEFT;
|
||||
case AVCHROMA_LOC_CENTER: return MP_CHROMA_CENTER;
|
||||
default: return MP_CHROMA_AUTO;
|
||||
}
|
||||
}
|
||||
|
||||
int mp_chroma_location_to_av(enum mp_chroma_location mploc)
|
||||
{
|
||||
switch (mploc) {
|
||||
case MP_CHROMA_TOPLEFT: return AVCHROMA_LOC_TOPLEFT;
|
||||
case MP_CHROMA_LEFT: return AVCHROMA_LOC_LEFT;
|
||||
case MP_CHROMA_CENTER: return AVCHROMA_LOC_CENTER;
|
||||
default: return AVCHROMA_LOC_UNSPECIFIED;
|
||||
}
|
||||
}
|
||||
|
||||
// Return location of chroma samples relative to luma samples. 0/0 means
|
||||
// centered. Other possible values are -1 (top/left) and +1 (right/bottom).
|
||||
void mp_get_chroma_location(enum mp_chroma_location loc, int *x, int *y)
|
||||
{
|
||||
*x = 0;
|
||||
*y = 0;
|
||||
if (loc == MP_CHROMA_LEFT || loc == MP_CHROMA_TOPLEFT)
|
||||
*x = -1;
|
||||
if (loc == MP_CHROMA_TOPLEFT)
|
||||
*y = -1;
|
||||
}
|
||||
|
||||
void mp_invert_matrix3x3(float m[3][3])
|
||||
{
|
||||
float m00 = m[0][0], m01 = m[0][1], m02 = m[0][2],
|
||||
|
|
|
@ -111,15 +111,7 @@ 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_TOPLEFT, // uhd
|
||||
MP_CHROMA_LEFT, // mpeg2/4, h264
|
||||
MP_CHROMA_CENTER, // mpeg1, jpeg
|
||||
MP_CHROMA_COUNT,
|
||||
};
|
||||
|
||||
extern const struct m_opt_choice_alternatives mp_chroma_names[];
|
||||
extern const struct m_opt_choice_alternatives pl_chroma_names[];
|
||||
extern const struct m_opt_choice_alternatives pl_alpha_names[];
|
||||
|
||||
extern const struct m_sub_options mp_csp_equalizer_conf;
|
||||
|
@ -150,10 +142,6 @@ struct mp_csp_primaries {
|
|||
enum pl_color_system mp_csp_guess_colorspace(int width, int height);
|
||||
enum pl_color_primaries mp_csp_guess_primaries(int width, int height);
|
||||
|
||||
enum mp_chroma_location avchroma_location_to_mp(int avloc);
|
||||
int mp_chroma_location_to_av(enum mp_chroma_location mploc);
|
||||
void mp_get_chroma_location(enum mp_chroma_location loc, int *x, int *y);
|
||||
|
||||
struct mp_csp_primaries mp_get_csp_primaries(enum pl_color_primaries csp);
|
||||
float mp_trc_nom_peak(enum pl_color_transfer trc);
|
||||
bool mp_trc_is_hdr(enum pl_color_transfer trc);
|
||||
|
|
|
@ -210,7 +210,7 @@ static const m_option_t vf_opts_fields[] = {
|
|||
{"gamma", OPT_CHOICE_C(gamma, pl_csp_trc_names)},
|
||||
{"sig-peak", OPT_FLOAT(sig_peak)},
|
||||
{"light", OPT_CHOICE_C(light, mp_csp_light_names)},
|
||||
{"chroma-location", OPT_CHOICE_C(chroma_location, mp_chroma_names)},
|
||||
{"chroma-location", OPT_CHOICE_C(chroma_location, pl_chroma_names)},
|
||||
{"stereo-in", OPT_CHOICE_C(stereo_in, mp_stereo3d_names)},
|
||||
{"rotate", OPT_INT(rotate), M_RANGE(-1, 359)},
|
||||
{"alpha", OPT_CHOICE_C(alpha, pl_alpha_names)},
|
||||
|
|
|
@ -194,7 +194,7 @@ static void copy_mp_to_vs_frame_props_map(struct priv *p, VSMap *map,
|
|||
pl_system_to_av(params->repr.sys), 0);
|
||||
if (params->chroma_location) {
|
||||
p->vsapi->propSetInt(map, "_ChromaLocation",
|
||||
params->chroma_location == MP_CHROMA_CENTER, 0);
|
||||
params->chroma_location == PL_CHROMA_CENTER, 0);
|
||||
}
|
||||
char pict_type = 0;
|
||||
switch (img->pict_type) {
|
||||
|
|
|
@ -147,7 +147,7 @@ static void prepare_avframe(AVFrame *pic, AVCodecContext *avctx,
|
|||
avctx->colorspace = pic->colorspace =
|
||||
pl_system_to_av(image->params.repr.sys);
|
||||
avctx->chroma_sample_location = pic->chroma_location =
|
||||
mp_chroma_location_to_av(image->params.chroma_location);
|
||||
pl_chroma_to_av(image->params.chroma_location);
|
||||
mp_dbg(log, "mapped color params:\n"
|
||||
" trc = %s\n"
|
||||
" primaries = %s\n"
|
||||
|
@ -645,7 +645,7 @@ static struct mp_image *convert_image(struct mp_image *image, int destfmt,
|
|||
if (p.repr.sys != PL_COLOR_SYSTEM_RGB) {
|
||||
p.repr.levels = yuv_levels;
|
||||
p.repr.sys = PL_COLOR_SYSTEM_BT_601;
|
||||
p.chroma_location = MP_CHROMA_CENTER;
|
||||
p.chroma_location = PL_CHROMA_CENTER;
|
||||
}
|
||||
mp_image_params_guess_csp(&p);
|
||||
}
|
||||
|
|
|
@ -778,7 +778,7 @@ char *mp_image_params_to_str_buf(char *b, size_t bs,
|
|||
m_opt_choice_str(pl_csp_levels_names, p->repr.levels),
|
||||
m_opt_choice_str(mp_csp_light_names, p->light));
|
||||
mp_snprintf_cat(b, bs, " CL=%s",
|
||||
m_opt_choice_str(mp_chroma_names, p->chroma_location));
|
||||
m_opt_choice_str(pl_chroma_names, p->chroma_location));
|
||||
if (mp_image_crop_valid(p)) {
|
||||
mp_snprintf_cat(b, bs, " crop=%dx%d+%d+%d", mp_rect_w(p->crop),
|
||||
mp_rect_h(p->crop), p->crop.x0, p->crop.y0);
|
||||
|
@ -971,11 +971,11 @@ void mp_image_params_guess_csp(struct mp_image_params *params)
|
|||
params->color.hdr = pl_hdr_metadata_empty;
|
||||
}
|
||||
|
||||
if (params->chroma_location == MP_CHROMA_AUTO) {
|
||||
if (params->chroma_location == PL_CHROMA_UNKNOWN) {
|
||||
if (params->repr.levels == PL_COLOR_LEVELS_LIMITED)
|
||||
params->chroma_location = MP_CHROMA_LEFT;
|
||||
params->chroma_location = PL_CHROMA_LEFT;
|
||||
if (params->repr.levels == PL_COLOR_LEVELS_FULL)
|
||||
params->chroma_location = MP_CHROMA_CENTER;
|
||||
params->chroma_location = PL_CHROMA_CENTER;
|
||||
}
|
||||
|
||||
if (params->light == MP_CSP_LIGHT_AUTO) {
|
||||
|
@ -1043,7 +1043,7 @@ struct mp_image *mp_image_from_av_frame(struct AVFrame *src)
|
|||
.transfer = pl_transfer_from_av(src->color_trc),
|
||||
};
|
||||
|
||||
dst->params.chroma_location = avchroma_location_to_mp(src->chroma_location);
|
||||
dst->params.chroma_location = pl_chroma_from_av(src->chroma_location);
|
||||
|
||||
if (src->opaque_ref) {
|
||||
struct mp_image_params *p = (void *)src->opaque_ref->data;
|
||||
|
@ -1172,7 +1172,7 @@ struct AVFrame *mp_image_to_av_frame(struct mp_image *src)
|
|||
pl_primaries_to_av(src->params.color.primaries);
|
||||
dst->color_trc = pl_transfer_to_av(src->params.color.transfer);
|
||||
|
||||
dst->chroma_location = mp_chroma_location_to_av(src->params.chroma_location);
|
||||
dst->chroma_location = pl_chroma_to_av(src->params.chroma_location);
|
||||
|
||||
dst->opaque_ref = av_buffer_alloc(sizeof(struct mp_image_params));
|
||||
MP_HANDLE_OOM(dst->opaque_ref);
|
||||
|
|
|
@ -50,7 +50,7 @@ struct mp_image_params {
|
|||
struct pl_color_space color;
|
||||
struct pl_color_repr repr;
|
||||
enum mp_csp_light light;
|
||||
enum mp_chroma_location chroma_location;
|
||||
enum pl_chroma_location chroma_location;
|
||||
// The image should be rotated clockwise (0-359 degrees).
|
||||
int rotate;
|
||||
enum mp_stereo3d_mode stereo3d; // image is encoded with this mode
|
||||
|
|
|
@ -762,16 +762,16 @@ static void pass_get_images(struct gl_video *p, struct video_image *vimg,
|
|||
|
||||
struct gl_transform chroma = {{{ls_w, 0.0}, {0.0, ls_h}}};
|
||||
|
||||
if (p->image_params.chroma_location != MP_CHROMA_CENTER) {
|
||||
int cx, cy;
|
||||
mp_get_chroma_location(p->image_params.chroma_location, &cx, &cy);
|
||||
if (p->image_params.chroma_location != PL_CHROMA_CENTER) {
|
||||
float cx, cy;
|
||||
pl_chroma_location_offset(p->image_params.chroma_location, &cx, &cy);
|
||||
// By default texture coordinates are such that chroma is centered with
|
||||
// any chroma subsampling. If a specific direction is given, make it
|
||||
// so that the luma and chroma sample line up exactly.
|
||||
// For 4:4:4, setting chroma location should have no effect at all.
|
||||
// luma sample size (in chroma coord. space)
|
||||
chroma.t[0] = ls_w < 1 ? ls_w * -cx / 2 : 0;
|
||||
chroma.t[1] = ls_h < 1 ? ls_h * -cy / 2 : 0;
|
||||
chroma.t[0] = ls_w < 1 ? ls_w * -cx : 0;
|
||||
chroma.t[1] = ls_h < 1 ? ls_h * -cy : 0;
|
||||
}
|
||||
|
||||
memset(img, 0, 4 * sizeof(img[0]));
|
||||
|
|
|
@ -72,19 +72,6 @@ void mppl_log_set_probing(pl_log log, bool probing)
|
|||
pl_log_update(log, ¶ms);
|
||||
}
|
||||
|
||||
enum pl_chroma_location mp_chroma_to_pl(enum mp_chroma_location chroma)
|
||||
{
|
||||
switch (chroma) {
|
||||
case MP_CHROMA_AUTO: return PL_CHROMA_UNKNOWN;
|
||||
case MP_CHROMA_TOPLEFT: return PL_CHROMA_TOP_LEFT;
|
||||
case MP_CHROMA_LEFT: return PL_CHROMA_LEFT;
|
||||
case MP_CHROMA_CENTER: return PL_CHROMA_CENTER;
|
||||
case MP_CHROMA_COUNT: return PL_CHROMA_COUNT;
|
||||
}
|
||||
|
||||
MP_ASSERT_UNREACHABLE();
|
||||
}
|
||||
|
||||
void mp_map_dovi_metadata_to_pl(struct mp_image *mpi,
|
||||
struct pl_frame *frame)
|
||||
{
|
||||
|
|
|
@ -27,7 +27,5 @@ static inline struct pl_rect2d mp_rect2d_to_pl(struct mp_rect rc)
|
|||
};
|
||||
}
|
||||
|
||||
enum pl_chroma_location mp_chroma_to_pl(enum mp_chroma_location chroma);
|
||||
|
||||
void mp_map_dovi_metadata_to_pl(struct mp_image *mpi,
|
||||
struct pl_frame *frame);
|
||||
|
|
|
@ -664,7 +664,7 @@ static bool map_frame(pl_gpu gpu, pl_tex *tex, const struct pl_source_frame *src
|
|||
}
|
||||
|
||||
// Update chroma location, must be done after initializing planes
|
||||
pl_frame_set_chroma_location(frame, mp_chroma_to_pl(par->chroma_location));
|
||||
pl_frame_set_chroma_location(frame, par->chroma_location);
|
||||
|
||||
// Set the frame DOVI metadata
|
||||
mp_map_dovi_metadata_to_pl(mpi, frame);
|
||||
|
|
|
@ -309,8 +309,8 @@ int mp_sws_reinit(struct mp_sws_context *ctx)
|
|||
av_opt_set_double(ctx->sws, "param0", ctx->params[0], 0);
|
||||
av_opt_set_double(ctx->sws, "param1", ctx->params[1], 0);
|
||||
|
||||
int cr_src = mp_chroma_location_to_av(src.chroma_location);
|
||||
int cr_dst = mp_chroma_location_to_av(dst.chroma_location);
|
||||
int cr_src = pl_chroma_to_av(src.chroma_location);
|
||||
int cr_dst = pl_chroma_to_av(dst.chroma_location);
|
||||
int cr_xpos, cr_ypos;
|
||||
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 37, 100)
|
||||
if (av_chroma_location_enum_to_pos(&cr_xpos, &cr_ypos, cr_src) >= 0) {
|
||||
|
|
15
video/zimg.c
15
video/zimg.c
|
@ -121,13 +121,16 @@ static void mp_zimg_update_from_cmdline(struct mp_zimg_context *ctx)
|
|||
ctx->opts = *opts;
|
||||
}
|
||||
|
||||
static zimg_chroma_location_e mp_to_z_chroma(enum mp_chroma_location cl)
|
||||
static zimg_chroma_location_e pl_to_z_chroma(enum pl_chroma_location cl)
|
||||
{
|
||||
switch (cl) {
|
||||
case MP_CHROMA_TOPLEFT: return ZIMG_CHROMA_TOP_LEFT;
|
||||
case MP_CHROMA_LEFT: return ZIMG_CHROMA_LEFT;
|
||||
case MP_CHROMA_CENTER: return ZIMG_CHROMA_CENTER;
|
||||
default: return ZIMG_CHROMA_LEFT;
|
||||
case PL_CHROMA_LEFT: return ZIMG_CHROMA_LEFT;
|
||||
case PL_CHROMA_CENTER: return ZIMG_CHROMA_CENTER;
|
||||
case PL_CHROMA_TOP_LEFT: return ZIMG_CHROMA_TOP_LEFT;
|
||||
case PL_CHROMA_TOP_CENTER: return ZIMG_CHROMA_TOP;
|
||||
case PL_CHROMA_BOTTOM_LEFT: return ZIMG_CHROMA_BOTTOM_LEFT;
|
||||
case PL_CHROMA_BOTTOM_CENTER: return ZIMG_CHROMA_BOTTOM;
|
||||
default: return ZIMG_CHROMA_LEFT;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -450,7 +453,7 @@ static bool setup_format(zimg_image_format *zfmt, struct mp_zimg_repack *r,
|
|||
zfmt->color_primaries = fmt.repr.sys == PL_COLOR_SYSTEM_XYZ
|
||||
? ZIMG_PRIMARIES_ST428
|
||||
: mp_to_z_prim(fmt.color.primaries);
|
||||
zfmt->chroma_location = mp_to_z_chroma(fmt.chroma_location);
|
||||
zfmt->chroma_location = pl_to_z_chroma(fmt.chroma_location);
|
||||
|
||||
if (ctx && ctx->opts.fast) {
|
||||
// mpv's default for RGB output slows down zimg significantly.
|
||||
|
|
Loading…
Reference in New Issue