mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-10-31 15:20:13 +00:00
clamp Sixel to max supported size #1550
This commit is contained in:
parent
266ed71c0b
commit
c875eb4544
4
USAGE.md
4
USAGE.md
@ -3060,8 +3060,8 @@ it was built up:
|
||||
// Get the size and ratio of ncvisual pixels to output cells along the y
|
||||
// and x axes. The input size (in pixels) will be written to 'y' and 'x'.
|
||||
// The scaling will be written to 'scaley' and 'scalex'. With these:
|
||||
// rows = (y / scaley) + !!(y % scaley)
|
||||
// cols = (x / scalex) + !!(x % scalex)
|
||||
// rows = (y / scaley) + !!(y % scaley) or (y + scaley - 1) / scaley
|
||||
// cols = (x / scalex) + !!(x % scalex) or (x + scalex - 1) / scalex
|
||||
// Returns non-zero for an invalid 'vopts'. The blitter that will be used
|
||||
// is returned in '*blitter'.
|
||||
int ncvisual_blitter_geom(const struct notcurses* nc, const struct ncvisual* n,
|
||||
|
@ -2698,8 +2698,8 @@ ncplane_rgba(const struct ncplane* n, ncblitter_e blit,
|
||||
// Get the size and ratio of ncvisual pixels to output cells along the y
|
||||
// and x axes. The input size (in pixels) will be written to 'y' and 'x'.
|
||||
// The scaling will be written to 'scaley' and 'scalex'. With these:
|
||||
// rows = (y / scaley) + !!(y % scaley)
|
||||
// cols = (x / scalex) + !!(x % scalex)
|
||||
// rows = (y / scaley) + !!(y % scaley) or (y + scaley - 1) / scaley
|
||||
// cols = (x / scalex) + !!(x % scalex) or (x + scalex - 1) / scalex
|
||||
// Returns non-zero for an invalid 'vopts'. The blitter that will be used
|
||||
// is returned in '*blitter'.
|
||||
API int ncvisual_blitter_geom(const struct notcurses* nc, const struct ncvisual* n,
|
||||
|
@ -510,6 +510,7 @@ ncdirect_render_visual(ncdirect* n, ncvisual* ncv, ncblitter_e blitfxn,
|
||||
}else{
|
||||
dispcols = dimx * n->tcache.cellpixx;
|
||||
disprows = (dimy - 1) * n->tcache.cellpixy;
|
||||
clamp_to_sixelmax(&n->tcache, &disprows, &dispcols);
|
||||
}
|
||||
if(scale == NCSCALE_SCALE || scale == NCSCALE_SCALE_HIRES){
|
||||
scale_visual(ncv, &disprows, &dispcols);
|
||||
|
@ -946,6 +946,16 @@ static inline bool sprixel_kitty_p(const tinfo* t){
|
||||
return t->pixel_shutdown == kitty_shutdown;
|
||||
}
|
||||
|
||||
static inline void
|
||||
clamp_to_sixelmax(const tinfo* t, int* y, int* x){
|
||||
if(t->sixel_maxy && *y > t->sixel_maxy){
|
||||
*y = t->sixel_maxy;
|
||||
}
|
||||
if(t->sixel_maxx && *x > t->sixel_maxx){
|
||||
*x = t->sixel_maxx;
|
||||
}
|
||||
}
|
||||
|
||||
// get the TAM entry for these (absolute) coordinates
|
||||
static inline sprixcell_e
|
||||
sprixel_state(sprixel* s, int y, int x){
|
||||
|
@ -36,6 +36,7 @@ ncvisual_set_data(ncvisual* ncv, void* data, bool owned){
|
||||
ncv->owndata = owned;
|
||||
}
|
||||
|
||||
// shrink one dimension to retrieve the original aspect ratio
|
||||
static inline void
|
||||
scale_visual(const ncvisual* ncv, int* disprows, int* dispcols){
|
||||
float xratio = (float)(*dispcols) / ncv->cols;
|
||||
|
@ -618,26 +618,25 @@ ncplane* ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const struct blits
|
||||
dispcols = ncv->cols;
|
||||
disprows = ncv->rows;
|
||||
}
|
||||
clamp_to_sixelmax(&nc->tcache, &disprows, &dispcols);
|
||||
ncplane* createdn = NULL;
|
||||
//fprintf(stderr, "INPUT N: %p rows: %d cols: %d 0x%016lx\n", n ? n : NULL, disprows, dispcols, flags);
|
||||
if(n == NULL){ // create plane
|
||||
if(scaling == NCSCALE_NONE || scaling == NCSCALE_NONE_HIRES){
|
||||
dispcols = ncv->cols;
|
||||
disprows = ncv->rows;
|
||||
}else{
|
||||
if(scaling != NCSCALE_NONE && scaling != NCSCALE_NONE_HIRES){
|
||||
notcurses_term_dim_yx(nc, &disprows, &dispcols);
|
||||
--disprows; // some terminals scroll when bitmaps hit the last line
|
||||
dispcols *= nc->tcache.cellpixx;
|
||||
disprows *= nc->tcache.cellpixy;
|
||||
clamp_to_sixelmax(&nc->tcache, &disprows, &dispcols);
|
||||
if(scaling == NCSCALE_SCALE || scaling == NCSCALE_SCALE_HIRES){
|
||||
scale_visual(ncv, &disprows, &dispcols);
|
||||
} // else stretch
|
||||
scale_visual(ncv, &disprows, &dispcols); // can only shrink
|
||||
}
|
||||
}
|
||||
struct ncplane_options nopts = {
|
||||
.y = placey,
|
||||
.x = placex,
|
||||
.rows = disprows / nc->tcache.cellpixy + !!(disprows % nc->tcache.cellpixy),
|
||||
.cols = dispcols / nc->tcache.cellpixx + !!(dispcols % nc->tcache.cellpixx),
|
||||
.rows = (disprows + nc->tcache.cellpixy - 1) / nc->tcache.cellpixy,
|
||||
.cols = (dispcols + nc->tcache.cellpixx - 1) / nc->tcache.cellpixx,
|
||||
.userptr = NULL,
|
||||
.name = "bmap",
|
||||
.resizecb = NULL,
|
||||
@ -661,6 +660,7 @@ ncplane* ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const struct blits
|
||||
ncplane_dim_yx(n, &disprows, &dispcols);
|
||||
dispcols *= nc->tcache.cellpixx;
|
||||
disprows *= nc->tcache.cellpixy;
|
||||
clamp_to_sixelmax(&nc->tcache, &disprows, &dispcols);
|
||||
if(!(flags & NCVISUAL_OPTION_HORALIGNED)){
|
||||
dispcols -= (placex * nc->tcache.cellpixx + 1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user