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

Go to the source code of this file.

Functions

void ncplane_greyscale (ncplane *n)
 
int ncplane_polyfill_yx (ncplane *n, int ystart, int xstart, const nccell *c)
 
bool check_gradient_args (uint64_t ul, uint64_t ur, uint64_t bl, uint64_t br)
 
int ncplane_gradient2x1 (ncplane *n, int y, int x, unsigned ylen, unsigned xlen, uint32_t ul, uint32_t ur, uint32_t ll, uint32_t lr)
 
int ncplane_highgradient_sized (ncplane *n, uint32_t ul, uint32_t ur, uint32_t ll, uint32_t lr, int ylen, int xlen)
 
int ncplane_gradient (ncplane *n, int y, int x, unsigned ylen, unsigned xlen, const char *egc, uint16_t stylemask, uint64_t ul, uint64_t ur, uint64_t bl, uint64_t br)
 
int ncplane_stain (ncplane *n, int y, int x, unsigned ylen, unsigned xlen, uint64_t tl, uint64_t tr, uint64_t bl, uint64_t br)
 
int ncplane_format (ncplane *n, int y, int x, unsigned ylen, unsigned xlen, uint16_t stylemask)
 
int ncplane_rotate_cw (ncplane *n)
 
int ncplane_rotate_ccw (ncplane *n)
 
int ncplane_qrcode (ncplane *n, unsigned *ymax, unsigned *xmax, const void *data, size_t len)
 

Function Documentation

◆ check_gradient_args()

bool check_gradient_args ( uint64_t  ul,
uint64_t  ur,
uint64_t  bl,
uint64_t  br 
)

Definition at line 150 of file fill.c.

150 {
151 if(check_gradient_channel_args(ncchannels_fchannel(ul), ncchannels_fchannel(ur),
152 ncchannels_fchannel(bl), ncchannels_fchannel(br))){
153 return true;
154 }
155 if(check_gradient_channel_args(ncchannels_bchannel(ul), ncchannels_bchannel(ur),
156 ncchannels_bchannel(bl), ncchannels_bchannel(br))){
157 return true;
158 }
159 return false;
160}
API int API int API int uint64_t ul
Definition direct.h:215
API int API int API int uint64_t uint64_t ur
Definition direct.h:215
Here is the caller graph for this function:

◆ ncplane_format()

int ncplane_format ( ncplane n,
int  y,
int  x,
unsigned  ylen,
unsigned  xlen,
uint16_t  stylemask 
)

Definition at line 296 of file fill.c.

297 {
298 unsigned ystart, xstart;
299 if(check_geometry_args(n, y, x, &ylen, &xlen, &ystart, &xstart)){
300 return -1;
301 }
302 int total = 0;
303 for(unsigned yy = ystart ; yy < ystart + ylen ; ++yy){
304 for(unsigned xx = xstart ; xx < xstart + xlen ; ++xx){
305 nccell* targc = ncplane_cell_ref_yx(n, yy, xx);
306 targc->stylemask = stylemask;
307 ++total;
308 }
309 }
310 return total;
311}
API int API int API int uint64_t uint64_t uint64_t uint64_t unsigned unsigned xlen
Definition direct.h:217
API int API int API int uint64_t uint64_t uint64_t uint64_t unsigned ylen
Definition direct.h:217
int y
Definition notcurses.h:1905
vopts n
Definition notcurses.h:3502
int int x
Definition notcurses.h:1905
uint16_t stylemask
Definition notcurses.h:703
Here is the caller graph for this function:

◆ ncplane_gradient()

int ncplane_gradient ( ncplane n,
int  y,
int  x,
unsigned  ylen,
unsigned  xlen,
const char *  egc,
uint16_t  stylemask,
uint64_t  ul,
uint64_t  ur,
uint64_t  bl,
uint64_t  br 
)

Definition at line 227 of file fill.c.

