directmode: honor xmax/ymax when rendering images #1661

pull/1672/head
nick black 3 years ago committed by Nick Black
parent 0b197fe19b
commit 0e593502d4

@ -532,9 +532,13 @@ static ncdirectv*
ncdirect_render_visual(ncdirect* n, ncvisual* ncv, ncblitter_e blitfxn,
ncscale_e scale, int ymax, int xmax,
uint32_t transcolor){
if(ymax < 0 || xmax < 0){
fprintf(stderr, "Invalid render geometry %d/%d\n", ymax, xmax);
return NULL;
}
int dimy = ymax > 0 ? ymax : (ncdirect_dim_y(n) - 1);
int dimx = xmax > 0 ? xmax : ncdirect_dim_x(n);
//fprintf(stderr, "OUR DATA: %p rows/cols: %d/%d outsize: %d/%d %d\n", ncv->data, ncv->pixy, ncv->pixx, dimy, dimx, ymax);
//fprintf(stderr, "OUR DATA: %p rows/cols: %d/%d outsize: %d/%d %d/%d\n", ncv->data, ncv->pixy, ncv->pixx, dimy, dimx, ymax, xmax);
//fprintf(stderr, "render %d/%d to scaling: %d\n", ncv->pixy, ncv->pixx, scale);
const struct blitset* bset = rgba_blitter_low(&n->tcache, scale, true, blitfxn);
if(!bset){
@ -572,6 +576,7 @@ ncdirect_render_visual(ncdirect* n, ncvisual* ncv, ncblitter_e blitfxn,
disprows = outy;
}
}
//fprintf(stderr, "max: %d/%d out: %d/%d\n", ymax, xmax, outy, dispcols);
//fprintf(stderr, "render: %d/%d stride %u %p\n", ncv->pixy, ncv->pixx, ncv->pixytride, ncv->data);
ncplane_options nopts = {
.y = 0,
@ -587,6 +592,12 @@ ncdirect_render_visual(ncdirect* n, ncvisual* ncv, ncblitter_e blitfxn,
nopts.rows = outy / n->tcache.cellpixy + !!(outy % n->tcache.cellpixy);
nopts.cols = dispcols / n->tcache.cellpixx + !!(dispcols % n->tcache.cellpixx);
}
if(ymax && nopts.rows > ymax){
nopts.rows = ymax;
}
if(xmax && nopts.cols > xmax){
nopts.cols = xmax;
}
struct ncplane* ncdv = ncplane_new_internal(NULL, NULL, &nopts);
if(!ncdv){
return NULL;
@ -624,7 +635,7 @@ ncdirectv* ncdirect_render_frame(ncdirect* n, const char* file,
int ncdirect_render_image(ncdirect* n, const char* file, ncalign_e align,
ncblitter_e blitfxn, ncscale_e scale){
ncdirectv* faken = ncdirect_render_frame(n, file, blitfxn, scale, -1, -1);
ncdirectv* faken = ncdirect_render_frame(n, file, blitfxn, scale, 0, 0);
if(!faken){
return -1;
}

@ -618,6 +618,8 @@ typedef struct blitterargs {
// consumed there, and blitters ought always work with the scaled output.
int begy; // upper left start within visual
int begx;
int leny; // number of source pixels to use
int lenx;
uint32_t transcolor; // if non-zero, treat the lower 24 bits as a transparent color
union { // cell vs pixel-specific arguments
struct {

@ -2,6 +2,42 @@
#include <unistd.h>
#include <notcurses/direct.h>
// print progressive partial subsets of the image
static int
partial_image(struct ncdirect* n, const char* file){
ncdirectf* nf = ncdirectf_from_file(n, file);
if(nf == NULL){
return -1;
}
// get the number of pixels
ncvgeom geom;
ncblitter_e blit = NCBLIT_1x1;
ncdirectf_geom(n, nf, &blit, NCSCALE_NONE, 0, 0, &geom);
if(geom.cdimy <= 0){
fprintf(stderr, "no cell dim information\n");
ncdirectf_free(nf);
return -1;
}
for(int y = geom.pixy ; y > 0 ; y -= 5){
int rows = y;
for(int x = geom.pixx ; x > 0 ; x -= 5){
int cols = x;
ncdirectv* v;
printf("Size: %dx%d\n", cols, rows);
if((v = ncdirectf_render(n, nf, blit, NCSCALE_NONE, rows, cols)) == NULL){
ncdirectf_free(nf);
return -1;
}
if(ncdirect_raster_frame(n, v, NCALIGN_CENTER)){
ncdirectf_free(nf);
return -1;
}
}
}
ncdirectf_free(nf);
return 0;
}
// can we leave what was already on the screen there? (narrator: it seems not)
int main(void){
if(!setlocale(LC_ALL, "")){

Loading…
Cancel
Save