diff options
author | Paweł Jastrzębski <pawelj@vulturis.eu> | 2013-12-04 18:30:19 +0100 |
---|---|---|
committer | Paweł Jastrzębski <pawelj@vulturis.eu> | 2013-12-04 18:30:19 +0100 |
commit | 572e1422bf08bc0b580548c86cfdf7fbac81d070 (patch) | |
tree | f041e4726bba7886beb6647b6a61cc66d7f2e4c6 /kcc/image.py | |
parent | Update README.md (diff) | |
download | kcc-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-x | kcc/image.py | 29 |
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 |