From 7f81e1e4b1f0d74bbbd884eb6edffd6bad1c460d Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Wed, 28 Sep 2022 15:09:04 +0200 Subject: [PATCH] Rename RenderBase.OTextureFormat.rgba8 to RenderBase.OTextureFormat.argb8 --- PCK-Studio/Classes/Misc/RenderBase.cs | 2 +- PCK-Studio/Classes/Texturing/TextureCodec.cs | 17 ++++++++--------- PCK-Studio/Classes/Utils/3DS/3DSUtil.cs | 9 ++++----- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/PCK-Studio/Classes/Misc/RenderBase.cs b/PCK-Studio/Classes/Misc/RenderBase.cs index 47ee3c7b..05b8a0d9 100644 --- a/PCK-Studio/Classes/Misc/RenderBase.cs +++ b/PCK-Studio/Classes/Misc/RenderBase.cs @@ -1525,7 +1525,7 @@ namespace Ohana3DS_Rebirth.Ohana /// public enum OTextureFormat { - rgba8 = 0, + argb8 = 0, rgb8 = 1, rgba5551 = 2, rgb565 = 3, diff --git a/PCK-Studio/Classes/Texturing/TextureCodec.cs b/PCK-Studio/Classes/Texturing/TextureCodec.cs index fa175190..fd139edf 100644 --- a/PCK-Studio/Classes/Texturing/TextureCodec.cs +++ b/PCK-Studio/Classes/Texturing/TextureCodec.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Drawing; +using System.Collections.Generic; namespace Ohana3DS_Rebirth.Ohana { @@ -20,12 +21,12 @@ namespace Ohana3DS_Rebirth.Ohana public static Bitmap Decode(byte[] data, int width, int height, RenderBase.OTextureFormat format) { byte[] output = new byte[width * height * 4]; - long dataOffset = 0; + int dataOffset = 0; bool toggle = false; switch (format) { - case RenderBase.OTextureFormat.rgba8: + case RenderBase.OTextureFormat.argb8: for (int tY = 0; tY < height / 8; tY++) { for (int tX = 0; tX < width / 8; tX++) @@ -34,11 +35,10 @@ namespace Ohana3DS_Rebirth.Ohana { int x = tileOrder[pixel] % 8; int y = (tileOrder[pixel] - x) / 8; - long outputOffset = ((tX * 8) + x + ((tY * 8 + y) * width)) * 4; + int outputOffset = ((tX * 8 + x) + ((tY * 8 + y) * width)) * 4; - Buffer.BlockCopy(data, (int)dataOffset + 1, output, (int)outputOffset, 3); + Buffer.BlockCopy(data, dataOffset + 1, output, outputOffset, 3); output[outputOffset + 3] = data[dataOffset]; - dataOffset += 4; } } @@ -56,7 +56,7 @@ namespace Ohana3DS_Rebirth.Ohana int y = (tileOrder[pixel] - x) / 8; long outputOffset = ((tX * 8) + x + ((tY * 8 + y) * width)) * 4; - Buffer.BlockCopy(data, (int)dataOffset, output, (int)outputOffset, 3); + Buffer.BlockCopy(data, dataOffset, output, (int)outputOffset, 3); output[outputOffset + 3] = 0xff; dataOffset += 3; @@ -327,7 +327,7 @@ namespace Ohana3DS_Rebirth.Ohana int outputOffset = 0; switch (format) { - case RenderBase.OTextureFormat.rgba8: + case RenderBase.OTextureFormat.argb8: for (int tY = 0; tY < img.Height / 8; tY++) { for (int tX = 0; tX < img.Width / 8; tX++) @@ -340,14 +340,13 @@ namespace Ohana3DS_Rebirth.Ohana Buffer.BlockCopy(data, dataOffset, output, outputOffset + 1, 3); output[outputOffset] = data[dataOffset + 3]; - outputOffset += 4; } } } break; - default: throw new NotImplementedException(); + default: throw new NotImplementedException(nameof(format)); } return output; diff --git a/PCK-Studio/Classes/Utils/3DS/3DSUtil.cs b/PCK-Studio/Classes/Utils/3DS/3DSUtil.cs index bf108095..0cbf28b4 100644 --- a/PCK-Studio/Classes/Utils/3DS/3DSUtil.cs +++ b/PCK-Studio/Classes/Utils/3DS/3DSUtil.cs @@ -38,7 +38,7 @@ namespace PckStudio.Classes.Utils { switch (fmt) { - case RenderBase.OTextureFormat.rgba8: + case RenderBase.OTextureFormat.argb8: return w * h * 4; case RenderBase.OTextureFormat.rgb8: return w * h * 3; @@ -66,11 +66,11 @@ namespace PckStudio.Classes.Utils { if (ReadString(stream, 4) == "3DST") { - int offset = 32; + const int offset = 32; stream.Seek(8L, SeekOrigin.Begin); RenderBase.OTextureFormat format = ReadInt32(stream) switch { - 0 => RenderBase.OTextureFormat.rgba8, + 0 => RenderBase.OTextureFormat.argb8, 1 => RenderBase.OTextureFormat.rgb8, 2 => RenderBase.OTextureFormat.rgba5551, 3 => RenderBase.OTextureFormat.rgb8, @@ -91,7 +91,7 @@ namespace PckStudio.Classes.Utils return null; } - public static void SetImageTo3DST(Stream stream, Image source, RenderBase.OTextureFormat format = RenderBase.OTextureFormat.rgba8) + public static void SetImageTo3DST(Stream stream, Image source, RenderBase.OTextureFormat format = RenderBase.OTextureFormat.argb8) { // TODO: fix Encoding WriteString(stream, "3DST"); // 0 @@ -102,7 +102,6 @@ namespace PckStudio.Classes.Utils WriteInt32(stream, 0); // 20 WriteInt32(stream, 0); // 24 WriteInt32(stream, 0); // 28 - WriteInt32(stream, 0); // 32 source.RotateFlip(RotateFlipType.RotateNoneFlipY); byte[] buffer = TextureCodec.Encode(new Bitmap(source), format); stream.Write(buffer, 0, buffer.Length);