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

Function ImageScriptObject

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

Source from the content-addressed store, hash-verified

16class ImageScriptObject : public script::ScriptObject {
17public:
18 ImageScriptObject() {
19 addProperty("width", [this]{return img()->width();})
20 .doc("read-only. The width of the image.");
21
22 addProperty("height", [this]{return img()->height();})
23 .doc("read-only. The height of the image.");
24
25 addProperty("stride", [this]{return img()->getRowStrideSize();})
26 .doc("read-only. The number of bytes per image row.");
27
28 addProperty("format", [this]{return (int) img()->pixelFormat();})
29 .doc("read-only. The PixelFormat of the image.");
30
31 addFunction("getPixel", [this](int x, int y){return img()->getPixel(x, y);})
32 .doc("reads a color from the given coordinate of the image.")
33 .docArg("x", "integer")
34 .docArg("y", "integer")
35 .docReturns("a color value");
36
37 addMethod("putPixel", &ImageScriptObject::putPixel)
38 .doc("writes the color onto the image at the the given coordinate.")
39 .docArg("x", "integer")
40 .docArg("y", "integer")
41 .docArg("color", "a 32-bit color in 8888 RGBA format.");
42
43 addMethod("clear", &ImageScriptObject::clear)
44 .doc("clears the image with the specified color.")
45 .docArg("color", "a 32-bit color in 8888 RGBA format.");
46
47 addMethod("putImageData", &ImageScriptObject::putImageData)
48 .doc("writes the given pixels onto the image. Must be the same size as the image.")
49 .docArg("data", "All of the pixels in the image.");
50
51 addMethod("getImageData", &ImageScriptObject::getImageData)
52 .doc("creates an array containing all of the image's pixels.")
53 .docReturns("All pixels in a Uint8Array");
54
55 addMethod("getPNGData", &ImageScriptObject::getPNGData)
56 .doc("Encodes the image as a PNG.")
57 .docReturns("The image as a Base64-encoded PNG string.");
58 }
59
60 doc::Image* img() {
61 auto img = handle<doc::Object, doc::Image>();

Callers

nothing calls this directly

Calls 7

imgFunction · 0.85
getRowStrideSizeMethod · 0.80
docMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45
pixelFormatMethod · 0.45
getPixelMethod · 0.45

Tested by

no test coverage detected