Notcurses 3.0.13
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
blit.c File Reference
#include <stddef.h>
#include <inttypes.h>
#include "internal.h"
Include dependency graph for blit.c:

Go to the source code of this file.

Data Structures

struct  qdriver
 

Macros

#define E(bits)   (1u << (bits))
 

Functions

void set_pixel_blitter (ncblitter blitfxn)
 
const struct blitsetlookup_blitset (const tinfo *tcache, ncblitter_e setid, bool may_degrade)
 
int notcurses_lex_blitter (const char *op, ncblitter_e *blitfxn)
 
const char * notcurses_str_blitter (ncblitter_e blitfxn)
 
int ncblit_bgrx (const void *data, int linesize, const struct ncvisual_options *vopts)
 
int ncblit_rgb_loose (const void *data, int linesize, const struct ncvisual_options *vopts, int alpha)
 
int ncblit_rgb_packed (const void *data, int linesize, const struct ncvisual_options *vopts, int alpha)
 
int ncblit_rgba (const void *data, int linesize, const struct ncvisual_options *vopts)
 
ncblitter_e ncvisual_media_defblitter (const notcurses *nc, ncscale_e scale)
 

Macro Definition Documentation

◆ E

#define E (   bits)    (1u << (bits))

Function Documentation

◆ lookup_blitset()

const struct blitset * lookup_blitset ( const tinfo tcache,
ncblitter_e  setid,
bool  may_degrade 
)

Definition at line 1297 of file blit.c.

1298 {
1299 if(setid == NCBLIT_DEFAULT){ // ought have resolved NCBLIT_DEFAULT before now
1300 return NULL;
1301 }
1302 // without braille support, NCBLIT_BRAILLE decays to NCBLIT_4x2
1303 if(setid == NCBLIT_BRAILLE){
1304 if(tcache->caps.braille){
1305 return &notcurses_blitters[setid - 1];
1306 }else if(!may_degrade){
1307 return NULL;
1308 }
1309 setid = NCBLIT_4x2;
1310 }
1311 // without octant support, NCBLIT_4x2 decays to NCBLIT_3x2
1312 if(setid == NCBLIT_4x2){
1313 if(tcache->caps.octants){
1314 return &notcurses_blitters[setid - 1];
1315 }else if(!may_degrade){
1316 return NULL;
1317 }
1318 setid = NCBLIT_3x2;
1319 }
1320 // without bitmap support, NCBLIT_PIXEL decays to NCBLIT_3x2
1321 if(setid == NCBLIT_PIXEL){
1322 if(tcache->pixel_draw || tcache->pixel_draw_late){
1323 return &notcurses_blitters[setid - 1];
1324 }else if(!may_degrade){
1325 return NULL;
1326 }
1327 setid = NCBLIT_3x2;
1328 }
1329 // without eighths support, NCBLIT_8x1 decays to NCBLIT_4x1
1330 if(setid == NCBLIT_8x1){ // plotter only
1331 if(tcache->caps.quadrants){
1332 return &notcurses_blitters[setid - 1];
1333 }else if(!may_degrade){
1334 return NULL;
1335 }
1336 setid = NCBLIT_4x1;
1337 }
1338 // without quarters support, NCBLIT_4x1 decays to NCBLIT_2x1
1339 if(setid == NCBLIT_4x1){ // plotter only
1340 if(tcache->caps.quadrants){
1341 return &notcurses_blitters[setid - 1];
1342 }else if(!may_degrade){
1343 return NULL;
1344 }
1345 setid = NCBLIT_2x1;
1346 }
1347 // without sextant support, NCBLIT_3x2 decays to NCBLIT_2x2
1348 if(setid == NCBLIT_3x2){
1349 if(tcache->caps.sextants){
1350 return &notcurses_blitters[setid - 1];
1351 }else if(!may_degrade){
1352 return NULL;
1353 }
1354 setid = NCBLIT_2x2;
1355 }
1356 // without quadrant support, NCBLIT_2x2 decays to NCBLIT_2x1
1357 if(setid == NCBLIT_2x2){
1358 if(tcache->caps.quadrants){
1359 return &notcurses_blitters[setid - 1];
1360 }else if(!may_degrade){
1361 return NULL;
1362 }
1363 setid = NCBLIT_2x1;
1364 }
1365 // without halfblock support, NCBLIT_2x1 decays to NCBLIT_1x1
1366 if(setid == NCBLIT_2x1){
1367 if(tcache->caps.halfblocks){
1368 return &notcurses_blitters[setid - 1];
1369 }else if(!may_degrade){
1370 return NULL;
1371 }
1372 setid = NCBLIT_1x1;
1373 }
1374 assert(NCBLIT_1x1 == setid);
1375 return &notcurses_blitters[setid - 1];
1376}
assert(false)
@ NCBLIT_PIXEL
Definition notcurses.h:73
@ NCBLIT_4x2
Definition notcurses.h:71
@ NCBLIT_DEFAULT
Definition notcurses.h:66
@ NCBLIT_4x1
Definition notcurses.h:75
@ NCBLIT_2x2
Definition notcurses.h:69
@ NCBLIT_3x2
Definition notcurses.h:70
@ NCBLIT_1x1
Definition notcurses.h:67
@ NCBLIT_BRAILLE
Definition notcurses.h:72
@ NCBLIT_2x1
Definition notcurses.h:68
@ NCBLIT_8x1
Definition notcurses.h:76
int(* pixel_draw_late)(const struct tinfo *, struct sprixel *s, int yoff, int xoff)
Definition termdesc.h:149
nccapabilities caps
Definition termdesc.h:111
int(* pixel_draw)(const struct tinfo *, const struct ncpile *p, struct sprixel *s, fbuf *f, int y, int x)
Definition termdesc.h:147
return NULL
Definition termdesc.h:229
Here is the call graph for this function:

