Notcurses 3.0.16
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
visual.c File Reference
#include <math.h>
#include <string.h>
#include "builddef.h"
#include "visual-details.h"
#include "internal.h"
#include "sixel.h"
Include dependency graph for visual.c:

Go to the source code of this file.

Functions

int ncvisual_init (int logl)
 
void ncvisual_printbanner (fbuf *f)
 
int ncvisual_decode (ncvisual *nc)
 
int ncvisual_decode_loop (ncvisual *nc)
 
ncvisualncvisual_from_file (const char *filename)
 
int ncvisual_stream (notcurses *nc, ncvisual *ncv, float timescale, ncstreamcb streamer, const struct ncvisual_options *vopts, void *curry)
 
ncplanencvisual_subtitle_plane (ncplane *parent, const ncvisual *ncv)
 
int ncvisual_blit_internal (const ncvisual *ncv, int rows, int cols, ncplane *n, const struct blitset *bset, const blitterargs *barg)
 
void ncvisual_details_seed (struct ncvisual *ncv)
 
ncvisualncvisual_create (void)
 
int ncvisual_geom_inner (const tinfo *ti, const ncvisual *n, const struct ncvisual_options *vopts, ncvgeom *geom, const struct blitset **bset, unsigned *disppixy, unsigned *disppixx, unsigned *outy, unsigned *outx, int *placey, int *placex)
 
int ncvisual_geom (const notcurses *nc, const ncvisual *n, const struct ncvisual_options *vopts, ncvgeom *geom)
 
void * rgb_loose_to_rgba (const void *data, int rows, int *rowstride, int cols, int alpha)
 
void * rgb_packed_to_rgba (const void *data, int rows, int *rowstride, int cols, int alpha)
 
void * bgra_to_rgba (const void *data, int rows, int *rowstride, int cols, int alpha)
 
int ncvisual_bounding_box (const ncvisual *ncv, int *leny, int *lenx, int *offy, int *offx)
 
int ncvisual_rotate (ncvisual *ncv, double rads)
 
ncvisualncvisual_from_rgba (const void *rgba, int rows, int rowstride, int cols)
 
ncvisualncvisual_from_sixel (const char *s, unsigned leny, unsigned lenx)
 
ncvisualncvisual_from_rgb_packed (const void *rgba, int rows, int rowstride, int cols, int alpha)
 
ncvisualncvisual_from_rgb_loose (const void *rgba, int rows, int rowstride, int cols, int alpha)
 
ncvisualncvisual_from_bgra (const void *bgra, int rows, int rowstride, int cols)
 
ncvisualncvisual_from_palidx (const void *pdata, int rows, int rowstride, int cols, int palsize, int pstride, const uint32_t *palette)
 
int ncvisual_resize (ncvisual *n, int rows, int cols)
 
int ncvisual_resize_noninterpolative (ncvisual *n, int rows, int cols)
 
ncplanencvisual_render_cells (ncvisual *ncv, const struct blitset *bset, int placey, int placex, ncvgeom *geom, ncplane *n, uint64_t flags, uint32_t transcolor)
 
ncplanencvisual_render_pixels (notcurses *nc, ncvisual *ncv, const struct blitset *bset, int placey, int placex, const ncvgeom *geom, ncplane *n, uint64_t flags, uint32_t transcolor, int pxoffy, int pxoffx)
 
ncplanencvisual_blit (notcurses *nc, ncvisual *ncv, const struct ncvisual_options *vopts)
 
ncvisualncvisual_from_plane (const ncplane *n, ncblitter_e blit, int begy, int begx, unsigned leny, unsigned lenx)
 
void ncvisual_destroy (ncvisual *ncv)
 
int ncvisual_simple_streamer (ncvisual *ncv, struct ncvisual_options *vopts, const struct timespec *tspec, void *curry)
 
int ncvisual_set_yx (const struct ncvisual *n, unsigned y, unsigned x, uint32_t pixel)
 
int ncvisual_at_yx (const ncvisual *n, unsigned y, unsigned x, uint32_t *pixel)
 
int ncvisual_polyfill_yx (ncvisual *n, unsigned y, unsigned x, uint32_t rgba)
 
bool notcurses_canopen_images (const notcurses *nc __attribute__((unused)))
 
bool notcurses_canopen_videos (const notcurses *nc __attribute__((unused)))
 

Variables

ncvisual_implementationvisual_implementation = &null_visual_implementation
 

Function Documentation

◆ bgra_to_rgba()

void * bgra_to_rgba ( const void *  data,
int  rows,
int *  rowstride,
int  cols,
int  alpha 
)

Definition at line 508 of file visual.c.

508 {
509 if(*rowstride % 4){ // must be a multiple of 4 bytes
510 return NULL;
511 }
512 if(*rowstride < cols * 4){
513 return NULL;
514 }
515 uint32_t* ret = malloc(4 * cols * rows);
516 if(ret){
517 for(int y = 0 ; y < rows ; ++y){
518 for(int x = 0 ; x < cols ; ++x){
519 const uint32_t* src = (const uint32_t*)data + (*rowstride / 4) * y + x;
520 uint32_t* dst = ret + cols * y + x;
521 *dst = 0; // kill scan-build warning about using uninitialized value below
522 ncpixel_set_a(dst, alpha);
523 ncpixel_set_r(dst, ncpixel_b(*src));
524 ncpixel_set_g(dst, ncpixel_g(*src));
525 ncpixel_set_b(dst, ncpixel_r(*src));
526 }
527 }
528 }
529 *rowstride = cols * 4;
530 return ret;
531}
int y
Definition notcurses.h:1905
int int x
Definition notcurses.h:1905
return NULL
Definition termdesc.h:229
Here is the caller graph for this function:

◆ ncvisual_at_yx()

int ncvisual_at_yx ( const ncvisual n,
unsigned  y,
unsigned  x,
uint32_t *  pixel 
)

Definition at line 1278 of file visual.c.

1278 {
1279 if(y >= n->pixy){
1280 logerror("invalid coordinates %u/%u (%d/%d)", y, x, n->pixy, n->pixx);
1281 return -1;
1282 }
1283 if(x >= n->pixx){
1284 logerror("invalid coordinates %u/%u (%d/%d)", y, x, n->pixy, n->pixx);
1285 return -1;
1286 }
1287 *pixel = n->data[y * (n->rowstride / 4) + x];
1288 return 0;
1289}
#define logerror(fmt,...)
Definition logging.h:32
vopts n
Definition notcurses.h:3506
Here is the caller graph for this function:

◆ ncvisual_blit()

ncplane * ncvisual_blit ( notcurses nc,
ncvisual ncv,
const struct ncvisual_options vopts 
)

Definition at line 1142 of file visual.c.

