Merge pull request #21 from kAworu/threshold-fix
Avoid division by zero.
This commit is contained in:
commit
aeb9b88d1a
1 changed files with 10 additions and 0 deletions
|
@ -174,6 +174,7 @@ static void flood_fill_seed(struct quirc *q, int x, int y, int from, int to,
|
|||
* Adaptive thresholding
|
||||
*/
|
||||
|
||||
#define THRESHOLD_S_MIN 1
|
||||
#define THRESHOLD_S_DEN 8
|
||||
#define THRESHOLD_T 5
|
||||
|
||||
|
@ -185,6 +186,15 @@ static void threshold(struct quirc *q)
|
|||
int threshold_s = q->w / THRESHOLD_S_DEN;
|
||||
quirc_pixel_t *row = q->pixels;
|
||||
|
||||
/*
|
||||
* Ensure a sane, non-zero value for threshold_s.
|
||||
*
|
||||
* threshold_s can be zero if the image width is small. We need to avoid
|
||||
* SIGFPE as it will be used as divisor.
|
||||
*/
|
||||
if (threshold_s < THRESHOLD_S_MIN)
|
||||
threshold_s = THRESHOLD_S_MIN;
|
||||
|
||||
for (y = 0; y < q->h; y++) {
|
||||
int row_average[q->w];
|
||||
|
||||
|
|
Loading…
Reference in a new issue