public void ReadSliceSuccessTest() { var Buffer = new byte[8]; SliceStream.Position = 1; int Readed = SliceStream.Read(Buffer, 0, 8); Assert.AreEqual(3, Readed); Readed = SliceStream.Read(Buffer, 0, 8); Assert.AreEqual(0, Readed); CollectionAssert.AreEqual(new byte[] { 3, 4, 5 }, Buffer.Take(3).ToArray()); }
public void Read_TwoTimes() { var slice = new BufferSlice(65535); var stream = new SliceStream(slice); var mammasBullar = Encoding.UTF8.GetBytes("Mammas bullar smakar godast."); stream.Write(mammasBullar, 0, mammasBullar.Length); var buffer = new byte[10]; stream.Position = 0; stream.Read(buffer, 0, 6); var buffer2 = new byte[10]; stream.Read(buffer2, 0, 7); Assert.Equal("Mammas", Encoding.UTF8.GetString(buffer, 0, 6)); Assert.Equal(" bullar", Encoding.UTF8.GetString(buffer2, 0, 7)); }
public void ReadLongerThanBuffer() { var slice = new BufferSlice(65535); var stream = new SliceStream(slice); var expected = "Mammas bullar smakar godast"; var mammasBullar = Encoding.UTF8.GetBytes(expected); stream.Write(mammasBullar, 0, mammasBullar.Length); var buffer = new byte[100]; stream.Position = 0; Assert.Equal(expected.Length, stream.Read(buffer, 0, 1024)); Assert.Equal(expected, Encoding.UTF8.GetString(buffer, 0, expected.Length)); }
public OP2BitmapFile GetImage(int index) { artFile.VerifyImageIndexInBounds(index); ImageMeta imageMeta = artFile.imageMetas[index]; Color[] palette; if (imageMeta.type.bShadow != 0) { // Shadow graphic uses a 2 color palette palette = new Color[2]; System.Array.Copy(artFile.palettes[imageMeta.paletteIndex].colors, palette, palette.Length); } else { // Normal graphic palette = new Color[artFile.palettes[imageMeta.paletteIndex].colors.Length]; System.Array.Copy(artFile.palettes[imageMeta.paletteIndex].colors, palette, palette.Length); } // Palette length is always 256 for OP2's master BMP uint pixelOffset = (uint)(imageMeta.pixelDataOffset + 14 + ImageHeader.SizeInBytes + 256 * Color.SizeInBytes); int height = (int)System.Math.Abs(imageMeta.height); int pitch = ImageHeader.CalculatePitch(imageMeta.GetBitCount(), (int)imageMeta.width); SliceStream pixels = GetPixels(pixelOffset, (uint)(height * pitch)); byte[] pixelContainer = new byte[height * pitch]; pixels.Read(pixelContainer, 0, pixelContainer.Length); // Outpost 2 stores pixels in normal raster scan order (top-down). This requires a negative height for BMP file format. if (imageMeta.height > uint.MaxValue) { throw new System.Exception("Image height is too large to fit in standard bitmap file format."); } return(new OP2BitmapFile(imageMeta, palette, pixelContainer)); }