1142 {
1143//fprintf(stderr, "%p tacache: %p\n", n, n->tacache);
1144 struct ncvisual_options fakevopts;
1145 if(vopts == NULL){
1146 memset(&fakevopts, 0, sizeof(fakevopts));
1147 vopts = &fakevopts;
1148 }
1149 loginfo("inblit %dx%d %d@%d %dx%d @ %dx%d %p", ncv->pixy, ncv->pixx, vopts->y, vopts->x,
1150 vopts->leny, vopts->lenx, vopts->begy, vopts->begx, vopts->n);
1151 ncvgeom geom;
1152 const struct blitset* bset;
1153 unsigned disppxy, disppxx, outy, outx;
1154 int placey, placex;
1155 if(ncvisual_geom_inner(&nc->tcache, ncv, vopts, &geom, &bset,
1156 &disppxy, &disppxx, &outy, &outx,
1157 &placey, &placex)){
1158 // ncvisual_blitset_geom() emits its own diagnostics, no need for an error here
1159 return NULL;
1160 }
1161 ncplane* n = vopts->n;
1162 uint32_t transcolor = 0;
1164 transcolor = 0x1000000ull | vopts->transcolor;
1165 }
1166 ncplane* createdn = NULL; // to destroy on error
1167 if(n == NULL || (vopts->flags & NCVISUAL_OPTION_CHILDPLANE)){ // create plane
1168 struct ncplane_options nopts = {
1169 .y = placey,
1170 .x = placex,
1171 .rows = geom.rcelly,
1172 .cols = geom.rcellx,
1173 .userptr = NULL,
1174 .name = geom.blitter == NCBLIT_PIXEL ? "bmap" : "cvis",
1175 .resizecb = NULL,
1176 .flags = 0,
1177 };
1180 nopts.x = vopts->x;
1181 }
1184 nopts.y = vopts->y;
1185 }
1186 loginfo("placing new plane: %d/%d @ %d/%d 0x%016" PRIx64, nopts.rows, nopts.cols, nopts.y, nopts.x, nopts.flags);
1187 if(n == NULL){
1188 n = ncpile_create(nc, &nopts);
1189 }else{
1190 n = ncplane_create(n, &nopts);
1191 }
1192 if((createdn = n) == NULL){
1193 return NULL;
1194 }
1195 placey = 0;
1196 placex = 0;
1197 }
1198 logdebug("blit to plane %p at %d/%d geom %dx%d", n, ncplane_abs_y(n), ncplane_abs_x(n), ncplane_dim_y(n), ncplane_dim_x(n));
1199 if(geom.blitter != NCBLIT_PIXEL){
1200 n = ncvisual_render_cells(ncv, bset, placey, placex,
1201 &geom, n, vopts->flags, transcolor);
1202 }else{
1203 n = ncvisual_render_pixels(nc, ncv, bset, placey, placex,
1204 &geom, n,
1205 vopts->flags, transcolor,
1206 vopts->pxoffy, vopts->pxoffx);
1207 }
1208 if(n == NULL){
1209 ncplane_destroy(createdn);
1210 }
1211 return n;
1212}
#define loginfo(fmt,...)
Definition logging.h:42
#define logdebug(fmt,...)
Definition logging.h:52
int ncplane_abs_x(const ncplane *n)
Definition notcurses.c:2643
ncplane * ncpile_create(notcurses *nc, const struct ncplane_options *nopts)
Definition notcurses.c:714
int ncplane_destroy(ncplane *ncp)
Definition notcurses.c:1021
int ncplane_abs_y(const ncplane *n)
Definition notcurses.c:2639
ncplane * ncplane_create(ncplane *n, const ncplane_options *nopts)
Definition notcurses.c:710
#define NCVISUAL_OPTION_CHILDPLANE
Definition notcurses.h:3346
const struct ncplane_options struct ncvisual * ncv
Definition notcurses.h:3488
#define NCPLANE_OPTION_HORALIGNED
Definition notcurses.h:1441
const struct ncplane_options struct ncvisual struct ncvisual_options * vopts
Definition notcurses.h:3488
#define NCPLANE_OPTION_VERALIGNED
Definition notcurses.h:1443
@ NCBLIT_PIXEL
Definition notcurses.h:73
#define NCVISUAL_OPTION_ADDALPHA
Definition notcurses.h:3345
#define NCVISUAL_OPTION_VERALIGNED
Definition notcurses.h:3344
#define NCVISUAL_OPTION_HORALIGNED
Definition notcurses.h:3343
ncblitter_e geom
Definition internal.h:399
ncblitter_e blitter
Definition notcurses.h:3410
unsigned rcellx
Definition notcurses.h:3405
unsigned rcelly
Definition notcurses.h:3405
tinfo tcache
Definition internal.h:360
ncplane * ncvisual_render_pixels(notcurses *nc, ncvisual *ncv, const struct blitset *bset, int placey, int placex, const ncvgeom *geom, ncplane *n, uint64_t flags, uint32_t transcolor, int pxoffy, int pxoffx)
Definition visual.c:1056
int ncvisual_geom_inner(const tinfo *ti, const ncvisual *n, const struct ncvisual_options *vopts, ncvgeom *geom, const struct blitset **bset, unsigned *disppixy, unsigned *disppixx, unsigned *outy, unsigned *outx, int *placey, int *placex)
Definition visual.c:208
ncplane * ncvisual_render_cells(ncvisual *ncv, const struct blitset *bset, int placey, int placex, ncvgeom *geom, ncplane *n, uint64_t flags, uint32_t transcolor)
Definition visual.c:1019
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncvisual_blit_internal()

int ncvisual_blit_internal ( const ncvisual ncv,
int  rows,
int  cols,
ncplane n,
const struct blitset bset,
const blitterargs barg 
)

Definition at line 84 of file visual.c.

85 {
88 if(visual_implementation->visual_blit(ncv, rows, cols, n, bset, barg) < 0){
89 return -1;
90 }
91 return 0;
92 }
93 }
94 // generic implementation
95 int stride = 4 * cols;
96 uint32_t* data = resize_bitmap(ncv->data, ncv->pixy, ncv->pixx,
97 ncv->rowstride, rows, cols, stride);
98 if(data == NULL){
99 return -1;
100 }
101 int ret = -1;
102 if(rgba_blit_dispatch(n, bset, stride, data, rows, cols, barg) >= 0){
103 ret = 0;
104 }
105 if(data != ncv->data){
106 free(data);
107 }
108 return ret;
109}
#define NCVISUAL_OPTION_NOINTERPOLATE
Definition notcurses.h:3347
uint64_t flags
Definition internal.h:379
int(* visual_blit)(const struct ncvisual *ncv, unsigned rows, unsigned cols, ncplane *n, const struct blitset *bset, const blitterargs *barg)
Definition internal.h:1794
ncvisual_implementation * visual_implementation
Definition visual.c:20
Here is the caller graph for this function:

◆ ncvisual_bounding_box()

int ncvisual_bounding_box ( const ncvisual ncv,
int *  leny,
int *  lenx,
int *  offy,
int *  offx 
)

Definition at line 537 of file visual.c.

538 {
539 unsigned lcol = 0;
540 unsigned rcol = UINT_MAX;
541 unsigned trow;
542 // first, find the topmost row with a real pixel. if there is no such row,
543 // there are no such pixels. if we find one, we needn't look in this region
544 // for other extrema, so long as we keep the leftmost and rightmost through
545 // this row (from the top). said leftmost and rightmost will be the leftmost
546 // and rightmost pixel of whichever row has the topmost valid pixel. unlike
547 // the topmost, they'll need be further verified.
548 for(trow = 0 ; trow < ncv->pixy ; ++trow){
549 for(unsigned x = 0 ; x < ncv->pixx ; ++x){
550 uint32_t rgba = ncv->data[trow * ncv->rowstride / 4 + x];
551 if(rgba){
552 lcol = x; // leftmost pixel of topmost row
553 // now find rightmost pixel of topmost row
554 unsigned xr;
555 for(xr = ncv->pixx - 1 ; xr > x ; --xr){
556 rgba = ncv->data[trow * ncv->rowstride / 4 + xr];
557 if(rgba){ // rightmost pixel of topmost row
558 break;
559 }
560 }
561 rcol = xr;
562 break;
563 }
564 }
565 if(rcol < INT_MAX){
566 break;
567 }
568 }
569 if(trow == ncv->pixy){ // no real pixels
570 *leny = 0;
571 *lenx = 0;
572 *offy = 0;
573 *offx = 0;
574 }else{
575 assert(rcol < ncv->pixx);
576 // we now know topmost row, and left/rightmost through said row. now we must
577 // find the bottommost row, checking left/rightmost throughout.
578 unsigned brow;
579 for(brow = ncv->pixy - 1 ; brow > trow ; --brow){
580 unsigned x;
581 for(x = 0 ; x < ncv->pixx ; ++x){
582 uint32_t rgba = ncv->data[brow * ncv->rowstride / 4 + x];
583 if(rgba){
584 if(x < lcol){
585 lcol = x;
586 }
587 unsigned xr;
588 for(xr = ncv->pixx - 1 ; xr > x && xr > rcol ; --xr){
589 rgba = ncv->data[brow * ncv->rowstride / 4 + xr];
590 if(rgba){ // rightmost pixel of bottommost row
591 if(xr > rcol){
592 rcol = xr;
593 }
594 break;
595 }
596 }
597 break;
598 }
599 }
600 if(x < ncv->pixx){
601 break;
602 }
603 }
604 // we now know topmost and bottommost row, and left/rightmost within those
605 // two sections. now check the rest for left and rightmost.
606 for(unsigned y = trow + 1 ; y < brow ; ++y){
607 for(unsigned x = 0 ; x < lcol ; ++x){
608 uint32_t rgba = ncv->data[y * ncv->rowstride / 4 + x];
609 if(rgba){
610 lcol = x;
611 break;
612 }
613 }
614 for(unsigned x = ncv->pixx - 1 ; x > rcol ; --x){
615 uint32_t rgba = ncv->data[y * ncv->rowstride / 4 + x];
616 if(rgba){
617 rcol = x;
618 break;
619 }
620 }
621 }
622 *offy = trow;
623 *leny = brow - trow + 1;
624 *offx = lcol;
625 *lenx = rcol - lcol + 1;
626 }
627 return *leny * *lenx;
628}
assert(r >=0)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncvisual_create()

