cleanup(jpeg): name TMC_JPEG fields and decoder parameters (worker e0c6e69a)

This commit is contained in:
coah
2026-10-09 19:45:07 +00:00
parent 8a67b68cf2
commit 8769b7afcd
8 changed files with 178 additions and 67 deletions

View File

@@ -15,26 +15,32 @@ extern "C" {
#define TMCC_JPEG_DEC_WORK_SIZE 0x1C00
enum TMCCJPEGOutputFormat {
TMCC_JPEG_OUTPUT_RGB565 = 0,
TMCC_JPEG_OUTPUT_RGBA8 = 1,
TMCC_JPEG_OUTPUT_Y8U8V8 = 2
};
typedef struct TMCCJPEGDecWork_t TMCCJPEGDecWork;
typedef s32(TMCCReadCallback)(void*, u8*, unsigned int);
typedef struct {
u8 unk_0x00[0x10];
u8 reserved[0x10];
void* pBuf2; // 0x10
u32 buf2Size; // 0x14
u32 dataSize; // 0x18
TMCCReadCallback* pCallback; // 0x1C
void* pContext; // 0x20
u8 unk_0x24; // 0x24
u8 pad_0x25[0x03];
u8 thumbnailMode; // 0x24
u8 workBufferPadding[0x03];
TMCCJPEGDecWork* pBuf1; // 0x28
u8 unk_0x2C; // 0x2C
u8 pad_0x2D[0x03];
u8 outputFormat; // 0x2C
u8 alignmentPadding[0x03];
} TMCCJPEGDecInitParam;
typedef struct {
u8 unk_0x00[0x0C];
u8 reserved[0x0C];
u16 orientation; // 0x0C
u32 xResNum; // 0x10
u32 xResDen; // 0x14
@@ -70,7 +76,7 @@ typedef struct {
u16 posX;
u16 posY;
s32 position; // 0x04
u8 unk_0x08[0x04];
u8 reserved[0x04];
u32 state; // 0x0C
u16 maxX;
u16 maxY;
@@ -80,8 +86,8 @@ typedef struct {
u8 stepYExt;
u32 dataSizeX;
u32 dataSizeY;
u8 exifFlags; // 0x20
u8 thumbFlag; // 0x21
u8 scaleFactor; // 0x20
u8 noEoiCheck; // 0x21
u8 componentCount;
u8 dimensionPadding;
u16 jpegWidth;
@@ -107,7 +113,7 @@ typedef struct {
u16 posX; // 0x00
u16 posY; // 0x02
s32 position; // 0x04
u8 unk_0x08[0x04];
u8 reserved[0x04];
u32 result; // 0x0C
u16 maxX; // 0x10
u16 maxY; // 0x12
@@ -118,30 +124,26 @@ typedef struct {
u32 dataSizeX; // 0x18
u32 dataSizeY; // 0x1C
u8 scaleFactor; // 0x20
u8 unk_0x21; // 0x21
u8 noEoiCheck; // 0x21
u8 componentCount; // 0x22
u8 unk_0x23; // 0x23
u8 dimensionPadding;
u16 jpegWidth; // 0x24
u16 jpegHeight; // 0x26
u16 outputWidth; // 0x28
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];
TMCCJPEGDecExifData exifData; // 0x4C
TMCCJPEGDecWork* pWorkBuf; // 0x6C8
s32 decodeResult; // 0x6CC
u8 converterType; // 0x6D0
u8 unk_0x6D1[0x03];
u8 alignmentPadding[0x03];
} TMCCJPEGDecState;
s32 TMCCJPEGDecInit(TMCCJPEGDecState* state, TMCCJPEGDecInitParam* param);

View File

@@ -5,12 +5,6 @@
#include <tmc_jpeg.h>
enum TMCCJPEGOutputFormat {
TMCC_JPEG_OUTPUT_RGB565 = 0,
TMCC_JPEG_OUTPUT_RGBA8 = 1,
TMCC_JPEG_OUTPUT_Y8U8V8 = 2
};
enum TMCJpegMarker {
TMC_JPEG_MARKER_SOF0 = 0xFFC0,
TMC_JPEG_MARKER_SOF2 = 0xFFC2,

View File

@@ -37,16 +37,16 @@ s32 TMCCJPEGDecInit(TMCCJPEGDecState* state, TMCCJPEGDecInitParam* param) {
work->pState = state;
state->pWorkBuf = work;
if (param->unk_0x24 != 0) {
if (param->thumbnailMode != 0) {
result = -1;
} else if (param->unk_0x2C != TMCC_JPEG_OUTPUT_RGB565 && param->unk_0x2C != TMCC_JPEG_OUTPUT_RGBA8 &&
param->unk_0x2C != TMCC_JPEG_OUTPUT_Y8U8V8) {
} else if (param->outputFormat != TMCC_JPEG_OUTPUT_RGB565 && param->outputFormat != TMCC_JPEG_OUTPUT_RGBA8 &&
param->outputFormat != TMCC_JPEG_OUTPUT_Y8U8V8) {
result = -1;
} else {
state->unk_0x21 = param->unk_0x24;
state->noEoiCheck = param->thumbnailMode;
result = 0;
state->scaleFactor = 1;
state->converterType = param->unk_0x2C;
state->converterType = param->outputFormat;
}
if (result < 0) {

View File

@@ -221,11 +221,11 @@ s32 TMCCJPEGDecGetInfoEXIF(TMCCJPEGDecExifInfo* pInfo, TMCCJPEGDecInitParam* pPa
return result;
}
if (pParam->unk_0x24 == 0) {
if (pParam->thumbnailMode == 0) {
return 0;
}
if (pParam->unk_0x24 == 1) {
if (pParam->thumbnailMode == 1) {
result = TMCJPEGDEC_ThumbnailCheck(pParam, pInfo, segSizeP2);
if (result < 0) {
return result;
@@ -668,7 +668,7 @@ static void TMCJPEGDEC_IFD1_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder,
static s32 TMCJPEGDEC_ThumbnailCheck(TMCCJPEGDecInitParam* param, TMCCJPEGDecExifInfo* info, u32 totalSize) {
s32 total;
s32 length;
s32 tmp;
s32 thumbnailBufferOffset;
total = (s32)info->exifData.thumbnailOffset;
if (total == 0) {
@@ -684,8 +684,8 @@ static s32 TMCJPEGDEC_ThumbnailCheck(TMCCJPEGDecInitParam* param, TMCCJPEGDecExi
return -0xA0;
}
tmp = (s32)info->exifData.thumbnailData - (s32)param->pBuf2;
total = length + total + tmp;
thumbnailBufferOffset = (s32)info->exifData.thumbnailData - (s32)param->pBuf2;
total = length + total + thumbnailBufferOffset;
if ((u32)total > param->buf2Size) {
return -0xF1;
@@ -695,19 +695,19 @@ static s32 TMCJPEGDEC_ThumbnailCheck(TMCCJPEGDecInitParam* param, TMCCJPEGDecExi
return -0xF1;
}
info->exifFlags = 1;
info->scaleFactor = 1;
if (param->unk_0x24 != 1) {
if (param->thumbnailMode != 1) {
return -1;
}
info->thumbFlag = 0;
info->noEoiCheck = 0;
if (param->unk_0x2C != TMCC_JPEG_OUTPUT_RGB565 && param->unk_0x2C != TMCC_JPEG_OUTPUT_RGBA8 &&
param->unk_0x2C != TMCC_JPEG_OUTPUT_Y8U8V8) {
if (param->outputFormat != TMCC_JPEG_OUTPUT_RGB565 && param->outputFormat != TMCC_JPEG_OUTPUT_RGBA8 &&
param->outputFormat != TMCC_JPEG_OUTPUT_Y8U8V8) {
return -1;
}
info->converterType = param->unk_0x2C;
info->converterType = param->outputFormat;
return 0;
}

View File

@@ -1,5 +1,6 @@
#define TMC_JPEG_FRAME_PARSER
#include <tmc_jpeg_internal.h>
#include <stddef.h>
extern void* memset(void* dest, s32 val, u32 count);
@@ -68,7 +69,7 @@ s32 TMCJPEGDEC_decompmcu(u32 maxMCU, u32 mcuCount, TMCCJPEGDecWork* work, void*
blockCountPtr = frameInfo + mcuIdx;
blockIdx = 0;
while (blockIdx < *(blockCountPtr + 0x1c)) {
while (blockIdx < *(blockCountPtr + offsetof(TMCJpegFrameInfo, blockCount))) {
s32 stackBlock[64];
s32 ret;
@@ -146,7 +147,7 @@ s32 TMCJPEGDEC_imagestart(TMCCJPEGDecWork* work) {
}
s32 TMCJPEGDEC_imageend(TMCCJPEGDecWork* work) {
if (work->pState->unk_0x21 == 1)
if (work->pState->noEoiCheck == 1)
return 0;
if (work->scanCount == 0) {
@@ -816,7 +817,7 @@ static s32 TMCJPEGDEC_parse_sos(TMCCJPEGDecWork* work) {
s32 idx;
TMCFrameComponents* components;
TMCJpegTableInfo* scalePtr;
TMCFrameComponents* mapPtr;
u8* mapPtr;
s32 dcTbl;
s32 acTbl;
@@ -858,7 +859,7 @@ static s32 TMCJPEGDEC_parse_sos(TMCCJPEGDecWork* work) {
for (ci = 0; ci < work->compCount; ci++) {
if ((s32)scanByte == (s32)components->id[ci]) {
components->map[idx] = ci;
mapPtr = (TMCFrameComponents*)&components->map[idx];
mapPtr = &components->map[idx];
goto componentFound;
}
}
@@ -877,8 +878,8 @@ componentFound:
return -0x51;
}
components->dcTable[mapPtr->map[0]] = dcTbl;
components->acTable[mapPtr->map[0]] = acTbl;
components->dcTable[*mapPtr] = dcTbl;
components->acTable[*mapPtr] = acTbl;
if (scalePtr->dcTblFlag[dcTbl] != 1) {
return -0x40;
@@ -888,7 +889,7 @@ componentFound:
return -0x40;
}
if (scalePtr->quantTblFlag[mapPtr->quantTable[0]] != 1) {
if (scalePtr->quantTblFlag[components->quantTable[idx]] != 1) {
return -0x41;
}
}
@@ -1002,18 +1003,15 @@ void TMCJPEGDEC_set_entropytbl(TMCJpegTableInfo* work, s32 idx, u8 data) {
}
}
if ((s32)data == 1) {
goto ac1;
if ((s32)data != 1) {
if ((s32)data < 1 && (s32)data >= 0) {
work->pACFast = work->huffDecTblAC0;
work->pACHuffSym = work->maxCodeAC0;
work->pACHuffTbl = work->valPtrAC0;
}
} else {
work->pACFast = work->huffDecTblAC1;
work->pACHuffSym = work->maxCodeAC1;
work->pACHuffTbl = work->valPtrAC1;
}
if ((s32)data < 1 && (s32)data >= 0) {
work->pACFast = work->huffDecTblAC0;
work->pACHuffSym = work->maxCodeAC0;
work->pACHuffTbl = work->valPtrAC0;
}
return;
ac1:
work->pACFast = work->huffDecTblAC1;
work->pACHuffSym = work->maxCodeAC1;
work->pACHuffTbl = work->valPtrAC1;
}

View File

@@ -1,4 +1,3 @@
#define TMC_JPEG_PLANAR_OUTPUT
#include <tmc_jpeg_internal.h>
static void TMCJPEG_814EFEAC(TMCCJPEGDecWork*, s32, s32);

View File

@@ -27,8 +27,8 @@ namespace ipl {
mReadPos = 0;
TMCCJPEGDecInitParam param;
param.unk_0x24 = 0;
param.unk_0x2C = 0;
param.thumbnailMode = 0;
param.outputFormat = TMCC_JPEG_OUTPUT_RGB565;
param.pBuf1 = mpBuf1;
param.pBuf2 = mpBuf2;
param.buf2Size = 0x10040;
@@ -212,8 +212,8 @@ namespace ipl {
Graphics::Orientation ori = Graphics::ORI_NONE;
TMCCJPEGDecInitParam param;
param.unk_0x24 = 0;
param.unk_0x2C = 0;
param.thumbnailMode = 0;
param.outputFormat = TMCC_JPEG_OUTPUT_RGB565;
param.pBuf1 = mpBuf1;
param.pBuf2 = mpBuf2;
param.buf2Size = 0x10040;
@@ -227,8 +227,8 @@ namespace ipl {
u32 exifSize;
if (TMCCJPEGDecGetOffsetEXIF(&exifOffset, &exifSize, &param) == 0) {
param.unk_0x24 = 0;
param.unk_0x2C = 0;
param.thumbnailMode = 0;
param.outputFormat = TMCC_JPEG_OUTPUT_RGB565;
param.pBuf1 = mpBuf1;
param.pBuf2 = mpData + exifOffset;
param.buf2Size = exifSize;

View File

@@ -0,0 +1,118 @@
# clean3-c7 JPEG cleanup
Worktree `/mnt/drive2/projects/wii-ipl-workers/clean3-c7`, branch `agent/w1009/clean3-c7`.
Starting commit `8a67b68cf`. Baseline completion check returned `DECOMPLETE_OK`.
Baseline DOL SHA1 `26116613f624061ba99c8d1a299aaa6efa85670d`.
## Prior evidence and source reference
Read `clean3-head.md`, `cleanup-common.md`, local `AGENTS.md`, and the cleanup-c5,
cleanup2-x9 and cleanup2-w5 attempt logs. Apply unslop and writing-for-agents.
Skip the previously rejected texture pragma deletion, declaration initialization,
sampling-case scopes, first-store splitting and alpha arithmetic changes. Keep the
buffer readers' explained empty branches and shared success exits. Skip the
already rejected direct rewrites of decapi's result helpers and Huffman-entry copies.
Read the older JPEG library in hotlandsoftware/wii-news-channel at revision
`128e3ffbaee9e70bd175c5f66a44fb8430068629` into `/tmp/clean3-c7-news-*`.
Reference: https://github.com/hotlandsoftware/wii-news-channel/blob/128e3ffbaee9e70bd175c5f66a44fb8430068629/src/revolution/TMCC_JPEG/jpgd_internal.h
Its `jpgd_internal.h` names the output format, EOI-check flag and planar fields.
The local EXIF parser proves that init offset 0x24 selects thumbnail processing;
the state byte at 0x21 disables EOI checking. These receive separate names.
The older library does not identify the untouched reserved byte ranges.
Before editing, rebuilt and saved all 15 JPEG objects plus iplJpegDecoder.
Every unit was exact and linked. Compare every allocated section and normalized
relocation destination against these saved objects for each compiled trial.
Compiler metadata and local literal symbol names do not establish byte changes.
## Retained changes
- tmc_jpeg.h and its callers: name thumbnailMode, outputFormat and noEoiCheck;
name alignment bytes and reserved ranges; expose the existing planar members
and typed EXIF data in every state declaration. Remove the planar-only macro
from Texture_MCUtoY8U8V8.c. All 16 rebuilt objects preserve every allocated byte
and relocation destination.
## Compiled trials
- `entropy-structured-if`: rejected; .text; TMCJPEGDEC_set_entropytbl: 14 diffs, 38/38 instructions.
- `sof-sampling-break`: rejected; .rela.text, .text; TMCJPEGDEC_parse_sof: 107 diffs, 225/223 instructions.
- `sos-component-break`: rejected; .rela.text, .text; TMCJPEGDEC_parse_sos: 73 diffs, 115/112 instructions.
- `mcu-typed-frame-view`: rejected; .text; TMCJPEGDEC_decompmcu: 13 diffs, 113/113 instructions.
- `sos-typed-map-byte`: retained; all allocated sections and relocations identical.
- `entropy-structured-nested-if`: retained; all allocated sections and relocations identical.
- `sof-sampling-inline-selection`: rejected; .text; TMCJPEGDEC_parse_sof: 21 diffs, 223/223 instructions.
- `converter-RGB565-rounding-inline-no-pragma`: rejected; .rela.text, .text; TMCJPEGDEC_set_converterRGB565: 169 diffs, 169/170 instructions.
- `converter-RGBA8-rounding-inline-no-pragma`: rejected; .rela.text, .text; TMCJPEGDEC_set_converterRGBA8: 169 diffs, 169/170 instructions; TMCJPEGDEC_converterYUV411toRGBA8: 6 diffs, 242/242 instructions.
- `converter-Y8U8V8-rounding-inline-no-pragma`: rejected; .rela.text, .text; TMCJPEGDEC_set_converterY8U8V8: 195 diffs, 195/196 instructions.
- `entropy-zero-comparison`: rejected; .text; TMCJPEGDEC_set_entropytbl: 18 diffs, 37/38 instructions.
- `mcu-named-block-count-offset`: retained; all allocated sections and relocations identical.
- `exif-thumbnail-buffer-offset-name`: retained; all allocated sections and relocations identical.
## Final source decisions
- Public header: all 11 unk names are removed. Three consumed fields receive
semantic names. The known planar and EXIF data replace opaque byte ranges.
Unused ranges remain reserved; their original purpose is unproven. Alignment
members receive names. Move the existing output-format enum to the public API.
- Internal header: remove the duplicate-location output-format enum.
- iplJpegDecoder.cpp: use named thumbnail/output fields and RGB565 format constants.
- exif_parse.c: use named init fields, consistent scaleFactor/noEoiCheck fields
for the state view, and thumbnailBufferOffset for the buffer-range calculation.
- decapi.c: use named init and EOI-check fields. Keep both shared error exits and
the wave-2 result helpers whose direct forms were already rejected.
- jdec_main.c: remove the AC-table goto and return through structured branches.
Replace the shifted component-struct view with the actual map-byte pointer.
Name the block-count offset with offsetof of the existing frame type. A fully
typed frame view changed 13 instructions and was restored. The simpler AC0
condition dropped one instruction and was restored.
- Preserve the sampling/component-search gotos: structured break forms add two
or three instructions; the sampling helper preserves size but changes 21
instructions. The older library uses the same two nested-search exit patterns.
- Preserve err_restart's stream reset and its existing compiler comment. The
final matching effort-policy entry records that this reset keeps the exact
loop-exit branch. Do not repeat its exhausted removal trials.
- All three texture setters keep their level-1 scopes and existing comments.
Moving dimension rounding into an ordinary inline helper without the pragma
still removes one setter instruction. RGBA8 also changes six operands in its
4:1:1 converter. Restore all three trials. Y8U8V8 drops its redundant planar
declaration macro because the public state now always has those real fields.
- No use-site volatile access exists in the assigned JPEG source. Keep the
previously explained buffer branches and Huffman copies unchanged.
## Final verification
Gate ran once with --quick over all 15 JPEG units and iplJpegDecoder. Log:
`/tmp/clean3-c7-final-gate.log`. GATE PASS, full build ok, zero regressions,
zero added forbidden patterns and zero readability warnings. The gate used
baseline 04d3d1e8, the immediate parent of the docs-only starting commit.
Fresh build/43U/report.json and build/43U/ok pass. DECOMPLETE_OK and ASM INVENTORY
PASS, with 162 original SDK assembly functions and zero placeholders. DOL SHA1
`26116613f624061ba99c8d1a299aaa6efa85670d`.
All 16 owned units retain 100 exact functions and 100% code, data, function,
section and link measures. Every allocated section and normalized relocation
matches the pre-edit object. Focused pool checks are identical. Focused ctxdiff
checks are zero for init, EXIF info/thumbnail checks, MCU decode, SOS parsing,
entropy selection, JpegDecoder::decodeJpg and JpegDecoder::get_orientation.
Focused log: `/tmp/clean3-c7-focused.log`. Whitespace check passes.
Global exact counts remain 12563/12563 functions and 1028/1028 units. Code and
data are 100% matched and linked. Global fuzzy remains the baseline 99.999886%.
Only the assigned module, iplJpegDecoder.cpp and this attempt log change.
Source and headers are committed individually. No push, PR, merge, rebase,
other-worktree edit or additional worker was performed.
## File commits
- `2acd985a5f519bb4a46c17c52ad5e178ef1636de` libs/RVLMiddleware/TMC_JPEG/include/tmc_jpeg.h
- `231bb21a6222e9bf3f9f72612ddb8876a3c042c7` libs/RVLMiddleware/TMC_JPEG/include/tmc_jpeg_internal.h
- `b95931e8832be19643fd31767002e3a4a0a2b6ee` libs/RVLMiddleware/TMC_JPEG/src/api/decapi.c
- `3e1a71167877e712e61774499f39f2c956d9cd60` libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse.c
- `ca977fc465a1d2da1467fad855bd258c663f5c4a` libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec_main.c
- `85ceb54b664d67d6c719734ee3705639f794e4ed` libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoY8U8V8.c
- `952e9e148ad7a54645333d52704c56ce60f7f7d4` src/utility/iplJpegDecoder.cpp