diff --git a/OpenRA.Mods.Cnc/FileFormats/VqaReader.cs b/OpenRA.Mods.Cnc/FileFormats/VqaReader.cs index 48438315cf..8c9d89aa33 100644 --- a/OpenRA.Mods.Cnc/FileFormats/VqaReader.cs +++ b/OpenRA.Mods.Cnc/FileFormats/VqaReader.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.Cnc.FileFormats readonly byte chunkBufferParts; readonly int2 blocks; readonly uint[] offsets; - readonly uint[] palette; + readonly byte[] paletteBytes; readonly uint videoFlags; // if 0x10 is set the video is a 16 bit hq video (ts and later) readonly ushort totalFrameWidth; @@ -116,7 +116,7 @@ namespace OpenRA.Mods.Cnc.FileFormats origData = new byte[2 * blocks.X * blocks.Y]; } - palette = new uint[numColors]; + paletteBytes = new byte[numColors * 4]; var type = stream.ReadASCII(4); while (type != "FINF") { @@ -396,7 +396,10 @@ namespace OpenRA.Mods.Cnc.FileFormats var r = (byte)(s.ReadUInt8() << 2); var g = (byte)(s.ReadUInt8() << 2); var b = (byte)(s.ReadUInt8() << 2); - palette[i] = (uint)((255 << 24) | (r << 16) | (g << 8) | b); + paletteBytes[i * 4] = b; + paletteBytes[i * 4 + 1] = g; + paletteBytes[i * 4 + 2] = r; + paletteBytes[i * 4 + 3] = 255; } break; @@ -492,15 +495,14 @@ namespace OpenRA.Mods.Cnc.FileFormats { var cbfi = (mod * 256 + px) * 8 + j * blockWidth + i; var colorIndex = (mod == 0x0f) ? px : cbf[cbfi]; - var color = palette[colorIndex]; var pixelX = x * blockWidth + i; var pixelY = y * blockHeight + j; var pos = pixelY * totalFrameWidth + pixelX; - CurrentFrameData[pos * 4] = (byte)(color & 0xFF); - CurrentFrameData[pos * 4 + 1] = (byte)(color >> 8 & 0xFF); - CurrentFrameData[pos * 4 + 2] = (byte)(color >> 16 & 0xFF); - CurrentFrameData[pos * 4 + 3] = (byte)(color >> 24 & 0xFF); + CurrentFrameData[pos * 4] = paletteBytes[colorIndex * 4]; + CurrentFrameData[pos * 4 + 1] = paletteBytes[colorIndex * 4 + 1]; + CurrentFrameData[pos * 4 + 2] = paletteBytes[colorIndex * 4 + 2]; + CurrentFrameData[pos * 4 + 3] = paletteBytes[colorIndex * 4 + 3]; } } } diff --git a/OpenRA.Mods.Cnc/FileFormats/WsaReader.cs b/OpenRA.Mods.Cnc/FileFormats/WsaReader.cs index 6e05ffbf94..eb0a84c7e4 100644 --- a/OpenRA.Mods.Cnc/FileFormats/WsaReader.cs +++ b/OpenRA.Mods.Cnc/FileFormats/WsaReader.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.Cnc.FileFormats public int SampleRate => 0; readonly Stream stream; - readonly uint[] palette; + readonly byte[] paletteBytes; readonly uint[] frameOffsets; readonly ushort totalFrameWidth; @@ -60,8 +60,8 @@ namespace OpenRA.Mods.Cnc.FileFormats if (flags == 1) { - palette = new uint[256]; - for (var i = 0; i < palette.Length; i++) + paletteBytes = new byte[1024]; + for (var i = 0; i < paletteBytes.Length;) { var r = (byte)(stream.ReadByte() << 2); var g = (byte)(stream.ReadByte() << 2); @@ -72,7 +72,10 @@ namespace OpenRA.Mods.Cnc.FileFormats g |= (byte)(g >> 6); b |= (byte)(b >> 6); - palette[i] = (uint)((255 << 24) | (r << 16) | (g << 8) | b); + paletteBytes[i++] = b; + paletteBytes[i++] = g; + paletteBytes[i++] = r; + paletteBytes[i++] = 255; } for (var i = 0; i < frameOffsets.Length; i++) @@ -138,11 +141,11 @@ namespace OpenRA.Mods.Cnc.FileFormats { for (var x = 0; x < Width; x++) { - var color = palette[currentFramePaletteIndexData[c++]]; - CurrentFrameData[position++] = (byte)(color & 0xFF); - CurrentFrameData[position++] = (byte)(color >> 8 & 0xFF); - CurrentFrameData[position++] = (byte)(color >> 16 & 0xFF); - CurrentFrameData[position++] = (byte)(color >> 24 & 0xFF); + var colorIndex = currentFramePaletteIndexData[c++]; + CurrentFrameData[position++] = paletteBytes[colorIndex * 4]; + CurrentFrameData[position++] = paletteBytes[colorIndex * 4 + 1]; + CurrentFrameData[position++] = paletteBytes[colorIndex * 4 + 2]; + CurrentFrameData[position++] = paletteBytes[colorIndex * 4 + 3]; } // Recalculate the position in the byte array to the start of the next pixel row just in case there is padding in the frame.