ncvisual * ncvisual_create ( void  )

Definition at line 120 of file visual.c.

120 {
123 }
124 ncvisual* ret = malloc(sizeof(*ret));
125 if(ret){
126 memset(ret, 0, sizeof(*ret));
127 }
128 return ret;
129}
struct ncvisual *(* visual_create)(void)
Definition internal.h:1796
Here is the caller graph for this function:

◆ ncvisual_decode()

int ncvisual_decode ( ncvisual nc)

Definition at line 39 of file visual.c.

39 {
41 return -1;
42 }
44}
int(* visual_decode)(struct ncvisual *nc)
Definition internal.h:1802
Here is the caller graph for this function:

◆ ncvisual_decode_loop()

int ncvisual_decode_loop ( ncvisual nc)

Definition at line 46 of file visual.c.

46 {
48 return -1;
49 }
51}
int(* visual_decode_loop)(struct ncvisual *nc)
Definition internal.h:1803
Here is the caller graph for this function:

◆ ncvisual_destroy()

void ncvisual_destroy ( ncvisual ncv)

Definition at line 1231 of file visual.c.

1231 {
1232 if(ncv){
1234 if(ncv->owndata){
1235 free(ncv->data);
1236 }
1237 free(ncv);
1238 }else{
1240 }
1241 }
1242}
void(* visual_destroy)(struct ncvisual *ncv)
Definition internal.h:1810
Here is the caller graph for this function:

◆ ncvisual_details_seed()

void ncvisual_details_seed ( struct ncvisual ncv)

Definition at line 114 of file visual.c.

114 {
117 }
118}
void(* visual_details_seed)(struct ncvisual *ncv)
Definition internal.h:1801
Here is the caller graph for this function:

◆ ncvisual_from_bgra()

ncvisual * ncvisual_from_bgra ( const void *  bgra,
int  rows,
int  rowstride,
int  cols 
)

Definition at line 895 of file visual.c.

895 {
896 if(rowstride % 4){
897 logerror("rowstride %d not a multiple of 4", rowstride);
898 return NULL;
899 }
900 if(rows <= 0 || cols <= 0 || rowstride < cols * 4){
901 logerror("illegal bgra geometry");
902 return NULL;
903 }
905 if(ncv){
906 ncv->rowstride = pad_for_image(rowstride, cols);
907 ncv->pixx = cols;
908 ncv->pixy = rows;
909 uint32_t* data = malloc(ncv->rowstride * ncv->pixy);
910 if(data == NULL){
912 return NULL;
913 }
914 for(int y = 0 ; y < rows ; ++y){
915 for(int x = 0 ; x < cols ; ++x){
916 uint32_t src;
917 memcpy(&src, (const char*)bgra + y * rowstride + x * 4, 4);
918 uint32_t* dst = &data[ncv->rowstride * y / 4 + x];
919 *dst = 0; // kill scan-build warning about using uninitialized value below
920 ncpixel_set_a(dst, ncpixel_a(src));
921 ncpixel_set_r(dst, ncpixel_b(src));
922 ncpixel_set_g(dst, ncpixel_g(src));
923 ncpixel_set_b(dst, ncpixel_r(src));
924//fprintf(stderr, "BGRA PIXEL: %02x%02x%02x%02x RGBA result: %02x%02x%02x%02x\n", ((const char*)&src)[0], ((const char*)&src)[1], ((const char*)&src)[2], ((const char*)&src)[3], ((const char*)dst)[0], ((const char*)dst)[1], ((const char*)dst)[2], ((const char*)dst)[3]);
925 }
926 }
927 ncvisual_set_data(ncv, data, true);
929 }
930 return ncv;
931}
void ncvisual_details_seed(struct ncvisual *ncv)
Definition visual.c:114
void ncvisual_destroy(ncvisual *ncv)
Definition visual.c:1231
ncvisual * ncvisual_create(void)
Definition visual.c:120
Here is the call graph for this function:

◆ ncvisual_from_file()

ncvisual * ncvisual_from_file ( const char *  filename)

Definition at line 53 of file visual.c.

53 {
55 return NULL;
56 }
58 if(n == NULL){
59 logerror("error loading %s", filename);
60 }
61 return n;
62}
struct ncvisual *(* visual_from_file)(const char *fname)
Definition internal.h:1797
Here is the caller graph for this function:

◆ ncvisual_from_palidx()

ncvisual * ncvisual_from_palidx ( const void *  pdata,
int  rows,
int  rowstride,
int  cols,
int  palsize,
int  pstride,
const uint32_t *  palette 
)

Definition at line 933 of file visual.c.

935 {
936 if(pstride <= 0 || rowstride % pstride){
937 logerror("bad pstride (%d) for rowstride (%d)", pstride, rowstride);
938 return NULL;
939 }
940 if(rows <= 0 || cols <= 0 || rowstride < cols * pstride){
941 logerror("illegal palimg geometry");
942 return NULL;
943 }
944 if(palsize > 256 || palsize <= 0){
945 logerror("palettes size (%d) is unsupported", palsize);
946 return NULL;
947 }
949 if(ncv){
950 ncv->rowstride = pad_for_image(rowstride, cols);
951 ncv->pixx = cols;
952 ncv->pixy = rows;
953 uint32_t* data = malloc(ncv->rowstride * ncv->pixy);
954 if(data == NULL){
956 return NULL;
957 }
958 for(int y = 0 ; y < rows ; ++y){
959 for(int x = 0 ; x < cols ; ++x){
960 int palidx = ((const unsigned char*)pdata)[y * rowstride + x * pstride];
961 if(palidx >= palsize){
962 free(data);
964 logerror("invalid palette idx %d >= %d", palidx, palsize);
965 return NULL;
966 }
967 uint32_t src = palette[palidx];
968 uint32_t* dst = &data[ncv->rowstride * y / 4 + x];
969 if(ncchannel_default_p(src)){
970 *dst = 0; // kill scan-build warning about using uninitialized value below
971 // FIXME use default color as detected, or just 0xffffff
972 ncpixel_set_a(dst, 255 - palidx);
973 ncpixel_set_r(dst, palidx);
974 ncpixel_set_g(dst, 220 - (palidx / 2));
975 ncpixel_set_b(dst, palidx);
976 }else{
977 *dst = 0;
978 }
979//fprintf(stderr, "BGRA PIXEL: %02x%02x%02x%02x RGBA result: %02x%02x%02x%02x\n", ((const char*)&src)[0], ((const char*)&src)[1], ((const char*)&src)[2], ((const char*)&src)[3], ((const char*)dst)[0], ((const char*)dst)[1], ((const char*)dst)[2], ((const char*)dst)[3]);
980 }
981 }
982 ncvisual_set_data(ncv, data, true);
984 }
985 return ncv;
986}
Here is the call graph for this function:

