mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-02 09:40:15 +00:00
ncdirect_render_image(): getting closer #725
This commit is contained in:
parent
3bb789eb74
commit
277cbc9c16
@ -212,6 +212,29 @@ int ncdirect_cursor_pop(ncdirect* n){
|
|||||||
return term_emit("rc", n->tcache.rc, n->ttyfp, false);
|
return term_emit("rc", n->tcache.rc, n->ttyfp, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
ncdirect_dump_plane(ncdirect* n, const ncplane* np){
|
||||||
|
int dimy, dimx;
|
||||||
|
ncplane_dim_yx(np, &dimy, &dimx);
|
||||||
|
for(int y = 0 ; y < dimy ; ++y){
|
||||||
|
for(int x = 0 ; x < dimx ; ++x){
|
||||||
|
uint32_t attrword;
|
||||||
|
uint64_t channels;
|
||||||
|
char* egc = ncplane_at_yx(np, y, x, &attrword, &channels);
|
||||||
|
if(egc == NULL){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
ncdirect_fg(n, channels_fg(channels));
|
||||||
|
ncdirect_bg(n, channels_bg(channels));
|
||||||
|
if(printf("%s", egc) < 0){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
putchar('\n');
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
nc_err_e ncdirect_render_image(ncdirect* n, const char* file, ncblitter_e blitter, ncscale_e scale){
|
nc_err_e ncdirect_render_image(ncdirect* n, const char* file, ncblitter_e blitter, ncscale_e scale){
|
||||||
nc_err_e ret;
|
nc_err_e ret;
|
||||||
struct ncvisual* ncv = ncvisual_from_file(file, &ret);
|
struct ncvisual* ncv = ncvisual_from_file(file, &ret);
|
||||||
@ -219,18 +242,18 @@ nc_err_e ncdirect_render_image(ncdirect* n, const char* file, ncblitter_e blitte
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
int begy, begx;
|
int begy, begx;
|
||||||
fprintf(stderr, "OUR DATA: %p rows/cols: %d/%d\n", ncv->data, ncv->rows, ncv->cols);
|
//fprintf(stderr, "OUR DATA: %p rows/cols: %d/%d\n", ncv->data, ncv->rows, ncv->cols);
|
||||||
|
if(ncdirect_cursor_yx(n, &begy, &begx)){
|
||||||
|
ncvisual_destroy(ncv);
|
||||||
|
return NCERR_SYSTEM;
|
||||||
|
}
|
||||||
int leny = ncv->rows; // we allow it to freely scroll
|
int leny = ncv->rows; // we allow it to freely scroll
|
||||||
int lenx = ncv->cols - begx;
|
int lenx = ncv->cols - begx;
|
||||||
if(leny == 0 || lenx == 0){
|
if(leny == 0 || lenx == 0){
|
||||||
ncvisual_destroy(ncv);
|
ncvisual_destroy(ncv);
|
||||||
return NCERR_DECODE;
|
return NCERR_DECODE;
|
||||||
}
|
}
|
||||||
if(ncdirect_cursor_yx(n, &begy, &begx)){
|
//fprintf(stderr, "render %d/%d to %dx%d+%dx%d scaling: %d\n", ncv->rows, ncv->cols, begy, begx, leny, lenx, scale);
|
||||||
ncvisual_destroy(ncv);
|
|
||||||
return NCERR_SYSTEM;
|
|
||||||
}
|
|
||||||
fprintf(stderr, "render %d/%d to %dx%d+%dx%d scaling: %d\n", ncv->rows, ncv->cols, begy, begx, leny, lenx, scale);
|
|
||||||
auto bset = rgba_blitter_low(n->utf8, scale, blitter, NCBLIT_DEFAULT);
|
auto bset = rgba_blitter_low(n->utf8, scale, blitter, NCBLIT_DEFAULT);
|
||||||
if(!bset){
|
if(!bset){
|
||||||
return NCERR_INVALID_ARG;
|
return NCERR_INVALID_ARG;
|
||||||
@ -248,7 +271,7 @@ fprintf(stderr, "render %d/%d to %dx%d+%dx%d scaling: %d\n", ncv->rows, ncv->col
|
|||||||
}
|
}
|
||||||
leny = (leny / (double)ncv->rows) * ((double)disprows);
|
leny = (leny / (double)ncv->rows) * ((double)disprows);
|
||||||
lenx = (lenx / (double)ncv->cols) * ((double)dispcols);
|
lenx = (lenx / (double)ncv->cols) * ((double)dispcols);
|
||||||
fprintf(stderr, "render: %dx%d:%d+%d of %d/%d stride %u %p\n", begy, begx, leny, lenx, ncv->rows, ncv->cols, ncv->rowstride, ncv->data);
|
//fprintf(stderr, "render: %dx%d:%d+%d of %d/%d stride %u %p\n", begy, begx, leny, lenx, ncv->rows, ncv->cols, ncv->rowstride, ncv->data);
|
||||||
struct ncplane* faken = ncplane_create(NULL, NULL, disprows, dispcols, 0, 0, NULL);
|
struct ncplane* faken = ncplane_create(NULL, NULL, disprows, dispcols, 0, 0, NULL);
|
||||||
if(faken == NULL){
|
if(faken == NULL){
|
||||||
return NCERR_NOMEM;
|
return NCERR_NOMEM;
|
||||||
@ -261,7 +284,7 @@ fprintf(stderr, "render: %dx%d:%d+%d of %d/%d stride %u %p\n", begy, begx, leny,
|
|||||||
return NCERR_SYSTEM;
|
return NCERR_SYSTEM;
|
||||||
}
|
}
|
||||||
ncvisual_destroy(ncv);
|
ncvisual_destroy(ncv);
|
||||||
// FIXME render faken
|
ncdirect_dump_plane(n, faken);
|
||||||
free_plane(faken);
|
free_plane(faken);
|
||||||
return NCERR_SUCCESS;
|
return NCERR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -416,9 +416,9 @@ nc_err_e ncvisual_blit(ncvisual* ncv, int rows, int cols, ncplane* n,
|
|||||||
int stride = 0;
|
int stride = 0;
|
||||||
AVFrame* sframe = nullptr;
|
AVFrame* sframe = nullptr;
|
||||||
const int targformat = AV_PIX_FMT_RGBA;
|
const int targformat = AV_PIX_FMT_RGBA;
|
||||||
//fprintf(stderr, "got format: %d want format: %d\n", inframe->format, targformat);
|
fprintf(stderr, "got format: %d want format: %d\n", inframe->format, targformat);
|
||||||
if(inframe && (cols != inframe->width || rows != inframe->height || inframe->format != targformat)){
|
if(inframe && (cols != inframe->width || rows != inframe->height || inframe->format != targformat)){
|
||||||
//fprintf(stderr, "resize+render: %d/%d->%d/%d (%dX%d @ %dX%d, %d/%d)\n", inframe->height, inframe->width, rows, cols, begy, begx, placey, placex, leny, lenx);
|
fprintf(stderr, "resize+render: %d/%d->%d/%d (%dX%d @ %dX%d, %d/%d)\n", inframe->height, inframe->width, rows, cols, begy, begx, placey, placex, leny, lenx);
|
||||||
sframe = av_frame_alloc();
|
sframe = av_frame_alloc();
|
||||||
if(sframe == nullptr){
|
if(sframe == nullptr){
|
||||||
//fprintf(stderr, "Couldn't allocate output frame for scaled frame\n");
|
//fprintf(stderr, "Couldn't allocate output frame for scaled frame\n");
|
||||||
@ -461,9 +461,10 @@ nc_err_e ncvisual_blit(ncvisual* ncv, int rows, int cols, ncplane* n,
|
|||||||
stride = ncv->rowstride;
|
stride = ncv->rowstride;
|
||||||
data = ncv->data;
|
data = ncv->data;
|
||||||
}
|
}
|
||||||
//fprintf(stderr, "place: %d/%d rows/cols: %d/%d %d/%d+%d/%d\n", placey, placex, rows, cols, begy, begx, leny, lenx);
|
fprintf(stderr, "place: %d/%d rows/cols: %d/%d %d/%d+%d/%d\n", placey, placex, rows, cols, begy, begx, leny, lenx);
|
||||||
if(rgba_blit_dispatch(n, bset, placey, placex, stride, data, begy, begx,
|
if(rgba_blit_dispatch(n, bset, placey, placex, stride, data, begy, begx,
|
||||||
leny, lenx, blendcolors) <= 0){
|
leny, lenx, blendcolors) <= 0){
|
||||||
|
fprintf(stderr, "rgba dispatch failed!\n");
|
||||||
if(sframe){
|
if(sframe){
|
||||||
av_freep(sframe->data);
|
av_freep(sframe->data);
|
||||||
av_freep(&sframe);
|
av_freep(&sframe);
|
||||||
|
21
src/poc/vizdirect.c
Normal file
21
src/poc/vizdirect.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include <locale.h>
|
||||||
|
#include <notcurses/notcurses.h>
|
||||||
|
|
||||||
|
// can we leave what was already on the screen there? (narrator: it seems not)
|
||||||
|
int main(void){
|
||||||
|
if(!setlocale(LC_ALL, "")){
|
||||||
|
fprintf(stderr, "Couldn't set locale\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
struct ncdirect* n; // see bug #391
|
||||||
|
if((n = ncdirect_init(NULL, stdout)) == NULL){
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
if(ncdirect_render_image(n, "../data/warmech.bmp", NCBLIT_DEFAULT, NCSCALE_STRETCH) != NCERR_SUCCESS){
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
if(ncdirect_stop(n)){
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user