◆ ncblit_bgrx()

int ncblit_bgrx ( const void *  data,
int  linesize,
const struct ncvisual_options vopts 
)

Definition at line 1408 of file blit.c.

1408 {
1409 if(vopts->leny <= 0 || vopts->lenx <= 0){
1410 logerror("invalid lengths %u %u", vopts->leny, vopts->lenx);
1411 return -1;
1412 }
1413 if(vopts->n == NULL){
1414 logerror("prohibited null plane");
1415 return -1;
1416 }
1417 void* rdata = bgra_to_rgba(data, vopts->leny, &linesize, vopts->lenx, 0xff);
1418 if(rdata == NULL){
1419 return -1;
1420 }
1421 int r = ncblit_rgba(rdata, linesize, vopts);
1422 free(rdata);
1423 return r;
1424}
int ncblit_rgba(const void *data, int linesize, const struct ncvisual_options *vopts)
Definition blit.c:1454
free(duplicated)
int r
Definition fbuf.h:226
ALLOC void * bgra_to_rgba(const void *data, int rows, int *rowstride, int cols, int alpha)
Definition visual.c:506
#define logerror(fmt,...)
Definition logging.h:32
const struct ncplane_options struct ncvisual struct ncvisual_options * vopts
Definition notcurses.h:3484
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncblit_rgb_loose()

int ncblit_rgb_loose ( const void *  data,
int  linesize,
const struct ncvisual_options vopts,
int  alpha 
)

Definition at line 1426 of file blit.c.

1427 {
1428 if(vopts->leny <= 0 || vopts->lenx <= 0){
1429 return -1;
1430 }
1431 void* rdata = rgb_loose_to_rgba(data, vopts->leny, &linesize, vopts->lenx, alpha);
1432 if(rdata == NULL){
1433 return -1;
1434 }
1435 int r = ncblit_rgba(rdata, linesize, vopts);
1436 free(rdata);
1437 return r;
1438}
ALLOC void * rgb_loose_to_rgba(const void *data, int rows, int *rowstride, int cols, int alpha)
Definition visual.c:461
Here is the call graph for this function:

◆ ncblit_rgb_packed()

int ncblit_rgb_packed ( const void *  data,
int  linesize,
const struct ncvisual_options vopts,
int  alpha 
)

