|
|
@ -181,18 +181,14 @@ unzip_color(const uint32_t* data, int linesize, int begy, int begx,
|
|
|
|
cdetails* deets = stab->deets + didx;
|
|
|
|
cdetails* deets = stab->deets + didx;
|
|
|
|
unsigned char* srcsixels = stab->data + stab->sixelcount * didx;
|
|
|
|
unsigned char* srcsixels = stab->data + stab->sixelcount * didx;
|
|
|
|
unsigned char* dstsixels = stab->data + stab->sixelcount * stab->colors;
|
|
|
|
unsigned char* dstsixels = stab->data + stab->sixelcount * stab->colors;
|
|
|
|
fprintf(stderr, "counts: src: %d dst: %d src: %p dst: %p\n", deets->count, targdeets->count, srcsixels, dstsixels);
|
|
|
|
//fprintf(stderr, "counts: src: %d dst: %d src: %p dst: %p\n", deets->count, targdeets->count, srcsixels, dstsixels);
|
|
|
|
int sixel = 0;
|
|
|
|
int sixel = 0;
|
|
|
|
int totalcount = 0;
|
|
|
|
|
|
|
|
int sixelson = 0;
|
|
|
|
|
|
|
|
memset(deets, 0, sizeof(*deets));
|
|
|
|
memset(deets, 0, sizeof(*deets));
|
|
|
|
for(int visy = begy ; visy < (begy + leny) ; visy += 6){
|
|
|
|
for(int visy = begy ; visy < (begy + leny) ; visy += 6){
|
|
|
|
for(int visx = begx ; visx < (begx + lenx) ; visx += 1, ++sixel){
|
|
|
|
for(int visx = begx ; visx < (begx + lenx) ; visx += 1, ++sixel){
|
|
|
|
if(srcsixels[sixel]){
|
|
|
|
if(srcsixels[sixel]){
|
|
|
|
++sixelson;
|
|
|
|
|
|
|
|
for(int sy = visy ; sy < (begy + leny) && sy < visy + 6 ; ++sy){
|
|
|
|
for(int sy = visy ; sy < (begy + leny) && sy < visy + 6 ; ++sy){
|
|
|
|
if(srcsixels[sixel] & (1u << (sy - visy))){
|
|
|
|
if(srcsixels[sixel] & (1u << (sy - visy))){
|
|
|
|
++totalcount;
|
|
|
|
|
|
|
|
const uint32_t* rgb = (const uint32_t*)(data + (linesize / 4 * sy) + visx);
|
|
|
|
const uint32_t* rgb = (const uint32_t*)(data + (linesize / 4 * sy) + visx);
|
|
|
|
unsigned char comps[RGBSIZE];
|
|
|
|
unsigned char comps[RGBSIZE];
|
|
|
|
break_sixel_comps(comps, *rgb, 0xff);
|
|
|
|
break_sixel_comps(comps, *rgb, 0xff);
|
|
|
@ -210,7 +206,6 @@ int sixelson = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(stderr, "counts: src: %d dst: %d total: %d sixels: %d\n", deets->count, targdeets->count, totalcount, sixelson);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// relax segment |coloridx|. we must have room for a new color. we find the
|
|
|
|
// relax segment |coloridx|. we must have room for a new color. we find the
|
|
|
@ -233,13 +228,13 @@ refine_color(const uint32_t* data, int linesize, int begy, int begx,
|
|
|
|
unsigned gmax = deets->hi[1];
|
|
|
|
unsigned gmax = deets->hi[1];
|
|
|
|
unsigned bmax = deets->hi[2];
|
|
|
|
unsigned bmax = deets->hi[2];
|
|
|
|
if(gdelt >= rdelt && gdelt >= bdelt){ // split on green
|
|
|
|
if(gdelt >= rdelt && gdelt >= bdelt){ // split on green
|
|
|
|
fprintf(stderr, "[%d->%d] SPLIT ON GREEN %d %d\n", color, stab->colors, deets->hi[1], deets->lo[1]);
|
|
|
|
//fprintf(stderr, "[%d->%d] SPLIT ON GREEN %d %d\n", color, stab->colors, deets->hi[1], deets->lo[1]);
|
|
|
|
gmax = deets->lo[1] + (deets->hi[1] - deets->lo[1]) / 2;
|
|
|
|
gmax = deets->lo[1] + (deets->hi[1] - deets->lo[1]) / 2;
|
|
|
|
}else if(rdelt >= gdelt && rdelt >= bdelt){ // split on red
|
|
|
|
}else if(rdelt >= gdelt && rdelt >= bdelt){ // split on red
|
|
|
|
fprintf(stderr, "[%d->%d] SPLIT ON RED %d %d\n", color, stab->colors, deets->hi[0], deets->lo[0]);
|
|
|
|
//fprintf(stderr, "[%d->%d] SPLIT ON RED %d %d\n", color, stab->colors, deets->hi[0], deets->lo[0]);
|
|
|
|
rmax = deets->lo[0] + (deets->hi[0] - deets->lo[0]) / 2;
|
|
|
|
rmax = deets->lo[0] + (deets->hi[0] - deets->lo[0]) / 2;
|
|
|
|
}else{ // split on blue
|
|
|
|
}else{ // split on blue
|
|
|
|
fprintf(stderr, "[%d->%d] SPLIT ON BLUE %d %d\n", color, stab->colors, deets->hi[2], deets->lo[2]);
|
|
|
|
//fprintf(stderr, "[%d->%d] SPLIT ON BLUE %d %d\n", color, stab->colors, deets->hi[2], deets->lo[2]);
|
|
|
|
bmax = deets->lo[2] + (deets->hi[2] - deets->lo[2]) / 2;
|
|
|
|
bmax = deets->lo[2] + (deets->hi[2] - deets->lo[2]) / 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unzip_color(data, linesize, begy, begx, leny, lenx, stab, color,
|
|
|
|
unzip_color(data, linesize, begy, begx, leny, lenx, stab, color,
|
|
|
@ -257,11 +252,11 @@ refine_color_table(const uint32_t* data, int linesize, int begy, int begx,
|
|
|
|
unsigned char* crec = stab->table + CENTSIZE * i;
|
|
|
|
unsigned char* crec = stab->table + CENTSIZE * i;
|
|
|
|
int didx = ctable_to_dtable(crec);
|
|
|
|
int didx = ctable_to_dtable(crec);
|
|
|
|
cdetails* deets = stab->deets + didx;
|
|
|
|
cdetails* deets = stab->deets + didx;
|
|
|
|
fprintf(stderr, "[%d->%d] hi: %d %d %d lo: %d %d %d\n", i, didx, deets->hi[0], deets->hi[1], deets->hi[2], deets->lo[0], deets->lo[1], deets->lo[2]);
|
|
|
|
//fprintf(stderr, "[%d->%d] hi: %d %d %d lo: %d %d %d\n", i, didx, deets->hi[0], deets->hi[1], deets->hi[2], deets->lo[0], deets->lo[1], deets->lo[2]);
|
|
|
|
if(memcmp(deets->hi, deets->lo, RGBSIZE)){
|
|
|
|
if(memcmp(deets->hi, deets->lo, RGBSIZE)){
|
|
|
|
refine_color(data, linesize, begy, begx, leny, lenx, stab, i);
|
|
|
|
refine_color(data, linesize, begy, begx, leny, lenx, stab, i);
|
|
|
|
if(stab->colors == stab->colorregs){
|
|
|
|
if(stab->colors == stab->colorregs){
|
|
|
|
fprintf(stderr, "filled table!\n");
|
|
|
|
//fprintf(stderr, "filled table!\n");
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
refined = true;
|
|
|
|
refined = true;
|
|
|
@ -325,7 +320,6 @@ write_sixel_data(FILE* fp, int lenx, sixeltable* stab){
|
|
|
|
(intmax_t)(stab->deets[idx].sums[2] * 100 / count / 255));
|
|
|
|
(intmax_t)(stab->deets[idx].sums[2] * 100 / count / 255));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int p = 0;
|
|
|
|
int p = 0;
|
|
|
|
int totals[stab->colors]; memset(totals, 0, sizeof(totals));
|
|
|
|
|
|
|
|
while(p < stab->sixelcount){
|
|
|
|
while(p < stab->sixelcount){
|
|
|
|
for(int i = 0 ; i < stab->colors ; ++i){
|
|
|
|
for(int i = 0 ; i < stab->colors ; ++i){
|
|
|
|
int printed = 0;
|
|
|
|
int printed = 0;
|
|
|
@ -335,7 +329,6 @@ int totals[stab->colors]; memset(totals, 0, sizeof(totals));
|
|
|
|
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);
|
|
|
|
if(stab->data[idx * stab->sixelcount + m]) ++totals[i];
|
|
|
|
|
|
|
|
if(seenrle){
|
|
|
|
if(seenrle){
|
|
|
|
if(stab->data[idx * stab->sixelcount + m] == crle){
|
|
|
|
if(stab->data[idx * stab->sixelcount + m] == crle){
|
|
|
|
++seenrle;
|
|
|
|
++seenrle;
|
|
|
@ -364,9 +357,6 @@ if(stab->data[idx * stab->sixelcount + m]) ++totals[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p += lenx;
|
|
|
|
p += lenx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(int i = 0 ; i < stab->colors ; ++i){
|
|
|
|
|
|
|
|
fprintf(stderr, "count: %d total: %d\n", stab->deets[i].count, totals[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// \x9c: 8-bit "string terminator" (end sixel) doesn't work on at
|
|
|
|
// \x9c: 8-bit "string terminator" (end sixel) doesn't work on at
|
|
|
|
// least xterm; we instead use '\e\\'
|
|
|
|
// least xterm; we instead use '\e\\'
|
|
|
|
fprintf(fp, "\e\\");
|
|
|
|
fprintf(fp, "\e\\");
|
|
|
@ -406,15 +396,18 @@ int sixel_blit_inner(ncplane* nc, int leny, int lenx, sixeltable* stab,
|
|
|
|
int sixel_blit(ncplane* nc, int linesize, const void* data, int begy, int begx,
|
|
|
|
int sixel_blit(ncplane* nc, int linesize, const void* data, int begy, int begx,
|
|
|
|
int leny, int lenx, const blitterargs* bargs){
|
|
|
|
int leny, int lenx, const blitterargs* bargs){
|
|
|
|
int sixelcount = (lenx - begx) * ((leny - begy + 5) / 6);
|
|
|
|
int sixelcount = (lenx - begx) * ((leny - begy + 5) / 6);
|
|
|
|
|
|
|
|
int colorregs = bargs->pixel.colorregs;
|
|
|
|
|
|
|
|
if(colorregs > 256){
|
|
|
|
|
|
|
|
colorregs = 256;
|
|
|
|
|
|
|
|
}
|
|
|
|
sixeltable stable = {
|
|
|
|
sixeltable stable = {
|
|
|
|
.data = malloc(bargs->pixel.colorregs * sixelcount),
|
|
|
|
.data = malloc(colorregs * sixelcount),
|
|
|
|
.deets = malloc(bargs->pixel.colorregs * sizeof(cdetails)),
|
|
|
|
.deets = malloc(colorregs * sizeof(cdetails)),
|
|
|
|
.table = malloc(bargs->pixel.colorregs * CENTSIZE),
|
|
|
|
.table = malloc(colorregs * CENTSIZE),
|
|
|
|
.sixelcount = sixelcount,
|
|
|
|
.sixelcount = sixelcount,
|
|
|
|
.colorregs = 256, // FIXME pull in from bargs
|
|
|
|
.colorregs = colorregs,
|
|
|
|
.colors = 0,
|
|
|
|
.colors = 0,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
fprintf(stderr, "DATA: %p DATA SIZE: %d\n", stable.data, bargs->pixel.colorregs * sixelcount);
|
|
|
|
|
|
|
|
if(stable.data == NULL || stable.deets == NULL || stable.table == NULL){
|
|
|
|
if(stable.data == NULL || stable.deets == NULL || stable.table == NULL){
|
|
|
|
free(stable.table);
|
|
|
|
free(stable.table);
|
|
|
|
free(stable.deets);
|
|
|
|
free(stable.deets);
|
|
|
|