← back to roto on ba3a.dev

PngCodec

object PngCodec

Reads and writes Rasters as PNG through javax.imageio.

Writing always produces 8-bit RGBA, and the same raster always encodes to the same bytes on the same JDK. Reading accepts any PNG colour type and bit depth and returns the stored sample values without colour management: a gray PNG reads back as the gray levels it holds, not as a linear-to-sRGB conversion of them, and gamma or ICC chunks are ignored.

Streams are buffered in memory rather than through ImageIO's temp-file cache, so no call here touches global ImageIO state or the file system beyond the given path.

Functions

Link copied to clipboard
fun read(input: InputStream): Raster

Reads a PNG from input, which is read to its end but not closed.

fun read(path: Path): Raster

Reads the PNG at path.

Link copied to clipboard
fun write(raster: Raster, output: OutputStream)

Writes raster to output, which is not closed.

fun write(raster: Raster, path: Path)

Writes raster to path through AtomicFile, so a crash never leaves a half-written file.