Charlie Jiang pushed to branch ftinspect-grayscale at FreeType / FreeType Demo Programs
Commits:
-
b33c0ecf
by Charlie Jiang at 2023-03-03T09:52:15+01:00
-
027f08ee
by Charlie Jiang at 2023-03-07T13:22:37+08:00
2 changed files:
Changes:
... | ... | @@ -136,14 +136,33 @@ RenderingEngine::convertGlyphToBitmapGlyph(FT_Glyph src, |
136 | 136 | FT_Bitmap
|
137 | 137 | RenderingEngine::convertBitmapTo8Bpp(FT_Bitmap* bitmap)
|
138 | 138 | {
|
139 | - FT_Bitmap out;
|
|
140 | - out.buffer = NULL;
|
|
139 | + FT_Bitmap out = {};
|
|
141 | 140 | // This will create a new bitmap object.
|
142 | 141 | auto error = FT_Bitmap_Convert(engine_->ftLibrary(), bitmap, &out, 1);
|
143 | 142 | if (error)
|
144 | 143 | {
|
145 | 144 | // XXX handling?
|
146 | 145 | }
|
146 | + |
|
147 | + if (out.num_grays == 256)
|
|
148 | + return out;
|
|
149 | + |
|
150 | + // Scale gray values, too.
|
|
151 | + auto buf = reinterpret_cast<uint32_t*>(out.buffer);
|
|
152 | + uint32_t scale = 255U / (out.num_grays - 1);
|
|
153 | + |
|
154 | + // Four bytes at a time.
|
|
155 | + unsigned i = 0;
|
|
156 | + unsigned size = std::abs(out.pitch) * out.rows;
|
|
157 | + for (; i <= size - 4; i += 4, buf++)
|
|
158 | + *buf *= scale;
|
|
159 | + |
|
160 | + // The remaining bytes.
|
|
161 | + for (; i < size; i++ )
|
|
162 | + out.buffer[i] *= scale;
|
|
163 | + |
|
164 | + out.num_grays = 256;
|
|
165 | + |
|
147 | 166 | return out;
|
148 | 167 | }
|
149 | 168 | |
... | ... | @@ -167,7 +186,7 @@ RenderingEngine::convertBitmapToQImage(FT_Bitmap* src) |
167 | 186 | {
|
168 | 187 | QImage* result = NULL;
|
169 | 188 | |
170 | - auto& bmap = *src;
|
|
189 | + auto bmap = *src;
|
|
171 | 190 | bool ownBitmap = false; // If true, we need to clean up `bmap`.
|
172 | 191 | |
173 | 192 | int width = INT_MAX;
|
... | ... | @@ -552,6 +552,8 @@ GlyphContinuous::drawCacheGlyph(QPainter* painter, |
552 | 552 | const GlyphCacheEntry& entry,
|
553 | 553 | bool colorInverted)
|
554 | 554 | {
|
555 | + if (!entry.image)
|
|
556 | + return;
|
|
555 | 557 | // From `ftview.c:557`.
|
556 | 558 | // Well, metrics are also part of the cache...
|
557 | 559 | int width = entry.advance.x ? entry.advance.x >> 16
|