From 19894057ec25afeab0d10c5e231548a09ea1739d Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Wed, 14 Oct 2026 20:03:28 -0700 Subject: vcr: include some text chunks in the png dest If the caller has some textual information to embed in the PNG metadata, it should be able to embed it. This adds three: timestamp: always populated with the current time name: always populated with --name arg, or empty payload: made available for customized usage payload is aimed at strobe users who have some context associated with the strobe request they'd like to embed in an easily machine-readable location attached to the png file. --- src/vcr.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/vcr.c') diff --git a/src/vcr.c b/src/vcr.c index a159379..76158f6 100644 --- a/src/vcr.c +++ b/src/vcr.c @@ -58,6 +58,7 @@ #include #include #include +#include #ifdef USE_XLIB #include @@ -204,6 +205,7 @@ typedef struct vcr_dest_t { png_infop info_ctx; png_structp png_ctx; FILE *output; + png_text text[3]; } png; #endif /* USE_PNG */ }; @@ -617,7 +619,7 @@ vcr_dest_t * vcr_dest_xpicture_new(vcr_backend_t *vbe, Picture picture) #ifdef USE_PNG -vcr_dest_t * vcr_dest_png_new(vcr_backend_t *vbe, FILE *output) +vcr_dest_t * vcr_dest_png_new(vcr_backend_t *vbe, FILE *output, const char *name, const char *payload) { vcr_dest_t *dest; @@ -651,6 +653,36 @@ vcr_dest_t * vcr_dest_png_new(vcr_backend_t *vbe, FILE *output) return NULL; } + { + time_t now = time(NULL); + struct tm *t = localtime(&now); + char t_str[32]; + + strftime(t_str, sizeof(t_str), "%F %T %Z", t); + + /* we always stick three text fields into the PNGs, the caller is expected to always + * provide a `date` style string for timestamp, the chart name for name, and the + * payload is flexible. For strobes it's expected the payload may contain some + * context about the cause for strobing. + */ + dest->png.text[0].compression = -1; /* none */ + dest->png.text[0].key = "timestamp"; + dest->png.text[0].text = t_str; + dest->png.text[0].text_length = strlen(t_str); + + dest->png.text[1].compression = -1; /* none */ + dest->png.text[1].key = "name"; + dest->png.text[1].text = (char *)name; + dest->png.text[1].text_length = name ? strlen(name) : 0; + + dest->png.text[2].compression = -1; /* none */ + dest->png.text[2].key = "payload"; + dest->png.text[2].text = (char *)payload; + dest->png.text[2].text_length = payload ? strlen(payload) : 0; + + png_set_text(dest->png.png_ctx, dest->png.info_ctx, dest->png.text, 3); + } + png_init_io(dest->png.png_ctx, output); return dest; -- cgit v1.2.3