◆ ncvisual_from_plane()

ncvisual * ncvisual_from_plane ( const ncplane n,
ncblitter_e  blit,
int  begy,
int  begx,
unsigned  leny,
unsigned  lenx 
)

Definition at line 1214 of file visual.c.

1216 {
1217 unsigned py, px;
1218 uint32_t* rgba = ncplane_as_rgba(n, blit, begy, begx, leny, lenx, &py, &px);
1219//fprintf(stderr, "snarg: %d/%d @ %d/%d (%p)\n", leny, lenx, begy, begx, rgba);
1220 if(rgba == NULL){
1221 return NULL;
1222 }
1223 unsigned dimy, dimx;
1224 ncplane_dim_yx(n, &dimy, &dimx);
1225 ncvisual* ncv = ncvisual_from_rgba(rgba, py, px * 4, px);
1226 free(rgba);
1227//fprintf(stderr, "RETURNING %p\n", ncv);
1228 return ncv;
1229}
uint32_t * ncplane_as_rgba(const ncplane *nc, ncblitter_e blit, int begy, int begx, unsigned leny, unsigned lenx, unsigned *pxdimy, unsigned *pxdimx)
Definition notcurses.c:3216
void ncplane_dim_yx(const ncplane *n, unsigned *rows, unsigned *cols)
Definition notcurses.c:304
ncvisual * ncvisual_from_rgba(const void *rgba, int rows, int rowstride, int cols)
Definition visual.c:779
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncvisual_from_rgb_loose()

ncvisual * ncvisual_from_rgb_loose ( const void *  rgba,
int  rows,
int  rowstride,
int  cols,
int  alpha 
)

Definition at line 862 of file visual.c.

863 {
864 if(rowstride % 4){
865 logerror("rowstride %d not a multiple of 4", rowstride);
866 return NULL;
867 }
868 if(rows <= 0 || cols <= 0 || rowstride < cols * 4){
869 logerror("illegal packed rgb geometry");
870 return NULL;
871 }
873 if(ncv){
874 ncv->rowstride = pad_for_image(cols * 4, cols);
875 ncv->pixx = cols;
876 ncv->pixy = rows;
877 uint32_t* data = malloc(ncv->rowstride * ncv->pixy);
878 if(data == NULL){
880 return NULL;
881 }
882 for(int y = 0 ; y < rows ; ++y){
883//fprintf(stderr, "ROWS: %d STRIDE: %d (%d) COLS: %d %08x\n", ncv->pixy, ncv->rowstride, ncv->rowstride / 4, cols, data[ncv->rowstride * y / 4]);
884 memcpy(data + (ncv->rowstride * y) / 4, (const char*)rgba + rowstride * y, rowstride);
885 for(int x = 0 ; x < cols ; ++x){
886 ncpixel_set_a(&data[y * ncv->rowstride / 4 + x], alpha);
887 }
888 }
889 ncvisual_set_data(ncv, data, true);
891 }
892 return ncv;
893}
Here is the call graph for this function:

◆ ncvisual_from_rgb_packed()

ncvisual * ncvisual_from_rgb_packed ( const void *  rgba,
int  rows,
int  rowstride,
int  cols,
int  alpha 
)

Definition at line 820 of file visual.c.

821 {
822 if(rowstride % 3){
823 logerror("rowstride %d not a multiple of 3", rowstride);
824 return NULL;
825 }
826 if(rows <= 0 || cols <= 0 || rowstride < cols * 3){
827 logerror("illegal packed rgb geometry");
828 return NULL;
829 }
831 if(ncv){
832 ncv->rowstride = pad_for_image(cols * 4, cols);
833 ncv->pixx = cols;
834 ncv->pixy = rows;
835 uint32_t* data = malloc(ncv->rowstride * ncv->pixy);
836 if(data == NULL){
838 return NULL;
839 }
840 const unsigned char* src = rgba;
841 for(int y = 0 ; y < rows ; ++y){
842//fprintf(stderr, "ROWS: %d STRIDE: %d (%d) COLS: %d %08x\n", ncv->pixy, ncv->rowstride, ncv->rowstride / 4, cols, data[ncv->rowstride * y / 4]);
843 for(int x = 0 ; x < cols ; ++x){
844 unsigned char r, g, b;
845 memcpy(&r, src + rowstride * y + 3 * x, 1);
846 memcpy(&g, src + rowstride * y + 3 * x + 1, 1);
847 memcpy(&b, src + rowstride * y + 3 * x + 2, 1);
848 data[y * ncv->rowstride / 4 + x] = 0; // eliminate scan-build uninitialized data warning
849 ncpixel_set_a(&data[y * ncv->rowstride / 4 + x], alpha);
850 ncpixel_set_r(&data[y * ncv->rowstride / 4 + x], r);
851 ncpixel_set_g(&data[y * ncv->rowstride / 4 + x], g);
852 ncpixel_set_b(&data[y * ncv->rowstride / 4 + x], b);
853//fprintf(stderr, "RGBA: 0x%02x 0x%02x 0x%02x 0x%02x\n", r, g, b, alpha);
854 }
855 }
856 ncvisual_set_data(ncv, data, true);
858 }
859 return ncv;
860}
int r
Definition fbuf.h:226
Here is the call graph for this function:

◆ ncvisual_from_rgba()

ncvisual * ncvisual_from_rgba ( const void *  rgba,
int  rows,
int  rowstride,
int  cols 
)

Definition at line 779 of file visual.c.

779 {
780 if(rowstride % 4){
781 logerror("rowstride %d not a multiple of 4", rowstride);
782 return NULL;
783 }
784 if(rowstride * 4 < cols || cols <= 0 || rows <= 0){
785 logerror("invalid rowstride or geometry");
786 return NULL;
787 }
789 if(ncv){
790 // ffmpeg needs inputs with rows aligned on 192-byte boundaries
791 ncv->rowstride = pad_for_image(rowstride, cols);
792 ncv->pixx = cols;
793 ncv->pixy = rows;
794 uint32_t* data = malloc(ncv->rowstride * ncv->pixy);
795 if(data == NULL){
797 return NULL;
798 }
799 for(int y = 0 ; y < rows ; ++y){
800//fprintf(stderr, "ROWS: %d STRIDE: %d (%d) COLS: %d %08x\n", ncv->pixy, ncv->rowstride, rowstride, cols, data[ncv->rowstride * y / 4]);
801 memcpy(data + (ncv->rowstride * y) / 4, (const char*)rgba + rowstride * y, rowstride);
802 }
803 ncvisual_set_data(ncv, data, true);
805 }
806 return ncv;
807}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncvisual_from_sixel()

ncvisual * ncvisual_from_sixel ( const char *  s,
unsigned  leny,
unsigned  lenx 
)

Definition at line 809 of file visual.c.

809 {
810 uint32_t* rgba = ncsixel_as_rgba(s, leny, lenx);
811 if(rgba == NULL){
812 logerror("failed converting sixel to rgba");
813 return NULL;
814 }
815 ncvisual* ncv = ncvisual_from_rgba(rgba, leny, lenx * sizeof(*rgba), lenx);
816 free(rgba);
817 return ncv;
818}
uint32_t * ncsixel_as_rgba(const char *sx, unsigned leny, unsigned lenx)
Definition sixel.h:12
Here is the call graph for this function:

◆ ncvisual_geom()

int ncvisual_geom ( const notcurses nc,
const ncvisual n,
const struct ncvisual_options vopts,
ncvgeom geom 
)

Definition at line 452 of file visual.c.

