| 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 | { |
no test coverage detected