summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2020-05-14 00:28:12 +0300
committerThiago Marcos P. Santos <thiago@mapbox.com>2020-05-26 20:35:05 +0300
commit9760515d83619e011e65752743359d8917360315 (patch)
tree19710dd761dbb6e6078a6dec74645c857adc0e7b
parentcc89ece719fcb93133d3a6f33aac9c8a12a9f4a5 (diff)
downloadqtlocation-mapboxgl-9760515d83619e011e65752743359d8917360315.tar.gz
Use single channel context for drawing glyphs
Should take less memory and avoid unnecessary iteration over pixel data
-rw-r--r--platform/darwin/src/local_glyph_rasterizer.mm26
1 files changed, 9 insertions, 17 deletions
diff --git a/platform/darwin/src/local_glyph_rasterizer.mm b/platform/darwin/src/local_glyph_rasterizer.mm
index c9e0b960a2..a5bef85670 100644
--- a/platform/darwin/src/local_glyph_rasterizer.mm
+++ b/platform/darwin/src/local_glyph_rasterizer.mm
@@ -193,7 +193,7 @@ bool LocalGlyphRasterizer::canRasterizeGlyph(const FontStack&, GlyphID glyphID)
representing the codepoint.
@returns An image containing the glyph.
*/
-PremultipliedImage drawGlyphBitmap(GlyphID glyphID, CTFontRef font, GlyphMetrics& metrics) {
+AlphaImage drawGlyphBitmap(GlyphID glyphID, CTFontRef font, GlyphMetrics& metrics) {
CFStringRefHandle string(CFStringCreateWithCharacters(NULL, reinterpret_cast<UniChar*>(&glyphID), 1));
if (!string) {
throw std::runtime_error("Unable to create string from codepoint");
@@ -224,25 +224,25 @@ PremultipliedImage drawGlyphBitmap(GlyphID glyphID, CTFontRef font, GlyphMetrics
metrics.width = size.width;
metrics.height = size.height;
- PremultipliedImage rgbaBitmap(size);
+ AlphaImage bitmap(size);
- CGColorSpaceHandle colorSpace(CGColorSpaceCreateDeviceRGB());
+ CGColorSpaceHandle colorSpace(CGColorSpaceCreateDeviceGray());
if (!colorSpace) {
- throw std::runtime_error("CGColorSpaceCreateDeviceRGB failed");
+ throw std::runtime_error("CGColorSpaceCreateDeviceGray failed");
}
constexpr const size_t bitsPerComponent = 8;
- constexpr const size_t bytesPerPixel = 4;
+ constexpr const size_t bytesPerPixel = 1;
const size_t bytesPerRow = bytesPerPixel * size.width;
CGContextHandle context(CGBitmapContextCreate(
- rgbaBitmap.data.get(),
+ bitmap.data.get(),
size.width,
size.height,
bitsPerComponent,
bytesPerRow,
*colorSpace,
- kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast));
+ kCGBitmapByteOrderDefault | kCGImageAlphaOnly));
if (!context) {
throw std::runtime_error("CGBitmapContextCreate failed");
}
@@ -265,7 +265,7 @@ PremultipliedImage drawGlyphBitmap(GlyphID glyphID, CTFontRef font, GlyphMetrics
CTLineDraw(*line, *context);
- return rgbaBitmap;
+ return bitmap;
}
/**
@@ -287,15 +287,7 @@ Glyph LocalGlyphRasterizer::rasterizeGlyph(const FontStack& fontStack, GlyphID g
}
manufacturedGlyph.id = glyphID;
-
- PremultipliedImage rgbaBitmap = drawGlyphBitmap(glyphID, *font, manufacturedGlyph.metrics);
-
- Size size(manufacturedGlyph.metrics.width, manufacturedGlyph.metrics.height);
- // Copy alpha values from RGBA bitmap into the AlphaImage output
- manufacturedGlyph.bitmap = AlphaImage(size);
- for (uint32_t i = 0; i < size.width * size.height; i++) {
- manufacturedGlyph.bitmap.data[i] = rgbaBitmap.data[4 * i + 3];
- }
+ manufacturedGlyph.bitmap = drawGlyphBitmap(glyphID, *font, manufacturedGlyph.metrics);
return manufacturedGlyph;
}