453 {
454 const struct blitset* bset;
455 unsigned disppxy, disppxx, outy, outx;
456 int placey, placex;
457 return ncvisual_geom_inner(nc ? &nc->tcache : NULL, n, vopts, geom, &bset,
458 &disppxy, &disppxx, &outy, &outx, &placey, &placex);
459}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncvisual_geom_inner()

int ncvisual_geom_inner ( const tinfo ti,
const ncvisual n,
const struct ncvisual_options vopts,
ncvgeom geom,
const struct blitset **  bset,
unsigned *  disppixy,
unsigned *  disppixx,
unsigned *  outy,
unsigned *  outx,
int *  placey,
int *  placex 
)

Definition at line 208 of file visual.c.

213 {
214 if(ti == NULL && n == NULL){
215 logerror("got NULL for both sources");
216 return -1;
217 }
218 struct ncvisual_options fakevopts;
219 if(vopts == NULL){
220 memset(&fakevopts, 0, sizeof(fakevopts));
221 vopts = &fakevopts;
222 }
223 // check basic vopts preconditions
225 logwarn("warning: unknown ncvisual options %016" PRIx64, vopts->flags);
226 }
228 logerror("requested child plane with NULL n");
229 return -1;
230 }
233 logerror("bad x %d for horizontal alignment", vopts->x);
234 return -1;
235 }
236 }
239 logerror("bad y %d for vertical alignment", vopts->y);
240 return -1;
241 }
242 }
243 if(n){
244 geom->pixy = n->pixy;
245 geom->pixx = n->pixx;
246 }
247 // when ti is NULL, we only report properties intrinsic to the ncvisual,
248 // i.e. only its original pixel geometry.
249 if(ti == NULL){
250 return 0;
251 }
252 // determine our blitter
253 *bset = rgba_blitter(ti, vopts);
254 if(!*bset){
255 logerror("couldn't get a blitter for %d", vopts ? vopts->blitter : NCBLIT_DEFAULT);
256 return -1;
257 }
258 const ncpile* p = vopts->n ? ncplane_pile_const(vopts->n) : NULL;
259 geom->cdimy = p ? p->cellpxy : ti->cellpxy;
260 geom->cdimx = p ? p->cellpxx : ti->cellpxx;
261 if((geom->blitter = (*bset)->geom) == NCBLIT_PIXEL){
262 geom->maxpixely = ti->sixel_maxy;
263 geom->maxpixelx = ti->sixel_maxx;
264 }
265 geom->scaley = encoding_y_scale(ti, *bset);
266 geom->scalex = encoding_x_scale(ti, *bset);
267 // when n is NULL, we only report properties unrelated to the ncvisual,
268 // i.e. the cell-pixel geometry, max bitmap geometry, blitter, and scaling.
269 if(n == NULL){
270 return 0;
271 }
273 // determine how much of the original image we're using (leny/lenx)
274 ncvisual_origin(vopts, &geom->begy, &geom->begx);
275 geom->lenx = vopts->lenx;
276 geom->leny = vopts->leny;
277 *placey = vopts->y;
278 *placex = vopts->x;
279 logdebug("vis %ux%u+%ux%u %p", geom->begy, geom->begx, geom->leny, geom->lenx, n->data);
280 if(n->data == NULL){
281 logerror("no data in visual");
282 return -1;
283 }
284 if(geom->begx >= n->pixx || geom->begy >= n->pixy){
285 logerror("visual too large %u > %d or %u > %d", geom->begy, n->pixy, geom->begx, n->pixx);
286 return -1;
287 }
288 if(geom->lenx == 0){ // 0 means "to the end"; use all available source material
289 geom->lenx = n->pixx - geom->begx;
290 }
291 if(geom->leny == 0){
292 geom->leny = n->pixy - geom->begy;
293 }
294 if(geom->lenx <= 0 || geom->leny <= 0){ // no need to draw zero-size object, exit
295 logerror("zero-size object %d %d", geom->leny, geom->lenx);
296 return -1;
297 }
298 if(geom->begx + geom->lenx > n->pixx || geom->begy + geom->leny > n->pixy){
299 logerror("geometry too large %d > %d or %d > %d", geom->begy + geom->leny, n->pixy, geom->begx + geom->lenx, n->pixx);
300 return -1;
301 }
302 if((*bset)->geom == NCBLIT_PIXEL){
303 if(vopts->n){
304 // FIXME does this work from direct mode?
307 logerror("won't blit bitmaps to the standard plane");
308 return -1;
309 }
310 }
312 logerror("non-origin y placement %d for sprixel", vopts->y);
313 return -1;
314 }
316 logerror("non-origin x placement %d for sprixel", vopts->x);
317 return -1;
318 }
319 if(vopts->pxoffy >= geom->cdimy){
320 logerror("pixel y-offset %d too tall for cell %d", vopts->pxoffy, geom->cdimy);
321 return -1;
322 }
323 if(vopts->pxoffx >= geom->cdimx){
324 logerror("pixel x-offset %d too wide for cell %d", vopts->pxoffx, geom->cdimx);
325 return -1;
326 }
328 // FIXME clamp to sprixel limits
329 unsigned rows = ((geom->leny + geom->cdimy - 1) / geom->cdimy) + !!vopts->pxoffy;
330 if(rows > ncplane_dim_y(vopts->n)){
331 logerror("sprixel too tall %d for plane %d", geom->leny + vopts->pxoffy,
332 ncplane_dim_y(vopts->n) * geom->cdimy);
333 return -1;
334 }
335 unsigned cols = ((geom->lenx + geom->cdimx - 1) / geom->cdimx) + !!vopts->pxoffx;
336 if(cols > ncplane_dim_x(vopts->n)){
337 logerror("sprixel too wide %d for plane %d", geom->lenx + vopts->pxoffx,
338 ncplane_dim_x(vopts->n) * geom->cdimx);
339 return -1;
340 }
341 }
342 }
344 // we'll need to create the plane
345 const int dimy = p ? p->dimy : ti->dimy;
346 const int dimx = p ? p->dimx : ti->dimx;
347 shape_sprixel_plane(ti, geom->cdimy, geom->cdimx, dimy, dimx,
348 vopts->n, n, scaling, disppixy, disppixx,
349 vopts->flags, outy, outx, placey, placex,
350 vopts->pxoffy, vopts->pxoffx);
351 }else{
353 ncplane_dim_yx(vopts->n, disppixy, disppixx);
354 *disppixx *= geom->cdimx;
355 *disppixx += vopts->pxoffx;
356 *disppixy *= geom->cdimy;
357 *disppixy += vopts->pxoffy;
358 clamp_to_sixelmax(ti, disppixy, disppixx, outy, scaling);
359 int absplacex = 0, absplacey = 0;
361 absplacex = *placex;
362 }
364 absplacey = *placey;
365 }
366 *disppixx -= absplacex * geom->cdimx;
367 *disppixy -= absplacey * geom->cdimy;
368 }else{
369 *disppixx = geom->lenx + vopts->pxoffx;
370 *disppixy = geom->leny + vopts->pxoffy;
371 }
372 logdebug("pixel prescale: %d %d %d %d", n->pixy, n->pixx, *disppixy, *disppixx);
374 clamp_to_sixelmax(ti, disppixy, disppixx, outy, scaling);
375 scale_visual(n, disppixy, disppixx);
376 }
377 clamp_to_sixelmax(ti, disppixy, disppixx, outy, scaling);
378 // FIXME use a closed form
379 while((*outy + geom->cdimy - 1) / geom->cdimy > ncplane_dim_y(vopts->n)){
380 *outy -= ti->sprixel_scale_height;
381 *disppixy = *outy;
382 }
383 *outx = *disppixx;
384 *disppixx -= vopts->pxoffx;
385 *disppixy -= vopts->pxoffy;
386 }
387 logdebug("pblit: %dx%d ← %dx%d of %d/%d stride %u @%dx%d %p %u", *disppixy, *disppixx, geom->begy, geom->begx, n->pixy, n->pixx, n->rowstride, *placey, *placex, n->data, geom->cdimx);
388 geom->rpixy = *disppixy;
389 geom->rpixx = *disppixx;
390 geom->rcellx = *outx / geom->cdimx + !!(*outx % geom->cdimx);
391 geom->rcelly = *outy / geom->cdimy + !!(*outy % geom->cdimy);
392 }else{ // cellblit
393 if(vopts->pxoffx || vopts->pxoffy){
394 logerror("pixel offsets cannot be used with cell blitting");
395 return -1;
396 }
397 unsigned dispcols, disprows;
398 if(vopts->n == NULL || (vopts->flags & NCVISUAL_OPTION_CHILDPLANE)){ // create plane
399//fprintf(stderr, "CPATH1, create beg %dx%d len %dx%d\n", geom->begy, geom->begx, geom->leny, geom->lenx);
401 dispcols = geom->lenx;
402 disprows = geom->leny;
403 }else{
404 if(vopts->n == NULL){
405 disprows = ti->dimy;
406 dispcols = ti->dimx;
407 }else{
408 ncplane_dim_yx(vopts->n, &disprows, &dispcols);
409 }
410 dispcols *= geom->scalex;
411 disprows *= geom->scaley;
413 scale_visual(n, &disprows, &dispcols);
414 } // else stretch
415 }
416 }else{
417//fprintf(stderr, "CPATH2, reuse beg %dx%d len %dx%d\n", geom->begy, geom->begx, geom->leny, geom->lenx);
419 dispcols = geom->lenx;
420 disprows = geom->leny;
421 }else{
422 ncplane_dim_yx(vopts->n, &disprows, &dispcols);
423 dispcols *= geom->scalex;
424 disprows *= geom->scaley;
426 dispcols -= *placex;
427 }
429 disprows -= *placey;
430 }
432 scale_visual(n, &disprows, &dispcols);
433 } // else stretch
434 }
436 *placex = ncplane_halign(vopts->n, *placex, dispcols / geom->scalex);
437 }
439 *placey = ncplane_valign(vopts->n, *placey, disprows / geom->scaley);
440 }
441 }
442 geom->rpixy = disprows;
443 geom->rpixx = dispcols;
444 geom->rcellx = dispcols / geom->scalex + !!(dispcols % geom->scalex);
445 geom->rcelly = disprows / geom->scaley + !!(disprows % geom->scaley);
446 }
447 logdebug("rgeom: %d %d %d %d @ %d/%d (%d on %p)", geom->rcelly, geom->rcellx,
448 geom->rpixy, geom->rpixx, *placey, *placex, (*bset)->geom, vopts->n);
449 return 0;
450}
#define logwarn(fmt,...)
Definition logging.h:37
const notcurses * ncplane_notcurses_const(const ncplane *n)
Definition notcurses.c:2635
const ncplane * notcurses_stdplane_const(const notcurses *nc)
Definition notcurses.c:706
ncscale_e
Definition notcurses.h:96
@ NCSCALE_SCALE_HIRES
Definition notcurses.h:101
@ NCSCALE_SCALE
Definition notcurses.h:98
@ NCSCALE_NONE
Definition notcurses.h:97
@ NCSCALE_NONE_HIRES
Definition notcurses.h:100
@ NCALIGN_UNALIGNED
Definition notcurses.h:81
@ NCALIGN_RIGHT
Definition notcurses.h:84
@ NCBLIT_DEFAULT
Definition notcurses.h:66
unsigned cellpxx
Definition internal.h:326
unsigned dimx
Definition internal.h:325
unsigned dimy
Definition internal.h:325
unsigned cellpxy
Definition internal.h:326
unsigned rpixx
Definition notcurses.h:3404
unsigned cdimx
Definition notcurses.h:3403
unsigned scaley
Definition notcurses.h:3406
unsigned lenx
Definition notcurses.h:3408
unsigned pixx
Definition notcurses.h:3402
unsigned pixy
Definition notcurses.h:3402
unsigned rpixy
Definition notcurses.h:3404
unsigned begy
Definition notcurses.h:3407
unsigned maxpixelx
Definition notcurses.h:3409
unsigned maxpixely
Definition notcurses.h:3409
unsigned begx
Definition notcurses.h:3407
unsigned leny
Definition notcurses.h:3408
unsigned cdimy
Definition notcurses.h:3403
unsigned scalex
Definition notcurses.h:3406
ncscale_e scaling
Definition notcurses.h:3358
unsigned cellpxx
Definition termdesc.h:117
unsigned dimx
Definition termdesc.h:118
unsigned sprixel_scale_height
Definition termdesc.h:174
unsigned sixel_maxx
Definition termdesc.h:165
unsigned dimy
Definition termdesc.h:118
unsigned sixel_maxy
Definition termdesc.h:172
unsigned cellpxy
Definition termdesc.h:116
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncvisual_init()

