|
|
@ -485,7 +485,7 @@ write_sixel_data(FILE* fp, int lenx, sixeltable* stab, int* parse_start, sprixce
|
|
|
|
// are programmed as a set of registers, which are then referenced by the
|
|
|
|
// are programmed as a set of registers, which are then referenced by the
|
|
|
|
// stacks. There is also a RLE component, handled in rasterization.
|
|
|
|
// stacks. There is also a RLE component, handled in rasterization.
|
|
|
|
// A pixel block is indicated by setting cell_pixels_p().
|
|
|
|
// A pixel block is indicated by setting cell_pixels_p().
|
|
|
|
int sixel_blit_inner(ncplane* nc, int leny, int lenx, sixeltable* stab,
|
|
|
|
int sixel_blit_inner(ncplane* n, int leny, int lenx, sixeltable* stab,
|
|
|
|
const blitterargs* bargs){
|
|
|
|
const blitterargs* bargs){
|
|
|
|
char* buf = NULL;
|
|
|
|
char* buf = NULL;
|
|
|
|
size_t size = 0;
|
|
|
|
size_t size = 0;
|
|
|
@ -494,31 +494,55 @@ int sixel_blit_inner(ncplane* nc, int leny, int lenx, sixeltable* stab,
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int parse_start = 0;
|
|
|
|
int parse_start = 0;
|
|
|
|
unsigned cols = lenx / bargs->u.pixel.celldimx + !!(lenx % bargs->u.pixel.celldimx);
|
|
|
|
int cols = lenx / bargs->u.pixel.celldimx + !!(lenx % bargs->u.pixel.celldimx);
|
|
|
|
unsigned rows = leny / bargs->u.pixel.celldimy + !!(leny % bargs->u.pixel.celldimy);
|
|
|
|
int rows = leny / bargs->u.pixel.celldimy + !!(leny % bargs->u.pixel.celldimy);
|
|
|
|
sprixcell_e* tacache = malloc(sizeof(*tacache) * rows * cols);
|
|
|
|
sprixcell_e* tacache = NULL;
|
|
|
|
memset(tacache, 0, sizeof(*tacache) * rows * cols);
|
|
|
|
bool reuse = false;
|
|
|
|
|
|
|
|
// if we have a sprixel attached to this plane, see if we can reuse it
|
|
|
|
|
|
|
|
// (we need the same dimensions) and thus immediately apply its T-A table.
|
|
|
|
|
|
|
|
if(n->sprite){
|
|
|
|
|
|
|
|
sprixel* s = n->sprite;
|
|
|
|
|
|
|
|
if(s->dimy == rows && s->dimx == cols){
|
|
|
|
|
|
|
|
tacache = s->tacache;
|
|
|
|
|
|
|
|
reuse = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!reuse){
|
|
|
|
|
|
|
|
tacache = malloc(sizeof(*tacache) * rows * cols);
|
|
|
|
if(tacache == NULL){
|
|
|
|
if(tacache == NULL){
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
free(buf);
|
|
|
|
free(buf);
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(tacache, 0, sizeof(*tacache) * rows * cols);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// calls fclose() on success
|
|
|
|
if(write_sixel_data(fp, lenx, stab, &parse_start, tacache)){
|
|
|
|
if(write_sixel_data(fp, lenx, stab, &parse_start, tacache)){
|
|
|
|
|
|
|
|
if(!reuse){
|
|
|
|
free(tacache);
|
|
|
|
free(tacache);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
free(buf);
|
|
|
|
free(buf);
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// takes ownership of |buf| on success
|
|
|
|
// both paths take ownership of buf on success
|
|
|
|
if(plane_blit_sixel(nc, buf, size, bargs->placey, bargs->placex,
|
|
|
|
if(reuse){
|
|
|
|
|
|
|
|
sprixel_update(n->sprite, buf, size);
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
if(plane_blit_sixel(n, buf, size, bargs->placey, bargs->placex,
|
|
|
|
rows, cols, bargs->u.pixel.sprixelid, leny, lenx,
|
|
|
|
rows, cols, bargs->u.pixel.sprixelid, leny, lenx,
|
|
|
|
parse_start, tacache) < 0){
|
|
|
|
parse_start, tacache) < 0){
|
|
|
|
|
|
|
|
if(!reuse){
|
|
|
|
free(tacache);
|
|
|
|
free(tacache);
|
|
|
|
|
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
free(buf);
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int sixel_blit(ncplane* nc, int linesize, const void* data,
|
|
|
|
int sixel_blit(ncplane* n, int linesize, const void* data,
|
|
|
|
int leny, int lenx, const blitterargs* bargs){
|
|
|
|
int leny, int lenx, const blitterargs* bargs){
|
|
|
|
int sixelcount = (lenx - bargs->begx) * ((leny - bargs->begy + 5) / 6);
|
|
|
|
int sixelcount = (lenx - bargs->begx) * ((leny - bargs->begy + 5) / 6);
|
|
|
|
int colorregs = bargs->u.pixel.colorregs;
|
|
|
|
int colorregs = bargs->u.pixel.colorregs;
|
|
|
@ -552,7 +576,7 @@ int sixel_blit(ncplane* nc, int linesize, const void* data,
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
refine_color_table(data, linesize, bargs->begy, bargs->begx, leny, lenx, &stable);
|
|
|
|
refine_color_table(data, linesize, bargs->begy, bargs->begx, leny, lenx, &stable);
|
|
|
|
int r = sixel_blit_inner(nc, leny, lenx, &stable, bargs);
|
|
|
|
int r = sixel_blit_inner(n, leny, lenx, &stable, bargs);
|
|
|
|
free(stable.data);
|
|
|
|
free(stable.data);
|
|
|
|
free(stable.deets);
|
|
|
|
free(stable.deets);
|
|
|
|
free(stable.table);
|
|
|
|
free(stable.table);
|
|
|
|