[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master 2aa1763 16/41: [ftinspect] Support LCD renderin
From: |
Werner Lemberg |
Subject: |
[freetype2-demos] master 2aa1763 16/41: [ftinspect] Support LCD rendering. |
Date: |
Mon, 3 Oct 2022 11:27:02 -0400 (EDT) |
branch: master
commit 2aa1763cbc04076bf3aa83059caabcc607e6c9c8
Author: Charlie Jiang <w@chariri.moe>
Commit: Werner Lemberg <wl@gnu.org>
[ftinspect] Support LCD rendering.
* src/ftinspect/engine/rendering.cpp, src/ftinspect/engine/rendering.hpp:
Implement `convertLCDToARGB` and `convertLCDVToARGB`.
Add `lcdUsesBGR` property.
* src/ftinspect/panels/settingpanel.cpp: Uncomment functional code.
---
src/ftinspect/engine/rendering.cpp | 88 ++++++++++++++++++++++++++++++++++-
src/ftinspect/engine/rendering.hpp | 3 ++
src/ftinspect/panels/settingpanel.cpp | 4 +-
3 files changed, 91 insertions(+), 4 deletions(-)
diff --git a/src/ftinspect/engine/rendering.cpp
b/src/ftinspect/engine/rendering.cpp
index 76f5eae..4fbb251 100644
--- a/src/ftinspect/engine/rendering.cpp
+++ b/src/ftinspect/engine/rendering.cpp
@@ -142,6 +142,20 @@ RenderingEngine::convertBitmapTo8Bpp(FT_Bitmap* bitmap)
}
+void
+convertLCDToARGB(FT_Bitmap& bitmap,
+ QImage& image,
+ bool isBGR,
+ QVector<QRgb>& colorTable);
+
+
+void
+convertLCDVToARGB(FT_Bitmap& bitmap,
+ QImage& image,
+ bool isBGR,
+ QVector<QRgb>& colorTable);
+
+
QImage*
RenderingEngine::convertBitmapToQImage(FT_Bitmap* src)
{
@@ -216,11 +230,11 @@ RenderingEngine::convertBitmapToQImage(FT_Bitmap* src)
break;
case FT_PIXEL_MODE_LCD:;
result = new QImage(width, height, format);
- //convertLCDToARGB(bmap, *result, engine_->lcdUsesBGR(), foregroundTable_);
+ convertLCDToARGB(bmap, *result, lcdUsesBGR_, foregroundTable_);
break;
case FT_PIXEL_MODE_LCD_V:;
result = new QImage(width, height, format);
- //convertLCDVToARGB(bmap, *result, engine_->lcdUsesBGR(),
foregroundTable_);
+ convertLCDVToARGB(bmap, *result, lcdUsesBGR_, foregroundTable_);
break;
}
@@ -432,4 +446,74 @@ RenderingEngine::tryDirectRenderColorLayers(int glyphIndex,
}
+void
+convertLCDToARGB(FT_Bitmap& bitmap,
+ QImage& image,
+ bool isBGR,
+ QVector<QRgb>& colorTable)
+{
+ int height = bitmap.rows;
+ int width = bitmap.width / 3;
+ int width3 = bitmap.width;
+
+ unsigned char* srcPtr = bitmap.buffer;
+ unsigned* dstPtr = reinterpret_cast<unsigned*>(image.bits());
+
+ int offR = !isBGR ? 0 : 2;
+ int offG = 1;
+ int offB = isBGR ? 0 : 2;
+ for (int i = 0; i < height; i++)
+ {
+ for (int j = 0; j < width3; j += 3)
+ {
+ unsigned char ar = srcPtr[j + offR];
+ unsigned char ag = srcPtr[j + offG];
+ unsigned char ab = srcPtr[j + offB];
+ unsigned dr = colorTable[ar] & 0xFF;
+ unsigned dg = colorTable[ag] & 0xFF;
+ unsigned db = colorTable[ab] & 0xFF;
+ *dstPtr = (0xFFu << 24) | (dr << 16) | (dg << 8) | db;
+ dstPtr++;
+ }
+ srcPtr += bitmap.pitch;
+ dstPtr += image.bytesPerLine() / 4 - width; // skip blank area
+ }
+}
+
+
+void
+convertLCDVToARGB(FT_Bitmap& bitmap,
+ QImage& image,
+ bool isBGR,
+ QVector<QRgb>& colorTable)
+{
+ int height = bitmap.rows / 3;
+ int width = bitmap.width;
+ int srcPitch = bitmap.pitch;
+
+ unsigned char* srcPtr = bitmap.buffer;
+ unsigned* dstPtr = reinterpret_cast<unsigned*>(image.bits());
+
+ int offR = !isBGR ? 0 : 2 * srcPitch;
+ int offG = srcPitch;
+ int offB = isBGR ? 0 : 2 * srcPitch;
+ for (int i = 0; i < height; i++)
+ {
+ for (int j = 0; j < width; j++)
+ {
+ unsigned char ar = srcPtr[j + offR];
+ unsigned char ag = srcPtr[j + offG];
+ unsigned char ab = srcPtr[j + offB];
+ unsigned dr = colorTable[ar] & 0xFF;
+ unsigned dg = colorTable[ag] & 0xFF;
+ unsigned db = colorTable[ab] & 0xFF;
+ *dstPtr = (0xFFu << 24) | (dr << 16) | (dg << 8) | db;
+ dstPtr++;
+ }
+ srcPtr += 3ull * srcPitch; // move 3 lines
+ dstPtr += image.bytesPerLine() / 4 - width; // skip blank area
+ }
+}
+
+
// end of rendering.cpp
diff --git a/src/ftinspect/engine/rendering.hpp
b/src/ftinspect/engine/rendering.hpp
index 6dcedf0..c7e44b2 100644
--- a/src/ftinspect/engine/rendering.hpp
+++ b/src/ftinspect/engine/rendering.hpp
@@ -19,6 +19,7 @@ public:
void setBackground(QRgb background);
void setGamma(double gamma);
void calculateForegroundTable();
+ void setLCDUsesBGR(bool isBGR) { lcdUsesBGR_ = isBGR; }
QRgb foreground() { return foregroundColor_; }
QRgb background() { return backgroundColor_; }
@@ -54,6 +55,8 @@ private:
QRgb foregroundColor_;
double gamma_;
QVector<QRgb> foregroundTable_;
+
+ bool lcdUsesBGR_;
};
diff --git a/src/ftinspect/panels/settingpanel.cpp
b/src/ftinspect/panels/settingpanel.cpp
index f07691c..359410e 100644
--- a/src/ftinspect/panels/settingpanel.cpp
+++ b/src/ftinspect/panels/settingpanel.cpp
@@ -382,8 +382,8 @@ SettingPanel::applySettings()
engine_->setPaletteIndex(paletteComboBox_->currentIndex());
engine_->setUseColorLayer(colorLayerCheckBox_->isChecked());
- //engine_->setLCDUsesBGR(aaSettings.isBGR);
- //engine_->setLCDSubPixelPositioning(
+ engine_->renderingEngine()->setLCDUsesBGR(aaSettings.isBGR);
+ //engine_->renderingEngine()->setLCDSubPixelPositioning(
// antiAliasingComboBox_->currentIndex()
// == AntiAliasingComboBoxModel::AntiAliasing_Light_SubPixel);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master 2aa1763 16/41: [ftinspect] Support LCD rendering.,
Werner Lemberg <=