image to text: improve DOUBLE_DITHERING
authorNiki Roo <niki@nikiroo.be>
Thu, 12 Apr 2018 17:20:41 +0000 (19:20 +0200)
committerNiki Roo <niki@nikiroo.be>
Thu, 12 Apr 2018 17:20:41 +0000 (19:20 +0200)
src/be/nikiroo/utils/ui/ImageTextAwt.java

index 8fdaa866b2357aa30aec72e1ba1dff042feb7d41..4c0c82483e640d47603d3e5f75d4f1751c284bc6 100644 (file)
@@ -389,7 +389,13 @@ public class ImageTextAwt {
                                avg += getBrightness(lowerright);
                                avg /= 4;
 
-                               return getDitheringChar(avg, " ░▒▓█");
+                               // Since all the quarters are > 0.5, avg is between 0.5 and 1.0
+                               // So, expand the range of the value
+                               avg = (avg - 0.5f) * 2;
+
+                               // Do not use the " " char, as it would make a
+                               // "all quarters > 0.5" pixel go black
+                               return getDitheringChar(avg, "░▒▓█");
                        }
 
                        return '█';