Vixen
feb85697
csharp
public static class PngCodec

PNG, encoded and decoded, in about two hundred lines and with no imaging dependency.

Read the guide page for this →

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, then owned by Vixen.Ui.Testing, and now here. Each move was the same argument one step further down: a picture is written by more things than the one that needed it first, and the assembly a consumer cannot reference is the assembly that forces a second encoder. A UI testing library was the wrong owner for the last of those reasons — a game head that wants to write its own frame to a file cannot reference a test framework to do it, and Platform/ could not reference it at all.

⚠ The direction of the reference is the whole reason it can be shared. Everything that encodes a picture — the golden suites, the UI baselines, a --vixen-capture run — is above this assembly, and none of them is above each other. Sitting under all three is what stops the count of hand-written PNG encoders in this repository from going back up.

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 (52, showing 40)

  • PaintedLayersTestsThirdPersonShooter.Frame.Tests
  • BakedMaterialImageTestsVixen.Graphics.Golden.Tests
  • CompositorImageTestsVixen.Graphics.Golden.Tests
  • ContainerStyleQueryPixelTestsVixen.Ui.Testing.Tests
  • ContainerTypePixelTestsVixen.Ui.Testing.Tests
  • FrameCaptureVixen.App.Hosting
  • GoldenImageVixen.Graphics.Golden.Tests
  • InterfaceOverASceneDeviceTestsVixen.Graphics.Golden.Tests
  • LayeredMaterialImageTestsVixen.Graphics.Golden.Tests
  • PngCodecTestsVixen.Core.Imaging.Tests
  • RasterizerTestsVixen.Ui.Testing.Tests
  • ScrollBarThumbContrastTestsVixen.Ui.Controls.Tests
  • ScrollBarThumbPictureTestsVixen.Ui.Controls.Tests
  • SmaaImageTestsVixen.Graphics.Golden.Tests
  • StandardFrameTierImageTestsVixen.Graphics.Golden.Tests
  • ToastWidthTestsVixen.Ui.Controls.Tests
  • UiApplicationVixen.Ui.Desktop
  • UiApplicationCaptureTestsVixen.Ui.Desktop.Tests
  • UiBlendDeviceTestsVixen.Graphics.Golden.Tests
  • UnderlyingValueAnimationPixelTestsVixen.Ui.Testing.Tests
  • VfxBackendPictureTestsVixen.Vfx.Gpu.Tests
  • VirtualGeometryGoldenTestsVixen.Graphics.Golden.Tests
  • VisualBaselineVixen.Ui.Testing
  • WhiteSpaceInlinePixelTestsVixen.Ui.Controls.Tests
  • AddressableGroupsViewDumpTestsVixen.Editor.AssetEditors.Tests
  • AssetGridDumpTestsVixen.Editor.App.Tests
  • BehaviorSearchPopupDumpTestsVixen.Editor.AssetEditors.Tests
  • ComposedPaneCaptureTestsVixen.Editor.App.Tests
  • ConsoleViewDumpTestsVixen.Editor.Ui.Tests
  • EditorUiCompositingDeviceTestsVixen.Editor.App.Tests
  • FixtureProjectVixen.Editor.Assets.Tests
  • FrameCaptureTestsVixen.App.Tests
  • HostedInterfaceComposeTestsVixen.App.Tests
  • KeyBindingsViewDumpTestsVixen.Editor.Ui.Tests
  • LayerStackBakeRouteDeviceTestsVixen.Editor.Texturing.Tests
  • LayerStackPanelDeviceTestsVixen.Editor.Texturing.Tests
  • MaterialBakeVixen.Editor.Assets
  • MaterialBakeAssetTestsVixen.Editor.Assets.Tests
  • MaterialBakeRouteDeviceTestsVixen.Editor.Texturing.Tests
  • MaterialBakeTestsVixen.Editor.Assets.Tests