riuson / lcd-image-converter

Tool to create bitmaps and fonts for embedded applications, v.2
https://lcd-image-converter.riuson.com/
GNU General Public License v3.0
337 stars 80 forks source link

Font antialiasing in 16 bit colour #30

Closed riuson closed 10 years ago

riuson commented 10 years ago

From onwards....@gmail.com on August 04, 2014 11:49:22

What steps will reproduce the problem? 1. Create 100pt (also works with range of other sizes) Arial bold font in colour with antialiasing (255red on black background)

  1. Use R5G6B5 preset to convert What is the expected output? What do you see instead? Expecting to see antialiased font on LCD panel. Instead there is none, edges look jagged (except for the odd, very faint pixel where you'd expect the antialiasing) What version of the product are you using? On what operating system? 19th July Beta, on Windows 7. Please provide any additional information below. I'm assuming it has something to do with the fact I truncate bits R0 -> R2 , G0->G1 and B0-B2 to convert to 16 bit which means everything is truncated, instead of actually being rounded. Is it possible to OR bits R2 and R3 say, to produce the output R3 to give some ability to round up? I couldn't seem to set that in the matrix? Or provide the ability to create a 16bit font image before the antialiasing so it uses valid levels that won't get truncated to zero?

Fantastic bit of software by the way :-)

Original issue: http://code.google.com/p/lcd-image-converter/issues/detail?id=30

riuson commented 10 years ago

From onwards....@gmail.com on August 04, 2014 20:39:34

Changed line 475 in converterhelper.cpp to: _result = im.scaled(10_im.size(),Qt::KeepAspectRatio, Qt::FastTransformation);

so can see preview image better (could a scaling control be added to the Options-Preview dialog to make it easier to see the detail?).

Seems there is plenty of antialiasing in there, but someone my LCD panel isn't showing it. Oddly, for pure Blue text it works great on the panel, but not for pure Red or Pure Green?

riuson commented 10 years ago

From riu...@gmail.com on August 04, 2014 23:10:54

Ignored bits are truncated. Bits may be ORed: ... R3 >> 8 R2 >> 7 ...

Also, try create 16-bit font image with this modification:

diff --git a/classes/data/fontdocument.cpp b/classes/data/fontdocument.cpp
index c619d53..963a6d8 100644
--- a/classes/data/fontdocument.cpp
+++ b/classes/data/fontdocument.cpp
@@ -720,7 +720,7 @@ QImage FontDocument::drawCharacter(const QChar value, const QFont &font, const Q
         imageWidth = charWidth;
         imageHeight = charHeight;
     }
-    QImage result(imageWidth, imageHeight, QImage::Format_RGB32);
+    QImage result(imageWidth, imageHeight, QImage::Format_RGB16);

     QPainter painter(&result);
     painter.setFont(font);
@@ -736,7 +736,8 @@ QImage FontDocument::drawCharacter(const QChar value, const QFont &font, const Q
                      fontMetrics.ascent(),//+4
                      QString(value));

-    return result;
+    QImage result2 = result.convertToFormat(QImage::Format_ARGB32);
+    return result2;
 }
 //-----------------------------------------------------------------------------
 void FontDocument::mon_container_dataChanged(bool historyStateMoved)

Scale control will be added.

Status: Accepted
Owner: riu...@gmail.com

Attachment: 2014-08-05 12:04:53.png

riuson commented 10 years ago

From riu...@gmail.com on August 07, 2014 08:15:00

Please check new preview dialog. Branch 'develop': https://code.google.com/p/lcd-image-converter/source/detail?r=c84b01aa2ad13e019e7b98d772387b1a4bf30e32&name=develop

Attachment: preview3.png

riuson commented 10 years ago

From onwards....@gmail.com on August 10, 2014 19:20:55

Fantastic - I have it all working now - thanks so much for your help! It turns out there was also an unrelated bug in my embedded code which would write a pixel as black every so often which was the main cause of the missing antialiasing pixels.

However, your suggestion to change the QImage format to RGB16 seems to create better quality antialiased fonts also so keeping on using that (still experimenting here however). The extra feature you added of being able to enlarge the image in a preview window is definitely very handy however.

riuson commented 10 years ago

From riu...@gmail.com on August 19, 2014 23:33:52

Status: Fixed