From 39529749bd4df513541bf259795ee6698f4fd679 Mon Sep 17 00:00:00 2001 From: Patrick Roth Date: Thu, 1 Jul 2021 10:54:34 +0200 Subject: change weights to -100.0...+100.0 per cent The upper and lower horizontal trapeze line will change. The vertical weight is not implemented now! --- trapcorr.c | 55 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 26 deletions(-) (limited to 'trapcorr.c') diff --git a/trapcorr.c b/trapcorr.c index 3ace25f..aef2411 100644 --- a/trapcorr.c +++ b/trapcorr.c @@ -188,7 +188,6 @@ static void correct(struct trapcorr_data_t *data) { const int scale_fact = data->map_scale_fact; const int is_color = data->is_color; - for(y = 0; y < height; y++) { for(x = 0; x < width; x++) { x_corr = map->x; @@ -228,15 +227,32 @@ static void init_map(struct trapcorr_data_t *data) { const int scale_fact = (1 << (data->map_scale_fact)); const int width = data->width; const int height = data->height; - const float p = data->wh * (width/2.0f); - float p_i, row_scale, x_corr, y_corr; + float p, p_i, row_scale, x_corr, y_corr; int x_start, x_end; + int shrink_upper; + // convert -100.0...+100.0 ---> 0.0...2.0 + const float fact = data->wh/100.0f+1.0f; -// printf("XXX P = %f\n", p); + /* + * Checking whether we shrink upper or lower horizontal + * trapeze line. + */ + if(data->wh <= 1.0f) { + // upper line shrinks + shrink_upper = 1; + p = fact * (width/2.0f); + } + else { + // lower line shrinks + shrink_upper = 0; + p = (2.0f - fact) * (width/2.0f); + } /* - * horizontal correction + * We'll loop through image with y-axis symmetrically centered. + * So the image is horizontally shifted to left. Do calculate + * the start and end values on x-axis. */ if((width%2) == 0) { // even width @@ -249,11 +265,15 @@ static void init_map(struct trapcorr_data_t *data) { x_end = (width-1)/2; } -// printf("XXX x_start = %d, x_end = %d, %d x %d\n", x_start, x_end, width, height); - + // loop through image for(y = 0; y < height; y++) { - - p_i = ((width/2.0f - p) / height) * y + p; + if(shrink_upper) { + p_i = ((width/2.0f - p) / height) * y + p; + } + else { + p_i = (-1.0f*((width/2.0f - p) / height)) * y + width/2.0f; + } + row_scale = 2.0f * p_i / width; // we don't correct vertically @@ -262,25 +282,9 @@ static void init_map(struct trapcorr_data_t *data) { for(x = x_start; x <= x_end; x++) { x_corr = x/row_scale; -// if(x > -325 && x < -315 && y < 2) { -// printf("%d/%d: p_i = %f, row_scale = %f, x_corr = %f\n", y, x, p_i, row_scale, x_corr); -// } - // trapeze is horizontally symmetrically centered --> shift right x_corr -= x_start; -// if(x > -325 && x < -315 && y < 2) { -// printf(" ----> x_corr (shift)= %f\n", x_corr); -// } - - // range check - if(x_corr < 0.0f) { - x_corr = 0.0f; - } - else if(x_corr > (width-1.0f)) { - x_corr = width-1.0f; - } - // apply scaling factor map->x = (int)roundf(x_corr*scale_fact); map->y = (int)roundf(y_corr*scale_fact); @@ -305,7 +309,6 @@ int trapcorr(struct trapcorr_data_t *trapcorr_data) { trapcorr_data->map_scale_fact = 9; // scale by 9 means 2^9 = 512 init_map(trapcorr_data); trapcorr_data->map_init = 1; - printf("XXXXX map initialized!\n"); } // apply perspective correction -- cgit v1.2.1