image_writer: add option parsing

image_writer now provides its own option parsing, and screenshot.c and
the mplayer frontend use it.
This commit is contained in:
wm4 2012-08-06 17:48:30 +02:00
parent 4de99d9c0c
commit 5f57d27656
5 changed files with 28 additions and 15 deletions

View File

@ -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},

View File

@ -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.,

View File

@ -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;

View File

@ -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;

View File

@ -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);
}