Merge branch 'master' into snapshot
This commit is contained in:
@@ -39,6 +39,10 @@ class Optimizer:
|
||||
|
||||
if (not exists_in_path(self.binaryname)) and (not exists_in_path(self.binaryname + ".exe")):
|
||||
raise Exception("Optimization program '%s' was not found!" % self.binaryname)
|
||||
|
||||
def is_crusher(self):
|
||||
"""Should return True if the optimization is lossless, i.e. none of the actual image data will be changed."""
|
||||
raise NotImplementedError("I'm so abstract I can't even say whether I'm a crusher.")
|
||||
|
||||
|
||||
class NonAtomicOptimizer(Optimizer):
|
||||
@@ -84,6 +88,9 @@ class pngnq(NonAtomicOptimizer, PNGOptimizer):
|
||||
|
||||
NonAtomicOptimizer.fire_and_forget(self, args, img)
|
||||
|
||||
def is_crusher(self):
|
||||
return False
|
||||
|
||||
class pngcrush(NonAtomicOptimizer, PNGOptimizer):
|
||||
binaryname = "pngcrush"
|
||||
# really can't be bothered to add some interface for all
|
||||
@@ -98,6 +105,9 @@ class pngcrush(NonAtomicOptimizer, PNGOptimizer):
|
||||
|
||||
NonAtomicOptimizer.fire_and_forget(self, args, img)
|
||||
|
||||
def is_crusher(self):
|
||||
return True
|
||||
|
||||
class optipng(Optimizer, PNGOptimizer):
|
||||
binaryname = "optipng"
|
||||
|
||||
@@ -106,6 +116,9 @@ class optipng(Optimizer, PNGOptimizer):
|
||||
|
||||
def optimize(self, img):
|
||||
Optimizer.fire_and_forget(self, [self.binaryname, "-o" + str(self.olevel), "-quiet", img])
|
||||
|
||||
def is_crusher(self):
|
||||
return True
|
||||
|
||||
|
||||
def optimize_image(imgpath, imgformat, optimizers):
|
||||
|
||||
@@ -160,15 +160,25 @@ def validateBGColor(color):
|
||||
def validateOptImg(optimizers):
|
||||
if isinstance(optimizers, (int, long)):
|
||||
from optimizeimages import pngcrush
|
||||
logging.warning("You're using a deprecated definition of optimizeimg. We'll do what you say for now, but please fix this as soon as possible.")
|
||||
logging.warning("You're using a deprecated definition of optimizeimg. "\
|
||||
"We'll do what you say for now, but please fix this as soon as possible.")
|
||||
optimizers = [pngcrush()]
|
||||
if not isinstance(optimizers, list):
|
||||
raise ValidationException("optimizeimg is not a list. Make sure you specify them like [foo()], with square brackets.")
|
||||
for opt in optimizers:
|
||||
if not isinstance(opt, Optimizer):
|
||||
raise ValidationException("Invalid Optimizer!")
|
||||
raise ValidationException("What you passed to optimizeimg is not a list. "\
|
||||
"Make sure you specify them like [foo()], with square brackets.")
|
||||
|
||||
opt.check_availability()
|
||||
if optimizers:
|
||||
for opt, next_opt in zip(optimizers, optimizers[1:]) + [(optimizers[-1], None)]:
|
||||
if not isinstance(opt, Optimizer):
|
||||
raise ValidationException("Invalid Optimizer!")
|
||||
|
||||
opt.check_availability()
|
||||
|
||||
# Check whether the chaining is somewhat sane
|
||||
if next_opt:
|
||||
if opt.is_crusher() and not next_opt.is_crusher():
|
||||
logging.warning("You're feeding a crushed output into an optimizer that does not crush. "\
|
||||
"This is most likely pointless, and wastes time.")
|
||||
|
||||
return optimizers
|
||||
|
||||
|
||||
@@ -161,17 +161,6 @@ class Textures(object):
|
||||
return None
|
||||
if verbose: logging.info('search_zip_paths: ' + ', '.join(search_zip_paths))
|
||||
|
||||
# we've sucessfully loaded something from here before, so let's quickly try
|
||||
# this before searching again
|
||||
if self.jar is not None:
|
||||
for jarfilename in search_zip_paths:
|
||||
try:
|
||||
self.jar.getinfo(jarfilename)
|
||||
if verbose: logging.info("Found (cached) %s in '%s'", jarfilename, self.jarpath)
|
||||
return self.jar.open(jarfilename)
|
||||
except (KeyError, IOError), e:
|
||||
pass
|
||||
|
||||
# A texture path was given on the command line. Search this location
|
||||
# for the file first.
|
||||
if self.find_file_local_path:
|
||||
@@ -227,6 +216,17 @@ class Textures(object):
|
||||
if verbose: logging.info("Did not find the file in overviewer executable directory")
|
||||
if verbose: logging.info("Looking for installed minecraft jar files...")
|
||||
|
||||
# we've sucessfully loaded something from here before, so let's quickly try
|
||||
# this before searching again
|
||||
if self.jar is not None:
|
||||
for jarfilename in search_zip_paths:
|
||||
try:
|
||||
self.jar.getinfo(jarfilename)
|
||||
if verbose: logging.info("Found (cached) %s in '%s'", jarfilename, self.jarpath)
|
||||
return self.jar.open(jarfilename)
|
||||
except (KeyError, IOError), e:
|
||||
pass
|
||||
|
||||
# Find an installed minecraft client jar and look in it for the texture
|
||||
# file we need.
|
||||
versiondir = ""
|
||||
|
||||
Reference in New Issue
Block a user