229 {
230 if(check_gradient_args(ul, ur, bl, br)){
231 return -1;
232 }
233 unsigned ystart, xstart;
234 if(check_geometry_args(n, y, x, &ylen, &xlen, &ystart, &xstart)){
235 return -1;
236 }
237 if(ylen == 1){
238 if(xlen == 1){
239 if(ul != ur || ur != br || br != bl){
240 logerror("channel variation in 1x1 area");
241 return -1;
242 }
243 }else{
244 if(ul != bl || ur != br){
245 logerror("vertical channel variation in single row");
246 return -1;
247 }
248 }
249 }else if(xlen == 1){
250 if(ul != ur || bl != br){
251 logerror("horizontal channel variation in single column");
252 return -1;
253 }
254 }
255 int total = 0;
256 for(unsigned yy = ystart ; yy < ystart + ylen ; ++yy){
257 for(unsigned xx = xstart ; xx < xstart + xlen ; ++xx){
258 nccell* targc = ncplane_cell_ref_yx(n, yy, xx);
259 targc->channels = 0;
260 if(nccell_load(n, targc, egc) < 0){
261 return -1;
262 }
263 targc->stylemask = stylemask;
264 calc_gradient_channels(&targc->channels, ul, ur, bl, br,
265 yy - ystart, xx - xstart, ylen, xlen);
266 ++total;
267 }
268 }
269 return total;
270}
const char * egc
Definition egcpool.h:173
bool check_gradient_args(uint64_t ul, uint64_t ur, uint64_t bl, uint64_t br)
Definition fill.c:150
#define logerror(fmt,...)
Definition logging.h:32
int nccell_load(ncplane *n, nccell *c, const char *gcluster)
Definition notcurses.c:1833
uint64_t channels
Definition notcurses.h:723
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_gradient2x1()

int ncplane_gradient2x1 ( ncplane n,
int  y,
int  x,
unsigned  ylen,
unsigned  xlen,
uint32_t  ul,
uint32_t  ur,
uint32_t  ll,
uint32_t  lr 
)

Definition at line 179 of file fill.c.

180 {
181 if(!notcurses_canutf8(ncplane_notcurses(n))){
182 logerror("highdef gradients require utf8");
183 return -1;
184 }
185 if(check_gradient_channel_args(ul, ur, ll, lr)){
186 return -1;
187 }
188 unsigned ystart, xstart;
189 if(check_geometry_args(n, y, x, &ylen, &xlen, &ystart, &xstart)){
190 return -1;
191 }
192 if(xlen == 1){
193 if(ul != ur || ll != lr){
194 logerror("horizontal channel variation in single column");
195 return -1;
196 }
197 }
198 int total = 0;
199 for(unsigned yy = ystart ; yy < ystart + ylen ; ++yy){
200 for(unsigned xx = xstart ; xx < xstart + xlen ; ++xx){
201 nccell* targc = ncplane_cell_ref_yx(n, yy, xx);
202 targc->channels = 0;
203 if(pool_blit_direct(&n->pool, targc, "▀", strlen("▀"), 1) <= 0){
204 return -1;
205 }
206 calc_highgradient(targc, ul, ur, ll, lr, yy - ystart, xx - xstart, ylen * 2, xlen);
207 ++total;
208 }
209 }
210 return total;
211}
API int API int API int uint64_t uint64_t uint64_t uint64_t lr
Definition direct.h:216
API int API int API int uint64_t uint64_t uint64_t ll
Definition direct.h:216
notcurses * ncplane_notcurses(const ncplane *n)
Definition notcurses.c:2626
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_greyscale()

void ncplane_greyscale ( ncplane n)

Definition at line 3 of file fill.c.

3 {
4 for(unsigned y = 0 ; y < n->leny ; ++y){
5 for(unsigned x = 0 ; x < n->lenx ; ++x){
6 nccell* c = &n->fb[nfbcellidx(n, y, x)];
7 unsigned r, g, b;
8 nccell_fg_rgb8(c, &r, &g, &b);
9 int gy = rgb_greyscale(r, g, b);
10 nccell_set_fg_rgb8(c, gy, gy, gy);
11 nccell_bg_rgb8(c, &r, &g, &b);
12 gy = rgb_greyscale(r, g, b);
13 nccell_set_bg_rgb8(c, gy, gy, gy);
14 }
15 }
16}
const nccell * c
Definition egcpool.h:296
int r
Definition fbuf.h:226
Here is the caller graph for this function:

