0

added imgquality config file option for setting JPG quality

Original code by alexjurkiewicz, ported to new DTT code.
This closes #83.
This commit is contained in:
Aaron Griffith
2011-05-02 18:02:13 -04:00
parent c1e71f0fda
commit 4a82e749ca
2 changed files with 10 additions and 5 deletions

View File

@@ -96,7 +96,8 @@ def main():
parser.add_option("--chunklist", dest="chunklist", help="A file containing, on each line, a path to a chunkfile to update. Instead of scanning the world directory for chunks, it will just use this list. Normal caching rules still apply.") parser.add_option("--chunklist", dest="chunklist", help="A file containing, on each line, a path to a chunkfile to update. Instead of scanning the world directory for chunks, it will just use this list. Normal caching rules still apply.")
parser.add_option("--rendermodes", dest="rendermode", help="Specifies the render types, separated by commas. Use --list-rendermodes to list them all.", type="choice", choices=avail_rendermodes, required=True, default=avail_rendermodes[0], listify=True) parser.add_option("--rendermodes", dest="rendermode", help="Specifies the render types, separated by commas. Use --list-rendermodes to list them all.", type="choice", choices=avail_rendermodes, required=True, default=avail_rendermodes[0], listify=True)
parser.add_option("--list-rendermodes", dest="list_rendermodes", action="store_true", help="List available render modes and exit.", commandLineOnly=True) parser.add_option("--list-rendermodes", dest="list_rendermodes", action="store_true", help="List available render modes and exit.", commandLineOnly=True)
parser.add_option("--imgformat", dest="imgformat", help="The image output format to use. Currently supported: png(default), jpg. NOTE: png will always be used as the intermediate image format.", configFileOnly=True ) parser.add_option("--imgformat", dest="imgformat", help="The image output format to use. Currently supported: png(default), jpg.", configFileOnly=True )
parser.add_option("--imgquality", dest="imgquality", default=95, help="Specify the quality of image output when using imgformat=\"jpg\".", type="int", configFileOnly=True)
parser.add_option("--bg_color", dest="bg_color", help="Configures the background color for the GoogleMap output. Specify in #RRGGBB format", configFileOnly=True, type="string", default="#1A1A1A") parser.add_option("--bg_color", dest="bg_color", help="Configures the background color for the GoogleMap output. Specify in #RRGGBB format", configFileOnly=True, type="string", default="#1A1A1A")
parser.add_option("--optimize-img", dest="optimizeimg", help="If using png, perform image file size optimizations on the output. Specify 1 for pngcrush, 2 for pngcrush+optipng+advdef. This may double (or more) render times, but will produce up to 30% smaller images. NOTE: requires corresponding programs in $PATH or %PATH%", configFileOnly=True) parser.add_option("--optimize-img", dest="optimizeimg", help="If using png, perform image file size optimizations on the output. Specify 1 for pngcrush, 2 for pngcrush+optipng+advdef. This may double (or more) render times, but will produce up to 30% smaller images. NOTE: requires corresponding programs in $PATH or %PATH%", configFileOnly=True)
parser.add_option("--web-assets-hook", dest="web_assets_hook", help="If provided, run this function after the web assets have been copied, but before actual tile rendering begins. It should accept a QuadtreeGen object as its only argument.", action="store", metavar="SCRIPT", type="function", configFileOnly=True) parser.add_option("--web-assets-hook", dest="web_assets_hook", help="If provided, run this function after the web assets have been copied, but before actual tile rendering begins. It should accept a QuadtreeGen object as its only argument.", action="store", metavar="SCRIPT", type="function", configFileOnly=True)
@@ -220,7 +221,7 @@ def main():
# create the quadtrees # create the quadtrees
# TODO chunklist # TODO chunklist
q = [] q = []
qtree_args = {'depth' : options.zoom, 'imgformat' : imgformat, 'optimizeimg' : optimizeimg, 'bgcolor':bgcolor} qtree_args = {'depth' : options.zoom, 'imgformat' : imgformat, 'imgquality' : options.imgquality, 'optimizeimg' : optimizeimg, 'bgcolor' : bgcolor}
for rendermode in options.rendermode: for rendermode in options.rendermode:
if rendermode == 'normal': if rendermode == 'normal':
qtree = quadtree.QuadtreeGen(w, destdir, rendermode=rendermode, tiledir='tiles', **qtree_args) qtree = quadtree.QuadtreeGen(w, destdir, rendermode=rendermode, tiledir='tiles', **qtree_args)

View File

@@ -49,7 +49,7 @@ def iterate_base4(d):
return itertools.product(xrange(4), repeat=d) return itertools.product(xrange(4), repeat=d)
class QuadtreeGen(object): class QuadtreeGen(object):
def __init__(self, worldobj, destdir, bgcolor, depth=None, tiledir=None, imgformat=None, optimizeimg=None, rendermode="normal"): def __init__(self, worldobj, destdir, bgcolor, depth=None, tiledir=None, imgformat=None, imgquality=95, optimizeimg=None, rendermode="normal"):
"""Generates a quadtree from the world given into the """Generates a quadtree from the world given into the
given dest directory given dest directory
@@ -61,6 +61,7 @@ class QuadtreeGen(object):
""" """
assert(imgformat) assert(imgformat)
self.imgformat = imgformat self.imgformat = imgformat
self.imgquality = imgquality
self.optimizeimg = optimizeimg self.optimizeimg = optimizeimg
self.bgcolor = bgcolor self.bgcolor = bgcolor
self.rendermode = rendermode self.rendermode = rendermode
@@ -336,7 +337,7 @@ class QuadtreeGen(object):
# Save it # Save it
if self.imgformat == 'jpg': if self.imgformat == 'jpg':
img.save(imgpath, quality=95, subsampling=0) img.save(imgpath, quality=self.imgquality, subsampling=0)
else: # png else: # png
img.save(imgpath) img.save(imgpath)
@@ -463,7 +464,10 @@ class QuadtreeGen(object):
pass pass
# Save them # Save them
tileimg.save(imgpath) if self.imgformat == 'jpg':
tileimg.save(imgpath, quality=self.imgquality, subsampling=0)
else: # png
tileimg.save(imgpath)
if self.optimizeimg: if self.optimizeimg:
optimize_image(imgpath, self.imgformat, self.optimizeimg) optimize_image(imgpath, self.imgformat, self.optimizeimg)