ncscale_e enumeration for ncvisuals #168

This commit is contained in:
nick black 2019-12-18 21:17:34 -05:00 committed by Nick Black
parent e2c58534ca
commit 3cfe88ee0c
5 changed files with 39 additions and 14 deletions

View File

@ -1264,14 +1264,25 @@ to a renderable scene on the associated `ncplane`.
struct ncvisual* ncplane_visual_open(struct ncplane* nc, const char* file,
int* averr);
// How to scale the visual in ncvisual_open_plane(). NCSCALE_NONE will open a
// plane tailored to the visual's exact needs, which is probably larger than the
// visible screen (but might be smaller). NCSCALE_SCALE scales a visual larger
// than the visible screen down, maintaining aspect ratio. NCSCALE_STRETCH
// stretches and scales the image in an attempt to fill the visible screen.
typedef enum {
NCSCALE_NONE,
NCSCALE_SCALE,
NCSCALE_STRETCH,
} ncscale_e;
// Open a visual, extract a codec and parameters, and create a new plane
// suitable for its display at 'y','x'. If there is sufficient room to display
// the visual in its native size, the new plane will be exactly that large.
// Otherwise, the visual will be scaled to the available space. If 'stretch' is
// false, its aspect ratio will be maintained. Otherwise, the visual will be
// scaled to fill the maximum possible new plane.
// the visual in its native size, or if NCSCALE_NONE is passed for 'style', the
// new plane will be exactly that large. Otherwise, the plane will be as large
// as possble (given the visible screen), either maintaining aspect ratio
// (NCSCALE_SCALE) or abandoning it (NCSCALE_STRETCH).
struct ncvisual* ncvisual_open_plane(struct notcurses* nc, const char* file,
int* averr, int y, int x, bool stretch);
int* averr, int y, int x, ncscale_e style);
// Destroy an ncvisual. Rendered elements will not be disrupted, but the visual
// can be neither decoded nor rendered any further.

View File

@ -1325,17 +1325,30 @@ struct AVFrame;
// Open a visual (image or video), associating it with the specified ncplane.
// Returns NULL on any error, writing the AVError to 'averr'.
// FIXME this ought also take an ncscale_e!
API struct ncvisual* ncplane_visual_open(struct ncplane* nc, const char* file,
int* averr);
// How to scale the visual in ncvisual_open_plane(). NCSCALE_NONE will open a
// plane tailored to the visual's exact needs, which is probably larger than the
// visible screen (but might be smaller). NCSCALE_SCALE scales a visual larger
// than the visible screen down, maintaining aspect ratio. NCSCALE_STRETCH
// stretches and scales the image in an attempt to fill the visible screen.
typedef enum {
NCSCALE_NONE,
NCSCALE_SCALE,
NCSCALE_STRETCH,
} ncscale_e;
// Open a visual, extract a codec and parameters, and create a new plane
// suitable for its display at 'y','x'. If there is sufficient room to display
// the visual in its native size, the new plane will be exactly that large.
// Otherwise, the visual will be scaled to the available space. If 'stretch' is
// false, its aspect ratio will be maintained. Otherwise, the visual will be
// scaled to fill the maximum possible new plane.
// the visual in its native size, or if NCSCALE_NONE is passed for 'style', the
// new plane will be exactly that large. Otherwise, the plane will be as large
// as possble (given the visible screen), either maintaining aspect ratio
// (NCSCALE_SCALE) or abandoning it (NCSCALE_STRETCH).
API struct ncvisual* ncvisual_open_plane(struct notcurses* nc, const char* file,
int* averr, int y, int x, bool stretch);
int* averr, int y, int x,
ncscale_e style);
// Destroy an ncvisual. Rendered elements will not be disrupted, but the visual
// can be neither decoded nor rendered any further.

View File

@ -74,7 +74,7 @@ typedef struct ncvisual {
// describe where the plane ought be placed, and how it ought be sized. this
// path sets ncobj. ncvisual_destroy() ought in that case kill the ncplane.
int placex, placey;
bool stretch; // false maintains aspect ratio of source media
ncscale_e style; // none, scale, or stretch
struct notcurses* ncobj; // set iff this ncvisual "owns" its ncplane
} ncvisual;

View File

@ -251,18 +251,19 @@ ncvisual* ncplane_visual_open(ncplane* nc, const char* filename, int* averr){
// ncv->dstwidth *= 2;
ncv->dstheight *= 2;
ncv->ncp = nc;
ncv->style = NCSCALE_STRETCH;
return ncv;
}
ncvisual* ncvisual_open_plane(notcurses* nc, const char* filename,
int* averr, int y, int x, bool stretch){
int* averr, int y, int x, ncscale_e style){
ncvisual* ncv = ncvisual_open(filename, averr);
if(ncv == NULL){
return NULL;
}
ncv->placey = y;
ncv->placex = x;
ncv->stretch = stretch;
ncv->style = style;
ncv->ncobj = nc;
return ncv;
}

View File

@ -74,7 +74,7 @@ TEST_F(LibavTest, LoadVideoCreatePlane) {
int averr;
int dimy, dimx;
ncplane_dim_yx(ncp_, &dimy, &dimx);
auto ncv = ncvisual_open_plane(nc_, "../tests/fm6.mkv", &averr, 0, 0, false);
auto ncv = ncvisual_open_plane(nc_, "../tests/fm6.mkv", &averr, 0, 0, NCSCALE_NONE);
ASSERT_NE(nullptr, ncv);
EXPECT_EQ(0, averr);
auto frame = ncvisual_decode(ncv, &averr);