◆ ncplane_highgradient_sized()

int ncplane_highgradient_sized ( ncplane n,
uint32_t  ul,
uint32_t  ur,
uint32_t  ll,
uint32_t  lr,
int  ylen,
int  xlen 
)

Definition at line 214 of file fill.c.

215 {
216 if(ylen < 1 || xlen < 1){
217 return -1;
218 }
219 if(!notcurses_canutf8(ncplane_notcurses_const(n))){
220 // this works because the uin32_ts we pass in will be promoted to uint64_ts
221 // via extension, and the space will employ the background. mwahh!
222 return ncplane_gradient(n, -1, -1, ylen, xlen, " ", 0, ul, ur, ll, lr);
223 }
224 return ncplane_gradient2x1(n, -1, -1, ylen, xlen, ul, ur, ll, lr);
225}
int ncplane_gradient2x1(ncplane *n, int y, int x, unsigned ylen, unsigned xlen, uint32_t ul, uint32_t ur, uint32_t ll, uint32_t lr)
Definition fill.c:179
int ncplane_gradient(ncplane *n, int y, int x, unsigned ylen, unsigned xlen, const char *egc, uint16_t stylemask, uint64_t ul, uint64_t ur, uint64_t bl, uint64_t br)
Definition fill.c:227
const notcurses * ncplane_notcurses_const(const ncplane *n)
Definition notcurses.c:2630
Here is the call graph for this function:

◆ ncplane_polyfill_yx()

int ncplane_polyfill_yx ( ncplane n,
int  ystart,
int  xstart,
const nccell c 
)

Definition at line 80 of file fill.c.

80 {
81 if(ystart < 0){
82 if(ystart != -1){
83 logerror("invalid y: %d", ystart);
84 return -1;
85 }
86 ystart = n->y;
87 }
88 unsigned y = ystart;
89 if(xstart < 0){
90 if(xstart != -1){
91 logerror("invalid x: %d", xstart);
92 return -1;
93 }
94 xstart = n->x;
95 }
96 unsigned x = xstart;
97 if(y >= n->leny || x >= n->lenx){
98 logerror("invalid start: %u/%u (%u/%u)", y, x, n->leny, n->lenx);
99 return -1;
100 }
101 const nccell* cur = &n->fb[nfbcellidx(n, y, x)];
102 const char* targ = nccell_extended_gcluster(n, cur);
103 const char* fillegc = nccell_extended_gcluster(n, c);
104//fprintf(stderr, "checking %d/%d (%s) for [%s]\n", y, x, targ, fillegc);
105 if(strcmp(fillegc, targ) == 0){
106 return 0;
107 }
108 int ret = -1;
109 // we need an external copy of this, since we'll be writing to it on
110 // the first call into ncplane_polyfill_inner()
111 char* targcopy = strdup(targ);
112 if(targcopy){
113 ret = ncplane_polyfill_inner(n, y, x, c, targcopy);
114 free(targcopy);
115 }
116 return ret;
117}
free(duplicated)
const char * nccell_extended_gcluster(const ncplane *n, const nccell *c)
Definition notcurses.c:1573
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_qrcode()

int ncplane_qrcode ( ncplane n,
unsigned *  ymax,
unsigned *  xmax,
const void *  data,
size_t  len 
)

Definition at line 651 of file fill.c.

651 {
652 (void)n;
653 (void)ymax;
654 (void)xmax;
655 (void)data;
656 (void)len;
657 return -1;
658}
API int API int const nccell unsigned len
Definition notcurses.h:2588
Here is the caller graph for this function:

◆ ncplane_rotate_ccw()

