MCPcopy Create free account
hub / github.com/Snapchat/Valdi / render

Method render

libs/image_toolbox/src/image_toolbox/SVGRenderer.cpp:84–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82}
83
84Valdi::Result<snap::drawing::Ref<snap::drawing::Image>> SVGRenderer::render(const Valdi::Byte* data,
85 size_t length,
86 int outputWidth,
87 int outputHeight) {
88 ReSVG reSVG;
89 auto result = reSVG.parse(data, length);
90 if (!result) {
91 return result.moveError();
92 }
93
94 auto svgSize = result.value()->getSize();
95
96 int surfaceWidth;
97 if (outputWidth > 0) {
98 surfaceWidth = outputWidth;
99 } else {
100 surfaceWidth = svgSize.first;
101 }
102
103 int surfaceHeight;
104 if (outputHeight > 0) {
105 surfaceHeight = outputHeight;
106 } else {
107 surfaceHeight = svgSize.second;
108 }
109
110 auto outputBitmapResult = snap::drawing::Bitmap::make(Valdi::BitmapInfo(
111 surfaceWidth, surfaceHeight, Valdi::ColorType::ColorTypeRGBA8888, Valdi::AlphaType::AlphaTypePremul, 0));
112 if (!outputBitmapResult) {
113 return outputBitmapResult.error().rethrow("Failed to create output bitmap: ");
114 }
115
116 auto outputBitmap = outputBitmapResult.moveValue();
117
118 auto* outputBytes = outputBitmap->lockBytes();
119
120 auto transform = resvg_transform_identity();
121 auto scale = std::max(static_cast<float>(surfaceWidth) / static_cast<float>(svgSize.first),
122 static_cast<float>(surfaceHeight) / static_cast<float>(svgSize.second));
123 transform.a = scale;
124 transform.d = scale;
125
126 resvg_render(result.value()->tree(),
127 transform,
128 static_cast<uint32_t>(surfaceWidth),
129 static_cast<uint32_t>(surfaceHeight),
130 reinterpret_cast<char*>(outputBytes));
131 outputBitmap->unlockBytes();
132
133 return snap::drawing::Image::makeFromBitmap(outputBitmap, false);
134}
135
136} // namespace snap::imagetoolbox

Callers

nothing calls this directly

Calls 10

maxFunction · 0.85
rethrowMethod · 0.80
treeMethod · 0.80
valueMethod · 0.65
errorMethod · 0.65
BitmapInfoClass · 0.50
parseMethod · 0.45
getSizeMethod · 0.45
lockBytesMethod · 0.45
unlockBytesMethod · 0.45

Tested by

no test coverage detected