| 331 | } |
| 332 | |
| 333 | void WriteToFile(std::string_view path, const Image& image, ImageFormat format) |
| 334 | { |
| 335 | switch (format) |
| 336 | { |
| 337 | case ImageFormat::automatic: |
| 338 | WriteToFile(path, image, GetImageFormatFromPath(path)); |
| 339 | break; |
| 340 | case ImageFormat::png: |
| 341 | { |
| 342 | #ifndef __EMSCRIPTEN__ |
| 343 | std::ofstream fs(fs::u8path(path), std::ios::binary); |
| 344 | WritePng(fs, image); |
| 345 | #else |
| 346 | std::ostringstream stream(std::ios::binary); |
| 347 | WritePng(stream, image); |
| 348 | std::string dataStr = stream.str(); |
| 349 | void* data = reinterpret_cast<void*>(dataStr.data()); |
| 350 | MAIN_THREAD_EM_ASM( |
| 351 | { |
| 352 | const a = document.createElement("a"); |
| 353 | // Blob requires the data must not be shared |
| 354 | const data = new Uint8Array(HEAPU8.subarray($0, $0 + $1)); |
| 355 | a.href = URL.createObjectURL(new Blob([data])); |
| 356 | a.download = UTF8ToString($2).split("/").pop(); |
| 357 | a.click(); |
| 358 | setTimeout(function(){ URL.revokeObjectURL(a.href) }, 1000); |
| 359 | }, |
| 360 | data, dataStr.size(), std::string(path).c_str()); |
| 361 | free(data); |
| 362 | #endif |
| 363 | break; |
| 364 | } |
| 365 | default: |
| 366 | throw std::runtime_error(kExceptionImageFormatUnknown); |
| 367 | } |
| 368 | } |
| 369 | } // namespace OpenRCT2::Imaging |
nothing calls this directly
no test coverage detected