From ca686a281abc6f044afb81e395cf8c754b16fe47 Mon Sep 17 00:00:00 2001 From: Damian Blatt Date: Wed, 24 Jun 2026 11:09:30 +0200 Subject: [PATCH 1/7] feat: add ignore area Ignored area is defined by passing position (from the upper left corner), width and length of the rectangle. --- diff-pdf.cpp | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 3 deletions(-) diff --git a/diff-pdf.cpp b/diff-pdf.cpp index 0c24358..e405633 100644 --- a/diff-pdf.cpp +++ b/diff-pdf.cpp @@ -41,6 +41,7 @@ #include #include #include +#include enum DisplayMode @@ -64,6 +65,11 @@ bool g_grayscale = false; #define DEFAULT_RESOLUTION 300 long g_resolution = DEFAULT_RESOLUTION; +// Rectangle (in PDF points, origin top-left) within which differences are +// ignored entirely. +struct IgnoreArea { double x, y, w, h; bool valid; }; +IgnoreArea g_ignore_area = { 0, 0, 0, 0, false }; + inline unsigned char to_grayscale(unsigned char r, unsigned char g, unsigned char b) { return (unsigned char)(0.2126 * r + 0.7152 * g + 0.0722 * b); @@ -174,6 +180,22 @@ cairo_surface_t *diff_images(int page, cairo_surface_t *s1, cairo_surface_t *s2, const unsigned char *data2 = s2 ? cairo_image_surface_get_data(s2) : NULL; unsigned char *datadiff = cairo_image_surface_get_data(diff); + // convert the ignore area from PDF points to pixel coordinates in the + // rdiff coordinate space: + wxRect ignore_px; + if ( g_ignore_area.valid ) + { + const double scale = (int)g_resolution / 72.0; + // round the edges individually (rather than rounding width/height + // separately) so the rectangle covers every pixel that the + // rasterizer may have touched, including anti-aliased borders + const int px1 = wxRound(g_ignore_area.x * scale); + const int py1 = wxRound(g_ignore_area.y * scale); + const int px2 = wxRound((g_ignore_area.x + g_ignore_area.w) * scale); + const int py2 = wxRound((g_ignore_area.y + g_ignore_area.h) * scale); + ignore_px = wxRect(px1 + r1.x, py1 + r1.y, px2 - px1, py2 - py1); + } + // we visualize the differences by taking one channel from s1 // and the other two channels from s2: @@ -210,9 +232,13 @@ cairo_surface_t *diff_images(int page, cairo_surface_t *s1, cairo_surface_t *s2, unsigned char cg2 = *(data2 + x + 1); unsigned char cb2 = *(data2 + x + 2); - if ( cr1 > (cr2+g_channel_tolerance) || cr1 < (cr2-g_channel_tolerance) - || cg1 > (cg2+g_channel_tolerance) || cg1 < (cg2-g_channel_tolerance) - || cb1 > (cb2+g_channel_tolerance) || cb1 < (cb2-g_channel_tolerance) + const bool ignored = g_ignore_area.valid && ignore_px.Contains(r2.x + x/4, r2.y + y); + + if ( ( cr1 > (cr2+g_channel_tolerance) || cr1 < (cr2-g_channel_tolerance) + || cg1 > (cg2+g_channel_tolerance) || cg1 < (cg2-g_channel_tolerance) + || cb1 > (cb2+g_channel_tolerance) || cb1 < (cb2-g_channel_tolerance) + ) + && !ignored ) { pixel_diff_count++; @@ -330,6 +356,20 @@ cairo_surface_t *diff_images(int page, cairo_surface_t *s1, cairo_surface_t *s2, // If we specified a tolerance, then return if we have exceeded that for this page if ( g_per_page_pixel_tolerance == 0 ? changes : pixel_diff_count > g_per_page_pixel_tolerance) { + if ( g_ignore_area.valid ) + { + // mark the ignored area with a dashed gray outline, so it's + // clear when reviewing the diff that it was excluded on purpose + cairo_t *cr = cairo_create(diff); + static const double dashes[] = { 4.0, 4.0 }; + cairo_set_dash(cr, dashes, 2, 0); + cairo_set_line_width(cr, 2.0); + cairo_set_source_rgb(cr, 0.5, 0.5, 0.5); + cairo_rectangle(cr, ignore_px.x, ignore_px.y, ignore_px.width, ignore_px.height); + cairo_stroke(cr); + cairo_destroy(cr); + } + return diff; } else @@ -991,6 +1031,10 @@ int main(int argc, char *argv[]) NULL, "per-page-pixel-tolerance", "total number of pixels allowed to be different per page before specifying the page is different", wxCMD_LINE_VAL_NUMBER }, + { wxCMD_LINE_OPTION, + NULL, "ignore-area", "ignore differences inside a rectangle, given as X,Y,WIDTH,HEIGHT in PDF points: X,Y is the top-left corner of the rectangle (measured from the page's top-left corner)", + wxCMD_LINE_VAL_STRING }, + { wxCMD_LINE_OPTION, NULL, "dpi", "rasterization resolution (default: " wxSTRINGIZE(DEFAULT_RESOLUTION) " dpi)", wxCMD_LINE_VAL_NUMBER }, @@ -1065,6 +1109,33 @@ int main(int argc, char *argv[]) } } + wxString ignore_area_str; + if ( parser.Found("ignore-area", &ignore_area_str) ) + { + wxStringTokenizer tokenizer(ignore_area_str, ","); + double values[4]; + bool ok = true; + size_t count = 0; + while ( ok && tokenizer.HasMoreTokens() && count < 4 ) + ok = tokenizer.GetNextToken().ToCDouble(&values[count++]); + ok = ok && (count == 4) && !tokenizer.HasMoreTokens(); + + if ( !ok || values[2] <= 0 || values[3] <= 0 ) + { + fprintf(stderr, "Invalid ignore-area: %s. Expected X,Y,WIDTH,HEIGHT in PDF points " + "(X,Y = top-left corner of the rectangle, measured from the page's top-left " + "corner)\n", + (const char*) ignore_area_str.c_str()); + return 2; + } + + g_ignore_area.x = values[0]; + g_ignore_area.y = values[1]; + g_ignore_area.w = values[2]; + g_ignore_area.h = values[3]; + g_ignore_area.valid = true; + } + if ( parser.Found("channel-tolerance", &g_channel_tolerance) ) { if (g_channel_tolerance < 0 || g_channel_tolerance > 255) { From 9a4c1767c9b16a1613040397fab0f3252715c1c8 Mon Sep 17 00:00:00 2001 From: Damian Blatt Date: Wed, 24 Jun 2026 11:20:51 +0200 Subject: [PATCH 2/7] fix: no color diff overlay in ignored area --- diff-pdf.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/diff-pdf.cpp b/diff-pdf.cpp index e405633..d88a61c 100644 --- a/diff-pdf.cpp +++ b/diff-pdf.cpp @@ -262,6 +262,13 @@ cairo_surface_t *diff_images(int page, cairo_surface_t *s1, cairo_surface_t *s2, } } + // leave pixels in the ignored area showing s1's original + // image, undistorted by the diff color overlay + if ( ignored ) + { + continue; + } + if (g_grayscale) { // convert both images to grayscale, use blue for s1, red for s2 From ea7a9f5067026dbfeec4c561f54bada19d0ac577 Mon Sep 17 00:00:00 2001 From: Damian Blatt Date: Wed, 24 Jun 2026 12:08:40 +0200 Subject: [PATCH 3/7] feat: allow multiple areas separated by semicolon --- diff-pdf.cpp | 103 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 41 deletions(-) diff --git a/diff-pdf.cpp b/diff-pdf.cpp index d88a61c..0ba9bc0 100644 --- a/diff-pdf.cpp +++ b/diff-pdf.cpp @@ -65,10 +65,10 @@ bool g_grayscale = false; #define DEFAULT_RESOLUTION 300 long g_resolution = DEFAULT_RESOLUTION; -// Rectangle (in PDF points, origin top-left) within which differences are +// Rectangles (in PDF points, origin top-left) within which differences are // ignored entirely. -struct IgnoreArea { double x, y, w, h; bool valid; }; -IgnoreArea g_ignore_area = { 0, 0, 0, 0, false }; +struct IgnoreArea { double x, y, w, h; }; +std::vector g_ignore_areas; inline unsigned char to_grayscale(unsigned char r, unsigned char g, unsigned char b) { @@ -180,22 +180,35 @@ cairo_surface_t *diff_images(int page, cairo_surface_t *s1, cairo_surface_t *s2, const unsigned char *data2 = s2 ? cairo_image_surface_get_data(s2) : NULL; unsigned char *datadiff = cairo_image_surface_get_data(diff); - // convert the ignore area from PDF points to pixel coordinates in the + // convert the ignore areas from PDF points to pixel coordinates in the // rdiff coordinate space: - wxRect ignore_px; - if ( g_ignore_area.valid ) + std::vector ignore_px; { const double scale = (int)g_resolution / 72.0; - // round the edges individually (rather than rounding width/height - // separately) so the rectangle covers every pixel that the - // rasterizer may have touched, including anti-aliased borders - const int px1 = wxRound(g_ignore_area.x * scale); - const int py1 = wxRound(g_ignore_area.y * scale); - const int px2 = wxRound((g_ignore_area.x + g_ignore_area.w) * scale); - const int py2 = wxRound((g_ignore_area.y + g_ignore_area.h) * scale); - ignore_px = wxRect(px1 + r1.x, py1 + r1.y, px2 - px1, py2 - py1); + for ( size_t i = 0; i < g_ignore_areas.size(); i++ ) + { + const IgnoreArea& a = g_ignore_areas[i]; + // round the edges individually (rather than rounding width/height + // separately) so the rectangle covers every pixel that the + // rasterizer may have touched, including anti-aliased borders + const int px1 = wxRound(a.x * scale); + const int py1 = wxRound(a.y * scale); + const int px2 = wxRound((a.x + a.w) * scale); + const int py2 = wxRound((a.y + a.h) * scale); + ignore_px.push_back(wxRect(px1 + r1.x, py1 + r1.y, px2 - px1, py2 - py1)); + } } + auto is_ignored = [&ignore_px](int x, int y) -> bool + { + for ( size_t i = 0; i < ignore_px.size(); i++ ) + { + if ( ignore_px[i].Contains(x, y) ) + return true; + } + return false; + }; + // we visualize the differences by taking one channel from s1 // and the other two channels from s2: @@ -232,7 +245,7 @@ cairo_surface_t *diff_images(int page, cairo_surface_t *s1, cairo_surface_t *s2, unsigned char cg2 = *(data2 + x + 1); unsigned char cb2 = *(data2 + x + 2); - const bool ignored = g_ignore_area.valid && ignore_px.Contains(r2.x + x/4, r2.y + y); + const bool ignored = is_ignored(r2.x + x/4, r2.y + y); if ( ( cr1 > (cr2+g_channel_tolerance) || cr1 < (cr2-g_channel_tolerance) || cg1 > (cg2+g_channel_tolerance) || cg1 < (cg2-g_channel_tolerance) @@ -363,17 +376,20 @@ cairo_surface_t *diff_images(int page, cairo_surface_t *s1, cairo_surface_t *s2, // If we specified a tolerance, then return if we have exceeded that for this page if ( g_per_page_pixel_tolerance == 0 ? changes : pixel_diff_count > g_per_page_pixel_tolerance) { - if ( g_ignore_area.valid ) + if ( !ignore_px.empty() ) { - // mark the ignored area with a dashed gray outline, so it's - // clear when reviewing the diff that it was excluded on purpose + // mark the ignored areas with a dashed gray outline, so it's + // clear when reviewing the diff that they were excluded on purpose cairo_t *cr = cairo_create(diff); static const double dashes[] = { 4.0, 4.0 }; cairo_set_dash(cr, dashes, 2, 0); cairo_set_line_width(cr, 2.0); cairo_set_source_rgb(cr, 0.5, 0.5, 0.5); - cairo_rectangle(cr, ignore_px.x, ignore_px.y, ignore_px.width, ignore_px.height); - cairo_stroke(cr); + for ( size_t i = 0; i < ignore_px.size(); i++ ) + { + cairo_rectangle(cr, ignore_px[i].x, ignore_px[i].y, ignore_px[i].width, ignore_px[i].height); + cairo_stroke(cr); + } cairo_destroy(cr); } @@ -1039,7 +1055,9 @@ int main(int argc, char *argv[]) wxCMD_LINE_VAL_NUMBER }, { wxCMD_LINE_OPTION, - NULL, "ignore-area", "ignore differences inside a rectangle, given as X,Y,WIDTH,HEIGHT in PDF points: X,Y is the top-left corner of the rectangle (measured from the page's top-left corner)", + NULL, "ignore-area", "ignore differences inside one or more rectangles, each given as X,Y,WIDTH,HEIGHT in PDF points" + "(X,Y is the rectangle's top-left corner, measured from the page's top-left corner); separate multiple rectangles with ';'," + "e.g. --ignore-area=\"20,750,80,80;480,700,40,40\"", wxCMD_LINE_VAL_STRING }, { wxCMD_LINE_OPTION, @@ -1119,28 +1137,31 @@ int main(int argc, char *argv[]) wxString ignore_area_str; if ( parser.Found("ignore-area", &ignore_area_str) ) { - wxStringTokenizer tokenizer(ignore_area_str, ","); - double values[4]; - bool ok = true; - size_t count = 0; - while ( ok && tokenizer.HasMoreTokens() && count < 4 ) - ok = tokenizer.GetNextToken().ToCDouble(&values[count++]); - ok = ok && (count == 4) && !tokenizer.HasMoreTokens(); - - if ( !ok || values[2] <= 0 || values[3] <= 0 ) + wxStringTokenizer area_tokenizer(ignore_area_str, ";"); + while ( area_tokenizer.HasMoreTokens() ) { - fprintf(stderr, "Invalid ignore-area: %s. Expected X,Y,WIDTH,HEIGHT in PDF points " - "(X,Y = top-left corner of the rectangle, measured from the page's top-left " - "corner)\n", - (const char*) ignore_area_str.c_str()); - return 2; - } + const wxString one_area = area_tokenizer.GetNextToken(); + + wxStringTokenizer tokenizer(one_area, ","); + double values[4]; + bool ok = true; + size_t count = 0; + while ( ok && tokenizer.HasMoreTokens() && count < 4 ) + ok = tokenizer.GetNextToken().ToCDouble(&values[count++]); + ok = ok && (count == 4) && !tokenizer.HasMoreTokens(); - g_ignore_area.x = values[0]; - g_ignore_area.y = values[1]; - g_ignore_area.w = values[2]; - g_ignore_area.h = values[3]; - g_ignore_area.valid = true; + if ( !ok || values[2] <= 0 || values[3] <= 0 ) + { + fprintf(stderr, "Invalid ignore-area: %s. Expected one or more X,Y,WIDTH,HEIGHT " + "rectangles (in PDF points; X,Y = top-left corner, measured from the " + "page's top-left corner; WIDTH,HEIGHT > 0), separated by ';', e.g. 20,750,80,80;480,700,40,40\n", + (const char*) ignore_area_str.c_str()); + return 2; + } + + IgnoreArea area = { values[0], values[1], values[2], values[3] }; + g_ignore_areas.push_back(area); + } } if ( parser.Found("channel-tolerance", &g_channel_tolerance) ) From 613d9bacf9eba36fa62350131c3f44657b53093e Mon Sep 17 00:00:00 2001 From: Damian Blatt Date: Wed, 22 Jul 2026 09:08:26 +0200 Subject: [PATCH 4/7] fix: error for negative coordinates Negative coordinates are now causing an error, just like negative height/width did --- diff-pdf.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diff-pdf.cpp b/diff-pdf.cpp index 0ba9bc0..ac5dd30 100644 --- a/diff-pdf.cpp +++ b/diff-pdf.cpp @@ -1150,11 +1150,11 @@ int main(int argc, char *argv[]) ok = tokenizer.GetNextToken().ToCDouble(&values[count++]); ok = ok && (count == 4) && !tokenizer.HasMoreTokens(); - if ( !ok || values[2] <= 0 || values[3] <= 0 ) + if ( !ok || values[0] < 0 || values[1] < 0 || values[2] <= 0 || values[3] <= 0 ) { fprintf(stderr, "Invalid ignore-area: %s. Expected one or more X,Y,WIDTH,HEIGHT " "rectangles (in PDF points; X,Y = top-left corner, measured from the " - "page's top-left corner; WIDTH,HEIGHT > 0), separated by ';', e.g. 20,750,80,80;480,700,40,40\n", + "page's top-left corner, with X,Y >= 0; WIDTH,HEIGHT > 0), separated by ';', e.g. 20,750,80,80;480,700,40,40\n", (const char*) ignore_area_str.c_str()); return 2; } From 7dd5a7271beefef1a4cd3074f92c09937fea3a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Sun, 8 Nov 2026 15:05:53 +0100 Subject: [PATCH 5/7] Round the ignore area outwards If the ignore area is specified in a way that it doesn't align with pixels precisely, it has to be rounded outwards to align to pixels; otherwise content changes inside the ignore are could be NOT ignored. --- diff-pdf.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/diff-pdf.cpp b/diff-pdf.cpp index ac5dd30..e07e803 100644 --- a/diff-pdf.cpp +++ b/diff-pdf.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -188,13 +189,12 @@ cairo_surface_t *diff_images(int page, cairo_surface_t *s1, cairo_surface_t *s2, for ( size_t i = 0; i < g_ignore_areas.size(); i++ ) { const IgnoreArea& a = g_ignore_areas[i]; - // round the edges individually (rather than rounding width/height - // separately) so the rectangle covers every pixel that the + // round the edges outward so the rectangle covers every pixel that the // rasterizer may have touched, including anti-aliased borders - const int px1 = wxRound(a.x * scale); - const int py1 = wxRound(a.y * scale); - const int px2 = wxRound((a.x + a.w) * scale); - const int py2 = wxRound((a.y + a.h) * scale); + const int px1 = int(std::floor(a.x * scale)); + const int py1 = int(std::floor(a.y * scale)); + const int px2 = int(std::ceil((a.x + a.w) * scale)); + const int py2 = int(std::ceil((a.y + a.h) * scale)); ignore_px.push_back(wxRect(px1 + r1.x, py1 + r1.y, px2 - px1, py2 - py1)); } } From 2bc61aa0369d149df5a8b911212ea1cccf4374d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Tue, 10 Nov 2026 17:28:07 +0100 Subject: [PATCH 6/7] Show ignore area rectangle even if there are no other changes Without this, it was very confusing: the page would show as no-changes, but with no indication of the rectangle in which there _might_ have been changes. This requires differentiating between "there are differences" and "there is a diff image": the former may be false while the latter is true. --- diff-pdf.cpp | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/diff-pdf.cpp b/diff-pdf.cpp index e07e803..b6df2a5 100644 --- a/diff-pdf.cpp +++ b/diff-pdf.cpp @@ -111,10 +111,20 @@ cairo_surface_t *render_page(PopplerPage *page) } +struct DiffResult +{ + // Comparison image, including annotations; may exist even without differences. + // NULL if no image is needed. The caller owns the surface. + cairo_surface_t *image; + + // Whether the pages differ under the configured ignore areas and tolerances. + bool has_differences; +}; + // Creates image of differences between s1 and s2. If the offset is specified, // then s2 is displaced by it. If thumbnail and thumbnail_width are specified, // then a thumbnail with highlighted differences is created too. -cairo_surface_t *diff_images(int page, cairo_surface_t *s1, cairo_surface_t *s2, +DiffResult diff_images(int page, cairo_surface_t *s1, cairo_surface_t *s2, int offset_x = 0, int offset_y = 0, wxImage *thumbnail = NULL, int thumbnail_width = -1) { @@ -373,8 +383,9 @@ cairo_surface_t *diff_images(int page, cairo_surface_t *s1, cairo_surface_t *s2, if ( g_verbose ) printf("page %d has %ld pixels that differ\n", page, pixel_diff_count); - // If we specified a tolerance, then return if we have exceeded that for this page - if ( g_per_page_pixel_tolerance == 0 ? changes : pixel_diff_count > g_per_page_pixel_tolerance) + const bool page_differs = g_per_page_pixel_tolerance == 0 + ? changes : pixel_diff_count > g_per_page_pixel_tolerance; + if ( page_differs || !ignore_px.empty() ) { if ( !ignore_px.empty() ) { @@ -393,18 +404,18 @@ cairo_surface_t *diff_images(int page, cairo_surface_t *s1, cairo_surface_t *s2, cairo_destroy(cr); } - return diff; + return { diff, page_differs }; } else { cairo_surface_destroy(diff); - return NULL; + return { NULL, page_differs }; } } -// Compares given two pages. If cr_out is not NULL, then the diff image (either -// differences or unmodified page, if there are no diffs) is drawn to it. +// Compares given two pages. If cr_out is not NULL, then the compared page, +// including any ignored-area outlines, is drawn to it unless skipped. // If thumbnail and thumbnail_width are specified, then a thumbnail with // highlighted differences is created too. bool page_compare(int page, cairo_t *cr_out, @@ -414,20 +425,19 @@ bool page_compare(int page, cairo_t *cr_out, cairo_surface_t *img1 = page1 ? render_page(page1) : NULL; cairo_surface_t *img2 = page2 ? render_page(page2) : NULL; - cairo_surface_t *diff = diff_images(page, img1, img2, 0, 0, + const DiffResult diff = diff_images(page, img1, img2, 0, 0, thumbnail, thumbnail_width); - const bool has_diff = (diff != NULL); - if ( cr_out ) + if ( cr_out && (diff.has_differences || !g_skip_identical) ) { - if ( diff ) + if ( diff.image ) { // render the difference as high-resolution bitmap cairo_save(cr_out); cairo_scale(cr_out, 72.0 / g_resolution, 72.0 / g_resolution); - cairo_set_source_surface(cr_out, diff ? diff : img1, 0, 0); + cairo_set_source_surface(cr_out, diff.image, 0, 0); cairo_paint(cr_out); cairo_restore(cr_out); @@ -442,19 +452,18 @@ bool page_compare(int page, cairo_t *cr_out, poppler_page_render(page1, cr_out); } - if (diff || !g_skip_identical) - cairo_show_page(cr_out); + cairo_show_page(cr_out); } - if ( diff ) - cairo_surface_destroy(diff); + if ( diff.image ) + cairo_surface_destroy(diff.image); if ( img1 ) cairo_surface_destroy(img1); if ( img2 ) cairo_surface_destroy(img2); - return !has_diff; + return !diff.has_differences; } @@ -775,7 +784,7 @@ class DiffFrame : public wxFrame cairo_surface_t *img2 = page2 ? render_page(page2) : NULL; wxImage thumbnail; - cairo_surface_t *diff = diff_images + const DiffResult diff = diff_images ( m_cur_page, img1, img2, @@ -807,7 +816,7 @@ class DiffFrame : public wxFrame case SHOW_DIFF_DOCUMENT: default: - m_viewer->Set(diff ? diff : img1); + m_viewer->Set(diff.image ? diff.image : img1); } // Always update the diff map. It will be all-white if there were @@ -818,8 +827,8 @@ class DiffFrame : public wxFrame cairo_surface_destroy(img1); if ( img2 ) cairo_surface_destroy(img2); - if ( diff ) - cairo_surface_destroy(diff); + if ( diff.image ) + cairo_surface_destroy(diff.image); UpdateStatus(); } From 1f9d4b1e168dfee914722cec159e054060f77778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Tue, 10 Nov 2026 17:34:24 +0100 Subject: [PATCH 7/7] Fix validation of --ignore-area arguments Reject empty areas, missing or extra coordinates, trailing separators, and non-finite numbers. --- diff-pdf.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/diff-pdf.cpp b/diff-pdf.cpp index b6df2a5..c333045 100644 --- a/diff-pdf.cpp +++ b/diff-pdf.cpp @@ -1146,17 +1146,21 @@ int main(int argc, char *argv[]) wxString ignore_area_str; if ( parser.Found("ignore-area", &ignore_area_str) ) { - wxStringTokenizer area_tokenizer(ignore_area_str, ";"); - while ( area_tokenizer.HasMoreTokens() ) + wxStringTokenizer area_tokenizer(ignore_area_str, ";", wxTOKEN_RET_EMPTY_ALL); + do { const wxString one_area = area_tokenizer.GetNextToken(); - wxStringTokenizer tokenizer(one_area, ","); + wxStringTokenizer tokenizer(one_area, ",", wxTOKEN_RET_EMPTY_ALL); double values[4]; bool ok = true; size_t count = 0; while ( ok && tokenizer.HasMoreTokens() && count < 4 ) - ok = tokenizer.GetNextToken().ToCDouble(&values[count++]); + { + ok = tokenizer.GetNextToken().ToCDouble(&values[count]) + && std::isfinite(values[count]); + count++; + } ok = ok && (count == 4) && !tokenizer.HasMoreTokens(); if ( !ok || values[0] < 0 || values[1] < 0 || values[2] <= 0 || values[3] <= 0 ) @@ -1171,6 +1175,7 @@ int main(int argc, char *argv[]) IgnoreArea area = { values[0], values[1], values[2], values[3] }; g_ignore_areas.push_back(area); } + while ( area_tokenizer.HasMoreTokens() ); } if ( parser.Found("channel-tolerance", &g_channel_tolerance) )