MCPcopy Create free account
hub / github.com/LibreSprite/LibreSprite / getPNGData

Function getPNGData

src/app/script/api/image_script.cpp:84–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82 }
83
84 std::string getPNGData() {
85 auto w = img()->width();
86 auto h = img()->height();
87 std::shared_ptr<she::Surface> surface{
88 she::instance()->createRgbaSurface(w, h),
89 [](auto s) {s->dispose();}
90 };
91 if (!surface)
92 return "";
93
94 for (auto y = 0; y < h; ++y) {
95 for (auto x = 0; x < w; ++x) {
96 surface->putPixel(img()->getPixel(x, y), x, y);
97 }
98 }
99
100 std::string encoded;
101 base::encode_base64(she::instance()->encodeSurfaceAsPNG(surface.get()), encoded);
102 return "data:image/png;base64," + encoded;
103 }
104
105 void putPixel(int x, int y, int color) {
106 if (unsigned(x) < unsigned(img()->width()) && unsigned(y) < unsigned(img()->height()))

Callers

nothing calls this directly

Calls 11

imgFunction · 0.85
instanceFunction · 0.85
encode_base64Function · 0.85
createRgbaSurfaceMethod · 0.80
encodeSurfaceAsPNGMethod · 0.80
widthMethod · 0.45
heightMethod · 0.45
disposeMethod · 0.45
putPixelMethod · 0.45
getPixelMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected