Remove RenderBase and move TextureCodec and TextureUtils to Utils/3DS

This commit is contained in:
miku-666
2022-11-12 18:03:55 +01:00
parent a58ba87224
commit 67ee75557a
7 changed files with 70 additions and 2345 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -4,8 +4,30 @@ using System.Drawing;
using System.IO;
using System.Text;
namespace PckStudio.Classes.Utils
namespace PckStudio.Classes._3ds.Utils
{
/// <summary>
/// Format of the texture used on the PICA200.
/// </summary>
public enum _3DSTextureFormat
{
argb8 = 0,
rgb8 = 1,
rgba5551 = 2,
rgb565 = 3,
rgba4 = 4,
la8 = 5,
hilo8 = 6,
l8 = 7,
a8 = 8,
la4 = 9,
l4 = 0xa,
a4 = 0xb,
etc1 = 0xc,
etc1a4 = 0xd,
dontCare
}
internal class _3DSUtil
{
private static string ReadString(Stream stream, int len)
@@ -34,28 +56,28 @@ namespace PckStudio.Classes.Utils
stream.Write(buffer, 0, 4);
}
public static int CalcBufferSize(RenderBase.OTextureFormat fmt, int w, int h)
public static int CalcBufferSize(_3DSTextureFormat fmt, int w, int h)
{
switch (fmt)
{
case RenderBase.OTextureFormat.argb8:
case _3DSTextureFormat.argb8:
return w * h * 4;
case RenderBase.OTextureFormat.rgb8:
case _3DSTextureFormat.rgb8:
return w * h * 3;
case RenderBase.OTextureFormat.rgba5551:
case RenderBase.OTextureFormat.rgb565:
case RenderBase.OTextureFormat.rgba4:
case RenderBase.OTextureFormat.la8:
case RenderBase.OTextureFormat.hilo8:
case _3DSTextureFormat.rgba5551:
case _3DSTextureFormat.rgb565:
case _3DSTextureFormat.rgba4:
case _3DSTextureFormat.la8:
case _3DSTextureFormat.hilo8:
return w * h * 2;
case RenderBase.OTextureFormat.l8:
case RenderBase.OTextureFormat.a8:
case RenderBase.OTextureFormat.la4:
case RenderBase.OTextureFormat.etc1a4:
case _3DSTextureFormat.l8:
case _3DSTextureFormat.a8:
case _3DSTextureFormat.la4:
case _3DSTextureFormat.etc1a4:
return w * h;
case RenderBase.OTextureFormat.l4:
case RenderBase.OTextureFormat.a4:
case RenderBase.OTextureFormat.etc1:
case _3DSTextureFormat.l4:
case _3DSTextureFormat.a4:
case _3DSTextureFormat.etc1:
return w * h >> 1;
default:
throw new InvalidDataException("Invalid texture format on BCH!");
@@ -68,15 +90,15 @@ namespace PckStudio.Classes.Utils
{
const int offset = 32;
stream.Seek(8L, SeekOrigin.Begin);
RenderBase.OTextureFormat format = ReadInt32(stream) switch
_3DSTextureFormat format = ReadInt32(stream) switch
{
0 => RenderBase.OTextureFormat.argb8,
1 => RenderBase.OTextureFormat.rgb8,
2 => RenderBase.OTextureFormat.rgba5551,
3 => RenderBase.OTextureFormat.rgb8,
4 => RenderBase.OTextureFormat.rgba4,
9 => RenderBase.OTextureFormat.la4,
_ => RenderBase.OTextureFormat.dontCare,
0 => _3DSTextureFormat.argb8,
1 => _3DSTextureFormat.rgb8,
2 => _3DSTextureFormat.rgba5551,
3 => _3DSTextureFormat.rgb8,
4 => _3DSTextureFormat.rgba4,
9 => _3DSTextureFormat.la4,
_ => _3DSTextureFormat.dontCare,
};
int width = ReadInt32(stream);
int height = ReadInt32(stream);
@@ -91,7 +113,7 @@ namespace PckStudio.Classes.Utils
return null;
}
public static void SetImageTo3DST(Stream stream, Image source, RenderBase.OTextureFormat format = RenderBase.OTextureFormat.argb8)
public static void SetImageTo3DST(Stream stream, Image source, _3DSTextureFormat format = _3DSTextureFormat.argb8)
{
// TODO: fix Encoding
WriteString(stream, "3DST"); // 0

View File

@@ -1,7 +1,6 @@
using System;
using System.Linq;
using System.Drawing;
using System.Collections.Generic;
using PckStudio.Classes._3ds.Utils;
namespace Ohana3DS_Rebirth.Ohana
{
@@ -18,7 +17,7 @@ namespace Ohana3DS_Rebirth.Ohana
/// <param name="height">Height of the Texture</param>
/// <param name="format">Pixel Format of the Texture</param>
/// <returns></returns>
public static Bitmap Decode(byte[] data, int width, int height, RenderBase.OTextureFormat format)
public static Bitmap Decode(byte[] data, int width, int height, _3DSTextureFormat format)
{
byte[] output = new byte[width * height * 4];
int dataOffset = 0;
@@ -26,7 +25,7 @@ namespace Ohana3DS_Rebirth.Ohana
switch (format)
{
case RenderBase.OTextureFormat.argb8:
case _3DSTextureFormat.argb8:
for (int tY = 0; tY < height / 8; tY++)
{
for (int tX = 0; tX < width / 8; tX++)
@@ -45,7 +44,7 @@ namespace Ohana3DS_Rebirth.Ohana
}
break;
case RenderBase.OTextureFormat.rgb8:
case _3DSTextureFormat.rgb8:
for (int tY = 0; tY < height / 8; tY++)
{
for (int tX = 0; tX < width / 8; tX++)
@@ -65,7 +64,7 @@ namespace Ohana3DS_Rebirth.Ohana
}
break;
case RenderBase.OTextureFormat.rgba5551:
case _3DSTextureFormat.rgba5551:
for (int tY = 0; tY < height / 8; tY++)
{
for (int tX = 0; tX < width / 8; tX++)
@@ -94,7 +93,7 @@ namespace Ohana3DS_Rebirth.Ohana
}
break;
case RenderBase.OTextureFormat.rgb565:
case _3DSTextureFormat.rgb565:
for (int tY = 0; tY < height / 8; tY++)
{
for (int tX = 0; tX < width / 8; tX++)
@@ -122,7 +121,7 @@ namespace Ohana3DS_Rebirth.Ohana
}
break;
case RenderBase.OTextureFormat.rgba4:
case _3DSTextureFormat.rgba4:
for (int tY = 0; tY < height / 8; tY++)
{
for (int tX = 0; tX < width / 8; tX++)
@@ -151,8 +150,8 @@ namespace Ohana3DS_Rebirth.Ohana
}
break;
case RenderBase.OTextureFormat.la8:
case RenderBase.OTextureFormat.hilo8:
case _3DSTextureFormat.la8:
case _3DSTextureFormat.hilo8:
for (int tY = 0; tY < height / 8; tY++)
{
for (int tX = 0; tX < width / 8; tX++)
@@ -174,7 +173,7 @@ namespace Ohana3DS_Rebirth.Ohana
}
break;
case RenderBase.OTextureFormat.l8:
case _3DSTextureFormat.l8:
for (int tY = 0; tY < height / 8; tY++)
{
for (int tX = 0; tX < width / 8; tX++)
@@ -196,7 +195,7 @@ namespace Ohana3DS_Rebirth.Ohana
}
break;
case RenderBase.OTextureFormat.a8:
case _3DSTextureFormat.a8:
for (int tY = 0; tY < height / 8; tY++)
{
for (int tX = 0; tX < width / 8; tX++)
@@ -218,7 +217,7 @@ namespace Ohana3DS_Rebirth.Ohana
}
break;
case RenderBase.OTextureFormat.la4:
case _3DSTextureFormat.la4:
for (int tY = 0; tY < height / 8; tY++)
{
for (int tX = 0; tX < width / 8; tX++)
@@ -240,7 +239,7 @@ namespace Ohana3DS_Rebirth.Ohana
}
break;
case RenderBase.OTextureFormat.l4:
case _3DSTextureFormat.l4:
for (int tY = 0; tY < height / 8; tY++)
{
for (int tX = 0; tX < width / 8; tX++)
@@ -263,7 +262,7 @@ namespace Ohana3DS_Rebirth.Ohana
}
break;
case RenderBase.OTextureFormat.a4:
case _3DSTextureFormat.a4:
for (int tY = 0; tY < height / 8; tY++)
{
for (int tX = 0; tX < width / 8; tX++)
@@ -285,9 +284,9 @@ namespace Ohana3DS_Rebirth.Ohana
}
break;
case RenderBase.OTextureFormat.etc1:
case RenderBase.OTextureFormat.etc1a4:
byte[] decodedData = etc1Decode(data, width, height, format == RenderBase.OTextureFormat.etc1a4);
case _3DSTextureFormat.etc1:
case _3DSTextureFormat.etc1a4:
byte[] decodedData = etc1Decode(data, width, height, format == _3DSTextureFormat.etc1a4);
int[] etc1Order = etc1Scramble(width, height);
int i = 0;
@@ -319,7 +318,7 @@ namespace Ohana3DS_Rebirth.Ohana
/// <param name="img">Input image to be encoded</param>
/// <param name="format">Pixel Format of the Texture</param>
/// <returns></returns>
public static byte[] Encode(Bitmap img, RenderBase.OTextureFormat format)
public static byte[] Encode(Bitmap img, _3DSTextureFormat format)
{
byte[] data = TextureUtils.ToArray(img);
byte[] output = new byte[data.Length];
@@ -327,7 +326,7 @@ namespace Ohana3DS_Rebirth.Ohana
int outputOffset = 0;
switch (format)
{
case RenderBase.OTextureFormat.argb8:
case _3DSTextureFormat.argb8:
for (int tY = 0; tY < img.Height / 8; tY++)
{
for (int tX = 0; tX < img.Width / 8; tX++)

View File

@@ -6,6 +6,7 @@ using System.Drawing.Drawing2D;
using PckStudio.Classes.FileTypes;
using System.Drawing.Imaging;
using PckStudio.Classes.Utils;
using PckStudio.Classes._3ds.Utils;
namespace PckStudio
{

View File

@@ -14,7 +14,7 @@ using PckStudio.Classes.IO;
using PckStudio.Classes.IO.LOC;
using PckStudio.Classes.IO.PCK;
using PckStudio.Classes.IO.GRF;
using PckStudio.Classes.Utils;
using PckStudio.Classes._3ds.Utils;
using PckStudio.Forms;
using PckStudio.Forms.Utilities;
using PckStudio.Forms.Editor;

View File

@@ -436,9 +436,8 @@
<DependentUpon>programInfo.cs</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Classes\Misc\RenderBase.cs" />
<Compile Include="Classes\Texturing\TextureCodec.cs" />
<Compile Include="Classes\Texturing\TextureUtils.cs" />
<Compile Include="Classes\Utils\3DS\TextureCodec.cs" />
<Compile Include="Classes\Utils\3DS\TextureUtils.cs" />
<EmbeddedResource Include="Forms\Additional-Popups\Loc\AddLanguage.resx">
<DependentUpon>AddLanguage.cs</DependentUpon>
</EmbeddedResource>