diff options
author | Kacper Michajłow <kasper93@gmail.com> | 2023-11-04 05:15:27 +0100 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2024-01-22 14:54:55 +0000 |
commit | 47be5ad4aaa20df4bb1577110198d5aab3c88925 (patch) | |
tree | 6829c9e597217dd2b928e3e5f474adcbf0eadc06 | |
parent | 0ac7a40dac2411cf9be429f611b8966560bb3f0c (diff) | |
download | mpv-47be5ad4aaa20df4bb1577110198d5aab3c88925.tar.bz2 mpv-47be5ad4aaa20df4bb1577110198d5aab3c88925.tar.xz |
csputils: replace mp_chroma_location with pl_chroma_location
-rw-r--r-- | player/command.c | 2 | ||||
-rw-r--r-- | sub/draw_bmp.c | 2 | ||||
-rw-r--r-- | video/csputils.c | 45 | ||||
-rw-r--r-- | video/csputils.h | 14 | ||||
-rw-r--r-- | video/filter/vf_format.c | 2 | ||||
-rw-r--r-- | video/filter/vf_vapoursynth.c | 2 | ||||
-rw-r--r-- | video/image_writer.c | 4 | ||||
-rw-r--r-- | video/mp_image.c | 12 | ||||
-rw-r--r-- | video/mp_image.h | 2 | ||||
-rw-r--r-- | video/out/gpu/video.c | 10 | ||||
-rw-r--r-- | video/out/placebo/utils.c | 13 | ||||
-rw-r--r-- | video/out/placebo/utils.h | 2 | ||||
-rw-r--r-- | video/out/vo_gpu_next.c | 2 | ||||
-rw-r--r-- | video/sws_utils.c | 4 | ||||
-rw-r--r-- | video/zimg.c | 15 |
15 files changed, 39 insertions, 92 deletions
diff --git a/player/command.c b/player/command.c index dc6b12a91c..49bd6b72e1 100644 --- a/player/command.c +++ b/player/command.c @@ -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)}, diff --git a/sub/draw_bmp.c b/sub/draw_bmp.c index cf214401a8..9052922115 100644 --- a/sub/draw_bmp.c +++ b/sub/draw_bmp.c @@ -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; diff --git a/video/csputils.c b/video/csputils.c index e1b7823b33..6b708f7525 100644 --- a/video/csputils.c +++ b/video/csputils.c @@ -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], diff --git a/video/csputils.h b/video/csputils.h index ac37e205ab..9b2d0378df 100644 --- a/video/csputils.h +++ b/video/csputils.h @@ -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); diff --git a/video/filter/vf_format.c b/video/filter/vf_format.c index 6a3e9fd390..2063045864 100644 --- a/video/filter/vf_format.c +++ b/video/filter/vf_format.c @@ -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)}, diff --git a/video/filter/vf_vapoursynth.c b/video/filter/vf_vapoursynth.c index 5a3ce423d1..0b798c8daf 100644 --- a/video/filter/vf_vapoursynth.c +++ b/video/filter/vf_vapoursynth.c @@ -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) { diff --git a/video/image_writer.c b/video/image_writer.c index 9c6ec16c3a..e86c255811 100644 --- a/video/image_writer.c +++ b/video/image_writer.c @@ -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); } diff --git a/video/mp_image.c b/video/mp_image.c index 44bd6feaa6..b86ecb9b6a 100644 --- a/video/mp_image.c +++ b/video/mp_image.c @@ -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); diff --git a/video/mp_image.h b/video/mp_image.h index 443488c9e1..149b63ead1 100644 --- a/video/mp_image.h +++ b/video/mp_image.h @@ -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 diff --git a/video/out/gpu/video.c b/video/out/gpu/video.c index 6714ef04b1..5e0175366a 100644 --- a/video/out/gpu/video.c +++ b/video/out/gpu/video.c @@ -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])); diff --git a/video/out/placebo/utils.c b/video/out/placebo/utils.c index ffba30401f..e01c371039 100644 --- a/video/out/placebo/utils.c +++ b/video/out/placebo/utils.c @@ -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) { diff --git a/video/out/placebo/utils.h b/video/out/placebo/utils.h index 84b2e0468e..d2fa619b4a 100644 --- a/video/out/placebo/utils.h +++ b/video/out/placebo/utils.h @@ -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); diff --git a/video/out/vo_gpu_next.c b/video/out/vo_gpu_next.c index fc9ccbe38d..06a9ce4a4f 100644 --- a/video/out/vo_gpu_next.c +++ b/video/out/vo_gpu_next.c @@ -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); diff --git a/video/sws_utils.c b/video/sws_utils.c index 9844dd62eb..a07bb55424 100644 --- a/video/sws_utils.c +++ b/video/sws_utils.c @@ -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) { diff --git a/video/zimg.c b/video/zimg.c index 4ea32af83a..35a987dfea 100644 --- a/video/zimg.c +++ b/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. |