public void CreateFromSubStreamKeepingOwnershipThrowIfInvalidArgument() { var stream = new MemoryStream(); stream.WriteByte(0xCA); stream.WriteByte(0xFE); Assert.That( () => DataStreamFactory.FromStreamKeepingOwnership(null, 0, 0), Throws.ArgumentNullException); Assert.That( () => DataStreamFactory.FromStreamKeepingOwnership(stream, -1, 0), Throws.InstanceOf <ArgumentOutOfRangeException>()); Assert.That( () => DataStreamFactory.FromStreamKeepingOwnership(stream, 0, -1), Throws.InstanceOf <ArgumentOutOfRangeException>()); Assert.That( () => DataStreamFactory.FromStreamKeepingOwnership(stream, 3, 0), Throws.InstanceOf <ArgumentOutOfRangeException>()); Assert.That( () => DataStreamFactory.FromStreamKeepingOwnership(stream, 1, 2), Throws.InstanceOf <ArgumentOutOfRangeException>()); stream.Dispose(); }
public void CreateFromSubStreamKeepsOwnership() { var stream = new MemoryStream(); stream.WriteByte(0xCA); int beforeCount = DataStream.ActiveStreams; var dataStream = DataStreamFactory.FromStreamKeepingOwnership(stream, 0, 1); Assert.That(DataStream.ActiveStreams, Is.EqualTo(beforeCount)); dataStream.Dispose(); Assert.That(() => stream.ReadByte(), Throws.Nothing); stream.Dispose(); }
private static void ImportDig(Node nDIG, Node nATM, Node nPNG, string outputPath) { log.Info("Importing " + nDIG.Name + ", " + nATM.Name + " and " + nPNG.Name); DIG originalDig = nDIG.TransformWith <Binary2DIG>().GetFormatAs <DIG>(); ALMT originalAtm = nATM.TransformWith <Binary2ALMT>().GetFormatAs <ALMT>(); // New stream var stream = new MemoryStream(); var dataStream = DataStreamFactory.FromStreamKeepingOwnership(stream, 0, 0); // Copy the png to the bitmap stream nPNG.Stream.WriteTo(dataStream); // Import the new PNG file Bitmap newImage = (Bitmap)Image.FromStream(stream); var quantization = new FixedPaletteQuantization(originalDig.Palette.GetPalette(0)); ColorFormat format; if (originalDig.PaletteType == 16) { format = ColorFormat.Indexed_4bpp; } else { format = ColorFormat.Indexed_8bpp; } Texim.ImageMapConverter importer = new Texim.ImageMapConverter { Format = format, PixelEncoding = PixelEncoding.HorizontalTiles, Quantization = quantization, //Mapable = new MatchMapping(originalDig.Pixels.GetPixels()) }; (Palette _, PixelArray pixelInfo, MapInfo[] mapInfos) = importer.Convert(newImage); originalDig.Pixels = pixelInfo; originalAtm.Info = mapInfos; BinaryFormat bDig = (BinaryFormat)ConvertFormat.With <Binary2DIG>(originalDig); BinaryFormat bAtm = (BinaryFormat)ConvertFormat.With <Binary2ALMT>(originalAtm); Utils.Lzss(bDig, "-evn").Stream.WriteTo(Path.Combine(outputPath, nDIG.Name + ".evn.dig")); bAtm.Stream.WriteTo(Path.Combine(outputPath, nATM.Name + ".atm")); }
public void CreateFromSubStreamKeepingOwnershipUseStream() { var stream = new MemoryStream(); stream.WriteByte(0xCA); stream.WriteByte(0xFE); stream.WriteByte(0xBE); var dataStream = DataStreamFactory.FromStreamKeepingOwnership(stream, 1, 2); Assert.That(dataStream.BaseStream, Is.AssignableFrom <StreamWrapper>()); Assert.That( ((StreamWrapper)dataStream.BaseStream).BaseStream, Is.SameAs(stream)); Assert.That(dataStream.Position, Is.EqualTo(0)); Assert.That(dataStream.Offset, Is.EqualTo(1)); Assert.That(dataStream.Length, Is.EqualTo(2)); stream.Dispose(); }