public void Identify_DetectsCorrectComponentType(string imagePath, PbmComponentType expectedComponentType) { 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(expectedComponentType, bitmapMetadata.ComponentType); }
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; } }
/// <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); }
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); }