ncdirect_render_image(): getting closer #725

pull/755/head
nick black 4 years ago committed by Nick Black
parent 3bb789eb74
commit 277cbc9c16

@ -212,6 +212,29 @@ int ncdirect_cursor_pop(ncdirect* n){
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 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;
}
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 lenx = ncv->cols - begx;
if(leny == 0 || lenx == 0){
ncvisual_destroy(ncv);
return NCERR_DECODE;
}
if(ncdirect_cursor_yx(n, &begy, &begx)){
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);
//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);
if(!bset){
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);
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);
if(faken == NULL){
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;
}
ncvisual_destroy(ncv);
// FIXME render faken
ncdirect_dump_plane(n, faken);
free_plane(faken);
return NCERR_SUCCESS;
}

@ -416,9 +416,9 @@ nc_err_e ncvisual_blit(ncvisual* ncv, int rows, int cols, ncplane* n,
int stride = 0;
AVFrame* sframe = nullptr;
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)){
//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();
if(sframe == nullptr){
//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;
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,
leny, lenx, blendcolors) <= 0){
fprintf(stderr, "rgba dispatch failed!\n");
if(sframe){
av_freep(sframe->data);
av_freep(&sframe);

@ -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…
Cancel
Save