#include "ImmediateAtlasGenerator.h" #include namespace msdf_atlas { template GEN_FN, class AtlasStorage> ImmediateAtlasGenerator::ImmediateAtlasGenerator() : threadCount(1) { } template GEN_FN, class AtlasStorage> ImmediateAtlasGenerator::ImmediateAtlasGenerator(int width, int height) : storage(width, height), threadCount(1) { } template GEN_FN, class AtlasStorage> void ImmediateAtlasGenerator::generate(const GlyphGeometry *glyphs, int count) { int maxBoxArea = 0; for (int i = 0; i < count; ++i) { GlyphBox box = glyphs[i]; maxBoxArea = std::max(maxBoxArea, box.rect.w*box.rect.h); layout.push_back((GlyphBox &&) box); } 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 threadAttributes(threadCount); for (int i = 0; i < threadCount; ++i) { threadAttributes[i] = attributes; threadAttributes[i].config.errorCorrection.buffer = errorCorrectionBuffer.data()+i*maxBoxArea; } 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 glyphBitmap(glyphBuffer.data()+threadNo*threadBufferSize, w, h); GEN_FN(glyphBitmap, glyph, threadAttributes[threadNo]); storage.put(l, b, msdfgen::BitmapConstRef(glyphBitmap)); } return true; }, count).finish(threadCount); } template GEN_FN, class AtlasStorage> void ImmediateAtlasGenerator::rearrange(int width, int height, const Remap *remapping, int count) { for (int i = 0; i < count; ++i) { layout[remapping[i].index].rect.x = remapping[i].target.x; layout[remapping[i].index].rect.y = remapping[i].target.y; } AtlasStorage newStorage((AtlasStorage &&) storage, width, height, remapping, count); storage = (AtlasStorage &&) newStorage; } template GEN_FN, class AtlasStorage> void ImmediateAtlasGenerator::resize(int width, int height) { AtlasStorage newStorage((AtlasStorage &&) storage, width, height); storage = (AtlasStorage &&) newStorage; } template GEN_FN, class AtlasStorage> void ImmediateAtlasGenerator::setAttributes(const GeneratorAttributes &attributes) { this->attributes = attributes; } template GEN_FN, class AtlasStorage> void ImmediateAtlasGenerator::setThreadCount(int threadCount) { this->threadCount = threadCount; } template GEN_FN, class AtlasStorage> const AtlasStorage & ImmediateAtlasGenerator::atlasStorage() const { return storage; } template GEN_FN, class AtlasStorage> const std::vector & ImmediateAtlasGenerator::getLayout() const { return layout; } }