public void TestMemoryPixelBuffer() { ITiffPixelBuffer <TiffGray8> pixelBuffer = InitializePixelBuffer(out TiffGray8[] pixels); Assert.Equal(3, pixelBuffer.Width); Assert.Equal(2, pixelBuffer.Height); Span <TiffGray8> span = pixelBuffer.GetSpan(); Assert.True(Unsafe.AreSame(ref pixels[0], ref span[0])); Assert.Equal(6, span.Length); span[0] = new TiffGray8(0xCD); span[5] = new TiffGray8(0xEF); Assert.Equal(0xCD, pixels[0].Intensity); Assert.Equal(0xEF, pixels[5].Intensity); Assert.Throws <ArgumentOutOfRangeException>("width", () => TiffPixelBuffer.Wrap(Array.Empty <TiffGray8>(), -1, 0)); Assert.Throws <ArgumentOutOfRangeException>("height", () => TiffPixelBuffer.Wrap(Array.Empty <TiffGray8>(), 0, -1)); }
public void Setup() { TiffGray8[] image = new TiffGray8[8192 * 8192]; _image = TiffPixelBuffer.WrapReadOnly(image, 8192, 8192); var builder = new TiffImageEncoderBuilder(); builder.PhotometricInterpretation = TiffPhotometricInterpretation.WhiteIsZero; builder.Compression = Compression; builder.MaxDegreeOfParallelism = DegreeOfParallelism; // Strip encoder builder.IsTiled = false; builder.RowsPerStrip = 256; _stripEncoder = builder.Build <TiffGray8>(); // Tile encoder builder.IsTiled = false; builder.TileSize = new TiffSize(512, 512); _tileEncoder = builder.Build <TiffGray8>(); }
public async Task Setup() { TiffGray8[] image = new TiffGray8[8192 * 8192]; _scratchSpace = TiffPixelBuffer.Wrap(image, 8192, 8192); var builder = new TiffImageEncoderBuilder(); builder.PhotometricInterpretation = TiffPhotometricInterpretation.WhiteIsZero; builder.Compression = Compression; // Generate a image with many strips var ms = new MemoryStream(); builder.IsTiled = false; builder.RowsPerStrip = 256; await GenerateImageAsync(ms, builder, _scratchSpace); _stripTestTiff = ms.ToArray(); ms.SetLength(0); // Generate a image with many tiles builder.IsTiled = true; builder.TileSize = new TiffSize(512, 512); await GenerateImageAsync(ms, builder, _scratchSpace); _tileTestTiff = ms.ToArray(); _stripReader = await TiffFileReader.OpenAsync(_stripTestTiff); _stripDecoder = await _stripReader.CreateImageDecoderAsync(new TiffImageDecoderOptions { MaxDegreeOfParallelism = DegreeOfParallelism }); await _stripDecoder.DecodeAsync(_scratchSpace); _tileReader = await TiffFileReader.OpenAsync(_tileTestTiff); _tileDecoder = await _tileReader.CreateImageDecoderAsync(new TiffImageDecoderOptions { MaxDegreeOfParallelism = DegreeOfParallelism }); await _tileDecoder.DecodeAsync(_scratchSpace); }
public async Task Setup() { TiffGray8[] image = new TiffGray8[8192 * 8192]; _scratchSpace = TiffPixelBuffer.Wrap(image, 8192, 8192); var builder = new TiffImageEncoderBuilder(); builder.PhotometricInterpretation = TiffPhotometricInterpretation.BlackIsZero; builder.Compression = TiffCompression.NoCompression; // Generate a image with many strips var ms = new MemoryStream(); builder.IsTiled = false; builder.RowsPerStrip = 1; await GenerateImageAsync(ms, builder, _scratchSpace); _stripTestTiff = ms.ToArray(); ms.SetLength(0); // Generate a image with many tiles builder.IsTiled = true; builder.TileSize = new TiffSize(16, 16); // the minimum tile size await GenerateImageAsync(ms, builder, _scratchSpace); _tileTestTiff = ms.ToArray(); _stripReader = await TiffFileReader.OpenAsync(_stripTestTiff); _stripDecoder = await _stripReader.CreateImageDecoderAsync(); await _stripDecoder.DecodeAsync(_scratchSpace); _tileReader = await TiffFileReader.OpenAsync(_tileTestTiff); _tileDecoder = await _tileReader.CreateImageDecoderAsync(); await _tileDecoder.DecodeAsync(_scratchSpace); }
public void TestWriteColumns() { ITiffPixelBuffer <TiffGray8> pixelBuffer = PixelBufferTests.InitializePixelBuffer(out TiffGray8[] pixels); var writer = new TiffPixelBufferWriterAdapter <TiffGray8>(pixelBuffer); // Write to first column using (TiffPixelSpanHandle <TiffGray8> pixelSpanHandle = writer.GetColumnSpan(0, 0, 1)) { Assert.Equal(1, pixelSpanHandle.Length); Span <TiffGray8> span = pixelSpanHandle.GetSpan(); Assert.Equal(1, span.Length); span[0] = new TiffGray8(0xb1); } // Make sure only the affected pixels are changed while others stay the same. Assert.Equal(0xb1, pixels[0].Intensity); Assert.Equal(0x12, pixels[1].Intensity); Assert.Equal(0x13, pixels[2].Intensity); Assert.Equal(0x21, pixels[3].Intensity); Assert.Equal(0x22, pixels[4].Intensity); Assert.Equal(0x23, pixels[5].Intensity); // Write to second column using (TiffPixelSpanHandle <TiffGray8> pixelSpanHandle = writer.GetColumnSpan(1, 1, 1)) { Assert.Equal(1, pixelSpanHandle.Length); Span <TiffGray8> span = pixelSpanHandle.GetSpan(); Assert.Equal(1, span.Length); span[0] = new TiffGray8(0xb2); } // Make sure only the affected pixels are changed while others stay the same. Assert.Equal(0xb1, pixels[0].Intensity); Assert.Equal(0x12, pixels[1].Intensity); Assert.Equal(0x13, pixels[2].Intensity); Assert.Equal(0x21, pixels[3].Intensity); Assert.Equal(0xb2, pixels[4].Intensity); Assert.Equal(0x23, pixels[5].Intensity); // Write to third column using (TiffPixelSpanHandle <TiffGray8> pixelSpanHandle = writer.GetColumnSpan(2, 0, 2)) { Assert.Equal(2, pixelSpanHandle.Length); Span <TiffGray8> span = pixelSpanHandle.GetSpan(); Assert.Equal(2, span.Length); span[0] = new TiffGray8(0xb3); span[1] = new TiffGray8(0xb4); } // Make sure only the affected pixels are changed while others stay the same. Assert.Equal(0xb1, pixels[0].Intensity); Assert.Equal(0x12, pixels[1].Intensity); Assert.Equal(0xb3, pixels[2].Intensity); Assert.Equal(0x21, pixels[3].Intensity); Assert.Equal(0xb2, pixels[4].Intensity); Assert.Equal(0xb4, pixels[5].Intensity); // Failure cases Assert.Throws <ArgumentOutOfRangeException>("colIndex", () => writer.GetColumnSpan(-1, 1, 1)); Assert.Throws <ArgumentOutOfRangeException>("colIndex", () => writer.GetColumnSpan(3, 1, 1)); Assert.Throws <ArgumentOutOfRangeException>("start", () => writer.GetColumnSpan(0, -1, 1)); Assert.Throws <ArgumentOutOfRangeException>("start", () => writer.GetColumnSpan(0, 3, 1)); Assert.Throws <ArgumentOutOfRangeException>("length", () => writer.GetColumnSpan(0, 1, -1)); Assert.Throws <ArgumentOutOfRangeException>("length", () => writer.GetColumnSpan(0, 1, 2)); }