1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
#!/usr/bin/env python
# Copyright (C) 2001-2020 Artifex Software, Inc.
# All Rights Reserved.
#
# This software is provided AS-IS with no warranty, either express or
# implied.
#
# This software is distributed under license and may not be copied,
# modified or distributed except as expressly authorized under the terms
# of the license contained in the file LICENSE in this distribution.
#
# Refer to licensing information at http://www.artifex.com or contact
# Artifex Software, Inc., 1305 Grant Avenue - Suite 200, Novato,
# CA 94945, U.S.A., +1(415)492-9861, for further information.
#
#
# gscheck_fuzzypdf.py
#
# does a fuzzy compare against the output of ps->raster and ps->pdf->raster
# to make sure that the pdfwrite device is functioning as expected
import os
import string
import gstestutils
import gsconf, gstestgs, gsparamsets
def fuzzy_compare(file1, file2, tolerance=2, windowsize=5):
cmd = gsconf.fuzzy + ' -w%d -t%d %s %s > /dev/null 2> /dev/null' % (windowsize, tolerance, file1, file2)
ret = os.system(cmd)
if ret == 0:
return 1
else:
return 0
class GSFuzzyCompareTestCase(gstestgs.GhostscriptTestCase):
def shortDescription(self):
return "Checking pdfwrite fuzzy test of %s (%s/%d/%d)" % (self.file[string.rindex(self.file, '/') + 1:], self.device, self.dpi, self.band)
def runTest(self):
file1 = '%s.%s.%d.%d' % (self.file, self.device, self.dpi, self.band)
file2 = '%s.%s.%d.%d.pdf' % (self.file, 'pdfwrite', self.dpi, self.band)
file3 = '%s.pdfwrite.%s.%d.%d' % (self.file, self.device, self.dpi, self.band)
gs = gstestgs.Ghostscript()
gs.command = self.gs
gs.dpi = self.dpi
gs.band = self.band
gs.infile = self.file
gs.device = self.device
if self.log_stdout:
gs.log_stdout = self.log_stdout
if self.log_stderr:
gs.log_stderr = self.log_stderr
# do PostScript->device (pbmraw, pgmraw, ppmraw, pkmraw)
gs.outfile = file1
if not gs.process():
self.fail("non-zero exit code trying to rasterize " + self.file)
# do PostScript->pdfwrite
gs.device = 'pdfwrite'
gs.dpi = None
gs.outfile = file2
if not gs.process():
self.fail("non-zero exit code trying to distill " + self.file)
# do PDF->device (pbmraw, pgmraw, ppmraw, pkmraw)
gs.device = self.device
gs.dpi = self.dpi
gs.infile = file2
gs.outfile = file3
if not gs.process():
self.fail("non-zero exit code trying to rasterize " + file2)
# fuzzy compare PostScript->device with PostScript->PDF->device
ret = fuzzy_compare(file1, file3)
os.unlink(file1)
os.unlink(file2)
os.unlink(file3)
self.assert_(ret, "fuzzy match failed")
# Add the tests defined in this file to a suite
def add_compare_test(suite, f, device, dpi, band):
suite.addTest(GSFuzzyCompareTestCase(gsroot, file=gsconf.comparefiledir + f, device=device, dpi=dpi, band=band))
def addTests(suite, gsroot, **args):
# get a list of test files
comparefiles = os.listdir(gsconf.comparefiledir)
for testfile in comparefiles:
# this comparison is not good...
if testfile[-3:] == '.ps':
for params in gsparamsets.testparamsets:
add_compare_test(suite, gsroot,testfile, params.device, params.resolution, params.banding)
if __name__ == "__main__":
gstestutils.gsRunTestsMain(addTests)
|