PaletteOptimiser

Changeset

77:b147df07482f
2015-10-10 Paul Boddie raw files shortlog changelog graph Converted other channel operations to explicit RGB operations.
optimiser.py (file)
     1.1 --- a/optimiser.py	Sat Oct 10 14:53:29 2015 +0200
     1.2 +++ b/optimiser.py	Sat Oct 10 14:57:16 2015 +0200
     1.3 @@ -161,13 +161,15 @@
     1.4      return x >= 0 and 1 or -1
     1.5  
     1.6  def saturate_rgb(rgb, exp):
     1.7 -    return tuple([saturate_value(x, exp) for x in rgb])
     1.8 +    r, g, b = rgb
     1.9 +    return saturate_value(r, exp), saturate_value(g, exp), saturate_value(b, exp)
    1.10  
    1.11  def saturate_value(x, exp):
    1.12      return int(127.5 + sign(x - 127.5) * 127.5 * pow(abs(x - 127.5) / 127.5, exp))
    1.13  
    1.14  def amplify_rgb(rgb, exp):
    1.15 -    return tuple([amplify_value(x, exp) for x in rgb])
    1.16 +    r, g, b = rgb
    1.17 +    return amplify_value(r, exp), amplify_value(g, exp), amplify_value(b, exp)
    1.18  
    1.19  def amplify_value(x, exp):
    1.20      return int(pow(x / 255.0, exp) * 255.0)
    1.21 @@ -339,12 +341,20 @@
    1.22  
    1.23              if x < width - 1:
    1.24                  rgbn = im.getpixel((x+1, y))
    1.25 -                rgbn = tuple(map(lambda i: clip(i[0] + (i[1] - i[2]) / 4.0), zip(rgbn, rgb, value)))
    1.26 +                rgbn = (
    1.27 +                    clip(rgbn[0] + (rgb[0] - value[0]) / 4.0),
    1.28 +                    clip(rgbn[1] + (rgb[1] - value[1]) / 4.0),
    1.29 +                    clip(rgbn[2] + (rgb[2] - value[2]) / 4.0)
    1.30 +                    )
    1.31                  im.putpixel((x+1, y), rgbn)
    1.32  
    1.33              if y < height - 1:
    1.34                  rgbn = im.getpixel((x, y+1))
    1.35 -                rgbn = tuple(map(lambda i: clip(i[0] + (i[1] - i[2]) / 2.0), zip(rgbn, rgb, value)))
    1.36 +                rgbn = (
    1.37 +                    clip(rgbn[0] + (rgb[0] - value[0]) / 2.0),
    1.38 +                    clip(rgbn[1] + (rgb[1] - value[1]) / 2.0),
    1.39 +                    clip(rgbn[2] + (rgb[2] - value[2]) / 2.0)
    1.40 +                    )
    1.41                  im.putpixel((x, y+1), rgbn)
    1.42  
    1.43  def get_float(options, flag):