Commits

Matteo Landi  committed 5eb0e96

Fix ``quantize_color`` function.

  • Participants
  • Parent commits dd39afc

Comments (0)

Files changed (2)

         inc = 0
 
     # first map each component from the range [0, 256[ to [0, levels[:
-    #       v * (levels - 1) // 255
+    #       v * levels // 256
     # then remap values to the range of default values [0, 256[, but
     # this time instead of obtaining all the possible values, we get
     # only discrete values:
     # finally, depending on the specified mode, grab the bottom, middle
     # or top value of the result range:
     #       .. + inc
-    ret = [v * (levels - 1) // 255 * 256 // levels + inc for v in color]
+    ret = [(v * levels) // 256 * (256 // levels) + inc for v in color]
     return tuple(ret)
 
 

File test/test_osaic.py

         self.assertEquals((192, 0, 0), quantize_color(red, 4, 'bottom'))
         self.assertEquals((224, 32, 32), quantize_color(red, 4, 'middle'))
         self.assertEquals((255, 63, 63), quantize_color(red, 4, 'top'))
+        self.assertEquals((192, 64, 64), quantize_color((240, 10, 20), 2, 'middle'))