From ca9e1024d0a5f08811864de0ce3258bd0cbc32f8 Mon Sep 17 00:00:00 2001 From: nick black Date: Mon, 31 May 2021 23:57:31 -0400 Subject: [PATCH] fill out ascii roundtrip unit test #1490 --- src/lib/blit.c | 18 +++++++++--------- src/lib/internal.h | 4 +++- src/lib/notcurses.c | 3 +-- src/tests/blit.cpp | 18 ++++++++++++++++-- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/lib/blit.c b/src/lib/blit.c index c5241d1a7e..7aa93ca1da 100644 --- a/src/lib/blit.c +++ b/src/lib/blit.c @@ -858,31 +858,31 @@ braille_blit(ncplane* nc, int linesize, const void* data, // it's safe to use even in the NCBLIT_1x1 ASCII case). static struct blitset notcurses_blitters[] = { { .geom = NCBLIT_8x1, .width = 1, .height = 8, - .egcs = NULL, .plotegcs = L" ▁▂▃▄▅▆▇█", + .egcs = NULL, .plotegcs = L" ▁▂▃▄▅▆▇█", .blit = tria_blit, .name = "eightstep", .fill = false, }, { .geom = NCBLIT_1x1, .width = 1, .height = 1, - .egcs = L" █", .plotegcs = L" █", + .egcs = L" █", .plotegcs = L" █", .blit = tria_blit_ascii,.name = "ascii", .fill = false, }, { .geom = NCBLIT_2x1, .width = 1, .height = 2, - .egcs = L" ▀▄█", .plotegcs = L" ▄█", + .egcs = L" ▀▄█", .plotegcs = L" ▄█", .blit = tria_blit, .name = "half", .fill = false, }, { .geom = NCBLIT_2x2, .width = 2, .height = 2, - .egcs = L" ▘▝▀▖▌▞▛▗▚▐▜▄▙▟█", .plotegcs = L" ▗▐▖▄▟▌▙█", + .egcs = L" ▘▝▀▖ ▌▞▛▗▚▐▜▄▙▟█", .plotegcs = NULL, // FIXME .blit = quadrant_blit, .name = "quad", .fill = false, }, { .geom = NCBLIT_3x2, .width = 2, .height = 3, - .egcs = NULL, .plotegcs = L" 🬞🬦▐🬏🬭🬵🬷🬓🬱🬹🬻▌🬲🬺█", + .egcs = NULL, .plotegcs = L" 🬞🬦▐🬏🬭🬵🬷🬓🬱🬹🬻▌🬲🬺█", // FIXME .blit = sextant_blit, .name = "sex", .fill = false, }, { .geom = NCBLIT_4x1, .width = 1, .height = 4, - .egcs = NULL, .plotegcs = L" ▂▄▆█", + .egcs = NULL, .plotegcs = L" ▂▄▆█", .blit = tria_blit, .name = "fourstep", .fill = false, }, { .geom = NCBLIT_BRAILLE, .width = 2, .height = 4, - .egcs = NULL, .plotegcs = L"⠀⢀⢠⢰⢸⡀⣀⣠⣰⣸⡄⣄⣤⣴⣼⡆⣆⣦⣶⣾⡇⣇⣧⣷⣿", + .egcs = NULL, .plotegcs = L"⠀⢀⢠⢰⢸⡀⣀⣠⣰⣸⡄⣄⣤⣴⣼⡆⣆⣦⣶⣾⡇⣇⣧⣷⣿", // FIXME .blit = braille_blit, .name = "braille", .fill = true, }, { .geom = NCBLIT_PIXEL, .width = 1, .height = 1, - .egcs = L"", .plotegcs = L"", + .egcs = L"", .plotegcs = NULL, .blit = sixel_blit, .name = "pixel", .fill = true, }, { .geom = 0, .width = 0, .height = 0, - .egcs = NULL, .plotegcs = NULL, + .egcs = NULL, .plotegcs = NULL, .blit = NULL, .name = NULL, .fill = false, }, }; diff --git a/src/lib/internal.h b/src/lib/internal.h index 7bfc7053ea..d83513c02b 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -535,11 +535,13 @@ struct blitset { ncblitter_e geom; int width; // number of input pixels per output cell, width int height; // number of input pixels per output cell, height + // the EGCs which form the blitter. bits grow left to right, and then top to + // bottom. the first character is always a space, the last a full block. + const wchar_t* egcs; // the EGCs which form the various levels of a given plotset. if the geometry // is wide, things are arranged with the rightmost side increasing most // quickly, i.e. it can be indexed as height arrays of 1 + height glyphs. i.e. // the first five braille EGCs are all 0 on the left, [0..4] on the right. - const wchar_t* egcs; const wchar_t* plotegcs; ncblitter blit; const char* name; diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index f3e7540523..c8b32f0c3a 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -2681,12 +2681,10 @@ ncplane_as_rgba_internal(const ncplane* nc, ncblitter_e blit, uint64_t channels; char* c = ncplane_at_yx(nc, y, x, &stylemask, &channels); if(c == NULL){ -fprintf(stderr, "NO CONTENT %d/%d\n", y, x); free(ret); return NULL; } int idx = get_blitter_egc_idx(bset, c); -fprintf(stderr, "%d/%d: [%s] %d\n", y, x, c, idx); if(idx < 0){ free(ret); free(c); @@ -2697,6 +2695,7 @@ fprintf(stderr, "%d/%d: [%s] %d\n", y, x, c, idx); fa = ncchannels_fg_alpha(channels); ncchannels_bg_rgb8(channels, &br, &bb, &bg); ba = ncchannels_bg_alpha(channels); +fprintf(stderr, "%d/%d: [%s] %d %d %d %d\n", y, x, c, idx, fr, fb, fg); // handle each destination pixel from this cell for(int py = 0 ; py < bset->height ; ++py){ for(int px = 0 ; px < bset->width ; ++px){ diff --git a/src/tests/blit.cpp b/src/tests/blit.cpp index 4a77baad48..b28c8e763e 100644 --- a/src/tests/blit.cpp +++ b/src/tests/blit.cpp @@ -167,11 +167,25 @@ TEST_CASE("Blit") { }; auto ncv = ncvisual_from_rgba(data, 1, 8, 2); REQUIRE(nullptr != ncv); - auto p = ncvisual_render(nc_, ncv, nullptr); + struct ncvisual_options vopts = { + .n = nullptr, + .scaling = NCSCALE_NONE, + .y = 0, .x = 0, + .begy = 0, .begx = 0, + .leny = 0, .lenx = 0, + .blitter = NCBLIT_1x1, + .flags = 0, + .transcolor = 0, + }; + auto p = ncvisual_render(nc_, ncv, &vopts); REQUIRE(nullptr != p); CHECK(1 == ncplane_dim_y(p)); CHECK(2 == ncplane_dim_x(p)); - // FIXME + int pxdimy, pxdimx; + auto edata = ncplane_as_rgba(p, vopts.blitter, 0, 0, -1, -1, &pxdimy, &pxdimx); + REQUIRE(nullptr != edata); + CHECK(0 == memcmp(data, edata, sizeof(data))); + free(edata); CHECK(0 == ncplane_destroy(p)); ncvisual_destroy(ncv); }