mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-20 03:25:47 +00:00
sixel: don't print empty bands #1391
This commit is contained in:
parent
b6d818c8f7
commit
f0c2570915
@ -141,7 +141,11 @@ extract_color_table(const uint32_t* data, int linesize, int begy, int begx,
|
|||||||
// Emit some number of equivalent, subsequent sixels, using sixel RLE. We've
|
// Emit some number of equivalent, subsequent sixels, using sixel RLE. We've
|
||||||
// seen the sixel |crle| for |seenrle| columns in a row. |seenrle| must > 0.
|
// seen the sixel |crle| for |seenrle| columns in a row. |seenrle| must > 0.
|
||||||
static int
|
static int
|
||||||
write_rle(FILE* fp, int seenrle, unsigned char crle){
|
write_rle(int* printed, int color, FILE* fp, int seenrle, unsigned char crle){
|
||||||
|
if(!*printed){
|
||||||
|
fprintf(fp, "#%d", color);
|
||||||
|
*printed = 1;
|
||||||
|
}
|
||||||
crle += 63;
|
crle += 63;
|
||||||
if(seenrle == 1){
|
if(seenrle == 1){
|
||||||
if(fputc(crle, fp) == EOF){
|
if(fputc(crle, fp) == EOF){
|
||||||
@ -180,9 +184,9 @@ write_sixel_data(FILE* fp, int lenx, sixeltable* stab){
|
|||||||
int p = 0;
|
int p = 0;
|
||||||
while(p < stab->ctab->sixelcount){
|
while(p < stab->ctab->sixelcount){
|
||||||
for(int i = 0 ; i < stab->ctab->colors ; ++i){
|
for(int i = 0 ; i < stab->ctab->colors ; ++i){
|
||||||
fprintf(fp, "#%d", i);
|
int printed = 0;
|
||||||
int seenrle = 0;
|
int seenrle = 0; // number of repetitions
|
||||||
unsigned char crle = 0;
|
unsigned char crle = 0; // character being repeated
|
||||||
int idx = ctable_to_dtable(stab->ctab->table + i * 5);
|
int idx = ctable_to_dtable(stab->ctab->table + i * 5);
|
||||||
for(int m = p ; m < stab->ctab->sixelcount && m < p + lenx ; ++m){
|
for(int m = p ; m < stab->ctab->sixelcount && m < p + lenx ; ++m){
|
||||||
//fprintf(stderr, "%d ", idx * stab->ctab->sixelcount + m);
|
//fprintf(stderr, "%d ", idx * stab->ctab->sixelcount + m);
|
||||||
@ -191,7 +195,7 @@ write_sixel_data(FILE* fp, int lenx, sixeltable* stab){
|
|||||||
if(stab->data[idx * stab->ctab->sixelcount + m] == crle){
|
if(stab->data[idx * stab->ctab->sixelcount + m] == crle){
|
||||||
++seenrle;
|
++seenrle;
|
||||||
}else{
|
}else{
|
||||||
write_rle(fp, seenrle, crle);
|
write_rle(&printed, i, fp, seenrle, crle);
|
||||||
seenrle = 1;
|
seenrle = 1;
|
||||||
crle = stab->data[idx * stab->ctab->sixelcount + m];
|
crle = stab->data[idx * stab->ctab->sixelcount + m];
|
||||||
}
|
}
|
||||||
@ -200,9 +204,13 @@ write_sixel_data(FILE* fp, int lenx, sixeltable* stab){
|
|||||||
crle = stab->data[idx * stab->ctab->sixelcount + m];
|
crle = stab->data[idx * stab->ctab->sixelcount + m];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
write_rle(fp, seenrle, crle);
|
if(crle){
|
||||||
|
write_rle(&printed, i, fp, seenrle, crle);
|
||||||
|
}
|
||||||
if(i + 1 < stab->ctab->colors){
|
if(i + 1 < stab->ctab->colors){
|
||||||
fputc('$', fp);
|
if(printed){
|
||||||
|
fputc('$', fp);
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
if(p + lenx < stab->ctab->sixelcount){
|
if(p + lenx < stab->ctab->sixelcount){
|
||||||
fputc('-', fp);
|
fputc('-', fp);
|
||||||
|
Loading…
Reference in New Issue
Block a user