Convert Map.SavePreview to new Png code.

This commit is contained in:
Paul Chote
2019-02-17 13:15:14 +00:00
committed by reaperrr
parent 368b0314d5
commit 5f212a99fe

View File

@@ -12,11 +12,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using OpenRA.FileFormats;
using OpenRA.FileSystem; using OpenRA.FileSystem;
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Support; using OpenRA.Support;
@@ -664,17 +664,9 @@ namespace OpenRA
if (isRectangularIsometric) if (isRectangularIsometric)
bitmapWidth = 2 * bitmapWidth - 1; bitmapWidth = 2 * bitmapWidth - 1;
using (var bitmap = new Bitmap(bitmapWidth, height)) var stride = bitmapWidth * 4;
{ var minimapData = new byte[stride * height];
var bitmapData = bitmap.LockBits(bitmap.Bounds(),
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
unsafe
{
var colors = (int*)bitmapData.Scan0;
var stride = bitmapData.Stride / 4;
Color leftColor, rightColor; Color leftColor, rightColor;
for (var y = 0; y < height; y++) for (var y = 0; y < height; y++)
{ {
for (var x = 0; x < width; x++) for (var x = 0; x < width; x++)
@@ -703,22 +695,36 @@ namespace OpenRA
// Odd rows are shifted right by 1px // Odd rows are shifted right by 1px
var dx = uv.V & 1; var dx = uv.V & 1;
if (x + dx > 0) if (x + dx > 0)
colors[y * stride + 2 * x + dx - 1] = leftColor.ToArgb(); {
var z = y * stride + 8 * x + dx - 4;
minimapData[z++] = leftColor.R;
minimapData[z++] = leftColor.G;
minimapData[z++] = leftColor.B;
minimapData[z++] = leftColor.A;
}
if (2 * x + dx < stride) if (2 * x + dx < stride)
colors[y * stride + 2 * x + dx] = rightColor.ToArgb(); {
var z = y * stride + 8 * x + dx;
minimapData[z++] = rightColor.R;
minimapData[z++] = rightColor.G;
minimapData[z++] = rightColor.B;
minimapData[z++] = rightColor.A;
}
} }
else else
colors[y * stride + x] = leftColor.ToArgb(); {
var z = y * stride + 4 * x;
minimapData[z++] = leftColor.R;
minimapData[z++] = leftColor.G;
minimapData[z++] = leftColor.B;
minimapData[z++] = leftColor.A;
} }
} }
} }
bitmap.UnlockBits(bitmapData); var png = new Png(minimapData, bitmapWidth, height);
bitmap.Save(stream, ImageFormat.Png); return png.Save();
}
return stream.ToArray();
} }
} }