From 5f57d276562c18ce65c47fa60f442ea427d7033e Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 6 Aug 2012 17:48:30 +0200 Subject: image_writer: add option parsing image_writer now provides its own option parsing, and screenshot.c and the mplayer frontend use it. --- cfg-mplayer.h | 14 ++++++++++---- defaultopts.c | 2 -- image_writer.c | 14 ++++++++++++++ options.h | 4 +--- screenshot.c | 9 +++------ 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/cfg-mplayer.h b/cfg-mplayer.h index 0f1789dec5..c250d94874 100644 --- a/cfg-mplayer.h +++ b/cfg-mplayer.h @@ -616,6 +616,14 @@ const m_option_t tvscan_conf[]={ }; #endif +extern const struct m_sub_options image_writer_conf; + +const m_option_t screenshot_conf[] = { + OPT_SUBSTRUCT(screenshot_image_opts, image_writer_conf, M_OPT_MERGE), + OPT_STRING("template", screenshot_template, 0), + {0}, +}; + const m_option_t mplayer_opts[]={ /* name, pointer, type, flags, min, max */ @@ -785,10 +793,8 @@ const m_option_t mplayer_opts[]={ {"tvscan", (void *) tvscan_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL}, #endif /* CONFIG_TV */ - OPT_INTRANGE("screenshot-jpeg-quality", screenshot_jpeg_quality, 0, 0, 100), - OPT_INTRANGE("screenshot-png-compression", screenshot_png_compression, 0, 0, 9), - OPT_STRING("screenshot-filetype", screenshot_filetype, 0), - OPT_STRING("screenshot-template", screenshot_template, 0), + {"screenshot", (void *) screenshot_conf, CONF_TYPE_SUBCONFIG, + M_OPT_PREFIXED, 0, 0, NULL}, OPT_FLAG_ON("list-properties", list_properties, CONF_GLOBAL), {"identify", &mp_msg_levels[MSGT_IDENTIFY], CONF_TYPE_FLAG, CONF_GLOBAL, 0, MSGL_V, NULL}, diff --git a/defaultopts.c b/defaultopts.c index 96768f605a..8636fe69f0 100644 --- a/defaultopts.c +++ b/defaultopts.c @@ -40,8 +40,6 @@ void set_default_mplayer_options(struct MPOpts *opts) .video_id = -1, .sub_id = -1, .extension_parsing = 1, - .screenshot_jpeg_quality = 85, - .screenshot_png_compression = 7, .audio_output_channels = 2, .audio_output_format = -1, // AF_FORMAT_UNKNOWN .playback_speed = 1., diff --git a/image_writer.c b/image_writer.c index 3aca95d963..750dd15426 100644 --- a/image_writer.c +++ b/image_writer.c @@ -51,6 +51,20 @@ const struct image_writer_opts image_writer_opts_defaults = { .jpeg_quality = 85, }; +#undef OPT_BASE_STRUCT +#define OPT_BASE_STRUCT struct image_writer_opts + +const struct m_sub_options image_writer_conf = { + .opts = (m_option_t[]) { + OPT_INTRANGE("jpeg-quality", jpeg_quality, 0, 0, 100), + OPT_INTRANGE("png-compression", png_compression, 0, 0, 9), + OPT_STRING("filetype", filetype, 0), + {0}, + }, + .size = sizeof(struct image_writer_opts), + .defaults = &image_writer_opts_defaults, +}; + struct image_writer_ctx { const struct image_writer_opts *opts; const struct img_writer *writer; diff --git a/options.h b/options.h index f87ee16669..307f9682b3 100644 --- a/options.h +++ b/options.h @@ -85,9 +85,7 @@ typedef struct MPOpts { char *sub_demuxer_name; int extension_parsing; - int screenshot_jpeg_quality; - int screenshot_png_compression; - char *screenshot_filetype; + struct image_writer_opts *screenshot_image_opts; char *screenshot_template; int audio_output_channels; diff --git a/screenshot.c b/screenshot.c index 6c734f57b5..032fa132f4 100644 --- a/screenshot.c +++ b/screenshot.c @@ -262,15 +262,12 @@ void screenshot_save(struct MPContext *mpctx, struct mp_image *image) struct mp_csp_details colorspace; get_detected_video_colorspace(mpctx->sh_video, &colorspace); - struct image_writer_opts opts = image_writer_opts_defaults; - opts.filetype = mpctx->opts.screenshot_filetype; - opts.jpeg_quality = mpctx->opts.screenshot_jpeg_quality; - opts.png_compression = mpctx->opts.screenshot_png_compression; + struct image_writer_opts *opts = mpctx->opts.screenshot_image_opts; - char *filename = gen_fname(ctx, image_writer_file_ext(&opts)); + char *filename = gen_fname(ctx, image_writer_file_ext(opts)); if (filename) { mp_msg(MSGT_CPLAYER, MSGL_INFO, "*** screenshot '%s' ***\n", filename); - if (!write_image(image, &colorspace, &opts, filename)) + if (!write_image(image, &colorspace, opts, filename)) mp_msg(MSGT_CPLAYER, MSGL_ERR, "\nError writing screenshot!\n"); talloc_free(filename); } -- cgit v1.2.3