MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / GetDataFromBufferLikeObject

Function GetDataFromBufferLikeObject

src/openrct2-ui/scripting/CustomImages.cpp:205–235  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

203 }
204
205 static std::vector<uint8_t> GetDataFromBufferLikeObject(JSContext* ctx, JSValue data)
206 {
207 std::vector<uint8_t> result;
208 if (JS_IsArray(data))
209 {
210 // From array of numbers
211 int64_t arrSz = 0;
212 JS_GetLength(ctx, data, &arrSz);
213 if (arrSz > 0)
214 {
215 result.reserve(arrSz);
216 JSIterateArray(ctx, data, [&result](JSContext* ctx2, JSValue val) { result.push_back(JSToInt(ctx2, val)); });
217 }
218 }
219 else if (JS_IsString(data))
220 {
221 std::string str = JSToStdString(ctx, data);
222 result = base64::decode_into<std::vector<uint8_t>>(str);
223 }
224 else if (JS_GetTypedArrayType(data) == JSTypedArrayEnum::JS_TYPED_ARRAY_UINT8)
225 {
226 // From Uint8Array
227 size_t sz = 0;
228 uint8_t* arr = JS_GetUint8Array(ctx, &sz, data);
229 if (arr)
230 {
231 result = std::vector<uint8_t>(arr, arr + sz);
232 }
233 }
234 return result;
235 }
236
237 static std::vector<uint8_t> RemovePadding(const std::vector<uint8_t>& srcData, const PixelData& pixelData)
238 {

Callers 1

GetBufferFromPixelDataFunction · 0.85

Calls 4

JSIterateArrayFunction · 0.85
JSToIntFunction · 0.85
JSToStdStringFunction · 0.85
push_backMethod · 0.45

Tested by

no test coverage detected