diff --git a/filters/f_swscale.c b/filters/f_swscale.c index 89fc2bb3fc..8e684d5507 100644 --- a/filters/f_swscale.c +++ b/filters/f_swscale.c @@ -105,6 +105,7 @@ static void sws_process(struct mp_filter *f) goto error; mp_image_copy_attributes(dst, src); + mp_image_setfmt(dst, dstfmt); if (s->use_out_params) dst->params = s->out_params; diff --git a/test/img_format.c b/test/img_format.c index 835c34acaf..c0a6480cac 100644 --- a/test/img_format.c +++ b/test/img_format.c @@ -84,6 +84,24 @@ int main(int argc, char *argv[]) fprintf(f, " endian_bytes=%d", 1 << d.endian_shift); for (int x = 0; x < MP_NUM_COMPONENTS; x++) { struct mp_imgfmt_comp_desc cm = d.comps[x]; + if (avd && x < avd->nb_components) { + const AVComponentDescriptor *cd = &avd->comp[x]; + // Validate only if padding is not 0. fill_pixdesc_layout() + // uses some heuristics to convert AVComponentDescriptor + // to mp_imgfmt_comp_desc. Some formats, mostly packed ones, + // are not fully supported. See fill_pixdesc_layout() + // for more details. + if (cm.pad) { + struct pl_bit_encoding be = { + .sample_depth = cm.size, + .color_depth = cm.size - abs(cm.pad), + .bit_shift = MPMAX(0, cm.pad), + }; + mp_require(be.color_depth == cd->depth); + mp_require(be.sample_depth == MP_ALIGN_UP(cd->depth, 8)); + mp_require(be.bit_shift == cd->shift); + } + } fprintf(f, " {"); if (cm.plane == n) { if (cm.size) { diff --git a/video/mp_image.c b/video/mp_image.c index 7890b9f9f4..1c629a6287 100644 --- a/video/mp_image.c +++ b/video/mp_image.c @@ -194,6 +194,17 @@ void mp_image_setfmt(struct mp_image *mpi, int out_fmt) mpi->fmt = fmt; mpi->imgfmt = fmt.id; mpi->num_planes = fmt.num_planes; + mpi->params.repr.alpha = (fmt.flags & MP_IMGFLAG_ALPHA) ? PL_ALPHA_INDEPENDENT +#if PL_API_VER >= 344 + : PL_ALPHA_NONE; +#else + : PL_ALPHA_UNKNOWN; +#endif + mpi->params.repr.bits = (struct pl_bit_encoding) { + .sample_depth = fmt.comps[0].size, + .color_depth = fmt.comps[0].size - abs(fmt.comps[0].pad), + .bit_shift = MPMAX(0, fmt.comps[0].pad), + }; } static void mp_image_destructor(void *ptr) @@ -1073,10 +1084,8 @@ struct mp_image *mp_image_from_av_frame(struct AVFrame *src) if (src->repeat_pict == 1) dst->fields |= MP_IMGFIELD_REPEAT_FIRST; - dst->params.repr = (struct pl_color_repr){ - .sys = pl_system_from_av(src->colorspace), - .levels = pl_levels_from_av(src->color_range), - }; + dst->params.repr.sys = pl_system_from_av(src->colorspace); + dst->params.repr.levels = pl_levels_from_av(src->color_range); dst->params.color = (struct pl_color_space){ .primaries = pl_primaries_from_av(src->color_primaries),