Remove System.Bitmap from UI artwork loading.
This commit is contained in:
@@ -14,6 +14,7 @@ using System.Drawing;
|
|||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
|
|
||||||
namespace OpenRA.Graphics
|
namespace OpenRA.Graphics
|
||||||
{
|
{
|
||||||
@@ -50,13 +51,10 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public Sheet(SheetType type, Stream stream)
|
public Sheet(SheetType type, Stream stream)
|
||||||
{
|
{
|
||||||
using (var bitmap = (Bitmap)Image.FromStream(stream))
|
var png = new Png(stream);
|
||||||
{
|
Size = new Size(png.Width, png.Height);
|
||||||
Size = bitmap.Size;
|
data = new byte[4 * Size.Width * Size.Height];
|
||||||
data = new byte[4 * Size.Width * Size.Height];
|
Util.FastCopyIntoSprite(new Sprite(this, new Rectangle(0, 0, png.Width, png.Height), TextureChannel.Red), png);
|
||||||
|
|
||||||
Util.FastCopyIntoSprite(new Sprite(this, bitmap.Bounds(), TextureChannel.Red), bitmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
Type = type;
|
Type = type;
|
||||||
ReleaseBuffer();
|
ReleaseBuffer();
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
|
|
||||||
namespace OpenRA.Graphics
|
namespace OpenRA.Graphics
|
||||||
{
|
{
|
||||||
@@ -81,6 +82,46 @@ namespace OpenRA.Graphics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void FastCopyIntoSprite(Sprite dest, Png src)
|
||||||
|
{
|
||||||
|
var destData = dest.Sheet.GetData();
|
||||||
|
var destStride = dest.Sheet.Size.Width;
|
||||||
|
var width = dest.Bounds.Width;
|
||||||
|
var height = dest.Bounds.Height;
|
||||||
|
|
||||||
|
unsafe
|
||||||
|
{
|
||||||
|
// Cast the data to an int array so we can copy the src data directly
|
||||||
|
fixed (byte* bd = &destData[0])
|
||||||
|
{
|
||||||
|
var data = (int*)bd;
|
||||||
|
var x = dest.Bounds.Left;
|
||||||
|
var y = dest.Bounds.Top;
|
||||||
|
|
||||||
|
var k = 0;
|
||||||
|
for (var j = 0; j < height; j++)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < width; i++)
|
||||||
|
{
|
||||||
|
Color cc;
|
||||||
|
if (src.Palette == null)
|
||||||
|
{
|
||||||
|
var r = src.Data[k++];
|
||||||
|
var g = src.Data[k++];
|
||||||
|
var b = src.Data[k++];
|
||||||
|
var a = src.Data[k++];
|
||||||
|
cc = Color.FromArgb(a, r, g, b);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
cc = src.Palette[src.Data[k++]];
|
||||||
|
|
||||||
|
data[(y + j) * destStride + x + i] = PremultiplyAlpha(cc).ToArgb();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void FastCopyIntoSprite(Sprite dest, Bitmap src)
|
public static void FastCopyIntoSprite(Sprite dest, Bitmap src)
|
||||||
{
|
{
|
||||||
var createdTempBitmap = false;
|
var createdTempBitmap = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user