Debian Codegraph @

toolbin/tests/make_two_versions

raw
1 #!/usr/bin/env python
2 # -*- Mode: python -*-
3
4 # Copyright (C) 2001-2023 Artifex Software, Inc.
5 # All Rights Reserved.
6 #
7 # This software is provided AS-IS with no warranty, either express or
8 # implied.
9 #
10 # This software is distributed under license and may not be copied,
11 # modified or distributed except as expressly authorized under the terms
12 # of the license contained in the file LICENSE in this distribution.
13 #
14 # Refer to licensing information at http://www.artifex.com or contact
15 # Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
16 # CA 94129, USA, for further information.
17 #
18
19
20 #
21 # make_two_versions <filename> [<device> [<res> [<banding>]]]
22 #
23 # this script creates two versions of the file specified
24 # one from baseline, and one from head
25 # these are appropriate for a visual diff
26
27 import gstestgs
28 import gsconf
29 import rasterdb
30 import os, sys
31 import string
32
33 if len(sys.argv) < 2:
34 print "\n usage: make_two_versions filename [ device:ppmraw [ res:72 [ banding:0 ] ] ]\n"
35 sys.exit()
36
37 file = os.path.basename(sys.argv[1])
38 if len(sys.argv) > 2:
39 device = sys.argv[2]
40 else:
41 device = 'ppmraw'
42 if len(sys.argv) > 3:
43 res = int(sys.argv[3])
44 else:
45 res = 72
46 if len(sys.argv) > 4:
47 banding = int(sys.argv[4])
48 else:
49 banding = 0
50
51 dbfile = "%s.%s.%d.%d" % (file, device, res, 0)
52 ofile = "%s.%s.baseline.pnm" % (file, device)
53
54 # check if raster for this baseline is in the database, and if so, use
55 # it instead of generating approximate raster via baselinegs
56 if rasterdb.exists(dbfile):
57 rasterdb.get_file(dbfile, output=ofile)
58 else:
59 gs = gstestgs.Ghostscript()
60 gs.command = gsconf.baselinegs
61 gs.infile = gsconf.comparefiledir + file
62 gs.outfile = ofile
63 gs.device = device
64 gs.dpi = res
65 gs.band = banding
66 gs.log_stdout = gsconf.log_stdout
67 gs.log_stderr = gsconf.log_stderr
68
69 if not gs.process():
70 print "Error occurred running baseline Ghostscript."
71 sys.exit(1)
72
73 ofile = "%s.%s.compare.pnm" % (file, device)
74
75 gs = gstestgs.Ghostscript()
76 gs.command = gsconf.comparegs
77 gs.infile = gsconf.comparefiledir + file
78 gs.outfile = ofile
79 gs.device = device
80 gs.dpi = res
81 gs.band = banding
82 gs.log_stdout = gsconf.log_stdout
83 gs.log_stderr = gsconf.log_stderr
84
85 if not gs.process():
86 print "Error occurred running compare Ghostscript."
87 sys.exit(1)