mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 01:29:05 -04:00
blitters: take bpp as parameter to deal with OIIO pixel_stride() #1723
This commit is contained in:
parent
383dc90842
commit
bb243989d3
@ -41,9 +41,9 @@ rgba_trans_q(const unsigned char* p, uint32_t transcolor){
|
||||
// Retarded RGBA blitter (ASCII only).
|
||||
static inline int
|
||||
tria_blit_ascii(ncplane* nc, int linesize, const void* data,
|
||||
int leny, int lenx, const blitterargs* bargs){
|
||||
int leny, int lenx, const blitterargs* bargs,
|
||||
int bpp){
|
||||
//fprintf(stderr, "ASCII %d X %d @ %d X %d (%p) place: %d X %d\n", leny, lenx, bargs->begy, bargs->begx, data, bargs->u.cell.placey, bargs->u.cell.placex);
|
||||
const int bpp = 32;
|
||||
int dimy, dimx, x, y;
|
||||
int total = 0; // number of cells written
|
||||
ncplane_dim_yx(nc, &dimy, &dimx);
|
||||
@ -94,11 +94,10 @@ tria_blit_ascii(ncplane* nc, int linesize, const void* data,
|
||||
// RGBA half-block blitter. Best for most images/videos. Full fidelity
|
||||
// combined with 1:1 pixel aspect ratio.
|
||||
static inline int
|
||||
tria_blit(ncplane* nc, int linesize, const void* data,
|
||||
int leny, int lenx, const blitterargs* bargs){
|
||||
tria_blit(ncplane* nc, int linesize, const void* data, int leny, int lenx,
|
||||
const blitterargs* bargs, int bpp){
|
||||
//fprintf(stderr, "HALF %d X %d @ %d X %d (%p) place: %d X %d\n", leny, lenx, bargs->begy, bargs->begx, data, bargs->u.cell.placey, bargs->u.cell.placex);
|
||||
uint32_t transcolor = bargs->transcolor;
|
||||
const int bpp = 32;
|
||||
int dimy, dimx, x, y;
|
||||
int total = 0; // number of cells written
|
||||
ncplane_dim_yx(nc, &dimy, &dimx);
|
||||
@ -424,9 +423,8 @@ qtrans_check(nccell* c, unsigned blendcolors,
|
||||
// quadrant blitter. maps 2x2 to each cell. since we only have two colors at
|
||||
// our disposal (foreground and background), we lose some fidelity.
|
||||
static inline int
|
||||
quadrant_blit(ncplane* nc, int linesize, const void* data,
|
||||
int leny, int lenx, const blitterargs* bargs){
|
||||
const int bpp = 32;
|
||||
quadrant_blit(ncplane* nc, int linesize, const void* data, int leny, int lenx,
|
||||
const blitterargs* bargs, int bpp){
|
||||
int dimy, dimx, x, y;
|
||||
int total = 0; // number of cells written
|
||||
ncplane_dim_yx(nc, &dimy, &dimx);
|
||||
@ -653,9 +651,8 @@ sex_trans_check(cell* c, const uint32_t rgbas[6], unsigned blendcolors,
|
||||
// sextant blitter. maps 3x2 to each cell. since we only have two colors at
|
||||
// our disposal (foreground and background), we lose some fidelity.
|
||||
static inline int
|
||||
sextant_blit(ncplane* nc, int linesize, const void* data,
|
||||
int leny, int lenx, const blitterargs* bargs){
|
||||
const int bpp = 32;
|
||||
sextant_blit(ncplane* nc, int linesize, const void* data, int leny, int lenx,
|
||||
const blitterargs* bargs, int bpp){
|
||||
int dimy, dimx, x, y;
|
||||
int total = 0; // number of cells written
|
||||
ncplane_dim_yx(nc, &dimy, &dimx);
|
||||
@ -727,9 +724,8 @@ fold_rgb8(unsigned* restrict r, unsigned* restrict g, unsigned* restrict b,
|
||||
// visuals with only two colors in a given area, as it packs lots of
|
||||
// resolution. always transparent background.
|
||||
static inline int
|
||||
braille_blit(ncplane* nc, int linesize, const void* data,
|
||||
int leny, int lenx, const blitterargs* bargs){
|
||||
const int bpp = 32;
|
||||
braille_blit(ncplane* nc, int linesize, const void* data, int leny, int lenx,
|
||||
const blitterargs* bargs, int bpp){
|
||||
int dimy, dimx, x, y;
|
||||
int total = 0; // number of cells written
|
||||
ncplane_dim_yx(nc, &dimy, &dimx);
|
||||
@ -1065,7 +1061,7 @@ int ncblit_rgba(const void* data, int linesize, const struct ncvisual_options* v
|
||||
},
|
||||
},
|
||||
};
|
||||
return bset->blit(nc, linesize, data, leny, lenx, &bargs);
|
||||
return bset->blit(nc, linesize, data, leny, lenx, &bargs, 32);
|
||||
}
|
||||
|
||||
ncblitter_e ncvisual_media_defblitter(const notcurses* nc, ncscale_e scale){
|
||||
|
@ -528,7 +528,8 @@ typedef struct blitterargs {
|
||||
// from scaling. we might actually need more pixels due to framing concerns,
|
||||
// in which case just assume transparent input pixels where needed.
|
||||
typedef int (*ncblitter)(struct ncplane* n, int linesize, const void* data,
|
||||
int scaledy, int scaledx, const blitterargs* bargs);
|
||||
int scaledy, int scaledx, const blitterargs* bargs,
|
||||
int bpp);
|
||||
|
||||
// a system for rendering RGBA pixels as text glyphs or sixel/kitty bitmaps
|
||||
struct blitset {
|
||||
@ -879,11 +880,11 @@ void sixelmap_free(struct sixelmap *s);
|
||||
// the transparency vector up into 1/8th as many bytes.
|
||||
uint8_t* sprixel_auxiliary_vector(const sprixel* s);
|
||||
|
||||
int sixel_blit(ncplane* nc, int linesize, const void* data,
|
||||
int leny, int lenx, const blitterargs* bargs);
|
||||
int sixel_blit(ncplane* nc, int linesize, const void* data, int leny, int lenx,
|
||||
const blitterargs* bargs, int bpp);
|
||||
|
||||
int kitty_blit(ncplane* nc, int linesize, const void* data,
|
||||
int leny, int lenx, const blitterargs* bargs);
|
||||
int kitty_blit(ncplane* nc, int linesize, const void* data, int leny, int lenx,
|
||||
const blitterargs* bargs, int bpp);
|
||||
|
||||
static inline int
|
||||
sprite_destroy(const notcurses* nc, const ncpile* p, FILE* out, sprixel* s){
|
||||
@ -1581,8 +1582,9 @@ const struct blitset* lookup_blitset(const tinfo* tcache, ncblitter_e setid, boo
|
||||
static inline int
|
||||
rgba_blit_dispatch(ncplane* nc, const struct blitset* bset,
|
||||
int linesize, const void* data,
|
||||
int leny, int lenx, const blitterargs* bargs){
|
||||
return bset->blit(nc, linesize, data, leny, lenx, bargs);
|
||||
int leny, int lenx, const blitterargs* bargs,
|
||||
int bpp){
|
||||
return bset->blit(nc, linesize, data, leny, lenx, bargs, bpp);
|
||||
}
|
||||
|
||||
static inline const struct blitset*
|
||||
|
@ -508,8 +508,8 @@ write_kitty_data(FILE* fp, int linesize, int leny, int lenx,
|
||||
|
||||
// Kitty graphics blitter. Kitty can take in up to 4KiB at a time of (optionally
|
||||
// deflate-compressed) 24bit RGB. Returns -1 on error, 1 on success.
|
||||
int kitty_blit(ncplane* n, int linesize, const void* data,
|
||||
int leny, int lenx, const blitterargs* bargs){
|
||||
int kitty_blit(ncplane* n, int linesize, const void* data, int leny, int lenx,
|
||||
const blitterargs* bargs, int bpp __attribute__ ((unused))){
|
||||
int cols = bargs->u.pixel.spx->dimx;
|
||||
int rows = bargs->u.pixel.spx->dimy;
|
||||
char* buf = NULL;
|
||||
|
@ -740,8 +740,8 @@ sixel_blit_inner(int leny, int lenx, sixeltable* stab,
|
||||
|
||||
// |leny| and |lenx| are the scaled output geometry. we take |leny| up to the
|
||||
// nearest multiple of six greater than or equal to |leny|.
|
||||
int sixel_blit(ncplane* n, int linesize, const void* data,
|
||||
int leny, int lenx, const blitterargs* bargs){
|
||||
int sixel_blit(ncplane* n, int linesize, const void* data, int leny, int lenx,
|
||||
const blitterargs* bargs, int bpp __attribute__ ((unused))){
|
||||
int colorregs = bargs->u.pixel.colorregs;
|
||||
if(colorregs <= 0){
|
||||
return -1;
|
||||
|
@ -70,7 +70,7 @@ int ncvisual_blit(ncvisual* ncv, int rows, int cols, ncplane* n,
|
||||
if(data == NULL){
|
||||
return -1;
|
||||
}
|
||||
if(rgba_blit_dispatch(n, bset, stride, data, rows, cols, barg) >= 0){
|
||||
if(rgba_blit_dispatch(n, bset, stride, data, rows, cols, barg, 32) >= 0){
|
||||
ret = 0;
|
||||
}
|
||||
if(data != ncv->data){
|
||||
|
@ -551,7 +551,7 @@ int ffmpeg_blit(ncvisual* ncv, int rows, int cols, ncplane* n,
|
||||
}
|
||||
//fprintf(stderr, "WHN NCV: %d/%d bargslen: %d/%d targ: %d/%d\n", inframe->width, inframe->height, bargs->leny, bargs->lenx, rows, cols);
|
||||
int ret = 0;
|
||||
if(rgba_blit_dispatch(n, bset, stride, data, rows, cols, bargs) < 0){
|
||||
if(rgba_blit_dispatch(n, bset, stride, data, rows, cols, bargs, 32) < 0){
|
||||
//fprintf(stderr, "rgba dispatch failed!\n");
|
||||
ret = -1;
|
||||
}
|
||||
|
@ -6,8 +6,9 @@
|
||||
|
||||
int oiio_blit_dispatch(struct ncplane* nc, const struct blitset* bset,
|
||||
int linesize, const void* data,
|
||||
int leny, int lenx, const blitterargs* bargs){
|
||||
if(rgba_blit_dispatch(nc, bset, linesize, data, leny, lenx, bargs) < 0){
|
||||
int leny, int lenx, const blitterargs* bargs,
|
||||
int bpp){
|
||||
if(rgba_blit_dispatch(nc, bset, linesize, data, leny, lenx, bargs, bpp) < 0){
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -129,10 +129,6 @@ int oiio_resize(ncvisual* nc, int rows, int cols) {
|
||||
//fprintf(stderr, "%d/%d -> %d/%d on the resize\n", nc->pixy, nc->pixx, rows, cols);
|
||||
auto ibuf = std::make_unique<OIIO::ImageBuf>();
|
||||
if(nc->details->ibuf && (nc->pixx != cols || nc->pixy != rows)){ // scale it
|
||||
OIIO::ImageSpec sp{};
|
||||
sp.width = cols;
|
||||
sp.height = rows;
|
||||
ibuf->reset(sp, OIIO::InitializePixels::Yes);
|
||||
OIIO::ROI roi(0, cols, 0, rows, 0, 1, 0, 4);
|
||||
if(!OIIO::ImageBufAlgo::resize(*ibuf, *nc->details->ibuf, "", 0, roi)){
|
||||
return -1;
|
||||
@ -155,23 +151,20 @@ int oiio_blit(struct ncvisual* ncv, int rows, int cols,
|
||||
int stride = 0;
|
||||
auto ibuf = std::make_unique<OIIO::ImageBuf>();
|
||||
if(ncv->details->ibuf && (ncv->pixx != cols || ncv->pixy != rows)){ // scale it
|
||||
OIIO::ImageSpec sp{};
|
||||
sp.width = cols;
|
||||
sp.height = rows;
|
||||
// FIXME need to honor leny/lenx and begy/begx
|
||||
ibuf->reset(sp, OIIO::InitializePixels::Yes);
|
||||
OIIO::ROI roi(0, cols, 0, rows, 0, 1, 0, 4);
|
||||
if(!OIIO::ImageBufAlgo::resize(*ibuf, *ncv->details->ibuf, "", 0, roi)){
|
||||
return -1;
|
||||
}
|
||||
stride = cols * 4;
|
||||
stride = ibuf->scanline_stride();
|
||||
//std::cerr << "output: " << ibuf->roi() << " stride: " << stride << std::endl;
|
||||
data = ibuf->localpixels();
|
||||
//fprintf(stderr, "HAVE SOME NEW DATA: %p\n", ibuf->localpixels());
|
||||
}else{
|
||||
data = ncv->data;
|
||||
stride = ncv->rowstride;
|
||||
}
|
||||
return oiio_blit_dispatch(n, bset, stride, data, rows, cols, bargs);
|
||||
return oiio_blit_dispatch(n, bset, stride, data, rows, cols, bargs, ibuf->pixel_stride() * CHAR_BIT);
|
||||
}
|
||||
|
||||
// FIXME before we can enable this, we need build an OIIO::APPBUFFER-style
|
||||
|
@ -21,7 +21,8 @@ ncvisual* oiio_create(void);
|
||||
void oiio_destroy(ncvisual* ncv);
|
||||
int oiio_blit_dispatch(struct ncplane* nc, const struct blitset* bset,
|
||||
int linesize, const void* data,
|
||||
int leny, int lenx, const blitterargs* bargs);
|
||||
int leny, int lenx, const blitterargs* bargs,
|
||||
int bpp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user