public static ushort[] LoadBuffer(string pathBase, int width, int height, int numberOfComponents) { string pathHigh = pathBase + ".high.png"; string pathLowDiff = pathBase + ".low-diff.png"; using var high = Image.Load <Rgba32>(pathHigh); using var lowDiff = Image.Load <Rgba32>(pathLowDiff); if (high.Width != width || high.Height != height || lowDiff.Width != width || lowDiff.Height != height) { throw new InvalidDataException(); } Rgba32[] highPixels = new Rgba32[width * height]; Rgba32[] lowDiffPixels = new Rgba32[width * height]; for (int i = 0; i < height; i++) { high.GetPixelRowSpan(i).CopyTo(highPixels.AsSpan(width * i, width)); lowDiff.GetPixelRowSpan(i).CopyTo(lowDiffPixels.AsSpan(width * i, width)); } ushort[] buffer = new ushort[width * height * 4]; CopyHighBits(highPixels, buffer, numberOfComponents); CopyLowBits(lowDiffPixels, buffer, numberOfComponents); ReversePrediction(buffer, numberOfComponents); return(buffer); }
public void TestJpegLibrary() { var decoder = new JpegDecoder(); decoder.SetInput(_inputBytes); decoder.Identify(); int width = decoder.Width; int height = decoder.Height; Rgba32[] rgba = new Rgba32[width * height]; byte[] ycbcr = ArrayPool <byte> .Shared.Rent(3 *rgba.Length); try { var outputWriter = new JpegBufferOutputWriter(decoder.Width, decoder.Height, 3, ycbcr); decoder.SetOutputWriter(outputWriter); decoder.Decode(); JpegYCbCrToRgbConverter.Shared.ConvertYCbCr8ToRgba32(ycbcr, MemoryMarshal.AsBytes(rgba.AsSpan()), decoder.Width * decoder.Height); } finally { ArrayPool <byte> .Shared.Return(ycbcr); } }
public void PublicMethods_ThrowIfDisposed() { var image = new Image <Rgba32>(Configuration.Default, 10, 10); var frameCollection = image.Frames; var rgba32Array = new Rgba32[0]; image.Dispose(); // this should invalidate underlying collection as well Assert.Throws <ObjectDisposedException>(() => { var res = frameCollection.AddFrame((ImageFrame)null); }); Assert.Throws <ObjectDisposedException>(() => { var res = frameCollection.AddFrame(rgba32Array); }); Assert.Throws <ObjectDisposedException>(() => { var res = frameCollection.AddFrame((ImageFrame <Rgba32>)null); }); Assert.Throws <ObjectDisposedException>(() => { var res = frameCollection.AddFrame(rgba32Array.AsSpan()); }); Assert.Throws <ObjectDisposedException>(() => { var res = frameCollection.CloneFrame(default); });