Notcurses 3.0.13
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
visual-details.h
Go to the documentation of this file.
1#ifndef NOTCURSES_VISUAL_DETAILS
2#define NOTCURSES_VISUAL_DETAILS
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <stdio.h>
9#include <stdlib.h>
10#include <stdint.h>
11#include <stdbool.h>
12#include "builddef.h"
13
14struct blitset;
15struct ncplane;
16struct sprixel;
17struct ncvisual_details;
18
19// an ncvisual is essentially just an unpacked RGBA bitmap, created by
20// reading media from disk, supplying RGBA pixels directly in memory, or
21// synthesizing pixels from a plane.
22typedef struct ncvisual {
23 struct ncvisual_details* details;// implementation-specific details
24 uint32_t* data; // (scaled) RGBA image data, rowstride bytes per row
25 unsigned pixx, pixy; // pixel geometry, *not* cell geometry
26 // lines are sometimes padded. this many true bytes per row in data.
27 unsigned rowstride;
28 bool owndata; // we own data iff owndata == true
30
31static inline void
32ncvisual_set_data(ncvisual* ncv, void* data, bool owned){
33//fprintf(stderr, "replacing %p with %p (%u -> %u)\n", ncv->data, data, ncv->owndata, owned);
34 if(ncv->owndata){
35 if(data != ncv->data){
36 free(ncv->data);
37 }
38 }
39 ncv->data = (uint32_t*)data;
40 ncv->owndata = owned;
41}
42
43// shrink one dimension to retrieve the original aspect ratio
44static inline void
45scale_visual(const ncvisual* ncv, unsigned* disprows, unsigned* dispcols){
46 float xratio = (float)(*dispcols) / ncv->pixx;
47 if(xratio * ncv->pixy > *disprows){
48 xratio = (float)(*disprows) / ncv->pixy;
49 }
50 *disprows = xratio * (ncv->pixy);
51 *dispcols = xratio * (ncv->pixx);
52}
53
54#ifdef __cplusplus
55}
56#endif
57
58#endif
free(duplicated)
const struct ncplane_options struct ncvisual * ncv
Definition notcurses.h:3484
unsigned pixx
unsigned pixy
unsigned rowstride
struct ncvisual_details * details
uint32_t * data