diff --git a/player/command.c b/player/command.c index d9f5dbc969..dc6b12a91c 100644 --- a/player/command.c +++ b/player/command.c @@ -2307,11 +2307,11 @@ static int property_imgparams(const struct mp_image_params *p, int action, void for (int i = 0; i < desc.num_planes; i++) bpp += desc.bpp[i] >> (desc.xs[i] + desc.ys[i]); - enum mp_alpha_type alpha = p->alpha; - // Alpha type is not supported by FFmpeg, so MP_ALPHA_AUTO may mean alpha + enum pl_alpha_mode alpha = p->repr.alpha; + // Alpha type is not supported by FFmpeg, so PL_ALPHA_UNKNOWN may mean alpha // is of an unknown type, or simply not present. Normalize to AUTO=no alpha. - if (!!(desc.flags & MP_IMGFLAG_ALPHA) != (alpha != MP_ALPHA_AUTO)) - alpha = (desc.flags & MP_IMGFLAG_ALPHA) ? MP_ALPHA_STRAIGHT : MP_ALPHA_AUTO; + if (!!(desc.flags & MP_IMGFLAG_ALPHA) != (alpha != PL_ALPHA_UNKNOWN)) + alpha = (desc.flags & MP_IMGFLAG_ALPHA) ? PL_ALPHA_INDEPENDENT : PL_ALPHA_UNKNOWN; const struct pl_hdr_metadata *hdr = &p->color.hdr; bool has_cie_y = pl_hdr_metadata_contains(hdr, PL_HDR_METADATA_CIE_Y); @@ -2357,9 +2357,9 @@ static int property_imgparams(const struct mp_image_params *p, int action, void SUB_PROP_STR(m_opt_choice_str(mp_stereo3d_names, p->stereo3d))}, {"rotate", SUB_PROP_INT(p->rotate)}, {"alpha", - SUB_PROP_STR(m_opt_choice_str(mp_alpha_names, alpha)), + SUB_PROP_STR(m_opt_choice_str(pl_alpha_names, alpha)), // avoid using "auto" for "no", so just make it unavailable - .unavailable = alpha == MP_ALPHA_AUTO}, + .unavailable = alpha == PL_ALPHA_UNKNOWN}, {"min-luma", SUB_PROP_FLOAT(hdr->min_luma), .unavailable = !has_hdr10}, {"max-luma", SUB_PROP_FLOAT(hdr->max_luma), .unavailable = !has_hdr10}, {"max-cll", SUB_PROP_FLOAT(hdr->max_cll), .unavailable = !has_hdr10}, diff --git a/sub/draw_bmp.c b/sub/draw_bmp.c index cde8f503f3..cf214401a8 100644 --- a/sub/draw_bmp.c +++ b/sub/draw_bmp.c @@ -431,7 +431,7 @@ static bool render_rgba(struct mp_draw_sub_cache *p, struct part *part, mp_image_set_size(&src_img, sw, sh); src_img.planes[0] = s_ptr; src_img.stride[0] = s_stride; - src_img.params.alpha = MP_ALPHA_PREMUL; + src_img.params.repr.alpha = PL_ALPHA_PREMULTIPLIED; scaled = mp_image_alloc(IMGFMT_BGRA, dw, dh); if (!scaled) @@ -525,7 +525,7 @@ static bool reinit_to_video(struct mp_draw_sub_cache *p) struct mp_image_params *params = &p->params; mp_image_params_guess_csp(params); - bool need_premul = params->alpha != MP_ALPHA_PREMUL && + bool need_premul = params->repr.alpha != PL_ALPHA_PREMULTIPLIED && (mp_imgfmt_get_desc(params->imgfmt).flags & MP_IMGFLAG_ALPHA); // Intermediate format for video_overlay. Requirements: @@ -660,7 +660,7 @@ static bool reinit_to_video(struct mp_draw_sub_cache *p) return false; mp_image_params_guess_csp(&p->rgba_overlay->params); - p->rgba_overlay->params.alpha = MP_ALPHA_PREMUL; + p->rgba_overlay->params.repr.alpha = PL_ALPHA_PREMULTIPLIED; p->overlay_tmp->params.color = params->color; p->video_tmp->params.color = params->color; @@ -677,7 +677,7 @@ static bool reinit_to_video(struct mp_draw_sub_cache *p) p->video_overlay->params.color = params->color; p->video_overlay->params.chroma_location = params->chroma_location; - p->video_overlay->params.alpha = MP_ALPHA_PREMUL; + p->video_overlay->params.repr.alpha = PL_ALPHA_PREMULTIPLIED; if (p->scale_in_tiles) p->video_overlay->params.chroma_location = MP_CHROMA_CENTER; @@ -762,7 +762,7 @@ static bool reinit_to_video(struct mp_draw_sub_cache *p) if (!p->premul_tmp) return false; mp_image_set_params(p->premul_tmp, params); - p->premul_tmp->params.alpha = MP_ALPHA_PREMUL; + p->premul_tmp->params.repr.alpha = PL_ALPHA_PREMULTIPLIED; // Only zimg supports this. p->premul->force_scaler = MP_SWS_ZIMG; @@ -787,7 +787,7 @@ static bool reinit_to_overlay(struct mp_draw_sub_cache *p) return false; mp_image_params_guess_csp(&p->rgba_overlay->params); - p->rgba_overlay->params.alpha = MP_ALPHA_PREMUL; + p->rgba_overlay->params.repr.alpha = PL_ALPHA_PREMULTIPLIED; // Some non-sense with the intention to somewhat isolate the returned image. mp_image_setfmt(&p->res_overlay, p->rgba_overlay->imgfmt); diff --git a/sub/draw_bmp.h b/sub/draw_bmp.h index fda7797c9e..b4c7378290 100644 --- a/sub/draw_bmp.h +++ b/sub/draw_bmp.h @@ -15,7 +15,7 @@ struct mp_draw_sub_cache *mp_draw_sub_alloc_test(struct mp_image *dst); // Render the sub-bitmaps in sbs_list to dst. sbs_list must have been rendered // for an OSD resolution equivalent to dst's size (UB if not). -// Warning: if dst is a format with alpha, and dst is not set to MP_ALPHA_PREMUL +// Warning: if dst is a format with alpha, and dst is not set to PL_ALPHA_PREMULTIPLIED // (not done by default), this will be extremely slow. // Warning: the caller is responsible for ensuring that dst is writable. // cache: allocated instance; caches non-changing OSD parts etc. diff --git a/video/csputils.c b/video/csputils.c index 3b43ba9f5b..e1b7823b33 100644 --- a/video/csputils.c +++ b/video/csputils.c @@ -112,10 +112,10 @@ const struct m_opt_choice_alternatives mp_chroma_names[] = { {0} }; -const struct m_opt_choice_alternatives mp_alpha_names[] = { - {"auto", MP_ALPHA_AUTO}, - {"straight", MP_ALPHA_STRAIGHT}, - {"premul", MP_ALPHA_PREMUL}, +const struct m_opt_choice_alternatives pl_alpha_names[] = { + {"auto", PL_ALPHA_UNKNOWN}, + {"straight", PL_ALPHA_INDEPENDENT}, + {"premul", PL_ALPHA_PREMULTIPLIED}, {0} }; diff --git a/video/csputils.h b/video/csputils.h index 80901659cf..ac37e205ab 100644 --- a/video/csputils.h +++ b/video/csputils.h @@ -120,14 +120,7 @@ enum mp_chroma_location { }; extern const struct m_opt_choice_alternatives mp_chroma_names[]; - -enum mp_alpha_type { - MP_ALPHA_AUTO, - MP_ALPHA_STRAIGHT, - MP_ALPHA_PREMUL, -}; - -extern const struct m_opt_choice_alternatives mp_alpha_names[]; +extern const struct m_opt_choice_alternatives pl_alpha_names[]; extern const struct m_sub_options mp_csp_equalizer_conf; diff --git a/video/filter/vf_format.c b/video/filter/vf_format.c index 4a14fc9102..6a3e9fd390 100644 --- a/video/filter/vf_format.c +++ b/video/filter/vf_format.c @@ -92,7 +92,7 @@ static void set_params(struct vf_format_opts *p, struct mp_image_params *out, if (p->rotate >= 0) out->rotate = p->rotate; if (p->alpha) - out->alpha = p->alpha; + out->repr.alpha = p->alpha; if (p->w > 0 && set_size) out->w = p->w; @@ -213,7 +213,7 @@ static const m_option_t vf_opts_fields[] = { {"chroma-location", OPT_CHOICE_C(chroma_location, mp_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, mp_alpha_names)}, + {"alpha", OPT_CHOICE_C(alpha, pl_alpha_names)}, {"w", OPT_INT(w)}, {"h", OPT_INT(h)}, {"dw", OPT_INT(dw)}, diff --git a/video/mp_image.c b/video/mp_image.c index b499d89f97..44bd6feaa6 100644 --- a/video/mp_image.c +++ b/video/mp_image.c @@ -523,7 +523,6 @@ void mp_image_copy_attributes(struct mp_image *dst, struct mp_image *src) dst->params.repr = src->params.repr; dst->params.light = src->params.light; dst->params.chroma_location = src->params.chroma_location; - dst->params.alpha = src->params.alpha; dst->params.crop = src->params.crop; dst->nominal_fps = src->nominal_fps; @@ -790,9 +789,9 @@ char *mp_image_params_to_str_buf(char *b, size_t bs, mp_snprintf_cat(b, bs, " stereo=%s", MP_STEREO3D_NAME_DEF(p->stereo3d, "?")); } - if (p->alpha) { + if (p->repr.alpha) { mp_snprintf_cat(b, bs, " A=%s", - m_opt_choice_str(mp_alpha_names, p->alpha)); + m_opt_choice_str(pl_alpha_names, p->repr.alpha)); } } else { snprintf(b, bs, "???"); @@ -842,7 +841,6 @@ bool mp_image_params_equal(const struct mp_image_params *p1, p1->chroma_location == p2->chroma_location && p1->rotate == p2->rotate && p1->stereo3d == p2->stereo3d && - p1->alpha == p2->alpha && mp_rect_equals(&p1->crop, &p2->crop); } @@ -1052,7 +1050,7 @@ struct mp_image *mp_image_from_av_frame(struct AVFrame *src) dst->params.stereo3d = p->stereo3d; // Might be incorrect if colorspace changes. dst->params.light = p->light; - dst->params.alpha = p->alpha; + dst->params.repr.alpha = p->repr.alpha; } sd = av_frame_get_side_data(src, AV_FRAME_DATA_DISPLAYMATRIX); diff --git a/video/mp_image.h b/video/mp_image.h index c1ba89ee0a..443488c9e1 100644 --- a/video/mp_image.h +++ b/video/mp_image.h @@ -54,7 +54,6 @@ struct mp_image_params { // The image should be rotated clockwise (0-359 degrees). int rotate; enum mp_stereo3d_mode stereo3d; // image is encoded with this mode - enum mp_alpha_type alpha; // usually auto; only set if explicitly known struct mp_rect crop; // crop applied on image }; diff --git a/video/out/gpu/video.c b/video/out/gpu/video.c index d685b978d2..6714ef04b1 100644 --- a/video/out/gpu/video.c +++ b/video/out/gpu/video.c @@ -2397,7 +2397,7 @@ static void pass_convert_yuv(struct gl_video *p) p->components = 3; if (!p->has_alpha || p->opts.alpha_mode == ALPHA_NO) { GLSL(color.a = 1.0;) - } else if (p->image_params.alpha == MP_ALPHA_PREMUL) { + } else if (p->image_params.repr.alpha == PL_ALPHA_PREMULTIPLIED) { p->components = 4; } else { p->components = 4; diff --git a/video/out/placebo/utils.c b/video/out/placebo/utils.c index b60e4ff5bc..ffba30401f 100644 --- a/video/out/placebo/utils.c +++ b/video/out/placebo/utils.c @@ -72,17 +72,6 @@ void mppl_log_set_probing(pl_log log, bool probing) pl_log_update(log, ¶ms); } -enum pl_alpha_mode mp_alpha_to_pl(enum mp_alpha_type alpha) -{ - switch (alpha) { - case MP_ALPHA_AUTO: return PL_ALPHA_UNKNOWN; - case MP_ALPHA_STRAIGHT: return PL_ALPHA_INDEPENDENT; - case MP_ALPHA_PREMUL: return PL_ALPHA_PREMULTIPLIED; - } - - MP_ASSERT_UNREACHABLE(); -} - enum pl_chroma_location mp_chroma_to_pl(enum mp_chroma_location chroma) { switch (chroma) { diff --git a/video/out/placebo/utils.h b/video/out/placebo/utils.h index 103fa4ce24..84b2e0468e 100644 --- a/video/out/placebo/utils.h +++ b/video/out/placebo/utils.h @@ -27,7 +27,6 @@ static inline struct pl_rect2d mp_rect2d_to_pl(struct mp_rect rc) }; } -enum pl_alpha_mode mp_alpha_to_pl(enum mp_alpha_type alpha); enum pl_chroma_location mp_chroma_to_pl(enum mp_chroma_location chroma); void mp_map_dovi_metadata_to_pl(struct mp_image *mpi, diff --git a/video/out/vo_gpu_next.c b/video/out/vo_gpu_next.c index dee8bc2301..fc9ccbe38d 100644 --- a/video/out/vo_gpu_next.c +++ b/video/out/vo_gpu_next.c @@ -575,7 +575,7 @@ static bool map_frame(pl_gpu gpu, pl_tex *tex, const struct pl_source_frame *src .repr = { .sys = par->repr.sys, .levels = par->repr.levels, - .alpha = mp_alpha_to_pl(par->alpha), + .alpha = par->repr.alpha, }, .profile = { .data = mpi->icc_profile ? mpi->icc_profile->data : NULL, diff --git a/video/zimg.c b/video/zimg.c index f744fe2c4b..4ea32af83a 100644 --- a/video/zimg.c +++ b/video/zimg.c @@ -375,7 +375,7 @@ static bool setup_format(zimg_image_format *zfmt, struct mp_zimg_repack *r, r->z_planes[3] = n; // alpha, always plane 4 in zimg #if HAVE_ZIMG_ALPHA - zfmt->alpha = fmt.alpha == MP_ALPHA_PREMUL + zfmt->alpha = fmt.repr.alpha == PL_ALPHA_PREMULTIPLIED ? ZIMG_ALPHA_PREMULTIPLIED : ZIMG_ALPHA_STRAIGHT; #else return false;