private void PaintSprite() { var item = _spriteListWindow.SelectedSprite; var remap = _spriteRemapsWindow.SelectedItem; int palette = remap.Key == -1 ? _spriteListWindow.SelectedSprite.DefaultPalette : remap.Palette; var activeDeltas = _spriteDeltasWindow.CheckedDeltaItems; Image previousImage = null; if (_spritePreviewWindow.Image != null) { previousImage = _spritePreviewWindow.Image; } var outputBitmap = new LockBitmap(new Bitmap(item.Rectangle.Width, item.Rectangle.Height)); outputBitmap.LockBits(); for (var x = 0; x < item.Rectangle.Width; x++) { for (var y = 0; y < item.Rectangle.Height; y++) { var value = _spriteData[item.Rectangle.X + x, item.Rectangle.Y + y]; if (value != 0) { outputBitmap.SetPixel(x, y, _paletteImage.GetPixel(palette, value)); } } } foreach (var delta in activeDeltas) { for (var x = 0; x < delta.Rectangle.Width; x++) { for (var y = 0; y < delta.Rectangle.Height; y++) { var value = _deltaData[delta.Rectangle.X + x, delta.Rectangle.Y + y]; if (value != 0) { outputBitmap.SetPixel(delta.RelativePosition.X + x, delta.RelativePosition.Y + y, _paletteImage.GetPixel(palette, value)); } } } } outputBitmap.UnlockBits(); _spritePreviewWindow.Image = outputBitmap.Source; if (previousImage != null) { previousImage.Dispose(); } }
private void PaintSprite() { var item = _spriteListWindow.SelectedSprite; var remap = _spriteRemapsWindow.SelectedItem; int palette = remap.Key == -1 ? _spriteListWindow.SelectedSprite.DefaultPalette : remap.Palette; var activeDeltas = _spriteDeltasWindow.CheckedDeltaItems; Image previousImage = null; if (_spritePreviewWindow.Image != null) previousImage = _spritePreviewWindow.Image; var outputBitmap = new LockBitmap(new Bitmap(item.Rectangle.Width, item.Rectangle.Height)); outputBitmap.LockBits(); for (var x = 0; x < item.Rectangle.Width; x++) { for (var y = 0; y < item.Rectangle.Height; y++) { var value = _spriteData[item.Rectangle.X + x, item.Rectangle.Y + y]; if (value != 0) outputBitmap.SetPixel(x, y, _paletteImage.GetPixel(palette, value)); } } foreach (var delta in activeDeltas) { for (var x = 0; x < delta.Rectangle.Width; x++) { for (var y = 0; y < delta.Rectangle.Height; y++) { var value = _deltaData[delta.Rectangle.X + x, delta.Rectangle.Y + y]; if (value != 0) outputBitmap.SetPixel(delta.RelativePosition.X + x, delta.RelativePosition.Y + y, _paletteImage.GetPixel(palette, value)); } } } outputBitmap.UnlockBits(); _spritePreviewWindow.Image = outputBitmap.Source; if (previousImage != null) previousImage.Dispose(); }
private void CreateSpriteData(TextureAtlasSprites sprites) { _spriteImage.LockBits(); _spriteData = new byte[_spriteImage.Width, _spriteImage.Height]; _deltaImage.LockBits(); _deltaData = new byte[_deltaImage.Width, _deltaImage.Height]; var colorCache = new Dictionary <Color, byte>(); _paletteImage.LockBits(); foreach (var sprite in sprites.SpriteDictionary) { //actual Sprite colorCache.Clear(); var palette = sprite.Value.DefaultPalette; for (var x = sprite.Value.Rectangle.X; x < sprite.Value.Rectangle.X + sprite.Value.Rectangle.Width; x++) { for (var y = sprite.Value.Rectangle.Y; y < sprite.Value.Rectangle.Y + sprite.Value.Rectangle.Height; y++) { var color = _spriteImage.GetPixel(x, y); if (color.ToArgb() == 0) { continue; } byte value; if (colorCache.TryGetValue(color, out value)) { _spriteData[x, y] = value; continue; } for (byte i = 0; i < 256; i++) { if (color == _paletteImage.GetPixel(palette, i)) { _spriteData[x, y] = i; colorCache.Add(color, i); break; } } } } //Deltas if (sprite.Value.DeltaItems == null) { continue; } foreach (var delta in sprite.Value.DeltaItems) { for (var x = delta.Rectangle.X; x < delta.Rectangle.X + delta.Rectangle.Width; x++) { for (var y = delta.Rectangle.Y; y < delta.Rectangle.Y + delta.Rectangle.Height; y++) { var color = _deltaImage.GetPixel(x, y); if (color.ToArgb() == 0) { continue; } byte value; if (colorCache.TryGetValue(color, out value)) { _deltaData[x, y] = value; continue; } for (byte i = 0; i < 256; i++) { if (color == _paletteImage.GetPixel(palette, i)) { _deltaData[x, y] = i; colorCache.Add(color, i); break; } if (i == 255) { System.Diagnostics.Debug.WriteLine("Color not found!"); //DetectPalette(paletteImage, deltaImage, delta.Rectangle); } } } } } } _deltaImage.UnlockBits(); _spriteImage.UnlockBits(); }