MCPcopy Create free account
hub / github.com/Tencent/tgfx / LoadImage

Function LoadImage

src/svg/node/SVGImage.cpp:53–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53std::shared_ptr<Image> LoadImage(const SVGIRI& href) {
54
55 // SVG image URLs support five protocols: http://, https://, file://, path, and base64
56 // For http, https, file, and path protocols:
57 // - http, https, and file require a registered StreamFactory
58 // - path protocol requires an absolute path
59 // - all are loaded using Image::MakeFromFile
60 // For base64 protocol:
61 // - base64 data is decoded and loaded using Image::MakeFromEncoded
62
63 switch (href.type()) {
64 case SVGIRI::Type::DataURI: {
65 const auto& base64URL = href.iri();
66 auto pos = base64URL.find("base64,");
67 if (pos == std::string::npos) {
68 return Image::MakeFromFile(base64URL);
69 }
70 std::string base64Data = base64URL.substr(pos + 7);
71 auto data = Base64Decode(base64Data);
72 return data ? Image::MakeFromEncoded(data) : nullptr;
73 }
74 case SVGIRI::Type::Nonlocal: {
75 return Image::MakeFromFile(href.iri());
76 }
77 default:
78 return nullptr;
79 }
80}
81
82SVGImage::ImageInfo SVGImage::LoadImage(const SVGIRI& iri, const Rect& viewPort) {
83 std::shared_ptr<Image> image = ::tgfx::LoadImage(iri);

Callers 2

LoadImageMethod · 0.85
onRenderMethod · 0.85

Calls 3

Base64DecodeFunction · 0.85
typeMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected