diff options
-rw-r--r-- | color_pipe.c | 32 | ||||
-rw-r--r-- | color_pipe.h | 8 | ||||
-rw-r--r-- | trapcorr.c | 55 |
3 files changed, 52 insertions, 43 deletions
diff --git a/color_pipe.c b/color_pipe.c index 648e259..b0a9ddf 100644 --- a/color_pipe.c +++ b/color_pipe.c @@ -396,8 +396,8 @@ static void set_default_value(struct color_pipe_t *pipe) { pipe->trapcorr_data.enable = 0; pipe->trapcorr_data.map_init = 0; - pipe->trapcorr_data.wv = 1.0f; - pipe->trapcorr_data.wh = 1.0f; + pipe->trapcorr_data.wv = 0.0f; + pipe->trapcorr_data.wh = 0.0f; pipe->trapcorr_data.wv_new = pipe->trapcorr_data.wv; pipe->trapcorr_data.wh_new = pipe->trapcorr_data.wh; } @@ -877,16 +877,15 @@ void __stdcall color_pipe_stageconf_gamma(struct color_pipe_t *color_pipe, int e /** * Pipeline stage configuration: Isosceles Trapeze Correction * - * The vertical and horizontal correction weight are positive - * numbers starting from 0. A weight of 1.0 means no correction. A weight lesser than - * 1.0 means the upper trapeze line is shorter than the lower trapeze line. - * Therfore a weight greater than 1.0 means the upper trapeze line is longer than - * the lower line. + * The vertical and horizontal correction weight are per cent values ranging + * from -100.0 % to +100.0 %. A positive weight means that the upper horizontal trapeze + * is fixed and won't shrink while a negative value means the opposite lower line won't change. + * A weight of zero means not correction. * * @param color_pipe Pointer to pipeline context * @param enable not 0: enable, 0: disable - * @param wv vertical weight - * @param wh horizontal weight + * @param wv vertical weight (range: -100.0 to +100.0) + * @param wh horizontal weight (range: -100.0 to +100.0) */ void __stdcall color_pipe_stageconf_trapcorr(struct color_pipe_t *color_pipe, int enable, float wv, float wh) { // paranoia @@ -896,11 +895,18 @@ void __stdcall color_pipe_stageconf_trapcorr(struct color_pipe_t *color_pipe, in } // range check - if(wv < 0.0f) { - wv = 0.0f; + if(wv < -100.0f) { + wv = -100.0f; } - if(wh < 0.0f) { - wh = 0.0f; + else if(wv > 100.0) { + wv = 100.0f; + } + + if(wh < -100.0f) { + wh = -100.0f; + } + else if(wh > 100.0) { + wh = 100.0f; } color_pipe->trapcorr_data.enable = enable; diff --git a/color_pipe.h b/color_pipe.h index b4c50da..9b52f23 100644 --- a/color_pipe.h +++ b/color_pipe.h @@ -293,10 +293,10 @@ struct trapcorr_data_t { int bit_channel; ///< Bits per color channel. int width; ///< image width in number of pixels int height; ///< image height in number of pixels - float wv; ///< vertical correction weight in per cent (NOTE not implemented yet!) - float wh; ///< horizontal correction weight in per cent - float wv_new; ///< this vertical correction weight in per cent is changed by API call (use double buffering) (NOTE not implemented yet!) - float wh_new; ///< this horizontal correction weight in per cent is changed by API call (use double buffering) + float wv; ///< vertical correction weight in per cent (range: -100.0 to +100.0) (NOTE not implemented yet!) + float wh; ///< horizontal correction weight in per cent (range: -100.0 to +100.0) + float wv_new; ///< double buffered vertical correction weight + float wh_new; ///< double buffered horizontal correction weight int map_init; ///< flag indicating perspective correction map is initialized @@ -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 |