mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 01:29:05 -04:00
ffmpeg: properly scale #714
This commit is contained in:
parent
0084dbaa6d
commit
7c1e9fe3d2
@ -87,7 +87,7 @@ int dragon_demo(struct notcurses* nc){
|
||||
++iters;
|
||||
lasttotal = r;
|
||||
pixel = 0xffffffffull;
|
||||
ncpixel_set_rgb(&pixel, 0, 0xb * iters, 0);
|
||||
ncpixel_set_rgb(&pixel, 0, 0xb * iters, 0xf0 - (4 * iters));
|
||||
dx = dxstart;
|
||||
dy = dystart;
|
||||
x = dimx / 2;
|
||||
|
@ -26596,7 +26596,6 @@ int jungle_demo(struct notcurses* nc){
|
||||
return 0;
|
||||
}
|
||||
struct timespec start, now;
|
||||
clock_gettime(CLOCK_MONOTONIC_RAW, &start);
|
||||
size_t have = 0, out = 0;
|
||||
struct ncplane* copyplane;
|
||||
palette256* pal;
|
||||
@ -26663,9 +26662,9 @@ int jungle_demo(struct notcurses* nc){
|
||||
}
|
||||
cell_release(n, &c);
|
||||
free(buf);
|
||||
clock_gettime(CLOCK_MONOTONIC_RAW, &start);
|
||||
int iter = 0;
|
||||
// don't try to run faster than, eh, 140Hz
|
||||
int64_t iterns = GIG / 100;
|
||||
int64_t iterns = GIG / 30;
|
||||
int64_t nsrunning;
|
||||
do{
|
||||
DEMO_RENDER(nc);
|
||||
|
@ -597,7 +597,7 @@ int ncplane_qrcode(ncplane* n, ncblitter_e blitter, int* ymax,
|
||||
if(rgba){
|
||||
for(int y = starty ; y < starty + square ; ++y){
|
||||
for(int x = startx ; x < startx + square ; ++x){
|
||||
const bool pixel = qrcodegen_getModule(dst, x, y);
|
||||
const bool pixel = !qrcodegen_getModule(dst, x, y);
|
||||
ncpixel_set_a(&rgba[y * square + x], 0xff);
|
||||
ncpixel_set_rgb(&rgba[y * square + x], r * pixel, g * pixel, b * pixel);
|
||||
}
|
||||
|
@ -429,21 +429,24 @@ auto ncvisual_render(notcurses* nc, ncvisual* ncv,
|
||||
//fprintf(stderr, "INPUT N: %p\n", vopts ? vopts->n : nullptr);
|
||||
if((n = (vopts ? vopts->n : nullptr)) == nullptr){ // create plane
|
||||
if(!vopts || vopts->scaling == NCSCALE_NONE){
|
||||
dispcols = ncv->cols / encoding_x_scale(bset) + ncv->cols % encoding_x_scale(bset);
|
||||
disprows = ncv->rows / encoding_y_scale(bset) + ncv->rows % encoding_y_scale(bset);
|
||||
dispcols = ncv->cols;
|
||||
disprows = ncv->rows;
|
||||
}else{
|
||||
notcurses_term_dim_yx(nc, &disprows, &dispcols);
|
||||
dispcols *= encoding_x_scale(bset);
|
||||
disprows *= encoding_y_scale(bset);
|
||||
if(vopts->scaling == NCSCALE_SCALE){
|
||||
double xratio = (double)(dispcols * encoding_x_scale(bset)) / ncv->cols;
|
||||
if(xratio * ncv->rows > disprows * encoding_y_scale(bset)){
|
||||
xratio = (double)(disprows * encoding_y_scale(bset)) / ncv->rows;
|
||||
double xratio = (double)(dispcols) / ncv->cols;
|
||||
if(xratio * ncv->rows > disprows){
|
||||
xratio = (double)(disprows) / ncv->rows;
|
||||
}
|
||||
disprows = xratio * (ncv->rows / encoding_y_scale(bset));
|
||||
dispcols = xratio * (ncv->cols / encoding_x_scale(bset));
|
||||
disprows = xratio * (ncv->rows);
|
||||
dispcols = xratio * (ncv->cols);
|
||||
}
|
||||
}
|
||||
//fprintf(stderr, "PLACING NEW PLANE: %d/%d @ %d/%d\n", disprows, dispcols, placey, placex);
|
||||
n = ncplane_new(nc, disprows, dispcols, placey, placex, nullptr);
|
||||
n = ncplane_new(nc, disprows / encoding_y_scale(bset),
|
||||
dispcols / encoding_x_scale(bset), placey, placex, nullptr);
|
||||
if(n == nullptr){
|
||||
return nullptr;
|
||||
}
|
||||
@ -451,27 +454,28 @@ auto ncvisual_render(notcurses* nc, ncvisual* ncv,
|
||||
placex = 0;
|
||||
}else{
|
||||
if(!vopts || vopts->scaling == NCSCALE_NONE){
|
||||
dispcols = ncv->cols / encoding_x_scale(bset) + ncv->cols % encoding_x_scale(bset);
|
||||
disprows = ncv->rows / encoding_y_scale(bset) + ncv->rows % encoding_y_scale(bset);
|
||||
dispcols = ncv->cols;
|
||||
disprows = ncv->rows;
|
||||
}else{
|
||||
ncplane_dim_yx(n, &disprows, &dispcols);
|
||||
dispcols *= encoding_x_scale(bset);
|
||||
disprows *= encoding_y_scale(bset);
|
||||
disprows -= placey;
|
||||
dispcols -= placex;
|
||||
if(vopts->scaling == NCSCALE_SCALE){
|
||||
double xratio = (double)(dispcols * encoding_x_scale(bset)) / ncv->cols;
|
||||
if(xratio * ncv->rows > (double)(disprows * encoding_y_scale(bset))){
|
||||
xratio = (double)(disprows * encoding_y_scale(bset)) / ncv->rows;
|
||||
double xratio = (double)(dispcols) / ncv->cols;
|
||||
if(xratio * ncv->rows > (double)(disprows)){
|
||||
xratio = (double)(disprows) / ncv->rows;
|
||||
}
|
||||
disprows = xratio * (ncv->rows / encoding_y_scale(bset));
|
||||
dispcols = xratio * (ncv->cols / encoding_x_scale(bset));
|
||||
disprows = xratio * (ncv->rows);
|
||||
dispcols = xratio * (ncv->cols);
|
||||
}
|
||||
}
|
||||
}
|
||||
leny = (leny / (double)ncv->rows) * ((double)disprows * encoding_y_scale(bset));
|
||||
lenx = (lenx / (double)ncv->cols) * ((double)dispcols * encoding_x_scale(bset));
|
||||
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);
|
||||
if(ncvisual_blit(ncv, disprows * encoding_y_scale(bset),
|
||||
dispcols * encoding_x_scale(bset), n, bset,
|
||||
if(ncvisual_blit(ncv, disprows, dispcols, n, bset,
|
||||
placey, placex, begy, begx, leny, lenx,
|
||||
vopts && (vopts->flags & NCVISUAL_OPTION_BLEND))){
|
||||
ncplane_destroy(n);
|
||||
|
Loading…
x
Reference in New Issue
Block a user