diff --git a/imgproc.c b/imgproc.c index 852b25d..4c1352a 100644 --- a/imgproc.c +++ b/imgproc.c @@ -613,92 +613,39 @@ double iterative_threshold(Imlib_Image *source_image, double thresh, return new_thresh * 100; } -/* get minimum lum value */ -double get_minval(Imlib_Image *source_image, int x, int y, int w, int h, - luminance_t lt) +/* get minimum and maximum lum values */ +void get_minmaxval(Imlib_Image *source_image, luminance_t lt, + double *min, double *max) { Imlib_Image current_image; /* save image pointer */ - int height, width; /* image dimensions */ + int w, h; /* image dimensions */ int xi,yi; /* iteration variables */ Imlib_Color color; /* Imlib2 RGBA color structure */ - int minval = MAXRGB; int lum = 0; + *min = MAXRGB; + *max = 0; + /* save pointer to current image */ current_image = imlib_context_get_image(); /* get image dimensions */ imlib_context_set_image(*source_image); - height = imlib_image_get_height(); - width = imlib_image_get_width(); - - /* special value -1 for width or height means image width/height */ - if(w == -1) w = width; - if(h == -1) h = width; - - /* assure valid coordinates */ - if(x+w > width) x = width-w; - if(y+h > height) y = height-h; - if(x<0) x=0; - if(y<0) y=0; + h = imlib_image_get_height(); + w = imlib_image_get_width(); /* find the minimum value in the image */ - for(xi=0; (xi *max) *max = lum; } } /* restore image from before function call */ imlib_context_set_image(current_image); - - return minval; -} - -/* get maximum luminance value */ -double get_maxval(Imlib_Image *source_image, int x, int y, int w, int h, - luminance_t lt) -{ - Imlib_Image current_image; /* save image pointer */ - int height, width; /* image dimensions */ - int xi,yi; /* iteration variables */ - Imlib_Color color; /* Imlib2 RGBA color structure */ - int lum = 0; - int maxval = 0; - - /* save pointer to current image */ - current_image = imlib_context_get_image(); - - /* get image dimensions */ - imlib_context_set_image(*source_image); - height = imlib_image_get_height(); - width = imlib_image_get_width(); - - /* special value -1 for width or height means image width/height */ - if(w == -1) w = width; - if(h == -1) h = width; - - /* assure valid coordinates */ - if(x+w > width) x = width-w; - if(y+h > height) y = height-h; - if(x<0) x=0; - if(y<0) y=0; - - /* find the minimum value in the image */ - for(xi=0; (xi maxval) maxval = lum; - } - } - - /* restore image from before function call */ - imlib_context_set_image(current_image); - - return maxval; } /* draw a white (background) border around image, overwriting image contents diff --git a/imgproc.h b/imgproc.h index fe73167..89a8908 100644 --- a/imgproc.h +++ b/imgproc.h @@ -141,13 +141,9 @@ double get_threshold(Imlib_Image *source_image, double fraction, luminance_t lt, double iterative_threshold(Imlib_Image *source_image, double thresh, luminance_t lt, int x, int y, int w, int h); -/* get minimum gray value */ -double get_minval(Imlib_Image *source_image, int x, int y, int w, int h, - luminance_t lt); - -/* get maximum gray value */ -double get_maxval(Imlib_Image *source_image, int x, int y, int w, int h, - luminance_t lt); +/* get minimum and maximum gray (luminace) values */ +void get_minmaxval(Imlib_Image *source_image, luminance_t lt, + double *min, double *max); /* compute luminance from RGB values */ int get_lum(Imlib_Color *color, luminance_t lt); diff --git a/ssocr.c b/ssocr.c index f8fe7e5..5dec665 100644 --- a/ssocr.c +++ b/ssocr.c @@ -727,9 +727,10 @@ int main(int argc, char **argv) /* get minimum and maximum "value" values */ if((flags & DEBUG_OUTPUT) || (flags & PRINT_INFO)) { + double min, max; + get_minmaxval(&image, lt, &min, &max); fprintf(stderr, "%.2f <= lum <= %.2f (lum should be in [0,255])\n", - get_minval(&image, 0, 0, -1, -1, lt), - get_maxval(&image, 0, 0, -1, -1, lt)); + min, max); } /* adapt threshold to image */ @@ -989,8 +990,7 @@ int main(int argc, char **argv) fprintf(stderr, " adjusting T1=%.2f and T2=%.2f to image\n", t1, t2); } - min = get_minval(&image, 0, 0, -1, -1, lt); - max = get_maxval(&image, 0, 0, -1, -1, lt); + get_minmaxval(&image, lt, &min, &max); t1 = min + t1/100.0 * (max - min); t2 = min + t2/100.0 * (max - min); if(flags & VERBOSE) { @@ -1046,10 +1046,10 @@ int main(int argc, char **argv) } /* get minimum and maximum "value" values in cropped image */ if((flags&DEBUG_OUTPUT) || (flags&PRINT_INFO) || (flags&VERBOSE)) { + double min, max; + get_minmaxval(&image, lt, &min, &max); fprintf(stderr, " %.2f <= lum <= %.2f in cropped image" - " (lum should be in [0,255])\n", - get_minval(&image, 0, 0, -1, -1, lt), - get_maxval(&image, 0, 0, -1, -1, lt)); + " (lum should be in [0,255])\n", min, max); } /* adapt threshold to cropped image */ thresh = adapt_threshold(&image, thresh, lt, 0, 0, -1, -1, flags);