screenshot: improve quality by using additional swscale flags

Adding these flags improves the quality of the YUV->RGB conversion when
screenshots are taken. It trades precision for performance.

This doesn't affect any other swscale uses, such as vf_scale or vo_x11.

Based on a patch by cantabile. Fixes #140.
This commit is contained in:
wm4 2012-01-18 02:09:43 +01:00
parent 2e0bae181f
commit 4e76c7514f
3 changed files with 20 additions and 8 deletions

View File

@ -704,7 +704,7 @@ void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, Sw
}
// will use sws_flags & src_filter (from cmd line)
struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat)
static struct SwsContext *sws_getContextFromCmdLine2(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int extraflags)
{
int flags;
SwsFilter *dstFilterParam, *srcFilterParam;
@ -718,6 +718,17 @@ struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat,
return sws_getContext(srcW, srcH, sfmt, dstW, dstH, dfmt, flags | get_sws_cpuflags(), srcFilterParam, dstFilterParam, NULL);
}
struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat)
{
return sws_getContextFromCmdLine2(srcW, srcH, srcFormat, dstW, dstH, dstFormat, 0);
}
struct SwsContext *sws_getContextFromCmdLine_hq(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat)
{
return sws_getContextFromCmdLine2(srcW, srcH, srcFormat, dstW, dstH, dstFormat,
SWS_FULL_CHR_H_INT | SWS_FULL_CHR_H_INP | SWS_ACCURATE_RND | SWS_BITEXACT);
}
/// An example of presets usage
static const struct size_preset {
char* name;

View File

@ -21,6 +21,7 @@
int get_sws_cpuflags(void);
struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat);
struct SwsContext *sws_getContextFromCmdLine_hq(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat);
struct mp_csp_details;
int mp_sws_set_colorspace(struct SwsContext *sws, struct mp_csp_details *csp);

View File

@ -41,7 +41,7 @@
#include "fmt-conversion.h"
//for sws_getContextFromCmdLine and mp_sws_set_colorspace
//for sws_getContextFromCmdLine_hq and mp_sws_set_colorspace
#include "libmpcodecs/vf_scale.h"
#include "libvo/csputils.h"
@ -147,12 +147,12 @@ void screenshot_save(struct MPContext *mpctx, struct mp_image *image)
screenshot_ctx *ctx = screenshot_get_ctx(mpctx);
struct mp_image *dst = alloc_mpi(image->w, image->h, IMGFMT_RGB24);
struct SwsContext *sws = sws_getContextFromCmdLine(image->width,
image->height,
image->imgfmt,
dst->width,
dst->height,
dst->imgfmt);
struct SwsContext *sws = sws_getContextFromCmdLine_hq(image->width,
image->height,
image->imgfmt,
dst->width,
dst->height,
dst->imgfmt);
struct mp_csp_details colorspace;
get_detected_video_colorspace(mpctx->sh_video, &colorspace);