Skip to content

Commit

Permalink
ncsixel_as_rgba: fix processing following '$'
Browse files Browse the repository at this point in the history
waveplate pointed out that we needed to move to
STATE_WANT_DATA rather than STATE_WANT_HASH following
a '$' in sixel text. this was breaking ncsixel_as_rgba()
for larger sixels, for which we now have a unit test.

Closes #2784
  • Loading branch information
dankamongmen committed Jun 11, 2024
1 parent 87ff6fb commit aeb6bca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ rearrangements of Notcurses.
* We now normalize the return of `nl_langinfo()` according to the behavior
of glibc's `_nl_normalize_charset()`, supporting some atypical synonyms
of `UTF-8`.
* Fixed a bug in `ncsixel_as_rgba()` (called by `ncvisual_from_sixel()`)
that broke loading of sixels having more than 12 rows (sixel generation
from images worked fine). Thanks, waveplate!
* Reject illegal geometries in `ncvisual_from_*()`.

* 3.0.9 (2022-12-10)
* Eliminated infinite loop in `ncplane_move_family_above()`.
Expand Down
20 changes: 12 additions & 8 deletions src/lib/sixel.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ extern "C" {
#include "logging.h"

uint32_t* ncsixel_as_rgba(const char *sx, unsigned leny, unsigned lenx){
if(!leny || !lenx){
logerror("null sixel geometry");
return NULL;
}
#define MAXCOLORS 65535
// cast is necessary for c++ callers
uint32_t* rgba = (uint32_t*)calloc(leny * lenx, sizeof(*rgba));
Expand All @@ -26,7 +30,7 @@ uint32_t* ncsixel_as_rgba(const char *sx, unsigned leny, unsigned lenx){
// transparent line (the only possible colorless line).
while(*sx != '#' && *sx != '-'){
if(!*sx){
logerror("expected octothorpe/hyphen, got eol\n");
logerror("expected octothorpe/hyphen, got eol");
return NULL;
}
++sx;
Expand Down Expand Up @@ -56,12 +60,12 @@ uint32_t* ncsixel_as_rgba(const char *sx, unsigned leny, unsigned lenx){
}else if('#' == *sx){
state = STATE_WANT_COLOR;
}else{
logerror("expected octothorpe, got %u\n", *sx);
logerror("expected octothorpe, got %u", *sx);
goto err;
}
}else if(state == STATE_WANT_COLOR){
if(!isdigit(*sx)){
logerror("expected digit, got %u\n", *sx);
logerror("expected digit, got %u", *sx);
goto err;
}
color = 0;
Expand All @@ -84,12 +88,12 @@ uint32_t* ncsixel_as_rgba(const char *sx, unsigned leny, unsigned lenx){
}
}else if(state == STATE_WANT_COLORSPACE){
if('2' != *(sx++)){
logerror("expected '2', got %u\n", *sx);
logerror("expected '2', got %u", *sx);
goto err;
}
//fprintf(stderr, "SX: %u 0x%02x %c\n", *sx, *sx, *sx);
if(';' != *(sx++)){
logerror("expected semicolon, got %u\n", *sx);
logerror("expected semicolon, got %u", *sx);
goto err;
}
//fprintf(stderr, "SX: %u 0x%02x %c\n", *sx, *sx, *sx);
Expand All @@ -100,7 +104,7 @@ uint32_t* ncsixel_as_rgba(const char *sx, unsigned leny, unsigned lenx){
++sx;
}while(isdigit(*sx));
if(';' != *(sx++)){
logerror("expected semicolon, got %u\n", *sx);
logerror("expected semicolon, got %u", *sx);
goto err;
}
//fprintf(stderr, "SX: %u 0x%02x %c\n", *sx, *sx, *sx);
Expand All @@ -112,7 +116,7 @@ uint32_t* ncsixel_as_rgba(const char *sx, unsigned leny, unsigned lenx){
++sx;
}while(isdigit(*sx));
if(';' != *(sx++)){
logerror("expected semicolon, got %u\n", *sx);
logerror("expected semicolon, got %u", *sx);
goto err;
}
//fprintf(stderr, "SX: %u 0x%02x %c\n", *sx, *sx, *sx);
Expand Down Expand Up @@ -153,7 +157,7 @@ uint32_t* ncsixel_as_rgba(const char *sx, unsigned leny, unsigned lenx){
--sx;
}else if(*sx == '$'){
x = 0;
state = STATE_WANT_HASH;
state = STATE_WANT_DATA;
}else if(*sx == '-'){
x = 0;
y += 6;
Expand Down

0 comments on commit aeb6bca

Please sign in to comment.