diff options
author | wm4 <wm4@nowhere> | 2012-10-27 18:06:09 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2012-11-01 02:07:45 +0100 |
commit | 9ba52ea6efd41db9dbd08311380f7fa633e22aa2 (patch) | |
tree | 698757630c88e96f323bc66461045234505ace91 /libmpcodecs | |
parent | d9839fe8623c855b6b335df3a5b9783e3ed22266 (diff) | |
download | mpv-9ba52ea6efd41db9dbd08311380f7fa633e22aa2.tar.bz2 mpv-9ba52ea6efd41db9dbd08311380f7fa633e22aa2.tar.xz |
screenshot, draw_bmp: use colorspace passed with mp_image
Remove the explicit struct mp_csp_details parameters from all related
functions, and use mp_image.colorspace/levels instead.
Diffstat (limited to 'libmpcodecs')
-rw-r--r-- | libmpcodecs/sws_utils.c | 67 | ||||
-rw-r--r-- | libmpcodecs/sws_utils.h | 4 | ||||
-rw-r--r-- | libmpcodecs/vf_sub.c | 7 |
3 files changed, 54 insertions, 24 deletions
diff --git a/libmpcodecs/sws_utils.c b/libmpcodecs/sws_utils.c index d7500efe2e..4fc5639e55 100644 --- a/libmpcodecs/sws_utils.c +++ b/libmpcodecs/sws_utils.c @@ -18,6 +18,8 @@ #include <assert.h> +#include <libavutil/opt.h> + #include "libmpcodecs/sws_utils.h" #include "libmpcodecs/mp_image.h" @@ -139,27 +141,58 @@ bool mp_sws_supported_format(int imgfmt) && sws_isSupportedOutput(av_format); } -void mp_image_swscale(struct mp_image *dst, - const struct mp_image *src, - struct mp_csp_details *csp, +static int mp_csp_to_sws_colorspace(enum mp_csp csp) +{ + switch (csp) { + case MP_CSP_BT_601: return SWS_CS_ITU601; + case MP_CSP_BT_709: return SWS_CS_ITU709; + case MP_CSP_SMPTE_240M: return SWS_CS_SMPTE240M; + default: return SWS_CS_DEFAULT; + } +} + +void mp_image_swscale(struct mp_image *dst, struct mp_image *src, int my_sws_flags) { - enum PixelFormat dfmt, sfmt; - dfmt = imgfmt2pixfmt(dst->imgfmt); - sfmt = imgfmt2pixfmt(src->imgfmt); + enum PixelFormat s_fmt = imgfmt2pixfmt(src->imgfmt); if (src->imgfmt == IMGFMT_RGB8 || src->imgfmt == IMGFMT_BGR8) - sfmt = PIX_FMT_PAL8; + s_fmt = PIX_FMT_PAL8; + int s_csp = mp_csp_to_sws_colorspace(mp_image_csp(src)); + int s_range = mp_image_levels(src) == MP_CSP_LEVELS_PC; + + enum PixelFormat d_fmt = imgfmt2pixfmt(dst->imgfmt); + int d_csp = mp_csp_to_sws_colorspace(mp_image_csp(dst)); + int d_range = mp_image_levels(dst) == MP_CSP_LEVELS_PC; + + // Work around libswscale bug #1852 (fixed in ffmpeg commit 8edf9b1fa): + // setting range flags for RGB gives random bogus results. + // Newer libswscale always ignores range flags for RGB. + bool s_yuv = src->flags & MP_IMGFLAG_YUV; + bool d_yuv = dst->flags & MP_IMGFLAG_YUV; + s_range = s_range && s_yuv; + d_range = d_range && d_yuv; + + struct SwsContext *sws = sws_alloc_context(); + + av_opt_set_int(sws, "sws_flags", my_sws_flags, 0); + + av_opt_set_int(sws, "srcw", src->w, 0); + av_opt_set_int(sws, "srch", src->h, 0); + av_opt_set_int(sws, "src_format", s_fmt, 0); + + av_opt_set_int(sws, "dstw", dst->w, 0); + av_opt_set_int(sws, "dsth", dst->h, 0); + av_opt_set_int(sws, "dst_format", d_fmt, 0); + + sws_setColorspaceDetails(sws, sws_getCoefficients(s_csp), s_range, + sws_getCoefficients(d_csp), d_range, + 0, 1 << 16, 1 << 16); + + int res = sws_init_context(sws, NULL, NULL); + assert(res >= 0); - struct SwsContext *sws = - sws_getContext(src->w, src->h, sfmt, dst->w, dst->h, dfmt, - my_sws_flags, NULL, NULL, NULL); - struct mp_csp_details mycsp = MP_CSP_DETAILS_DEFAULTS; - if (csp) - mycsp = *csp; - mp_sws_set_colorspace(sws, &mycsp); - sws_scale(sws, (const unsigned char *const *) src->planes, src->stride, - 0, src->h, - dst->planes, dst->stride); + sws_scale(sws, (const uint8_t *const *) src->planes, src->stride, + 0, src->h, dst->planes, dst->stride); sws_freeContext(sws); } diff --git a/libmpcodecs/sws_utils.h b/libmpcodecs/sws_utils.h index 70b7d0b7fb..a0cc47d850 100644 --- a/libmpcodecs/sws_utils.h +++ b/libmpcodecs/sws_utils.h @@ -25,9 +25,7 @@ int mp_sws_set_colorspace(struct SwsContext *sws, struct mp_csp_details *csp); bool mp_sws_supported_format(int imgfmt); -void mp_image_swscale(struct mp_image *dst, - const struct mp_image *src, - struct mp_csp_details *csp, +void mp_image_swscale(struct mp_image *dst, struct mp_image *src, int my_sws_flags); #endif /* MP_SWS_UTILS_H */ diff --git a/libmpcodecs/vf_sub.c b/libmpcodecs/vf_sub.c index 78f75221cb..2d5de3a7ba 100644 --- a/libmpcodecs/vf_sub.c +++ b/libmpcodecs/vf_sub.c @@ -221,11 +221,10 @@ static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) struct osd_state *osd = priv->osd; prepare_image(vf, mpi); + mp_image_set_colorspace_details(mpi, &priv->csp); - if (pts != MP_NOPTS_VALUE) { - osd_draw_on_image(osd, priv->dim, pts, OSD_DRAW_SUB_FILTER, vf->dmpi, - &priv->csp); - } + if (pts != MP_NOPTS_VALUE) + osd_draw_on_image(osd, priv->dim, pts, OSD_DRAW_SUB_FILTER, vf->dmpi); return vf_next_put_image(vf, vf->dmpi, pts); } |