From 3fef1bd99edea90c03b47cf4d65b0feef16546fc Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 30 Sep 2026 07:47:12 +0000 Subject: [PATCH 1/4] docs: update progress [skip ci] --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 99cda23f..e69073db 100644 --- a/README.md +++ b/README.md @@ -53,9 +53,9 @@ Progress | Decompiled | Matched | Linked | Data | |:---:|:---:|:---:|:---:| -| 93.35% | 82.03% | 57.21% | 89.10% | +| 93.35% | 82.08% | 57.94% | 89.10% | -units 768/1027 complete, functions 11879/12563 matched. +units 770/1027 complete, functions 11881/12563 matched. decompiled = code with a C/C++ implementation (objdiff fuzzy), matched = byte-exact code, linked = code actually linked into the DOL, data = byte-exact data -- 2.49.1 From dcc384b7fa707623102ce8ad28ad52f92e9b2457 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Wed, 30 Sep 2026 03:03:53 -0500 Subject: [PATCH 2/4] misc: 8 small setting/SDK units, 45/54 functions (worker 4db219ff) (#354) --- README.md | 4 +- libs/RVL_SDK/src/kbd/kbd_lib_map_us.c | 240 ++++++++++++ libs/RVL_SDK/src/kpr/kpr_lib.c | 339 +++++++++++++++++ libs/RVL_SDK/src/nup/nup_mem.cpp | 51 +++ src/scene/setting/AOSSLink.c | 352 ++++++++++++++++++ src/scene/setting/iplRakuRakuThread.cpp | 284 ++++++++++++++ src/scene/setting/iplSensitivity.cpp | 85 +++++ src/scene/setting/iplUSBAP.cpp | 156 ++++++++ src/scene/setting/iplUSBAPThread.cpp | 67 ++++ tools/decomp-assist/sol-low-batch.attempts.md | 88 +++++ 10 files changed, 1664 insertions(+), 2 deletions(-) create mode 100644 libs/RVL_SDK/src/kbd/kbd_lib_map_us.c create mode 100644 libs/RVL_SDK/src/kpr/kpr_lib.c create mode 100644 libs/RVL_SDK/src/nup/nup_mem.cpp create mode 100644 src/scene/setting/AOSSLink.c create mode 100644 src/scene/setting/iplRakuRakuThread.cpp create mode 100644 src/scene/setting/iplSensitivity.cpp create mode 100644 src/scene/setting/iplUSBAP.cpp create mode 100644 src/scene/setting/iplUSBAPThread.cpp create mode 100644 tools/decomp-assist/sol-low-batch.attempts.md diff --git a/README.md b/README.md index e69073db..17d8cea0 100644 --- a/README.md +++ b/README.md @@ -53,9 +53,9 @@ Progress | Decompiled | Matched | Linked | Data | |:---:|:---:|:---:|:---:| -| 93.35% | 82.08% | 57.94% | 89.10% | +| 93.64% | 82.24% | 57.94% | 89.35% | -units 770/1027 complete, functions 11881/12563 matched. +units 770/1027 complete, functions 11926/12563 matched. decompiled = code with a C/C++ implementation (objdiff fuzzy), matched = byte-exact code, linked = code actually linked into the DOL, data = byte-exact data diff --git a/libs/RVL_SDK/src/kbd/kbd_lib_map_us.c b/libs/RVL_SDK/src/kbd/kbd_lib_map_us.c new file mode 100644 index 00000000..d14e0743 --- /dev/null +++ b/libs/RVL_SDK/src/kbd/kbd_lib_map_us.c @@ -0,0 +1,240 @@ +#include + +void kbdInitMapIntl(void); +void kbdInitMap(u32 country, u8 codeCount, u8 flags, u16* keyMap, u16* modifierMap, + u8 lockIndex, u8 shiftIndex, u8 altIndex, u8 maxCode, s32 keypadType); + +static u16 kbdKeyMapCANADA[400] = { + 0x003F, 0x0061, 0x0041, 0x0000, 0x003F, 0x0062, 0x0042, 0x0000, + 0x003F, 0x0063, 0x0043, 0x0000, 0x003F, 0x0064, 0x0044, 0x0000, + 0x003F, 0x0065, 0x0045, 0x0000, 0x003F, 0x0066, 0x0046, 0x0000, + 0x003F, 0x0067, 0x0047, 0x0000, 0x003F, 0x0068, 0x0048, 0x0000, + 0x003F, 0x0069, 0x0049, 0x0000, 0x003F, 0x006A, 0x004A, 0x0000, + 0x003F, 0x006B, 0x004B, 0x0000, 0x003F, 0x006C, 0x004C, 0x0000, + 0x003F, 0x006D, 0x004D, 0x0000, 0x003F, 0x006E, 0x004E, 0x0000, + 0x003F, 0x006F, 0x004F, 0x0000, 0x003F, 0x0070, 0x0050, 0x0000, + 0x003F, 0x0071, 0x0051, 0x0000, 0x003F, 0x0072, 0x0052, 0x0000, + 0x003F, 0x0073, 0x0053, 0x0000, 0x003F, 0x0074, 0x0054, 0x0000, + 0x003F, 0x0075, 0x0055, 0x0000, 0x003F, 0x0076, 0x0056, 0x0000, + 0x003F, 0x0077, 0x0057, 0x0000, 0x003F, 0x0078, 0x0058, 0x00BB, + 0x003F, 0x0079, 0x0059, 0x0000, 0x003F, 0x007A, 0x005A, 0x00AB, + 0x0000, 0x0031, 0x0021, 0x0000, 0x0000, 0x0032, 0x0040, 0x0000, + 0x0000, 0x0033, 0x0023, 0x0000, 0x0000, 0x0034, 0x0024, 0x0000, + 0x0000, 0x0035, 0x0025, 0x0000, 0x0000, 0x0036, 0x003F, 0x0000, + 0x0000, 0x0037, 0x0026, 0x007B, 0x0000, 0x0038, 0x002A, 0x007D, + 0x0000, 0x0039, 0x0028, 0x005B, 0x0000, 0x0030, 0x0029, 0x005D, + 0x0000, 0xF1CD, 0xF1CD, 0xF1CD, 0x0000, 0xF1DB, 0xF1DB, 0xF1DB, + 0x0000, 0xF1C8, 0xF1C8, 0xF1C8, 0x0000, 0xF1C9, 0xF1C9, 0xF1C9, + 0x0000, 0x0020, 0x0020, 0x0020, 0x0000, 0x002D, 0x005F, 0x0000, + 0x0000, 0x003D, 0x002B, 0x00AC, 0x0000, 0x0302, 0x0308, 0x0300, + 0x003F, 0x00E7, 0x00C7, 0x0303, 0x0000, 0x0000, 0x0000, 0x0000, + 0x003F, 0x00E0, 0x00C0, 0x0000, 0x0000, 0x003B, 0x003A, 0x00B0, + 0x003F, 0x00E8, 0x00C8, 0x0000, 0x0000, 0x002F, 0x005C, 0x007C, + 0x0000, 0x002C, 0x0027, 0x003C, 0x0000, 0x002E, 0x0022, 0x003E, + 0x003F, 0x00E9, 0x00C9, 0x0000, 0xC000, 0xF008, 0xF008, 0xF008, + 0x0000, 0xF061, 0xF061, 0xF061, 0x0000, 0xF062, 0xF062, 0xF062, + 0x0000, 0xF063, 0xF063, 0xF063, 0x0000, 0xF064, 0xF064, 0xF064, + 0x0000, 0xF065, 0xF065, 0xF065, 0x0000, 0xF066, 0xF066, 0xF066, + 0x0000, 0xF067, 0xF067, 0xF067, 0x0000, 0xF068, 0xF068, 0xF068, + 0x0000, 0xF069, 0xF069, 0xF069, 0x0000, 0xF06A, 0xF06A, 0xF06A, + 0x0000, 0xF06B, 0xF06B, 0xF06B, 0x0000, 0xF06C, 0xF06C, 0xF06C, + 0xC000, 0xF020, 0xF020, 0xF020, 0xC000, 0xF021, 0xF021, 0xF021, + 0xC000, 0xF022, 0xF022, 0xF022, 0x0000, 0xF1B0, 0xF1B0, 0xF1B0, + 0x0000, 0xF1B7, 0xF1B7, 0xF1B7, 0x0000, 0xF1B9, 0xF1B9, 0xF1B9, + 0x0000, 0xF1AE, 0xF1AE, 0xF1AE, 0x0000, 0xF1B1, 0xF1B1, 0xF1B1, + 0x0000, 0xF1B3, 0xF1B3, 0xF1B3, 0x0000, 0xF1B6, 0xF1B6, 0xF1B6, + 0x0000, 0xF1B4, 0xF1B4, 0xF1B4, 0x0000, 0xF1B2, 0xF1B2, 0xF1B2, + 0x0000, 0xF1B8, 0xF1B8, 0xF1B8, 0xC000, 0xF007, 0xF007, 0xF007, + 0x0000, 0xF12F, 0xF12F, 0xF12F, 0x0000, 0xF12A, 0xF12A, 0xF12A, + 0x0000, 0xF12D, 0xF12D, 0xF12D, 0x0000, 0xF12B, 0xF12B, 0xF12B, + 0x0000, 0xF10D, 0xF10D, 0xF10D, 0x80FF, 0xF171, 0xF131, 0x0000, + 0x80FF, 0xF172, 0xF132, 0x0000, 0x80FF, 0xF173, 0xF133, 0x0000, + 0x80FF, 0xF174, 0xF134, 0x0000, 0x80FF, 0xF175, 0xF135, 0x0000, + 0x80FF, 0xF176, 0xF136, 0x0000, 0x80FF, 0xF177, 0xF137, 0x0000, + 0x80FF, 0xF178, 0xF138, 0x0000, 0x80FF, 0xF179, 0xF139, 0x0000, + 0x80FF, 0xF170, 0xF130, 0x0000, 0x80FF, 0xF16E, 0xF12E, 0x0000, + 0x003F, 0x00F9, 0x00D9, 0x0000, 0xC000, 0xF02F, 0xF02F, 0xF02F, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xF13D, 0xF13D, 0xF13D, +}; + +static u16 kbdModifierMapCANADA[32] = { + 0xC000, 0xF000, 0xF000, 0xF000, 0xC000, 0xF001, 0xF001, 0xF001, + 0xC000, 0xF002, 0xF002, 0xF002, 0xC000, 0xF003, 0xF003, 0xF003, + 0xC000, 0xF000, 0xF000, 0xF000, 0xC000, 0xF001, 0xF001, 0xF001, + 0xC000, 0xF005, 0xF005, 0xF005, 0xC000, 0xF003, 0xF003, 0xF003, +}; + +static u16 kbdKeyMapCANADA_FR[400] = { + 0x003F, 0x0061, 0x0041, 0x0000, 0x003F, 0x0062, 0x0042, 0x0000, + 0x003F, 0x0063, 0x0043, 0x0000, 0x003F, 0x0064, 0x0044, 0x0000, + 0x003F, 0x0065, 0x0045, 0x0000, 0x003F, 0x0066, 0x0046, 0x0000, + 0x003F, 0x0067, 0x0047, 0x0000, 0x003F, 0x0068, 0x0048, 0x0000, + 0x003F, 0x0069, 0x0049, 0x0000, 0x003F, 0x006A, 0x004A, 0x0000, + 0x003F, 0x006B, 0x004B, 0x0000, 0x003F, 0x006C, 0x004C, 0x0000, + 0x003F, 0x006D, 0x004D, 0x00B5, 0x003F, 0x006E, 0x004E, 0x0000, + 0x003F, 0x006F, 0x004F, 0x00A7, 0x003F, 0x0070, 0x0050, 0x00B6, + 0x003F, 0x0071, 0x0051, 0x0000, 0x003F, 0x0072, 0x0052, 0x0000, + 0x003F, 0x0073, 0x0053, 0x0000, 0x003F, 0x0074, 0x0054, 0x0000, + 0x003F, 0x0075, 0x0055, 0x0000, 0x003F, 0x0076, 0x0056, 0x0000, + 0x003F, 0x0077, 0x0057, 0x0000, 0x003F, 0x0078, 0x0058, 0x0000, + 0x003F, 0x0079, 0x0059, 0x0000, 0x003F, 0x007A, 0x005A, 0x0000, + 0x0000, 0x0031, 0x0021, 0x00B1, 0x0000, 0x0032, 0x0022, 0x0040, + 0x0000, 0x0033, 0x002F, 0x00A3, 0x0000, 0x0034, 0x0024, 0x00A2, + 0x0000, 0x0035, 0x0025, 0x00A4, 0x0000, 0x0036, 0x003F, 0x00AC, + 0x0000, 0x0037, 0x0026, 0x00A6, 0x0000, 0x0038, 0x002A, 0x00B2, + 0x0000, 0x0039, 0x0028, 0x00B3, 0x0000, 0x0030, 0x0029, 0x00BC, + 0x0000, 0xF1CD, 0xF1CD, 0xF1CD, 0x0000, 0xF1DB, 0xF1DB, 0xF1DB, + 0x0000, 0xF1C8, 0xF1C8, 0xF1C8, 0x0000, 0xF1C9, 0xF1C9, 0xF1C9, + 0x0000, 0x0020, 0x0020, 0x0020, 0x0000, 0x002D, 0x005F, 0x00BD, + 0x0000, 0x003D, 0x002B, 0x00BE, 0x0000, 0x0302, 0x0302, 0x005B, + 0x0000, 0x0327, 0x0308, 0x005D, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x003C, 0x003E, 0x007D, 0x0000, 0x003B, 0x003A, 0x007E, + 0x0000, 0x0300, 0x0300, 0x007B, 0x0000, 0x0023, 0x007C, 0x005C, + 0x0000, 0x002C, 0x0027, 0x00AF, 0x0000, 0x002E, 0x002E, 0x002D, + 0x003F, 0x00E9, 0x00C9, 0x0301, 0xC000, 0xF008, 0xF008, 0xF008, + 0x0000, 0xF061, 0xF061, 0xF061, 0x0000, 0xF062, 0xF062, 0xF062, + 0x0000, 0xF063, 0xF063, 0xF063, 0x0000, 0xF064, 0xF064, 0xF064, + 0x0000, 0xF065, 0xF065, 0xF065, 0x0000, 0xF066, 0xF066, 0xF066, + 0x0000, 0xF067, 0xF067, 0xF067, 0x0000, 0xF068, 0xF068, 0xF068, + 0x0000, 0xF069, 0xF069, 0xF069, 0x0000, 0xF06A, 0xF06A, 0xF06A, + 0x0000, 0xF06B, 0xF06B, 0xF06B, 0x0000, 0xF06C, 0xF06C, 0xF06C, + 0xC000, 0xF020, 0xF020, 0xF020, 0xC000, 0xF021, 0xF021, 0xF021, + 0xC000, 0xF022, 0xF022, 0xF022, 0x0000, 0xF1B0, 0xF1B0, 0xF1B0, + 0x0000, 0xF1B7, 0xF1B7, 0xF1B7, 0x0000, 0xF1B9, 0xF1B9, 0xF1B9, + 0x0000, 0xF1AE, 0xF1AE, 0xF1AE, 0x0000, 0xF1B1, 0xF1B1, 0xF1B1, + 0x0000, 0xF1B3, 0xF1B3, 0xF1B3, 0x0000, 0xF1B6, 0xF1B6, 0xF1B6, + 0x0000, 0xF1B4, 0xF1B4, 0xF1B4, 0x0000, 0xF1B2, 0xF1B2, 0xF1B2, + 0x0000, 0xF1B8, 0xF1B8, 0xF1B8, 0xC000, 0xF007, 0xF007, 0xF007, + 0x0000, 0xF12F, 0xF12F, 0xF12F, 0x0000, 0xF12A, 0xF12A, 0xF12A, + 0x0000, 0xF12D, 0xF12D, 0xF12D, 0x0000, 0xF12B, 0xF12B, 0xF12B, + 0x0000, 0xF10D, 0xF10D, 0xF10D, 0x80FF, 0xF171, 0xF131, 0x0000, + 0x80FF, 0xF172, 0xF132, 0x0000, 0x80FF, 0xF173, 0xF133, 0x0000, + 0x80FF, 0xF174, 0xF134, 0x0000, 0x80FF, 0xF175, 0xF135, 0x0000, + 0x80FF, 0xF176, 0xF136, 0x0000, 0x80FF, 0xF177, 0xF137, 0x0000, + 0x80FF, 0xF178, 0xF138, 0x0000, 0x80FF, 0xF179, 0xF139, 0x0000, + 0x80FF, 0xF170, 0xF130, 0x0000, 0x80FF, 0xF16E, 0xF12E, 0x0000, + 0x0000, 0x00AB, 0x00BB, 0x00B0, 0x0000, 0xF02F, 0xF02F, 0xF02F, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xF13D, 0xF13D, 0xF13D, +}; + +static u16 kbdModifierMapCANADA_FR[32] = { + 0xC000, 0xF000, 0xF000, 0xF000, 0xC000, 0xF001, 0xF001, 0xF001, + 0xC000, 0xF002, 0xF002, 0xF002, 0xC000, 0xF003, 0xF003, 0xF003, + 0xC000, 0xF000, 0xF000, 0xF000, 0xC000, 0xF001, 0xF001, 0xF001, + 0xC000, 0xF005, 0xF005, 0xF005, 0xC000, 0xF003, 0xF003, 0xF003, +}; + +static u16 kbdKeyMapLATIN_AMERICA[400] = { + 0x003F, 0x0061, 0x0041, 0x0000, 0x003F, 0x0062, 0x0042, 0x0000, + 0x003F, 0x0063, 0x0043, 0x0000, 0x003F, 0x0064, 0x0044, 0x0000, + 0x003F, 0x0065, 0x0045, 0x0000, 0x003F, 0x0066, 0x0046, 0x0000, + 0x003F, 0x0067, 0x0047, 0x0000, 0x003F, 0x0068, 0x0048, 0x0000, + 0x003F, 0x0069, 0x0049, 0x0000, 0x003F, 0x006A, 0x004A, 0x0000, + 0x003F, 0x006B, 0x004B, 0x0000, 0x003F, 0x006C, 0x004C, 0x0000, + 0x003F, 0x006D, 0x004D, 0x0000, 0x003F, 0x006E, 0x004E, 0x0000, + 0x003F, 0x006F, 0x004F, 0x0000, 0x003F, 0x0070, 0x0050, 0x0000, + 0x003F, 0x0071, 0x0051, 0x0040, 0x003F, 0x0072, 0x0052, 0x0000, + 0x003F, 0x0073, 0x0053, 0x0000, 0x003F, 0x0074, 0x0054, 0x0000, + 0x003F, 0x0075, 0x0055, 0x0000, 0x003F, 0x0076, 0x0056, 0x0000, + 0x003F, 0x0077, 0x0057, 0x0000, 0x003F, 0x0078, 0x0058, 0x0000, + 0x003F, 0x0079, 0x0059, 0x0000, 0x003F, 0x007A, 0x005A, 0x0000, + 0x0000, 0x0031, 0x0021, 0x0000, 0x0000, 0x0032, 0x0022, 0x0000, + 0x0000, 0x0033, 0x0023, 0x0000, 0x0000, 0x0034, 0x0024, 0x0000, + 0x0000, 0x0035, 0x0025, 0x0000, 0x0000, 0x0036, 0x0026, 0x0000, + 0x0000, 0x0037, 0x002F, 0x0000, 0x0000, 0x0038, 0x0028, 0x0000, + 0x0000, 0x0039, 0x0029, 0x0000, 0x0000, 0x0030, 0x003D, 0x0000, + 0x0000, 0xF1CD, 0xF1CD, 0xF1CD, 0x0000, 0xF1DB, 0xF1DB, 0xF1DB, + 0x0000, 0xF1C8, 0xF1C8, 0xF1C8, 0x0000, 0xF1C9, 0xF1C9, 0xF1C9, + 0x0000, 0x0020, 0x0020, 0x0020, 0x0000, 0x0027, 0x003F, 0x005C, + 0x0000, 0x00BF, 0x00A1, 0x0000, 0x0000, 0x0301, 0x0308, 0x0000, + 0x0000, 0x002B, 0x002A, 0x007E, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x007D, 0x005D, 0x0300, 0x003F, 0x00F1, 0x00D1, 0x0000, + 0x0000, 0x007B, 0x005B, 0x0302, 0x0000, 0x007C, 0x00B0, 0x00AC, + 0x0000, 0x002C, 0x003B, 0x0000, 0x0000, 0x002E, 0x003A, 0x0000, + 0x0000, 0x002D, 0x005F, 0x0000, 0xC000, 0xF008, 0xF008, 0xF008, + 0x0000, 0xF061, 0xF061, 0xF061, 0x0000, 0xF062, 0xF062, 0xF062, + 0x0000, 0xF063, 0xF063, 0xF063, 0x0000, 0xF064, 0xF064, 0xF064, + 0x0000, 0xF065, 0xF065, 0xF065, 0x0000, 0xF066, 0xF066, 0xF066, + 0x0000, 0xF067, 0xF067, 0xF067, 0x0000, 0xF068, 0xF068, 0xF068, + 0x0000, 0xF069, 0xF069, 0xF069, 0x0000, 0xF06A, 0xF06A, 0xF06A, + 0x0000, 0xF06B, 0xF06B, 0xF06B, 0x0000, 0xF06C, 0xF06C, 0xF06C, + 0xC000, 0xF020, 0xF020, 0xF020, 0xC000, 0xF021, 0xF021, 0xF021, + 0xC000, 0xF022, 0xF022, 0xF022, 0x0000, 0xF1B0, 0xF1B0, 0xF1B0, + 0x0000, 0xF1B7, 0xF1B7, 0xF1B7, 0x0000, 0xF1B9, 0xF1B9, 0xF1B9, + 0x0000, 0xF1AE, 0xF1AE, 0xF1AE, 0x0000, 0xF1B1, 0xF1B1, 0xF1B1, + 0x0000, 0xF1B3, 0xF1B3, 0xF1B3, 0x0000, 0xF1B6, 0xF1B6, 0xF1B6, + 0x0000, 0xF1B4, 0xF1B4, 0xF1B4, 0x0000, 0xF1B2, 0xF1B2, 0xF1B2, + 0x0000, 0xF1B8, 0xF1B8, 0xF1B8, 0xC000, 0xF007, 0xF007, 0xF007, + 0x0000, 0xF12F, 0xF12F, 0xF12F, 0x0000, 0xF12A, 0xF12A, 0xF12A, + 0x0000, 0xF12D, 0xF12D, 0xF12D, 0x0000, 0xF12B, 0xF12B, 0xF12B, + 0x0000, 0xF10D, 0xF10D, 0xF10D, 0x80FF, 0xF171, 0xF131, 0x0000, + 0x80FF, 0xF172, 0xF132, 0x0000, 0x80FF, 0xF173, 0xF133, 0x0000, + 0x80FF, 0xF174, 0xF134, 0x0000, 0x80FF, 0xF175, 0xF135, 0x0000, + 0x80FF, 0xF176, 0xF136, 0x0000, 0x80FF, 0xF177, 0xF137, 0x0000, + 0x80FF, 0xF178, 0xF138, 0x0000, 0x80FF, 0xF179, 0xF139, 0x0000, + 0x80FF, 0xF170, 0xF130, 0x0000, 0x80FF, 0xF16E, 0xF12E, 0x0000, + 0x0000, 0x003C, 0x003E, 0x0000, 0xC000, 0xF02F, 0xF02F, 0xF02F, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xF13D, 0xF13D, 0xF13D, +}; + +static u16 kbdModifierMapLATIN_AMERICA[32] = { + 0xC000, 0xF000, 0xF000, 0xF000, 0xC000, 0xF001, 0xF001, 0xF001, + 0xC000, 0xF002, 0xF002, 0xF002, 0xC000, 0xF003, 0xF003, 0xF003, + 0xC000, 0xF000, 0xF000, 0xF000, 0xC000, 0xF001, 0xF001, 0xF001, + 0xC000, 0xF005, 0xF005, 0xF005, 0xC000, 0xF003, 0xF003, 0xF003, +}; + +static u16 kbdKeyMapUSA[300] = { + 0x003F, 0x0061, 0x0041, 0x003F, 0x0062, 0x0042, 0x003F, 0x0063, + 0x0043, 0x003F, 0x0064, 0x0044, 0x003F, 0x0065, 0x0045, 0x003F, + 0x0066, 0x0046, 0x003F, 0x0067, 0x0047, 0x003F, 0x0068, 0x0048, + 0x003F, 0x0069, 0x0049, 0x003F, 0x006A, 0x004A, 0x003F, 0x006B, + 0x004B, 0x003F, 0x006C, 0x004C, 0x003F, 0x006D, 0x004D, 0x003F, + 0x006E, 0x004E, 0x003F, 0x006F, 0x004F, 0x003F, 0x0070, 0x0050, + 0x003F, 0x0071, 0x0051, 0x003F, 0x0072, 0x0052, 0x003F, 0x0073, + 0x0053, 0x003F, 0x0074, 0x0054, 0x003F, 0x0075, 0x0055, 0x003F, + 0x0076, 0x0056, 0x003F, 0x0077, 0x0057, 0x003F, 0x0078, 0x0058, + 0x003F, 0x0079, 0x0059, 0x003F, 0x007A, 0x005A, 0x0000, 0x0031, + 0x0021, 0x0000, 0x0032, 0x0040, 0x0000, 0x0033, 0x0023, 0x0000, + 0x0034, 0x0024, 0x0000, 0x0035, 0x0025, 0x0000, 0x0036, 0x005E, + 0x0000, 0x0037, 0x0026, 0x0000, 0x0038, 0x002A, 0x0000, 0x0039, + 0x0028, 0x0000, 0x0030, 0x0029, 0x0000, 0xF1CD, 0xF1CD, 0x0000, + 0xF1DB, 0xF1DB, 0x0000, 0xF1C8, 0xF1C8, 0x0000, 0xF1C9, 0xF1C9, + 0x0000, 0x0020, 0x0020, 0x0000, 0x002D, 0x005F, 0x0000, 0x003D, + 0x002B, 0x0000, 0x005B, 0x007B, 0x0000, 0x005D, 0x007D, 0x0000, + 0x005C, 0x007C, 0x0000, 0x0000, 0x0000, 0x0000, 0x003B, 0x003A, + 0x0000, 0x0027, 0x0022, 0x0000, 0x0060, 0x007E, 0x0000, 0x002C, + 0x003C, 0x0000, 0x002E, 0x003E, 0x0000, 0x002F, 0x003F, 0xC000, + 0xF008, 0xF008, 0x0000, 0xF061, 0xF061, 0x0000, 0xF062, 0xF062, + 0x0000, 0xF063, 0xF063, 0x0000, 0xF064, 0xF064, 0x0000, 0xF065, + 0xF065, 0x0000, 0xF066, 0xF066, 0x0000, 0xF067, 0xF067, 0x0000, + 0xF068, 0xF068, 0x0000, 0xF069, 0xF069, 0x0000, 0xF06A, 0xF06A, + 0x0000, 0xF06B, 0xF06B, 0x0000, 0xF06C, 0xF06C, 0xC000, 0xF020, + 0xF020, 0xC000, 0xF021, 0xF021, 0xC000, 0xF022, 0xF022, 0x0000, + 0xF1B0, 0xF1B0, 0x0000, 0xF1B7, 0xF1B7, 0x0000, 0xF1B9, 0xF1B9, + 0x0000, 0xF1AE, 0xF1AE, 0x0000, 0xF1B1, 0xF1B1, 0x0000, 0xF1B3, + 0xF1B3, 0x0000, 0xF1B6, 0xF1B6, 0x0000, 0xF1B4, 0xF1B4, 0x0000, + 0xF1B2, 0xF1B2, 0x0000, 0xF1B8, 0xF1B8, 0xC000, 0xF007, 0xF007, + 0x0000, 0xF12F, 0xF12F, 0x0000, 0xF12A, 0xF12A, 0x0000, 0xF12D, + 0xF12D, 0x0000, 0xF12B, 0xF12B, 0x0000, 0xF10D, 0xF10D, 0x80FF, + 0xF171, 0xF131, 0x80FF, 0xF172, 0xF132, 0x80FF, 0xF173, 0xF133, + 0x80FF, 0xF174, 0xF134, 0x80FF, 0xF175, 0xF135, 0x80FF, 0xF176, + 0xF136, 0x80FF, 0xF177, 0xF137, 0x80FF, 0xF178, 0xF138, 0x80FF, + 0xF179, 0xF139, 0x80FF, 0xF170, 0xF130, 0x80FF, 0xF16E, 0xF12E, + 0x0000, 0x0000, 0x0000, 0xC000, 0xF02F, 0xF02F, 0x0000, 0x0000, + 0x0000, 0x0000, 0xF13D, 0xF13D, +}; + +static u16 kbdModifierMapUSA[24] = { + 0xC000, 0xF000, 0xF000, 0xC000, 0xF001, 0xF001, 0xC000, 0xF002, + 0xF002, 0xC000, 0xF003, 0xF003, 0xC000, 0xF000, 0xF000, 0xC000, + 0xF001, 0xF001, 0xC000, 0xF002, 0xF002, 0xC000, 0xF003, 0xF003, +}; + +void KBDInitRegionUS(void) { + kbdInitMapIntl(); + kbdInitMap(3, 4, 0x10, kbdKeyMapCANADA, kbdModifierMapCANADA, 0, 0, 3, 100, 2); + kbdInitMap(4, 4, 0x10, kbdKeyMapCANADA_FR, kbdModifierMapCANADA_FR, 0, 0, 3, 100, 2); + kbdInitMap(17, 4, 0x10, kbdKeyMapLATIN_AMERICA, kbdModifierMapLATIN_AMERICA, 0, 0, 3, 100, 2); + kbdInitMap(33, 3, 0, kbdKeyMapUSA, kbdModifierMapUSA, 0, 0, 0, 100, 0); +} diff --git a/libs/RVL_SDK/src/kpr/kpr_lib.c b/libs/RVL_SDK/src/kpr/kpr_lib.c new file mode 100644 index 00000000..6bfd1fb0 --- /dev/null +++ b/libs/RVL_SDK/src/kpr/kpr_lib.c @@ -0,0 +1,339 @@ +#include +#include + +struct KPRDeadKey { + u16 accent; + u16 base; + u16 composed; +}; + +const struct KPRDeadKey kprDeadKeyMap[] = { + {0x0300, 0x0300, 0x0060}, + {0x0300, 0x0041, 0x00C0}, + {0x0300, 0x0045, 0x00C8}, + {0x0300, 0x0049, 0x00CC}, + {0x0300, 0x004F, 0x00D2}, + {0x0300, 0x0055, 0x00D9}, + {0x0300, 0x0061, 0x00E0}, + {0x0300, 0x0065, 0x00E8}, + {0x0300, 0x0069, 0x00EC}, + {0x0300, 0x006F, 0x00F2}, + {0x0300, 0x0075, 0x00F9}, + {0x0301, 0x0301, 0x00B4}, + {0x0301, 0x0041, 0x00C1}, + {0x0301, 0x0045, 0x00C9}, + {0x0301, 0x0049, 0x00CD}, + {0x0301, 0x004F, 0x00D3}, + {0x0301, 0x0055, 0x00DA}, + {0x0301, 0x0059, 0x00DD}, + {0x0301, 0x0061, 0x00E1}, + {0x0301, 0x0065, 0x00E9}, + {0x0301, 0x0069, 0x00ED}, + {0x0301, 0x006F, 0x00F3}, + {0x0301, 0x0075, 0x00FA}, + {0x0301, 0x0079, 0x00FD}, + {0x0302, 0x0302, 0x005E}, + {0x0302, 0x0041, 0x00C2}, + {0x0302, 0x0045, 0x00CA}, + {0x0302, 0x0049, 0x00CE}, + {0x0302, 0x004F, 0x00D4}, + {0x0302, 0x0055, 0x00DB}, + {0x0302, 0x0061, 0x00E2}, + {0x0302, 0x0065, 0x00EA}, + {0x0302, 0x0069, 0x00EE}, + {0x0302, 0x006F, 0x00F4}, + {0x0302, 0x0075, 0x00FB}, + {0x0303, 0x0303, 0x007E}, + {0x0303, 0x0041, 0x00C3}, + {0x0303, 0x004E, 0x00D1}, + {0x0303, 0x004F, 0x00D5}, + {0x0303, 0x0061, 0x00E3}, + {0x0303, 0x006E, 0x00F1}, + {0x0303, 0x006F, 0x00F5}, + {0x0308, 0x0308, 0x00A8}, + {0x0308, 0x0041, 0x00C4}, + {0x0308, 0x0045, 0x00CB}, + {0x0308, 0x0049, 0x00CF}, + {0x0308, 0x004F, 0x00D6}, + {0x0308, 0x0055, 0x00DC}, + {0x0308, 0x0059, 0x0178}, + {0x0308, 0x0061, 0x00E4}, + {0x0308, 0x0065, 0x00EB}, + {0x0308, 0x0069, 0x00EF}, + {0x0308, 0x006F, 0x00F6}, + {0x0308, 0x0075, 0x00FC}, + {0x0308, 0x0079, 0x00FF}, + {0x0327, 0x0327, 0x00B8}, + {0x0327, 0x0043, 0x00C7}, + {0x0327, 0x0063, 0x00E7}, + {0x030D, 0x030D, 0x0027}, + {0x030D, 0x0041, 0x00C1}, + {0x030D, 0x0045, 0x00C9}, + {0x030D, 0x0049, 0x00CD}, + {0x030D, 0x004F, 0x00D3}, + {0x030D, 0x0055, 0x00DA}, + {0x030D, 0x0059, 0x00DD}, + {0x030D, 0x0043, 0x00C7}, + {0x030D, 0x0061, 0x00E1}, + {0x030D, 0x0065, 0x00E9}, + {0x030D, 0x0069, 0x00ED}, + {0x030D, 0x006F, 0x00F3}, + {0x030D, 0x0075, 0x00FA}, + {0x030D, 0x0079, 0x00FD}, + {0x030D, 0x0063, 0x00E7}, + {0x030E, 0x030E, 0x0022}, + {0x030E, 0x0041, 0x00C4}, + {0x030E, 0x0045, 0x00CB}, + {0x030E, 0x0049, 0x00CF}, + {0x030E, 0x004F, 0x00D6}, + {0x030E, 0x0055, 0x00DC}, + {0x030E, 0x0059, 0x0178}, + {0x030E, 0x0061, 0x00E4}, + {0x030E, 0x0065, 0x00EB}, + {0x030E, 0x0069, 0x00EF}, + {0x030E, 0x006F, 0x00F6}, + {0x030E, 0x0075, 0x00FC}, + {0x030E, 0x0079, 0x00FF}, + {0x0344, 0x0344, 0x0385}, + {0x0344, 0x03B9, 0x0390}, + {0x0344, 0x03C5, 0x03B0}, + {0x0308, 0x0399, 0x03AA}, + {0x0308, 0x03A5, 0x03AB}, + {0x0308, 0x03B9, 0x03CA}, + {0x0308, 0x03C5, 0x03CB}, + {0x0301, 0x0391, 0x0386}, + {0x0301, 0x0395, 0x0388}, + {0x0301, 0x0397, 0x0389}, + {0x0301, 0x0399, 0x038A}, + {0x0301, 0x039F, 0x038C}, + {0x0301, 0x03A5, 0x038E}, + {0x0301, 0x03A9, 0x038F}, + {0x0301, 0x03B1, 0x03AC}, + {0x0301, 0x03B5, 0x03AD}, + {0x0301, 0x03B7, 0x03AE}, + {0x0301, 0x03B9, 0x03AF}, + {0x0301, 0x03BF, 0x03CC}, + {0x0301, 0x03C5, 0x03CD}, + {0x0301, 0x03C9, 0x03CE}, + {0x0000, 0x0000, 0x0000}, +}; + +const u16 kprLookupTable1252[] = { + 0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, + 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x017D, 0x0000, + 0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, + 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0000, 0x017E, 0x0178, +}; + +const u16 kprLookupTable437[] = { + 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, + 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5, + 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, + 0x00FF, 0x00D6, 0x00DC, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192, + 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, + 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, + 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, + 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, + 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, + 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, + 0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, + 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229, + 0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, + 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0, +}; + +static void (*kprProcDeadKeysFP)(KPRQueue* queue); +static void (*kprProcRomajiFP)(KPRQueue* queue); +const char* __KPRVersion = "<< RVL_SDK - KPR \trelease build: Apr 20 2010 11:21:44 (0x4199_60831) >>"; + +void KPRProcessDeadKeys(KPRQueue* queue); +BOOL KPRProcessAltKeypad(KPRQueue* queue, u16 character); + +void KPRInitRegionUS(void) { + kprProcDeadKeysFP = KPRProcessDeadKeys; +} + +void KPRInitQueue(KPRQueue* queue) { + static u8 once; + if (!once) { + OSRegisterVersion(__KPRVersion); + once = TRUE; + } + queue->mode = KPR_MODE_ALT_KEYPAD; + queue->oCount = 0; + queue->iCount = 0; + queue->altVal = 0; +} + +void KPRClearQueue(KPRQueue* queue) { + queue->oCount = 0; + queue->iCount = 0; + queue->altVal = 0; +} + +void KPRSetMode(KPRQueue* queue, KPRMode mode) { + queue->mode = mode; + queue->oCount = 0; + queue->iCount = 0; + queue->altVal = 0; +} + +u8 KPRPutChar(KPRQueue* queue, u16 character) { + BOOL interrupts; + if (queue->oCount + queue->iCount + 1 >= 5) { + OSPanic("kpr_lib.c", 215, "KPRPutChar: Overflow"); + } + interrupts = OSDisableInterrupts(); + if (!(queue->mode & KPR_MODE_ALT_KEYPAD) || !KPRProcessAltKeypad(queue, character)) { + queue->text[queue->oCount + queue->iCount] = character; + ++queue->iCount; + if (queue->mode & KPR_MODE_DEADKEY) { + kprProcDeadKeysFP(queue); + } else if ((queue->mode & KPR_MODE_JP_ROMAJI_KATAKANA) || (queue->mode & KPR_MODE_JP_ROMAJI_HIRAGANA)) { + kprProcRomajiFP(queue); + } else { + queue->oCount = queue->iCount; + queue->iCount = 0; + } + if (character == 0xFFFF) { + --queue->oCount; + } + } + OSRestoreInterrupts(interrupts); + return queue->oCount; +} + +u16 KPRGetChar(KPRQueue* queue) { + BOOL interrupts; + u16 character; + u16* source; + u32 index; + if (!queue->oCount) { + return 0; + } + interrupts = OSDisableInterrupts(); + character = queue->text[0]; + source = &queue->text[1]; + for (index = 1; index < queue->iCount + queue->oCount; ++index) { + source[-1] = *source; + ++source; + } + --queue->oCount; + OSRestoreInterrupts(interrupts); + return character; +} + +u8 KPRLookAhead(KPRQueue* queue, u16* destination, u32 capacity) { + BOOL interrupts; + u8 index; + if (destination == NULL || capacity == 0) { + return queue->iCount + queue->oCount; + } + interrupts = OSDisableInterrupts(); + for (index = 0; index < queue->iCount + queue->oCount && index < capacity; ++index) { + destination[index] = queue->text[index]; + } + if (index < capacity) { + destination[index] = 0; + } + OSRestoreInterrupts(interrupts); + return queue->iCount + queue->oCount; +} + +BOOL KPRProcessAltKeypad(KPRQueue* queue, u16 character) { + if (queue->altVal != 0) { + u32 accumulator = queue->altVal; + u32 leadingZero = accumulator & 0x80000000; + u32 value; + accumulator &= 0x7FFFFFFF; + queue->altVal = accumulator; + if (character >= 0xF130 && character <= 0xF139) { + if (accumulator > 0x6666666) { + return TRUE; + } + queue->altVal = leadingZero | (character - 0xF130 + accumulator * 10); + return TRUE; + } + value = queue->altVal; + if (value >= 128 && value <= 255) { + if (leadingZero) { + if (value < 160) { + value = kprLookupTable1252[value - 128]; + } + } else { + value = kprLookupTable437[value - 128]; + } + } else if (value > 255) { + u32 converted = 32; + if (value <= 0x6666666) { + converted = (u8)value; + } + value = converted; + } + { + int index = queue->oCount + queue->iCount; + u16* destination = &queue->text[index]; + for (; index > queue->oCount; --index, --destination) { + *destination = destination[-1]; + } + } + queue->text[queue->oCount] = value; + queue->altVal = 0; + ++queue->oCount; + return character == 0; + } + if (character >= 0xF130 && character <= 0xF139) { + if (character == 0xF130) { + queue->altVal = 0x80000000; + } else { + queue->altVal = character - 0xF130; + } + return TRUE; + } + if (character == 0) { + return TRUE; + } + return FALSE; +} + +void KPRProcessDeadKeys(KPRQueue* queue) { + int index; + int firstFallback; + int secondFallback; + if (queue->iCount == 1) { + for (index = 0; index < 107; ++index) { + if (queue->text[queue->oCount] == kprDeadKeyMap[index].accent) { + return; + } + } + ++queue->oCount; + queue->iCount = 0; + return; + } + firstFallback = 0; + secondFallback = 107; + for (index = 0; index < 107; ++index) { + u16 first = queue->text[queue->oCount]; + if (first == kprDeadKeyMap[index].accent && queue->text[queue->oCount + 1] == kprDeadKeyMap[index].base) { + queue->text[queue->oCount] = kprDeadKeyMap[index].composed; + queue->iCount = 0; + ++queue->oCount; + return; + } + if (first == kprDeadKeyMap[index].accent && first == kprDeadKeyMap[index].base) { + firstFallback = index; + } + if (queue->text[queue->oCount + 1] == kprDeadKeyMap[index].accent && queue->text[queue->oCount + 1] == kprDeadKeyMap[index].base) { + secondFallback = index; + } + } + queue->text[queue->oCount] = kprDeadKeyMap[firstFallback].composed; + if (secondFallback < 107) { + queue->text[queue->oCount + 1] = kprDeadKeyMap[secondFallback].composed; + } + queue->iCount = 0; + queue->oCount += 2; + return; +} diff --git a/libs/RVL_SDK/src/nup/nup_mem.cpp b/libs/RVL_SDK/src/nup/nup_mem.cpp new file mode 100644 index 00000000..184ea549 --- /dev/null +++ b/libs/RVL_SDK/src/nup/nup_mem.cpp @@ -0,0 +1,51 @@ +#include + +namespace nup { +static MEMAllocator* __mem; + +void* __nupMallocAlign(unsigned long size, unsigned long alignment) { + if (__mem == NULL) { + return NULL; + } + MEMHeapHandle heap = (MEMHeapHandle)__mem->heap; + if (heap->magic != 0x45585048) { + return NULL; + } + return MEMAllocFromExpHeapEx(heap, size, alignment); +} + +void* __nupMalloc(unsigned long size) { + if (__mem == NULL) { + return NULL; + } + MEMHeapHandle heap = (MEMHeapHandle)__mem->heap; + if (heap->magic != 0x45585048) { + return NULL; + } + return MEMAllocFromExpHeapEx(heap, size, 32); +} + +void __nupFree(void* block) { + if (__mem != NULL) { + MEMHeapHandle heap = (MEMHeapHandle)__mem->heap; + if (heap->magic == 0x45585048 && block != NULL) { + MEMFreeToExpHeap(heap, block); + } + } +} + +int __nupRegisterAllocator(MEMAllocator* allocator) { + int result = 0; + if (allocator == NULL) { + result = -5011; + } else { + if (((MEMHeapHandle)allocator->heap)->magic != 0x45585048) { + result = -5011; + } + if (((MEMHeapHandle)allocator->heap)->magic == 0x45585048) { + __mem = allocator; + } + } + return result; +} +} diff --git a/src/scene/setting/AOSSLink.c b/src/scene/setting/AOSSLink.c new file mode 100644 index 00000000..3972dc90 --- /dev/null +++ b/src/scene/setting/AOSSLink.c @@ -0,0 +1,352 @@ +#include +#include +#include +#include + +s32 AOSSi_cancel_flag; +static u8 ipAddress[4]; +static u8 ipNetmask[4]; +static u8 ipGateway[4]; +static u8 primaryDns[4]; +static u8 secondaryDns[4]; +static void* (*allocateMemory)(u32, s32); +static void (*releaseMemory)(u32, void*, s32); +static void (*statusCallback)(void); +static NCDIfConfig AOSS_810BD4A8; +static NCDIpConfig AOSS_810BD608; + +struct AOSSRate { + u16 mask; + u8 value; + u8 reserved; +}; +static struct AOSSRate supportedRates[] = { + {1, 2, 0}, {2, 4, 0}, {4, 11, 0}, {8, 12, 0}, + {16, 18, 0}, {32, 22, 0}, {64, 24, 0}, {128, 36, 0}, + {256, 48, 0}, {512, 72, 0}, {1024, 96, 0}, {2048, 108, 0} +}; +struct AOSSAccessPoint { + u32 ssidLength; + u8 ssid[32]; + u32 channel; + u32 signal; + u32 privacy; + u8 bssid[6]; + u16 capabilities; + u32 rateCount; + u8 rates[12]; + u32 beaconPeriod; + u32 mode; +}; +struct AOSSAccessPointList { + u32 count; + struct AOSSAccessPoint accessPoints[1]; +}; +struct AOSSConnection { + u32 ssidLength; + u8 ssid[32]; + u32 security; + u32 keyLength; + u8 key[64]; +}; +struct AOSSConnectionStatus { + u32 connected; + u32 ssidLength; + u8 ssid[32]; + u32 channel; +}; + +void AOSSi_Cancel(void) { + AOSSi_cancel_flag = 1; +} + +void AOSS_813FD17C(OSAlarm* alarm, OSContext* context) { + OSSendMessage((OSMessageQueue*)alarm->tag, NULL, 0); +} + +void AOSS_813FD18C(u32 milliseconds) { + OSMessage storage; + OSMessage message; + OSMessageQueue queue; + OSAlarm alarm; + OSInitMessageQueue(&queue, &storage, 1); + OSCreateAlarm(&alarm); + OSSetAlarmTag(&alarm, (u32)&queue); + OSSetAlarm(&alarm, (u32)(milliseconds * (OS_TIMER_CLOCK / 1000)), AOSS_813FD17C); + OSReceiveMessage(&queue, &message, 1); +} + +void* AOSSi_Alloc(u32 size) { + if (allocateMemory != NULL) { + return allocateMemory(0, size); + } + return NULL; +} + +void AOSSi_Free(void* block) { + if (releaseMemory != NULL) { + releaseMemory(0, block, 0); + } +} + +void AOSS_813FD25C(u8* destination, u32 address) { + int index; + for (index = 0; index < 4; ++index) { + *destination++ = address >> ((3 - index) * 8); + } +} + +int AOSSi_SetNCDIPAddr(u32 address, u32 netmask, u32 gateway, u32 dns1, u32 dns2) { + AOSS_813FD25C(ipAddress, address); + AOSS_813FD25C(ipNetmask, netmask); + AOSS_813FD25C(ipGateway, gateway); + AOSS_813FD25C(primaryDns, dns1); + AOSS_813FD25C(secondaryDns, dns2); + return 0; +} + +int AOSSi_InitLocal(void* (*allocate)(u32, s32), void (*release)(u32, void*, s32)) { + BOOL interrupts; + if (allocate == NULL || release == NULL) { + return -1; + } + interrupts = OSDisableInterrupts(); + allocateMemory = allocate; + releaseMemory = release; + AOSSi_cancel_flag = 0; + OSRestoreInterrupts(interrupts); + return 0; +} + +int AOSSi_EndLocal(void) { + BOOL interrupts = OSDisableInterrupts(); + allocateMemory = NULL; + releaseMemory = NULL; + OSRestoreInterrupts(interrupts); + return 0; +} + +int AOSSi_WLANGetBSSList(struct AOSSAccessPointList** output) { + int result = -1; + int startupRetries = 0; + int scanRetries = 0; + int cleanupRetries = 0; + int unlockRetries = 0; + int driver; + u8* buffer; + WD_Info info ATTRIBUTE_ALIGN(32); + WDScanParam scan; + u8 macAddress[6]; + if (allocateMemory == NULL || releaseMemory == NULL) { + return -1; + } + driver = NCDLockWirelessDriver(); + if (driver <= 0) { + return -1; + } +startup: + if (WD_Startup(3) != 0) { + if (startupRetries > 10) { + goto unlock; + } + ++startupRetries; + AOSS_813FD18C(10); + goto startup; + } + if (WD_GetInfo(&info) == 0) { + memcpy(macAddress, info.MAC, 6); + } + buffer = AOSSi_Alloc(0x3200); + if (buffer != NULL) { + memset(buffer, 0, 0x3200); + scan.channelBit = info.enableChannel; + scan.maxChannelTime = 40; + memset(scan.bssid, 255, 6); + scan.type = 0; + scan.ssidLength = 0; + memset(scan.ssid, 0, 32); + memset(scan.ssidMask, 255, 32); + while (1) { + int scanResult = WD_Scan(&scan, buffer, 0x3200); + int count; + struct AOSSAccessPointList* list; + WDBssDesc* descriptor; + int index; + if (scanResult != 0 && scanResult != WD_INTERNAL_ERR_4) { + break; + } + count = *(u16*)buffer; + if (count != 0) { + list = AOSSi_Alloc(sizeof(*list) + (count - 1) * sizeof(struct AOSSAccessPoint)); + if (list == NULL) { + result = -1; + break; + } + list->count = count; + descriptor = (WDBssDesc*)&buffer[2]; + for (index = 0; index < count; ++index) { + struct AOSSAccessPoint* accessPoint = &list->accessPoints[index]; + int rate; + int rateCount = 0; + accessPoint->ssidLength = descriptor->ssidLength; + memcpy(accessPoint->ssid, descriptor->ssid, 32); + accessPoint->channel = descriptor->channel; + memcpy(accessPoint->bssid, descriptor->bssid, 6); + for (rate = 0; rate < 12; ++rate) { + if (descriptor->rateSet.support & supportedRates[rate].mask) { + accessPoint->rates[rateCount] = supportedRates[rate].value; + if (descriptor->rateSet.basic & supportedRates[rate].mask) { + accessPoint->rates[rateCount] |= 128; + } + ++rateCount; + } + } + accessPoint->rateCount = rateCount; + accessPoint->beaconPeriod = descriptor->beaconPeriod; + if ((descriptor->capabilities & 3) == 1) { + accessPoint->mode = 1; + } else if ((descriptor->capabilities & 3) == 2) { + accessPoint->mode = 2; + } else { + accessPoint->mode = 0; + } + descriptor = (WDBssDesc*)((u16*)descriptor + descriptor->length); + } + *output = list; + result = 0; + break; + } + if (AOSSi_cancel_flag == 1) { + result = -1; + break; + } + if (++scanRetries > 10) { + list = AOSSi_Alloc(sizeof(*list)); + if (list == NULL) { + result = -1; + break; + } + list->count = 0; + result = 0; + *output = list; + break; + } + AOSS_813FD18C(100); + } + AOSSi_Free(buffer); + } +cleanup: + if (WD_Cleanup() != 0) { + if (cleanupRetries > 10) { + result = -1; + goto unlock; + } + ++cleanupRetries; + AOSS_813FD18C(10); + goto cleanup; + } +unlock: + if (NCDUnlockWirelessDriver(driver) != 0) { + if (unlockRetries > 10) { + result = -1; + return -1; + } + ++unlockRetries; + AOSS_813FD18C(10); + goto unlock; + } + return result; +} + +int AOSSi_WLANConnect(struct AOSSConnection* connection, struct AOSSConnectionStatus* status) { + int retries = 0; + int result = 0; + WD_Info info ATTRIBUTE_ALIGN(32); + NCDIfConfig* interfaceConfig = &AOSS_810BD4A8; + NCDIpConfig* ipConfig; + memset(interfaceConfig, 0, sizeof(*interfaceConfig)); + interfaceConfig->selectedMedia = 1; + interfaceConfig->netif.wireless.rateset = 0; + interfaceConfig->netif.wireless.configMethod = 0; + if (connection->keyLength == 0) { + interfaceConfig->netif.wireless.config.manual.privacy.mode = 0; + } + if (connection->keyLength == 5) { + interfaceConfig->netif.wireless.config.manual.privacy.mode = 1; + interfaceConfig->netif.wireless.config.manual.privacy.wep40.keyId = 0; + memcpy(interfaceConfig->netif.wireless.config.manual.privacy.wep40.key, + connection->key, connection->keyLength); + } else if (connection->keyLength == 13) { + interfaceConfig->netif.wireless.config.manual.privacy.mode = 2; + interfaceConfig->netif.wireless.config.manual.privacy.wep104.keyId = 0; + memcpy(interfaceConfig->netif.wireless.config.manual.privacy.wep104.key, + connection->key, connection->keyLength); + } else if (connection->keyLength == 16) { + return -1; + } else { + return -1; + } + interfaceConfig->netif.wireless.config.manual.ssidLength = (u8)connection->ssidLength; + memcpy(interfaceConfig->netif.wireless.config.manual.ssid, connection->ssid, connection->ssidLength); + ipConfig = &AOSS_810BD608; + memset(ipConfig, 0, sizeof(*ipConfig)); + ipConfig->adjust.maxTransferUnit = 1300; + ipConfig->adjust.tcpRetransTimeout = 100; + ipConfig->adjust.dhcpRetransCount = 4; + ipConfig->useDhcp = 0; + ipConfig->useProxy = 0; + memcpy(ipConfig->ip.addr, ipAddress, 4); + memcpy(ipConfig->ip.netmask, ipNetmask, 4); + memcpy(ipConfig->ip.gateway, ipGateway, 4); + memcpy(ipConfig->ip.dns1, primaryDns, 4); + memcpy(ipConfig->ip.dns2, secondaryDns, 4); + if (NCDSetIpConfig(ipConfig) != 0) { + result = -1; + } + if (result == 0 && NCDSetIfConfig(&AOSS_810BD4A8) != 0) { + result = -1; + } + if (result == 0) { + while (!NCDIsInterfaceDecided()) { + if (AOSSi_cancel_flag == 1) { + result = -1; + break; + } + if (retries > 600) { + result = -1; + break; + } + ++retries; + AOSS_813FD18C(10); + } + } + if (result == 0) { + status->connected = 1; + if (WD_GetInfo(&info) == 0) { + status->channel = info.channel; + } + status->ssidLength = interfaceConfig->netif.wireless.config.manual.ssidLength; + memcpy(status->ssid, interfaceConfig->netif.wireless.config.manual.ssid, + interfaceConfig->netif.wireless.config.manual.ssidLength); + } else { + status->connected = 0; + } + return result; +} + +void AOSSi_Sleep(u32 milliseconds) { + AOSS_813FD18C(milliseconds); +} + +int AOSSi_Status(void) { + if (statusCallback != NULL) { + statusCallback(); + } + return 0; +} + +void AOSS_SetCallback(void (*callback)(void)) { + BOOL interrupts = OSDisableInterrupts(); + statusCallback = callback; + OSRestoreInterrupts(interrupts); +} diff --git a/src/scene/setting/iplRakuRakuThread.cpp b/src/scene/setting/iplRakuRakuThread.cpp new file mode 100644 index 00000000..8cf67ee4 --- /dev/null +++ b/src/scene/setting/iplRakuRakuThread.cpp @@ -0,0 +1,284 @@ +#include "utility/iplThread.h" +#include +#include +#include +#include +#include + +struct RakuProgress { + s32 state; + int remainingTime; + int result; +}; +struct RakuConfiguration { + char ssid[32]; + s32 security; + u32 keyId; + char wepKeys[4][32]; + char passphrase[64]; +}; +extern "C" { +int ATERMi_ApConfigGetVersion(); +int ATERMi_ApConfigGetState(RakuProgress* progress); +int ATERMi_ApConfigGetResult(RakuConfiguration* configuration); +int ATERMi_ApConfigStart(int priority, u32 scanLimit, void (*callback)(RakuProgress*), + void* (*allocate)(u32), void (*release)(void*), u32 stackSize); +int ATERMi_ApConfigEnd(); +} + +namespace ipl { +namespace scene { +extern "C" MEMAllocator RakuRakuThread_810BDDD0; +MEMAllocator RakuRakuThread_810BDDD0; +struct RakuStatus { + RakuProgress progress; + RakuConfiguration configuration; +}; +extern "C" RakuStatus RakuRakuThread_810BDDE0; +RakuStatus RakuRakuThread_810BDDE0; +extern "C" OSMessageQueue RakuRakuThread_810BDED4; +OSMessageQueue RakuRakuThread_810BDED4; +static OSTime startTime; +static bool active; +static OSMessage messageSlot; +static int displayState = 1; + +extern "C" { +static void* RakuRakuThread_813FDEF0(u32, s32 size); +static void RakuRakuThread_813FDEFC(u32, void* block, s32); +static void* RakuRakuThread_813FDF08(u32 size); +static void RakuRakuThread_813FDF18(void* block); +} + +struct RakuStack { + u32 storage[4080]; + u32 sentinel; +}; +class RakuRakuThread : public utility::ut_thread { +public: + RakuRakuThread(EGG::Heap* heap); + virtual ~RakuRakuThread(); + virtual void* Run(); + virtual void unk_0x2C() = 0; + void RakuRakuThread_813FDA04(); + static void progressCallback(RakuProgress* progress); + void destroy(); + int start(); + int getState(); + int cancel(); + int finish(NCDApConfig* config, int* result); + void printInfo() NO_INLINE; +private: + int mReserved; + int mFinished; + int mRunning; + int mPriority; + void* mHeapBuffer; + RakuStack* mStack; + MEMHeapHandle mHeap; +}; + +void RakuRakuThread::RakuRakuThread_813FDA04() { + BOOL interrupts = OSDisableInterrupts(); + RakuRakuThread_810BDDE0.progress = *(RakuProgress*)this; + startTime = OSGetTime(); + OSRestoreInterrupts(interrupts); +} + +void RakuRakuThread::progressCallback(RakuProgress* progress) { + ((RakuRakuThread*)progress)->RakuRakuThread_813FDA04(); +} + +RakuRakuThread::RakuRakuThread(EGG::Heap* heap) : utility::ut_thread() { + u32 version = ATERMi_ApConfigGetVersion(); + if (((version >> 12) & 15) * 10 + ((version >> 8) & 15) != 1) { + mHeapBuffer = NULL; + } else { + mHeapBuffer = heap->alloc(0x40000, 32); + mStack = (RakuStack*)heap->alloc(4096, 32); + } + mHeap = NULL; + active = false; + mFinished = 0; + mRunning = 0; + OSInitMessageQueue(&RakuRakuThread_810BDED4, &messageSlot, 1); +} + +RakuRakuThread::~RakuRakuThread() { + if (mRunning) { + OSJamMessage(&RakuRakuThread_810BDED4, (OSMessage)2, 1); + WaitForThreadExit(); + } + destroy(); +} + +void RakuRakuThread::destroy() { + if (active) { + OSSendMessage(&RakuRakuThread_810BDED4, (OSMessage)1, 0); + u32 start = OSGetTick(); + while ((u32)(OSGetTick() - start) / (OS_TIMER_CLOCK / 1000) < 2000) { + RakuProgress progress; + if (ATERMi_ApConfigGetState(&progress) == 1 && progress.state == 7) { + break; + } + } + SOFinish(); + active = false; + } + if (mHeap != NULL) { + MEMDestroyExpHeap(mHeap); + memset(&RakuRakuThread_810BDDD0, 0, sizeof(MEMAllocator)); + mHeap = NULL; + } +} + +int RakuRakuThread::start() { + if (active || mHeapBuffer == NULL) { + return 0; + } + BOOL interrupts = OSDisableInterrupts(); + startTime = OSGetTime(); + mHeap = MEMCreateExpHeapEx(mHeapBuffer, 0x40000, 2); + MEMInitAllocatorForExpHeap(&RakuRakuThread_810BDDD0, mHeap, 32); + mPriority = OSGetThreadPriority(OSGetCurrentThread()) - 1; + active = true; + mFinished = 0; + memset(&RakuRakuThread_810BDDE0.configuration, 0, sizeof(RakuConfiguration)); + memset(&RakuRakuThread_810BDDE0.progress, 0, sizeof(RakuProgress)); + SOLibraryConfig socketConfig; + socketConfig.alloc = RakuRakuThread_813FDEF0; + socketConfig.free = RakuRakuThread_813FDEFC; + SOInit(&socketConfig); + ATERMi_ApConfigStart(mPriority, 200, + progressCallback, + RakuRakuThread_813FDF08, RakuRakuThread_813FDF18, 4096); + if (!mRunning) { + mRunning = 1; + memset(mStack, 0, 4); + Create(mStack, 4096, mPriority - 1, true); + OSReport("RakuRakuThread (for End function) start with prio(%d) \n", mPriority); + } + OSRestoreInterrupts(interrupts); + return 1; +} + +void* RakuRakuThread::Run() { + OSMessage message; + while (true) { + while (OSReceiveMessage(&RakuRakuThread_810BDED4, &message, 0)) { + if ((s32)message == 2) { + return this; + } + } + OSReceiveMessage(&RakuRakuThread_810BDED4, &message, 1); + if ((s32)message == 2) { + break; + } + mStack->sentinel = 0x97654321; + ATERMi_ApConfigEnd(); + mFinished = 1; + if (!mRunning) { + break; + } + } + return this; +} + +static void* RakuRakuThread_813FDEF0(u32, s32 size) { + return MEMAllocFromAllocator(&RakuRakuThread_810BDDD0, size); +} +static void RakuRakuThread_813FDEFC(u32, void* block, s32) { + MEMFreeToAllocator(&RakuRakuThread_810BDDD0, block); +} +static void* RakuRakuThread_813FDF08(u32 size) { + return MEMAllocFromAllocator(&RakuRakuThread_810BDDD0, size); +} +static void RakuRakuThread_813FDF18(void* block) { + MEMFreeToAllocator(&RakuRakuThread_810BDDD0, block); +} + +int RakuRakuThread::getState() { + if (!active) { + return 0; + } + BOOL interrupts = OSDisableInterrupts(); + switch (RakuRakuThread_810BDDE0.progress.state) { + case 1: displayState = 1; break; + case 2: displayState = 2; break; + case 3: displayState = 2; break; + case 4: displayState = 4; break; + case 5: displayState = 5; break; + case 6: displayState = 6; break; + case 7: displayState = 7; break; + default: displayState = 1; break; + } + if (displayState != 6 && displayState != 7 && + ((u32)OSGetTime() - (u32)startTime) / (OS_TIMER_CLOCK / 1000) >= 90000) { + OSSendMessage(&RakuRakuThread_810BDED4, (OSMessage)1, 0); + } + OSRestoreInterrupts(interrupts); + return displayState; +} + +int RakuRakuThread::cancel() { + return OSSendMessage(&RakuRakuThread_810BDED4, (OSMessage)1, 0); +} + +int RakuRakuThread::finish(NCDApConfig* config, int* result) { + if (!active) { + if (result != NULL) { + *result = -99; + } + return 1; + } + s32 state = RakuRakuThread_810BDDE0.progress.state; + if ((u32)(state - 6) > 1) { + return 0; + } + if (!mFinished) { + if (state == 6) { + ATERMi_ApConfigGetResult(&RakuRakuThread_810BDDE0.configuration); + printInfo(); + } + OSSendMessage(&RakuRakuThread_810BDED4, (OSMessage)1, 0); + return 0; + } + SOFinish(); + active = false; + destroy(); + if (config != NULL) { + RakuConfiguration* settings = &RakuRakuThread_810BDDE0.configuration; + memcpy(config->ssid, settings->ssid, 32); + config->ssidLength = strlen(settings->ssid); + if (settings->security == 1) { + config->privacy.mode = 1; + config->privacy.wep40.keyId = settings->keyId; + for (int index = 0; index < 4; ++index) { + memcpy(config->privacy.wep40.key[index], settings->wepKeys[index], 5); + } + } else if (settings->security == 2) { + config->privacy.mode = 2; + config->privacy.wep104.keyId = settings->keyId; + for (int index = 0; index < 4; ++index) { + memcpy(config->privacy.wep104.key[index], settings->wepKeys[index], 13); + } + } else if (settings->security == 4) { + config->privacy.mode = 4; + memcpy(config->privacy.tkip.key, settings->passphrase, 64); + config->privacy.tkip.keyLen = strlen(settings->passphrase); + } else if (settings->security == 5) { + config->privacy.mode = 6; + memcpy(config->privacy.aes.key, settings->passphrase, 64); + config->privacy.aes.keyLen = strlen(settings->passphrase); + } + } + if (result != NULL) { + *result = RakuRakuThread_810BDDE0.progress.result; + } + return 1; +} + +void RakuRakuThread::printInfo() { +} +} +} diff --git a/src/scene/setting/iplSensitivity.cpp b/src/scene/setting/iplSensitivity.cpp new file mode 100644 index 00000000..348300a0 --- /dev/null +++ b/src/scene/setting/iplSensitivity.cpp @@ -0,0 +1,85 @@ +#include "system/iplSystem.h" +#include "system/iplNand.h" +#include "utility/iplGraphics.h" +#include + +extern "C" { +WPADStatus* KPADGetWPADRingBuffer(s32 channel); +WPADFSStatus* KPADGetWPADFSRingBuffer(s32 channel); +WPADCLStatus* KPADGetWPADCLRingBuffer(s32 channel); +} + +namespace ipl { +class SensitivityDrawing { +public: + static void draw(nand::File* texture); +}; + +void SensitivityDrawing::draw(nand::File* texture) { + GXRenderModeObj renderMode = *System::getRenderModeObj(); + nw4r::ut::Rect projection; + System::getProjectionRect(&projection); + GXColor background = {96, 96, 96, 192}; + u32 scissorX, scissorY, scissorWidth, scissorHeight; + GXGetScissor(&scissorX, &scissorY, &scissorWidth, &scissorHeight); + f32 projectionWidth = projection.GetWidth(); + f32 projectionHeight = projection.GetHeight(); + f32 halfWidth = 0.5f * projectionWidth; + f32 scaleX = renderMode.fbWidth / projectionWidth; + f32 scaleY = renderMode.efbHeight / projectionHeight; + f32 halfHeight = 0.5f * projectionHeight; + utility::Graphics::setDefaultOrtho(0); + projectionHeight = projection.GetHeight(); + projectionWidth = projection.GetWidth(); + GXSetScissor(scaleX * (0.5f * projection.left + halfWidth), + scaleY * (-45.0f + (0.5f * projection.top + halfHeight)), + scaleX * (0.5f * projectionWidth), + scaleY * (0.5f * projectionHeight)); + utility::Graphics::drawPolygon(projection, background); + controller::Interface* controller = System::getYoungController(); + if (controller != NULL && controller->getKPADStatus() != NULL) { + GXTexObj image; + TPLGetGXTexObjFromPalette((TPLPalette*)texture->getBuffer(), &image, 1); + GXInitTexObjWrapMode(&image, GX_MIRROR, GX_MIRROR); + f32 width = projection.GetWidth(); + f32 height = projection.GetHeight(); + f32 horizontalScale = (0.5f * width) / 1024.0f; + f32 verticalScale = (0.5f * height) / 768.0f; + int sample = WPADGetLatestIndexInBuf(controller->getChannel()); + DPDObject* object; + DPDObject* first; + switch (controller->getType()) { + case 0: { + WPADStatus* status = KPADGetWPADRingBuffer(controller->getChannel()) + sample; + object = &status->obj[3]; + first = &status->obj[0]; + break; + } + case 1: { + WPADFSStatus* status = KPADGetWPADFSRingBuffer(controller->getChannel()) + sample; + object = &status->obj[3]; + first = &status->obj[0]; + break; + } + case 2: { + WPADCLStatus* status = KPADGetWPADCLRingBuffer(controller->getChannel()) + sample; + object = &status->obj[3]; + first = &status->obj[0]; + break; + } + } + do { + if (object->size != 0) { + f32 radius = 0.15f * (object->size + 25); + f32 x = (object->x - 512) * horizontalScale; + f32 y = (object->y - 384) * verticalScale; + GXColor foreground = {255, 255, 255, 255}; + nw4r::ut::Rect rectangle(x - radius, -y + radius - -45.0f, + x + radius, -y - radius - -45.0f); + utility::Graphics::drawTexture(rectangle, image, foreground, 2, utility::Graphics::ORI_NONE); + } + } while (--object >= first); + } + GXSetScissor(scissorX, scissorY, scissorWidth, scissorHeight); +} +} diff --git a/src/scene/setting/iplUSBAP.cpp b/src/scene/setting/iplUSBAP.cpp new file mode 100644 index 00000000..7b12c1c8 --- /dev/null +++ b/src/scene/setting/iplUSBAP.cpp @@ -0,0 +1,156 @@ +#include +#include +#include + +static OSThread usbapThread; +static u8 usbapStack[4096]; +static OSMessageQueue usbapMessageQ; +static wchar_t usbapNickname[11]; +static OSMessage registrationMessage; +static void (*registrationCallback)(int); +static s32 registrationMode; +static u16 enabledChannels; +static u8* scanBuffer; +struct RegisteredAccessPoints { + u8 count; + u8 addresses[20][6]; +}; +static RegisteredAccessPoints* registeredAccessPoints; + +extern "C" { +static void* DoRegistration(void*); +} + +extern "C" BOOL USBAPStartRegistration(void*, void*, u32 priority, u32 mode, + void* nickname, void (*callback)(int), + u16* buffer, u8* accessPoints) { + BOOL interrupts = OSDisableInterrupts(); + scanBuffer = (u8*)buffer; + registeredAccessPoints = (RegisteredAccessPoints*)accessPoints; + if (usbapThread.state != 0 && !OSIsThreadTerminated(&usbapThread)) { + OSRestoreInterrupts(interrupts); + return FALSE; + } + if (priority > 31 || nickname == NULL || callback == NULL) { + OSRestoreInterrupts(interrupts); + return FALSE; + } + registrationMode = mode; + registrationCallback = callback; + memcpy(usbapNickname, nickname, 20); + OSInitMessageQueue(&usbapMessageQ, ®istrationMessage, 1); + if (OSCreateThread(&usbapThread, DoRegistration, NULL, usbapStack + sizeof(usbapStack), + sizeof(usbapStack), priority, OS_THREAD_ATTR_DETACH) == TRUE) { + OSRestoreInterrupts(interrupts); + while (OSResumeThread(&usbapThread) > 1) { + } + return TRUE; + } + OSRestoreInterrupts(interrupts); + return FALSE; +} + +extern "C" BOOL USBAPCancelRegistration() { + return OSSendMessage(&usbapMessageQ, NULL, 0); +} + +extern "C" BOOL USBAPIsThreadTerminated() { + return OSIsThreadTerminated(&usbapThread); +} + +struct USBAPSSID { + u8 prefix[8]; + u8 reserved; + u8 flags; + u8 version; + u8 status; + wchar_t nickname[10]; +}; + +struct USBAPScan { + u16 channelBit; + u16 maxChannelTime; + u8 bssid[6]; + u16 type; + u16 ssidLength; + USBAPSSID ssid; + u8 ssidMask[32]; +}; + +static void* DoRegistration(void*) { + BOOL success; + int result; + if (WDCheckEnableChannel(&enabledChannels) != 0) { + success = FALSE; + if (registrationCallback != NULL) { + registrationCallback(FALSE); + } + goto complete; + } + do { + OSMessage message; + OSYieldThread(); + if (OSReceiveMessage(&usbapMessageQ, &message, 0) == TRUE) { + success = FALSE; + if (registrationCallback != NULL) { + registrationCallback(FALSE); + } + goto complete; + } + USBAPScan scan; + scan.channelBit = enabledChannels; + scan.maxChannelTime = 100; + result = 0; + memset(scan.bssid, 255, 6); + scan.type = 0; + scan.ssidLength = 32; + memcpy(scan.ssid.prefix, "NWCUSBAP", 8); + scan.ssid.reserved = 0; + scan.ssid.flags = 1; + if (registrationMode == 1) { + scan.ssid.flags |= 2; + } + scan.ssid.version = 1; + scan.ssid.status = 0; + memcpy(scan.ssid.nickname, usbapNickname, 20); + memset(scan.ssidMask, 0, 8); + memset(&scan.ssidMask[8], 255, 24); + if (WDScanOnce(scanBuffer, 2048, (WDScanParam*)&scan) == 0) { + u16 count = *(u16*)scanBuffer; + WDBssDesc* accessPoint = (WDBssDesc*)&scanBuffer[2]; + int found = 0; + int failed = 0; + for (int index = 0; index < count; ++index) { + if (accessPoint->ssidLength == 32 && strncmp((char*)accessPoint->ssid, "NWCUSBAP", 8) == 0) { + RegisteredAccessPoints* registered = registeredAccessPoints; + int address; + for (address = 0; address < 20; ++address) { + if (memcmp(accessPoint->bssid, registered->addresses[address], 6) == 0) { + break; + } + } + if (address == 20) { + USBAPSSID* response = (USBAPSSID*)accessPoint->ssid; + if (response->flags == 1) { + memcpy(registeredAccessPoints->addresses[registeredAccessPoints->count], accessPoint->bssid, 6); + found = 1; + ++registeredAccessPoints->count; + } else if (response->flags == 0) { + failed = 1; + } + } + } + accessPoint = (WDBssDesc*)((u16*)accessPoint + accessPoint->length); + } + if (found) { + result = (failed != 0) + 1; + } + } + } while (result == 0); + success = result == 1; + if (registrationCallback != NULL) { + registrationCallback(success); + } +complete: + return (void*)success; +} diff --git a/src/scene/setting/iplUSBAPThread.cpp b/src/scene/setting/iplUSBAPThread.cpp new file mode 100644 index 00000000..4f093a7d --- /dev/null +++ b/src/scene/setting/iplUSBAPThread.cpp @@ -0,0 +1,67 @@ +#include +#include +#include "utility/iplCharacterCode.h" + +extern "C" { +BOOL USBAPStartRegistration(void*, void*, u32, u32, void*, void (*)(int), u16*, u8*); +BOOL USBAPCancelRegistration(); +BOOL USBAPIsThreadTerminated(); +} + +namespace ipl { +namespace scene { + +class USBAPThread { +public: + USBAPThread(); + void Init(unsigned short* buffer, unsigned char* accessPoints); + BOOL cancel(); + BOOL is(); + void setData(const wchar_t* nickname, unsigned char* result); + void callback(); +private: + wchar_t mNickname[10]; +}; + +static u8* registrationResult; + +USBAPThread::USBAPThread() { +} + +void USBAPRegisterCallback(int result) { + if (result == 1) { + *registrationResult = 1; + OSReport("Registration completed !\n"); + } else { + *registrationResult = 2; + OSReport("Registration failed...\n"); + } +} + +void USBAPThread::Init(unsigned short* buffer, unsigned char* accessPoints) { + int priority = OSGetThreadPriority(OSGetCurrentThread()) + 1; + if (USBAPStartRegistration(NULL, NULL, priority, + 0, this, USBAPRegisterCallback, buffer, accessPoints) == 1) { + OSReport("Registration started\n"); + } +} + +BOOL USBAPThread::cancel() { + return USBAPCancelRegistration(); +} + +BOOL USBAPThread::is() { + return USBAPIsThreadTerminated(); +} + +void USBAPThread::setData(const wchar_t* nickname, unsigned char* result) { + registrationResult = result; + memcpy(mNickname, nickname, 20); + utility::CharacterCode::changeEndian(mNickname, 10); +} + +void USBAPThread::callback() { +} + +} +} diff --git a/tools/decomp-assist/sol-low-batch.attempts.md b/tools/decomp-assist/sol-low-batch.attempts.md new file mode 100644 index 00000000..6521a160 --- /dev/null +++ b/tools/decomp-assist/sol-low-batch.attempts.md @@ -0,0 +1,88 @@ +# Setting and SDK batch + +All units remain NonMatching. No shared header or configure.py changes. + +## USBAPThread::Init + +1. Nested current-thread priority expression: 32/32 instructions, two li instructions swapped. +2. Separate priority temporary: unchanged. +3. Pointer, integer, and Boolean argument declarations: unchanged. Retained pointer parameters and the priority temporary. + +## USBAP::DoRegistration + +1. WDScanParam plus a local typed SSID pointer: 160/161 instructions and larger frame. +2. A typed scan structure and corrected response flags: 161/161, 48 differences. +3. Shared function exit for cancellation and initial failure: 161/161, 35 differences, mostly register assignments. + +## SensitivityDrawing::draw + +1. Independent GetWidth/GetHeight expressions: 278/278, 39 differences. +2. Width/height temporaries: 15 differences. +3. Explicit dimensions in the texture section: 11 differences. +4. Direct GXSetScissor arguments: removed the integer register permutation. +5. Four dimension and scale declaration variants: best seven differences. +6. Horizontal scale computed before vertical scale: one operand-order difference. +7. Division by 1024 rather than multiplication by its reciprocal: zero instruction differences. Corrected the vertical offset constant to -45 after examining the target constant bytes. Code is exact; the constant pool still differs. + +## RakuRakuThread + +Constructor, destructor, callback, destroy, Run, getState, four allocator callbacks, cancel, and printInfo reached exact instructions in the separate-global implementation. The additional progressCallback adapts the recovered member callback to the ATERM callback signature. That recovered signature needs parent review. + +### start + +1. Separate allocator, status, and queue globals: 97/96 instructions. +2. A domain context containing those fields: 96/96, 30 differences; changed previously exact functions through relocation offsets. +3. An explicit context pointer before the active check: 96/96, one mr versus addi difference, but worsened other owned functions. Restored the separate globals to preserve 12 exact functions. + +### finish + +1. Separate globals and early state rejection: 136/133 instructions. +2. Signed state and unsigned state-range check: removed branch differences. +3. Domain context and nested success branch: 133/133, 115 differences. +4. Context pointer, out-of-line printInfo and delayed configuration pointer: 132/133, allocation and address-generation differences. Restored separate globals and retained the signed security field and out-of-line printInfo. + +## AOSSLink + +Twelve functions have exact instructions. Swapping the alarm message/storage declaration order fixed AOSS_813FD18C. + +### AOSSi_WLANGetBSSList + +1. Structured access-point output and while retry loops: 227/227, 186 differences. +2. Startup label, retry increment ordering and aligned scan variables: 227/227, 186 differences; larger frame. +3. Cleanup/unlock labels and ordinary scan/mac locals: 227/227, 202 differences. Corrected the access-point layout with its real privacy field, restoring the 84-byte record size. Remaining differences involve stack placement, loop scheduling and register allocation. + +### AOSSi_WLANConnect + +1. Direct global configuration fields: 162/155 instructions. +2. Typed interface/IP pointers: 154/155 instructions. +3. Separate cancellation and timeout branches, pre-sleep retry increment: 156/155 instructions. Remaining differences involve pointer lifetime, control flow and register allocation. + +## nup_mem::__nupRegisterAllocator + +The three allocation/free functions match exactly; allocator registration remains open. + +1. Two heap-magic checks in the non-null branch: 17/19 instructions; compiler removes two repeated loads. +2. Explicit heap pointer and validity Boolean: unchanged. +3. Separate null-aware registration branch: 21/19 instructions with two extra null-check instructions. Restored the first version. + +## kbd_lib_map_us + +Restored the eight ordinary key/modifier tables as u16 arrays and four region registrations. Code and data match 100 percent. + +## kpr_lib + +Seven functions have exact instructions after using a byte for the initialization guard. + +### KPRProcessAltKeypad + +1. Shared normalized and converted value plus while shift loop: 96/96, 28 differences. +2. Separate accumulator and translated value, digit subtraction before multiplication: 96/96, 25 differences. +3. For-form insertion shift loop: unchanged. Kept the readable for loop. Remaining differences are register assignments. + +### KPRProcessDeadKeys + +1. Initialized fallback indices, second-character temporary: 89/90 instructions. +2. Initialize fallbacks after the single-character case and load the second character inside the matching condition: 91/90. +3. A moving mapping pointer: 91/90 with more register differences. Restored variant two. The original reads an unset fallback register on invalid input; this source deliberately initializes that fallback rather than adding an uninitialized value to obtain a match. + +Not attempted: vi/i2c, nup/nup_nhttp, axfx/AXFXChorusExp, and all eight requested eZiText units. This is a partial batch, not completion. -- 2.49.1 From f34c0b3aa7c47298a9c4822b2a996a0af28132d6 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Wed, 30 Sep 2026 03:29:46 -0500 Subject: [PATCH 3/4] TMC_JPEG: exif_parse 3/6; partial texture converters, idct, iqdec (worker c8e8d278) (#355) --- README.md | 4 +- .../RVLMiddleware/TMC_JPEG/include/tmc_jpeg.h | 8 + .../TMC_JPEG/src/b65/iqdec_b65_frv32.c | 132 +- .../TMC_JPEG/src/buffer/idct_block_var.c | 68 +- .../TMC_JPEG/src/exif/exif_parse.c | 339 ++- .../src/texturecvtr/Texture_MCUtoRGB565.c | 760 ++++++- .../src/texturecvtr/Texture_MCUtoRGBA8.c | 1824 ++++++----------- .../src/texturecvtr/Texture_MCUtoY8U8V8.c | 667 ++++++ tools/decomp-assist/tmc-jpeg.attempts.md | 510 +++++ 9 files changed, 2834 insertions(+), 1478 deletions(-) create mode 100644 tools/decomp-assist/tmc-jpeg.attempts.md diff --git a/README.md b/README.md index 17d8cea0..cd8ef1ed 100644 --- a/README.md +++ b/README.md @@ -53,9 +53,9 @@ Progress | Decompiled | Matched | Linked | Data | |:---:|:---:|:---:|:---:| -| 93.64% | 82.24% | 57.94% | 89.35% | +| 94.06% | 82.26% | 57.94% | 89.35% | -units 770/1027 complete, functions 11926/12563 matched. +units 770/1027 complete, functions 11927/12563 matched. decompiled = code with a C/C++ implementation (objdiff fuzzy), matched = byte-exact code, linked = code actually linked into the DOL, data = byte-exact data diff --git a/libs/RVLMiddleware/TMC_JPEG/include/tmc_jpeg.h b/libs/RVLMiddleware/TMC_JPEG/include/tmc_jpeg.h index 0c385921..96566560 100644 --- a/libs/RVLMiddleware/TMC_JPEG/include/tmc_jpeg.h +++ b/libs/RVLMiddleware/TMC_JPEG/include/tmc_jpeg.h @@ -106,7 +106,15 @@ typedef struct { u16 outputHeight; // 0x2A u32 convWidth; // 0x2C u32 convHeight; // 0x30 +#ifdef TMC_JPEG_PLANAR_OUTPUT + u32 chromaWidth; + u32 chromaHeight; + u8* pLumaBuffer; + u8* pCbBuffer; + u8* pCrBuffer; +#else u8 unk_0x34[0x14]; // 0x34 +#endif void* pTexBuffer; // 0x48 u8 unk_0x4C[0x67C]; TMCCJPEGDecWork* pWorkBuf; // 0x6C8 diff --git a/libs/RVLMiddleware/TMC_JPEG/src/b65/iqdec_b65_frv32.c b/libs/RVLMiddleware/TMC_JPEG/src/b65/iqdec_b65_frv32.c index 47704d01..eb060ea2 100644 --- a/libs/RVLMiddleware/TMC_JPEG/src/b65/iqdec_b65_frv32.c +++ b/libs/RVLMiddleware/TMC_JPEG/src/b65/iqdec_b65_frv32.c @@ -1,13 +1,30 @@ +#include #include +typedef struct { + u16 bitLength; + u16 symbol; +} TMCHuffmanEntry; + +static TMCHuffmanEntry readHuffmanEntry(const TMCHuffmanEntry* entries, u32 index) { + return entries[index]; +} + +static TMCHuffmanEntry readHuffmanLimit(const TMCHuffmanEntry* entries) { + TMCHuffmanEntry limit; + limit.bitLength = entries->bitLength; + limit.symbol = entries->symbol; + return limit; +} + s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_ptr, TMCCJPEGDecWork* work) { - volatile u32 ac_comb; - u16* ac_fast; + TMCHuffmanEntry acEntry; + const TMCHuffmanEntry* ac_fast; u8* huff_sym; u32* huff_tbl; s32 bit_pos; u32 bit_data; - u16* dc_fast; + const TMCHuffmanEntry* dc_fast; s32 r; s32 blk0; s32 idx; @@ -19,29 +36,23 @@ s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_p const u8* zztbl; bit_pos = work->bitCount; - dc_fast = work->pDCFast; + dc_fast = (const TMCHuffmanEntry*)work->pDCFast; if (bit_pos <= 8) { r = TMCJPEGDEC_load_buff(work); if (r < 0) { return r; } - bit_pos = work->bitCount; } + bit_pos = work->bitCount; bit_data = work->bitBuf; tmp = bit_pos - 8; tmp = ((bit_data >> tmp) & 0xFF) << 2; { - u16* dc_entry = (u16*)((u8*)dc_fast + tmp); - r = dc_entry[0]; - extra = dc_entry[1]; - } - - { - volatile u32 dc_comb; - *(u16*)&dc_comb = r; - *((u16*)&dc_comb + 1) = extra; + TMCHuffmanEntry dcEntry = readHuffmanEntry(dc_fast, tmp >> 2); + r = dcEntry.bitLength; + extra = dcEntry.symbol; } if (r != 0) { @@ -51,7 +62,7 @@ s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_p } else { u32 code; unsigned int i; - u16* entry; + const TMCHuffmanEntry* entry; s32 thresh; s32 offs; @@ -71,13 +82,13 @@ s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_p work->bitCount = bit_pos; i = 9; - entry = (u16*)((u8*)huff_tbl + 0x24); + entry = (const TMCHuffmanEntry*)huff_tbl + 9; goto dc_entry; while (1) { i++; - entry += 2; + entry++; if (i > 16) { r = TMCC_ERROR_OVERFLOW; goto dc_end; @@ -91,27 +102,17 @@ s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_p code |= (bit_data >> bit_pos) & 1; dc_entry: - thresh = entry[0]; - offs = entry[1]; - { - volatile u16 p[2]; - p[0] = thresh; - p[1] = offs; - tmp = *(u32*)p; - } - - { - volatile u32 cw; - cw = tmp; - thresh = *(u16*)&cw; + TMCHuffmanEntry decoded = readHuffmanLimit(entry); + thresh = decoded.bitLength; + offs = decoded.symbol; } if (code > (u32)thresh) { continue; } - code = code - entry[0] + offs; + code = code - entry->bitLength + offs; r = huff_sym[code & 0xFF]; break; } @@ -138,21 +139,19 @@ s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_p bit_pos -= r; work->bitCount = bit_pos; extra = extra & (bit_data >> bit_pos); - if ((s32)tmp >> 1 <= extra) { - extra = extra; - } else { - extra = extra - (tmp - 1); + if (extra < (s32)tmp >> 1) { + extra -= tmp - 1; } dc_predict_row_ptr[0] += extra; } *block = dc_predict_row_ptr[0] * blk0; - ac_fast = work->pACFast; + ac_fast = (const TMCHuffmanEntry*)work->pACFast; huff_tbl = work->pACHuffTbl; huff_sym = work->pACHuffSym; - memset((u8*)block + 4, 0, 0xFC); + memset(block + 1, 0, 0xFC); bit_pos = work->bitCount; idx = 1; @@ -166,25 +165,19 @@ s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_p zztbl = TMCJPEGDEC_Zigzag_data; bit_data = work->bitBuf; t = bit_pos - 8; - { - u32 tbl_idx = ((bit_data >> t) & 0xFF) << 2; - s32 thresh_val = ac_fast[tbl_idx >> 1]; - s32 offs_val = *(u16*)((u8*)ac_fast + tbl_idx + 2); - *(u16*)&ac_comb = thresh_val; - *((u16*)&ac_comb + 1) = offs_val; - } + acEntry = readHuffmanEntry(ac_fast, (bit_data >> t) & 0xFF); while (idx < 64) { - s32 ac_thresh = *(u16*)&ac_comb; + s32 ac_thresh = acEntry.bitLength; if (ac_thresh != 0) { bit_pos = work->bitCount; bit_pos -= ac_thresh; work->bitCount = bit_pos; - r = *((u16*)&ac_comb + 1); + r = acEntry.symbol; } else { u32 code; unsigned int i; - u16* entry; + const TMCHuffmanEntry* entry; s32 thresh; s32 offs; @@ -202,13 +195,13 @@ s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_p work->bitCount = bit_pos; i = 9; - entry = (u16*)((u8*)work->pACHuffTbl + 0x24); + entry = (const TMCHuffmanEntry*)huff_tbl + 9; goto ac_entry_huff; while (1) { i++; - entry += 2; + entry++; if (i > 16) { r = TMCC_ERROR_OVERFLOW; goto ac_end; @@ -222,27 +215,17 @@ s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_p code |= (bit_data >> bit_pos) & 1; ac_entry_huff: - thresh = entry[0]; - offs = entry[1]; - { - volatile u16 p[2]; - p[0] = thresh; - p[1] = offs; - tmp = *(u32*)p; - } - - { - volatile u32 cw; - cw = tmp; - thresh = *(u16*)&cw; + TMCHuffmanEntry decoded = readHuffmanLimit(entry); + thresh = decoded.bitLength; + offs = decoded.symbol; } if (code > (u32)thresh) { continue; } - code = code - entry[0] + offs; + code = code - entry->bitLength + offs; r = huff_sym[code & 0xFF]; break; } @@ -278,19 +261,11 @@ s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_p bit_pos -= t; work->bitCount = bit_pos; t = bit_pos - 8; - { - u32 next_tbl = ((bit_data >> t) & 0xFF) << 2; - s32 next_th = ac_fast[next_tbl >> 1]; - s32 next_of = *(u16*)((u8*)ac_fast + next_tbl + 2); - extra = extra & (bit_data >> bit_pos); - *(u16*)&ac_comb = next_th; - *((u16*)&ac_comb + 1) = next_of; - } + extra = extra & (bit_data >> bit_pos); + acEntry = readHuffmanEntry(ac_fast, (bit_data >> t) & 0xFF); - if ((s32)tmp >> 1 <= extra) { - extra = extra; - } else { - extra = extra - (tmp - 1); + if (extra < (s32)tmp >> 1) { + extra -= tmp - 1; } q = ((s32*)conv_row_ptr)[zz]; @@ -312,12 +287,7 @@ s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_p bit_pos = work->bitCount; t = bit_pos - 8; tmp = ((bit_data >> t) & 0xFF) << 2; - { - s32 next_thresh = ac_fast[tmp >> 1]; - s32 next_offs = *(u16*)((u8*)ac_fast + tmp + 2); - *(u16*)&ac_comb = next_thresh; - *((u16*)&ac_comb + 1) = next_offs; - } + acEntry = readHuffmanEntry(ac_fast, tmp >> 2); idx += 16; } diff --git a/libs/RVLMiddleware/TMC_JPEG/src/buffer/idct_block_var.c b/libs/RVLMiddleware/TMC_JPEG/src/buffer/idct_block_var.c index 69258933..8113dfbe 100644 --- a/libs/RVLMiddleware/TMC_JPEG/src/buffer/idct_block_var.c +++ b/libs/RVLMiddleware/TMC_JPEG/src/buffer/idct_block_var.c @@ -7,17 +7,21 @@ static u8 clampU8(s32 v) { if (v < 256 && v > -1) { ok = 1; } - return (ok) ? v : ((v < 0) ? 0 : 255); + return ok ? v : 255 & ~(v >> 31); } static s8 clampS8(s32 v) { - return (v < 128 && v > -129) ? (s8)v : (v > 0) ? 127 : -128; + s32 inRange = 0; + if (v < 128 && v > -129) { + inRange = 1; + } + return inRange ? (s8)v : (v > 0) ? 127 : -128; } static s32 scalingClampU8(s32 val) { - s32 result = 0; + s32 result; if (val >> 19 != 0) - result &= ~(val >> 31) & 0xFF; + result = ~(val >> 31) & 0xFF; else result = (val >> 11); return result; @@ -38,8 +42,8 @@ void TMCJPEGDEC_IdctBlock_Lumi(s32* block, u8* conv_row_ptr, u16 pitch, s32 zigz iter = (u32)(r + 7) >> 3; dst = tmp; done = 0; - if (r > 0) { - for (; iter > 0; iter--) { + { + for (; done < r; done += 8) { u32 ac; b4 = block[4]; b6 = block[6]; @@ -49,7 +53,13 @@ void TMCJPEGDEC_IdctBlock_Lumi(s32* block, u8* conv_row_ptr, u16 pitch, s32 zigz b5 = block[5]; b3 = block[3]; - ac = (u32)b4 | (u32)b6 | (u32)b2 | (u32)b1 | (u32)b7 | (u32)b5 | (u32)b3; + ac = (u32)b4; + ac |= (u32)b6; + ac |= (u32)b2; + ac |= (u32)b1; + ac |= (u32)b7; + ac |= (u32)b5; + ac |= (u32)b3; if (ac == 0) { s32 val = block[0]; dst[7] = val; @@ -64,7 +74,7 @@ void TMCJPEGDEC_IdctBlock_Lumi(s32* block, u8* conv_row_ptr, u16 pitch, s32 zigz t = (b2 - b6) * 0xB5 >> 8; a = block[0] - b4; d = block[0] + b4; - u = t + b6 + b2; + u = t + (b6 + b2); v = a + t; e = a - t; w = d + u; @@ -76,10 +86,13 @@ void TMCJPEGDEC_IdctBlock_Lumi(s32* block, u8* conv_row_ptr, u16 pitch, s32 zigz x = x_factor * 0xB5 >> 8; z = z_factor * 0x62 >> 8; m = m_part - z; - n = b1 + b7 + b5 + b3 + m; + n = (b1 + b7) + ((b5 + b3) + m); o = x + m; p = z + p_part; q = p + x; + dst[0] = w + n; + dst[7] = w - n; + dst[1] = v + o; dst[6] = v - o; dst[2] = e + q; dst[5] = e - q; @@ -88,12 +101,11 @@ void TMCJPEGDEC_IdctBlock_Lumi(s32* block, u8* conv_row_ptr, u16 pitch, s32 zigz } block += 8; dst += 8; - done += 8; } } dst = tmp + done; - for (; done < 0x38; done += 8) { + for (; done <= 0x38; done += 8) { memset(dst, 0, 0x20); dst += 8; } @@ -114,7 +126,13 @@ void TMCJPEGDEC_IdctBlock_Lumi(s32* block, u8* conv_row_ptr, u16 pitch, s32 zigz b5 = dst[0x28]; b3 = dst[0x18]; - ac = (u32)b4 | (u32)b6 | (u32)b2 | (u32)b1 | (u32)b7 | (u32)b5 | (u32)b3; + ac = (u32)b4; + ac |= (u32)b6; + ac |= (u32)b2; + ac |= (u32)b1; + ac |= (u32)b7; + ac |= (u32)b5; + ac |= (u32)b3; out = conv_row_ptr + i; if (ac == 0) { u8 val = clampU8((*dst >> 11) + 0x80); @@ -128,13 +146,14 @@ void TMCJPEGDEC_IdctBlock_Lumi(s32* block, u8* conv_row_ptr, u16 pitch, s32 zigz out[0] = val; } else { t = (b2 - b6) * 0xB5 >> 8; - a = *dst - b4; - d = *dst + b4; - u = t + b6 + b2; + a = (*dst + 0x40000) - b4; + d = (*dst + 0x40000) + b4; + u = t + (b6 + b2); v = a + t; e = a - t; w = d + u; - x = ((b1 + b7) - (b5 + b3)) * 0xB5 >> 8; + x_factor = (b1 + b7) - (b5 + b3); + x = x_factor * 0xB5 >> 8; y = d - u; z_factor = ((b5 - b3) + (b1 - b7)) * 0x62 >> 8; @@ -296,7 +315,7 @@ mode_gt_2: t = (b2 - b6) * 0xB5 >> 8; a = block[0] - b4; d = block[0] + b4; - u = t + b6 + b2; + u = t + (b6 + b2); v = a + t; e = a - t; w = d + u; @@ -308,10 +327,13 @@ mode_gt_2: x = x_factor * 0xB5 >> 8; z = z_factor * 0x62 >> 8; m = m_part - z; - n = b1 + b7 + b5 + b3 + m; + n = (b1 + b7) + ((b5 + b3) + m); o = x + m; p = z + p_part; q = p + x; + dst[0] = w + n; + dst[7] = w - n; + dst[1] = v + o; dst[6] = v - o; dst[2] = e + q; dst[5] = e - q; @@ -365,15 +387,17 @@ epilogue: t = (b2 - b6) * 0xB5 >> 8; a = *dst - b4; d = *dst + b4; - u = t + b6 + b2; + u = t + (b6 + b2); v = a + t; e = a - t; w = d + u; - x = ((b1 + b7) - (b5 + b3)) * 0xB5 >> 8; + x_factor = (b1 + b7) - (b5 + b3); + x = x_factor * 0xB5 >> 8; y = d - u; - z = ((b5 - b3) + (b1 - b7)) * 0x62 >> 8; + z_factor = (b5 - b3) + (b1 - b7); + z = z_factor * 0x62 >> 8; m = ((b1 - b7) * 0x14E >> 8) - z; - n = b1 + b7 + b5 + b3 + m; + n = (b1 + b7) + ((b5 + b3) + m); o = x + m; p = z + ((b5 - b3) * 0x8B >> 8); diff --git a/libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse.c b/libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse.c index 86dfaa51..8cb4a9ab 100644 --- a/libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse.c +++ b/libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse.c @@ -15,9 +15,16 @@ static u16 readU16(const u8* p, u16 byteOrder) { return (u16)(raw >> 8 & 0xFF | (raw & 0xFF) << 8); } +static u16 readExifU16(const u8* data, u16 byteOrder) { + u32 value = data[0] | data[1] << 8; + if (byteOrder == 0x4949) { + return (u16)value; + } + return (u16)(value >> 8 & 255 | (value & 255) << 8); +} + static u32 readU32(const u8* p, u16 byteOrder) { - u32 raw = p[0] | p[1] << 8; - raw = raw | p[3] << 24 | p[2] << 16; + u32 raw = p[1] << 8 | p[0] | p[2] << 16 | p[3] << 24; if (byteOrder == 0x4949) { return raw; } @@ -26,9 +33,9 @@ static u32 readU32(const u8* p, u16 byteOrder) { s32 TMCCJPEGDecGetOffsetEXIF(u32* pOffset, u32* pSize, TMCCJPEGDecInitParam* pParam) { TMCCJPEGDecWork* work; - u16 marker; - u32 dataSize; u16 segSize; + u32 dataSize; + u16 marker; s32 result; u8 sig[4]; @@ -108,62 +115,26 @@ s32 TMCCJPEGDecGetOffsetEXIF(u32* pOffset, u32* pSize, TMCCJPEGDecInitParam* pPa continue; } - if (marker >= 0xFFD9) { - if (marker == 0xFFD9) { + switch (marker) { + case 0xFFC0: + case 0xFFC2: + case 0xFFC4: + case 0xFFDB: + case 0xFFDC: + case 0xFFDD: + case 0xFFFE: + result = TMCJPEGDEC_move_ptr(segSize, work); + if (result < 0) { + return result; + } + break; + case 0xFFDA: return -2; - } - - if (marker == 0xFFFE) { - result = TMCJPEGDEC_move_ptr(segSize, work); - if (result < 0) { - return result; - } - continue; - } - - if (marker >= 0xFFDE) + case 0xFFD9: + return -2; + default: return -0x2F; - - if (marker >= 0xFFDB) { - result = TMCJPEGDEC_move_ptr(segSize, work); - if (result < 0) { - return result; - } - continue; - } - - return -2; } - - if (marker >= 0xFFC2) { - if (marker == 0xFFC2) { - result = TMCJPEGDEC_move_ptr(segSize, work); - if (result < 0) { - return result; - } - continue; - } - - if (marker == 0xFFC4) { - result = TMCJPEGDEC_move_ptr(segSize, work); - if (result < 0) { - return result; - } - continue; - } - - return -0x2F; - } - - if (marker == 0xFFC0) { - result = TMCJPEGDEC_move_ptr(segSize, work); - if (result < 0) { - return result; - } - continue; - } - - return -0x2F; } } @@ -271,114 +242,103 @@ _error: } static s32 TMCJPEGDEC_exif_parse(const u8* data, u32 size, TMCCJPEGDecExifData* pInfo) { - u32 ifd0Offset; - u32 ifd1Offset; - u32 exifIfdOffset; - u16 count; - u32 entriesSize; - u32 i; - const u8* p; - s32 sval; u16 byteOrder; - u32 raw; - + u32 ifdOffset; pInfo->thumbnailData = (u8*)data; pInfo->dataEnd = (u8*)data + size; pInfo->nextIfdOffset = 0; - if (size < 8) { return -161; } - - raw = data[0] | data[1] << 8; - byteOrder = raw; + byteOrder = data[0] | data[1] << 8; if (byteOrder != 0x4D4D && byteOrder != 0x4949) { return -161; } - - if (readU16(data + 2, byteOrder) != 0x002A) { + if (readExifU16(data + 2, byteOrder) != 42) { return -161; } - - ifd0Offset = readU32(data + 4, byteOrder); - if (ifd0Offset > size) { + ifdOffset = readU32(data + 4, byteOrder); + if (size < ifdOffset) { return -161; } - - sval = size - (u16)ifd0Offset; - if (sval < 2) { - return -161; - } - - p = data + (u16)ifd0Offset; - count = readU16(p, byteOrder); - entriesSize = count * 12; - sval = (u32)(sval - 2); - if (sval < entriesSize) { - return -161; - } - - p += 2; - for (i = 0; i < count; i++) { - TMCJPEGDEC_IFD0_tag_parse(pInfo, byteOrder, p); - p += 12; - } - - sval -= entriesSize; - if (sval < 4) { - return -161; - } - - ifd1Offset = readU32(p, byteOrder); - if (ifd1Offset != 0) { - if (ifd1Offset > size) { + { + const u8* entries = data + ifdOffset; + u16 remaining = size - (u16)ifdOffset; + u16 count; + s32 entriesSize; + u16 index; + if (remaining < 2) { return -161; } - - sval = size - (u16)ifd1Offset; - if (sval < 2) { - return -161; - } - - p = data + (u16)ifd1Offset; - count = readU16(p, byteOrder); + count = readExifU16(entries, byteOrder); entriesSize = count * 12; - sval = (u32)(sval - 2); - if (sval < entriesSize) { + entries += 2; + remaining -= 2; + if (remaining < entriesSize) { return -161; } - - p += 2; - for (i = 0; i < count; i++) { - TMCJPEGDEC_IFD1_tag_parse(pInfo, byteOrder, p); - p += 12; + for (index = 0; index < count; index++) { + TMCJPEGDEC_IFD0_tag_parse(pInfo, byteOrder, entries); + entries += 12; + } + remaining -= entriesSize; + if (remaining < 4) { + return -161; + } + ifdOffset = readU32(entries, byteOrder); + } + if (ifdOffset == 0) { + return 0; + } + if (size < ifdOffset) { + return -161; + } + { + const u8* entries = data + ifdOffset; + u16 remaining = size - (u16)ifdOffset; + u16 count; + s32 entriesSize; + u16 index; + if (remaining < 2) { + return -161; + } + count = readExifU16(entries, byteOrder); + entriesSize = count * 12; + entries += 2; + remaining -= 2; + if (remaining < entriesSize) { + return -161; + } + for (index = 0; index < count; index++) { + TMCJPEGDEC_IFD1_tag_parse(pInfo, byteOrder, entries); + entries += 12; } } - - exifIfdOffset = pInfo->nextIfdOffset; - if (exifIfdOffset == 0 || exifIfdOffset > size) { + ifdOffset = pInfo->nextIfdOffset; + if (size < ifdOffset) { return -161; } - - sval = size - (u16)exifIfdOffset; - if (sval < 2) { - return -161; + { + const u8* entries = data + ifdOffset; + u16 remaining = size - (u16)ifdOffset; + u16 count; + s32 entriesSize; + u16 index; + if (remaining < 2) { + return -161; + } + count = readExifU16(entries, byteOrder); + entriesSize = count * 12; + entries += 2; + remaining -= 2; + if (remaining < entriesSize) { + return -161; + } + for (index = 0; index < count; index++) { + TMCJPEGDEC_IFD0_tag_parse(pInfo, byteOrder, entries); + entries += 12; + } } - - p = data + (u16)exifIfdOffset; - count = readU16(p, byteOrder); - entriesSize = count * 12; - sval = (u32)(sval - 2); - if (sval < entriesSize) { - return -161; - } - - p += 2; - for (i = 0; i < count; i++) { - TMCJPEGDEC_IFD0_tag_parse(pInfo, byteOrder, p); - p += 12; - } - return 0; } @@ -391,7 +351,9 @@ static void TMCJPEGDEC_IFD0_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder, switch (tag) { case 0x0103: - case 0x0111: { + case 0x0111: + case 0x0201: + case 0x0202: { return; } case 0x0112: { @@ -401,18 +363,18 @@ static void TMCJPEGDEC_IFD0_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder, case 0x011A: { u32 offset = readU32(entry + 8, byteOrder); const u8* p = pInfo->thumbnailData + offset; - if (p < pInfo->thumbnailData) { + if (pInfo->thumbnailData > p) { return; } - if (p + 4 > pInfo->dataEnd) { + if (p > pInfo->dataEnd - 4) { return; } pInfo->xResNum = readU32(p, byteOrder); p = (const u8*)(pInfo->thumbnailData + offset + 4); - if (p < pInfo->thumbnailData) { + if (pInfo->thumbnailData > p) { return; } - if (p + 4 > pInfo->dataEnd) { + if (p > pInfo->dataEnd - 4) { return; } pInfo->xResDen = readU32(p, byteOrder); @@ -421,18 +383,18 @@ static void TMCJPEGDEC_IFD0_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder, case 0x011B: { u32 offset = readU32(entry + 8, byteOrder); const u8* p = pInfo->thumbnailData + offset; - if (p < pInfo->thumbnailData) { + if (pInfo->thumbnailData > p) { return; } - if (p + 4 > pInfo->dataEnd) { + if (p > pInfo->dataEnd - 4) { return; } pInfo->yResNum = readU32(p, byteOrder); p = (const u8*)(pInfo->thumbnailData + offset + 4); - if (p < pInfo->thumbnailData) { + if (pInfo->thumbnailData > p) { return; } - if (p + 4 > pInfo->dataEnd) { + if (p > pInfo->dataEnd - 4) { return; } pInfo->yResDen = readU32(p, byteOrder); @@ -444,19 +406,19 @@ static void TMCJPEGDEC_IFD0_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder, } case 0x012D: { u32 offset = readU32(entry + 8, byteOrder); - const u8* p = pInfo->thumbnailData + offset; - u32 j; - u32 i; - for (j = 0; j < 3; j++) { - for (i = 0; i < 256; i++) { - if (p < pInfo->thumbnailData) { - return; + u32 channel; + u32 index; + for (channel = 0; channel < 3; channel++) { + for (index = 0; index < 256; index++) { + const u8* p = pInfo->thumbnailData + offset; + if (pInfo->thumbnailData > p) { + break; } - if (p + 2 > pInfo->dataEnd) { - return; + if (p > pInfo->dataEnd - 2) { + break; } - pInfo->transferFunc[j][i] = readU16(p, byteOrder); - p += 2; + pInfo->transferFunc[channel][index] = readU16(p, byteOrder); + offset += 2; } } return; @@ -464,17 +426,18 @@ static void TMCJPEGDEC_IFD0_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder, case 0x0132: { u32 offset = readU32(entry + 8, byteOrder); const u8* p = pInfo->thumbnailData + offset; - if (p < pInfo->thumbnailData) { + if (pInfo->thumbnailData > p) { return; } - if (p + 20 > pInfo->dataEnd) { + if (p > pInfo->dataEnd - 20) { return; } - *(u32*)(pInfo->dateTime + 0) = *(u32*)(p + 0); - *(u32*)(pInfo->dateTime + 4) = *(u32*)(p + 4); - *(u32*)(pInfo->dateTime + 8) = *(u32*)(p + 8); - *(u32*)(pInfo->dateTime + 12) = *(u32*)(p + 12); - *(u32*)(pInfo->dateTime + 16) = *(u32*)(p + 16); + { + u32 index; + for (index = 0; index < 20; index++) { + pInfo->dateTime[index] = p[index]; + } + } return; } case 0x0213: { @@ -538,52 +501,54 @@ static void TMCJPEGDEC_IFD1_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder, switch (tag) { case 0x0132: case 0x0111: + case 0x0112: case 0x012D: case 0x0213: case 0x8769: case 0x9000: - case 0x9101: { - return; - } - case 0x0103: { - pInfo->compressionIfd1 = readU16(entry + 8, byteOrder); + case 0x9101: + case 0xA003: { return; } case 0x011A: { - u32 offset = readU32(entry + 8, byteOrder); - const u8* p = pInfo->thumbnailData + offset; - if (p < pInfo->thumbnailData) { + u32 offset; + const u8* p; + offset = readU32(entry + 8, byteOrder); + p = pInfo->thumbnailData + offset; + if (pInfo->thumbnailData > p) { return; } - if (p + 4 > pInfo->dataEnd) { + if (p > pInfo->dataEnd - 4) { return; } pInfo->xResNumIfd1 = readU32(p, byteOrder); p = (const u8*)(pInfo->thumbnailData + offset + 4); - if (p < pInfo->thumbnailData) { + if (pInfo->thumbnailData > p) { return; } - if (p + 4 > pInfo->dataEnd) { + if (p > pInfo->dataEnd - 4) { return; } pInfo->xResDenIfd1 = readU32(p, byteOrder); return; } case 0x011B: { - u32 offset = readU32(entry + 8, byteOrder); - const u8* p = pInfo->thumbnailData + offset; - if (p < pInfo->thumbnailData) { + u32 offset; + const u8* p; + offset = readU32(entry + 8, byteOrder); + p = pInfo->thumbnailData + offset; + if (pInfo->thumbnailData > p) { return; } - if (p + 4 > pInfo->dataEnd) { + if (p > pInfo->dataEnd - 4) { return; } pInfo->planarConfigIfd1 = readU32(p, byteOrder); p = (const u8*)(pInfo->thumbnailData + offset + 4); - if (p < pInfo->thumbnailData) { + if (pInfo->thumbnailData > p) { return; } - if (p + 4 > pInfo->dataEnd) { + if (p > pInfo->dataEnd - 4) { return; } pInfo->yResDenIfd1 = readU32(p, byteOrder); @@ -593,6 +558,10 @@ static void TMCJPEGDEC_IFD1_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder, pInfo->resUnitIfd1 = readU16(entry + 8, byteOrder); return; } + case 0x0103: { + pInfo->compressionIfd1 = readU16(entry + 8, byteOrder); + return; + } case 0x0201: { pInfo->thumbnailOffset = readU32(entry + 8, byteOrder); return; diff --git a/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565.c b/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565.c index d10a492f..26505d80 100644 --- a/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565.c +++ b/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565.c @@ -50,7 +50,7 @@ s32 TMCJPEGDEC_set_converterRGB565(TMCCJPEGDecWork* work) { work->pConvRowPtrs[0] = (void*)ptr; work->pConvRowPtrs[1] = (void*)(ptr + mode); work->pConvRowPtrs[5] = (void*)(ob + 0x84); - work->pConvRowPtrs[6] = (void*)(ob + 0xC4); + work->pConvRowPtrs[6] = (void*)(ob + 0xc4); work->pitch = 0x10; work->converterFlags = 0; break; @@ -58,12 +58,15 @@ s32 TMCJPEGDEC_set_converterRGB565(TMCCJPEGDecWork* work) { case 2: { u8 mode = work->idctMode; u8* ptr = ob + 4; + u8* p1 = ptr + mode; + u8* p2 = ptr + mode * 16; + u8* p3 = p2 + mode; work->pConverterFunc = TMCJPEGDEC_converterYUV420toRGB565; work->pConverterFuncEdge = TMCJPEGDEC_converterYUV420toRGB565edge; work->pConvRowPtrs[0] = (void*)ptr; - work->pConvRowPtrs[1] = (void*)(ptr + mode); - work->pConvRowPtrs[2] = (void*)(ptr + mode * 16); - work->pConvRowPtrs[3] = (void*)(ptr + mode * 16 + mode); + work->pConvRowPtrs[1] = (void*)p1; + work->pConvRowPtrs[2] = (void*)p2; + work->pConvRowPtrs[3] = (void*)p3; work->pConvRowPtrs[5] = (void*)(ob + 0x104); work->pConvRowPtrs[6] = (void*)(ob + 0x144); work->pitch = 0x10; @@ -77,26 +80,26 @@ s32 TMCJPEGDEC_set_converterRGB565(TMCCJPEGDecWork* work) { work->pConverterFuncEdge = TMCJPEGDEC_converterYUV211toRGB565edge; work->pConvRowPtrs[0] = (void*)ptr; work->pConvRowPtrs[1] = (void*)(ptr + mode * 8); - work->pConvRowPtrs[5] = (void*)(ptr + 0x84); - work->pConvRowPtrs[6] = (void*)(ptr + 0xC4); + work->pConvRowPtrs[5] = (void*)(ob + 0x84); + work->pConvRowPtrs[6] = (void*)(ob + 0xc4); work->pitch = 0x08; work->converterFlags = 0; break; } case 4: { - work->pConverterFunc = TMCJPEGDEC_converterYUV400toRGB565; - work->pConverterFuncEdge = TMCJPEGDEC_converterYUV400toRGB565edge; - work->pConvRowPtrs[0] = (void*)(ob + 4); + work->pConverterFunc = TMCJPEGDEC_converterYUV444toRGB565; + work->pConverterFuncEdge = TMCJPEGDEC_converterYUV444toRGB565edge; + work->pConvRowPtrs[0] = (void*)(ob + 0x4); + work->pConvRowPtrs[5] = (void*)(ob + 0x44); + work->pConvRowPtrs[6] = (void*)(ob + 0x84); work->pitch = 0x08; work->converterFlags = 0; break; } case 5: { - work->pConverterFunc = TMCJPEGDEC_converterYUV444toRGB565; - work->pConverterFuncEdge = TMCJPEGDEC_converterYUV444toRGB565edge; - work->pConvRowPtrs[0] = (void*)(ob + 4); - work->pConvRowPtrs[5] = (void*)(ob + 0x44); - work->pConvRowPtrs[6] = (void*)(ob + 0x84); + work->pConverterFunc = TMCJPEGDEC_converterYUV400toRGB565; + work->pConverterFuncEdge = TMCJPEGDEC_converterYUV400toRGB565edge; + work->pConvRowPtrs[0] = (void*)(ob + 0x4); work->pitch = 0x08; work->converterFlags = 0; break; @@ -107,18 +110,723 @@ s32 TMCJPEGDEC_set_converterRGB565(TMCCJPEGDecWork* work) { } { - u32 fw = st->jpegWidth; - u32 fh = st->jpegHeight; - s32 bw = (s32)(((fw << 30) - (fw >> 31)) * 4 + (fw >> 31)); - s32 bh = (s32)(((fh << 30) - (fh >> 31)) * 4 + (fh >> 31)); - { - s32 nb = -bw; - s32 nb2 = -bh; - bw = ((nb | bw) >> 31) + (fw >> 2); - bh = ((nb2 | bh) >> 31) + (fh >> 2); - } - st->convWidth = bw << 2; - st->convHeight = bh << 2; + s32 width = st->jpegWidth; + s32 height = st->jpegHeight; + st->convWidth = ((u32)width / 4 + (width % 4 != 0)) * 4; + st->convHeight = ((u32)height / 4 + (height % 4 != 0)) * 4; } return 0; } + +static void TMCJPEGDEC_converterYUV411toRGB565(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + u8* cb = work->convBuf + 260; + u8* cr = work->convBuf + 324; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 2; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + width = 32 / state->scaleFactor; + height = 8 / state->scaleFactor; + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 lumaSkip = 32 - width; + s32 chromaSkip = lumaSkip >> 2; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 4) { + s32 redOffset, greenOffset, blueOffset; + { + s32 cbValue = (s8)*cb++; + s32 crValue = (s8)*cr++; + redOffset = (crValue * 359) >> 8; + greenOffset = -(cbValue * 88 + crValue * 183) >> 8; + blueOffset = (cbValue * 454) >> 8; + } + { + s32 value = luminance[0]; + s32 red = value + redOffset; + s32 green = value + greenOffset; + s32 blue = value + blueOffset; + if ((blue | red | green) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column & 3) + ((((column) >> 2) + tileRow) << 4)] = + ((blue & 0xF8) >> 3) + ((red & 0xF8) << 8) + ((green & 0xFC) << 3); + } + { + s32 value = luminance[1]; + s32 red = value + redOffset; + s32 green = value + greenOffset; + s32 blue = value + blueOffset; + if ((blue | red | green) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column + 1 & 3) + ((((column + 1) >> 2) + tileRow) << 4)] = + ((blue & 0xF8) >> 3) + ((red & 0xF8) << 8) + ((green & 0xFC) << 3); + } + { + s32 value = luminance[2]; + s32 red = value + redOffset; + s32 green = value + greenOffset; + s32 blue = value + blueOffset; + if ((blue | red | green) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column + 2 & 3) + ((((column + 2) >> 2) + tileRow) << 4)] = + ((blue & 0xF8) >> 3) + ((red & 0xF8) << 8) + ((green & 0xFC) << 3); + } + { + s32 value = luminance[3]; + s32 red = value + redOffset; + s32 green = value + greenOffset; + s32 blue = value + blueOffset; + if ((blue | red | green) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column + 3 & 3) + ((((column + 3) >> 2) + tileRow) << 4)] = + ((blue & 0xF8) >> 3) + ((red & 0xF8) << 8) + ((green & 0xFC) << 3); + } + luminance += 4; + } + luminance += lumaSkip; + cb += chromaSkip; + cr += chromaSkip; + } + } +} + +static void TMCJPEGDEC_converterYUV411toRGB565edge(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + u8* cb = work->convBuf + 260; + u8* cr = work->convBuf + 324; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 2; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + if (state->dataSizeX == (u32)x) { + width = state->stepXExt; + } else { + width = 32 / state->scaleFactor; + } + if (state->dataSizeY == (u32)y) { + height = state->stepYExt; + } else { + height = 8 / state->scaleFactor; + } + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 lumaSkip = 32 - width; + s32 chromaSkip = lumaSkip >> 2; + s32 redOffset = 0, greenOffset = 0, blueOffset = 0; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 1) { + if ((column & 3) == 0) { + s32 cbValue = (s8)*cb++; + s32 crValue = (s8)*cr++; + redOffset = (crValue * 359) >> 8; + greenOffset = -(cbValue * 88 + crValue * 183) >> 8; + blueOffset = (cbValue * 454) >> 8; + } + { + s32 value = luminance[0]; + s32 red = value + redOffset; + s32 green = value + greenOffset; + s32 blue = value + blueOffset; + if ((blue | red | green) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column & 3) + ((((column) >> 2) + tileRow) << 4)] = + ((blue & 0xF8) >> 3) + ((red & 0xF8) << 8) + ((green & 0xFC) << 3); + } + luminance += 1; + } + luminance += lumaSkip; + cb += chromaSkip; + cr += chromaSkip; + } + } +} + +static void TMCJPEGDEC_converterYUV422toRGB565(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + u8* cb = work->convBuf + 132; + u8* cr = work->convBuf + 196; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 2; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + width = 16 / state->scaleFactor; + height = 8 / state->scaleFactor; + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 lumaSkip = 16 - width; + s32 chromaSkip = lumaSkip >> 1; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 2) { + s32 redOffset, greenOffset, blueOffset; + { + s32 cbValue = (s8)*cb++; + s32 crValue = (s8)*cr++; + redOffset = (crValue * 359) >> 8; + greenOffset = -(cbValue * 88 + crValue * 183) >> 8; + blueOffset = (cbValue * 454) >> 8; + } + { + s32 value = luminance[0]; + s32 red = value + redOffset; + s32 green = value + greenOffset; + s32 blue = value + blueOffset; + if ((blue | red | green) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column & 3) + ((((column) >> 2) + tileRow) << 4)] = + ((blue & 0xF8) >> 3) + ((red & 0xF8) << 8) + ((green & 0xFC) << 3); + } + { + s32 value = luminance[1]; + s32 red = value + redOffset; + s32 green = value + greenOffset; + s32 blue = value + blueOffset; + if ((blue | red | green) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column + 1 & 3) + ((((column + 1) >> 2) + tileRow) << 4)] = + ((blue & 0xF8) >> 3) + ((red & 0xF8) << 8) + ((green & 0xFC) << 3); + } + luminance += 2; + } + luminance += lumaSkip; + cb += chromaSkip; + cr += chromaSkip; + } + } +} + +static void TMCJPEGDEC_converterYUV422toRGB565edge(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + u8* cb = work->convBuf + 132; + u8* cr = work->convBuf + 196; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 2; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + if (state->dataSizeX == (u32)x) { + width = state->stepXExt; + } else { + width = 16 / state->scaleFactor; + } + if (state->dataSizeY == (u32)y) { + height = state->stepYExt; + } else { + height = 8 / state->scaleFactor; + } + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 lumaSkip = 16 - width; + s32 chromaSkip = lumaSkip >> 1; + s32 redOffset = 0, greenOffset = 0, blueOffset = 0; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 1) { + if ((column & 1) == 0) { + s32 cbValue = (s8)*cb++; + s32 crValue = (s8)*cr++; + redOffset = (crValue * 359) >> 8; + greenOffset = -(cbValue * 88 + crValue * 183) >> 8; + blueOffset = (cbValue * 454) >> 8; + } + { + s32 value = luminance[0]; + s32 red = value + redOffset; + s32 green = value + greenOffset; + s32 blue = value + blueOffset; + if ((blue | red | green) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column & 3) + ((((column) >> 2) + tileRow) << 4)] = + ((blue & 0xF8) >> 3) + ((red & 0xF8) << 8) + ((green & 0xFC) << 3); + } + luminance += 1; + } + luminance += lumaSkip; + cb += chromaSkip; + cr += chromaSkip; + } + } +} + +static void TMCJPEGDEC_converterYUV420toRGB565(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + u8* cb = work->convBuf + 260; + u8* cr = work->convBuf + 324; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 2; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + width = 16 / state->scaleFactor; + height = 16 / state->scaleFactor; + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 lumaSkip = 16 - width; + s32 chromaSkip = lumaSkip >> 1; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 2) { + s32 redOffset, greenOffset, blueOffset; + { + s32 cbValue = (s8)*cb++; + s32 crValue = (s8)*cr++; + redOffset = (crValue * 359) >> 8; + greenOffset = -(cbValue * 88 + crValue * 183) >> 8; + blueOffset = (cbValue * 454) >> 8; + } + { + s32 value = luminance[0]; + s32 red = value + redOffset; + s32 green = value + greenOffset; + s32 blue = value + blueOffset; + if ((blue | red | green) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column & 3) + ((((column) >> 2) + tileRow) << 4)] = + ((blue & 0xF8) >> 3) + ((red & 0xF8) << 8) + ((green & 0xFC) << 3); + } + { + s32 value = luminance[1]; + s32 red = value + redOffset; + s32 green = value + greenOffset; + s32 blue = value + blueOffset; + if ((blue | red | green) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column + 1 & 3) + ((((column + 1) >> 2) + tileRow) << 4)] = + ((blue & 0xF8) >> 3) + ((red & 0xF8) << 8) + ((green & 0xFC) << 3); + } + luminance += 2; + } + luminance += lumaSkip; + if (y & 1) { + cb += chromaSkip; + cr += chromaSkip; + } else { + cb -= (width + 1) >> 1; + cr -= (width + 1) >> 1; + } + } + } +} + +static void TMCJPEGDEC_converterYUV420toRGB565edge(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + u8* cb = work->convBuf + 260; + u8* cr = work->convBuf + 324; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 2; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + if (state->dataSizeX == (u32)x) { + width = state->stepXExt; + } else { + width = 16 / state->scaleFactor; + } + if (state->dataSizeY == (u32)y) { + height = state->stepYExt; + } else { + height = 16 / state->scaleFactor; + } + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 lumaSkip = 16 - width; + s32 chromaSkip = lumaSkip >> 1; + s32 redOffset = 0, greenOffset = 0, blueOffset = 0; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 1) { + if ((column & 1) == 0) { + s32 cbValue = (s8)*cb++; + s32 crValue = (s8)*cr++; + redOffset = (crValue * 359) >> 8; + greenOffset = -(cbValue * 88 + crValue * 183) >> 8; + blueOffset = (cbValue * 454) >> 8; + } + { + s32 value = luminance[0]; + s32 red = value + redOffset; + s32 green = value + greenOffset; + s32 blue = value + blueOffset; + if ((blue | red | green) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column & 3) + ((((column) >> 2) + tileRow) << 4)] = + ((blue & 0xF8) >> 3) + ((red & 0xF8) << 8) + ((green & 0xFC) << 3); + } + luminance += 1; + } + luminance += lumaSkip; + if (y & 1) { + cb += chromaSkip; + cr += chromaSkip; + } else { + cb -= (width + 1) >> 1; + cr -= (width + 1) >> 1; + } + } + } +} + +static void TMCJPEGDEC_converterYUV211toRGB565(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + u8* cb = work->convBuf + 132; + u8* cr = work->convBuf + 196; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 2; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + width = 8 / state->scaleFactor; + height = 16 / state->scaleFactor; + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 lumaSkip = 8 - width; + s32 chromaSkip = lumaSkip >> 0; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 1) { + s32 redOffset, greenOffset, blueOffset; + { + s32 cbValue = (s8)*cb++; + s32 crValue = (s8)*cr++; + redOffset = (crValue * 359) >> 8; + greenOffset = -(cbValue * 88 + crValue * 183) >> 8; + blueOffset = (cbValue * 454) >> 8; + } + { + s32 value = luminance[0]; + s32 red = value + redOffset; + s32 green = value + greenOffset; + s32 blue = value + blueOffset; + if ((blue | red | green) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column & 3) + ((((column) >> 2) + tileRow) << 4)] = + ((blue & 0xF8) >> 3) + ((red & 0xF8) << 8) + ((green & 0xFC) << 3); + } + luminance += 1; + } + luminance += lumaSkip; + if (y & 1) { + cb += chromaSkip; + cr += chromaSkip; + } else { + cb -= (width + 0) >> 0; + cr -= (width + 0) >> 0; + } + } + } +} + +static void TMCJPEGDEC_converterYUV211toRGB565edge(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + u8* cb = work->convBuf + 132; + u8* cr = work->convBuf + 196; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 2; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + if (state->dataSizeX == (u32)x) { + width = state->stepXExt; + } else { + width = 8 / state->scaleFactor; + } + if (state->dataSizeY == (u32)y) { + height = state->stepYExt; + } else { + height = 16 / state->scaleFactor; + } + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 lumaSkip = 8 - width; + s32 chromaSkip = lumaSkip >> 0; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 1) { + s32 redOffset, greenOffset, blueOffset; + { + s32 cbValue = (s8)*cb++; + s32 crValue = (s8)*cr++; + redOffset = (crValue * 359) >> 8; + greenOffset = -(cbValue * 88 + crValue * 183) >> 8; + blueOffset = (cbValue * 454) >> 8; + } + { + s32 value = luminance[0]; + s32 red = value + redOffset; + s32 green = value + greenOffset; + s32 blue = value + blueOffset; + if ((blue | red | green) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column & 3) + ((((column) >> 2) + tileRow) << 4)] = + ((blue & 0xF8) >> 3) + ((red & 0xF8) << 8) + ((green & 0xFC) << 3); + } + luminance += 1; + } + luminance += lumaSkip; + if (y & 1) { + cb += chromaSkip; + cr += chromaSkip; + } else { + cb -= (width + 0) >> 0; + cr -= (width + 0) >> 0; + } + } + } +} + +static void TMCJPEGDEC_converterYUV444toRGB565(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + u8* cb = work->convBuf + 68; + u8* cr = work->convBuf + 132; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 2; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + width = 8 / state->scaleFactor; + height = 8 / state->scaleFactor; + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 lumaSkip = 8 - width; + s32 chromaSkip = lumaSkip >> 0; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 1) { + s32 redOffset, greenOffset, blueOffset; + { + s32 cbValue = (s8)*cb++; + s32 crValue = (s8)*cr++; + redOffset = (crValue * 359) >> 8; + greenOffset = -(cbValue * 88 + crValue * 183) >> 8; + blueOffset = (cbValue * 454) >> 8; + } + { + s32 value = luminance[0]; + s32 red = value + redOffset; + s32 green = value + greenOffset; + s32 blue = value + blueOffset; + if ((blue | red | green) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column & 3) + ((((column) >> 2) + tileRow) << 4)] = + ((blue & 0xF8) >> 3) + ((red & 0xF8) << 8) + ((green & 0xFC) << 3); + } + luminance += 1; + } + luminance += lumaSkip; + cb += chromaSkip; + cr += chromaSkip; + } + } +} + +static void TMCJPEGDEC_converterYUV444toRGB565edge(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + u8* cb = work->convBuf + 68; + u8* cr = work->convBuf + 132; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 2; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + if (state->dataSizeX == (u32)x) { + width = state->stepXExt; + } else { + width = 8 / state->scaleFactor; + } + if (state->dataSizeY == (u32)y) { + height = state->stepYExt; + } else { + height = 8 / state->scaleFactor; + } + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 lumaSkip = 8 - width; + s32 chromaSkip = lumaSkip >> 0; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 1) { + s32 redOffset, greenOffset, blueOffset; + { + s32 cbValue = (s8)*cb++; + s32 crValue = (s8)*cr++; + redOffset = (crValue * 359) >> 8; + greenOffset = -(cbValue * 88 + crValue * 183) >> 8; + blueOffset = (cbValue * 454) >> 8; + } + { + s32 value = luminance[0]; + s32 red = value + redOffset; + s32 green = value + greenOffset; + s32 blue = value + blueOffset; + if ((blue | red | green) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column & 3) + ((((column) >> 2) + tileRow) << 4)] = + ((blue & 0xF8) >> 3) + ((red & 0xF8) << 8) + ((green & 0xFC) << 3); + } + luminance += 1; + } + luminance += lumaSkip; + cb += chromaSkip; + cr += chromaSkip; + } + } +} + +static void TMCJPEGDEC_converterYUV400toRGB565(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 2; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + width = 8 / state->scaleFactor; + height = 8 / state->scaleFactor; + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 lumaSkip = 8 - width; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 1) { + s32 value = *luminance++; + s32 red, green, blue; + if (value >> 8) { + blue = (value > 255) ? 255 : value & ~(value >> 31); + green = (value > 255) ? 255 : value & ~(value >> 31); + red = (value > 255) ? 255 : value & ~(value >> 31); + } else { + red = green = blue = value; + } + output[(column & 3) + (((column >> 2) + tileRow) << 4)] = + ((blue & 0xF8) >> 3) + ((red & 0xF8) << 8) + ((green & 0xFC) << 3); + } + luminance += lumaSkip; + } + } +} + +static void TMCJPEGDEC_converterYUV400toRGB565edge(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 2; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + if (state->dataSizeX == (u32)x) { + width = state->stepXExt; + } else { + width = 8 / state->scaleFactor; + } + if (state->dataSizeY == (u32)y) { + height = state->stepYExt; + } else { + height = 8 / state->scaleFactor; + } + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 lumaSkip = 8 - width; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 1) { + s32 value = *luminance++; + s32 red, green, blue; + if (value >> 8) { + blue = (value > 255) ? 255 : value & ~(value >> 31); + green = (value > 255) ? 255 : value & ~(value >> 31); + red = (value > 255) ? 255 : value & ~(value >> 31); + } else { + red = green = blue = value; + } + output[(column & 3) + (((column >> 2) + tileRow) << 4)] = + ((blue & 0xF8) >> 3) + ((red & 0xF8) << 8) + ((green & 0xFC) << 3); + } + luminance += lumaSkip; + } + } +} diff --git a/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8.c b/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8.c index a3cf3164..bd0e2577 100644 --- a/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8.c +++ b/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8.c @@ -13,86 +13,75 @@ static void TMCJPEGDEC_converterYUV444toRGBA8edge(TMCCJPEGDecWork*, s32, s32); static void TMCJPEGDEC_converterYUV400toRGBA8(TMCCJPEGDecWork*, s32, s32); static void TMCJPEGDEC_converterYUV400toRGBA8edge(TMCCJPEGDecWork*, s32, s32); -static s32 clampU8(s32 v) { - if (v > 0xFF) { - return 0xFF; - } else { - s32 t = v >> 31; - v &= ~t; - return v; - } -} - s32 TMCJPEGDEC_set_converterRGBA8(TMCCJPEGDecWork* work) { - u8* ob = work->convBuf; - u8 cc = work->componentCount; - TMCCJPEGDecState* st = work->pState; + u8* ob; + s32 cc; + TMCCJPEGDecState* st; + + ob = work->convBuf; + cc = work->componentCount; + st = work->pState; switch (cc) { case 0: { u8 mode = work->idctMode; - u8* p0 = ob + 4; - u8* p1 = p0 + mode; + u8* ptr = ob + 4; + u8* p1 = ptr + mode; u8* p2 = p1 + mode; u8* p3 = p2 + mode; work->pConverterFunc = TMCJPEGDEC_converterYUV411toRGBA8; work->pConverterFuncEdge = TMCJPEGDEC_converterYUV411toRGBA8edge; - work->pConvRowPtrs[0] = p0; - work->pConvRowPtrs[1] = p1; - work->pConvRowPtrs[2] = p2; - work->pConvRowPtrs[3] = p3; - work->pConvRowPtrs[5] = ob + 0x104; - work->pConvRowPtrs[6] = ob + 0x144; + work->pConvRowPtrs[0] = (void*)ptr; + work->pConvRowPtrs[1] = (void*)p1; + work->pConvRowPtrs[2] = (void*)p2; + work->pConvRowPtrs[3] = (void*)p3; + work->pConvRowPtrs[5] = (void*)(ob + 0x104); + work->pConvRowPtrs[6] = (void*)(ob + 0x144); work->pitch = 0x20; work->converterFlags = 0; break; } case 1: { u8 mode = work->idctMode; - u8* p0 = ob + 4; - u8* p1 = p0 + mode; - + u8* ptr = ob + 4; work->pConverterFunc = TMCJPEGDEC_converterYUV422toRGBA8; work->pConverterFuncEdge = TMCJPEGDEC_converterYUV422toRGBA8edge; - work->pConvRowPtrs[0] = p0; - work->pConvRowPtrs[1] = p1; - work->pConvRowPtrs[5] = ob + 0x84; - work->pConvRowPtrs[6] = ob + 0xC4; + work->pConvRowPtrs[0] = (void*)ptr; + work->pConvRowPtrs[1] = (void*)(ptr + mode); + work->pConvRowPtrs[5] = (void*)(ob + 0x84); + work->pConvRowPtrs[6] = (void*)(ob + 0xC4); work->pitch = 0x10; work->converterFlags = 0; break; } case 2: { u8 mode = work->idctMode; - u8* p0 = ob + 4; - u8* p1 = p0 + mode; - u8* p2 = p0 + mode * 16; + u8* ptr = ob + 4; + u8* p1 = ptr + mode; + u8* p2 = ptr + mode * 16; u8* p3 = p2 + mode; - work->pConverterFunc = TMCJPEGDEC_converterYUV420toRGBA8; work->pConverterFuncEdge = TMCJPEGDEC_converterYUV420toRGBA8edge; - work->pConvRowPtrs[0] = p0; - work->pConvRowPtrs[1] = p1; - work->pConvRowPtrs[2] = p2; - work->pConvRowPtrs[3] = p3; - work->pConvRowPtrs[5] = ob + 0x104; - work->pConvRowPtrs[6] = ob + 0x144; + work->pConvRowPtrs[0] = (void*)ptr; + work->pConvRowPtrs[1] = (void*)p1; + work->pConvRowPtrs[2] = (void*)p2; + work->pConvRowPtrs[3] = (void*)p3; + work->pConvRowPtrs[5] = (void*)(ob + 0x104); + work->pConvRowPtrs[6] = (void*)(ob + 0x144); work->pitch = 0x10; work->converterFlags = 0; break; } case 3: { u8 mode = work->idctMode; - u8* p0 = ob + 4; - u8* p1 = p0 + mode * 8; - + u8* ptr = ob + 4; work->pConverterFunc = TMCJPEGDEC_converterYUV211toRGBA8; work->pConverterFuncEdge = TMCJPEGDEC_converterYUV211toRGBA8edge; - work->pConvRowPtrs[0] = p0; - work->pConvRowPtrs[1] = p1; - work->pConvRowPtrs[5] = ob + 0x84; - work->pConvRowPtrs[6] = ob + 0xC4; + work->pConvRowPtrs[0] = (void*)ptr; + work->pConvRowPtrs[1] = (void*)(ptr + mode * 8); + work->pConvRowPtrs[5] = (void*)(ob + 0x84); + work->pConvRowPtrs[6] = (void*)(ob + 0xC4); work->pitch = 0x08; work->converterFlags = 0; break; @@ -100,9 +89,9 @@ s32 TMCJPEGDEC_set_converterRGBA8(TMCCJPEGDecWork* work) { case 4: { work->pConverterFunc = TMCJPEGDEC_converterYUV444toRGBA8; work->pConverterFuncEdge = TMCJPEGDEC_converterYUV444toRGBA8edge; - work->pConvRowPtrs[0] = ob + 4; - work->pConvRowPtrs[5] = ob + 0x44; - work->pConvRowPtrs[6] = ob + 0x84; + work->pConvRowPtrs[0] = (void*)(ob + 4); + work->pConvRowPtrs[5] = (void*)(ob + 0x44); + work->pConvRowPtrs[6] = (void*)(ob + 0x84); work->pitch = 0x08; work->converterFlags = 0; break; @@ -110,7 +99,7 @@ s32 TMCJPEGDEC_set_converterRGBA8(TMCCJPEGDecWork* work) { case 5: { work->pConverterFunc = TMCJPEGDEC_converterYUV400toRGBA8; work->pConverterFuncEdge = TMCJPEGDEC_converterYUV400toRGBA8edge; - work->pConvRowPtrs[0] = ob + 4; + work->pConvRowPtrs[0] = (void*)(ob + 4); work->pitch = 0x08; work->converterFlags = 0; break; @@ -121,1246 +110,757 @@ s32 TMCJPEGDEC_set_converterRGBA8(TMCCJPEGDecWork* work) { } { - int fw = st->jpegWidth; - int fh = st->jpegHeight; - - st->convWidth = (fw / 4 + (fw % 4 != 0)) * 4; - st->convHeight = (fh / 4 + (fh % 4 != 0)) * 4; + s32 width = st->jpegWidth; + s32 height = st->jpegHeight; + st->convWidth = ((u32)width / 4 + (width % 4 != 0)) * 4; + st->convHeight = ((u32)height / 4 + (height % 4 != 0)) * 4; } - return 0; } static void TMCJPEGDEC_converterYUV411toRGBA8(TMCCJPEGDecWork* work, s32 x, s32 y) { - TMCCJPEGDecState* st; - s32 bw; - u8* out; - s32 ss; - s32 step, step_v; - s32 x_end, y_end; - u8* cb_row; - u8* y_row; - u8* cr_row; - - st = work->pState; - cb_row = work->convBuf + 4; - y_row = work->convBuf + 0x104; - cr_row = work->convBuf + 0x144; - bw = st->convWidth; - out = (u8*)st->pTexBuffer; - ss = st->scaleFactor; - step = 0x20 / ss; - step_v = 0x08 / ss; - x_end = x + step; - y_end = y + step_v; - + u8* luminance = work->convBuf + 4; + u8* cb = work->convBuf + 260; + u8* cr = work->convBuf + 324; + TMCCJPEGDecState* state = work->pState; + s32 tileWidth = (state->convWidth >> 2) << 1; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + width = 32 / state->scaleFactor; + height = 8 / state->scaleFactor; { - s32 cb_skip = 0x20 - step; - s32 cb_step = cb_skip >> 2; - s32 stride = (bw >> 1) & 0x7FFFFFFE; - s32 count = (x_end - x + 3) >> 2; - s32 yv; - s32 crv; - s32 s; - s32 ra; - s32 ga; - s32 ba; - s32 rr; - s32 gg; - s32 bb; - s32 n; - s32 x_pos; - s32 row_base; - u8* ob; - s32 xo; - s32 xg; - s32 off; - s32 ba0; - - for (; y < y_end; y++) { - row_base = (y >> 2) * stride; - ob = out + ((y & 3) << 3); - - n = count; - x_pos = x; - - if (x < x_end) { - do { - yv = *y_row; - y_row = y_row + 1; - crv = *cr_row; - cr_row = cr_row + 1; - - ra = (crv * 0x167) >> 8; - s = (yv * 0x58) + (crv * 0xB7); - ga = -s >> 8; - ba = (yv * 0x1C6) >> 8; - - { - rr = cb_row[0] + ra; - gg = cb_row[0] + ga; - bb = cb_row[0] + ba; - if ((rr | gg | bb) >> 8) { - rr = clampU8(rr); - gg = clampU8(gg); - bb = clampU8(bb); - } - xo = x_pos & 3; - xg = (x_pos >> 2) << 1; - off = (xg + row_base) << 4; - ba0 = off + xo; - ((u16*)(ob + (ba0 << 1)))[0] = (u16)((u8)bb - 0x100); - ((u16*)(ob + ((ba0 + 1) << 1)))[0] = (u16)((gg & 0xFF) * 256 + (rr & 0xFF)); - x_pos++; + s32 yEnd = y + height; + s32 xEnd = x + width; + s32 lumaSkip = 32 - width; + s32 chromaSkip = lumaSkip >> 2; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 4) { + s32 redOffset, greenOffset, blueOffset; + { + s32 cbValue = (s8)*cb++; + s32 crValue = (s8)*cr++; + greenOffset = -(cbValue * 88 + crValue * 183) >> 8; + redOffset = (crValue * 359) >> 8; + blueOffset = (cbValue * 454) >> 8; + } + { + s32 value = luminance[0]; + s32 green = value + greenOffset; + s32 red = value + redOffset; + s32 blue = value + blueOffset; + if ((blue | green | red) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); } - - { - rr = cb_row[1] + ra; - gg = cb_row[1] + ga; - bb = cb_row[1] + ba; - if ((rr | gg | bb) >> 8) { - rr = clampU8(rr); - gg = clampU8(gg); - bb = clampU8(bb); - } - xo = x_pos & 3; - xg = (x_pos >> 2) << 1; - off = (xg + row_base) << 4; - ba0 = off + xo; - ((u16*)(ob + (ba0 << 1)))[0] = (u16)((u8)bb - 0x100); - ((u16*)(ob + ((ba0 + 1) << 1)))[0] = (u16)((gg & 0xFF) * 256 + (rr & 0xFF)); - x_pos++; + output[(column & 3) + (((((column) >> 2) << 1) + tileRow) << 4)] = + (u8)red + 0x10000 - 0x100; + output[(column & 3) + (((((column) >> 2) << 1) + tileRow + 1) << 4)] = + ((green & 255) << 8) + (blue & 255); + } + { + s32 value = luminance[1]; + s32 green = value + greenOffset; + s32 red = value + redOffset; + s32 blue = value + blueOffset; + if ((blue | green | red) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); } - - { - rr = cb_row[2] + ra; - gg = cb_row[2] + ga; - bb = cb_row[2] + ba; - if ((rr | gg | bb) >> 8) { - rr = clampU8(rr); - gg = clampU8(gg); - bb = clampU8(bb); - } - xo = x_pos & 3; - xg = (x_pos >> 2) << 1; - off = (xg + row_base) << 4; - ba0 = off + xo; - ((u16*)(ob + (ba0 << 1)))[0] = (u16)((u8)bb - 0x100); - ((u16*)(ob + ((ba0 + 1) << 1)))[0] = (u16)((gg & 0xFF) * 256 + (rr & 0xFF)); - x_pos++; + output[(column + 1 & 3) + (((((column + 1) >> 2) << 1) + tileRow) << 4)] = + (u8)red + 0x10000 - 0x100; + output[(column + 1 & 3) + (((((column + 1) >> 2) << 1) + tileRow + 1) << 4)] = + ((green & 255) << 8) + (blue & 255); + } + { + s32 value = luminance[2]; + s32 green = value + greenOffset; + s32 red = value + redOffset; + s32 blue = value + blueOffset; + if ((blue | green | red) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); } - - { - rr = cb_row[3] + ra; - gg = cb_row[3] + ga; - bb = cb_row[3] + ba; - if ((rr | gg | bb) >> 8) { - rr = clampU8(rr); - gg = clampU8(gg); - bb = clampU8(bb); - } - xo = x_pos & 3; - xg = (x_pos >> 2) << 1; - off = (xg + row_base) << 4; - ba0 = off + xo; - ((u16*)(ob + (ba0 << 1)))[0] = (u16)((u8)bb - 0x100); - ((u16*)(ob + ((ba0 + 1) << 1)))[0] = (u16)((gg & 0xFF) * 256 + (rr & 0xFF)); - x_pos++; + output[(column + 2 & 3) + (((((column + 2) >> 2) << 1) + tileRow) << 4)] = + (u8)red + 0x10000 - 0x100; + output[(column + 2 & 3) + (((((column + 2) >> 2) << 1) + tileRow + 1) << 4)] = + ((green & 255) << 8) + (blue & 255); + } + { + s32 value = luminance[3]; + s32 green = value + greenOffset; + s32 red = value + redOffset; + s32 blue = value + blueOffset; + if ((blue | green | red) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); } - - cb_row += 4; - n--; - } while (n); + output[(column + 3 & 3) + (((((column + 3) >> 2) << 1) + tileRow) << 4)] = + (u8)red + 0x10000 - 0x100; + output[(column + 3 & 3) + (((((column + 3) >> 2) << 1) + tileRow + 1) << 4)] = + ((green & 255) << 8) + (blue & 255); + } + luminance += 4; } - - cb_row += cb_skip; - y_row += cb_step; - cr_row += cb_step; + luminance += lumaSkip; + cb += chromaSkip; + cr += chromaSkip; } } } static void TMCJPEGDEC_converterYUV411toRGBA8edge(TMCCJPEGDecWork* work, s32 x, s32 y) { - TMCCJPEGDecState* st; - s32 bw; - u8* out; - s32 step, step_v; - s32 x_end, y_end; - u8* cb_row; - u8* y_row; - u8* cr_row; - s32 i; - - st = work->pState; - cb_row = work->convBuf + 4; - y_row = work->convBuf + 0x104; - cr_row = work->convBuf + 0x144; - bw = st->convWidth; - out = (u8*)st->pTexBuffer; - { - s32 ss = st->scaleFactor; - - if (st->dataSizeX == (u32)x) { - step = st->stepXExt; - } else { - step = 0x20 / ss; - } - - if (st->dataSizeY == (u32)y) { - step_v = st->stepYExt; - } else { - step_v = 0x08 / ss; - } + u8* luminance = work->convBuf + 4; + u8* cb = work->convBuf + 260; + u8* cr = work->convBuf + 324; + TMCCJPEGDecState* state = work->pState; + s32 tileWidth = (state->convWidth >> 2) << 1; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + if (state->dataSizeX == (u32)x) { + width = state->stepXExt; + } else { + width = 32 / state->scaleFactor; + } + if (state->dataSizeY == (u32)y) { + height = state->stepYExt; + } else { + height = 8 / state->scaleFactor; } - x_end = x + step; - y_end = y + step_v; { - s32 cb_step = (0x20 - step) >> 2; - s32 stride = (bw >> 1) & 0x7FFFFFFE; - - for (i = y; i < y_end; i++) { - u8* cb_ptr; - u8* y_ptr; - u8* cr_ptr; - s32 n; - s32 x_pos; - s32 row_base; - u8* ob; - s32 ra, ga, ba; - s32 y_d4 = i >> 2; - s32 y_ofs = (i & 3) << 3; - - row_base = y_d4 * stride; - ob = out + row_base + y_ofs; - cb_ptr = cb_row; - y_ptr = y_row; - cr_ptr = cr_row; - n = step; - x_pos = x; - - while (n > 0) { - s32 yv, crv, cbv; - s32 rr, gg, bb; - - if ((x_pos & 3) == 0) { - yv = (s8)(y_ptr[0]); - y_ptr++; - crv = (s8)(cr_ptr[0]); - cr_ptr++; - ga = -((yv * 0x58) + (crv * 0xB7)) >> 8; - ra = (crv * 0x167) >> 8; - ba = (yv * 0x1C6) >> 8; + s32 yEnd = y + height; + s32 xEnd = x + width; + s32 lumaSkip = 32 - width; + s32 chromaSkip = lumaSkip >> 2; + s32 redOffset = 0, greenOffset = 0, blueOffset = 0; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 1) { + if ((column & 3) == 0) { + s32 cbValue = (s8)*cb++; + s32 crValue = (s8)*cr++; + greenOffset = -(cbValue * 88 + crValue * 183) >> 8; + redOffset = (crValue * 359) >> 8; + blueOffset = (cbValue * 454) >> 8; } - - cbv = cb_ptr[0]; - cb_ptr++; - - gg = cbv + ga; - rr = cbv + ra; - bb = cbv + ba; - - if ((rr | gg | bb) >> 8) { - bb = clampU8(bb); - gg = clampU8(gg); - rr = clampU8(rr); - } - { - s32 xo = x_pos & 3; - s32 xg = (x_pos >> 2) << 1; - s32 off = (xg + row_base) << 4; - s32 ba0 = off + xo; - ((u16*)(ob + (ba0 << 1)))[0] = (u16)(0xFF00 | (rr & 0xFF)); - ((u16*)(ob + ((ba0 + 1) << 1)))[0] = (u16)((((gg & 0xFF) << 8) | (bb & 0xFF))); + s32 value = luminance[0]; + s32 green = value + greenOffset; + s32 red = value + redOffset; + s32 blue = value + blueOffset; + if ((blue | green | red) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column & 3) + (((((column) >> 2) << 1) + tileRow) << 4)] = + (u8)red + 0x10000 - 0x100; + output[(column & 3) + (((((column) >> 2) << 1) + tileRow + 1) << 4)] = + ((green & 255) << 8) + (blue & 255); } - x_pos++; - n--; + luminance += 1; } - - cb_row += (0x20 - step); - y_row += cb_step; - cr_row += cb_step; + luminance += lumaSkip; + cb += chromaSkip; + cr += chromaSkip; } } } static void TMCJPEGDEC_converterYUV422toRGBA8(TMCCJPEGDecWork* work, s32 x, s32 y) { - TMCCJPEGDecState* st; - s32 bw; - u8* out; - s32 ss; - s32 step, step_v; - s32 x_end, y_end; - u8* cb_row; - u8* y_row; - u8* cr_row; - - st = work->pState; - cb_row = work->convBuf + 4; - y_row = work->convBuf + 0x84; - cr_row = work->convBuf + 0xC4; - bw = st->convWidth; - out = (u8*)st->pTexBuffer; - ss = st->scaleFactor; - step = 0x10 / ss; - step_v = 0x08 / ss; - x_end = x + step; - y_end = y + step_v; - + u8* luminance = work->convBuf + 4; + u8* cb = work->convBuf + 132; + u8* cr = work->convBuf + 196; + TMCCJPEGDecState* state = work->pState; + s32 tileWidth = (state->convWidth >> 2) << 1; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + width = 16 / state->scaleFactor; + height = 8 / state->scaleFactor; { - s32 cb_step = (0x10 - step) >> 1; - s32 stride = (bw >> 1) & 0x7FFFFFFE; - s32 count = step >> 1; - s32 ra; - s32 ga; - s32 ba; - s32 rr; - s32 gg; - s32 bb; - s32 n; - s32 x_pos; - s32 row_base; - u8* ob; - s32 s; - s32 xo; - s32 xg; - s32 off; - s32 ba0; - - for (; y < y_end; y++) { - row_base = (y >> 2) * stride; - ob = out + ((y & 3) << 3); - - n = count; - x_pos = x; - - if (x < x_end) { - do { - s32 yv = *y_row; - s32 crv = *cr_row; - y_row = y_row + 1; - cr_row = cr_row + 1; - - ra = (crv * 0x167) >> 8; - s = (yv * 0x58) + (crv * 0xB7); - ga = -s >> 8; - ba = (yv * 0x1C6) >> 8; - - { - rr = cb_row[0] + ra; - gg = cb_row[0] + ga; - bb = cb_row[0] + ba; - if ((rr | gg | bb) >> 8) { - rr = clampU8(rr); - gg = clampU8(gg); - bb = clampU8(bb); - } - xo = x_pos & 3; - xg = (x_pos >> 2) << 1; - off = (xg + row_base) << 4; - ba0 = off + xo; - ((u16*)(ob + (ba0 << 1)))[0] = (u16)((u8)bb - 0x100); - ((u16*)(ob + ((ba0 + 1) << 1)))[0] = (u16)((gg & 0xFF) * 256 + (rr & 0xFF)); - x_pos++; + s32 yEnd = y + height; + s32 xEnd = x + width; + s32 lumaSkip = 16 - width; + s32 chromaSkip = lumaSkip >> 1; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 2) { + s32 redOffset, greenOffset, blueOffset; + { + s32 cbValue = (s8)*cb++; + s32 crValue = (s8)*cr++; + greenOffset = -(cbValue * 88 + crValue * 183) >> 8; + redOffset = (crValue * 359) >> 8; + blueOffset = (cbValue * 454) >> 8; + } + { + s32 value = luminance[0]; + s32 green = value + greenOffset; + s32 red = value + redOffset; + s32 blue = value + blueOffset; + if ((blue | green | red) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); } - - { - rr = cb_row[1] + ra; - gg = cb_row[1] + ga; - bb = cb_row[1] + ba; - if ((rr | gg | bb) >> 8) { - rr = clampU8(rr); - gg = clampU8(gg); - bb = clampU8(bb); - } - xo = x_pos & 3; - xg = (x_pos >> 2) << 1; - off = (xg + row_base) << 4; - ba0 = off + xo; - ((u16*)(ob + (ba0 << 1)))[0] = (u16)((u8)bb - 0x100); - ((u16*)(ob + ((ba0 + 1) << 1)))[0] = (u16)((gg & 0xFF) * 256 + (rr & 0xFF)); - x_pos++; + output[(column & 3) + (((((column) >> 2) << 1) + tileRow) << 4)] = + (u8)red + 0x10000 - 0x100; + output[(column & 3) + (((((column) >> 2) << 1) + tileRow + 1) << 4)] = + ((green & 255) << 8) + (blue & 255); + } + { + s32 value = luminance[1]; + s32 green = value + greenOffset; + s32 red = value + redOffset; + s32 blue = value + blueOffset; + if ((blue | green | red) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); } - - cb_row += 2; - n--; - } while (n); + output[(column + 1 & 3) + (((((column + 1) >> 2) << 1) + tileRow) << 4)] = + (u8)red + 0x10000 - 0x100; + output[(column + 1 & 3) + (((((column + 1) >> 2) << 1) + tileRow + 1) << 4)] = + ((green & 255) << 8) + (blue & 255); + } + luminance += 2; } - - cb_row += (0x10 - step); - y_row += cb_step; - cr_row += cb_step; + luminance += lumaSkip; + cb += chromaSkip; + cr += chromaSkip; } } } static void TMCJPEGDEC_converterYUV422toRGBA8edge(TMCCJPEGDecWork* work, s32 x, s32 y) { - TMCCJPEGDecState* st; - s32 bw; - u8* out; - s32 step, step_v; - s32 x_end, y_end; - u8* cb_row; - u8* y_row; - u8* cr_row; - s32 i; - - st = work->pState; - cb_row = work->convBuf + 4; - y_row = work->convBuf + 0x84; - cr_row = work->convBuf + 0xC4; - bw = st->convWidth; - out = (u8*)st->pTexBuffer; - { - s32 ss = st->scaleFactor; - - if (st->dataSizeX == (u32)x) { - step = st->stepXExt; - } else { - step = 0x10 / ss; - } - - if (st->dataSizeY == (u32)y) { - step_v = st->stepYExt; - } else { - step_v = 0x08 / ss; - } + u8* luminance = work->convBuf + 4; + u8* cb = work->convBuf + 132; + u8* cr = work->convBuf + 196; + TMCCJPEGDecState* state = work->pState; + s32 tileWidth = (state->convWidth >> 2) << 1; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + if (state->dataSizeX == (u32)x) { + width = state->stepXExt; + } else { + width = 16 / state->scaleFactor; + } + if (state->dataSizeY == (u32)y) { + height = state->stepYExt; + } else { + height = 8 / state->scaleFactor; } - x_end = x + step; - y_end = y + step_v; { - s32 cb_step = (0x10 - step) >> 1; - s32 stride = (bw >> 1) & 0x7FFFFFFE; - - for (i = y; i < y_end; i++) { - u8* cb_ptr; - u8* y_ptr; - u8* cr_ptr; - s32 n; - s32 x_pos; - s32 row_base; - u8* ob; - s32 ra, ga, ba; - s32 y_d4 = i >> 2; - s32 y_ofs = (i & 3) << 3; - - row_base = y_d4 * stride; - ob = out + y_ofs; - cb_ptr = cb_row; - y_ptr = y_row; - cr_ptr = cr_row; - n = step; - x_pos = x; - - while (n > 0) { - s32 yv, crv, cbv; - s32 rr, gg, bb; - - if ((x_pos & 1) == 0) { - yv = (s8)(y_ptr[0]); - y_ptr++; - crv = (s8)(cr_ptr[0]); - cr_ptr++; - ga = -((yv * 0x58) + (crv * 0xB7)) >> 8; - ra = (crv * 0x167) >> 8; - ba = (yv * 0x1C6) >> 8; + s32 yEnd = y + height; + s32 xEnd = x + width; + s32 lumaSkip = 16 - width; + s32 chromaSkip = lumaSkip >> 1; + s32 redOffset = 0, greenOffset = 0, blueOffset = 0; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 1) { + if ((column & 1) == 0) { + s32 cbValue = (s8)*cb++; + s32 crValue = (s8)*cr++; + greenOffset = -(cbValue * 88 + crValue * 183) >> 8; + redOffset = (crValue * 359) >> 8; + blueOffset = (cbValue * 454) >> 8; } - - cbv = cb_ptr[0]; - cb_ptr++; - - gg = cbv + ga; - rr = cbv + ra; - bb = cbv + ba; - - if ((rr | gg | bb) >> 8) { - bb = clampU8(bb); - gg = clampU8(gg); - rr = clampU8(rr); - } - { - s32 xo = x_pos & 3; - s32 xg = (x_pos >> 2) << 1; - s32 off = (xg + row_base) << 4; - s32 ba0 = off + xo; - ((u16*)(ob + (ba0 << 1)))[0] = (u16)(0xFF00 | (rr & 0xFF)); - ((u16*)(ob + ((ba0 + 1) << 1)))[0] = (u16)((((gg & 0xFF) << 8) | (bb & 0xFF))); + s32 value = luminance[0]; + s32 green = value + greenOffset; + s32 red = value + redOffset; + s32 blue = value + blueOffset; + if ((blue | green | red) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column & 3) + (((((column) >> 2) << 1) + tileRow) << 4)] = + (u8)red + 0x10000 - 0x100; + output[(column & 3) + (((((column) >> 2) << 1) + tileRow + 1) << 4)] = + ((green & 255) << 8) + (blue & 255); } - x_pos++; - n--; + luminance += 1; } - - cb_row += (0x10 - step); - y_row += cb_step; - cr_row += cb_step; + luminance += lumaSkip; + cb += chromaSkip; + cr += chromaSkip; } } } static void TMCJPEGDEC_converterYUV420toRGBA8(TMCCJPEGDecWork* work, s32 x, s32 y) { - TMCCJPEGDecState* st; - s32 bw; - u8* out; - s32 ss; - s32 step; - s32 x_end; - s32 y_end; - u8* cb_row; - u8* y_row; - u8* cr_row; - - st = work->pState; - cb_row = work->convBuf + 4; - y_row = work->convBuf + 0x104; - cr_row = work->convBuf + 0x144; - ss = st->scaleFactor; - bw = st->convWidth; - step = 0x10 / ss; - out = (u8*)st->pTexBuffer; - x_end = x + step; - y_end = y + step; - + u8* luminance = work->convBuf + 4; + u8* cb = work->convBuf + 260; + u8* cr = work->convBuf + 324; + TMCCJPEGDecState* state = work->pState; + s32 tileWidth = (state->convWidth >> 2) << 1; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + width = 16 / state->scaleFactor; + height = 16 / state->scaleFactor; { - s32 cb_step = (0x10 - step) >> 1; - s32 stride = (bw >> 1) & 0x7FFFFFFE; - s32 count = (x_end - x + 1) >> 1; - s32 tmp = (step + 1) >> 1; - s32 ra, ga, ba; - s32 rr, gg, bb; - s32 n; - s32 x_pos; - s32 row_base; - u8* ob; - s32 s; - s32 xo; - s32 xg; - s32 off; - for (; y < y_end; y++) { - row_base = (y >> 2) * stride; - ob = out + ((y & 3) << 3); - - n = count; - x_pos = x; - - if (x < x_end) { - do { - s32 yv = *y_row; - s32 crv = *cr_row; - y_row = y_row + 1; - cr_row = cr_row + 1; - - ra = (crv * 0x167) >> 8; - s = (yv * 0x58) + (crv * 0xB7); - ga = -s >> 8; - ba = (yv * 0x1C6) >> 8; - - { - rr = cb_row[0] + ra; - gg = cb_row[0] + ga; - bb = cb_row[0] + ba; - if ((bb | gg | rr) >> 8) { - bb = clampU8(bb); - gg = clampU8(gg); - rr = clampU8(rr); - } - xo = x_pos & 3; - xg = (x_pos >> 2) << 1; - off = (xg + row_base) << 4; - ((u16*)(ob + ((xo + off) << 1)))[0] = (u16)((u8)rr - 0x100); - ((u16*)(ob + ((xo + off + 16) << 1)))[0] = (u16)((gg & 0xFF) * 256 + (bb & 0xFF)); - x_pos++; + s32 yEnd = y + height; + s32 xEnd = x + width; + s32 lumaSkip = 16 - width; + s32 chromaSkip = lumaSkip >> 1; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 2) { + s32 redOffset, greenOffset, blueOffset; + { + s32 cbValue = (s8)*cb++; + s32 crValue = (s8)*cr++; + greenOffset = -(cbValue * 88 + crValue * 183) >> 8; + redOffset = (crValue * 359) >> 8; + blueOffset = (cbValue * 454) >> 8; + } + { + s32 value = luminance[0]; + s32 green = value + greenOffset; + s32 red = value + redOffset; + s32 blue = value + blueOffset; + if ((blue | green | red) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); } - - { - rr = cb_row[1] + ra; - gg = cb_row[1] + ga; - bb = cb_row[1] + ba; - if ((bb | gg | rr) >> 8) { - bb = clampU8(bb); - gg = clampU8(gg); - rr = clampU8(rr); - } - xo = (x_pos + 1) & 3; - xg = ((x_pos + 1) >> 2) << 1; - off = (xg + row_base) << 4; - ((u16*)(ob + ((xo + off) << 1)))[0] = (u16)((u8)rr - 0x100); - ((u16*)(ob + ((xo + off + 16) << 1)))[0] = (u16)((gg & 0xFF) * 256 + (bb & 0xFF)); - x_pos += 2; + output[(column & 3) + (((((column) >> 2) << 1) + tileRow) << 4)] = + (u8)red + 0x10000 - 0x100; + output[(column & 3) + (((((column) >> 2) << 1) + tileRow + 1) << 4)] = + ((green & 255) << 8) + (blue & 255); + } + { + s32 value = luminance[1]; + s32 green = value + greenOffset; + s32 red = value + redOffset; + s32 blue = value + blueOffset; + if ((blue | green | red) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); } - - cb_row += 2; - n--; - } while (n); + output[(column + 1 & 3) + (((((column + 1) >> 2) << 1) + tileRow) << 4)] = + (u8)red + 0x10000 - 0x100; + output[(column + 1 & 3) + (((((column + 1) >> 2) << 1) + tileRow + 1) << 4)] = + ((green & 255) << 8) + (blue & 255); + } + luminance += 2; } - - cb_row += (0x10 - step); + luminance += lumaSkip; if (y & 1) { - y_row += cb_step; - cr_row += cb_step; + cb += chromaSkip; + cr += chromaSkip; } else { - y_row -= tmp; - cr_row -= tmp; + cb -= (width + 1) >> 1; + cr -= (width + 1) >> 1; } } } } static void TMCJPEGDEC_converterYUV420toRGBA8edge(TMCCJPEGDecWork* work, s32 x, s32 y) { - TMCCJPEGDecState* st; - s32 bw; - u8* out; - s32 step, step_v; - s32 x_end, y_end; - u8* cb_row; - u8* y_row; - u8* cr_row; - s32 i; - - st = work->pState; - cb_row = work->convBuf + 4; - y_row = work->convBuf + 0x104; - cr_row = work->convBuf + 0x144; - bw = st->convWidth; - out = (u8*)st->pTexBuffer; - { - s32 ss = st->scaleFactor; - - if (st->dataSizeX == (u32)x) { - step = st->stepXExt; - } else { - step = 0x10 / ss; - } - - if (st->dataSizeY == (u32)y) { - step_v = st->stepYExt; - } else { - step_v = 0x10 / ss; - } + u8* luminance = work->convBuf + 4; + u8* cb = work->convBuf + 260; + u8* cr = work->convBuf + 324; + TMCCJPEGDecState* state = work->pState; + s32 tileWidth = (state->convWidth >> 2) << 1; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + if (state->dataSizeX == (u32)x) { + width = state->stepXExt; + } else { + width = 16 / state->scaleFactor; + } + if (state->dataSizeY == (u32)y) { + height = state->stepYExt; + } else { + height = 16 / state->scaleFactor; } - x_end = x + step; - y_end = y + step_v; { - s32 cb_step = (0x10 - step) >> 1; - s32 stride = (bw >> 1) & 0x7FFFFFFE; - - for (i = y; i < y_end; i++) { - u8* cb_ptr; - u8* y_ptr; - u8* cr_ptr; - s32 n; - s32 x_pos; - s32 row_base; - u8* ob; - s32 ra, ga, ba; - s32 y_d4 = i >> 2; - s32 y_ofs = (i & 3) << 3; - - row_base = y_d4 * stride; - ob = out + y_ofs; - cb_ptr = cb_row; - y_ptr = y_row; - cr_ptr = cr_row; - n = step; - x_pos = x; - - while (n > 0) { - s32 yv, crv, cbv; - s32 rr, gg, bb; - - if ((x_pos & 1) == 0) { - yv = (s8)(y_ptr[0]); - y_ptr++; - crv = (s8)(cr_ptr[0]); - cr_ptr++; - ga = -((yv * 0x58) + (crv * 0xB7)) >> 8; - ra = (crv * 0x167) >> 8; - ba = (yv * 0x1C6) >> 8; + s32 yEnd = y + height; + s32 xEnd = x + width; + s32 lumaSkip = 16 - width; + s32 chromaSkip = lumaSkip >> 1; + s32 redOffset = 0, greenOffset = 0, blueOffset = 0; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 1) { + if ((column & 1) == 0) { + s32 cbValue = (s8)*cb++; + s32 crValue = (s8)*cr++; + greenOffset = -(cbValue * 88 + crValue * 183) >> 8; + redOffset = (crValue * 359) >> 8; + blueOffset = (cbValue * 454) >> 8; } - - cbv = cb_ptr[0]; - cb_ptr++; - - gg = cbv + ga; - rr = cbv + ra; - bb = cbv + ba; - - if ((rr | gg | bb) >> 8) { - bb = clampU8(bb); - gg = clampU8(gg); - rr = clampU8(rr); - } - { - s32 xo = x_pos & 3; - s32 xg = (x_pos >> 2) << 1; - s32 off = (xg + row_base) << 4; - s32 ba0 = off + xo; - ((u16*)(ob + (ba0 << 1)))[0] = (u16)(0xFF00 | (rr & 0xFF)); - ((u16*)(ob + ((ba0 + 1) << 1)))[0] = (u16)((((gg & 0xFF) << 8) | (bb & 0xFF))); + s32 value = luminance[0]; + s32 green = value + greenOffset; + s32 red = value + redOffset; + s32 blue = value + blueOffset; + if ((blue | green | red) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column & 3) + (((((column) >> 2) << 1) + tileRow) << 4)] = + (u8)red + 0x10000 - 0x100; + output[(column & 3) + (((((column) >> 2) << 1) + tileRow + 1) << 4)] = + ((green & 255) << 8) + (blue & 255); } - x_pos++; - n--; + luminance += 1; } - - cb_row += (0x10 - step); - if (i & 1) { - y_row += cb_step; - cr_row += cb_step; + luminance += lumaSkip; + if (y & 1) { + cb += chromaSkip; + cr += chromaSkip; } else { - y_row -= ((step + 1) >> 1); - cr_row -= ((step + 1) >> 1); + cb -= (width + 1) >> 1; + cr -= (width + 1) >> 1; } } } } static void TMCJPEGDEC_converterYUV211toRGBA8(TMCCJPEGDecWork* work, s32 x, s32 y) { - TMCCJPEGDecState* st; - s32 bw; - u8* out; - s32 ss; - s32 step, step_v; - s32 x_end, y_end; - u8* cb_row; - u8* y_row; - u8* cr_row; - s32 i; - - st = work->pState; - cb_row = work->convBuf + 4; - y_row = work->convBuf + 0x84; - cr_row = work->convBuf + 0xC4; - bw = st->convWidth; - out = (u8*)st->pTexBuffer; - ss = st->scaleFactor; - step = 0x08 / ss; - step_v = 0x10 / ss; - x_end = x + step; - y_end = y + step_v; - + u8* luminance = work->convBuf + 4; + u8* cb = work->convBuf + 132; + u8* cr = work->convBuf + 196; + TMCCJPEGDecState* state = work->pState; + s32 tileWidth = (state->convWidth >> 2) << 1; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + width = 8 / state->scaleFactor; + height = 16 / state->scaleFactor; { - s32 stride = (bw >> 1) & 0x7FFFFFFE; - s32 count = step; - s32 step_half = step >> 1; - - for (i = y; i < y_end; i++) { - s32 x_pos; - s32 row_base; - u8* ob; - s32 y_d4 = i >> 2; - s32 y_ofs = (i & 3) << 3; - - row_base = y_d4 * stride; - ob = out + y_ofs; - - for (x_pos = x; x_pos < x_end; x_pos++) { - s32 yv, crv, cbv; - s32 ra, ga, ba; - s32 rr, gg, bb; - - yv = (s8)(y_row[0]); - y_row++; - crv = (s8)(cr_row[0]); - cr_row++; - cbv = cb_row[0]; - cb_row++; - - ga = -((yv * 0x58) + (crv * 0xB7)) >> 8; - gg = cbv + ga; - ra = (crv * 0x167) >> 8; - rr = cbv + ra; - ba = (yv * 0x1C6) >> 8; - bb = cbv + ba; - - if ((rr | gg | bb) >> 8) { - bb = clampU8(bb); - gg = clampU8(gg); - rr = clampU8(rr); - } - + s32 yEnd = y + height; + s32 xEnd = x + width; + s32 lumaSkip = 8 - width; + s32 chromaSkip = lumaSkip >> 0; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 1) { + s32 redOffset, greenOffset, blueOffset; { - s32 xo = x_pos & 3; - s32 xg = (x_pos >> 2) << 1; - s32 off = (xg + row_base) << 4; - s32 ba0 = off + xo; - ((u16*)(ob + (ba0 << 1)))[0] = (u16)(0xFF00 | (rr & 0xFF)); - ((u16*)(ob + ((ba0 + 1) << 1)))[0] = (u16)((((gg & 0xFF) << 8) | (bb & 0xFF))); + s32 cbValue = (s8)*cb++; + s32 crValue = (s8)*cr++; + greenOffset = -(cbValue * 88 + crValue * 183) >> 8; + redOffset = (crValue * 359) >> 8; + blueOffset = (cbValue * 454) >> 8; } + { + s32 value = luminance[0]; + s32 green = value + greenOffset; + s32 red = value + redOffset; + s32 blue = value + blueOffset; + if ((blue | green | red) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column & 3) + (((((column) >> 2) << 1) + tileRow) << 4)] = + (u8)red + 0x10000 - 0x100; + output[(column & 3) + (((((column) >> 2) << 1) + tileRow + 1) << 4)] = + ((green & 255) << 8) + (blue & 255); + } + luminance += 1; } - - cb_row += (0x08 - step); - if (i & 1) { - y_row += (0x08 - step); - cr_row += (0x08 - step); + luminance += lumaSkip; + if (y & 1) { + cb += chromaSkip; + cr += chromaSkip; } else { - y_row -= step; - cr_row -= step; + cb -= (width + 0) >> 0; + cr -= (width + 0) >> 0; } } } } static void TMCJPEGDEC_converterYUV211toRGBA8edge(TMCCJPEGDecWork* work, s32 x, s32 y) { - TMCCJPEGDecState* st; - s32 bw; - u8* out; - s32 step, step_v; - s32 x_end, y_end; - u8* cb_row; - u8* y_row; - u8* cr_row; - s32 i; - - st = work->pState; - cb_row = work->convBuf + 4; - y_row = work->convBuf + 0x84; - cr_row = work->convBuf + 0xC4; - bw = st->convWidth; - out = (u8*)st->pTexBuffer; - { - s32 ss = st->scaleFactor; - - if (st->dataSizeX == (u32)x) { - step = st->stepXExt; - } else { - step = 0x08 / ss; - } - - if (st->dataSizeY == (u32)y) { - step_v = st->stepYExt; - } else { - step_v = 0x10 / ss; - } + u8* luminance = work->convBuf + 4; + u8* cb = work->convBuf + 132; + u8* cr = work->convBuf + 196; + TMCCJPEGDecState* state = work->pState; + s32 tileWidth = (state->convWidth >> 2) << 1; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + if (state->dataSizeX == (u32)x) { + width = state->stepXExt; + } else { + width = 8 / state->scaleFactor; + } + if (state->dataSizeY == (u32)y) { + height = state->stepYExt; + } else { + height = 16 / state->scaleFactor; } - x_end = x + step; - y_end = y + step_v; - { - s32 stride = (bw >> 1) & 0x7FFFFFFE; - s32 count = step; - - for (i = y; i < y_end; i++) { - u8* cb_ptr; - u8* y_ptr; - u8* cr_ptr; - s32 n; - s32 x_pos; - s32 row_base; - u8* ob; - s32 y_d4 = i >> 2; - s32 y_ofs = (i & 3) << 3; - - row_base = y_d4 * stride; - ob = out + row_base + y_ofs; - cb_ptr = cb_row; - y_ptr = y_row; - cr_ptr = cr_row; - n = count; - x_pos = x; - - while (x_pos < x_end) { - s32 yv, crv, cbv; - s32 ra, ga, ba; - s32 rr, gg, bb; - - yv = (s8)(y_ptr[0]); - y_ptr++; - crv = (s8)(cr_ptr[0]); - cr_ptr++; - cbv = cb_ptr[0]; - - ga = -((yv * 0x58) + (crv * 0xB7)) >> 8; - gg = cbv + ga; - ra = (crv * 0x167) >> 8; - rr = cbv + ra; - ba = (yv * 0x1C6) >> 8; - bb = cbv + ba; - - if ((rr | gg | bb) >> 8) { - bb = clampU8(bb); - gg = clampU8(gg); - rr = clampU8(rr); - } - + s32 yEnd = y + height; + s32 xEnd = x + width; + s32 lumaSkip = 8 - width; + s32 chromaSkip = lumaSkip >> 0; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 1) { + s32 redOffset, greenOffset, blueOffset; { - s32 xo = x_pos & 3; - s32 xg = (x_pos >> 2) << 1; - s32 off = (xg + row_base) << 4; - s32 ba0 = off + xo; - ((u16*)(ob + (ba0 << 1)))[0] = (u16)(0xFF00 | (rr & 0xFF)); - ((u16*)(ob + ((ba0 + 1) << 1)))[0] = (u16)((((gg & 0xFF) << 8) | (bb & 0xFF))); + s32 cbValue = (s8)*cb++; + s32 crValue = (s8)*cr++; + greenOffset = -(cbValue * 88 + crValue * 183) >> 8; + redOffset = (crValue * 359) >> 8; + blueOffset = (cbValue * 454) >> 8; } - x_pos++; - n--; - - cb_ptr += 1; + { + s32 value = luminance[0]; + s32 green = value + greenOffset; + s32 red = value + redOffset; + s32 blue = value + blueOffset; + if ((blue | green | red) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column & 3) + (((((column) >> 2) << 1) + tileRow) << 4)] = + (u8)red + 0x10000 - 0x100; + output[(column & 3) + (((((column) >> 2) << 1) + tileRow + 1) << 4)] = + ((green & 255) << 8) + (blue & 255); + } + luminance += 1; } - - cb_row += step; - if (i & 1) { - y_row += step_v; - cr_row += step_v; + luminance += lumaSkip; + if (y & 1) { + cb += chromaSkip; + cr += chromaSkip; } else { - y_row -= step_v; - cr_row -= step_v; + cb -= (width + 0) >> 0; + cr -= (width + 0) >> 0; } } } } static void TMCJPEGDEC_converterYUV444toRGBA8(TMCCJPEGDecWork* work, s32 x, s32 y) { - TMCCJPEGDecState* st; - s32 bw; - u8* out; - s32 ss; - s32 step; - s32 x_end, y_end; - u8* cb_row; - u8* y_row; - u8* cr_row; - s32 i; - - st = work->pState; - cb_row = work->convBuf + 4; - y_row = work->convBuf + 0x44; - cr_row = work->convBuf + 0x84; - bw = st->convWidth; - out = (u8*)st->pTexBuffer; - ss = st->scaleFactor; - step = 0x08 / ss; - x_end = x + step; - y_end = y + step; - + u8* luminance = work->convBuf + 4; + u8* cb = work->convBuf + 68; + u8* cr = work->convBuf + 132; + TMCCJPEGDecState* state = work->pState; + s32 tileWidth = (state->convWidth >> 2) << 1; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + width = 8 / state->scaleFactor; + height = 8 / state->scaleFactor; { - s32 stride = (bw >> 1) & 0x7FFFFFFE; - s32 count = step; - - for (i = y; i < y_end; i++) { - u8* y_ptr; - u8* cr_ptr; - s32 n; - s32 x_pos; - s32 row_base; - u8* ob; - s32 y_d4 = i >> 2; - s32 y_ofs = (i & 3) << 3; - - row_base = y_d4 * stride; - ob = out + row_base + y_ofs; - y_ptr = y_row; - cr_ptr = cr_row; - n = count; - x_pos = x; - - while (x_pos < x_end) { - s32 yv, crv, cbv; - s32 ra, ga, ba; - s32 rr, gg, bb; - - yv = (s8)(y_ptr[0]); - y_ptr++; - crv = (s8)(cr_ptr[0]); - cr_ptr++; - cbv = cb_row[0]; - cb_row++; - - ga = -((yv * 0x58) + (crv * 0xB7)) >> 8; - gg = cbv + ga; - ra = (crv * 0x167) >> 8; - rr = cbv + ra; - ba = (yv * 0x1C6) >> 8; - bb = cbv + ba; - - if ((rr | gg | bb) >> 8) { - bb = clampU8(bb); - gg = clampU8(gg); - rr = clampU8(rr); - } - + s32 yEnd = y + height; + s32 xEnd = x + width; + s32 lumaSkip = 8 - width; + s32 chromaSkip = lumaSkip >> 0; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 1) { + s32 redOffset, greenOffset, blueOffset; { - s32 xo = x_pos & 3; - s32 xg = (x_pos >> 2) << 1; - s32 off = (xg + row_base) << 4; - s32 ba0 = off + xo; - ((u16*)(ob + (ba0 << 1)))[0] = (u16)(0xFF00 | (rr & 0xFF)); - ((u16*)(ob + ((ba0 + 1) << 1)))[0] = (u16)((((gg & 0xFF) << 8) | (bb & 0xFF))); + s32 cbValue = (s8)*cb++; + s32 crValue = (s8)*cr++; + greenOffset = -(cbValue * 88 + crValue * 183) >> 8; + redOffset = (crValue * 359) >> 8; + blueOffset = (cbValue * 454) >> 8; } - x_pos++; - n--; + { + s32 value = luminance[0]; + s32 green = value + greenOffset; + s32 red = value + redOffset; + s32 blue = value + blueOffset; + if ((blue | green | red) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column & 3) + (((((column) >> 2) << 1) + tileRow) << 4)] = + (u8)red + 0x10000 - 0x100; + output[(column & 3) + (((((column) >> 2) << 1) + tileRow + 1) << 4)] = + ((green & 255) << 8) + (blue & 255); + } + luminance += 1; } - - cb_row += step; - y_row += step; - cr_row += step; + luminance += lumaSkip; + cb += chromaSkip; + cr += chromaSkip; } } } static void TMCJPEGDEC_converterYUV444toRGBA8edge(TMCCJPEGDecWork* work, s32 x, s32 y) { - TMCCJPEGDecState* st; - s32 bw; - u8* out; - s32 step, step_v; - s32 x_end, y_end; - u8* cb_row; - u8* y_row; - u8* cr_row; - s32 i; - - st = work->pState; - cb_row = work->convBuf + 4; - y_row = work->convBuf + 0x44; - cr_row = work->convBuf + 0x84; - bw = st->convWidth; - out = (u8*)st->pTexBuffer; - { - s32 ss = st->scaleFactor; - - if (st->dataSizeX == (u32)x) { - step = st->stepXExt; - } else { - step = 0x08 / ss; - } - - if (st->dataSizeY == (u32)y) { - step_v = st->stepYExt; - } else { - step_v = 0x08 / ss; - } + u8* luminance = work->convBuf + 4; + u8* cb = work->convBuf + 68; + u8* cr = work->convBuf + 132; + TMCCJPEGDecState* state = work->pState; + s32 tileWidth = (state->convWidth >> 2) << 1; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + if (state->dataSizeX == (u32)x) { + width = state->stepXExt; + } else { + width = 8 / state->scaleFactor; + } + if (state->dataSizeY == (u32)y) { + height = state->stepYExt; + } else { + height = 8 / state->scaleFactor; } - x_end = x + step; - y_end = y + step_v; - { - s32 stride = (bw >> 1) & 0x7FFFFFFE; - s32 count = step; - - for (i = y; i < y_end; i++) { - u8* cb_ptr; - u8* y_ptr; - u8* cr_ptr; - s32 n; - s32 x_pos; - s32 row_base; - u8* ob; - s32 y_d4 = i >> 2; - s32 y_ofs = (i & 3) << 3; - - row_base = y_d4 * stride; - ob = out + row_base + y_ofs; - cb_ptr = cb_row; - y_ptr = y_row; - cr_ptr = cr_row; - n = count; - x_pos = x; - - while (x_pos < x_end) { - s32 yv, crv, cbv; - s32 ra, ga, ba; - s32 rr, gg, bb; - - yv = (s8)(y_ptr[0]); - y_ptr++; - crv = (s8)(cr_ptr[0]); - cr_ptr++; - cbv = cb_ptr[0]; - - ga = -((yv * 0x58) + (crv * 0xB7)) >> 8; - gg = cbv + ga; - ra = (crv * 0x167) >> 8; - rr = cbv + ra; - ba = (yv * 0x1C6) >> 8; - bb = cbv + ba; - - if ((rr | gg | bb) >> 8) { - bb = clampU8(bb); - gg = clampU8(gg); - rr = clampU8(rr); - } - + s32 yEnd = y + height; + s32 xEnd = x + width; + s32 lumaSkip = 8 - width; + s32 chromaSkip = lumaSkip >> 0; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 1) { + s32 redOffset, greenOffset, blueOffset; { - s32 xo = x_pos & 3; - s32 xg = (x_pos >> 2) << 1; - s32 off = (xg + row_base) << 4; - s32 ba0 = off + xo; - ((u16*)(ob + (ba0 << 1)))[0] = (u16)(0xFF00 | (rr & 0xFF)); - ((u16*)(ob + ((ba0 + 1) << 1)))[0] = (u16)((((gg & 0xFF) << 8) | (bb & 0xFF))); + s32 cbValue = (s8)*cb++; + s32 crValue = (s8)*cr++; + greenOffset = -(cbValue * 88 + crValue * 183) >> 8; + redOffset = (crValue * 359) >> 8; + blueOffset = (cbValue * 454) >> 8; } - x_pos++; - n--; - - cb_ptr += 1; + { + s32 value = luminance[0]; + s32 green = value + greenOffset; + s32 red = value + redOffset; + s32 blue = value + blueOffset; + if ((blue | green | red) >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); + } + output[(column & 3) + (((((column) >> 2) << 1) + tileRow) << 4)] = + (u8)red + 0x10000 - 0x100; + output[(column & 3) + (((((column) >> 2) << 1) + tileRow + 1) << 4)] = + ((green & 255) << 8) + (blue & 255); + } + luminance += 1; } - - cb_row += (0x08 - step); - y_row += (0x08 - step); - cr_row += (0x08 - step); + luminance += lumaSkip; + cb += chromaSkip; + cr += chromaSkip; } } } static void TMCJPEGDEC_converterYUV400toRGBA8(TMCCJPEGDecWork* work, s32 x, s32 y) { - TMCCJPEGDecState* st; - s32 bw; - u8* out; - s32 ss; - s32 step; - s32 x_end, y_end; - u8* cb_row; - s32 i; - - st = work->pState; - cb_row = work->convBuf + 4; - bw = st->convWidth; - out = (u8*)st->pTexBuffer; - ss = st->scaleFactor; - step = 0x08 / ss; - x_end = x + step; - y_end = y + step; - + u8* luminance = work->convBuf + 4; + TMCCJPEGDecState* state = work->pState; + s32 tileWidth = (state->convWidth >> 2) << 1; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + width = 8 / state->scaleFactor; + height = 8 / state->scaleFactor; { - s32 stride = (bw >> 1) & 0x7FFFFFFE; - s32 count = step; - - for (i = y; i < y_end; i++) { - u8* cb_ptr; - s32 n; - s32 x_pos; - s32 row_base; - u8* ob; - s32 y_d4 = i >> 2; - s32 y_ofs = (i & 3) << 3; - - row_base = y_d4 * stride; - ob = out + y_ofs; - n = count; - x_pos = x; - - while (x_pos < x_end) { - s32 val; - s32 rr; - s32 gg; - s32 bb; - - val = cb_row[0]; - cb_row++; - if (val >> 8) { - rr = clampU8(val); - gg = clampU8(val); - bb = clampU8(val); + s32 yEnd = y + height; + s32 xEnd = x + width; + s32 lumaSkip = 8 - width; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 1) { + s32 value = *luminance++; + s32 red = value, green = value, blue = value; + if (value >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); } else { - rr = val; - gg = val; - bb = val; + red = green = blue = value; } - - { - s32 off; - s32 ba0; - u32 bb_store; - - off = ((x_pos >> 2) << 1) + row_base; - ba0 = (off << 4) + (x_pos & 3); - x_pos++; - bb_store = (u32)(bb & 0xFF) + 0x10000; - bb_store -= 0x100; - ((u16*)(ob + (ba0 << 1)))[0] = (u16)bb_store; - ((u16*)(ob + ((ba0 + 1) << 1)))[0] = (u16)(((gg & 0xFF) << 8) + (rr & 0xFF)); - } - n--; + output[(column & 3) + (((((column) >> 2) << 1) + tileRow) << 4)] = + (u8)red + 0x10000 - 0x100; + output[(column & 3) + (((((column) >> 2) << 1) + tileRow + 1) << 4)] = + ((green & 255) << 8) + (blue & 255); } - - cb_row += (0x08 - step); + luminance += lumaSkip; } } } static void TMCJPEGDEC_converterYUV400toRGBA8edge(TMCCJPEGDecWork* work, s32 x, s32 y) { - TMCCJPEGDecState* st; - s32 bw; - u8* out; - s32 step, step_v; - s32 x_end, y_end; - u8* cb_row; - s32 i; - - st = work->pState; - cb_row = work->convBuf + 4; - bw = st->convWidth; - out = (u8*)st->pTexBuffer; - { - s32 ss = st->scaleFactor; - - if (st->dataSizeX == (u32)x) { - step = st->stepXExt; - } else { - step = 0x08 / ss; - } - - if (st->dataSizeY == (u32)y) { - step_v = st->stepYExt; - } else { - step_v = 0x08 / ss; - } + u8* luminance = work->convBuf + 4; + TMCCJPEGDecState* state = work->pState; + s32 tileWidth = (state->convWidth >> 2) << 1; + u8* texture = state->pTexBuffer; + s32 width; + s32 height; + if (state->dataSizeX == (u32)x) { + width = state->stepXExt; + } else { + width = 8 / state->scaleFactor; + } + if (state->dataSizeY == (u32)y) { + height = state->stepYExt; + } else { + height = 8 / state->scaleFactor; } - x_end = x + step; - y_end = y + step_v; - { - s32 stride = (bw >> 1) & 0x7FFFFFFE; - s32 count = step; - - for (i = y; i < y_end; i++) { - u8* cb_ptr; - s32 n; - s32 x_pos; - s32 row_base; - u8* ob; - s32 y_d4 = i >> 2; - s32 y_ofs = (i & 3) << 3; - - row_base = y_d4 * stride; - ob = out + y_ofs; - cb_ptr = cb_row; - n = count; - x_pos = x; - - while (x_pos < x_end) { - s32 val; - s32 rr; - s32 gg; - s32 bb; - - val = cb_ptr[0]; - cb_ptr += 1; - if (val >> 8) { - rr = clampU8(val); - gg = clampU8(val); - bb = clampU8(val); + s32 yEnd = y + height; + s32 xEnd = x + width; + s32 lumaSkip = 8 - width; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u16* output = (u16*)(texture + ((y & 3) << 3)); + s32 column; + for (column = x; column < xEnd; column += 1) { + s32 value = *luminance++; + s32 red = value, green = value, blue = value; + if (value >> 8) { + blue = (blue > 255) ? 255 : blue & ~(blue >> 31); + green = (green > 255) ? 255 : green & ~(green >> 31); + red = (red > 255) ? 255 : red & ~(red >> 31); } else { - rr = val; - gg = val; - bb = val; + red = green = blue = value; } - - { - s32 off; - s32 ba0; - u32 bb_store; - - off = ((x_pos >> 2) << 1) + row_base; - ba0 = (off << 4) + (x_pos & 3); - x_pos++; - bb_store = (u32)(bb & 0xFF) + 0x10000; - bb_store -= 0x100; - ((u16*)(ob + (ba0 << 1)))[0] = (u16)bb_store; - ((u16*)(ob + ((ba0 + 1) << 1)))[0] = (u16)(((gg & 0xFF) << 8) + (rr & 0xFF)); - } - n--; + output[(column & 3) + (((((column) >> 2) << 1) + tileRow) << 4)] = + (u8)red + 0x10000 - 0x100; + output[(column & 3) + (((((column) >> 2) << 1) + tileRow + 1) << 4)] = + ((green & 255) << 8) + (blue & 255); } - - cb_row += step; + luminance += lumaSkip; } } -} \ No newline at end of file +} diff --git a/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8.c b/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8.c index fe8df540..305331aa 100644 --- a/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8.c +++ b/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8.c @@ -1,5 +1,672 @@ +#define TMC_JPEG_PLANAR_OUTPUT #include +static void TMCJPEG_814EFEAC(TMCCJPEGDecWork*, s32, s32); +static void TMCJPEG_814F043C(TMCCJPEGDecWork*, s32, s32); +static void TMCJPEG_814F0A58(TMCCJPEGDecWork*, s32, s32); +static void TMCJPEG_814F11C4(TMCCJPEGDecWork*, s32, s32); +static void TMCJPEG_814F17E0(TMCCJPEGDecWork*, s32, s32); +static void TMCJPEG_814F1F48(TMCCJPEGDecWork*, s32, s32); +static void TMCJPEG_814F2570(TMCCJPEGDecWork*, s32, s32); +static void TMCJPEG_814F2B50(TMCCJPEGDecWork*, s32, s32); +static void TMCJPEG_814F3158(TMCCJPEGDecWork*, s32, s32); +static void TMCJPEG_814F32E4(TMCCJPEGDecWork*, s32, s32); +static void TMCJPEG_814F34A4(TMCCJPEGDecWork*, s32, s32); +static void TMCJPEG_814F372C(TMCCJPEGDecWork*, s32, s32); + s32 TMCJPEGDEC_set_converterY8U8V8(TMCCJPEGDecWork* work) { + u8* ob; + s32 cc; + TMCCJPEGDecState* st; + + ob = (u8*)&work->convBuf; + cc = work->componentCount; + st = work->pState; + + switch (cc) { + case 0: { + u8 mode = work->idctMode; + u8* ptr = ob + 4; + u8* p1 = ptr + mode; + u8* p2 = p1 + mode; + u8* p3 = p2 + mode; + + work->pConverterFunc = TMCJPEG_814EFEAC; + work->pConverterFuncEdge = TMCJPEG_814F043C; + work->pConvRowPtrs[0] = (void*)ptr; + work->pConvRowPtrs[1] = (void*)p1; + work->pConvRowPtrs[2] = (void*)p2; + work->pConvRowPtrs[3] = (void*)p3; + work->pConvRowPtrs[5] = (void*)(ob + 0x104); + work->pConvRowPtrs[6] = (void*)(ob + 0x144); + work->pitch = 0x20; + work->converterFlags = 0; + break; + } + case 1: { + u8 mode = work->idctMode; + u8* ptr = ob + 4; + work->pConverterFunc = TMCJPEG_814F0A58; + work->pConverterFuncEdge = TMCJPEG_814F11C4; + work->pConvRowPtrs[0] = (void*)ptr; + work->pConvRowPtrs[1] = (void*)(ptr + mode); + work->pConvRowPtrs[5] = (void*)(ob + 0x84); + work->pConvRowPtrs[6] = (void*)(ob + 0xC4); + work->pitch = 0x10; + work->converterFlags = 0; + break; + } + case 2: { + u8 mode = work->idctMode; + u8* ptr = ob + 4; + u8* p1 = ptr + mode; + u8* p2 = ptr + mode * 16; + u8* p3 = p2 + mode; + work->pConverterFunc = TMCJPEG_814F17E0; + work->pConverterFuncEdge = TMCJPEG_814F1F48; + work->pConvRowPtrs[0] = (void*)ptr; + work->pConvRowPtrs[1] = (void*)p1; + work->pConvRowPtrs[2] = (void*)p2; + work->pConvRowPtrs[3] = (void*)p3; + work->pConvRowPtrs[5] = (void*)(ob + 0x104); + work->pConvRowPtrs[6] = (void*)(ob + 0x144); + work->pitch = 0x10; + work->converterFlags = 0; + break; + } + case 3: { + u8 mode = work->idctMode; + u8* ptr = ob + 4; + work->pConverterFunc = TMCJPEG_814F2570; + work->pConverterFuncEdge = TMCJPEG_814F2B50; + work->pConvRowPtrs[0] = (void*)ptr; + work->pConvRowPtrs[1] = (void*)(ptr + mode * 8); + work->pConvRowPtrs[5] = (void*)(ob + 0x84); + work->pConvRowPtrs[6] = (void*)(ob + 0xC4); + work->pitch = 0x08; + work->converterFlags = 0; + break; + } + case 4: { + work->pConverterFunc = TMCJPEG_814F3158; + work->pConverterFuncEdge = TMCJPEG_814F32E4; + work->pConvRowPtrs[0] = (void*)(ob + 4); + work->pConvRowPtrs[5] = (void*)(ob + 0x44); + work->pConvRowPtrs[6] = (void*)(ob + 0x84); + work->pitch = 0x08; + work->converterFlags = 0; + break; + } + case 5: { + work->pConverterFunc = TMCJPEG_814F34A4; + work->pConverterFuncEdge = TMCJPEG_814F372C; + work->pConvRowPtrs[0] = (void*)(ob + 4); + work->pitch = 0x08; + work->converterFlags = 0; + break; + } + default: { + return TMCC_ERROR_FORMAT; + } + } + + { + s32 width = st->jpegWidth; + s32 height = st->jpegHeight; + st->convWidth = ((u32)width / 8 + (width % 8 != 0)) * 8; + st->convHeight = ((u32)height / 4 + (height % 4 != 0)) * 4; + width = st->outputWidth; + height = st->outputHeight; + st->chromaWidth = ((u32)width / 8 + (width % 8 != 0)) * 8; + st->chromaHeight = ((u32)height / 4 + (height % 4 != 0)) * 4; + } return 0; } + +static void TMCJPEG_814EFEAC(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + s8* cb = (s8*)&work->convBuf[260]; + s8* cr = (s8*)&work->convBuf[324]; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 3; + u8* lumaTexture = state->pLumaBuffer; + u8* cbTexture = state->pCbBuffer; + u8* crTexture = state->pCrBuffer; + s32 width, height; + width = 32 / state->scaleFactor; + height = 8 / state->scaleFactor; + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 row; + for (row = y; row < yEnd; row++) { + s32 tileRow = (row >> 2) * tileWidth; + u8* output = lumaTexture + ((row & 3) << 3); + s32 column; + for (column = x; column < xEnd; column += 4) { + output[((column) & 7) + ((((column) >> 3) + tileRow) << 5)] = luminance[0]; + output[((column + 1) & 7) + ((((column + 1) >> 3) + tileRow) << 5)] = luminance[1]; + output[((column + 2) & 7) + ((((column + 2) >> 3) + tileRow) << 5)] = luminance[2]; + output[((column + 3) & 7) + ((((column + 3) >> 3) + tileRow) << 5)] = luminance[3]; + luminance += 4; + } + luminance += 32 - width; + } + x = (u32)x >> 2; + width = 8 / state->scaleFactor; + height = 8 / state->scaleFactor; + xEnd = x + width; + yEnd = y + height; + tileWidth = state->chromaWidth >> 3; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u8* cbOutput = cbTexture + ((y & 3) << 3); + u8* crOutput = crTexture + ((y & 3) << 3); + s32 column; + for (column = x; column < xEnd; column++) { + cbOutput[(column & 7) + (((column >> 3) + tileRow) << 5)] = *cb++ + 128; + crOutput[(column & 7) + (((column >> 3) + tileRow) << 5)] = *cr++ + 128; + } + cb += 8 - width; + cr += 8 - width; + } + } +} + +static void TMCJPEG_814F043C(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + s8* cb = (s8*)&work->convBuf[260]; + s8* cr = (s8*)&work->convBuf[324]; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 3; + u8* lumaTexture = state->pLumaBuffer; + u8* cbTexture = state->pCbBuffer; + u8* crTexture = state->pCrBuffer; + s32 width, height; + if (state->dataSizeX == (u32)x) { + width = state->stepXExt; + } else { + width = 32 / state->scaleFactor; + } + if (state->dataSizeY == (u32)y) { + height = state->stepYExt; + } else { + height = 8 / state->scaleFactor; + } + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 row; + for (row = y; row < yEnd; row++) { + s32 tileRow = (row >> 2) * tileWidth; + u8* output = lumaTexture + ((row & 3) << 3); + s32 column; + for (column = x; column < xEnd; column += 1) { + output[((column) & 7) + ((((column) >> 3) + tileRow) << 5)] = luminance[0]; + luminance += 1; + } + luminance += 32 - width; + } + x = (u32)x >> 2; + width = (width + 3) >> 2; + xEnd = x + width; + yEnd = y + height; + tileWidth = state->chromaWidth >> 3; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u8* cbOutput = cbTexture + ((y & 3) << 3); + u8* crOutput = crTexture + ((y & 3) << 3); + s32 column; + for (column = x; column < xEnd; column++) { + cbOutput[(column & 7) + (((column >> 3) + tileRow) << 5)] = *cb++ + 128; + crOutput[(column & 7) + (((column >> 3) + tileRow) << 5)] = *cr++ + 128; + } + cb += 8 - width; + cr += 8 - width; + } + } +} + +static void TMCJPEG_814F0A58(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + s8* cb = (s8*)&work->convBuf[132]; + s8* cr = (s8*)&work->convBuf[196]; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 3; + u8* lumaTexture = state->pLumaBuffer; + u8* cbTexture = state->pCbBuffer; + u8* crTexture = state->pCrBuffer; + s32 width, height; + width = 16 / state->scaleFactor; + height = 8 / state->scaleFactor; + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 row; + for (row = y; row < yEnd; row++) { + s32 tileRow = (row >> 2) * tileWidth; + u8* output = lumaTexture + ((row & 3) << 3); + s32 column; + for (column = x; column < xEnd; column += 2) { + output[((column) & 7) + ((((column) >> 3) + tileRow) << 5)] = luminance[0]; + output[((column + 1) & 7) + ((((column + 1) >> 3) + tileRow) << 5)] = luminance[1]; + luminance += 2; + } + luminance += 16 - width; + } + x = (u32)x >> 1; + width = 8 / state->scaleFactor; + height = 8 / state->scaleFactor; + xEnd = x + width; + yEnd = y + height; + tileWidth = state->chromaWidth >> 3; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u8* cbOutput = cbTexture + ((y & 3) << 3); + u8* crOutput = crTexture + ((y & 3) << 3); + s32 column; + for (column = x; column < xEnd; column++) { + cbOutput[(column & 7) + (((column >> 3) + tileRow) << 5)] = *cb++ + 128; + crOutput[(column & 7) + (((column >> 3) + tileRow) << 5)] = *cr++ + 128; + } + cb += 8 - width; + cr += 8 - width; + } + } +} + +static void TMCJPEG_814F11C4(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + s8* cb = (s8*)&work->convBuf[132]; + s8* cr = (s8*)&work->convBuf[196]; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 3; + u8* lumaTexture = state->pLumaBuffer; + u8* cbTexture = state->pCbBuffer; + u8* crTexture = state->pCrBuffer; + s32 width, height; + if (state->dataSizeX == (u32)x) { + width = state->stepXExt; + } else { + width = 16 / state->scaleFactor; + } + if (state->dataSizeY == (u32)y) { + height = state->stepYExt; + } else { + height = 8 / state->scaleFactor; + } + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 row; + for (row = y; row < yEnd; row++) { + s32 tileRow = (row >> 2) * tileWidth; + u8* output = lumaTexture + ((row & 3) << 3); + s32 column; + for (column = x; column < xEnd; column += 1) { + output[((column) & 7) + ((((column) >> 3) + tileRow) << 5)] = luminance[0]; + luminance += 1; + } + luminance += 16 - width; + } + x = (u32)x >> 1; + width = (width + 1) >> 1; + xEnd = x + width; + yEnd = y + height; + tileWidth = state->chromaWidth >> 3; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u8* cbOutput = cbTexture + ((y & 3) << 3); + u8* crOutput = crTexture + ((y & 3) << 3); + s32 column; + for (column = x; column < xEnd; column++) { + cbOutput[(column & 7) + (((column >> 3) + tileRow) << 5)] = *cb++ + 128; + crOutput[(column & 7) + (((column >> 3) + tileRow) << 5)] = *cr++ + 128; + } + cb += 8 - width; + cr += 8 - width; + } + } +} + +static void TMCJPEG_814F17E0(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + s8* cb = (s8*)&work->convBuf[260]; + s8* cr = (s8*)&work->convBuf[324]; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 3; + u8* lumaTexture = state->pLumaBuffer; + u8* cbTexture = state->pCbBuffer; + u8* crTexture = state->pCrBuffer; + s32 width, height; + width = 16 / state->scaleFactor; + height = 16 / state->scaleFactor; + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 row; + for (row = y; row < yEnd; row++) { + s32 tileRow = (row >> 2) * tileWidth; + u8* output = lumaTexture + ((row & 3) << 3); + s32 column; + for (column = x; column < xEnd; column += 2) { + output[((column) & 7) + ((((column) >> 3) + tileRow) << 5)] = luminance[0]; + output[((column + 1) & 7) + ((((column + 1) >> 3) + tileRow) << 5)] = luminance[1]; + luminance += 2; + } + luminance += 16 - width; + } + x = (u32)x >> 1; + y = (u32)y >> 1; + width = 8 / state->scaleFactor; + height = 8 / state->scaleFactor; + xEnd = x + width; + yEnd = y + height; + tileWidth = state->chromaWidth >> 3; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u8* cbOutput = cbTexture + ((y & 3) << 3); + u8* crOutput = crTexture + ((y & 3) << 3); + s32 column; + for (column = x; column < xEnd; column++) { + cbOutput[(column & 7) + (((column >> 3) + tileRow) << 5)] = *cb++ + 128; + crOutput[(column & 7) + (((column >> 3) + tileRow) << 5)] = *cr++ + 128; + } + cb += 8 - width; + cr += 8 - width; + } + } +} + +static void TMCJPEG_814F1F48(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + s8* cb = (s8*)&work->convBuf[260]; + s8* cr = (s8*)&work->convBuf[324]; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 3; + u8* lumaTexture = state->pLumaBuffer; + u8* cbTexture = state->pCbBuffer; + u8* crTexture = state->pCrBuffer; + s32 width, height; + if (state->dataSizeX == (u32)x) { + width = state->stepXExt; + } else { + width = 16 / state->scaleFactor; + } + if (state->dataSizeY == (u32)y) { + height = state->stepYExt; + } else { + height = 16 / state->scaleFactor; + } + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 row; + for (row = y; row < yEnd; row++) { + s32 tileRow = (row >> 2) * tileWidth; + u8* output = lumaTexture + ((row & 3) << 3); + s32 column; + for (column = x; column < xEnd; column += 1) { + output[((column) & 7) + ((((column) >> 3) + tileRow) << 5)] = luminance[0]; + luminance += 1; + } + luminance += 16 - width; + } + x = (u32)x >> 1; + y = (u32)y >> 1; + width = (width + 1) >> 1; + height = (height + 1) >> 1; + xEnd = x + width; + yEnd = y + height; + tileWidth = state->chromaWidth >> 3; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u8* cbOutput = cbTexture + ((y & 3) << 3); + u8* crOutput = crTexture + ((y & 3) << 3); + s32 column; + for (column = x; column < xEnd; column++) { + cbOutput[(column & 7) + (((column >> 3) + tileRow) << 5)] = *cb++ + 128; + crOutput[(column & 7) + (((column >> 3) + tileRow) << 5)] = *cr++ + 128; + } + cb += 8 - width; + cr += 8 - width; + } + } +} + +static void TMCJPEG_814F2570(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + s8* cb = (s8*)&work->convBuf[132]; + s8* cr = (s8*)&work->convBuf[196]; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 3; + u8* lumaTexture = state->pLumaBuffer; + u8* cbTexture = state->pCbBuffer; + u8* crTexture = state->pCrBuffer; + s32 width, height; + width = 8 / state->scaleFactor; + height = 16 / state->scaleFactor; + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 row; + for (row = y; row < yEnd; row++) { + s32 tileRow = (row >> 2) * tileWidth; + u8* output = lumaTexture + ((row & 3) << 3); + s32 column; + for (column = x; column < xEnd; column += 1) { + output[((column) & 7) + ((((column) >> 3) + tileRow) << 5)] = luminance[0]; + luminance += 1; + } + luminance += 8 - width; + } + y = (u32)y >> 1; + width = 8 / state->scaleFactor; + height = 8 / state->scaleFactor; + xEnd = x + width; + yEnd = y + height; + tileWidth = state->chromaWidth >> 3; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u8* cbOutput = cbTexture + ((y & 3) << 3); + u8* crOutput = crTexture + ((y & 3) << 3); + s32 column; + for (column = x; column < xEnd; column++) { + cbOutput[(column & 7) + (((column >> 3) + tileRow) << 5)] = *cb++ + 128; + crOutput[(column & 7) + (((column >> 3) + tileRow) << 5)] = *cr++ + 128; + } + cb += 8 - width; + cr += 8 - width; + } + } +} + +static void TMCJPEG_814F2B50(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + s8* cb = (s8*)&work->convBuf[132]; + s8* cr = (s8*)&work->convBuf[196]; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 3; + u8* lumaTexture = state->pLumaBuffer; + u8* cbTexture = state->pCbBuffer; + u8* crTexture = state->pCrBuffer; + s32 width, height; + if (state->dataSizeX == (u32)x) { + width = state->stepXExt; + } else { + width = 8 / state->scaleFactor; + } + if (state->dataSizeY == (u32)y) { + height = state->stepYExt; + } else { + height = 16 / state->scaleFactor; + } + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 row; + for (row = y; row < yEnd; row++) { + s32 tileRow = (row >> 2) * tileWidth; + u8* output = lumaTexture + ((row & 3) << 3); + s32 column; + for (column = x; column < xEnd; column += 1) { + output[((column) & 7) + ((((column) >> 3) + tileRow) << 5)] = luminance[0]; + luminance += 1; + } + luminance += 8 - width; + } + y = (u32)y >> 1; + height = (height + 1) >> 1; + xEnd = x + width; + yEnd = y + height; + tileWidth = state->chromaWidth >> 3; + for (; y < yEnd; y++) { + s32 tileRow = (y >> 2) * tileWidth; + u8* cbOutput = cbTexture + ((y & 3) << 3); + u8* crOutput = crTexture + ((y & 3) << 3); + s32 column; + for (column = x; column < xEnd; column++) { + cbOutput[(column & 7) + (((column >> 3) + tileRow) << 5)] = *cb++ + 128; + crOutput[(column & 7) + (((column >> 3) + tileRow) << 5)] = *cr++ + 128; + } + cb += 8 - width; + cr += 8 - width; + } + } +} + +static void TMCJPEG_814F3158(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + s8* cb = (s8*)&work->convBuf[68]; + s8* cr = (s8*)&work->convBuf[132]; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 3; + u8* lumaTexture = state->pLumaBuffer; + u8* cbTexture = state->pCbBuffer; + u8* crTexture = state->pCrBuffer; + s32 width, height; + width = 8 / state->scaleFactor; + height = 8 / state->scaleFactor; + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 row; + for (row = y; row < yEnd; row++) { + s32 tileRow = (row >> 2) * tileWidth; + u8* output = lumaTexture + ((row & 3) << 3); + s32 column; + u8* cbOutput = cbTexture + ((row & 3) << 3); + u8* crOutput = crTexture + ((row & 3) << 3); + for (column = x; column < xEnd; column += 1) { + output[((column) & 7) + ((((column) >> 3) + tileRow) << 5)] = luminance[0]; + cbOutput[(column & 7) + (((column >> 3) + tileRow) << 5)] = *cb++ + 128; + crOutput[(column & 7) + (((column >> 3) + tileRow) << 5)] = *cr++ + 128; + luminance += 1; + } + luminance += 8 - width; + cb += 8 - width; + cr += 8 - width; + } + } +} + +static void TMCJPEG_814F32E4(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + s8* cb = (s8*)&work->convBuf[68]; + s8* cr = (s8*)&work->convBuf[132]; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 3; + u8* lumaTexture = state->pLumaBuffer; + u8* cbTexture = state->pCbBuffer; + u8* crTexture = state->pCrBuffer; + s32 width, height; + if (state->dataSizeX == (u32)x) { + width = state->stepXExt; + } else { + width = 8 / state->scaleFactor; + } + if (state->dataSizeY == (u32)y) { + height = state->stepYExt; + } else { + height = 8 / state->scaleFactor; + } + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 row; + for (row = y; row < yEnd; row++) { + s32 tileRow = (row >> 2) * tileWidth; + u8* output = lumaTexture + ((row & 3) << 3); + s32 column; + u8* cbOutput = cbTexture + ((row & 3) << 3); + u8* crOutput = crTexture + ((row & 3) << 3); + for (column = x; column < xEnd; column += 1) { + output[((column) & 7) + ((((column) >> 3) + tileRow) << 5)] = luminance[0]; + cbOutput[(column & 7) + (((column >> 3) + tileRow) << 5)] = *cb++ + 128; + crOutput[(column & 7) + (((column >> 3) + tileRow) << 5)] = *cr++ + 128; + luminance += 1; + } + luminance += 8 - width; + cb += 8 - width; + cr += 8 - width; + } + } +} + +static void TMCJPEG_814F34A4(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 3; + u8* lumaTexture = state->pLumaBuffer; + s32 width, height; + width = 8 / state->scaleFactor; + height = 8 / state->scaleFactor; + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 row; + for (row = y; row < yEnd; row++) { + s32 tileRow = (row >> 2) * tileWidth; + u8* output = lumaTexture + ((row & 3) << 3); + s32 column; + for (column = x; column < xEnd; column += 1) { + output[((column) & 7) + ((((column) >> 3) + tileRow) << 5)] = luminance[0]; + luminance += 1; + } + luminance += 8 - width; + } + } +} + +static void TMCJPEG_814F372C(TMCCJPEGDecWork* work, s32 x, s32 y) { + u8* luminance = work->convBuf + 4; + TMCCJPEGDecState* state = work->pState; + u32 tileWidth = state->convWidth >> 3; + u8* lumaTexture = state->pLumaBuffer; + s32 width, height; + if (state->dataSizeX == (u32)x) { + width = state->stepXExt; + } else { + width = 8 / state->scaleFactor; + } + if (state->dataSizeY == (u32)y) { + height = state->stepYExt; + } else { + height = 8 / state->scaleFactor; + } + { + s32 xEnd = x + width; + s32 yEnd = y + height; + s32 row; + for (row = y; row < yEnd; row++) { + s32 tileRow = (row >> 2) * tileWidth; + u8* output = lumaTexture + ((row & 3) << 3); + s32 column; + for (column = x; column < xEnd; column += 1) { + output[((column) & 7) + ((((column) >> 3) + tileRow) << 5)] = luminance[0]; + luminance += 1; + } + luminance += 8 - width; + } + } +} diff --git a/tools/decomp-assist/tmc-jpeg.attempts.md b/tools/decomp-assist/tmc-jpeg.attempts.md new file mode 100644 index 00000000..a01f7214 --- /dev/null +++ b/tools/decomp-assist/tmc-jpeg.attempts.md @@ -0,0 +1,510 @@ +# TMC JPEG matching attempts + +All work stayed in this worktree. No units were changed to Matching. Only the EXIF marker scan gained an exact function. The other five units are uncommitted partial implementations or cleanup experiments. + +The quick gate accepts non-regressing partial code. A GATE PASS alone does not establish a new exact function or a complete unit. + +All six units have no data bytes or string pools. pool_diff.py cannot read absent .data sections; the gate independently reported identical empty pools. + +## texturecvtr/Texture_MCUtoRGB565 + +- rgb-inline-store: Reordered 444/400 switch cases and named the four 420 row pointers before assigning them. +- rgb-explicit-pixels: Expanded the pixel-store helper into scoped RGB channel calculations at each pixel. +- rgb-byte-samples: Changed signed sample pointers to byte pointers with signed sample casts; expressed texture rows through byte pointers. +- rgb-final-byte-setup: Final setup uses byte offsets into the actual conversion buffer; no address-pinning symbols or objects. +- rgb-initial-layouts: Literal MCU loops, signed chroma pointers, inlined pixel-store helper; corrected buffer layout and rounded texture bounds. +- rgb-self-saturation: Used explicit channel saturation statements and copied grayscale channels before saturation. +- rgb-ternary-saturation: Expressed channel saturation with ternaries and kept grayscale copies in their branch. + +| Function | Attempt | Objdiff % | Instructions mine/target | Instruction differences | +| --- | --- | ---: | ---: | ---: | +| TMCJPEGDEC_set_converterRGB565 | rgb-inline-store | 93.635290 | 169/170 | different counts | +| TMCJPEGDEC_set_converterRGB565 | rgb-explicit-pixels | 93.635290 | 169/170 | different counts | +| TMCJPEGDEC_set_converterRGB565 | rgb-byte-samples | 93.635290 | 169/170 | different counts | +| TMCJPEGDEC_set_converterRGB565 | rgb-final-byte-setup | 93.635290 | 169/170 | different counts | +| TMCJPEGDEC_set_converterRGB565 | rgb-initial-layouts | 88.511765 | 169/170 | different counts | +| TMCJPEGDEC_set_converterRGB565 | rgb-self-saturation | 93.635290 | 169/170 | different counts | +| TMCJPEGDEC_set_converterRGB565 | rgb-ternary-saturation | 93.635290 | 169/170 | different counts | +| TMCJPEGDEC_converterYUV411toRGB565 | rgb-inline-store | 74.502304 | 217/217 | 199 | +| TMCJPEGDEC_converterYUV411toRGB565 | rgb-explicit-pixels | 72.820274 | 217/217 | 200 | +| TMCJPEGDEC_converterYUV411toRGB565 | rgb-byte-samples | 72.797230 | 217/217 | 201 | +| TMCJPEGDEC_converterYUV411toRGB565 | rgb-final-byte-setup | 72.797230 | 217/217 | 201 | +| TMCJPEGDEC_converterYUV411toRGB565 | rgb-initial-layouts | 74.502304 | 217/217 | 199 | +| TMCJPEGDEC_converterYUV411toRGB565 | rgb-self-saturation | 72.797230 | 217/217 | 201 | +| TMCJPEGDEC_converterYUV411toRGB565 | rgb-ternary-saturation | 72.797230 | 217/217 | 201 | +| TMCJPEGDEC_converterYUV411toRGB565edge | rgb-inline-store | 75.311320 | 109/106 | different counts | +| TMCJPEGDEC_converterYUV411toRGB565edge | rgb-explicit-pixels | 80.783020 | 109/106 | different counts | +| TMCJPEGDEC_converterYUV411toRGB565edge | rgb-byte-samples | 80.924530 | 109/106 | different counts | +| TMCJPEGDEC_converterYUV411toRGB565edge | rgb-final-byte-setup | 80.924530 | 109/106 | different counts | +| TMCJPEGDEC_converterYUV411toRGB565edge | rgb-initial-layouts | 75.311320 | 109/106 | different counts | +| TMCJPEGDEC_converterYUV411toRGB565edge | rgb-self-saturation | 80.924530 | 109/106 | different counts | +| TMCJPEGDEC_converterYUV411toRGB565edge | rgb-ternary-saturation | 80.924530 | 109/106 | different counts | +| TMCJPEGDEC_converterYUV422toRGB565 | rgb-inline-store | 76.058820 | 136/136 | 121 | +| TMCJPEGDEC_converterYUV422toRGB565 | rgb-explicit-pixels | 76.544120 | 136/136 | 122 | +| TMCJPEGDEC_converterYUV422toRGB565 | rgb-byte-samples | 76.580880 | 136/136 | 122 | +| TMCJPEGDEC_converterYUV422toRGB565 | rgb-final-byte-setup | 76.580880 | 136/136 | 122 | +| TMCJPEGDEC_converterYUV422toRGB565 | rgb-initial-layouts | 76.058820 | 136/136 | 121 | +| TMCJPEGDEC_converterYUV422toRGB565 | rgb-self-saturation | 76.580880 | 136/136 | 122 | +| TMCJPEGDEC_converterYUV422toRGB565 | rgb-ternary-saturation | 76.580880 | 136/136 | 122 | +| TMCJPEGDEC_converterYUV422toRGB565edge | rgb-inline-store | 83.037384 | 110/107 | different counts | +| TMCJPEGDEC_converterYUV422toRGB565edge | rgb-explicit-pixels | 80.934580 | 110/107 | different counts | +| TMCJPEGDEC_converterYUV422toRGB565edge | rgb-byte-samples | 80.794395 | 110/107 | different counts | +| TMCJPEGDEC_converterYUV422toRGB565edge | rgb-final-byte-setup | 80.794395 | 110/107 | different counts | +| TMCJPEGDEC_converterYUV422toRGB565edge | rgb-initial-layouts | 83.037384 | 110/107 | different counts | +| TMCJPEGDEC_converterYUV422toRGB565edge | rgb-self-saturation | 80.794395 | 110/107 | different counts | +| TMCJPEGDEC_converterYUV422toRGB565edge | rgb-ternary-saturation | 80.794395 | 110/107 | different counts | +| TMCJPEGDEC_converterYUV420toRGB565 | rgb-inline-store | 75.531910 | 141/141 | 127 | +| TMCJPEGDEC_converterYUV420toRGB565 | rgb-explicit-pixels | 77.340420 | 141/141 | 125 | +| TMCJPEGDEC_converterYUV420toRGB565 | rgb-byte-samples | 77.375885 | 141/141 | 125 | +| TMCJPEGDEC_converterYUV420toRGB565 | rgb-final-byte-setup | 77.375885 | 141/141 | 125 | +| TMCJPEGDEC_converterYUV420toRGB565 | rgb-initial-layouts | 75.531910 | 141/141 | 127 | +| TMCJPEGDEC_converterYUV420toRGB565 | rgb-self-saturation | 77.375885 | 141/141 | 125 | +| TMCJPEGDEC_converterYUV420toRGB565 | rgb-ternary-saturation | 77.375885 | 141/141 | 125 | +| TMCJPEGDEC_converterYUV420toRGB565edge | rgb-inline-store | 81.842100 | 117/114 | different counts | +| TMCJPEGDEC_converterYUV420toRGB565edge | rgb-explicit-pixels | 83.552635 | 117/114 | different counts | +| TMCJPEGDEC_converterYUV420toRGB565edge | rgb-byte-samples | 83.289474 | 117/114 | different counts | +| TMCJPEGDEC_converterYUV420toRGB565edge | rgb-final-byte-setup | 83.289474 | 117/114 | different counts | +| TMCJPEGDEC_converterYUV420toRGB565edge | rgb-initial-layouts | 81.842100 | 117/114 | different counts | +| TMCJPEGDEC_converterYUV420toRGB565edge | rgb-self-saturation | 83.289474 | 117/114 | different counts | +| TMCJPEGDEC_converterYUV420toRGB565edge | rgb-ternary-saturation | 83.289474 | 117/114 | different counts | +| TMCJPEGDEC_converterYUV211toRGB565 | rgb-inline-store | 76.816330 | 98/98 | 80 | +| TMCJPEGDEC_converterYUV211toRGB565 | rgb-explicit-pixels | 73.000000 | 98/98 | 85 | +| TMCJPEGDEC_converterYUV211toRGB565 | rgb-byte-samples | 73.051020 | 98/98 | 85 | +| TMCJPEGDEC_converterYUV211toRGB565 | rgb-final-byte-setup | 73.051020 | 98/98 | 85 | +| TMCJPEGDEC_converterYUV211toRGB565 | rgb-initial-layouts | 76.816330 | 98/98 | 80 | +| TMCJPEGDEC_converterYUV211toRGB565 | rgb-self-saturation | 73.051020 | 98/98 | 85 | +| TMCJPEGDEC_converterYUV211toRGB565 | rgb-ternary-saturation | 73.051020 | 98/98 | 85 | +| TMCJPEGDEC_converterYUV211toRGB565edge | rgb-inline-store | 80.862390 | 109/109 | 82 | +| TMCJPEGDEC_converterYUV211toRGB565edge | rgb-explicit-pixels | 77.192660 | 109/109 | 91 | +| TMCJPEGDEC_converterYUV211toRGB565edge | rgb-byte-samples | 77.238530 | 109/109 | 91 | +| TMCJPEGDEC_converterYUV211toRGB565edge | rgb-final-byte-setup | 77.238530 | 109/109 | 91 | +| TMCJPEGDEC_converterYUV211toRGB565edge | rgb-initial-layouts | 80.862390 | 109/109 | 82 | +| TMCJPEGDEC_converterYUV211toRGB565edge | rgb-self-saturation | 77.238530 | 109/109 | 91 | +| TMCJPEGDEC_converterYUV211toRGB565edge | rgb-ternary-saturation | 77.238530 | 109/109 | 91 | +| TMCJPEGDEC_converterYUV444toRGB565 | rgb-inline-store | 75.373630 | 91/91 | 75 | +| TMCJPEGDEC_converterYUV444toRGB565 | rgb-explicit-pixels | 73.450550 | 91/91 | 80 | +| TMCJPEGDEC_converterYUV444toRGB565 | rgb-byte-samples | 73.505490 | 91/91 | 80 | +| TMCJPEGDEC_converterYUV444toRGB565 | rgb-final-byte-setup | 73.505490 | 91/91 | 80 | +| TMCJPEGDEC_converterYUV444toRGB565 | rgb-initial-layouts | 75.373630 | 91/91 | 75 | +| TMCJPEGDEC_converterYUV444toRGB565 | rgb-self-saturation | 73.505490 | 91/91 | 80 | +| TMCJPEGDEC_converterYUV444toRGB565 | rgb-ternary-saturation | 73.505490 | 91/91 | 80 | +| TMCJPEGDEC_converterYUV444toRGB565edge | rgb-inline-store | 80.182690 | 104/104 | 79 | +| TMCJPEGDEC_converterYUV444toRGB565edge | rgb-explicit-pixels | 76.432690 | 104/104 | 88 | +| TMCJPEGDEC_converterYUV444toRGB565edge | rgb-byte-samples | 76.480770 | 104/104 | 88 | +| TMCJPEGDEC_converterYUV444toRGB565edge | rgb-final-byte-setup | 76.480770 | 104/104 | 88 | +| TMCJPEGDEC_converterYUV444toRGB565edge | rgb-initial-layouts | 80.182690 | 104/104 | 79 | +| TMCJPEGDEC_converterYUV444toRGB565edge | rgb-self-saturation | 76.480770 | 104/104 | 88 | +| TMCJPEGDEC_converterYUV444toRGB565edge | rgb-ternary-saturation | 76.480770 | 104/104 | 88 | +| TMCJPEGDEC_converterYUV400toRGB565 | rgb-inline-store | 82.571430 | 68/70 | different counts | +| TMCJPEGDEC_converterYUV400toRGB565 | rgb-explicit-pixels | 82.571430 | 68/70 | different counts | +| TMCJPEGDEC_converterYUV400toRGB565 | rgb-byte-samples | 82.571430 | 68/70 | different counts | +| TMCJPEGDEC_converterYUV400toRGB565 | rgb-final-byte-setup | 82.571430 | 68/70 | different counts | +| TMCJPEGDEC_converterYUV400toRGB565 | rgb-initial-layouts | 82.571430 | 68/70 | different counts | +| TMCJPEGDEC_converterYUV400toRGB565 | rgb-self-saturation | 79.571430 | 67/70 | different counts | +| TMCJPEGDEC_converterYUV400toRGB565 | rgb-ternary-saturation | 82.571430 | 68/70 | different counts | +| TMCJPEGDEC_converterYUV400toRGB565edge | rgb-inline-store | 84.216866 | 81/83 | different counts | +| TMCJPEGDEC_converterYUV400toRGB565edge | rgb-explicit-pixels | 84.216866 | 81/83 | different counts | +| TMCJPEGDEC_converterYUV400toRGB565edge | rgb-byte-samples | 84.216866 | 81/83 | different counts | +| TMCJPEGDEC_converterYUV400toRGB565edge | rgb-final-byte-setup | 84.216866 | 81/83 | different counts | +| TMCJPEGDEC_converterYUV400toRGB565edge | rgb-initial-layouts | 84.216866 | 81/83 | different counts | +| TMCJPEGDEC_converterYUV400toRGB565edge | rgb-self-saturation | 81.686745 | 80/83 | different counts | +| TMCJPEGDEC_converterYUV400toRGB565edge | rgb-ternary-saturation | 84.216866 | 81/83 | different counts | + +## texturecvtr/Texture_MCUtoRGBA8 + +- rgba-inline-pixels: Ported the RGB MCU loops to split AR/GB texture tiles; corrected chroma signs and tile offsets. +- rgba-green-first: Computed green before red and changed the order of the channel range expression. +- rgba-signed-stride-and-bounds: Used a signed tile stride, computed vertical bounds first, and made grayscale copies before saturation. +- rgba-final: Reviewed the final readable source and rebuilt it. + +| Function | Attempt | Objdiff % | Instructions mine/target | Instruction differences | +| --- | --- | ---: | ---: | ---: | +| TMCJPEGDEC_set_converterRGBA8 | rgba-inline-pixels | 93.635290 | 169/170 | different counts | +| TMCJPEGDEC_set_converterRGBA8 | rgba-green-first | 93.635290 | 169/170 | different counts | +| TMCJPEGDEC_set_converterRGBA8 | rgba-signed-stride-and-bounds | 93.635290 | 169/170 | different counts | +| TMCJPEGDEC_set_converterRGBA8 | rgba-final | 93.635290 | 169/170 | different counts | +| TMCJPEGDEC_converterYUV411toRGBA8 | rgba-inline-pixels | 63.995870 | 242/242 | 220 | +| TMCJPEGDEC_converterYUV411toRGBA8 | rgba-green-first | 65.190090 | 242/242 | 218 | +| TMCJPEGDEC_converterYUV411toRGBA8 | rgba-signed-stride-and-bounds | 65.871900 | 242/242 | 221 | +| TMCJPEGDEC_converterYUV411toRGBA8 | rgba-final | 65.871900 | 242/242 | 221 | +| TMCJPEGDEC_converterYUV411toRGBA8edge | rgba-inline-pixels | 75.294640 | 115/112 | different counts | +| TMCJPEGDEC_converterYUV411toRGBA8edge | rgba-green-first | 71.544640 | 115/112 | different counts | +| TMCJPEGDEC_converterYUV411toRGBA8edge | rgba-signed-stride-and-bounds | 71.544640 | 115/112 | different counts | +| TMCJPEGDEC_converterYUV411toRGBA8edge | rgba-final | 71.544640 | 115/112 | different counts | +| TMCJPEGDEC_converterYUV422toRGBA8 | rgba-inline-pixels | 68.743240 | 148/148 | 132 | +| TMCJPEGDEC_converterYUV422toRGBA8 | rgba-green-first | 67.770270 | 148/148 | 137 | +| TMCJPEGDEC_converterYUV422toRGBA8 | rgba-signed-stride-and-bounds | 66.486490 | 148/148 | 137 | +| TMCJPEGDEC_converterYUV422toRGBA8 | rgba-final | 66.486490 | 148/148 | 137 | +| TMCJPEGDEC_converterYUV422toRGBA8edge | rgba-inline-pixels | 71.725660 | 116/113 | different counts | +| TMCJPEGDEC_converterYUV422toRGBA8edge | rgba-green-first | 68.610620 | 116/113 | different counts | +| TMCJPEGDEC_converterYUV422toRGBA8edge | rgba-signed-stride-and-bounds | 68.610620 | 116/113 | different counts | +| TMCJPEGDEC_converterYUV422toRGBA8edge | rgba-final | 68.610620 | 116/113 | different counts | +| TMCJPEGDEC_converterYUV420toRGBA8 | rgba-inline-pixels | 68.424835 | 153/153 | 132 | +| TMCJPEGDEC_converterYUV420toRGBA8 | rgba-green-first | 69.810455 | 153/153 | 136 | +| TMCJPEGDEC_converterYUV420toRGBA8 | rgba-signed-stride-and-bounds | 69.745094 | 153/153 | 136 | +| TMCJPEGDEC_converterYUV420toRGBA8 | rgba-final | 69.745094 | 153/153 | 136 | +| TMCJPEGDEC_converterYUV420toRGBA8edge | rgba-inline-pixels | 74.166664 | 123/120 | different counts | +| TMCJPEGDEC_converterYUV420toRGBA8edge | rgba-green-first | 74.191666 | 123/120 | different counts | +| TMCJPEGDEC_converterYUV420toRGBA8edge | rgba-signed-stride-and-bounds | 74.191666 | 123/120 | different counts | +| TMCJPEGDEC_converterYUV420toRGBA8edge | rgba-final | 74.191666 | 123/120 | different counts | +| TMCJPEGDEC_converterYUV211toRGBA8 | rgba-inline-pixels | 69.846150 | 104/104 | 89 | +| TMCJPEGDEC_converterYUV211toRGBA8 | rgba-green-first | 69.480770 | 104/104 | 93 | +| TMCJPEGDEC_converterYUV211toRGBA8 | rgba-signed-stride-and-bounds | 69.480770 | 104/104 | 93 | +| TMCJPEGDEC_converterYUV211toRGBA8 | rgba-final | 69.480770 | 104/104 | 93 | +| TMCJPEGDEC_converterYUV211toRGBA8edge | rgba-inline-pixels | 74.295654 | 115/115 | 96 | +| TMCJPEGDEC_converterYUV211toRGBA8edge | rgba-green-first | 73.965220 | 115/115 | 99 | +| TMCJPEGDEC_converterYUV211toRGBA8edge | rgba-signed-stride-and-bounds | 73.965220 | 115/115 | 99 | +| TMCJPEGDEC_converterYUV211toRGBA8edge | rgba-final | 73.965220 | 115/115 | 99 | +| TMCJPEGDEC_converterYUV444toRGBA8 | rgba-inline-pixels | 70.453606 | 97/97 | 85 | +| TMCJPEGDEC_converterYUV444toRGBA8 | rgba-green-first | 70.082470 | 97/97 | 87 | +| TMCJPEGDEC_converterYUV444toRGBA8 | rgba-signed-stride-and-bounds | 70.082470 | 97/97 | 87 | +| TMCJPEGDEC_converterYUV444toRGBA8 | rgba-final | 70.082470 | 97/97 | 87 | +| TMCJPEGDEC_converterYUV444toRGBA8edge | rgba-inline-pixels | 73.445460 | 110/110 | 93 | +| TMCJPEGDEC_converterYUV444toRGBA8edge | rgba-green-first | 73.118180 | 110/110 | 94 | +| TMCJPEGDEC_converterYUV444toRGBA8edge | rgba-signed-stride-and-bounds | 73.118180 | 110/110 | 94 | +| TMCJPEGDEC_converterYUV444toRGBA8edge | rgba-final | 73.118180 | 110/110 | 94 | +| TMCJPEGDEC_converterYUV400toRGBA8 | rgba-inline-pixels | 84.276310 | 74/76 | different counts | +| TMCJPEGDEC_converterYUV400toRGBA8 | rgba-green-first | 84.276310 | 74/76 | different counts | +| TMCJPEGDEC_converterYUV400toRGBA8 | rgba-signed-stride-and-bounds | 84.276310 | 74/76 | different counts | +| TMCJPEGDEC_converterYUV400toRGBA8 | rgba-final | 84.276310 | 74/76 | different counts | +| TMCJPEGDEC_converterYUV400toRGBA8edge | rgba-inline-pixels | 85.561800 | 87/89 | different counts | +| TMCJPEGDEC_converterYUV400toRGBA8edge | rgba-green-first | 85.561800 | 87/89 | different counts | +| TMCJPEGDEC_converterYUV400toRGBA8edge | rgba-signed-stride-and-bounds | 85.561800 | 87/89 | different counts | +| TMCJPEGDEC_converterYUV400toRGBA8edge | rgba-final | 85.561800 | 87/89 | different counts | + +## texturecvtr/Texture_MCUtoY8U8V8 + +- planar-indexed-tiles: Implemented each original symbol using tiled luma and chroma output loops; width and height fields are guarded for this TU only. +- planar-tile-index-and-count: Expressed tile addresses with multiplication, tested a bounded decrementing 444 loop, and used border-selection ternaries. +- planar-shared-chroma-offset: Used signed tile strides, vertical bounds first, shared chroma offsets, and explicit sample temporaries. +- planar-final: Returned to direct indexed tile loops after the weaker shared-offset experiment. +- planar-guarded-counted-444: Tested a guarded do-loop for the combined 444 planes. It removed automatic unrolling but was still smaller than the target. +- planar-signed-chroma-pointers: Changed chroma pointers to signed bytes. The compiler eliminated sign extension before byte stores; measurements stayed unchanged. + +| Function | Attempt | Objdiff % | Instructions mine/target | Instruction differences | +| --- | --- | ---: | ---: | ---: | +| TMCJPEGDEC_set_converterY8U8V8 | planar-indexed-tiles | 92.540820 | 195/196 | different counts | +| TMCJPEGDEC_set_converterY8U8V8 | planar-tile-index-and-count | 89.760200 | 195/196 | different counts | +| TMCJPEGDEC_set_converterY8U8V8 | planar-shared-chroma-offset | 84.530610 | 193/196 | different counts | +| TMCJPEGDEC_set_converterY8U8V8 | planar-final | 92.540820 | 195/196 | different counts | +| TMCJPEGDEC_set_converterY8U8V8 | planar-guarded-counted-444 | 92.540820 | 195/196 | different counts | +| TMCJPEGDEC_set_converterY8U8V8 | planar-signed-chroma-pointers | 92.540820 | 195/196 | different counts | +| TMCJPEG_814EFEAC | planar-indexed-tiles | 52.233147 | 338/356 | different counts | +| TMCJPEG_814EFEAC | planar-tile-index-and-count | 52.233147 | 338/356 | different counts | +| TMCJPEG_814EFEAC | planar-shared-chroma-offset | 45.828650 | 317/356 | different counts | +| TMCJPEG_814EFEAC | planar-final | 52.233147 | 338/356 | different counts | +| TMCJPEG_814EFEAC | planar-guarded-counted-444 | 52.233147 | 338/356 | different counts | +| TMCJPEG_814EFEAC | planar-signed-chroma-pointers | 52.233147 | 338/356 | different counts | +| TMCJPEG_814F043C | planar-indexed-tiles | 51.355500 | 391/391 | 387 | +| TMCJPEG_814F043C | planar-tile-index-and-count | 51.355500 | 391/391 | 387 | +| TMCJPEG_814F043C | planar-shared-chroma-offset | 44.304348 | 371/391 | different counts | +| TMCJPEG_814F043C | planar-final | 51.355500 | 391/391 | 387 | +| TMCJPEG_814F043C | planar-guarded-counted-444 | 51.355500 | 391/391 | 387 | +| TMCJPEG_814F043C | planar-signed-chroma-pointers | 51.355500 | 391/391 | 387 | +| TMCJPEG_814F0A58 | planar-indexed-tiles | 43.534737 | 477/475 | different counts | +| TMCJPEG_814F0A58 | planar-tile-index-and-count | 43.534737 | 477/475 | different counts | +| TMCJPEG_814F0A58 | planar-shared-chroma-offset | 41.677895 | 456/475 | different counts | +| TMCJPEG_814F0A58 | planar-final | 43.534737 | 477/475 | different counts | +| TMCJPEG_814F0A58 | planar-guarded-counted-444 | 43.534737 | 477/475 | different counts | +| TMCJPEG_814F0A58 | planar-signed-chroma-pointers | 43.534737 | 477/475 | different counts | +| TMCJPEG_814F11C4 | planar-indexed-tiles | 51.355500 | 391/391 | 387 | +| TMCJPEG_814F11C4 | planar-tile-index-and-count | 51.355500 | 391/391 | 387 | +| TMCJPEG_814F11C4 | planar-shared-chroma-offset | 44.304348 | 371/391 | different counts | +| TMCJPEG_814F11C4 | planar-final | 51.355500 | 391/391 | 387 | +| TMCJPEG_814F11C4 | planar-guarded-counted-444 | 51.355500 | 391/391 | 387 | +| TMCJPEG_814F11C4 | planar-signed-chroma-pointers | 51.355500 | 391/391 | 387 | +| TMCJPEG_814F17E0 | planar-indexed-tiles | 41.890297 | 475/474 | different counts | +| TMCJPEG_814F17E0 | planar-tile-index-and-count | 41.890297 | 475/474 | different counts | +| TMCJPEG_814F17E0 | planar-shared-chroma-offset | 39.810127 | 454/474 | different counts | +| TMCJPEG_814F17E0 | planar-final | 41.890297 | 475/474 | different counts | +| TMCJPEG_814F17E0 | planar-guarded-counted-444 | 41.890297 | 475/474 | different counts | +| TMCJPEG_814F17E0 | planar-signed-chroma-pointers | 41.890297 | 475/474 | different counts | +| TMCJPEG_814F1F48 | planar-indexed-tiles | 46.809643 | 400/394 | different counts | +| TMCJPEG_814F1F48 | planar-tile-index-and-count | 46.809643 | 400/394 | different counts | +| TMCJPEG_814F1F48 | planar-shared-chroma-offset | 41.375633 | 379/394 | different counts | +| TMCJPEG_814F1F48 | planar-final | 46.809643 | 400/394 | different counts | +| TMCJPEG_814F1F48 | planar-guarded-counted-444 | 46.809643 | 400/394 | different counts | +| TMCJPEG_814F1F48 | planar-signed-chroma-pointers | 46.809643 | 400/394 | different counts | +| TMCJPEG_814F2570 | planar-indexed-tiles | 47.063830 | 376/376 | 370 | +| TMCJPEG_814F2570 | planar-tile-index-and-count | 47.063830 | 376/376 | 370 | +| TMCJPEG_814F2570 | planar-shared-chroma-offset | 42.981384 | 356/376 | different counts | +| TMCJPEG_814F2570 | planar-final | 47.063830 | 376/376 | 370 | +| TMCJPEG_814F2570 | planar-guarded-counted-444 | 47.063830 | 376/376 | 370 | +| TMCJPEG_814F2570 | planar-signed-chroma-pointers | 47.063830 | 376/376 | 370 | +| TMCJPEG_814F2B50 | planar-indexed-tiles | 52.950780 | 385/386 | different counts | +| TMCJPEG_814F2B50 | planar-tile-index-and-count | 52.950780 | 385/386 | different counts | +| TMCJPEG_814F2B50 | planar-shared-chroma-offset | 46.113990 | 365/386 | different counts | +| TMCJPEG_814F2B50 | planar-final | 52.950780 | 385/386 | different counts | +| TMCJPEG_814F2B50 | planar-guarded-counted-444 | 52.950780 | 385/386 | different counts | +| TMCJPEG_814F2B50 | planar-signed-chroma-pointers | 52.950780 | 385/386 | different counts | +| TMCJPEG_814F3158 | planar-indexed-tiles | unscored | 275/99 | different counts | +| TMCJPEG_814F3158 | planar-tile-index-and-count | unscored | 230/99 | different counts | +| TMCJPEG_814F3158 | planar-shared-chroma-offset | unscored | 215/99 | different counts | +| TMCJPEG_814F3158 | planar-final | unscored | 275/99 | different counts | +| TMCJPEG_814F3158 | planar-guarded-counted-444 | 37.404040 | 63/99 | different counts | +| TMCJPEG_814F3158 | planar-signed-chroma-pointers | unscored | 275/99 | different counts | +| TMCJPEG_814F32E4 | planar-indexed-tiles | unscored | 288/112 | different counts | +| TMCJPEG_814F32E4 | planar-tile-index-and-count | unscored | 243/112 | different counts | +| TMCJPEG_814F32E4 | planar-shared-chroma-offset | unscored | 228/112 | different counts | +| TMCJPEG_814F32E4 | planar-final | unscored | 288/112 | different counts | +| TMCJPEG_814F32E4 | planar-guarded-counted-444 | 45.651787 | 76/112 | different counts | +| TMCJPEG_814F32E4 | planar-signed-chroma-pointers | unscored | 288/112 | different counts | +| TMCJPEG_814F34A4 | planar-indexed-tiles | 60.037037 | 147/162 | different counts | +| TMCJPEG_814F34A4 | planar-tile-index-and-count | 60.037037 | 147/162 | different counts | +| TMCJPEG_814F34A4 | planar-shared-chroma-offset | 59.728394 | 147/162 | different counts | +| TMCJPEG_814F34A4 | planar-final | 60.037037 | 147/162 | different counts | +| TMCJPEG_814F34A4 | planar-guarded-counted-444 | 60.037037 | 147/162 | different counts | +| TMCJPEG_814F34A4 | planar-signed-chroma-pointers | 60.037037 | 147/162 | different counts | +| TMCJPEG_814F372C | planar-indexed-tiles | 62.891430 | 160/175 | different counts | +| TMCJPEG_814F372C | planar-tile-index-and-count | 62.891430 | 160/175 | different counts | +| TMCJPEG_814F372C | planar-shared-chroma-offset | 62.605713 | 160/175 | different counts | +| TMCJPEG_814F372C | planar-final | 62.891430 | 160/175 | different counts | +| TMCJPEG_814F372C | planar-guarded-counted-444 | 62.891430 | 160/175 | different counts | +| TMCJPEG_814F372C | planar-signed-chroma-pointers | 62.891430 | 160/175 | different counts | + +## buffer/idct_block_var + +- idct-output-and-saturation: Restored missing Lumi butterfly outputs, completed zero filling, fixed unsigned saturation, and restored the second-pass luma bias. +- idct-row-loop-and-butterfly-sums: Tested a row-count loop, sequential AC accumulation, and grouped butterfly sums in both functions. +- idct-butterfly-temporaries: Separated odd butterfly factors into temporaries and used a sign-mask clamp. +- idct-final-complete-butterfly-output: Also restored the three missing Col butterfly stores so no temporary output is left uninitialized. + +| Function | Attempt | Objdiff % | Instructions mine/target | Instruction differences | +| --- | --- | ---: | ---: | ---: | +| TMCJPEGDEC_IdctBlock_Lumi | idct-output-and-saturation | 64.821014 | 259/257 | different counts | +| TMCJPEGDEC_IdctBlock_Lumi | idct-row-loop-and-butterfly-sums | 64.712060 | 258/257 | different counts | +| TMCJPEGDEC_IdctBlock_Lumi | idct-butterfly-temporaries | 63.077820 | 257/257 | 217 | +| TMCJPEGDEC_IdctBlock_Lumi | idct-final-complete-butterfly-output | 63.077820 | 257/257 | 217 | +| TMCJPEGDEC_IdctBlock_Col | idct-output-and-saturation | 70.601320 | 471/454 | different counts | +| TMCJPEGDEC_IdctBlock_Col | idct-row-loop-and-butterfly-sums | 70.055070 | 471/454 | different counts | +| TMCJPEGDEC_IdctBlock_Col | idct-butterfly-temporaries | 70.055070 | 471/454 | different counts | +| TMCJPEGDEC_IdctBlock_Col | idct-final-complete-butterfly-output | 69.085900 | 480/454 | different counts | + +## b65/iqdec_b65_frv32 + +- iq-struct-return-helper: Removed all volatile coercions; represented fast Huffman entries with named fields and ordinary struct-value returns. +- iq-value-limit-helper: Used a local limit struct returned by value and reloaded the bit position after buffer loading. +- iq-shared-long-code-decoder: Factored long Huffman decoding into a shared C helper. The compiler did not inline it. +- iq-inline-long-code-decoder: Requested ordinary C inline expansion of the shared helper; branch layout and register allocation still differed. +- iq-final: Retained the value-copy experiment rather than the weaker shared-decoder experiment. +- iq-typed-limit-iteration: Removed redundant reads and byte-offset casts; iterated typed entries and reused the cached AC table. + +| Function | Attempt | Objdiff % | Instructions mine/target | Instruction differences | +| --- | --- | ---: | ---: | ---: | +| TMCJPEGDEC_decode_iquant | iq-struct-return-helper | 83.829710 | 271/276 | different counts | +| TMCJPEGDEC_decode_iquant | iq-value-limit-helper | 85.333336 | 281/276 | different counts | +| TMCJPEGDEC_decode_iquant | iq-shared-long-code-decoder | 61.442028 | 196/276 | different counts | +| TMCJPEGDEC_decode_iquant | iq-inline-long-code-decoder | 71.557970 | 280/276 | different counts | +| TMCJPEGDEC_decode_iquant | iq-final | 85.333336 | 281/276 | different counts | +| TMCJPEGDEC_decode_iquant | iq-typed-limit-iteration | 84.641304 | 280/276 | different counts | + +## exif/exif_parse + +- exif-bounds-widths-and-entry-order: Corrected directory offset checks and remaining-byte widths; changed byte assembly order and bounded pointers against end minus field size. +- exif-pointer-lifetimes-and-switch-tags: Computed entry pointers before remaining counts, advanced pointers before checking entry space, and tested ignored EXIF tag cases. +- exif-switch-breaks-and-declarations: Tested break-based switch bodies and separate declarations for tag offsets and pointers. +- exif-scoped-directory-entries: Gave each directory its own pointer, remaining count, entry count, and loop index. +- exif-marker-switch-and-byte-copy: Used a marker switch, copied the 20 date-time bytes individually, and recomputed transfer-function pointers from offsets. +- exif-marker-local-order: Ordered marker and segment locals to match the target stack slots and swapped the two terminal-marker case bodies. GetOffsetEXIF reached exact. +- exif-separate-ignored-tag-blocks: Tested separate ignored-tag bodies. The dispatch grew and did not improve matching; discarded. +- exif-final: Restored the independently gated, committed EXIF result. + +| Function | Attempt | Objdiff % | Instructions mine/target | Instruction differences | +| --- | --- | ---: | ---: | ---: | +| TMCCJPEGDecGetOffsetEXIF | exif-bounds-widths-and-entry-order | 77.129036 | 171/155 | different counts | +| TMCCJPEGDecGetOffsetEXIF | exif-pointer-lifetimes-and-switch-tags | 77.129036 | 171/155 | different counts | +| TMCCJPEGDecGetOffsetEXIF | exif-switch-breaks-and-declarations | 77.129036 | 171/155 | different counts | +| TMCCJPEGDecGetOffsetEXIF | exif-scoped-directory-entries | 77.129036 | 171/155 | different counts | +| TMCCJPEGDecGetOffsetEXIF | exif-marker-switch-and-byte-copy | 99.877420 | 155/155 | 11 | +| TMCCJPEGDecGetOffsetEXIF | exif-marker-local-order | 100.000000 | 155/155 | 0 | +| TMCCJPEGDecGetOffsetEXIF | exif-separate-ignored-tag-blocks | 100.000000 | 155/155 | 0 | +| TMCCJPEGDecGetOffsetEXIF | exif-final | 100.000000 | 155/155 | 0 | +| TMCCJPEGDecGetInfoEXIF | exif-bounds-widths-and-entry-order | 100.000000 | 132/132 | 0 | +| TMCCJPEGDecGetInfoEXIF | exif-pointer-lifetimes-and-switch-tags | 100.000000 | 132/132 | 0 | +| TMCCJPEGDecGetInfoEXIF | exif-switch-breaks-and-declarations | 100.000000 | 132/132 | 0 | +| TMCCJPEGDecGetInfoEXIF | exif-scoped-directory-entries | 100.000000 | 132/132 | 0 | +| TMCCJPEGDecGetInfoEXIF | exif-marker-switch-and-byte-copy | 100.000000 | 132/132 | 0 | +| TMCCJPEGDecGetInfoEXIF | exif-marker-local-order | 100.000000 | 132/132 | 0 | +| TMCCJPEGDecGetInfoEXIF | exif-separate-ignored-tag-blocks | 100.000000 | 132/132 | 0 | +| TMCCJPEGDecGetInfoEXIF | exif-final | 100.000000 | 132/132 | 0 | +| TMCJPEGDEC_exif_parse | exif-bounds-widths-and-entry-order | 85.528305 | 212/212 | 118 | +| TMCJPEGDEC_exif_parse | exif-pointer-lifetimes-and-switch-tags | 98.514150 | 212/212 | 52 | +| TMCJPEGDEC_exif_parse | exif-switch-breaks-and-declarations | 98.514150 | 212/212 | 52 | +| TMCJPEGDEC_exif_parse | exif-scoped-directory-entries | 98.113205 | 212/212 | 58 | +| TMCJPEGDEC_exif_parse | exif-marker-switch-and-byte-copy | 98.113205 | 212/212 | 58 | +| TMCJPEGDEC_exif_parse | exif-marker-local-order | 98.113205 | 212/212 | 58 | +| TMCJPEGDEC_exif_parse | exif-separate-ignored-tag-blocks | 98.113205 | 212/212 | 58 | +| TMCJPEGDEC_exif_parse | exif-final | 98.113205 | 212/212 | 58 | +| TMCJPEGDEC_IFD0_tag_parse | exif-bounds-widths-and-entry-order | 70.449066 | 446/481 | different counts | +| TMCJPEGDEC_IFD0_tag_parse | exif-pointer-lifetimes-and-switch-tags | 75.883575 | 446/481 | different counts | +| TMCJPEGDEC_IFD0_tag_parse | exif-switch-breaks-and-declarations | 75.883575 | 446/481 | different counts | +| TMCJPEGDEC_IFD0_tag_parse | exif-scoped-directory-entries | 75.883575 | 446/481 | different counts | +| TMCJPEGDEC_IFD0_tag_parse | exif-marker-switch-and-byte-copy | 85.507280 | 480/481 | different counts | +| TMCJPEGDEC_IFD0_tag_parse | exif-marker-local-order | 85.507280 | 480/481 | different counts | +| TMCJPEGDEC_IFD0_tag_parse | exif-separate-ignored-tag-blocks | 85.507280 | 480/481 | different counts | +| TMCJPEGDEC_IFD0_tag_parse | exif-final | 85.507280 | 480/481 | different counts | +| TMCJPEGDEC_IFD1_tag_parse | exif-bounds-widths-and-entry-order | 82.797520 | 243/242 | different counts | +| TMCJPEGDEC_IFD1_tag_parse | exif-pointer-lifetimes-and-switch-tags | 97.570250 | 244/242 | different counts | +| TMCJPEGDEC_IFD1_tag_parse | exif-switch-breaks-and-declarations | 91.566120 | 240/242 | different counts | +| TMCJPEGDEC_IFD1_tag_parse | exif-scoped-directory-entries | 91.566120 | 240/242 | different counts | +| TMCJPEGDEC_IFD1_tag_parse | exif-marker-switch-and-byte-copy | 92.107440 | 242/242 | 79 | +| TMCJPEGDEC_IFD1_tag_parse | exif-marker-local-order | 92.107440 | 242/242 | 79 | +| TMCJPEGDEC_IFD1_tag_parse | exif-separate-ignored-tag-blocks | 85.975204 | 260/242 | different counts | +| TMCJPEGDEC_IFD1_tag_parse | exif-final | 92.107440 | 242/242 | 79 | +| TMCJPEGDEC_ThumbnailCheck | exif-bounds-widths-and-entry-order | 100.000000 | 50/50 | 0 | +| TMCJPEGDEC_ThumbnailCheck | exif-pointer-lifetimes-and-switch-tags | 100.000000 | 50/50 | 0 | +| TMCJPEGDEC_ThumbnailCheck | exif-switch-breaks-and-declarations | 100.000000 | 50/50 | 0 | +| TMCJPEGDEC_ThumbnailCheck | exif-scoped-directory-entries | 100.000000 | 50/50 | 0 | +| TMCJPEGDEC_ThumbnailCheck | exif-marker-switch-and-byte-copy | 100.000000 | 50/50 | 0 | +| TMCJPEGDEC_ThumbnailCheck | exif-marker-local-order | 100.000000 | 50/50 | 0 | +| TMCJPEGDEC_ThumbnailCheck | exif-separate-ignored-tag-blocks | 100.000000 | 50/50 | 0 | +| TMCJPEGDEC_ThumbnailCheck | exif-final | 100.000000 | 50/50 | 0 | + +## Remaining differences + +The last full gate is the final authority. Each unmatched function is listed here with its final score and instruction evidence. Equal instruction counts do not establish a pure register tie-break; branch offsets and operand scheduling also remain. + +- TMCJPEGDEC_set_converterRGB565: 93.635290%, 169/170 instructions, conversion-buffer address folding and scheduling. +- TMCJPEGDEC_converterYUV411toRGB565: 72.797230%, 217/217 instructions, operand/register allocation and scheduling. +- TMCJPEGDEC_converterYUV411toRGB565edge: 80.924530%, 109/106 instructions, three initialized chroma offsets remain; no uninitialized-value shortcut used. +- TMCJPEGDEC_converterYUV422toRGB565: 76.580880%, 136/136 instructions, operand/register allocation and scheduling. +- TMCJPEGDEC_converterYUV422toRGB565edge: 80.794395%, 110/107 instructions, three initialized chroma offsets remain; no uninitialized-value shortcut used. +- TMCJPEGDEC_converterYUV420toRGB565: 77.375885%, 141/141 instructions, operand/register allocation and scheduling. +- TMCJPEGDEC_converterYUV420toRGB565edge: 83.289474%, 117/114 instructions, three initialized chroma offsets remain; no uninitialized-value shortcut used. +- TMCJPEGDEC_converterYUV211toRGB565: 73.051020%, 98/98 instructions, operand/register allocation and scheduling. +- TMCJPEGDEC_converterYUV211toRGB565edge: 77.238530%, 109/109 instructions, operand/register allocation and scheduling. +- TMCJPEGDEC_converterYUV444toRGB565: 73.505490%, 91/91 instructions, operand/register allocation and scheduling. +- TMCJPEGDEC_converterYUV444toRGB565edge: 76.480770%, 104/104 instructions, operand/register allocation and scheduling. +- TMCJPEGDEC_converterYUV400toRGB565: 82.571430%, 68/70 instructions, instruction count and control-flow/code-generation structure. +- TMCJPEGDEC_converterYUV400toRGB565edge: 84.216866%, 81/83 instructions, instruction count and control-flow/code-generation structure. +- TMCJPEGDEC_set_converterRGBA8: 93.635290%, 169/170 instructions, conversion-buffer address folding and scheduling. +- TMCJPEGDEC_converterYUV411toRGBA8: 65.871900%, 242/242 instructions, operand/register allocation and scheduling. +- TMCJPEGDEC_converterYUV411toRGBA8edge: 71.544640%, 115/112 instructions, three initialized chroma offsets remain; no uninitialized-value shortcut used. +- TMCJPEGDEC_converterYUV422toRGBA8: 66.486490%, 148/148 instructions, operand/register allocation and scheduling. +- TMCJPEGDEC_converterYUV422toRGBA8edge: 68.610620%, 116/113 instructions, three initialized chroma offsets remain; no uninitialized-value shortcut used. +- TMCJPEGDEC_converterYUV420toRGBA8: 69.745094%, 153/153 instructions, operand/register allocation and scheduling. +- TMCJPEGDEC_converterYUV420toRGBA8edge: 74.191666%, 123/120 instructions, three initialized chroma offsets remain; no uninitialized-value shortcut used. +- TMCJPEGDEC_converterYUV211toRGBA8: 69.480770%, 104/104 instructions, operand/register allocation and scheduling. +- TMCJPEGDEC_converterYUV211toRGBA8edge: 73.965220%, 115/115 instructions, operand/register allocation and scheduling. +- TMCJPEGDEC_converterYUV444toRGBA8: 70.082470%, 97/97 instructions, operand/register allocation and scheduling. +- TMCJPEGDEC_converterYUV444toRGBA8edge: 73.118180%, 110/110 instructions, operand/register allocation and scheduling. +- TMCJPEGDEC_converterYUV400toRGBA8: 84.276310%, 74/76 instructions, instruction count and control-flow/code-generation structure. +- TMCJPEGDEC_converterYUV400toRGBA8edge: 85.561800%, 87/89 instructions, instruction count and control-flow/code-generation structure. +- TMCJPEGDEC_set_converterY8U8V8: 92.540820%, 195/196 instructions, conversion-buffer address folding and scheduling. +- TMCJPEG_814EFEAC: 52.233147%, 338/356 instructions, instruction count and control-flow/code-generation structure. +- TMCJPEG_814F043C: 51.355500%, 391/391 instructions, operand/register allocation and scheduling. +- TMCJPEG_814F0A58: 43.534737%, 477/475 instructions, instruction count and control-flow/code-generation structure. +- TMCJPEG_814F11C4: 51.355500%, 391/391 instructions, operand/register allocation and scheduling. +- TMCJPEG_814F17E0: 41.890297%, 475/474 instructions, instruction count and control-flow/code-generation structure. +- TMCJPEG_814F1F48: 46.809643%, 400/394 instructions, instruction count and control-flow/code-generation structure. +- TMCJPEG_814F2570: 47.063830%, 376/376 instructions, operand/register allocation and scheduling. +- TMCJPEG_814F2B50: 52.950780%, 385/386 instructions, instruction count and control-flow/code-generation structure. +- TMCJPEG_814F3158: unscored, 275/99 instructions, instruction count and control-flow/code-generation structure. +- TMCJPEG_814F32E4: unscored, 288/112 instructions, instruction count and control-flow/code-generation structure. +- TMCJPEG_814F34A4: 60.037037%, 147/162 instructions, instruction count and control-flow/code-generation structure. +- TMCJPEG_814F372C: 62.891430%, 160/175 instructions, instruction count and control-flow/code-generation structure. +- TMCJPEGDEC_IdctBlock_Lumi: 63.077820%, 257/257 instructions, operand/register allocation and scheduling. +- TMCJPEGDEC_IdctBlock_Col: 69.085900%, 480/454 instructions, instruction count and control-flow/code-generation structure. +- TMCJPEGDEC_decode_iquant: 84.641304%, 280/276 instructions, instruction count and control-flow/code-generation structure. +- TMCJPEGDEC_exif_parse: 98.113205%, 212/212 instructions, operand/register allocation and scheduling. +- TMCJPEGDEC_IFD0_tag_parse: 85.507280%, 480/481 instructions, instruction count and control-flow/code-generation structure. +- TMCJPEGDEC_IFD1_tag_parse: 92.107440%, 242/242 instructions, switch dispatch tree and operand/register allocation. + +## Review limits + +The planar 444 loops remain much larger than the targets and are unscored by objdiff. No converter unit reached exact. MCU converter behavior was reconstructed from the target assembly but has not been tested on decoded images. The instruction-level differences remain open. + +Changed sources: the three texture converters, buffer/idct_block_var.c, b65/iqdec_b65_frv32.c, exif/exif_parse.c. The planar output fields in include/tmc_jpeg.h are guarded by TMC_JPEG_PLANAR_OUTPUT and enabled only by Texture_MCUtoY8U8V8.c. + +## Final full gate + +```text +full build: ok +main.dol sha1: 26116613f624061ba99c8d1a299aaa6efa85670d +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565] pool: IDENTICAL +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565] objdiff: code None/6184 data None/None functions 0/13 fuzzy 79.3978 linked code 0 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565] instruction-exact functions: 0/13 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565] section .text size 6184 match 79.397804 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565] below 100: TMCJPEGDEC_set_converterRGB565 93.63529 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565] below 100: TMCJPEGDEC_converterYUV411toRGB565 72.79723 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565] below 100: TMCJPEGDEC_converterYUV411toRGB565edge 80.92453 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565] below 100: TMCJPEGDEC_converterYUV422toRGB565 76.58088 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565] below 100: TMCJPEGDEC_converterYUV422toRGB565edge 80.794395 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565] below 100: TMCJPEGDEC_converterYUV420toRGB565 77.375885 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565] below 100: TMCJPEGDEC_converterYUV420toRGB565edge 83.289474 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565] below 100: TMCJPEGDEC_converterYUV211toRGB565 73.05102 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565] below 100: TMCJPEGDEC_converterYUV211toRGB565edge 77.23853 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565] below 100: TMCJPEGDEC_converterYUV444toRGB565 73.50549 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565] below 100: TMCJPEGDEC_converterYUV444toRGB565edge 76.48077 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565] below 100: TMCJPEGDEC_converterYUV400toRGB565 82.57143 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565] below 100: TMCJPEGDEC_converterYUV400toRGB565edge 84.216866 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565] baseline: code None/6184 data None functions 0 fuzzy 9.2756 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8] pool: IDENTICAL +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8] objdiff: code None/6596 data None/None functions 0/13 fuzzy 73.7611 linked code 0 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8] instruction-exact functions: 0/13 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8] section .text size 6596 match 73.76107 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8] below 100: TMCJPEGDEC_set_converterRGBA8 93.63529 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8] below 100: TMCJPEGDEC_converterYUV411toRGBA8 65.8719 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8] below 100: TMCJPEGDEC_converterYUV411toRGBA8edge 71.54464 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8] below 100: TMCJPEGDEC_converterYUV422toRGBA8 66.48649 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8] below 100: TMCJPEGDEC_converterYUV422toRGBA8edge 68.61062 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8] below 100: TMCJPEGDEC_converterYUV420toRGBA8 69.745094 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8] below 100: TMCJPEGDEC_converterYUV420toRGBA8edge 74.191666 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8] below 100: TMCJPEGDEC_converterYUV211toRGBA8 69.48077 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8] below 100: TMCJPEGDEC_converterYUV211toRGBA8edge 73.96522 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8] below 100: TMCJPEGDEC_converterYUV444toRGBA8 70.08247 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8] below 100: TMCJPEGDEC_converterYUV444toRGBA8edge 73.11818 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8] below 100: TMCJPEGDEC_converterYUV400toRGBA8 84.27631 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8] below 100: TMCJPEGDEC_converterYUV400toRGBA8edge 85.5618 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8] baseline: code None/6596 data None functions 0 fuzzy 76.5585 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8] pool: IDENTICAL +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8] objdiff: code None/15948 data None/None functions 0/13 fuzzy 48.8432 linked code 0 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8] instruction-exact functions: 0/13 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8] section .text size 15948 match 48.84324 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8] below 100: TMCJPEGDEC_set_converterY8U8V8 92.54082 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8] below 100: TMCJPEG_814EFEAC 52.233147 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8] below 100: TMCJPEG_814F043C 51.3555 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8] below 100: TMCJPEG_814F0A58 43.534737 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8] below 100: TMCJPEG_814F11C4 51.3555 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8] below 100: TMCJPEG_814F17E0 41.890297 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8] below 100: TMCJPEG_814F1F48 46.809643 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8] below 100: TMCJPEG_814F2570 47.06383 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8] below 100: TMCJPEG_814F2B50 52.95078 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8] below 100: TMCJPEG_814F3158 None +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8] below 100: TMCJPEG_814F32E4 None +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8] below 100: TMCJPEG_814F34A4 60.037037 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8] below 100: TMCJPEG_814F372C 62.89143 +[libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8] baseline: code None/15948 data None functions 0 fuzzy 0.0351 +[libs/RVLMiddleware/TMC_JPEG/src/buffer/idct_block_var] pool: IDENTICAL +[libs/RVLMiddleware/TMC_JPEG/src/buffer/idct_block_var] objdiff: code None/2844 data None/None functions 0/2 fuzzy 66.9142 linked code 0 +[libs/RVLMiddleware/TMC_JPEG/src/buffer/idct_block_var] instruction-exact functions: 0/2 +[libs/RVLMiddleware/TMC_JPEG/src/buffer/idct_block_var] section .text size 2844 match 66.91421 +[libs/RVLMiddleware/TMC_JPEG/src/buffer/idct_block_var] below 100: TMCJPEGDEC_IdctBlock_Lumi 63.07782 +[libs/RVLMiddleware/TMC_JPEG/src/buffer/idct_block_var] below 100: TMCJPEGDEC_IdctBlock_Col 69.0859 +[libs/RVLMiddleware/TMC_JPEG/src/buffer/idct_block_var] baseline: code None/2844 data None functions 0 fuzzy 69.6357 +[libs/RVLMiddleware/TMC_JPEG/src/b65/iqdec_b65_frv32] pool: IDENTICAL +[libs/RVLMiddleware/TMC_JPEG/src/b65/iqdec_b65_frv32] objdiff: code None/1104 data None/None functions 0/1 fuzzy 84.6413 linked code 0 +[libs/RVLMiddleware/TMC_JPEG/src/b65/iqdec_b65_frv32] instruction-exact functions: 0/1 +[libs/RVLMiddleware/TMC_JPEG/src/b65/iqdec_b65_frv32] section .text size 1104 match 84.641304 +[libs/RVLMiddleware/TMC_JPEG/src/b65/iqdec_b65_frv32] below 100: TMCJPEGDEC_decode_iquant 84.641304 +[libs/RVLMiddleware/TMC_JPEG/src/b65/iqdec_b65_frv32] baseline: code None/1104 data None functions 0 fuzzy 85.7101 +[libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse] pool: IDENTICAL +[libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse] objdiff: code 1348/5088 data None/None functions 3/6 fuzzy 92.7036 linked code 0 +[libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse] instruction-exact functions: 3/6 +[libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse] section .text size 5088 match 92.70361 +[libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse] below 100: TMCJPEGDEC_exif_parse 98.113205 +[libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse] below 100: TMCJPEGDEC_IFD0_tag_parse 85.50728 +[libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse] below 100: TMCJPEGDEC_IFD1_tag_parse 92.10744 +[libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse] baseline: code 728/5088 data None functions 2 fuzzy 77.1800 +regressions vs baseline: 0 +global matched_code_percent: 82.03095 -> 82.05164 +global fuzzy_match_percent: 93.26352 -> 93.68542 +global complete_code_percent: 57.20994 -> 57.20994 +global matched_data_percent: 89.09599 -> 89.09599 +forbidden patterns added (net, per file): 0 +readability warnings (net, per file; must be 0 in the final result): 0 +review note: libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565.c: possible pointer+offset into a blob (orchestrator reviews) (+2 net), e.g. work->pConvRowPtrs[6] = (void*)(ob + 0xc4); +review note: libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8.c: possible pointer+offset into a blob (orchestrator reviews) (+10 net), e.g. work->pConvRowPtrs[5] = (void*)(ob + 0x104); +review note: libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8.c: possible pointer+offset into a blob (orchestrator reviews) (+10 net), e.g. work->pConvRowPtrs[5] = (void*)(ob + 0x104); +GATE PASS +``` -- 2.49.1 From bca717c26b61cc6cfe6c54b9675de64474948d82 Mon Sep 17 00:00:00 2001 From: devin Date: Wed, 30 Sep 2026 08:54:25 +0000 Subject: [PATCH 4/4] fa: link 6 dir/entry units (objdiff 100%) Co-Authored-By: wch --- configure.py | 12 ++++----- libs/RVL_SDK/src/fa/pf_entry.c | 12 ++++++--- libs/RVL_SDK/src/fa/pf_opendir.c | 41 +++++++++++++++--------------- libs/RVL_SDK/src/fa/pf_readdir.c | 12 ++++++--- libs/RVL_SDK/src/fa/pf_rewinddir.c | 10 +++++--- libs/RVL_SDK/src/fa/pf_seekdir.c | 10 +++++--- libs/RVL_SDK/src/fa/pf_telldir.c | 10 +++++--- 7 files changed, 60 insertions(+), 47 deletions(-) diff --git a/configure.py b/configure.py index 0e8539c1..471dba50 100644 --- a/configure.py +++ b/configure.py @@ -1694,7 +1694,7 @@ config.libs = [ Object(NonMatching, "fa/pf_cache.c"), Object(NonMatching, "fa/pf_cluster.c"), Object(NonMatching, "fa/pf_dir.c"), - Object(NonMatching, "fa/pf_entry.c"), + Object(Matching, "fa/pf_entry.c"), Object(NonMatching, "fa/pf_entry_iterator.c"), Object(NonMatching, "fa/pf_fat.c"), Object(NonMatching, "fa/pf_fat12.c"), @@ -1753,15 +1753,15 @@ config.libs = [ Object(Matching, "fa/pf_mkdir.c"), Object(Matching, "fa/pf_mount.c"), Object(NonMatching, "fa/pf_move.c"), - Object(NonMatching, "fa/pf_opendir.c"), - Object(NonMatching, "fa/pf_readdir.c"), + Object(Matching, "fa/pf_opendir.c"), + Object(Matching, "fa/pf_readdir.c"), Object(NonMatching, "fa/pf_regctx.c"), Object(Matching, "fa/pf_remove.c"), Object(Matching, "fa/pf_rename.c"), - Object(NonMatching, "fa/pf_rewinddir.c"), + Object(Matching, "fa/pf_rewinddir.c"), Object(Matching, "fa/pf_rmdir.c"), Object(NonMatching, "fa/pf_rmvvol.c"), - Object(NonMatching, "fa/pf_seekdir.c"), + Object(Matching, "fa/pf_seekdir.c"), Object(NonMatching, "fa/pf_setclstlink.c"), Object(NonMatching, "fa/pf_setcode.c"), Object(NonMatching, "fa/pf_setencode.c"), @@ -1770,7 +1770,7 @@ config.libs = [ Object(NonMatching, "fa/pf_setvol.c"), Object(NonMatching, "fa/pf_setvolcfg.c"), Object(NonMatching, "fa/pf_sync.c"), - Object(NonMatching, "fa/pf_telldir.c"), + Object(Matching, "fa/pf_telldir.c"), Object(Matching, "fa/pf_unmount.c"), Object(NonMatching, "fa/pf_unregctx.c"), Object(NonMatching, "fa/pf_xdivide.c"), diff --git a/libs/RVL_SDK/src/fa/pf_entry.c b/libs/RVL_SDK/src/fa/pf_entry.c index d0a12eb5..1eea1b50 100644 --- a/libs/RVL_SDK/src/fa/pf_entry.c +++ b/libs/RVL_SDK/src/fa/pf_entry.c @@ -653,7 +653,10 @@ pf_s32 PFENT_MakeRootDir(PF_VOLUME* p_vol) { default: return 7; } - PFDRV_LoadVolumeLabelFromBuf(p_vol, (pf_u8*)"NO NAME "); + { + static pf_u8 default_volume_label[16] = "NO NAME "; + PFDRV_LoadVolumeLabelFromBuf(p_vol, default_volume_label); + } return 0; } @@ -722,7 +725,8 @@ pf_s32 PFENT_RemoveEntry(PF_DIR_ENT* p_ent, PFENTRY_ENT_ITER* p_iter) { pf_u16 entry_offset; pf_u32 i; PF_VOLUME* p_vol = PF_NULL; - const pf_u8 dir_fb_free[1] = {0xE5}; + pf_u8 dir_fb_free[8] = {0xE5}; + pf_u8 del = dir_fb_free[0]; p_vol = p_ent->p_vol; entry_sector = p_ent->entry_sector; @@ -735,7 +739,7 @@ pf_s32 PFENT_RemoveEntry(PF_DIR_ENT* p_ent, PFENTRY_ENT_ITER* p_iter) { } entry_sector = p_iter->sector; entry_offset = p_iter->offset; - err = PFSEC_WriteData(p_vol, (pf_u8*)&dir_fb_free, entry_sector, entry_offset, 1, &success_size, 0); + err = PFSEC_WriteData(p_vol, &del, entry_sector, entry_offset, 1, &success_size, 0); if (err != 0) { return err; } @@ -744,7 +748,7 @@ pf_s32 PFENT_RemoveEntry(PF_DIR_ENT* p_ent, PFENTRY_ENT_ITER* p_iter) { } } } - err = PFSEC_WriteData(p_vol, (pf_u8*)&dir_fb_free, p_ent->entry_sector, p_ent->entry_offset, 1, &success_size, 0); + err = PFSEC_WriteData(p_vol, &del, p_ent->entry_sector, p_ent->entry_offset, 1, &success_size, 0); if (err != 0) { return err; } diff --git a/libs/RVL_SDK/src/fa/pf_opendir.c b/libs/RVL_SDK/src/fa/pf_opendir.c index 8e0016f5..a9992cb9 100644 --- a/libs/RVL_SDK/src/fa/pf_opendir.c +++ b/libs/RVL_SDK/src/fa/pf_opendir.c @@ -1,34 +1,33 @@ #include -typedef struct PF_API_STRING { - const s8* head; - const s8* tail; - const s8* current; +typedef struct PFF2_STR { + const s8* p_head; + const s8* p_tail; + const s8* p_current; u32 code_mode; -} PF_API_STRING; +} PFF2_STR; -typedef struct PF_API_VOLUME_SET { +typedef struct PFF2_VOL_SET { u8 reserved[0x40]; s32 last_error; -} PF_API_VOLUME_SET; +} PFF2_VOL_SET; -extern PF_API_VOLUME_SET pf_vol_set; -extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); -extern s32 PFAPI_convertReturnValue(s32 error); - -extern s32 PFDIR_opendir(PF_API_STRING* path, FADIR** directory); -extern void* PFAPI_convertReturnValue2NULL(s32 error, void* stream); +extern PFF2_VOL_SET pf_vol_set; +extern s32 PFSTR_InitStr(PFF2_STR* path, const s8* text, u32 code_mode); +extern s32 PFDIR_opendir(PFF2_STR* path, FADIR** result); +extern FAFILE* PFAPI_convertReturnValue2NULL(s32 err, FAFILE* p_stream); FADIR* pf2_opendir(const char* path) { - PF_API_STRING path_string; - FADIR* directory; - s32 error; + FADIR* p_dir; + PFF2_STR path_str; + s32 err; - error = PFSTR_InitStr(&path_string, (const s8*)path, 1); - if (error == 0) { - error = PFDIR_opendir(&path_string, &directory); + err = PFSTR_InitStr(&path_str, (const s8*)path, 1); + if (err == 0) { + err = PFDIR_opendir(&path_str, &p_dir); } else { - pf_vol_set.last_error = error; + pf_vol_set.last_error = err; } - return PFAPI_convertReturnValue2NULL(error, directory); + p_dir = PFAPI_convertReturnValue2NULL(err, p_dir); + return p_dir; } diff --git a/libs/RVL_SDK/src/fa/pf_readdir.c b/libs/RVL_SDK/src/fa/pf_readdir.c index 96b78c3a..7a9481da 100644 --- a/libs/RVL_SDK/src/fa/pf_readdir.c +++ b/libs/RVL_SDK/src/fa/pf_readdir.c @@ -1,8 +1,12 @@ #include -extern s32 PFDIR_readdir(FADIR* directory, void* result); -extern s32 PFAPI_convertReturnValue(s32 error); +typedef struct FADirEnt FADirEnt; -s32 pf2_readdir(FADIR* directory, void* result) { - return PFAPI_convertReturnValue(PFDIR_readdir(directory, result)); +extern s32 PFDIR_readdir(FADIR* dir, FADirEnt* result); +extern s32 PFAPI_convertReturnValue(s32 err); + +FAError pf2_readdir(FADIR* dir, FADirEnt* result) { + s32 err = PFDIR_readdir(dir, result); + err = PFAPI_convertReturnValue(err); + return err; } diff --git a/libs/RVL_SDK/src/fa/pf_rewinddir.c b/libs/RVL_SDK/src/fa/pf_rewinddir.c index 396356df..011229fc 100644 --- a/libs/RVL_SDK/src/fa/pf_rewinddir.c +++ b/libs/RVL_SDK/src/fa/pf_rewinddir.c @@ -1,8 +1,10 @@ #include -extern s32 PFDIR_seekdir(FADIR* directory, u32 position); -extern s32 PFAPI_convertReturnValue(s32 error); +extern s32 PFDIR_seekdir(FADIR* dir, u32 position); +extern s32 PFAPI_convertReturnValue(s32 err); -s32 pf2_rewinddir(FADIR* directory) { - return PFAPI_convertReturnValue(PFDIR_seekdir(directory, 0)); +FAError pf2_rewinddir(FADIR* dir) { + s32 err = PFDIR_seekdir(dir, 0); + err = PFAPI_convertReturnValue(err); + return err; } diff --git a/libs/RVL_SDK/src/fa/pf_seekdir.c b/libs/RVL_SDK/src/fa/pf_seekdir.c index 2acd1e99..d225f812 100644 --- a/libs/RVL_SDK/src/fa/pf_seekdir.c +++ b/libs/RVL_SDK/src/fa/pf_seekdir.c @@ -1,8 +1,10 @@ #include -extern s32 PFDIR_seekdir(FADIR* directory, u32 position); -extern s32 PFAPI_convertReturnValue(s32 error); +extern s32 PFDIR_seekdir(FADIR* dir, u32 position); +extern s32 PFAPI_convertReturnValue(s32 err); -s32 pf2_seekdir(FADIR* directory, u32 position) { - return PFAPI_convertReturnValue(PFDIR_seekdir(directory, position)); +FAError pf2_seekdir(FADIR* dir, u32 position) { + s32 err = PFDIR_seekdir(dir, position); + err = PFAPI_convertReturnValue(err); + return err; } diff --git a/libs/RVL_SDK/src/fa/pf_telldir.c b/libs/RVL_SDK/src/fa/pf_telldir.c index 1115c69d..7b4c4066 100644 --- a/libs/RVL_SDK/src/fa/pf_telldir.c +++ b/libs/RVL_SDK/src/fa/pf_telldir.c @@ -1,8 +1,10 @@ #include -extern s32 PFDIR_telldir(FADIR* directory, u32* position); -extern s32 PFAPI_convertReturnValue(s32 error); +extern s32 PFDIR_telldir(FADIR* dir, u32* position); +extern s32 PFAPI_convertReturnValue(s32 err); -s32 pf2_telldir(FADIR* directory, u32* position) { - return PFAPI_convertReturnValue(PFDIR_telldir(directory, position)); +FAError pf2_telldir(FADIR* dir, u32* position) { + s32 err = PFDIR_telldir(dir, position); + err = PFAPI_convertReturnValue(err); + return err; } -- 2.49.1