From 4effee947a51e269eff85e0fa927814d21278328 Mon Sep 17 00:00:00 2001 From: nick black Date: Wed, 28 Oct 2020 05:38:57 -0400 Subject: [PATCH] keller demo #736 --- src/demo/keller.c | 49 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/src/demo/keller.c b/src/demo/keller.c index 3c994830b..4a6dffd4a 100644 --- a/src/demo/keller.c +++ b/src/demo/keller.c @@ -1,6 +1,51 @@ #include "demo.h" -int keller_demo(struct notcurses* nc){ - // FIXME +// show it with each blitter, with a legend +static int +visualize(struct notcurses* nc, struct ncvisual* ncv){ + for(ncblitter_e b = NCBLIT_DEFAULT + 1 ; b < NCBLIT_SIXEL ; ++b){ + struct timespec ts = { .tv_sec = 1, .tv_nsec = 0, }; + struct ncvisual_options vopts = { + .scaling = NCSCALE_STRETCH, + .blitter = b, + }; + struct ncplane* n = ncvisual_render(nc, ncv, &vopts); + if(n == NULL){ + return -1; + } + const char* name = notcurses_str_blitter(b); + ncplane_set_bg_rgb(n, 0); + int scalex, scaley, truey, truex; + ncvisual_geom(nc, ncv, &vopts, &truey, &truex, &scaley, &scalex); + ncplane_printf_aligned(n, ncplane_dim_y(n) / 2 - 1, NCALIGN_CENTER, + "%dx%d", truex, truey); + ncplane_putstr_aligned(n, ncplane_dim_y(n) / 2, NCALIGN_CENTER, name); + ncplane_printf_aligned(n, ncplane_dim_y(n) / 2 + 1, NCALIGN_CENTER, + "%d:%d pixels -> cell", scalex, scaley); + int ret = demo_render(nc); + demo_nanosleep(nc, &ts); + ncplane_destroy(n); + if(ret){ + return ret; + } + } return 0; } + +int keller_demo(struct notcurses* nc){ + if(!notcurses_canopen_images(nc)){ + return 0; + } + char* file = find_data("covid19.jpg"); + if(file == NULL){ + return -1; + } + struct ncvisual* ncv = ncvisual_from_file(file); + free(file); + if(ncv == NULL){ + return -1; + } + int r = visualize(nc, ncv); + ncvisual_destroy(ncv); + return r; +}