Definition at line 1440 of file blit.c.

1441 {
1442 if(vopts->leny <= 0 || vopts->lenx <= 0){
1443 return -1;
1444 }
1445 void* rdata = rgb_packed_to_rgba(data, vopts->leny, &linesize, vopts->lenx, alpha);
1446 if(rdata == NULL){
1447 return -1;
1448 }
1449 int r = ncblit_rgba(rdata, linesize, vopts);
1450 free(rdata);
1451 return r;
1452}
ALLOC void * rgb_packed_to_rgba(const void *data, int rows, int *rowstride, int cols, int alpha)
Definition visual.c:485
Here is the call graph for this function:

◆ ncblit_rgba()

int ncblit_rgba ( const void *  data,
int  linesize,
const struct ncvisual_options vopts 
)

Definition at line 1454 of file blit.c.

1454 {
1455 if(vopts->leny <= 0 || vopts->lenx <= 0){
1456 logerror("invalid lengths %u %u", vopts->leny, vopts->lenx);
1457 return -1;
1458 }
1459 if(vopts->n == NULL){
1460 logerror("prohibited null plane");
1461 return -1;
1462 }
1463 struct ncvisual* ncv = ncvisual_from_rgba(data, vopts->leny, linesize, vopts->lenx);
1464 if(ncv == NULL){
1465 return -1;
1466 }
1469 return -1;
1470 }
1472 return 0;
1473}
notcurses * ncplane_notcurses(const ncplane *n)
Definition notcurses.c:2626
const struct ncplane_options struct ncvisual * ncv
Definition notcurses.h:3484
uint32_t * data
ncvisual * ncvisual_from_rgba(const void *rgba, int rows, int rowstride, int cols)
Definition visual.c:776
void ncvisual_destroy(ncvisual *ncv)
Definition visual.c:1225
ncplane * ncvisual_blit(notcurses *nc, ncvisual *ncv, const struct ncvisual_options *vopts)
Definition visual.c:1136
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncvisual_media_defblitter()

ncblitter_e ncvisual_media_defblitter ( const notcurses nc,
ncscale_e  scale 
)

Definition at line 1475 of file blit.c.

1475 {
1476 return rgba_blitter_default(&nc->tcache, scale);
1477}
tinfo tcache
Definition internal.h:360
Here is the caller graph for this function:

◆ notcurses_lex_blitter()

int notcurses_lex_blitter ( const char *  op,
ncblitter_e blitfxn 
)

Definition at line 1378 of file blit.c.

1378 {
1379 const struct blitset* bset = notcurses_blitters;
1380 while(bset->name){
1381 if(strcasecmp(bset->name, op) == 0){
1382 *blitfxn = bset->geom;
1383 return 0;
1384 }
1385 ++bset;
1386 }
1387 if(strcasecmp("default", op) == 0){
1388 *blitfxn = NCBLIT_DEFAULT;
1389 return 0;
1390 }
1391 return -1;
1392}
ncblitter_e geom
Definition internal.h:399
const char * name
Definition internal.h:411
Here is the caller graph for this function:

◆ notcurses_str_blitter()

const char * notcurses_str_blitter ( ncblitter_e  blitfxn)

Definition at line 1394 of file blit.c.

1394 {
1395 if(blitfxn == NCBLIT_DEFAULT){
1396 return "default";
1397 }
1398 const struct blitset* bset = notcurses_blitters;
1399 while(bset->name){
1400 if(bset->geom == blitfxn){
1401 return bset->name;
1402 }
1403 ++bset;
1404 }
1405 return NULL;
1406}
Here is the caller graph for this function:

◆ set_pixel_blitter()

void set_pixel_blitter ( ncblitter  blitfxn)

Definition at line 1289 of file blit.c.

1289 {
1290 struct blitset* b = notcurses_blitters;
1291 while(b->geom != NCBLIT_PIXEL){
1292 ++b;
1293 }
1294 b->blit = blitfxn;
1295}
ncblitter blit
Definition internal.h:410