summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy White <jwhite@codeweavers.com>2020-03-19 12:50:58 -0500
committerJeremy White <jwhite@codeweavers.com>2020-04-20 12:19:57 -0500
commit5e52043b4ebf4705d68064589b48dff6c6228a33 (patch)
tree44b17033a9598389acdb20e82408ece8f25a4719
parentf546e278392cf4460439eaf178f7d7a659870630 (diff)
Bug fix - send the last few lines of a scanned box when rounding badly.
If the number of vertical lines results in an odd dividend, we were truncating the computation and not sending the last few lines. This fixes that by first avoiding early division which would truncate values, and by then rounding up our width and height calculations. This fixes the bug in the tests introduced in the previous patch.
-rw-r--r--src/scan.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/scan.c b/src/scan.c
index aa57427..e2e4dc2 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -173,11 +173,20 @@ static void free_queue_item(gpointer data)
static void push_tiles_report(scanner_t *scanner, int start_row, int start_col, int end_row,
int end_col)
{
- int x = (scanner->session->display.fullscreen->w / NUM_HORIZONTAL_TILES) * start_col;
- int w = (scanner->session->display.fullscreen->w / NUM_HORIZONTAL_TILES) * (end_col - start_col + 1);
-
- int y = (scanner->session->display.fullscreen->h / NUM_SCANLINES) * start_row;
- int h = scanner->session->display.fullscreen->h / NUM_SCANLINES * (end_row - start_row + 1);
+ /* Note: we do this as integer math, and so we multiply first to avoid discarding
+ fractions in our calculations. We also want to round down for our x, y, and
+ round up for our width and height calculations, as doesn't hurt to send more */
+ int x = (start_col * scanner->session->display.fullscreen->w) / NUM_HORIZONTAL_TILES;
+ int w = ((end_col - start_col + 1) * scanner->session->display.fullscreen->w) /
+ NUM_HORIZONTAL_TILES;
+ if (((end_col - start_col + 1) * scanner->session->display.fullscreen->w) %
+ NUM_HORIZONTAL_TILES)
+ w++;
+
+ int y = (start_row * scanner->session->display.fullscreen->h) / NUM_SCANLINES;
+ int h = ((end_row - start_row + 1) * scanner->session->display.fullscreen->h) / NUM_SCANLINES;
+ if (((end_row - start_row + 1) * scanner->session->display.fullscreen->h) % NUM_SCANLINES)
+ h++;
if (x + w > scanner->session->display.fullscreen->w)
w = scanner->session->display.fullscreen->w - x;
@@ -458,7 +467,7 @@ int scanner_push(scanner_t *scanner, scan_type_t type, int x, int y, int w, int
}
#if defined(DEBUG_SCANLINES)
- fprintf(stderr, "scan: %dx%d @ %dx%d\n", w, h, x, y);
+ fprintf(stderr, "scan: type %d, %dx%d @ %dx%d\n", type, w, h, x, y);
fflush(stderr);
#endif