public static class PngCodecPNG, encoded and decoded, in about two hundred lines and with no imaging dependency.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
A reference picture nobody can open is a reference picture nobody will look at, and looking at it is the entire workflow when one fails. So baselines are PNGs rather than a raw blob: viewable in any file browser, diffable by eye, and small in git.
Written by hand rather than taken from a package. ImageSharp is in the dependency register but ADR-015 confines it to editor and tooling assemblies for licence reasons, and this assembly ships to game developers. PNG's baseline — one colour type, one bit depth, one interlace mode — is a couple of hundred lines, and the compression is System.IO.Compression's.
Written for Vixen.Graphics.Golden.Tests and moved here, which is why a UI testing library owns the tree's PNG codec. That suite needed one first; this one needed the same thing for its screenshots, and two hand-rolled PNG encoders is one too many.
⚠ The direction of the reference is the whole reason it could be consolidated at all. A shipping library can be referenced by a test project and a test project can be referenced by nothing, so the copy that ships is the only one that can be the shared one — and it is also the copy under a documentation and API-compatibility obligation, which is the right one to make load bearing.
Methods (4)
public static byte[] Encode(in Bitmap image)Encodes a picture.
public static Bitmap Decode(ReadOnlySpan<byte> data)Decodes a picture.
public static Bitmap Load(string path)Reads a picture from disk.
public static void Save(string path, in Bitmap image)Writes a picture to disk, creating the directory if it is not there.
Used by (4)
- GoldenImageVixen.Graphics.Golden.Tests
- PngCodecTestsVixen.Ui.Testing.Tests
- RasterizerTestsVixen.Ui.Testing.Tests
- VisualBaselineVixen.Ui.Testing