int ncvisual_init ( int  logl)

Definition at line 23 of file visual.c.

23 {
26 }
27 return 0;
28}
int(* visual_init)(int loglevel)
Definition internal.h:1792
Here is the caller graph for this function:

◆ ncvisual_polyfill_yx()

int ncvisual_polyfill_yx ( ncvisual n,
unsigned  y,
unsigned  x,
uint32_t  rgba 
)

Definition at line 1350 of file visual.c.

1350 {
1351 if(y >= n->pixy){
1352 logerror("invalid coordinates %u/%u", y, x);
1353 return -1;
1354 }
1355 if(x >= n->pixx){
1356 logerror("invalid coordinates %u/%u", y, x);
1357 return -1;
1358 }
1359 uint32_t* pixel = &n->data[y * (n->rowstride / 4) + x];
1360 return ncvisual_polyfill_core(n, y, x, rgba, *pixel);
1361}
Here is the caller graph for this function:

◆ ncvisual_printbanner()

void ncvisual_printbanner ( fbuf f)

Definition at line 30 of file visual.c.

Here is the caller graph for this function:

◆ ncvisual_render_cells()

ncplane * ncvisual_render_cells ( ncvisual ncv,
const struct blitset bset,
int  placey,
int  placex,
ncvgeom geom,
ncplane n,
uint64_t  flags,
uint32_t  transcolor 
)

Definition at line 1019 of file visual.c.

1022 {
1023 logdebug("cblit: rows/cols: %dx%d plane: %d/%d pix: %d/%d", geom->rcelly, geom->rcellx, ncplane_dim_y(n), ncplane_dim_x(n), geom->rpixy, geom->rpixx);
1024 blitterargs bargs;
1025 bargs.transcolor = transcolor;
1026 bargs.begy = geom->begy;
1027 bargs.begx = geom->begx;
1028 bargs.leny = geom->leny;
1029 bargs.lenx = geom->lenx;
1030 bargs.flags = flags;
1031 bargs.u.cell.placey = placey;
1032 bargs.u.cell.placex = placex;
1033 if(ncvisual_blit_internal(ncv, geom->rpixy, geom->rpixx, n, bset, &bargs)){
1034 return NULL;
1035 }
1036 return n;
1037}
struct blitterargs::@3::@4 cell
union blitterargs::@3 u
uint32_t transcolor
Definition internal.h:380
int ncvisual_blit_internal(const ncvisual *ncv, int rows, int cols, ncplane *n, const struct blitset *bset, const blitterargs *barg)
Definition visual.c:84
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncvisual_render_pixels()

ncplane * ncvisual_render_pixels ( notcurses nc,
ncvisual ncv,
const struct blitset bset,
int  placey,
int  placex,
const ncvgeom geom,
ncplane n,
uint64_t  flags,
uint32_t  transcolor,
int  pxoffy,
int  pxoffx 
)

Definition at line 1056 of file visual.c.

