From 4aed28f37875ceb8625b0328a6882518e5f7c2a7 Mon Sep 17 00:00:00 2001 From: MeltyPlayer Date: Mon, 23 Oct 2023 14:53:27 -0500 Subject: [PATCH] Sped up ETC1 parsing by optimizing some array accesses. --- FinModelUtility/.editorconfig | 2 +- .../Fin/src/image/io/tile/Etc1TileReader.cs | 24 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/FinModelUtility/.editorconfig b/FinModelUtility/.editorconfig index a0b5450c6..cea05a073 100644 --- a/FinModelUtility/.editorconfig +++ b/FinModelUtility/.editorconfig @@ -149,7 +149,7 @@ csharp_new_line_before_catch = false csharp_new_line_before_else = false csharp_new_line_before_finally = false csharp_new_line_before_members_in_anonymous_types = true -csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_members_in_object_initializers = false csharp_new_line_before_open_brace = none csharp_new_line_between_query_expression_clauses = true diff --git a/FinModelUtility/Fin/Fin/src/image/io/tile/Etc1TileReader.cs b/FinModelUtility/Fin/Fin/src/image/io/tile/Etc1TileReader.cs index 150a7a523..6a4e5d60a 100644 --- a/FinModelUtility/Fin/Fin/src/image/io/tile/Etc1TileReader.cs +++ b/FinModelUtility/Fin/Fin/src/image/io/tile/Etc1TileReader.cs @@ -12,7 +12,7 @@ namespace fin.image.io.tile { /// Stolen from: /// https://github.com/xdanieldzd/Scarlet/blob/master/Scarlet/Drawing/Compression/ETC1.cs /// - public class Etc1TileReader : ITileReader { + public readonly struct Etc1TileReader : ITileReader { private readonly bool hasAlpha_; /* Specs: https://www.khronos.org/registry/gles/extensions/OES/OES_compressed_ETC1_RGB8_texture.txt */ @@ -22,15 +22,15 @@ public class Etc1TileReader : ITileReader { * https://github.com/Gericom/EveryFileExplorer/blob/master/3DS/GPU/Textures.cs * https://github.com/gdkchan/Ohana3DS-Rebirth/blob/master/Ohana3DS%20Rebirth/Ohana/TextureCodec.cs */ - private static readonly int[,] ETC1_MODIFIER_TABLES_ = { - { 2, 8, -2, -8 }, - { 5, 17, -5, -17 }, - { 9, 29, -9, -29 }, - { 13, 42, -13, -42 }, - { 18, 60, -18, -60 }, - { 24, 80, -24, -80 }, - { 33, 106, -33, -106 }, - { 47, 183, -47, -183 } + private static readonly int[] ETC1_MODIFIER_TABLES_ = { + 2, 8, -2, -8, + 5, 17, -5, -17, + 9, 29, -9, -29, + 13, 42, -13, -42, + 18, 60, -18, -60, + 24, 80, -24, -80, + 33, 106, -33, -106, + 47, 183, -47, -183 }; public Etc1TileReader(bool hasAlpha) { @@ -147,13 +147,13 @@ private static void DecodeETC1Block_(Span colors, ulong block) { if ((flipBit == 0x01 && py < 2) || (flipBit == 0x00 && px < 2)) { int modifier = - Etc1TileReader.ETC1_MODIFIER_TABLES_[tableIndex1, index]; + Etc1TileReader.ETC1_MODIFIER_TABLES_[4 * tableIndex1 + index]; colors[indexInPart] = new Rgb24(ClampByte_(r1 + modifier), ClampByte_(g1 + modifier), ClampByte_(b1 + modifier)); } else { int modifier = - Etc1TileReader.ETC1_MODIFIER_TABLES_[tableIndex2, index]; + Etc1TileReader.ETC1_MODIFIER_TABLES_[4 * tableIndex2 + index]; colors[indexInPart] = new Rgb24(ClampByte_(r2 + modifier), ClampByte_(g2 + modifier), ClampByte_(b2 + modifier));