bool OsmAnd::MapPresentationEnvironment_P::obtainIconShield(const QString& name, std::shared_ptr<const SkBitmap>& outIconShield) const { QMutexLocker scopedLocker(&_iconShieldsMutex); auto itIconShield = _iconShields.constFind(name); if (itIconShield == _iconShields.cend()) { const auto bitmapPath = QString::fromLatin1("map/shields/%1.png").arg(name); // Get data from embedded resources auto data = obtainResourceByName(bitmapPath); // Decode data const std::shared_ptr<SkBitmap> bitmap(new SkBitmap()); SkMemoryStream dataStream(data.constData(), data.length(), false); if (!SkImageDecoder::DecodeStream(&dataStream, bitmap.get(), SkColorType::kUnknown_SkColorType, SkImageDecoder::kDecodePixels_Mode)) return false; itIconShield = _iconShields.insert(name, bitmap); } outIconShield = *itIconShield; return true; }
bool OsmAnd::RasterizerEnvironment_P::obtainTextShield( const QString& name, std::shared_ptr<const SkBitmap>& outTextShield ) const { QMutexLocker scopedLock(&_textShieldsMutex); auto itTextShield = _textShields.constFind(name); if(itTextShield == _textShields.cend()) { const auto bitmapPath = QString::fromLatin1("map/shields/%1.png").arg(name); // Get data from embedded resources auto data = obtainResourceByName(bitmapPath); // Decode data auto bitmap = new SkBitmap(); SkMemoryStream dataStream(data.constData(), data.length(), false); if(!SkImageDecoder::DecodeStream(&dataStream, bitmap, SkBitmap::Config::kNo_Config, SkImageDecoder::kDecodePixels_Mode)) return false; itTextShield = _textShields.insert(name, std::shared_ptr<const SkBitmap>(bitmap)); } outTextShield = *itTextShield; return true; }
bool OsmAnd::MapPresentationEnvironment_P::obtainShaderBitmap(const QString& name, std::shared_ptr<const SkBitmap>& outShaderBitmap) const { QMutexLocker scopedLocker(&_shadersBitmapsMutex); auto itShaderBitmap = _shadersBitmaps.constFind(name); if (itShaderBitmap == _shadersBitmaps.cend()) { const auto shaderBitmapPath = QString::fromLatin1("map/shaders/%1.png").arg(name); // Get data from embedded resources const auto data = obtainResourceByName(shaderBitmapPath); // Decode bitmap for a shader const std::shared_ptr<SkBitmap> bitmap(new SkBitmap()); SkMemoryStream dataStream(data.constData(), data.length(), false); if (!SkImageDecoder::DecodeStream(&dataStream, bitmap.get(), SkColorType::kUnknown_SkColorType, SkImageDecoder::kDecodePixels_Mode)) return false; itShaderBitmap = _shadersBitmaps.insert(name, bitmap); } // Create shader from that bitmap outShaderBitmap = *itShaderBitmap; return true; }
bool OsmAnd::RasterizerEnvironment_P::obtainBitmapShader( const QString& name, SkBitmapProcShader* &outShader ) const { QMutexLocker scopedLock(&_shadersBitmapsMutex); auto itShaderBitmap = _shadersBitmaps.constFind(name); if(itShaderBitmap == _shadersBitmaps.cend()) { const auto shaderBitmapPath = QString::fromLatin1("map/shaders/%1.png").arg(name); // Get data from embedded resources const auto data = obtainResourceByName(shaderBitmapPath); // Decode bitmap for a shader auto shaderBitmap = new SkBitmap(); SkMemoryStream dataStream(data.constData(), data.length(), false); if(!SkImageDecoder::DecodeStream(&dataStream, shaderBitmap, SkBitmap::Config::kNo_Config, SkImageDecoder::kDecodePixels_Mode)) return false; itShaderBitmap = _shadersBitmaps.insert(name, std::shared_ptr<SkBitmap>(shaderBitmap)); } // Create shader from that bitmap outShader = new SkBitmapProcShader(*itShaderBitmap->get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); return true; }