Replace Sheet.AsBitmap with Sheet.AsPng.

This commit is contained in:
Paul Chote
2019-02-12 12:50:10 +00:00
committed by reaperrr
parent 2c96eb9d24
commit 82fade25a6
2 changed files with 12 additions and 35 deletions

View File

@@ -11,9 +11,7 @@
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using OpenRA.FileFormats;
namespace OpenRA.Graphics
@@ -79,48 +77,27 @@ namespace OpenRA.Graphics
return texture;
}
public Bitmap AsBitmap()
public Png AsPng()
{
var d = GetData();
var dataStride = 4 * Size.Width;
var bitmap = new Bitmap(Size.Width, Size.Height);
var bd = bitmap.LockBits(bitmap.Bounds(),
ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
for (var y = 0; y < Size.Height; y++)
Marshal.Copy(d, y * dataStride, IntPtr.Add(bd.Scan0, y * bd.Stride), dataStride);
bitmap.UnlockBits(bd);
return bitmap;
return new Png(GetData(), Size.Width, Size.Height);
}
public Bitmap AsBitmap(TextureChannel channel, IPalette pal)
public Png AsPng(TextureChannel channel, IPalette pal)
{
var d = GetData();
var plane = new byte[Size.Width * Size.Height];
var dataStride = 4 * Size.Width;
var bitmap = new Bitmap(Size.Width, Size.Height);
var channelOffset = (int)channel;
var bd = bitmap.LockBits(bitmap.Bounds(),
ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
unsafe
{
var colors = (uint*)bd.Scan0;
for (var y = 0; y < Size.Height; y++)
{
var dataRowIndex = y * dataStride + channelOffset;
var bdRowIndex = y * bd.Stride / 4;
for (var x = 0; x < Size.Width; x++)
{
var paletteIndex = d[dataRowIndex + 4 * x];
colors[bdRowIndex + x] = pal[paletteIndex];
}
}
}
for (var y = 0; y < Size.Height; y++)
for (var x = 0; x < Size.Width; x++)
plane[y * Size.Width + x] = d[y * dataStride + channelOffset + 4 * x];
bitmap.UnlockBits(bd);
var palColors = new Color[Palette.Size];
for (var i = 0; i < Palette.Size; i++)
palColors[i] = pal.GetColor(i);
return bitmap;
return new Png(plane, Size.Width, Size.Height, palColors);
}
public void CreateBuffer()

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
{
var max = s == sb.Current ? (int)sb.CurrentChannel + 1 : 4;
for (var i = 0; i < max; i++)
s.AsBitmap((TextureChannel)ChannelMasks[i], palette).Save("{0}.png".F(count++));
s.AsPng((TextureChannel)ChannelMasks[i], palette).Save("{0}.png".F(count++));
}
Console.WriteLine("Saved [0..{0}].png", count - 1);