1059 {
1060 logdebug("pblit: rows/cols: %dx%d plane: %d/%d", geom->rcelly, geom->rcellx, ncplane_dim_y(n), ncplane_dim_x(n));
1061 const tinfo* ti = &nc->tcache;
1062 blitterargs bargs;
1063 bargs.transcolor = transcolor;
1064 bargs.begy = geom->begy;
1065 bargs.begx = geom->begx;
1066 bargs.leny = geom->leny;
1067 bargs.lenx = geom->lenx;
1068 bargs.flags = flags;
1069 bargs.u.pixel.colorregs = ti->color_registers;
1070 bargs.u.pixel.pxoffy = pxoffy;
1071 bargs.u.pixel.pxoffx = pxoffx;
1072 bargs.u.pixel.cellpxy = geom->cdimy;
1073 bargs.u.pixel.cellpxx = geom->cdimx;
1074 const ncpile* p = ncplane_pile_const(n);
1075 if(n->sprite == NULL){
1076 if((n->sprite = sprixel_alloc(n, geom->rcelly, geom->rcellx)) == NULL){
1077 return NULL;
1078 }
1079 if((n->tam = create_tam(geom->rcelly, geom->rcellx)) == NULL){
1080 return NULL;;
1081 }
1082 }else{
1083 n->sprite = sprixel_recycle(n);
1084 if(n->sprite->dimy != geom->rcelly || n->sprite->dimx != geom->rcellx){
1085 destroy_tam(n);
1086 if((n->tam = create_tam(geom->rcelly, geom->rcellx)) == NULL){
1087 return NULL;
1088 }
1089 }
1090 n->sprite->dimx = geom->rcellx;
1091 n->sprite->dimy = geom->rcelly;
1092 }
1093 bargs.u.pixel.spx = n->sprite;
1094 // FIXME need to pull off the ncpile's sprixellist if anything below fails!
1095 if(ncvisual_blit_internal(ncv, geom->rpixy, geom->rpixx, n, bset, &bargs)){
1096 return NULL;
1097 }
1098 // if we created the plane earlier, placex/placey were taken into account, and
1099 // zeroed out, thus neither of these will have any effect.
1100 if(flags & NCVISUAL_OPTION_HORALIGNED){
1101 if(placex == NCALIGN_CENTER){
1102 placex = (ncplane_dim_x(ncplane_parent_const(n)) * p->cellpxx - geom->rpixx) / 2 / p->cellpxx;
1103 }else if(placex == NCALIGN_RIGHT){
1104 placex = (ncplane_dim_x(ncplane_parent_const(n)) * p->cellpxx - geom->rpixx) / p->cellpxx;
1105 }
1106 if(placex < 0){
1107 return NULL;
1108 }
1109 }
1110 if(flags & NCVISUAL_OPTION_VERALIGNED){
1111 if(placey == NCALIGN_CENTER){
1112 placey = (ncplane_dim_y(ncplane_parent_const(n)) * p->cellpxy - geom->rpixy) / 2 / p->cellpxy;
1113 }else if(placey == NCALIGN_BOTTOM){
1114 placey = (ncplane_dim_y(ncplane_parent_const(n)) * p->cellpxy - geom->rpixy) / p->cellpxy;
1115 }
1116 if(placey < 0){
1117 return NULL;
1118 }
1119 }
1120 // ncplane_resize() hides any attached sprixel, so lift it (the sprixel) out
1121 // for a moment as we shrink the plane to fit. we keep the origin and move to
1122 // the intended location.
1123 sprixel* s = n->sprite;
1124 n->sprite = NULL;
1125//fprintf(stderr, "ABOUT TO RESIZE: yoff/xoff: %d/%d\n", placey, placex);
1126 // FIXME might need shrink down the TAM and kill unnecessary auxvecs
1127 if(ncplane_resize(n, 0, 0, s->dimy, s->dimx, placey, placex, s->dimy, s->dimx)){
1128 // if we blow up here, then we've got a TAM sized to the sprixel, rather
1129 // than the plane. running it through destroy_tam() via ncplane_destroy()
1130 // will use incorrect bounds for scrubbing said TAM. do it manually here.
1131 cleanup_tam(n->tam, geom->rcelly, geom->rcellx);
1132 free(n->tam);
1133 n->tam = NULL;
1134 sprixel_hide(bargs.u.pixel.spx);
1135 return NULL;
1136 }
1137 n->sprite = bargs.u.pixel.spx;
1138//fprintf(stderr, "RESIZED: %d/%d at %d/%d %p\n", ncplane_dim_y(n), ncplane_dim_x(n), ncplane_y(n), ncplane_x(n), n->sprite);
1139 return n;
1140}
sprixel * sprixel_recycle(ncplane *n)
Definition sprite.c:51
void sprixel_hide(sprixel *s)
Definition sprite.c:83
sprixel * sprixel_alloc(ncplane *n, int dimy, int dimx)
Definition sprite.c:117
const ncplane * ncplane_parent_const(const ncplane *n)
Definition notcurses.c:2660
int ncplane_resize(ncplane *n, int keepy, int keepx, unsigned keepleny, unsigned keeplenx, int yoff, int xoff, unsigned ylen, unsigned xlen)
Definition notcurses.c:1009
@ NCALIGN_CENTER
Definition notcurses.h:83
#define NCALIGN_BOTTOM
Definition notcurses.h:88
struct blitterargs::@3::@5 pixel
sprixel * spx
Definition internal.h:388
int colorregs
Definition internal.h:387
unsigned dimx
Definition sprite.h:146
unsigned dimy
Definition sprite.h:146
int color_registers
Definition termdesc.h:164
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncvisual_resize()

int ncvisual_resize ( ncvisual n,
int  rows,
int  cols 
)

Definition at line 988 of file visual.c.

988 {
990 return ncvisual_resize_noninterpolative(n, rows, cols);
991 }
992 if(visual_implementation->visual_resize(n, rows, cols)){
993 return -1;
994 }
995 return 0;
996}
int(* visual_resize)(struct ncvisual *ncv, unsigned rows, unsigned cols)
Definition internal.h:1809
int ncvisual_resize_noninterpolative(ncvisual *n, int rows, int cols)
Definition visual.c:998
Here is the call graph for this function:

◆ ncvisual_resize_noninterpolative()

int ncvisual_resize_noninterpolative ( ncvisual n,
int  rows,
int  cols 
)

Definition at line 998 of file visual.c.

998 {
999 size_t dstride = pad_for_image(cols * 4, cols);
1000 uint32_t* r = resize_bitmap(n->data, n->pixy, n->pixx, n->rowstride,
1001 rows, cols, dstride);
1002 if(r == NULL){
1003 return -1;
1004 }
1005 ncvisual_set_data(n, r, true);
1006 n->rowstride = dstride;
1007 n->pixy = rows;
1008 n->pixx = cols;
1010 return 0;
1011}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncvisual_rotate()

int ncvisual_rotate ( ncvisual ncv,
double  rads 
)

Definition at line 707 of file visual.c.

