summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@mplayer2.org>2012-01-18 02:09:43 +0100
committerwm4 <wm4@mplayer2.org>2012-01-18 02:53:30 +0100
commit4e76c7514f847648cdc9740d6ef997d1653effa8 (patch)
treef0b16dbb9f98d30bfee4281fcaf2840b4262b148
parent2e0bae181f155541922278d681185a5b84f602b4 (diff)
downloadmpv-4e76c7514f847648cdc9740d6ef997d1653effa8.tar.bz2
mpv-4e76c7514f847648cdc9740d6ef997d1653effa8.tar.xz
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.
-rw-r--r--libmpcodecs/vf_scale.c13
-rw-r--r--libmpcodecs/vf_scale.h1
-rw-r--r--screenshot.c14
3 files changed, 20 insertions, 8 deletions
diff --git a/libmpcodecs/vf_scale.c b/libmpcodecs/vf_scale.c
index 585ef4d9a1..6bb076c744 100644
--- a/libmpcodecs/vf_scale.c
+++ b/libmpcodecs/vf_scale.c
@@ -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;
diff --git a/libmpcodecs/vf_scale.h b/libmpcodecs/vf_scale.h
index a9b3b506d5..08d651ce16 100644
--- a/libmpcodecs/vf_scale.h
+++ b/libmpcodecs/vf_scale.h
@@ -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);
diff --git a/screenshot.c b/screenshot.c
index 9b8c67a89a..5ebe2e647f 100644
--- a/screenshot.c
+++ b/screenshot.c
@@ -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);