mp_image: set repr.alpha and repr.bits when mapping AVFrame

Fixes invalid colors with gpu-next direct mapping of some formats.
This commit is contained in:
Kacper Michajłow committed 2025-03-26 18:39:40 +01:00
1 parent d9f27bd0f1
commit 74d3c2f0e7
3 files changed
+32 -4

No files matched your search

+1
View File
@@ -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;
+18
View File
@@ -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) {
+13 -4
View File
@@ -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),