Пример #1
0
        private static void TestTgaEncoderCore <TPixel>(
            TestImageProvider <TPixel> provider,
            TgaBitsPerPixel bitsPerPixel,
            TgaCompression compression = TgaCompression.None,
            bool useExactComparer      = true,
            float compareTolerance     = 0.01f)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            using (Image <TPixel> image = provider.GetImage())
            {
                var encoder = new TgaEncoder {
                    BitsPerPixel = bitsPerPixel, Compression = compression
                };

                using (var memStream = new MemoryStream())
                {
                    image.Save(memStream, encoder);
                    memStream.Position = 0;
                    using (var encodedImage = (Image <TPixel>)Image.Load(memStream))
                    {
                        TgaTestUtils.CompareWithReferenceDecoder(provider, encodedImage, useExactComparer, compareTolerance);
                    }
                }
            }
        }
Пример #2
0
        public void Identify_WithValidData_Works(byte[] data, int width, int height, TgaBitsPerPixel bitsPerPixel)
        {
            using var stream = new MemoryStream(data);

            IImageInfo  info    = Image.Identify(stream);
            TgaMetadata tgaData = info.Metadata.GetTgaMetadata();

            Assert.Equal(bitsPerPixel, tgaData.BitsPerPixel);
            Assert.Equal(width, info.Width);
            Assert.Equal(height, info.Height);
        }
Пример #3
0
        public void TgaEncoder_PreserveBitsPerPixel(string imagePath, TgaBitsPerPixel bmpBitsPerPixel)
        {
            var options = new TgaEncoder();

            var testFile = TestFile.Create(imagePath);

            using (Image <Rgba32> input = testFile.CreateRgba32Image())
            {
                using (var memStream = new MemoryStream())
                {
                    input.Save(memStream, options);
                    memStream.Position = 0;
                    using (var output = Image.Load <Rgba32>(memStream))
                    {
                        TgaMetadata meta = output.Metadata.GetTgaMetadata();
                        Assert.Equal(bmpBitsPerPixel, meta.BitsPerPixel);
                    }
                }
            }
        }
Пример #4
0
        public void Encode_WithCompression_PreserveBitsPerPixel(string imagePath, TgaBitsPerPixel bmpBitsPerPixel)
        {
            var options = new TgaEncoder()
            {
                Compression = TgaCompression.RunLength
            };

            TestFile testFile = TestFile.Create(imagePath);

            using (Image <Rgba32> input = testFile.CreateRgba32Image())
            {
                using (var memStream = new MemoryStream())
                {
                    input.Save(memStream, options);
                    memStream.Position = 0;
                    using (Image <Rgba32> output = Image.Load <Rgba32>(memStream))
                    {
                        TgaMetadata meta = output.Metadata.GetFormatMetadata(TgaFormat.Instance);
                        Assert.Equal(bmpBitsPerPixel, meta.BitsPerPixel);
                    }
                }
            }
        }
Пример #5
0
 public void TgaEncoder_Bit24_Works <TPixel>(TestImageProvider <TPixel> provider, TgaBitsPerPixel bitsPerPixel = TgaBitsPerPixel.Pixel24)
     where TPixel : unmanaged, IPixel <TPixel> => TestTgaEncoderCore(provider, bitsPerPixel, TgaCompression.None);
Пример #6
0
 public void TgaEncoder_Bit16_Works <TPixel>(TestImageProvider <TPixel> provider, TgaBitsPerPixel bitsPerPixel = TgaBitsPerPixel.Pixel16)
     where TPixel : unmanaged, IPixel <TPixel> => TestTgaEncoderCore(provider, bitsPerPixel, TgaCompression.None, useExactComparer : false);
Пример #7
0
        public void TgaEncoder_Bit8_Works <TPixel>(TestImageProvider <TPixel> provider, TgaBitsPerPixel bitsPerPixel = TgaBitsPerPixel.Pixel8)

        // Using tolerant comparer here. The results from magick differ slightly. Maybe a different ToGrey method is used. The image looks otherwise ok.
            where TPixel : unmanaged, IPixel <TPixel> => TestTgaEncoderCore(provider, bitsPerPixel, TgaCompression.None, useExactComparer : false, compareTolerance : 0.03f);
Пример #8
0
 public void TgaEncoder_WorksWithDiscontiguousBuffers <TPixel>(TestImageProvider <TPixel> provider, TgaBitsPerPixel bitsPerPixel)
     where TPixel : unmanaged, IPixel <TPixel>
 {
     provider.LimitAllocatorBufferCapacity().InPixelsSqrt(100);
     TestTgaEncoderCore(provider, bitsPerPixel, TgaCompression.RunLength);
 }
Пример #9
0
 public void TgaEncoder_Bit32_WithRunLengthEncoding_Works <TPixel>(TestImageProvider <TPixel> provider, TgaBitsPerPixel bitsPerPixel = TgaBitsPerPixel.Pixel32)
     where TPixel : unmanaged, IPixel <TPixel> => TestTgaEncoderCore(provider, bitsPerPixel, TgaCompression.RunLength);
Пример #10
0
 public void Encode_Bit24_WithRunLengthEncoding_Works <TPixel>(TestImageProvider <TPixel> provider, TgaBitsPerPixel bitsPerPixel = TgaBitsPerPixel.Pixel24)
     where TPixel : struct, IPixel <TPixel> => TestTgaEncoderCore(provider, bitsPerPixel, TgaCompression.RunLength);
Пример #11
0
 public void Encode_Bit16_WithRunLengthEncoding_Works <TPixel>(TestImageProvider <TPixel> provider, TgaBitsPerPixel bitsPerPixel = TgaBitsPerPixel.Pixel16)
     where TPixel : struct, IPixel <TPixel> => TestTgaEncoderCore(provider, bitsPerPixel, TgaCompression.RunLength, useExactComparer : false);
Пример #12
0
 public void Encode_Bit32_Works <TPixel>(TestImageProvider <TPixel> provider, TgaBitsPerPixel bitsPerPixel = TgaBitsPerPixel.Pixel32)
     where TPixel : struct, IPixel <TPixel> => TestTgaEncoderCore(provider, bitsPerPixel, TgaCompression.None);