int ncplane_rotate_ccw ( ncplane n)

Definition at line 515 of file fill.c.

515 {
516 ncplane* newp = rotate_plane(n);
517 if(newp == NULL){
518 return -1;
519 }
520 unsigned dimy, dimx, targdimy, targdimx;
521 ncplane_dim_yx(n, &dimy, &dimx);
522 ncplane_dim_yx(newp, &targdimy, &targdimx);
523 int x = (int)dimx - 2;
524 int y;
525 // Each row of the target plane is taken from a column of the source plane.
526 // As the target row grows (down), the source column shrinks (moves left).
527 for(unsigned targy = 0 ; targy < targdimy ; ++targy){
528 y = 0;
529 for(unsigned targx = 0 ; targx < targdimx ; targx += 2){
530 if(rotate_2x1_ccw(n, newp, y, x, targy, targx)){
531 ncplane_destroy(newp);
532 return -1;
533 }
534 ++y;
535 }
536 x -= 2;
537 }
538 int ret = rotate_merge(n, newp);
539 ret |= ncplane_destroy(newp);
540 return ret;
541}
int ncplane_destroy(ncplane *ncp)
Definition notcurses.c:1018
void ncplane_dim_yx(const ncplane *n, unsigned *rows, unsigned *cols)
Definition notcurses.c:301
return NULL
Definition termdesc.h:229
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_rotate_cw()

int ncplane_rotate_cw ( ncplane n)

Definition at line 484 of file fill.c.

484 {
485 ncplane* newp = rotate_plane(n);
486 if(newp == NULL){
487 return -1;
488 }
489 unsigned dimy, dimx;
490 ncplane_dim_yx(n, &dimy, &dimx);
491 int centy, centx;
492 ncplane_center_abs(n, &centy, &centx);
493 // the topmost row consists of the leftmost two columns. the rightmost column
494 // of the topmost row consists of the top half of the top two leftmost cells.
495 // the penultimate column of the topmost row consists of the bottom half of
496 // the top two leftmost cells. work from the bottom up on the source, so we
497 // can copy to the top row from the left to the right.
498 int targx, targy = 0;
499 for(unsigned x = 0 ; x < dimx ; x += 2){
500 targx = 0;
501 for(int y = (int)dimy - 1 ; y >= 0 ; --y){
502 if(rotate_2x1_cw(n, newp, y, x, targy, targx)){
503 ncplane_destroy(newp);
504 return -1;
505 }
506 targx += 2;
507 }
508 ++targy;
509 }
510 int ret = rotate_merge(n, newp);
511 ret |= ncplane_destroy(newp);
512 return ret;
513}
void ncplane_center_abs(const ncplane *n, int *RESTRICT y, int *RESTRICT x)
Definition notcurses.c:3268
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_stain()

int ncplane_stain ( ncplane n,
int  y,
int  x,
unsigned  ylen,
unsigned  xlen,
uint64_t  tl,
uint64_t  tr,
uint64_t  bl,
uint64_t  br 
)

Definition at line 272 of file fill.c.

273 {
274 // Can't use default or palette-indexed colors in a gradient
275 if(check_gradient_args(tl, tr, bl, br)){
276 return -1;
277 }
278 unsigned ystart, xstart;
279 if(check_geometry_args(n, y, x, &ylen, &xlen, &ystart, &xstart)){
280 return -1;
281 }
282 int total = 0;
283 for(unsigned yy = ystart ; yy < ystart + ylen ; ++yy){
284 for(unsigned xx = xstart ; xx < xstart + xlen ; ++xx){
285 nccell* targc = ncplane_cell_ref_yx(n, yy, xx);
286 if(targc->gcluster){
287 calc_gradient_channels(&targc->channels, tl, tr, bl, br,
288 yy - ystart, xx - xstart, ylen, xlen);
289 }
290 ++total;
291 }
292 }
293 return total;
294}
uint32_t gcluster
Definition notcurses.h:693
Here is the call graph for this function:
Here is the caller graph for this function: