[pixel] pass tacache into plane_blit_pixel from constructors #1388

pull/1458/head
nick black 4 years ago
parent 33d408b4a3
commit b2948a5581
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -45,7 +45,7 @@ int yield_demo(struct notcurses* nc){
const long total = vy * vx;
// less than this, and we exit almost immediately. more than this, and we
// run closer to twenty seconds. 11/50 it is, then.
const long threshold_painted = total * 11 / 50;
const long threshold_painted = total * 1 / 50;
const int MAXITER = 256;
timespec_div(&demodelay, MAXITER, &scaled);
long tfilled = 0;

@ -65,7 +65,9 @@ typedef struct sprixel {
int y, x;
int dimy, dimx; // cell geometry
int pixy, pixx; // pixel geometry (might be smaller than cell geo)
int* tacache; // transparency-annihilatin cache (dimy * dimx)
int* tacache; // transparency-annihilation cache (dimy * dimx)
// each tacache entry is one of 0 (standard opaque cell), 1 (cell with
// some transparency), 2 (annihilated, excised)
int parse_start; // where to start parsing for cell wipes
} sprixel;
@ -727,7 +729,7 @@ void sprixel_hide(sprixel* s);
// dimy and dimx are cell geometry, not pixel
sprixel* sprixel_create(ncplane* n, const char* s, int bytes, int placey, int placex,
int sprixelid, int dimy, int dimx, int pixy, int pixx,
int parse_start);
int parse_start, int* tacache);
API int sprite_wipe_cell(const notcurses* nc, sprixel* s, int y, int x);
int sprite_kitty_annihilate(const notcurses* nc, const ncpile* p, FILE* out, sprixel* s);
int sprite_kitty_init(int fd);
@ -1130,9 +1132,9 @@ egc_rtl(const char* egc, int* bytes){
static inline int
plane_blit_sixel(ncplane* n, const char* s, int bytes, int placey, int placex,
int leny, int lenx, int sprixelid, int dimy, int dimx,
int parse_start){
int parse_start, int* tacache){
sprixel* spx = sprixel_create(n, s, bytes, placey, placex, sprixelid,
leny, lenx, dimy, dimx, parse_start);
leny, lenx, dimy, dimx, parse_start, tacache);
if(spx == NULL){
return -1;
}

@ -193,12 +193,18 @@ int sprite_kitty_cell_wipe(const notcurses* nc, sprixel* s, int ycell, int xcell
// we can only write 4KiB at a time. we're writing base64-encoded RGBA. each
// pixel is 4B raw (32 bits). each chunk of three pixels is then 12 bytes, or
// 16 base64-encoded bytes. 4096 / 16 == 256 3-pixel groups, or 768 pixels.
static int
write_kitty_data(FILE* fp, int linesize, int leny, int lenx,
static int*
write_kitty_data(FILE* fp, int rows, int cols, int linesize, int leny, int lenx,
const uint32_t* data, int sprixelid, int* parse_start){
if(linesize % sizeof(*data)){
return -1;
return NULL;
}
int* tacache = malloc(sizeof(*tacache) * rows * cols);
if(tacache == NULL){
return NULL;
}
memset(tacache, 0, sizeof(*tacache) * rows * cols);
(void)tacache; // FIXME populate tacache with 1s for cells with transparency
int total = leny * lenx; // total number of pixels (4 * total == bytecount)
// number of 4KiB chunks we'll need
int chunks = (total + (RGBA_MAXLEN - 1)) / RGBA_MAXLEN;
@ -241,9 +247,10 @@ write_kitty_data(FILE* fp, int linesize, int leny, int lenx,
fprintf(fp, "\e\\");
}
if(fclose(fp) == EOF){
return -1;
free(tacache);
return NULL;
}
return 0;
return tacache;
}
#undef RGBA_MAXLEN
@ -260,15 +267,17 @@ int kitty_blit_inner(ncplane* nc, int linesize, int leny, int lenx,
return -1;
}
int parse_start = 0;
if(write_kitty_data(fp, linesize, leny, lenx, data, bargs->u.pixel.sprixelid,
&parse_start)){
int* tacache = write_kitty_data(fp, rows, cols, linesize, leny, lenx, data,
bargs->u.pixel.sprixelid, &parse_start);
if(tacache == NULL){
fclose(fp);
free(buf);
return -1;
}
if(plane_blit_sixel(nc, buf, size, bargs->placey, bargs->placex,
rows, cols, bargs->u.pixel.sprixelid, leny, lenx,
parse_start) < 0){
parse_start, tacache) < 0){
free(tacache);
free(buf);
return -1;
}

@ -415,7 +415,7 @@ write_rle(int* printed, int color, FILE* fp, int seenrle, unsigned char crle){
// Emit the sprixel in its entirety, plus enable and disable pixel mode.
static int
write_sixel_data(FILE* fp, int lenx, sixeltable* stab, int* parse_start){
write_sixel_data(FILE* fp, int lenx, sixeltable* stab, int* parse_start, int* tacache){
*parse_start = fprintf(fp, "\ePq");
// Set Raster Attributes - pan/pad=1 (pixel aspect ratio), Ph=lenx, Pv=leny
// using Ph/Pv causes a background to be drawn using color register 0 for all
@ -434,6 +434,7 @@ write_sixel_data(FILE* fp, int lenx, sixeltable* stab, int* parse_start){
(intmax_t)(stab->deets[idx].sums[2] * 100 / count / 255));
}
int p = 0;
(void)tacache; // FIXME fill in tacache when we hit transparencies
while(p < stab->sixelcount){
for(int i = 0 ; i < stab->colors ; ++i){
int printed = 0;
@ -493,16 +494,23 @@ int sixel_blit_inner(ncplane* nc, int leny, int lenx, sixeltable* stab,
return -1;
}
int parse_start = 0;
if(write_sixel_data(fp, lenx, stab, &parse_start)){
fclose(fp);
unsigned cols = lenx / bargs->u.pixel.celldimx + !!(lenx % bargs->u.pixel.celldimx);
unsigned rows = leny / bargs->u.pixel.celldimy + !!(leny % bargs->u.pixel.celldimy);
int* tacache = malloc(sizeof(*tacache) * rows * cols);
memset(tacache, 0, sizeof(*tacache) * rows * cols);
if(tacache == NULL){
free(buf);
return -1;
}
if(write_sixel_data(fp, lenx, stab, &parse_start, tacache)){
free(tacache);
free(buf);
return -1;
}
unsigned cols = lenx / bargs->u.pixel.celldimx + !!(lenx % bargs->u.pixel.celldimx);
unsigned rows = leny / bargs->u.pixel.celldimy + !!(leny % bargs->u.pixel.celldimy);
if(plane_blit_sixel(nc, buf, size, bargs->placey, bargs->placex,
rows, cols, bargs->u.pixel.sprixelid, leny, lenx,
parse_start) < 0){
parse_start, tacache) < 0){
free(tacache);
free(buf);
return -1;
}

@ -17,22 +17,14 @@ void sprixel_hide(sprixel* s){
// y and x are the cell geometry, not the pixel geometry
sprixel* sprixel_create(ncplane* n, const char* s, int bytes, int placey, int placex,
int sprixelid, int dimy, int dimx, int pixy, int pixx,
int parse_start){
int parse_start, int* tacache){
sprixel* ret = malloc(sizeof(sprixel));
if(ret){
if((ret->glyph = memdup(s, bytes + 1)) == NULL){
free(ret);
return NULL;
}
const size_t tasize = sizeof(*ret->tacache) * dimy * dimx;
if((ret->tacache = malloc(tasize)) == NULL){
free(ret->glyph);
free(ret);
return NULL;
}
// FIXME set up transparency cache when generating sprixel;
// we manage only annihilation cache
memset(ret->tacache, 0, tasize);
ret->tacache = tacache;
ret->invalidated = SPRIXEL_INVALIDATED;
ret->n = n;
ret->dimy = dimy;

Loading…
Cancel
Save