From e8e41f10a4898059b9f722ebacadeef350bbcd38 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Fri, 25 Nov 2022 11:00:56 +0100 Subject: [PATCH] dummy dump: allow saving raw images again As it was before saving RGB codecs to PNM was added. --- src/video_display/dummy.c | 7 +++++-- src/video_frame.c | 5 ++--- src/video_frame.h | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/video_display/dummy.c b/src/video_display/dummy.c index edfdc3007..3b5581c37 100644 --- a/src/video_display/dummy.c +++ b/src/video_display/dummy.c @@ -62,6 +62,7 @@ struct dummy_display_state { size_t dump_bytes; _Bool dump_to_file; _Bool oneshot; + _Bool raw; int dump_to_file_skip_frames; }; @@ -76,7 +77,7 @@ static void *display_dummy_init(struct module *parent, const char *cfg, unsigned struct key_val options[] = { { "codec=", "force the use of a codec instead of default set" }, { "rgb_shift=,,", "if using output codec RGBA, use specified shifts instead of default (" TOSTRING(DEFAULT_R_SHIFT) ", " TOSTRING(DEFAULT_G_SHIFT) ", " TOSTRING(DEFAULT_B_SHIFT) ")" }, - { "dump[:skip=][:oneshot]", "dump first frame to file dummy. (optionally skip first frames); 'oneshot' - exit after dumping the picture" }, + { "dump[:skip=][:oneshot][:raw]", "dump first frame to file dummy. (optionally skip first frames); 'oneshot' - exit after dumping the picture; 'raw' - dump raw data" }, { "hexdump[=]", "dump first n (default " TOSTRING(DEFAULT_DUMP_LEN) ") bytes of every frame in hexadecimal format" }, { NULL, NULL } }; @@ -116,6 +117,8 @@ static void *display_dummy_init(struct module *parent, const char *cfg, unsigned s.dump_to_file_skip_frames = atoi(strchr(item, '=') + 1); } else if (strcmp(item, "oneshot") == 0) { s.oneshot = 1; + } else if (strcmp(item, "raw") == 0) { + s.raw = 1; } else { log_msg(LOG_LEVEL_ERROR, MOD_NAME "Unrecognized option: %s\n", item); return NULL; @@ -164,7 +167,7 @@ static int display_dummy_putf(void *state, struct video_frame *frame, long long } if (s->dump_to_file) { if (s->dump_to_file_skip_frames-- == 0) { - const char *filename = save_video_frame(frame, "dummy"); + const char *filename = save_video_frame(frame, "dummy", s->raw); if (filename) { log_msg(LOG_LEVEL_NOTICE, MOD_NAME "Written dump to file %s\n", filename); } else { diff --git a/src/video_frame.c b/src/video_frame.c index 6c32ea11c..87f6bc568 100644 --- a/src/video_frame.c +++ b/src/video_frame.c @@ -472,10 +472,9 @@ bool save_video_frame_as_pnm(struct video_frame *frame, const char *name) /** * Saves video_frame to file name.. */ -const char *save_video_frame(struct video_frame *frame, const char *name) { +const char *save_video_frame(struct video_frame *frame, const char *name, bool raw) { _Thread_local static char filename[FILENAME_MAX]; - snprintf(filename, sizeof filename, "%s.%s", name, get_codec_file_extension(frame->color_spec)); - if (!is_codec_opaque(frame->color_spec) && codec_is_a_rgb(frame->color_spec) && + if (!raw && !is_codec_opaque(frame->color_spec) && codec_is_a_rgb(frame->color_spec) && ((get_bits_per_component(frame->color_spec) <= 8 && get_decoder_from_to(frame->color_spec, RGB)) || (get_bits_per_component(frame->color_spec) > 8 && get_decoder_from_to(frame->color_spec, RG48)))) { snprintf(filename, sizeof filename, "%s.pnm", name); diff --git a/src/video_frame.h b/src/video_frame.h index 6a194f131..6c1ca6ffc 100644 --- a/src/video_frame.h +++ b/src/video_frame.h @@ -189,7 +189,7 @@ void il_merged_to_upper(char *dst, char *src, int linesize, int height, void **s double compute_fps(int fps, int fpsd, int fd, int fi); bool save_video_frame_as_pnm(struct video_frame *frame, const char *name); -const char *save_video_frame(struct video_frame *frame, const char *name); +const char *save_video_frame(struct video_frame *frame, const char *name, bool raw); void vf_copy_metadata(struct video_frame *desc, const struct video_frame *src); void vf_store_metadata(struct video_frame *f, void *);