diff options
author | wm4 <wm4@nowhere> | 2015-04-29 21:05:04 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-04-29 21:05:04 +0200 |
commit | d51dee093fd0cc4dbfa5f04580251ecd09b4f0cb (patch) | |
tree | 77881921ae3ee54e734cbef419903efd1ae9032a /video/image_writer.c | |
parent | f07c9b16f9c2793605cb8b930095104018379622 (diff) | |
download | mpv-d51dee093fd0cc4dbfa5f04580251ecd09b4f0cb.tar.bz2 mpv-d51dee093fd0cc4dbfa5f04580251ecd09b4f0cb.tar.xz |
screenshots: add option to prevent 16 bit output
That's what it's usually about (again).
Diffstat (limited to 'video/image_writer.c')
-rw-r--r-- | video/image_writer.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/video/image_writer.c b/video/image_writer.c index 935d4bd962..79cd4ec171 100644 --- a/video/image_writer.c +++ b/video/image_writer.c @@ -42,6 +42,7 @@ const struct image_writer_opts image_writer_opts_defaults = { .format = "jpg", + .high_bit_depth = 1, .png_compression = 7, .png_filter = 5, .jpeg_quality = 90, @@ -64,6 +65,7 @@ const struct m_sub_options image_writer_conf = { OPT_INTRANGE("png-compression", png_compression, 0, 0, 9), OPT_INTRANGE("png-filter", png_filter, 0, 0, 5), OPT_STRING("format", format, 0), + OPT_FLAG("high-bit-depth", high_bit_depth, 0), OPT_FLAG("tag-colorspace", tag_csp, 0), {0}, }, @@ -218,6 +220,22 @@ static bool write_jpeg(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp #endif +static int get_encoder_format(struct AVCodec *codec, int srcfmt, bool highdepth) +{ + const enum AVPixelFormat *pix_fmts = codec->pix_fmts; + int current = 0; + for (int n = 0; pix_fmts && pix_fmts[n] != AV_PIX_FMT_NONE; n++) { + int fmt = pixfmt2imgfmt(pix_fmts[n]); + if (!fmt) + continue; + // Ignore formats larger than 8 bit per pixel. + if (!highdepth && IMGFMT_RGB_DEPTH(fmt) > 32) + continue; + current = current ? mp_imgfmt_select_best(current, fmt, srcfmt) : fmt; + } + return current; +} + static int get_target_format(struct image_writer_ctx *ctx, int srcfmt) { if (!ctx->writer->lavc_codec) @@ -227,22 +245,14 @@ static int get_target_format(struct image_writer_ctx *ctx, int srcfmt) if (!codec) goto unknown; - const enum AVPixelFormat *pix_fmts = codec->pix_fmts; - if (!pix_fmts) - goto unknown; + int target = get_encoder_format(codec, srcfmt, ctx->opts->high_bit_depth); + if (!target) + target = get_encoder_format(codec, srcfmt, true); - int current = 0; - for (int n = 0; pix_fmts[n] != AV_PIX_FMT_NONE; n++) { - int fmt = pixfmt2imgfmt(pix_fmts[n]); - if (!fmt) - continue; - current = current ? mp_imgfmt_select_best(current, fmt, srcfmt) : fmt; - } - - if (!current) + if (!target) goto unknown; - return current; + return target; unknown: return IMGFMT_RGB24; |