[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] gsoc-2019-veeki 737bca1 1/3: Gamma Correction added
From: |
Veeki Yadav |
Subject: |
[freetype2-demos] gsoc-2019-veeki 737bca1 1/3: Gamma Correction added |
Date: |
Wed, 26 Jun 2019 18:06:41 -0400 (EDT) |
branch: gsoc-2019-veeki
commit 737bca1a11320525feab33845b27fd3674e57314
Author: gevic <address@hidden>
Commit: gevic <address@hidden>
Gamma Correction added
---
src/ftinspect/maingui.cpp | 3 +++
src/ftinspect/rendering/glyphbitmap.cpp | 20 ++++++++++++++++----
src/ftinspect/rendering/glyphbitmap.hpp | 2 ++
3 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/src/ftinspect/maingui.cpp b/src/ftinspect/maingui.cpp
index a748ef3..cc7d6d0 100644
--- a/src/ftinspect/maingui.cpp
+++ b/src/ftinspect/maingui.cpp
@@ -831,6 +831,7 @@ MainGUI::drawGlyph()
currentGlyphBitmapItem = new GlyphBitmap(outline,
engine->library,
pixelMode,
+ (gammaSlider->value()/10.0),
monoColorTable,
grayColorTable);
glyphScene->addItem(currentGlyphBitmapItem);
@@ -1222,6 +1223,8 @@ MainGUI::createConnections()
SLOT(drawGlyph()));
connect(showOutlinesCheckBox, SIGNAL(clicked()),
SLOT(drawGlyph()));
+ connect(gammaSlider, SIGNAL(valueChanged(int)),
+ SLOT(drawGlyph()));
connect(sizeDoubleSpinBox, SIGNAL(valueChanged(double)),
SLOT(drawGlyph()));
diff --git a/src/ftinspect/rendering/glyphbitmap.cpp
b/src/ftinspect/rendering/glyphbitmap.cpp
index 4ed4dbe..eae5fba 100644
--- a/src/ftinspect/rendering/glyphbitmap.cpp
+++ b/src/ftinspect/rendering/glyphbitmap.cpp
@@ -13,10 +13,12 @@
GlyphBitmap::GlyphBitmap(FT_Outline* outline,
FT_Library lib,
FT_Pixel_Mode pxlMode,
+ double gammaVal,
const QVector<QRgb>& monoColorTbl,
const QVector<QRgb>& grayColorTbl)
: library(lib),
pixelMode(pxlMode),
+ gamma(gammaVal),
monoColorTable(monoColorTbl),
grayColorTable(grayColorTbl)
{
@@ -62,6 +64,11 @@ GlyphBitmap::paint(QPainter* painter,
{
FT_Bitmap bitmap;
+ if ( gamma <= 0 ) // special case for sRGB
+ {
+ gamma = 2.4;
+ }
+
int height = static_cast<int>(ceil(bRect.height()));
int width = static_cast<int>(ceil(bRect.width()));
QImage::Format format = QImage::Format_Indexed8;
@@ -112,14 +119,19 @@ GlyphBitmap::paint(QPainter* painter,
{
// be careful not to lose the alpha channel
QRgb p = image.pixel(x, y);
+ const double r = qRed(p) / 255.0;
+ const double g = qGreen(p) / 255.0;
+ const double b = qBlue(p) / 255.0;
+ const double a = qAlpha(p) / 255.0;
painter->fillRect(QRectF(x + bRect.left() - 1 / lod / 2,
y + bRect.top() - 1 / lod / 2,
1 + 1 / lod,
1 + 1 / lod),
- QColor(qRed(p),
- qGreen(p),
- qBlue(p),
- qAlpha(p)));
+ QColor(
+ 255 * std::pow(r, 1/gamma),
+ 255 * std::pow(g, 1/gamma),
+ 255 * std::pow(b, 1/gamma),
+ 255 * std::pow(a, 1/gamma)));
}
#endif
}
diff --git a/src/ftinspect/rendering/glyphbitmap.hpp
b/src/ftinspect/rendering/glyphbitmap.hpp
index 3a77417..449bcd8 100644
--- a/src/ftinspect/rendering/glyphbitmap.hpp
+++ b/src/ftinspect/rendering/glyphbitmap.hpp
@@ -20,6 +20,7 @@ public:
GlyphBitmap(FT_Outline* outline,
FT_Library library,
FT_Pixel_Mode pixelMode,
+ double gamma,
const QVector<QRgb>& monoColorTable,
const QVector<QRgb>& grayColorTable);
~GlyphBitmap();
@@ -32,6 +33,7 @@ private:
FT_Outline transformed;
FT_Library library;
unsigned char pixelMode;
+ double gamma;
const QVector<QRgb>& monoColorTable;
const QVector<QRgb>& grayColorTable;
QRectF bRect;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] gsoc-2019-veeki 737bca1 1/3: Gamma Correction added,
Veeki Yadav <=