|
|
@ -323,10 +323,12 @@ refine_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(int* printed, int color, FILE* fp, int seenrle, unsigned char crle){
|
|
|
|
write_rle(int* printed, int color, FILE* fp, int seenrle, unsigned char crle,
|
|
|
|
|
|
|
|
int* needclosure){
|
|
|
|
if(!*printed){
|
|
|
|
if(!*printed){
|
|
|
|
fprintf(fp, "#%d", color);
|
|
|
|
fprintf(fp, "%s#%d", *needclosure ? "$" : "", color);
|
|
|
|
*printed = 1;
|
|
|
|
*printed = 1;
|
|
|
|
|
|
|
|
*needclosure = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
crle += 63;
|
|
|
|
crle += 63;
|
|
|
|
if(seenrle == 1){
|
|
|
|
if(seenrle == 1){
|
|
|
@ -365,11 +367,12 @@ write_sixel_data(FILE* fp, int leny, int lenx, const sixeltable* stab, int* pars
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int p = 0;
|
|
|
|
int p = 0;
|
|
|
|
while(p < stab->sixelcount){
|
|
|
|
while(p < stab->sixelcount){
|
|
|
|
|
|
|
|
int needclosure = 0;
|
|
|
|
for(int i = 0 ; i < stab->colors ; ++i){
|
|
|
|
for(int i = 0 ; i < stab->colors ; ++i){
|
|
|
|
int printed = 0;
|
|
|
|
|
|
|
|
int seenrle = 0; // number of repetitions
|
|
|
|
int seenrle = 0; // number of repetitions
|
|
|
|
unsigned char crle = 0; // character being repeated
|
|
|
|
unsigned char crle = 0; // character being repeated
|
|
|
|
int idx = ctable_to_dtable(stab->table + i * CENTSIZE);
|
|
|
|
int idx = ctable_to_dtable(stab->table + i * CENTSIZE);
|
|
|
|
|
|
|
|
int printed = 0;
|
|
|
|
for(int m = p ; m < stab->sixelcount && m < p + lenx ; ++m){
|
|
|
|
for(int m = p ; m < stab->sixelcount && m < p + lenx ; ++m){
|
|
|
|
//fprintf(stderr, "%d ", idx * stab->sixelcount + m);
|
|
|
|
//fprintf(stderr, "%d ", idx * stab->sixelcount + m);
|
|
|
|
//fputc(stab->data[idx * stab->sixelcount + m] + 63, stderr);
|
|
|
|
//fputc(stab->data[idx * stab->sixelcount + m] + 63, stderr);
|
|
|
@ -377,7 +380,7 @@ write_sixel_data(FILE* fp, int leny, int lenx, const sixeltable* stab, int* pars
|
|
|
|
if(stab->data[idx * stab->sixelcount + m] == crle){
|
|
|
|
if(stab->data[idx * stab->sixelcount + m] == crle){
|
|
|
|
++seenrle;
|
|
|
|
++seenrle;
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
write_rle(&printed, i, fp, seenrle, crle);
|
|
|
|
write_rle(&printed, i, fp, seenrle, crle, &needclosure);
|
|
|
|
seenrle = 1;
|
|
|
|
seenrle = 1;
|
|
|
|
crle = stab->data[idx * stab->sixelcount + m];
|
|
|
|
crle = stab->data[idx * stab->sixelcount + m];
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -387,18 +390,13 @@ write_sixel_data(FILE* fp, int leny, int lenx, const sixeltable* stab, int* pars
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(crle){
|
|
|
|
if(crle){
|
|
|
|
write_rle(&printed, i, fp, seenrle, crle);
|
|
|
|
write_rle(&printed, i, fp, seenrle, crle, &needclosure);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(i + 1 < stab->colors){
|
|
|
|
needclosure = needclosure | printed;
|
|
|
|
if(printed){
|
|
|
|
|
|
|
|
fputc('$', fp);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
|
|
|
|
if(p + lenx < stab->sixelcount){
|
|
|
|
if(p + lenx < stab->sixelcount){
|
|
|
|
fputc('-', fp);
|
|
|
|
fputc('-', fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
p += lenx;
|
|
|
|
p += lenx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// \x9c: 8-bit "string terminator" (end sixel) doesn't work on at
|
|
|
|
// \x9c: 8-bit "string terminator" (end sixel) doesn't work on at
|
|
|
|