| 122 | } |
| 123 | |
| 124 | bool SpriteImageExport(const G1Element& spriteElement, u8string_view outPath) |
| 125 | { |
| 126 | const size_t pixelBufferSize = static_cast<size_t>(spriteElement.width) * spriteElement.height; |
| 127 | auto pixelBuffer = std::make_unique<PaletteIndex[]>(pixelBufferSize); |
| 128 | auto pixels = pixelBuffer.get(); |
| 129 | |
| 130 | RenderTarget rt; |
| 131 | rt.bits = pixels; |
| 132 | rt.x = 0; |
| 133 | rt.y = 0; |
| 134 | rt.width = spriteElement.width; |
| 135 | rt.height = spriteElement.height; |
| 136 | rt.pitch = 0; |
| 137 | rt.zoom_level = ZoomLevel{ 0 }; |
| 138 | |
| 139 | DrawSpriteArgs args( |
| 140 | ImageId(), PaletteMap::GetDefault(), spriteElement, 0, 0, spriteElement.width, spriteElement.height, pixels); |
| 141 | GfxSpriteToBuffer(rt, args); |
| 142 | |
| 143 | auto const pixels8 = reinterpret_cast<uint8_t*>(rt.bits); |
| 144 | auto const pixelsLen = rt.LineStride() * rt.WorldHeight(); |
| 145 | try |
| 146 | { |
| 147 | Image image; |
| 148 | image.Width = rt.width; |
| 149 | image.Height = rt.height; |
| 150 | image.Depth = 8; |
| 151 | image.Stride = rt.LineStride(); |
| 152 | image.Palette = StandardPalette; |
| 153 | image.Pixels = std::vector<uint8_t>(pixels8, pixels8 + pixelsLen); |
| 154 | Imaging::WriteToFile(outPath, image, ImageFormat::png); |
| 155 | return true; |
| 156 | } |
| 157 | catch (const std::exception& e) |
| 158 | { |
| 159 | fprintf(stderr, "Unable to write png: %s", e.what()); |
| 160 | return false; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | std::optional<Image> SpriteImageLoad(u8string_view path, ImageImportMeta meta) |
| 165 | { |
no test coverage detected