public bool SetData(GR.Memory.ByteBuffer ImageData) { if (ImageData.Length != m_ImageData.Length) { return(false); } ImageData.CopyTo(m_ImageData); return(true); }
// resize and try to keep existing data intact public void Resize(int NewWidth, int NewHeight) { int safeWidth = Math.Min(Width, NewWidth); int safeHeight = Math.Min(Height, NewHeight); int origBytesPerLine = BitsPerPixel * Width / 8; int bytesPerLine = BitsPerPixel * NewWidth / 8; var newImageData = new ByteBuffer((uint)(bytesPerLine * Height)); for (int j = 0; j < safeHeight; ++j) { m_ImageData.CopyTo(newImageData, bytesPerLine * j, (BitsPerPixel * safeWidth) / 8, j * origBytesPerLine); } m_Width = NewWidth; m_Height = NewHeight; m_ImageData = newImageData; }
public bool ReadFromBuffer(GR.Memory.ByteBuffer DataIn) { if (DataIn == null) { return(false); } SpriteLayers.Clear(); Sprites.Clear(); GR.IO.MemoryReader memIn = DataIn.MemoryReader(); uint Version = memIn.ReadUInt32(); if (Version == 2) { Colors.Palettes.Clear(); GR.IO.FileChunk chunkMain = new GR.IO.FileChunk(); while (chunkMain.ReadFromStream(memIn)) { switch (chunkMain.Type) { case FileChunkConstants.SPRITESET_PROJECT: { var chunkReader = chunkMain.MemoryReader(); GR.IO.FileChunk subChunk = new GR.IO.FileChunk(); while (subChunk.ReadFromStream(chunkReader)) { var subChunkReader = subChunk.MemoryReader(); switch (subChunk.Type) { case FileChunkConstants.SPRITESET_INFO: TotalNumberOfSprites = subChunkReader.ReadInt32(); Name = subChunkReader.ReadString(); ExportFilename = subChunkReader.ReadString(); ExportStartIndex = subChunkReader.ReadInt32(); ExportSpriteCount = subChunkReader.ReadInt32(); break; case FileChunkConstants.MULTICOLOR_DATA: Mode = (SpriteProjectMode)subChunkReader.ReadInt32(); Colors.BackgroundColor = subChunkReader.ReadInt32(); Colors.MultiColor1 = subChunkReader.ReadInt32(); Colors.MultiColor2 = subChunkReader.ReadInt32(); Colors.ActivePalette = 0; break; case FileChunkConstants.PALETTE: Colors.Palettes.Add(Palette.Read(subChunkReader)); break; case FileChunkConstants.SPRITESET_SPRITE: { var sprite = new SpriteData(new ColorSettings(Colors)); sprite.Mode = (SpriteMode)subChunkReader.ReadInt32(); sprite.Tile.Mode = (GraphicTileMode)subChunkReader.ReadInt32(); sprite.Tile.CustomColor = subChunkReader.ReadInt32(); sprite.Tile.Width = subChunkReader.ReadInt32(); sprite.Tile.Height = subChunkReader.ReadInt32(); int dataLength = subChunkReader.ReadInt32(); sprite.Tile.Data = new GR.Memory.ByteBuffer(); subChunkReader.ReadBlock(sprite.Tile.Data, (uint)dataLength); if (sprite.Tile.CustomColor == -1) { sprite.Tile.CustomColor = 1; } sprite.Tile.Colors.ActivePalette = subChunkReader.ReadInt32(); sprite.Tile.Image = new GR.Image.MemoryImage(sprite.Tile.Width, sprite.Tile.Height, GR.Drawing.PixelFormat.Format32bppRgb); Sprites.Add(sprite); } break; case FileChunkConstants.SPRITESET_LAYER: { Layer layer = new Layer(); SpriteLayers.Add(layer); GR.IO.FileChunk subChunkL = new GR.IO.FileChunk(); while (subChunkL.ReadFromStream(subChunkReader)) { var subChunkReaderL = subChunkL.MemoryReader(); if (subChunkL.Type == FileChunkConstants.SPRITESET_LAYER_ENTRY) { LayerSprite sprite = new LayerSprite(); sprite.Index = subChunkReaderL.ReadInt32(); sprite.Color = subChunkReaderL.ReadInt32(); sprite.X = subChunkReaderL.ReadInt32(); sprite.Y = subChunkReaderL.ReadInt32(); sprite.ExpandX = (subChunkReaderL.ReadInt32() != 0); sprite.ExpandY = (subChunkReaderL.ReadInt32() != 0); layer.Sprites.Add(sprite); } else if (subChunkL.Type == FileChunkConstants.SPRITESET_LAYER_INFO) { layer.Name = subChunkReaderL.ReadString(); layer.BackgroundColor = subChunkReaderL.ReadInt32(); layer.DelayMS = subChunkReaderL.ReadInt32(); } } } break; } } } break; default: Debug.Log("SpriteProject.ReadFromBuffer unexpected chunk type " + chunkMain.Type.ToString("X")); return(false); } } return(true); } int numSprites = 256; if (Version >= 1) { numSprites = memIn.ReadInt32(); } Sprites = new List <SpriteData>(); for (int i = 0; i < numSprites; ++i) { Sprites.Add(new SpriteData(Colors)); PaletteManager.ApplyPalette(Sprites[i].Tile.Image); } string name = memIn.ReadString(); for (int i = 0; i < numSprites; ++i) { Sprites[i].Tile.CustomColor = memIn.ReadInt32(); } for (int i = 0; i < numSprites; ++i) { Sprites[i].Mode = (SpriteMode)memIn.ReadUInt8(); Sprites[i].Tile.Mode = Lookup.GraphicTileModeFromSpriteMode(Sprites[i].Mode); } Colors.BackgroundColor = memIn.ReadInt32(); Colors.MultiColor1 = memIn.ReadInt32(); Colors.MultiColor2 = memIn.ReadInt32(); bool genericMultiColor = (memIn.ReadUInt32() != 0); for (int i = 0; i < numSprites; ++i) { GR.Memory.ByteBuffer tempBuffer = new GR.Memory.ByteBuffer(); memIn.ReadBlock(tempBuffer, 64); tempBuffer.CopyTo(Sprites[i].Tile.Data, 0, 63); } ExportSpriteCount = memIn.ReadInt32(); ExportFilename = memIn.ReadString(); string exportPathSpriteFile = memIn.ReadString(); for (int i = 0; i < numSprites; ++i) { string desc = memIn.ReadString(); } int spriteTestCount = memIn.ReadInt32(); for (int i = 0; i < spriteTestCount; ++i) { int spriteIndex = memIn.ReadInt32(); byte spriteColor = memIn.ReadUInt8(); bool spriteMultiColor = (memIn.ReadUInt8() != 0); int spriteX = memIn.ReadInt32(); int spriteY = memIn.ReadInt32(); } GR.IO.FileChunk chunk = new GR.IO.FileChunk(); while (chunk.ReadFromStream(memIn)) { switch (chunk.Type) { case FileChunkConstants.SPRITESET_LAYER: { Layer layer = new Layer(); SpriteLayers.Add(layer); var chunkReader = chunk.MemoryReader(); GR.IO.FileChunk subChunk = new GR.IO.FileChunk(); while (subChunk.ReadFromStream(chunkReader)) { var subChunkReader = subChunk.MemoryReader(); if (subChunk.Type == FileChunkConstants.SPRITESET_LAYER_ENTRY) { LayerSprite sprite = new LayerSprite(); sprite.Index = subChunkReader.ReadInt32(); sprite.Color = subChunkReader.ReadUInt8(); sprite.X = subChunkReader.ReadInt32(); sprite.Y = subChunkReader.ReadInt32(); sprite.ExpandX = (subChunkReader.ReadUInt8() != 0); sprite.ExpandY = (subChunkReader.ReadUInt8() != 0); layer.Sprites.Add(sprite); } else if (subChunk.Type == FileChunkConstants.SPRITESET_LAYER_INFO) { layer.Name = subChunkReader.ReadString(); layer.BackgroundColor = subChunkReader.ReadUInt8(); layer.DelayMS = subChunkReader.ReadInt32(); } } } break; } } while (Sprites.Count > 256) { Sprites.RemoveAt(256); } return(true); }