public void Encode_PreserveTrns(string imagePath, PngBitDepth pngBitDepth, PngColorType pngColorType) { var options = new PngEncoder(); var testFile = TestFile.Create(imagePath); using (Image <Rgba32> input = testFile.CreateImage()) { PngMetaData inMeta = input.MetaData.GetFormatMetaData(PngFormat.Instance); Assert.True(inMeta.HasTrans); using (var memStream = new MemoryStream()) { input.Save(memStream, options); memStream.Position = 0; using (var output = Image.Load <Rgba32>(memStream)) { PngMetaData outMeta = output.MetaData.GetFormatMetaData(PngFormat.Instance); Assert.True(outMeta.HasTrans); switch (pngColorType) { case PngColorType.Grayscale: if (pngBitDepth.Equals(PngBitDepth.Bit16)) { Assert.True(outMeta.TransparentGray16.HasValue); Assert.Equal(inMeta.TransparentGray16, outMeta.TransparentGray16); } else { Assert.True(outMeta.TransparentGray8.HasValue); Assert.Equal(inMeta.TransparentGray8, outMeta.TransparentGray8); } break; case PngColorType.Rgb: if (pngBitDepth.Equals(PngBitDepth.Bit16)) { Assert.True(outMeta.TransparentRgb48.HasValue); Assert.Equal(inMeta.TransparentRgb48, outMeta.TransparentRgb48); } else { Assert.True(outMeta.TransparentRgb24.HasValue); Assert.Equal(inMeta.TransparentRgb24, outMeta.TransparentRgb24); } break; } } } } }
public void CloneIsDeep() { var meta = new PngMetaData() { BitDepth = PngBitDepth.Bit16, ColorType = PngColorType.GrayscaleWithAlpha, Gamma = 2 }; var clone = (PngMetaData)meta.DeepClone(); clone.BitDepth = PngBitDepth.Bit2; clone.ColorType = PngColorType.Palette; clone.Gamma = 1; Assert.False(meta.BitDepth.Equals(clone.BitDepth)); Assert.False(meta.ColorType.Equals(clone.ColorType)); Assert.False(meta.Gamma.Equals(clone.Gamma)); }
public void Encode_PreserveBits(string imagePath, PngBitDepth pngBitDepth) { var options = new PngEncoder(); var testFile = TestFile.Create(imagePath); using (Image <Rgba32> input = testFile.CreateImage()) { using (var memStream = new MemoryStream()) { input.Save(memStream, options); memStream.Position = 0; using (var output = Image.Load <Rgba32>(memStream)) { PngMetaData meta = output.MetaData.GetFormatMetaData(PngFormat.Instance); Assert.Equal(pngBitDepth, meta.BitDepth); } } } }
/// <summary> /// Initializes a new instance of the <see cref="PngMetaData"/> class. /// </summary> /// <param name="other">The metadata to create an instance from.</param> private PngMetaData(PngMetaData other) { this.BitDepth = other.BitDepth; this.ColorType = other.ColorType; this.Gamma = other.Gamma; }