mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-10-31 15:20:13 +00:00
ncblit: accept an ncvisual_options #680
This commit is contained in:
parent
358c9a5c73
commit
9a0f0c66fe
10
NEWS.md
10
NEWS.md
@ -1,11 +1,11 @@
|
||||
This document attempts to list user-visible changes and any major internal
|
||||
rearrangements of Notcurses.
|
||||
|
||||
* 1.5.0 (not yet released)
|
||||
* `ncblit_rgba()` and `ncblit_bgrx()` have been renamed `ncplane_blit_rgba()`
|
||||
and `ncplane_blit_bgrx()`, to match every other existing ncplane function.
|
||||
In addition, they both now accept an `ncblitter_e` to select the blitting
|
||||
method. `NCBLIT_DEFAULT` will use `NCBLITTER_2x1`.
|
||||
* 1.4.5 (not yet released)
|
||||
* `ncblit_rgba()` and `ncblit_bgrx()` have replaced most of their arguments
|
||||
with a `const struct ncvisual_options*`. `NCBLIT_DEFAULT` will use
|
||||
`NCBLITTER_2x1` (with fallback) in this context. The `->n` field must
|
||||
be non-`NULL`--new planes will not be created.
|
||||
* Added `ncplane_notcurses_const()`.
|
||||
|
||||
* 1.4.4.1 (2020-06-01)
|
||||
|
26
USAGE.md
26
USAGE.md
@ -1249,21 +1249,19 @@ void ncfadectx_free(struct ncfadectx* nctx);
|
||||
Raw streams of RGBA or BGRx data can be blitted directly to an ncplane:
|
||||
|
||||
```c
|
||||
// Blit a flat array 'data' of BGRx 32-bit values to the ncplane 'nc', offset
|
||||
// from the upper left by 'placey' and 'placex'. Each row ought occupy
|
||||
// 'linesize' bytes (this might be greater than lenx * 4 due to padding). A
|
||||
// subregion of the input can be specified with 'begy'x'begx' and 'leny'x'lenx'.
|
||||
int ncplane_blit_bgrx(struct ncplane* nc, int placey, int placex, int linesize,
|
||||
ncblitter_e blitter, const unsigned char* data,
|
||||
int begy, int begx, int leny, int lenx);
|
||||
// Blit a flat array 'data' of RGBA 32-bit values to the ncplane 'vopts->n',
|
||||
// which mustn't be NULL. the blit begins at 'vopts->y' and 'vopts->x' relative
|
||||
// to the specified plane. Each source row ought occupy 'linesize' bytes (this
|
||||
// might be greater than 'vopts->lenx' * 4 due to padding or partial blits). A
|
||||
// subregion of the input can be specified with the 'begy'x'begx' and
|
||||
// 'leny'x'lenx' fields from 'vopts'. Returns the number of pixels blitted, or
|
||||
// -1 on error.
|
||||
int ncblit_rgba(const void* data, int linesize,
|
||||
const struct ncvisual_options* vopts);
|
||||
|
||||
// Blit a flat array 'data' of RGBA 32-bit values to the ncplane 'nc', offset
|
||||
// from the upper left by 'placey' and 'placex'. Each row ought occupy
|
||||
// 'linesize' bytes (this might be greater than lenx * 4 due to padding). A
|
||||
// subregion of the input can be specified with 'begy'x'begx' and 'leny'x'lenx'.
|
||||
int ncplane_blit_rgba(struct ncplane* nc, int placey, int placex, int linesize,
|
||||
ncblitter_e blitter, const unsigned char* data,
|
||||
int begy, int begx, int leny, int lenx);
|
||||
// Same as ncblit_rgba(), but for BGRx.
|
||||
int ncblit_bgrx(const void* data, int linesize,
|
||||
const struct ncvisual_options* vopts);
|
||||
```
|
||||
|
||||
|
||||
|
@ -1015,15 +1015,15 @@ namespace ncpp
|
||||
|
||||
static Plane* map_plane (ncplane *ncp, Plane *associated_plane = nullptr) noexcept;
|
||||
|
||||
bool blit_bgrx (int placey, int placex, int linesize, const void* data, int begy, int begx, int leny, int lenx) const NOEXCEPT_MAYBE
|
||||
bool blit_bgrx (const void* data, int linesize, const struct ncvisual_options *vopts) const NOEXCEPT_MAYBE
|
||||
{
|
||||
bool ret = ncplane_blit_bgrx (plane, placey, placex, linesize, NCBLIT_DEFAULT, data, begy, begx, leny, lenx) < 0;
|
||||
bool ret = ncblit_bgrx (data, linesize, vopts) < 0;
|
||||
return error_guard_cond<bool, bool> (ret, ret);
|
||||
}
|
||||
|
||||
bool blit_rgba (int placey, int placex, int linesize, const void* data, int begy, int begx, int leny, int lenx) const NOEXCEPT_MAYBE
|
||||
bool blit_rgba (const void* data, int linesize, const struct ncvisual_options *vopts) const NOEXCEPT_MAYBE
|
||||
{
|
||||
bool ret = ncplane_blit_rgba (plane, placey, placex, linesize, NCBLIT_DEFAULT, data, begy, begx, leny, lenx) < 0;
|
||||
bool ret = ncblit_rgba (data, linesize, vopts) < 0;
|
||||
return error_guard_cond<bool, bool> (ret, ret);
|
||||
}
|
||||
|
||||
|
@ -2233,21 +2233,19 @@ API int ncvisual_stream(struct notcurses* nc, struct ncvisual* ncv,
|
||||
nc_err_e* ncerr, float timescale, streamcb streamer,
|
||||
const struct ncvisual_options* vopts, void* curry);
|
||||
|
||||
// Blit a flat array 'data' of BGRx 32-bit values to the ncplane 'nc', offset
|
||||
// from the upper left by 'placey' and 'placex'. Each row ought occupy
|
||||
// 'linesize' bytes (this might be greater than lenx * 4 due to padding). A
|
||||
// subregion of the input can be specified with 'begy'x'begx' and 'leny'x'lenx'.
|
||||
API int ncplane_blit_bgrx(struct ncplane* nc, int placey, int placex,
|
||||
int linesize, ncblitter_e blitter, const void* data,
|
||||
int begy, int begx, int leny, int lenx);
|
||||
// Blit a flat array 'data' of RGBA 32-bit values to the ncplane 'vopts->n',
|
||||
// which mustn't be NULL. the blit begins at 'vopts->y' and 'vopts->x' relative
|
||||
// to the specified plane. Each source row ought occupy 'linesize' bytes (this
|
||||
// might be greater than 'vopts->lenx' * 4 due to padding or partial blits). A
|
||||
// subregion of the input can be specified with the 'begy'x'begx' and
|
||||
// 'leny'x'lenx' fields from 'vopts'. Returns the number of pixels blitted, or
|
||||
// -1 on error.
|
||||
API int ncblit_rgba(const void* data, int linesize,
|
||||
const struct ncvisual_options* vopts);
|
||||
|
||||
// Blit a flat array 'data' of RGBA 32-bit values to the ncplane 'nc', offset
|
||||
// from the upper left by 'placey' and 'placex'. Each row ought occupy
|
||||
// 'linesize' bytes (this might be greater than lenx * 4 due to padding). A
|
||||
// subregion of the input can be specified with 'begy'x'begx' and 'leny'x'lenx'.
|
||||
API int ncplane_blit_rgba(struct ncplane* nc, int placey, int placex,
|
||||
int linesize, ncblitter_e blitter, const void* data,
|
||||
int begy, int begx, int leny, int lenx);
|
||||
// Same as ncblit_rgba(), but for BGRx.
|
||||
API int ncblit_bgrx(const void* data, int linesize,
|
||||
const struct ncvisual_options* vopts);
|
||||
|
||||
// An ncreel is a notcurses region devoted to displaying zero or more
|
||||
// line-oriented, contained panels between which the user may navigate. If at
|
||||
|
@ -323,8 +323,8 @@ struct ncvisual_options {
|
||||
ncblitter_e blitter;
|
||||
uint64_t flags;
|
||||
};
|
||||
int ncplane_blit_bgrx(struct ncplane* nc, int placey, int placex, int linesize, ncblitter_e blitter, const unsigned char* data, int begy, int begx, int leny, int lenx);
|
||||
int ncplane_blit_rgba(struct ncplane* nc, int placey, int placex, int linesize, ncblitter_e blitter, const unsigned char* data, int begy, int begx, int leny, int lenx);
|
||||
struct ncplane* ncblit_bgrx(const void* data, int linesize, const struct ncvisual_options *vopts);
|
||||
struct ncplane* ncblit_rgba(const void* data, int linesize, const struct ncvisual_options *vopts);
|
||||
struct ncselector_item {
|
||||
char* option;
|
||||
char* desc;
|
||||
|
@ -173,7 +173,12 @@ int normal_demo(struct notcurses* nc){
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if(ncplane_blit_rgba(nstd, 0, 0, dx * sizeof(*rgba), NCBLIT_DEFAULT, rgba, 0, 0, dy, dx) < 0){
|
||||
struct ncvisual_options vopts = {
|
||||
.n = nstd,
|
||||
.leny = dy,
|
||||
.lenx = dx,
|
||||
};
|
||||
if(ncblit_rgba(rgba, dx * sizeof(*rgba), &vopts) < 0){
|
||||
goto err;
|
||||
}
|
||||
if( (r = demo_render(nc)) ){
|
||||
|
@ -443,30 +443,56 @@ const struct blitset notcurses_blitters[] = {
|
||||
.blit = NULL, .fill = false, },
|
||||
};
|
||||
|
||||
// Blit a flat array 'data' of BGRx 32-bit values to the ncplane 'nc', offset
|
||||
// from the upper left by 'placey' and 'placex'. Each row ought occupy
|
||||
// 'linesize' bytes (this might be greater than lenx * 4 due to padding). A
|
||||
// subregion of the input can be specified with 'begy'x'begx' and 'leny'x'lenx'.
|
||||
int ncplane_blit_bgrx(ncplane* nc, int placey, int placex, int linesize,
|
||||
ncblitter_e blitter, const void* data,
|
||||
int begy, int begx, int leny, int lenx){
|
||||
const struct blitset* bset = lookup_blitset(ncplane_notcurses(nc), blitter, true);
|
||||
int ncblit_bgrx(const void* data, int linesize, const struct ncvisual_options* vopts){
|
||||
if(vopts->flags > NCVISUAL_OPTION_BLEND){
|
||||
return -1;
|
||||
}
|
||||
struct ncplane* nc = vopts->n;
|
||||
if(nc == NULL){
|
||||
return -1;
|
||||
}
|
||||
int lenx = vopts->lenx;
|
||||
int leny = vopts->leny;
|
||||
int begy = vopts->begy;
|
||||
int begx = vopts->begx;
|
||||
//fprintf(stderr, "render %dx%d+%dx%d %p\n", begy, begx, leny, lenx, ncv->data);
|
||||
if(begy < 0 || begx < 0 || lenx < -1 || leny < -1){
|
||||
return -1;
|
||||
}
|
||||
const bool degrade = (vopts->flags & NCVISUAL_OPTION_MAYDEGRADE);
|
||||
const struct blitset* bset = lookup_blitset(nc->nc, vopts->blitter, degrade);
|
||||
if(bset == NULL){
|
||||
return -1;
|
||||
}
|
||||
return bset->blit(nc, placey, placex, linesize, data, begy, begx,
|
||||
leny, lenx, true, false);
|
||||
const bool blend = (vopts->flags & NCVISUAL_OPTION_BLEND);
|
||||
return bset->blit(nc, vopts->y, vopts->x, linesize, data, begy, begx,
|
||||
leny, lenx, true, blend);
|
||||
}
|
||||
|
||||
int ncplane_blit_rgba(ncplane* nc, int placey, int placex, int linesize,
|
||||
ncblitter_e blitter, const void* data,
|
||||
int begy, int begx, int leny, int lenx){
|
||||
const struct blitset* bset = lookup_blitset(ncplane_notcurses(nc), blitter, true);
|
||||
int ncblit_rgba(const void* data, int linesize, const struct ncvisual_options* vopts){
|
||||
if(vopts->flags > NCVISUAL_OPTION_BLEND){
|
||||
return -1;
|
||||
}
|
||||
struct ncplane* nc = vopts->n;
|
||||
if(nc == NULL){
|
||||
return -1;
|
||||
}
|
||||
int lenx = vopts->lenx;
|
||||
int leny = vopts->leny;
|
||||
int begy = vopts->begy;
|
||||
int begx = vopts->begx;
|
||||
//fprintf(stderr, "render %dx%d+%dx%d %p\n", begy, begx, leny, lenx, ncv->data);
|
||||
if(begy < 0 || begx < 0 || lenx < -1 || leny < -1){
|
||||
return -1;
|
||||
}
|
||||
const bool degrade = (vopts->flags & NCVISUAL_OPTION_MAYDEGRADE);
|
||||
const struct blitset* bset = lookup_blitset(nc->nc, vopts->blitter, degrade);
|
||||
if(bset == NULL){
|
||||
return -1;
|
||||
}
|
||||
return bset->blit(nc, placey, placex, linesize, data, begy, begx,
|
||||
leny, lenx, false, false);
|
||||
const bool blend = (vopts->flags & NCVISUAL_OPTION_BLEND);
|
||||
return bset->blit(nc, vopts->y, vopts->x, linesize, data, begy, begx,
|
||||
leny, lenx, false, blend);
|
||||
}
|
||||
|
||||
int rgba_blit_dispatch(ncplane* nc, const struct blitset* bset, int placey,
|
||||
|
@ -31,8 +31,12 @@ rotate_grad(struct notcurses* nc){
|
||||
notcurses_render(nc);
|
||||
clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);;
|
||||
|
||||
if(ncplane_blit_rgba(n, 0, 0, dimx * 4, NCBLIT_DEFAULT,
|
||||
rgba, 0, 0, dimy * 2, dimx) < 0){
|
||||
struct ncvisual_options vopts = {
|
||||
.n = n,
|
||||
.leny = dimy * 2,
|
||||
.lenx = dimx,
|
||||
};
|
||||
if(ncblit_rgba(rgba, dimx * 4, &vopts) == NULL){
|
||||
free(rgba);
|
||||
return -1;
|
||||
}
|
||||
@ -49,9 +53,8 @@ rotate_grad(struct notcurses* nc){
|
||||
if(v == NULL){
|
||||
return -1;
|
||||
}
|
||||
struct ncvisual_options vopts = {
|
||||
.n = n,
|
||||
};
|
||||
vopts.leny = 0;
|
||||
vopts.lenx = 0;
|
||||
if(n != ncvisual_render(nc, v, &vopts)){
|
||||
ncvisual_destroy(v);
|
||||
return -1;
|
||||
@ -161,8 +164,14 @@ rotate(struct notcurses* nc){
|
||||
notcurses_render(nc);
|
||||
clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);;
|
||||
|
||||
if(ncplane_blit_rgba(n, dimy / 2, XSIZE, XSIZE * 4, NCBLIT_DEFAULT,
|
||||
rgba, 0, 0, 4, XSIZE) < 0){
|
||||
struct ncvisual_options vopts = {
|
||||
.lenx = XSIZE,
|
||||
.leny = 4,
|
||||
.y = dimy / 2,
|
||||
.x = XSIZE,
|
||||
.n = n,
|
||||
};
|
||||
if(ncblit_rgba(rgba, XSIZE * 4, &vopts) == NULL){
|
||||
free(rgba);
|
||||
return -1;
|
||||
}
|
||||
@ -179,11 +188,8 @@ rotate(struct notcurses* nc){
|
||||
if(v == NULL){
|
||||
return -1;
|
||||
}
|
||||
struct ncvisual_options vopts = {
|
||||
.x = (dimx - XSIZE) / 2,
|
||||
.y = dimy / 2,
|
||||
.n = n,
|
||||
};
|
||||
vopts.x = (dimx - XSIZE) / 2;
|
||||
vopts.y = dimy / 2;
|
||||
ncvisual_render(nc, v, &vopts);
|
||||
notcurses_render(nc);
|
||||
clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);;
|
||||
|
Loading…
Reference in New Issue
Block a user