Skip to content

Commit

Permalink
Error correction buffer optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Chlumsky committed May 29, 2021
1 parent d238eec commit 0e81034
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions msdf-atlas-gen/ImmediateAtlasGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ImmediateAtlasGenerator {
AtlasStorage storage;
std::vector<GlyphBox> layout;
std::vector<T> glyphBuffer;
std::vector<byte> errorCorrectionBuffer;
GeneratorAttributes attributes;
int threadCount;

Expand Down
11 changes: 9 additions & 2 deletions msdf-atlas-gen/ImmediateAtlasGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ void ImmediateAtlasGenerator<T, N, GEN_FN, AtlasStorage>::generate(const GlyphGe
int threadBufferSize = N*maxBoxArea;
if (threadCount*threadBufferSize > (int) glyphBuffer.size())
glyphBuffer.resize(threadCount*threadBufferSize);
if (threadCount*maxBoxArea > (int) errorCorrectionBuffer.size())
errorCorrectionBuffer.resize(threadCount*maxBoxArea);
std::vector<GeneratorAttributes> threadAttributes(threadCount);
for (int i = 0; i < threadCount; ++i) {
threadAttributes[i] = attributes;
threadAttributes[i].config.errorCorrection.buffer = errorCorrectionBuffer.data()+i*maxBoxArea;
}

Workload([this, &glyphs, threadBufferSize](int i, int threadNo) -> bool {
Workload([this, glyphs, &threadAttributes, threadBufferSize](int i, int threadNo) -> bool {
const GlyphGeometry &glyph = glyphs[i];
if (!glyph.isWhitespace()) {
int l, b, w, h;
glyph.getBoxRect(l, b, w, h);
msdfgen::BitmapRef<T, N> glyphBitmap(glyphBuffer.data()+threadNo*threadBufferSize, w, h);
GEN_FN(glyphBitmap, glyph, attributes);
GEN_FN(glyphBitmap, glyph, threadAttributes[threadNo]);
storage.put(l, b, msdfgen::BitmapConstRef<T, N>(glyphBitmap));
}
return true;
Expand Down

0 comments on commit 0e81034

Please sign in to comment.