about summary refs log tree commit diff
path: root/kcc/image.py
diff options
context:
space:
mode:
authorPaweł Jastrzębski <pawelj@vulturis.eu>2013-12-04 18:30:19 +0100
committerPaweł Jastrzębski <pawelj@vulturis.eu>2013-12-04 18:30:19 +0100
commit572e1422bf08bc0b580548c86cfdf7fbac81d070 (patch)
treef041e4726bba7886beb6647b6a61cc66d7f2e4c6 /kcc/image.py
parentUpdate README.md (diff)
downloadkcc-572e1422bf08bc0b580548c86cfdf7fbac81d070.tar.gz
kcc-572e1422bf08bc0b580548c86cfdf7fbac81d070.tar.bz2
kcc-572e1422bf08bc0b580548c86cfdf7fbac81d070.zip
Gamma auto mode is now even more automatic
Diffstat (limited to 'kcc/image.py')
-rwxr-xr-xkcc/image.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/kcc/image.py b/kcc/image.py
index 3c80d74..3e848c3 100755
--- a/kcc/image.py
+++ b/kcc/image.py
@@ -214,6 +214,8 @@ class ComicPage:
     def optimizeImage(self, gamma):
         if gamma < 0.1:
             gamma = self.gamma
+            if self.gamma != 1.0 and self.isImageColor(self.image):
+                gamma = 1.0
         if gamma == 1.0:
             self.image = ImageOps.autocontrast(self.image)
         else:
@@ -519,4 +521,29 @@ class ComicPage:
             if fill > 0:
                 self.fill = 'black'
             else:
-                self.fill = 'white'
\ No newline at end of file
+                self.fill = 'white'
+
+    def isImageColor(self, image):
+        v = ImageStat.Stat(image).var
+        isMonochromatic = reduce(lambda x, y: x and y < 0.005, v, True)
+        if isMonochromatic:
+            # Monochromatic
+            return False
+        else:
+            if len(v) == 3:
+                maxmin = abs(max(v) - min(v))
+                if maxmin > 1000:
+                    # Color
+                    return True
+                elif maxmin > 100:
+                    # Probably color
+                    return True
+                else:
+                    # Grayscale
+                    return False
+            elif len(v) == 1:
+                # Black and white
+                return False
+            else:
+                # Detection failed
+                return False