MCPcopy Create free account
hub / github.com/comaps/comaps / LoadSymbols

Function LoadSymbols

libs/drape/symbols_texture.cpp:121–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119};
120
121void LoadSymbols(std::string const & skinPathName, std::string const & textureName, bool convertToUV,
122 TDefinitionInserter const & definitionInserter, TSymbolsLoadingCompletion const & completionHandler,
123 TSymbolsLoadingFailure const & failureHandler)
124{
125 ASSERT(definitionInserter != nullptr, ());
126 ASSERT(completionHandler != nullptr, ());
127 ASSERT(failureHandler != nullptr, ());
128
129 std::vector<unsigned char> rawData;
130 uint32_t width, height;
131
132 try
133 {
134 DefinitionLoader loader(definitionInserter, convertToUV);
135
136 {
137 ReaderPtr<Reader> reader = GetStyleReader().GetResourceReader(textureName + ".sdf", skinPathName);
138 ReaderSource<ReaderPtr<Reader>> source(reader);
139 if (!ParseXML(source, loader))
140 {
141 failureHandler("Error parsing skin");
142 return;
143 }
144
145 width = loader.GetWidth();
146 height = loader.GetHeight();
147 }
148
149 {
150 ReaderPtr<Reader> reader = GetStyleReader().GetResourceReader(textureName + ".png", skinPathName);
151 size_t const size = static_cast<size_t>(reader.Size());
152 rawData.resize(size);
153 reader.Read(0, &rawData[0], size);
154 }
155 }
156 catch (RootException & e)
157 {
158 failureHandler(e.what());
159 return;
160 }
161
162 int w, h, bpp;
163 unsigned char * data = stbi_load_from_memory(&rawData[0], static_cast<int>(rawData.size()), &w, &h, &bpp, 0);
164 ASSERT_EQUAL(bpp, 4, ("Incorrect symbols texture format"));
165 ASSERT(glm::isPowerOfTwo(w), (w));
166 ASSERT(glm::isPowerOfTwo(h), (h));
167
168 if (width == static_cast<uint32_t>(w) && height == static_cast<uint32_t>(h))
169 completionHandler(data, width, height);
170 else
171 failureHandler("Error symbols texture creation");
172
173 stbi_image_free(data);
174}
175} // namespace
176
177SymbolsTexture::SymbolKey::SymbolKey(std::string const & symbolName) : m_symbolName(symbolName) {}

Callers 1

LoadMethod · 0.85

Calls 12

ASSERTFunction · 0.85
ParseXMLFunction · 0.85
stbi_load_from_memoryFunction · 0.85
stbi_image_freeFunction · 0.85
GetResourceReaderMethod · 0.80
GetWidthMethod · 0.45
GetHeightMethod · 0.45
SizeMethod · 0.45
resizeMethod · 0.45
ReadMethod · 0.45
whatMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected