mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-20 03:25:47 +00:00
allow different backends to specify their own padding requirements #1722
This commit is contained in:
parent
a749ede622
commit
d8c37337d9
@ -1759,6 +1759,7 @@ typedef struct ncvisual_implementation {
|
|||||||
int (*visual_stream)(notcurses* nc, struct ncvisual* ncv, float timescale,
|
int (*visual_stream)(notcurses* nc, struct ncvisual* ncv, float timescale,
|
||||||
ncstreamcb streamer, const struct ncvisual_options* vopts, void* curry);
|
ncstreamcb streamer, const struct ncvisual_options* vopts, void* curry);
|
||||||
char* (*visual_subtitle)(const struct ncvisual* ncv);
|
char* (*visual_subtitle)(const struct ncvisual* ncv);
|
||||||
|
int rowalign; // rowstride base, can be 0 for no padding
|
||||||
// do a persistent resize, changing the ncv itself
|
// do a persistent resize, changing the ncv itself
|
||||||
int (*visual_resize)(struct ncvisual* ncv, int rows, int cols);
|
int (*visual_resize)(struct ncvisual* ncv, int rows, int cols);
|
||||||
void (*visual_destroy)(struct ncvisual* ncv);
|
void (*visual_destroy)(struct ncvisual* ncv);
|
||||||
|
@ -562,16 +562,16 @@ int ncvisual_rotate(ncvisual* ncv, double rads){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ffmpeg wants rows to be multiples of IMGALIGN (64)
|
|
||||||
#define IMGALIGN 64
|
|
||||||
static inline size_t
|
static inline size_t
|
||||||
pad_for_image(size_t stride){
|
pad_for_image(size_t stride, int cols){
|
||||||
if(stride % IMGALIGN == 0){
|
if(visual_implementation.rowalign == 0){
|
||||||
|
return 4 * cols;
|
||||||
|
}else if(stride % visual_implementation.rowalign == 0){
|
||||||
return stride;
|
return stride;
|
||||||
}
|
}
|
||||||
return (stride + IMGALIGN) / IMGALIGN * IMGALIGN;
|
return (stride + visual_implementation.rowalign) /
|
||||||
|
visual_implementation.rowalign * visual_implementation.rowalign;
|
||||||
}
|
}
|
||||||
#undef IMGALIGN
|
|
||||||
|
|
||||||
ncvisual* ncvisual_from_rgba(const void* rgba, int rows, int rowstride, int cols){
|
ncvisual* ncvisual_from_rgba(const void* rgba, int rows, int rowstride, int cols){
|
||||||
if(rowstride % 4){
|
if(rowstride % 4){
|
||||||
@ -581,7 +581,7 @@ ncvisual* ncvisual_from_rgba(const void* rgba, int rows, int rowstride, int cols
|
|||||||
ncvisual* ncv = ncvisual_create();
|
ncvisual* ncv = ncvisual_create();
|
||||||
if(ncv){
|
if(ncv){
|
||||||
// ffmpeg needs inputs with rows aligned on 192-byte boundaries
|
// ffmpeg needs inputs with rows aligned on 192-byte boundaries
|
||||||
ncv->rowstride = pad_for_image(rowstride);
|
ncv->rowstride = pad_for_image(rowstride, cols);
|
||||||
ncv->pixx = cols;
|
ncv->pixx = cols;
|
||||||
ncv->pixy = rows;
|
ncv->pixy = rows;
|
||||||
uint32_t* data = malloc(ncv->rowstride * ncv->pixy);
|
uint32_t* data = malloc(ncv->rowstride * ncv->pixy);
|
||||||
@ -603,7 +603,7 @@ ncvisual* ncvisual_from_rgb_packed(const void* rgba, int rows, int rowstride,
|
|||||||
int cols, int alpha){
|
int cols, int alpha){
|
||||||
ncvisual* ncv = ncvisual_create();
|
ncvisual* ncv = ncvisual_create();
|
||||||
if(ncv){
|
if(ncv){
|
||||||
ncv->rowstride = pad_for_image(cols * 4);
|
ncv->rowstride = pad_for_image(cols * 4, cols);
|
||||||
ncv->pixx = cols;
|
ncv->pixx = cols;
|
||||||
ncv->pixy = rows;
|
ncv->pixy = rows;
|
||||||
uint32_t* data = malloc(ncv->rowstride * ncv->pixy);
|
uint32_t* data = malloc(ncv->rowstride * ncv->pixy);
|
||||||
@ -640,7 +640,7 @@ ncvisual* ncvisual_from_rgb_loose(const void* rgba, int rows, int rowstride,
|
|||||||
}
|
}
|
||||||
ncvisual* ncv = ncvisual_create();
|
ncvisual* ncv = ncvisual_create();
|
||||||
if(ncv){
|
if(ncv){
|
||||||
ncv->rowstride = pad_for_image(cols * 4);
|
ncv->rowstride = pad_for_image(cols * 4, cols);
|
||||||
ncv->pixx = cols;
|
ncv->pixx = cols;
|
||||||
ncv->pixy = rows;
|
ncv->pixy = rows;
|
||||||
uint32_t* data = malloc(ncv->rowstride * ncv->pixy);
|
uint32_t* data = malloc(ncv->rowstride * ncv->pixy);
|
||||||
@ -667,7 +667,7 @@ ncvisual* ncvisual_from_bgra(const void* bgra, int rows, int rowstride, int cols
|
|||||||
}
|
}
|
||||||
ncvisual* ncv = ncvisual_create();
|
ncvisual* ncv = ncvisual_create();
|
||||||
if(ncv){
|
if(ncv){
|
||||||
ncv->rowstride = pad_for_image(rowstride);
|
ncv->rowstride = pad_for_image(rowstride, cols);
|
||||||
ncv->pixx = cols;
|
ncv->pixx = cols;
|
||||||
ncv->pixy = rows;
|
ncv->pixy = rows;
|
||||||
uint32_t* data = malloc(ncv->rowstride * ncv->pixy);
|
uint32_t* data = malloc(ncv->rowstride * ncv->pixy);
|
||||||
@ -704,7 +704,7 @@ int ncvisual_resize(ncvisual* n, int rows, int cols){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ncvisual_resize_noninterpolative(ncvisual* n, int rows, int cols){
|
int ncvisual_resize_noninterpolative(ncvisual* n, int rows, int cols){
|
||||||
size_t dstride = pad_for_image(cols * 4);
|
size_t dstride = pad_for_image(cols * 4, cols);
|
||||||
uint32_t* r = resize_bitmap(n->data, n->pixy, n->pixx, n->rowstride,
|
uint32_t* r = resize_bitmap(n->data, n->pixy, n->pixx, n->rowstride,
|
||||||
rows, cols, dstride);
|
rows, cols, dstride);
|
||||||
if(r == NULL){
|
if(r == NULL){
|
||||||
|
@ -633,6 +633,7 @@ const ncvisual_implementation local_visual_implementation = {
|
|||||||
.visual_subtitle = ffmpeg_subtitle,
|
.visual_subtitle = ffmpeg_subtitle,
|
||||||
.visual_resize = ffmpeg_resize,
|
.visual_resize = ffmpeg_resize,
|
||||||
.visual_destroy = ffmpeg_destroy,
|
.visual_destroy = ffmpeg_destroy,
|
||||||
|
.rowalign = 64, // ffmpeg wants multiples of IMGALIGN (64)
|
||||||
.canopen_images = true,
|
.canopen_images = true,
|
||||||
.canopen_videos = true,
|
.canopen_videos = true,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user