707 {
708 assert(ncv->rowstride / 4 >= ncv->pixx);
709 rads = -rads; // we're a left-handed Cartesian
710 int centy, centx;
711 ncvisual_center(ncv, &centy, &centx); // pixel center (center of 'data')
712 double stheta, ctheta; // sine, cosine
713 stheta = sin(rads);
714 ctheta = cos(rads);
715 // bounding box for real data within the ncvisual. we must only resize to
716 // accommodate real data, lest we grow without band as we rotate.
717 // see https://github.com/dankamongmen/notcurses/issues/599.
718 int bby = ncv->pixy;
719 int bbx = ncv->pixx;
720 int bboffy = 0;
721 int bboffx = 0;
722 if(ncvisual_bounding_box(ncv, &bby, &bbx, &bboffy, &bboffx) <= 0){
723 logerror("couldn't find a bounding box");
724 return -1;
725 }
726 int bbarea;
727 bbarea = rotate_bounding_box(stheta, ctheta, &bby, &bbx, &bboffy, &bboffx);
728 if(bbarea <= 0){
729 logerror("couldn't rotate the visual (%d, %d, %d, %d)", bby, bbx, bboffy, bboffx);
730 return -1;
731 }
732 int bbcentx = bbx, bbcenty = bby;
733 center_box(&bbcenty, &bbcentx);
734//fprintf(stderr, "stride: %d height: %d width: %d\n", ncv->rowstride, ncv->pixy, ncv->pixx);
735 assert(ncv->rowstride / 4 >= ncv->pixx);
736 uint32_t* data = malloc(bbarea * 4);
737 if(data == NULL){
738 return -1;
739 }
740 memset(data, 0, bbarea * 4);
741//fprintf(stderr, "bbarea: %d bby: %d bbx: %d centy: %d centx: %d bbcenty: %d bbcentx: %d\n", bbarea, bby, bbx, centy, centx, bbcenty, bbcentx);
742 for(unsigned y = 0 ; y < ncv->pixy ; ++y){
743 for(unsigned x = 0 ; x < ncv->pixx ; ++x){
744 int targx = x, targy = y;
745 rotate_point(&targy, &targx, stheta, ctheta, centy, centx);
746 if(targx > bboffx && targy > bboffy){
747 const int deconvx = targx - bboffx;
748 const int deconvy = targy - bboffy;
749 if(deconvy < bby && deconvx < bbx){
750 data[deconvy * bbx + deconvx] = ncv->data[y * (ncv->rowstride / 4) + x];
751 }
752 }
753//fprintf(stderr, "CW: %d/%d (%08x) -> %d/%d (stride: %d)\n", y, x, ncv->data[y * (ncv->rowstride / 4) + x], targy, targx, ncv->rowstride);
754//fprintf(stderr, "wrote %08x to %d (%d)\n", data[targy * ncv->pixy + targx], targy * ncv->pixy + targx, (targy * ncv->pixy + targx) * 4);
755 }
756 }
757 ncvisual_set_data(ncv, data, true);
758 ncv->pixx = bbx;
759 ncv->pixy = bby;
760 ncv->rowstride = bbx * 4;
762 return 0;
763}
int ncvisual_bounding_box(const ncvisual *ncv, int *leny, int *lenx, int *offy, int *offx)
Definition visual.c:537
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncvisual_set_yx()

int ncvisual_set_yx ( const struct ncvisual n,
unsigned  y,
unsigned  x,
uint32_t  pixel 
)

Definition at line 1265 of file visual.c.

1265 {
1266 if(y >= n->pixy){
1267 logerror("invalid coordinates %u/%u", y, x);
1268 return -1;
1269 }
1270 if(x >= n->pixx){
1271 logerror("invalid coordinates %u/%u", y, x);
1272 return -1;
1273 }
1274 n->data[y * (n->rowstride / 4) + x] = pixel;
1275 return 0;
1276}
Here is the caller graph for this function:

◆ ncvisual_simple_streamer()

int ncvisual_simple_streamer ( ncvisual ncv,
struct ncvisual_options vopts,
const struct timespec *  tspec,
void *  curry 
)

Definition at line 1244 of file visual.c.

1245 {
1246 struct ncplane* subtitle = NULL;
1247 int ret = 0;
1248 if(curry){
1249 // FIXME improve this hrmmmmm
1250 ncplane* subncp = curry;
1251 if(subncp->blist){
1252 ncplane_destroy(subncp->blist);
1253 subncp->blist = NULL;
1254 }
1255 subtitle = ncvisual_subtitle_plane(subncp, ncv);
1256 }
1257 if(notcurses_render(ncplane_notcurses(vopts->n))){
1258 return -1;
1259 }
1260 clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, tspec, NULL);
1261 ncplane_destroy(subtitle);
1262 return ret;
1263}
notcurses * ncplane_notcurses(const ncplane *n)
Definition notcurses.c:2631
struct ncplane * blist
Definition internal.h:102
ncplane * ncvisual_subtitle_plane(ncplane *parent, const ncvisual *ncv)
Definition visual.c:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncvisual_stream()

int ncvisual_stream ( notcurses nc,
ncvisual ncv,
float  timescale,
ncstreamcb  streamer,
const struct ncvisual_options vopts,
void *  curry 
)

Definition at line 64 of file visual.c.

66 {
68 return -1;
69 }
70 int ret = visual_implementation->visual_stream(nc, ncv, timescale, streamer, vopts, curry);
71 if(ret < 0){
72 logerror("error streaming media");
73 }
74 return ret;
75}
int(* visual_stream)(notcurses *nc, struct ncvisual *ncv, float timescale, ncstreamcb streamer, const struct ncvisual_options *vopts, void *curry)
Definition internal.h:1804
Here is the caller graph for this function:

◆ ncvisual_subtitle_plane()

ncplane * ncvisual_subtitle_plane ( ncplane parent,
const ncvisual ncv 
)

Definition at line 77 of file visual.c.

77 {
79 return NULL;
80 }
82}
ncplane *(* visual_subtitle)(ncplane *parent, const struct ncvisual *ncv)
Definition internal.h:1806
Here is the caller graph for this function:

◆ notcurses_canopen_images()

bool notcurses_canopen_images ( const notcurses *nc   __attribute__(unused))

Definition at line 1363 of file visual.c.

1363 {
1365 return false;
1366 }
1368}
Here is the caller graph for this function:

◆ notcurses_canopen_videos()

bool notcurses_canopen_videos ( const notcurses *nc   __attribute__(unused))

Definition at line 1370 of file visual.c.

1370 {
1372 return false;
1373 }
1375}
Here is the caller graph for this function:

◆ rgb_loose_to_rgba()

void * rgb_loose_to_rgba ( const void *  data,
int  rows,
int *  rowstride,
int  cols,
int  alpha 
)

Definition at line 461 of file visual.c.

461 {
462 if(*rowstride % 4){ // must be a multiple of 4 bytes
463 return NULL;
464 }
465 if(*rowstride < cols * 4){
466 return NULL;
467 }
468 uint32_t* ret = malloc(4 * cols * rows);
469 if(ret){
470 for(int y = 0 ; y < rows ; ++y){
471 for(int x = 0 ; x < cols ; ++x){
472 const uint32_t* src = (const uint32_t*)data + (*rowstride / 4) * y + x;
473 uint32_t* dst = ret + cols * y + x;
474 *dst = 0; // kill scan-build warning about using uninitialized value below
475 ncpixel_set_a(dst, alpha);
476 ncpixel_set_r(dst, ncpixel_r(*src));
477 ncpixel_set_g(dst, ncpixel_g(*src));
478 ncpixel_set_b(dst, ncpixel_b(*src));
479 }
480 }
481 }
482 *rowstride = cols * 4;
483 return ret;
484}
Here is the caller graph for this function:

◆ rgb_packed_to_rgba()

void * rgb_packed_to_rgba ( const void *  data,
int  rows,
int *  rowstride,
int  cols,
int  alpha 
)

Definition at line 486 of file visual.c.

486 {
487 if(*rowstride < cols * 3){
488 return NULL;
489 }
490 uint32_t* ret = malloc(4 * cols * rows);
491 if(ret){
492 for(int y = 0 ; y < rows ; ++y){
493 for(int x = 0 ; x < cols ; ++x){
494 const unsigned char* src = (const unsigned char*)data + *rowstride * y + x;
495 uint32_t* dst = ret + cols * y + x;
496 *dst = 0; // kill scan-build warning about using uninitialized value below
497 ncpixel_set_a(dst, alpha);
498 ncpixel_set_r(dst, src[0]);
499 ncpixel_set_g(dst, src[1]);
500 ncpixel_set_b(dst, src[2]);
501 }
502 }
503 }
504 *rowstride = cols * 4;
505 return ret;
506}
Here is the caller graph for this function:

Variable Documentation

◆ visual_implementation

ncvisual_implementation* visual_implementation = &null_visual_implementation

Definition at line 20 of file visual.c.