Skip to content

Commit 82f6a19

Browse files
fatalmindvslavik
authored andcommitted
Introduce parameter --channel-tolerance to ignore difference within a threshold
1 parent 6741ab9 commit 82f6a19

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

diff-pdf.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
// ------------------------------------------------------------------------
4848

4949
bool g_verbose = false;
50+
long g_channel_tolerance = 0;
5051

5152
// Resolution to use for rasterization, in DPI
5253
#define RESOLUTION 300
@@ -189,7 +190,11 @@ cairo_surface_t *diff_images(cairo_surface_t *s1, cairo_surface_t *s2,
189190
unsigned char cg2 = *(data2 + x + 1);
190191
unsigned char cb2 = *(data2 + x + 2);
191192

192-
if ( cr1 != cr2 || cg1 != cg2 || cb1 != cb2 )
193+
194+
if ( cr1 > (cr2+g_channel_tolerance) || cr2 < (cr2-g_channel_tolerance)
195+
|| cg1 > (cg2+g_channel_tolerance) || cg2 < (cg2-g_channel_tolerance)
196+
|| cb1 > (cb2+g_channel_tolerance) || cb2 < (cb2-g_channel_tolerance)
197+
)
193198
{
194199
changes = true;
195200
if ( thumbnail )
@@ -863,6 +868,10 @@ int main(int argc, char *argv[])
863868
NULL, wxT28("output-diff"), wxT28("output differences to given PDF file"),
864869
wxCMD_LINE_VAL_STRING },
865870

871+
{ wxCMD_LINE_OPTION,
872+
NULL, wxT28("channel-tolerance"), wxT28("consider channel values to be equal if within specified tolerance"),
873+
wxCMD_LINE_VAL_NUMBER },
874+
866875
{ wxCMD_LINE_SWITCH,
867876
NULL, wxT28("view"), wxT28("view the differences in a window") },
868877

@@ -919,6 +928,15 @@ int main(int argc, char *argv[])
919928
return 3;
920929
}
921930

931+
if ( parser.Found(wxT("channel-tolerance"), &g_channel_tolerance) )
932+
{
933+
if (g_channel_tolerance < 0 || g_channel_tolerance > 255) {
934+
fprintf(stderr, "Invalid channel-tolerance: %ld. Valid range is 0(default, exact matching)-255\n", g_channel_tolerance);
935+
return 2;
936+
}
937+
}
938+
939+
922940
int retval = 0;
923941

924942
wxString pdf_file;

0 commit comments

Comments
 (0)