Exemplo n.º 1
0
        public void Identify_DetectsCorrectColorType(string imagePath, PbmColorType expectedColorType)
        {
            var testFile = TestFile.Create(imagePath);

            using var stream = new MemoryStream(testFile.Bytes, false);
            IImageInfo imageInfo = Image.Identify(stream);

            Assert.NotNull(imageInfo);
            PbmMetadata bitmapMetadata = imageInfo.Metadata.GetPbmMetadata();

            Assert.NotNull(bitmapMetadata);
            Assert.Equal(expectedColorType, bitmapMetadata.ColorType);
        }
Exemplo n.º 2
0
        private void DeduceOptions <TPixel>(Image <TPixel> image)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            this.configuration = image.GetConfiguration();
            PbmMetadata metadata = image.Metadata.GetPbmMetadata();

            this.encoding  = this.options.Encoding ?? metadata.Encoding;
            this.colorType = this.options.ColorType ?? metadata.ColorType;
            if (this.colorType != PbmColorType.BlackAndWhite)
            {
                this.componentType = this.options.ComponentType ?? metadata.ComponentType;
            }
            else
            {
                this.componentType = PbmComponentType.Bit;
            }
        }
Exemplo n.º 3
0
        public void ImageLoadCanDecode(string imagePath, PbmColorType expectedColorType, PbmComponentType expectedComponentType)
        {
            // Arrange
            var testFile = TestFile.Create(imagePath);

            using var stream = new MemoryStream(testFile.Bytes, false);

            // Act
            using var image = Image.Load(stream);

            // Assert
            Assert.NotNull(image);
            PbmMetadata metadata = image.Metadata.GetPbmMetadata();

            Assert.NotNull(metadata);
            Assert.Equal(expectedColorType, metadata.ColorType);
            Assert.Equal(expectedComponentType, metadata.ComponentType);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Decode pixels into the PBM plain encoding.
        /// </summary>
        /// <typeparam name="TPixel">The type of input pixel.</typeparam>
        /// <param name="configuration">The configuration.</param>
        /// <param name="stream">The bytestream to write to.</param>
        /// <param name="image">The input image.</param>
        /// <param name="colorType">The ColorType to use.</param>
        /// <param name="componentType">Data type of the pixles components.</param>
        public static void WritePixels <TPixel>(Configuration configuration, Stream stream, ImageFrame <TPixel> image, PbmColorType colorType, PbmComponentType componentType)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            if (colorType == PbmColorType.Grayscale)
            {
                if (componentType == PbmComponentType.Byte)
                {
                    WriteGrayscale(configuration, stream, image);
                }
                else
                {
                    WriteWideGrayscale(configuration, stream, image);
                }
            }
            else if (colorType == PbmColorType.Rgb)
            {
                if (componentType == PbmComponentType.Byte)
                {
                    WriteRgb(configuration, stream, image);
                }
                else
                {
                    WriteWideRgb(configuration, stream, image);
                }
            }
            else
            {
                WriteBlackAndWhite(configuration, stream, image);
            }

            // Write EOF indicator, as some encoders expect it.
            stream.WriteByte(Space);
        }