mirror of
https://github.com/mpv-player/mpv
synced 2025-03-20 02:09:52 +00:00
vd_lavc: decode embedded ICC profiles
Since these need to be refcounted, we throw them directly into struct mp_image instead of being part of mp_colorspace. Even though they would semantically make more sense in mp_colorspace, having them there is really awkward because mp_colorspace is passed around and stored a lot, and this way their lifetime is exactly tied to the lifetime of the mp_image associated with it.
This commit is contained in:
parent
0f956f0929
commit
1aab037601
@ -1184,6 +1184,12 @@ static bool decode_frame(struct dec_video *vd)
|
||||
mp_pts_from_av(av_frame_get_pkt_duration(ctx->pic), &ctx->codec_timebase);
|
||||
#endif
|
||||
|
||||
#if HAVE_AVUTIL_ICC_PROFILE
|
||||
sd = av_frame_get_side_data(ctx->pic, AV_FRAME_DATA_ICC_PROFILE);
|
||||
if (sd)
|
||||
mpi->icc_profile = av_buffer_ref(sd->buf);
|
||||
#endif
|
||||
|
||||
update_image_params(vd, ctx->pic, &mpi->params);
|
||||
|
||||
av_frame_unref(ctx->pic);
|
||||
|
@ -200,6 +200,7 @@ static void mp_image_destructor(void *ptr)
|
||||
for (int p = 0; p < MP_MAX_PLANES; p++)
|
||||
av_buffer_unref(&mpi->bufs[p]);
|
||||
av_buffer_unref(&mpi->hwctx);
|
||||
av_buffer_unref(&mpi->icc_profile);
|
||||
}
|
||||
|
||||
int mp_chroma_div_up(int size, int shift)
|
||||
@ -316,6 +317,12 @@ struct mp_image *mp_image_new_ref(struct mp_image *img)
|
||||
fail = true;
|
||||
}
|
||||
|
||||
if (new->icc_profile) {
|
||||
new->icc_profile = av_buffer_ref(new->icc_profile);
|
||||
if (!new->icc_profile)
|
||||
fail = true;
|
||||
}
|
||||
|
||||
if (!fail)
|
||||
return new;
|
||||
|
||||
@ -525,6 +532,13 @@ void mp_image_copy_attributes(struct mp_image *dst, struct mp_image *src)
|
||||
memcpy(dst->planes[1], src->planes[1], MP_PALETTE_SIZE);
|
||||
}
|
||||
}
|
||||
av_buffer_unref(&dst->icc_profile);
|
||||
dst->icc_profile = src->icc_profile;
|
||||
if (dst->icc_profile) {
|
||||
dst->icc_profile = av_buffer_ref(dst->icc_profile);
|
||||
if (!dst->icc_profile)
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
// Crop the given image to (x0, y0)-(x1, y1) (bottom/right border exclusive)
|
||||
|
@ -100,6 +100,8 @@ typedef struct mp_image {
|
||||
struct AVBufferRef *bufs[MP_MAX_PLANES];
|
||||
// Points to AVHWFramesContext* (same as AVFrame.hw_frames_ctx)
|
||||
struct AVBufferRef *hwctx;
|
||||
// Embedded ICC profile, if any
|
||||
struct AVBufferRef *icc_profile;
|
||||
} mp_image_t;
|
||||
|
||||
int mp_chroma_div_up(int size, int shift);
|
||||
|
6
wscript
6
wscript
@ -461,6 +461,12 @@ FFmpeg/Libav libraries. You need at least {0}. Aborting.".format(libav_versions_
|
||||
'func': check_statement('libavutil/frame.h',
|
||||
'AV_FRAME_DATA_CONTENT_LIGHT_LEVEL',
|
||||
use='libav'),
|
||||
}, {
|
||||
'name': 'avutil-icc-profile',
|
||||
'desc': 'libavutil ICC profile side data',
|
||||
'func': check_statement('libavutil/frame.h',
|
||||
'AV_FRAME_DATA_ICC_PROFILE',
|
||||
use='libav'),
|
||||
},
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user