Пример #1
0
        public async Task TestRoundtrip(bool isTile)
        {
            TiffGray8[] refImage  = new TiffGray8[2048 * 2048];
            TiffGray8[] testImage = new TiffGray8[2048 * 2048];

            var rand = new Random(42);

            rand.NextBytes(MemoryMarshal.AsBytes(refImage.AsSpan()));

            var builder = new TiffImageEncoderBuilder();

            builder.PhotometricInterpretation = TiffPhotometricInterpretation.BlackIsZero;
            builder.Compression = TiffCompression.NoCompression;
            builder.IsTiled     = isTile;
            // Make sure we have at least CacheSize strips or tiles
            // Cache size in the current implementation is 256
            // Any value greater than 256 should be OK.
            builder.RowsPerStrip = 2;                    // 1024 strips
            builder.TileSize     = new TiffSize(16, 16); // 16384 tiles

            var ms = new MemoryStream();

            await GenerateImageAsync(ms, builder, TiffPixelBuffer.WrapReadOnly(refImage, 2048, 2048));

            ms.Seek(0, SeekOrigin.Begin);

            await using TiffFileReader tiff = await TiffFileReader.OpenAsync(ms, leaveOpen : true);

            TiffImageDecoder decoder = await tiff.CreateImageDecoderAsync();

            await decoder.DecodeAsync(TiffPixelBuffer.Wrap(testImage, 2048, 2048));

            Assert.True(refImage.AsSpan().SequenceEqual(testImage.AsSpan()));
        }
Пример #2
0
        public async Task TestRoundtrip(bool isTile, int maxDegreeOfParallelism, bool isYCbCr)
        {
            TiffGray8[] refImage  = new TiffGray8[4096 * 4096];
            TiffGray8[] testImage = new TiffGray8[4096 * 4096];

            var rand = new Random(42);

            rand.NextBytes(MemoryMarshal.AsBytes(refImage.AsSpan()));

            var builder = new TiffImageEncoderBuilder();

            if (isYCbCr)
            {
                builder.PhotometricInterpretation   = TiffPhotometricInterpretation.YCbCr;
                builder.HorizontalChromaSubSampling = 2;
                builder.VerticalChromaSubSampling   = 2;
            }
            else
            {
                builder.PhotometricInterpretation = TiffPhotometricInterpretation.BlackIsZero;
                builder.Predictor = TiffPredictor.HorizontalDifferencing;
            }

            builder.Compression            = TiffCompression.Lzw;
            builder.IsTiled                = isTile;
            builder.RowsPerStrip           = 64;
            builder.TileSize               = new TiffSize(64, 64);
            builder.MaxDegreeOfParallelism = maxDegreeOfParallelism;

            var ms = new MemoryStream();

            await GenerateImageAsync(ms, builder, TiffPixelBuffer.WrapReadOnly(refImage, 4096, 4096));

            ms.Seek(0, SeekOrigin.Begin);

            await using TiffFileReader tiff = await TiffFileReader.OpenAsync(ms, leaveOpen : true);

            TiffImageDecoder decoder = await tiff.CreateImageDecoderAsync();

            await decoder.DecodeAsync(TiffPixelBuffer.Wrap(testImage, 4096, 4096));

            Assert.True(refImage.AsSpan().SequenceEqual(testImage.AsSpan()));
        }
Пример #3
0
        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>();
        }