aboutsummaryrefslogtreecommitdiffstats
path: root/trapcorr.c
diff options
context:
space:
mode:
authorPatrick Roth <roth@stettbacher.ch>2021-07-01 10:54:34 +0200
committerPatrick Roth <roth@stettbacher.ch>2021-07-01 10:54:34 +0200
commit39529749bd4df513541bf259795ee6698f4fd679 (patch)
treef3ec2d2256d6f11f6c1b50c2815597c42c3843fd /trapcorr.c
parentworking copy (diff)
downloado3000-color-pipe-39529749bd4df513541bf259795ee6698f4fd679.tar.gz
o3000-color-pipe-39529749bd4df513541bf259795ee6698f4fd679.zip
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!
Diffstat (limited to 'trapcorr.c')
-rw-r--r--trapcorr.c55
1 files changed, 29 insertions, 26 deletions
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