Skip to content

Commit

Permalink
fill out ascii roundtrip unit test #1490
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Jun 1, 2021
1 parent 7fbd026 commit ca9e102
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
18 changes: 9 additions & 9 deletions src/lib/blit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, },
};

Expand Down
4 changes: 3 additions & 1 deletion src/lib/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/lib/notcurses.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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){
Expand Down
18 changes: 16 additions & 2 deletions src/tests/blit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit ca9e102

Please sign in to comment.