Compare commits

...

1 Commits

11 changed files with 510 additions and 247 deletions

View File

@@ -49,17 +49,17 @@ typedef struct {
u8 flashVer[4]; // 0x640
s8 flashPixVer[4]; // 0x644
u16 colorSpace; // 0x648
u8 unk_0x64A[0x02];
u8 colorSpacePadding[0x02];
u32 pixelXDim; // 0x64C
u32 pixelYDim; // 0x650
u16 compressionIfd1; // 0x654
u8 unk_0x656[0x02];
u8 compressionPadding[0x02];
u32 xResNumIfd1; // 0x658
u32 xResDenIfd1; // 0x65C
u32 planarConfigIfd1; // 0x660
u32 yResDenIfd1; // 0x664
u16 resUnitIfd1; // 0x668
u8 unk_0x66A[0x02];
u8 resolutionPadding[0x02];
u32 thumbnailOffset; // 0x66C
u32 thumbnailLength; // 0x670
u8* thumbnailData; // 0x674
@@ -67,19 +67,40 @@ typedef struct {
} TMCCJPEGDecExifData;
typedef struct {
u8 unk_0x00[0x04];
u16 posX;
u16 posY;
s32 position; // 0x04
u8 unk_0x08[0x04];
u32 state; // 0x0C
u8 unk_0x10[0x10];
u16 maxX;
u16 maxY;
u8 stepX;
u8 stepY;
u8 stepXExt;
u8 stepYExt;
u32 dataSizeX;
u32 dataSizeY;
u8 exifFlags; // 0x20
u8 thumbFlag; // 0x21
u8 unk_0x22[0x2A];
u8 componentCount;
u8 dimensionPadding;
u16 jpegWidth;
u16 jpegHeight;
u16 outputWidth;
u16 outputHeight;
u32 convWidth;
u32 convHeight;
u32 chromaWidth;
u32 chromaHeight;
u8* pLumaBuffer;
u8* pCbBuffer;
u8* pCrBuffer;
void* pTexBuffer;
TMCCJPEGDecExifData exifData; // 0x4C
TMCCJPEGDecWork* pWorkBuf; // 0x6C8
u8 unk_0x6CC[0x04];
s32 decodeResult;
u8 converterType; // 0x6D0
u8 unk_0x6D1[0x03];
u8 alignmentPadding[0x03];
} TMCCJPEGDecExifInfo;
typedef struct {

View File

@@ -39,43 +39,32 @@ typedef void(TMCConverterFunc)(TMCCJPEGDecWork*, s32 x, s32 y);
extern "C" {
#endif
// TODO: The following two structs are subsets of TMCCJPEGDecWork.
// Their members in TMCCJPEGDecWork should eventually be removed and replaced with these structs as a member.
// Some code accesses scaleFlag, frameWidth and convBuf as a pointer and uses them as a base to do further pointer arithmetic on,
// so they likely were nested structs.
typedef struct {
u8 scaleFlag; // 0x00
u8 unk_0x01[0x3E7];
u8* pDCACPtrs[6]; // 0x03E8-0x03FF
u8 zigzagData[64]; // 0x0400-0x043F
u16* pDCFast; // 0x0440
u32* pDCHuffTbl; // 0x0444
u8* pDCHuffSym; // 0x0448
u32 unk_0x4A4; // 0x044C
u16* pACFast; // 0x0450
u32* pACHuffTbl; // 0x0454
u8* pACHuffSym; // 0x0458
u32 unk_0x4C5;
u8 unk_0x460[0x1B4];
u32 thumbHuffSize[3]; // 0x0614
u8 unk_0x620[0x1E8];
u8 huffDecTblDC1[0x400]; // 0x0808-0x0C07
u8 huffDecTblAC0[0x400]; // 0x0C08-0x1007
u8 huffDecTblAC1[0x400]; // 0x1008-0x1407
u8 valPtrDC0[0x44]; // 0x1408-0x144B
u8 valPtrDC1[0x44]; // 0x144C-0x148F
u8 valPtrAC0[0x44]; // 0x1490-0x14D3
u8 valPtrAC1[0x44]; // 0x14D4-0x1517
u8 maxCodeDC0[0x10]; // 0x1518-0x1527
u8 maxCodeDC1[0x10]; // 0x1528-0x1537
u8 maxCodeAC0[0x100]; // 0x1538-0x1637
u8 maxCodeAC1[0x100]; // 0x1638-0x1737
u8 unk_0x1738[0x04];
u8 huffTblInitFlag[4]; // 0x173C
u8 unk_0x1740[0x50];
u8 quantTblFlag[4]; // 0x1790
u8 dcTblFlag[2]; // 0x1794
u8 acTblFlag[2]; // 0x1796
u32 coefficients[4][64];
u8 zigzagData[64];
u16* pDCFast;
u32* pDCHuffTbl;
u8* pDCHuffSym;
u32 reservedDC;
u16* pACFast;
u32* pACHuffTbl;
u8* pACHuffSym;
u32 reservedAC;
u16 huffDecTblDC0[0x200];
u16 huffDecTblDC1[0x200];
u16 huffDecTblAC0[0x200];
u16 huffDecTblAC1[0x200];
u32 valPtrDC0[17];
u32 valPtrDC1[17];
u32 valPtrAC0[17];
u32 valPtrAC1[17];
u8 maxCodeDC0[0x10];
u8 maxCodeDC1[0x10];
u8 maxCodeAC0[0x100];
u8 maxCodeAC1[0x100];
u8 quantTblFlag[4];
u8 dcTblFlag[2];
u8 acTblFlag[2];
} TMCJpegTableInfo;
typedef struct {
@@ -101,9 +90,18 @@ typedef struct {
u8 maxVSamp; // 0x29
u16 restartInterval; // 0x2A
u8 scanCount; // 0x2C
u8 unk_0x2D[0x03];
u8 alignmentPadding[0x03];
} TMCJpegFrameInfo;
typedef struct {
u8 map[4];
u32 dcPredict[4];
u8 id[4];
u8 quantTable[4];
u8 dcTable[4];
u8 acTable[4];
} TMCFrameComponents;
struct TMCCJPEGDecWork_t {
u32 bitBuf; // 0x00
s32 bitCount; // 0x04
@@ -116,47 +114,11 @@ struct TMCCJPEGDecWork_t {
s32 remaining; // 0x20
TMCCReadCallback* pCallback; // 0x24
void* pCbCtx; // 0x28
u8 compMap[4]; // 0x2C
u32 dcPredict[4]; // 0x30
u8 compId[4]; // 0x40
u8 compQTbl[4]; // 0x44
u8 copDCTbl[4]; // 0x48
u8 copACTbl[4]; // 0x4C
TMCFrameComponents components;
u16 restartCnt; // 0x50
u16 rstMarkerIdx; // 0x52
u32 mcuPos; // 0x54
// Section below is likely a nested struct
u8 scaleFlag; // 0x58
u8 unk_0x59[0x3E7];
u8* pDCACPtrs[6]; // 0x440
u8 zigzagData[64]; // 0x458
u16* pDCFast; // 0x498
u32* pDCHuffTbl; // 0x49C
u8* pDCHuffSym; // 0x4A0
u32 unk_0x4A4;
u16* pACFast; // 0x4A8
u32* pACHuffTbl; // 0x4AC
u8* pACHuffSym; // 0x4B0
u8 unk_0x4B4[0x1B8];
u32 thumbHuffSize[3]; // 0x66C
u8 unk_0x678[0x1E8];
u8 huffDecTblDC1[0x400]; // 0x860-0xC5F
u8 huffDecTblAC0[0x400]; // 0xC60-0x105F
u8 huffDecTblAC1[0x400]; // 0x1060-0x145F
u8 valPtrDC0[0x44]; // 0x1460-0x14A3
u8 valPtrDC1[0x44]; // 0x14A4-0x14E7
u8 valPtrAC0[0x44]; // 0x14E8-0x152B
u8 valPtrAC1[0x44]; // 0x152C-0x156F
u8 maxCodeDC0[0x10]; // 0x1570-0x157F
u8 maxCodeDC1[0x10]; // 0x1580-0x158F
u8 maxCodeAC0[0x100]; // 0x1590-0x168F
u8 maxCodeAC1[0x100]; // 0x1690-0x178F
u8 unk_0x1790[0x04];
u8 huffTblInitFlag[4]; // 0x1794
u8 unk_0x1798[0x50];
u8 quantTblFlag[4]; // 0x17E8
u8 dcTblFlag[2]; // 0x17EC
u8 acTblFlag[2]; // 0x17EE
TMCJpegTableInfo tables;
// Section below is likely a nested struct
u16 frameWidth; // 0x17F0
u16 frameHeight; // 0x17F2
@@ -180,7 +142,7 @@ struct TMCCJPEGDecWork_t {
u8 maxVSamp; // 0x1819
u16 restartInterval; // 0x181A
u8 scanCount; // 0x181C
u8 unk_0x181D[0x03];
u8 framePadding[0x03];
TMCIdctFunc* idctPtr; // 0x1820
TMCIdctFunc* idctLumiPtr; // 0x1824
TMCDecodeFunc* decodePtr; // 0x1828
@@ -191,10 +153,10 @@ struct TMCCJPEGDecWork_t {
u8* pConvRowPtrs[7]; // 0x183C
u8 convBuf[0x184]; // 0x1858
u8 idctMode; // 0x19DC
u8 unk_0x19DD;
u8 pitchPadding;
u16 pitch; // 0x19DE
u8 converterFlags; // 0x19E0
u8 unk_0x19E1[0x03];
u8 statePadding[0x03];
TMCCJPEGDecState* pState; // 0x19E4
};
@@ -213,7 +175,7 @@ s32 TMCJPEGDEC_rewind_ptr(TMCCJPEGDecWork* work);
typedef struct {
u32* huffTable; // 0x00
u8* valptr; // 0x04
u32* valptr; // 0x04
u32* maxCode; // 0x08
u8 count; // 0x0C
} TMCHuffParam;
@@ -228,7 +190,7 @@ s32 TMCJPEGDEC_scanstart(TMCCJPEGDecWork* work);
s32 TMCJPEGDEC_scan_varinit(TMCCJPEGDecWork* work);
s32 TMCJPEGDEC_restart_interval(TMCCJPEGDecWork* work, u32 maxMCU, u32 mcuCount);
s32 TMCJPEGDEC_err_restart(TMCCJPEGDecWork* work);
void TMCJPEGDEC_set_entropytbl(TMCCJPEGDecWork* work, s32 idx, u8 data);
void TMCJPEGDEC_set_entropytbl(TMCJpegTableInfo* work, s32 idx, u8 data);
s32 TMCJPEGDEC_Decompscan(TMCCJPEGDecWork* work);
s32 TMCJPEGDEC_Setsize(TMCCJPEGDecWork* work);

View File

@@ -140,7 +140,7 @@ s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_p
conv_row = (s32*)conv_row_ptr;
bit_pos = work->bitCount;
dc_fast = work->pDCFast;
dc_fast = work->tables.pDCFast;
if (bit_pos <= 8) {
r = TMCJPEGDEC_load_buff(work);
@@ -161,8 +161,8 @@ s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_p
work->bitCount = bit_pos - r;
r = extra;
} else {
huff_sym = work->pDCHuffSym;
huff_tbl = work->pDCHuffTbl;
huff_sym = work->tables.pDCHuffSym;
huff_tbl = work->tables.pDCHuffTbl;
r = decodeLongHuffman(bit_pos, huff_tbl, huff_sym, work, &dcLimit, &dcDecoded);
if (r < 0) {
return r;
@@ -196,9 +196,9 @@ s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_p
u32* ac_huff_tbl;
u8* ac_huff_sym;
ac_fast = work->pACFast;
ac_huff_tbl = work->pACHuffTbl;
ac_huff_sym = work->pACHuffSym;
ac_fast = work->tables.pACFast;
ac_huff_tbl = work->tables.pACHuffTbl;
ac_huff_sym = work->tables.pACHuffSym;
memset(block + 1, 0, 0xFC);
@@ -279,8 +279,8 @@ s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_p
bit_data = work->bitBuf;
bit_pos = work->bitCount;
t = bit_pos - 8;
tmp = ((bit_data >> t) & 0xFF) << 2;
acEntry = readHuffmanEntry((const TMCHuffmanEntry*)ac_fast, tmp >> 2);
tmp = (bit_data >> t) & 0xFF;
acEntry = readHuffmanEntry((const TMCHuffmanEntry*)ac_fast, tmp);
idx += 16;
}

View File

@@ -12,9 +12,9 @@ s32 TMCJPEGDEC_init_ptr_buff(TMCCJPEGDecWork* work, void* param) {
u32 newRemaining;
const TMCCJPEGDecInitParam* input = (const TMCCJPEGDecInitParam*)((u8*)param - offsetof(TMCCJPEGDecInitParam, pBuf2));
if ((u32)input->pBuf2 & 0x1F)
if ((u32)input->pBuf2 & (DEFAULT_ALIGN - 1))
return -1;
if (input->buf2Size & 0x1F)
if (input->buf2Size & (DEFAULT_ALIGN - 1))
return -1;
if (input->dataSize == 0)
return -1;

View File

@@ -27,7 +27,7 @@ s32 TMCJPEGDEC_init_buff_thumbnail(TMCCJPEGDecWork* work, u8* dst, u8* src) {
endAddress = (u32)buffer->pBufCur + endAddress;
buffer->remaining = 0;
buffer->pBufEnd = (u8*)endAddress;
buffer->pBufMark = (u8*)((u32)endAddress - 0x22);
buffer->pBufMark = (u8*)endAddress - 0x22;
return 0;
}

View File

@@ -121,7 +121,7 @@ s32 TMCJPEGDEC_make_huffdec(const u8* dht, u8* tb, TMCHuffParam* hp) {
void TMCJPEGDEC_set_HuffmanTable(TMCHuffParam* tbl, s32 tblType, s32 tblID, TMCJpegTableInfo* info) {
TMCCJPEGDecWork* work = (TMCCJPEGDecWork*)info;
TMCJpegTableInfo* work = info;
void* hufftable;
void* maxcode;
void* valptr;
@@ -129,15 +129,15 @@ void TMCJPEGDEC_set_HuffmanTable(TMCHuffParam* tbl, s32 tblType, s32 tblID, TMCJ
if (tblType == 0) {
switch (tblID) {
case 0: {
hufftable = &work->zigzagData[8];
hufftable = work->huffDecTblDC0;
maxcode = work->maxCodeDC0;
tbl->huffTable = hufftable;
tbl->maxCode = maxcode;
tbl->valptr = work->valPtrDC0;
work->huffTblInitFlag[0] = 1;
memset(hufftable, 0, 0x400);
memset(work->maxCodeDC0, 0, 0x10);
memset(work->valPtrDC0, 0, 0x44);
work->dcTblFlag[0] = 1;
memset(hufftable, 0, sizeof(work->huffDecTblDC0));
memset(work->maxCodeDC0, 0, sizeof(work->maxCodeDC0));
memset(work->valPtrDC0, 0, sizeof(work->valPtrDC0));
break;
}
case 1: {
@@ -147,10 +147,10 @@ void TMCJPEGDEC_set_HuffmanTable(TMCHuffParam* tbl, s32 tblType, s32 tblID, TMCJ
tbl->huffTable = hufftable;
tbl->maxCode = maxcode;
tbl->valptr = valptr;
work->huffTblInitFlag[1] = 1;
memset(hufftable, 0, 0x400);
memset(work->maxCodeDC1, 0, 0x10);
memset(work->valPtrDC1, 0, 0x44);
work->dcTblFlag[1] = 1;
memset(hufftable, 0, sizeof(work->huffDecTblDC1));
memset(work->maxCodeDC1, 0, sizeof(work->maxCodeDC1));
memset(work->valPtrDC1, 0, sizeof(work->valPtrDC1));
break;
}
}
@@ -163,10 +163,10 @@ void TMCJPEGDEC_set_HuffmanTable(TMCHuffParam* tbl, s32 tblType, s32 tblID, TMCJ
tbl->huffTable = hufftable;
tbl->maxCode = maxcode;
tbl->valptr = valptr;
work->huffTblInitFlag[2] = 1;
memset(hufftable, 0, 0x400);
memset(work->maxCodeAC0, 0, 0x100);
memset(work->valPtrAC0, 0, 0x44);
work->acTblFlag[0] = 1;
memset(hufftable, 0, sizeof(work->huffDecTblAC0));
memset(work->maxCodeAC0, 0, sizeof(work->maxCodeAC0));
memset(work->valPtrAC0, 0, sizeof(work->valPtrAC0));
break;
}
case 1: {
@@ -176,10 +176,10 @@ void TMCJPEGDEC_set_HuffmanTable(TMCHuffParam* tbl, s32 tblType, s32 tblID, TMCJ
tbl->huffTable = hufftable;
tbl->maxCode = maxcode;
tbl->valptr = valptr;
work->huffTblInitFlag[3] = 1;
memset(hufftable, 0, 0x400);
memset(work->maxCodeAC1, 0, 0x100);
memset(work->valPtrAC1, 0, 0x44);
work->acTblFlag[1] = 1;
memset(hufftable, 0, sizeof(work->huffDecTblAC1));
memset(work->maxCodeAC1, 0, sizeof(work->maxCodeAC1));
memset(work->valPtrAC1, 0, sizeof(work->valPtrAC1));
break;
}
}

View File

@@ -33,9 +33,16 @@ enum TMCExifTag {
TMC_EXIF_TAG_PIXEL_Y_DIMENSION = 0xA003,
};
typedef struct {
u8 tag[2];
u8 type[2];
u8 count[4];
u8 value[4];
} TMCExifEntry;
static s32 TMCJPEGDEC_exif_parse(const u8* data, u32 size, TMCCJPEGDecExifData* pInfo);
static void TMCJPEGDEC_IFD0_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder, u8* entry);
static void TMCJPEGDEC_IFD1_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder, const u8* entry);
static void TMCJPEGDEC_IFD0_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder, TMCExifEntry* entry);
static void TMCJPEGDEC_IFD1_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder, const TMCExifEntry* entry);
static s32 TMCJPEGDEC_ThumbnailCheck(TMCCJPEGDecInitParam* param, TMCCJPEGDecExifInfo* info, u32 totalSize);
static u16 readU16(const u8* p, u16 byteOrder) {
@@ -316,8 +323,8 @@ static s32 TMCJPEGDEC_exif_parse(const u8* entries, u32 size, TMCCJPEGDecExifDat
return -161;
}
for (index = 0; index < count; index++) {
TMCJPEGDEC_IFD0_tag_parse(pInfo, byteOrder, (u8*)entries);
entries += 12;
TMCJPEGDEC_IFD0_tag_parse(pInfo, byteOrder, (TMCExifEntry*)entries);
entries += sizeof(TMCExifEntry);
}
remaining -= (s32)count * 12;
if (remaining < 4) {
@@ -344,8 +351,8 @@ static s32 TMCJPEGDEC_exif_parse(const u8* entries, u32 size, TMCCJPEGDecExifDat
return -161;
}
for (ifd1Index = 0; ifd1Index < ifd1Count; ifd1Index++) {
TMCJPEGDEC_IFD1_tag_parse(pInfo, byteOrder, ifd1Entries);
ifd1Entries += 12;
TMCJPEGDEC_IFD1_tag_parse(pInfo, byteOrder, (const TMCExifEntry*)ifd1Entries);
ifd1Entries += sizeof(TMCExifEntry);
}
}
ifdOffset = pInfo->nextIfdOffset;
@@ -365,19 +372,19 @@ static s32 TMCJPEGDEC_exif_parse(const u8* entries, u32 size, TMCCJPEGDecExifDat
return -161;
}
for (exifIndex = 0; exifIndex < exifCount; exifIndex++) {
TMCJPEGDEC_IFD0_tag_parse(pInfo, byteOrder, (u8*)exifEntries);
exifEntries += 12;
TMCJPEGDEC_IFD0_tag_parse(pInfo, byteOrder, (TMCExifEntry*)exifEntries);
exifEntries += sizeof(TMCExifEntry);
}
}
return 0;
}
static void TMCJPEGDEC_IFD0_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder, u8* entry) {
static void TMCJPEGDEC_IFD0_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder, TMCExifEntry* entry) {
s32 tag;
u32 type;
tag = readExifU16(entry, byteOrder);
type = readExifU16(entry + 2, byteOrder);
tag = readExifU16(entry->tag, byteOrder);
type = readExifU16(entry->type, byteOrder);
switch (tag) {
case TMC_EXIF_TAG_COMPRESSION:
@@ -387,11 +394,11 @@ static void TMCJPEGDEC_IFD0_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder,
break;
}
case TMC_EXIF_TAG_ORIENTATION: {
pInfo->orientation = readU16(entry + 8, byteOrder);
pInfo->orientation = readU16(entry->value, byteOrder);
return;
}
case TMC_EXIF_TAG_X_RESOLUTION: {
u32 offset = readU32(entry + 8, byteOrder);
u32 offset = readU32(entry->value, byteOrder);
const u8* p = pInfo->thumbnailData + offset;
if (pInfo->thumbnailData > p) {
return;
@@ -400,7 +407,7 @@ static void TMCJPEGDEC_IFD0_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder,
return;
}
pInfo->xResNum = readU32(p, byteOrder);
p = pInfo->thumbnailData + (offset + 4);
p = pInfo->thumbnailData + (offset + sizeof(u32));
if (pInfo->thumbnailData > p) {
return;
}
@@ -411,7 +418,7 @@ static void TMCJPEGDEC_IFD0_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder,
return;
}
case TMC_EXIF_TAG_Y_RESOLUTION: {
u32 offset = readU32(entry + 8, byteOrder);
u32 offset = readU32(entry->value, byteOrder);
const u8* p = pInfo->thumbnailData + offset;
if (pInfo->thumbnailData > p) {
return;
@@ -420,7 +427,7 @@ static void TMCJPEGDEC_IFD0_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder,
return;
}
pInfo->yResNum = readU32(p, byteOrder);
p = pInfo->thumbnailData + (offset + 4);
p = pInfo->thumbnailData + (offset + sizeof(u32));
if (pInfo->thumbnailData > p) {
return;
}
@@ -431,11 +438,11 @@ static void TMCJPEGDEC_IFD0_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder,
return;
}
case TMC_EXIF_TAG_RESOLUTION_UNIT: {
pInfo->resUnit = readU16(entry + 8, byteOrder);
pInfo->resUnit = readU16(entry->value, byteOrder);
return;
}
case TMC_EXIF_TAG_TRANSFER_FUNCTION: {
u32 offset = readU32(entry + 8, byteOrder);
u32 offset = readU32(entry->value, byteOrder);
u32 channel;
u32 index;
for (channel = 0; channel < 3; channel++) {
@@ -444,87 +451,87 @@ static void TMCJPEGDEC_IFD0_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder,
if (pInfo->thumbnailData > p) {
break;
}
if (p > pInfo->dataEnd - 2) {
if (p > pInfo->dataEnd - sizeof(u16)) {
break;
}
pInfo->transferFunc[channel][index] = readU16(p, byteOrder);
offset += 2;
offset += sizeof(u16);
}
}
return;
}
case TMC_EXIF_TAG_DATE_TIME: {
u32 offset = readU32(entry + 8, byteOrder);
u32 offset = readU32(entry->value, byteOrder);
const u8* p = pInfo->thumbnailData + offset;
if (pInfo->thumbnailData > p) {
return;
}
if (p > pInfo->dataEnd - 20) {
if (p > pInfo->dataEnd - sizeof(pInfo->dateTime)) {
return;
}
{
u32 index;
for (index = 0; index < 20; index++) {
for (index = 0; index < sizeof(pInfo->dateTime); index++) {
pInfo->dateTime[index] = p[index];
}
}
return;
}
case TMC_EXIF_TAG_YCBCR_POSITIONING: {
pInfo->yCbCrPos = readU16(entry + 8, byteOrder);
pInfo->yCbCrPos = readU16(entry->value, byteOrder);
return;
}
case TMC_EXIF_TAG_EXIF_IFD: {
pInfo->nextIfdOffset = readU32(entry + 8, byteOrder);
pInfo->nextIfdOffset = readU32(entry->value, byteOrder);
return;
}
case TMC_EXIF_TAG_EXIF_VERSION: {
pInfo->exifVer[0] = entry[8];
pInfo->exifVer[1] = entry[9];
pInfo->exifVer[2] = entry[10];
pInfo->exifVer[3] = entry[11];
pInfo->exifVer[0] = entry->value[0];
pInfo->exifVer[1] = entry->value[1];
pInfo->exifVer[2] = entry->value[2];
pInfo->exifVer[3] = entry->value[3];
return;
}
case TMC_EXIF_TAG_COMPONENTS_CONFIGURATION: {
pInfo->flashVer[0] = entry[8];
pInfo->flashVer[1] = entry[9];
pInfo->flashVer[2] = entry[10];
pInfo->flashVer[3] = entry[11];
pInfo->flashVer[0] = entry->value[0];
pInfo->flashVer[1] = entry->value[1];
pInfo->flashVer[2] = entry->value[2];
pInfo->flashVer[3] = entry->value[3];
return;
}
case TMC_EXIF_TAG_FLASHPIX_VERSION: {
pInfo->flashPixVer[0] = entry[8];
pInfo->flashPixVer[1] = entry[9];
pInfo->flashPixVer[2] = entry[10];
pInfo->flashPixVer[3] = entry[11];
pInfo->flashPixVer[0] = entry->value[0];
pInfo->flashPixVer[1] = entry->value[1];
pInfo->flashPixVer[2] = entry->value[2];
pInfo->flashPixVer[3] = entry->value[3];
return;
}
case TMC_EXIF_TAG_COLOR_SPACE: {
pInfo->colorSpace = readU16(entry + 8, byteOrder);
pInfo->colorSpace = readU16(entry->value, byteOrder);
return;
}
case TMC_EXIF_TAG_PIXEL_X_DIMENSION: {
if (type == TMC_EXIF_TYPE_SHORT) {
pInfo->pixelXDim = readU16(entry + 8, byteOrder);
pInfo->pixelXDim = readU16(entry->value, byteOrder);
} else if (type == TMC_EXIF_TYPE_LONG) {
pInfo->pixelXDim = readU32(entry + 8, byteOrder);
pInfo->pixelXDim = readU32(entry->value, byteOrder);
}
return;
}
case TMC_EXIF_TAG_PIXEL_Y_DIMENSION: {
if (type == TMC_EXIF_TYPE_SHORT) {
pInfo->pixelYDim = readU16(entry + 8, byteOrder);
pInfo->pixelYDim = readU16(entry->value, byteOrder);
} else if (type == TMC_EXIF_TYPE_LONG) {
pInfo->pixelYDim = readU32(entry + 8, byteOrder);
pInfo->pixelYDim = readU32(entry->value, byteOrder);
}
return;
}
}
}
static void TMCJPEGDEC_IFD1_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder, const u8* entry) {
s32 tag = readU16(entry, byteOrder);
static void TMCJPEGDEC_IFD1_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder, const TMCExifEntry* entry) {
s32 tag = readU16(entry->tag, byteOrder);
switch (tag) {
case TMC_EXIF_TAG_DATE_TIME:
@@ -545,7 +552,7 @@ static void TMCJPEGDEC_IFD1_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder,
case TMC_EXIF_TAG_X_RESOLUTION: {
u32 offset;
const u8* p;
offset = readU32(entry + 8, byteOrder);
offset = readU32(entry->value, byteOrder);
p = pInfo->thumbnailData + offset;
if (pInfo->thumbnailData > p) {
return;
@@ -554,7 +561,7 @@ static void TMCJPEGDEC_IFD1_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder,
return;
}
pInfo->xResNumIfd1 = readU32(p, byteOrder);
p = pInfo->thumbnailData + (offset + 4);
p = pInfo->thumbnailData + (offset + sizeof(u32));
if (pInfo->thumbnailData > p) {
return;
}
@@ -567,7 +574,7 @@ static void TMCJPEGDEC_IFD1_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder,
case TMC_EXIF_TAG_Y_RESOLUTION: {
u32 offset;
const u8* p;
offset = readU32(entry + 8, byteOrder);
offset = readU32(entry->value, byteOrder);
p = pInfo->thumbnailData + offset;
if (pInfo->thumbnailData > p) {
return;
@@ -576,7 +583,7 @@ static void TMCJPEGDEC_IFD1_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder,
return;
}
pInfo->planarConfigIfd1 = readU32(p, byteOrder);
p = pInfo->thumbnailData + (offset + 4);
p = pInfo->thumbnailData + (offset + sizeof(u32));
if (pInfo->thumbnailData > p) {
return;
}
@@ -587,19 +594,19 @@ static void TMCJPEGDEC_IFD1_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder,
return;
}
case TMC_EXIF_TAG_RESOLUTION_UNIT: {
pInfo->resUnitIfd1 = readU16(entry + 8, byteOrder);
pInfo->resUnitIfd1 = readU16(entry->value, byteOrder);
return;
}
case TMC_EXIF_TAG_COMPRESSION: {
pInfo->compressionIfd1 = readU16(entry + 8, byteOrder);
pInfo->compressionIfd1 = readU16(entry->value, byteOrder);
return;
}
case TMC_EXIF_TAG_JPEG_INTERCHANGE_FORMAT: {
pInfo->thumbnailOffset = readU32(entry + 8, byteOrder);
pInfo->thumbnailOffset = readU32(entry->value, byteOrder);
return;
}
case TMC_EXIF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH: {
pInfo->thumbnailLength = readU32(entry + 8, byteOrder);
pInfo->thumbnailLength = readU32(entry->value, byteOrder);
return;
}
}

View File

@@ -18,7 +18,7 @@ static s32 TMCJPEGDEC_parse_sof(TMCCJPEGDecWork* work);
static s32 TMCJPEGDEC_parse_sos(TMCCJPEGDecWork* work);
s32 TMCJPEGDEC_decompmcu(u32 maxMCU, u32 mcuCount, TMCCJPEGDecWork* work, void* buf) {
u8* compMapBase;
TMCFrameComponents* compMapBase;
u8* compMapPtr;
u32* mcuDataInfo;
@@ -34,7 +34,7 @@ s32 TMCJPEGDEC_decompmcu(u32 maxMCU, u32 mcuCount, TMCCJPEGDecWork* work, void*
u16 pitch;
u8* frameInfo;
u8* scaleInfo;
TMCJpegTableInfo* scaleInfo;
u8** convRowPtrs;
TMCCJPEGDecState* state;
@@ -44,12 +44,12 @@ s32 TMCJPEGDEC_decompmcu(u32 maxMCU, u32 mcuCount, TMCCJPEGDecWork* work, void*
TMCDecodeFunc* decodeFunc;
state = work->pState;
compMapBase = work->compMap;
compMapBase = &work->components;
frameInfo = (u8*)&work->frameWidth;
compMapPtr = compMapBase;
scaleInfo = &work->scaleFlag;
compMapPtr = compMapBase->map;
scaleInfo = &work->tables;
convRowPtrs = work->pConvRowPtrs;
mcuDataInfo = (u32*)(compMapBase + 4);
mcuDataInfo = compMapBase->dcPredict;
mcuIdx = 0;
decodeFunc = work->decodePtr;
@@ -60,15 +60,15 @@ s32 TMCJPEGDEC_decompmcu(u32 maxMCU, u32 mcuCount, TMCCJPEGDecWork* work, void*
while (mcuIdx < ((TMCJpegFrameInfo*)frameInfo)->scanCompCount) {
compIdx = *compMapPtr;
entTblBase = scaleInfo + ((u32) * (compMapBase + compIdx + 0x18) << 8);
TMCJPEGDEC_set_entropytbl((TMCCJPEGDecWork*)scaleInfo, *(compMapBase + compIdx + 0x1c), *(compMapBase + compIdx + 0x20));
entTblBase = (u8*)scaleInfo->coefficients[compMapBase->quantTable[compIdx]];
TMCJPEGDEC_set_entropytbl(scaleInfo, compMapBase->dcTable[compIdx], compMapBase->acTable[compIdx]);
curBlockInfo = convRowPtrs;
specificConvRowPtr = convRowPtrs + compIdx;
blockCountPtr = frameInfo + mcuIdx;
blockIdx = 0;
while (blockIdx < (s32) * (blockCountPtr + 0x1c)) {
while (blockIdx < *(blockCountPtr + 0x1c)) {
s32 stackBlock[64];
s32 ret;
@@ -113,7 +113,7 @@ static inline void initZigzag(TMCCJPEGDecWork* work) {
work->restartInterval = 0;
work->scanCount = 0;
for (i = 0; i < 64; i++) {
work->zigzagData[i] = *zigzag++ << 2;
work->tables.zigzagData[i] = *zigzag++ << 2;
}
}
@@ -199,10 +199,10 @@ s32 TMCJPEGDEC_scanstart(TMCCJPEGDecWork* work) {
return r;
}
work->dcPredict[0] = 0;
work->dcPredict[1] = 0;
work->dcPredict[2] = 0;
work->dcPredict[3] = 0;
work->components.dcPredict[0] = 0;
work->components.dcPredict[1] = 0;
work->components.dcPredict[2] = 0;
work->components.dcPredict[3] = 0;
work->restartCnt = 0;
r = TMCJPEGDEC_init_buff(work);
if (r < 0) {
@@ -230,11 +230,11 @@ s32 TMCJPEGDEC_scan_varinit(TMCCJPEGDecWork* work) {
u8 component;
hSamp = p->maxHSamp;
component = work->compMap[0];
component = work->components.map[0];
qTblH = p->hSampFactor[component];
hMul8 = hSamp * 8;
p->mcuXCount = (u8)(hMul8 / qTblH);
p->mcuXRem = (u8)(p->maxVSamp * 8 / p->vSampFactor[component]);
p->mcuXCount = hMul8 / qTblH;
p->mcuXRem = p->maxVSamp * 8 / p->vSampFactor[component];
p->mcuYCount = p->frameWidth / p->mcuXCount;
p->mcuXCount2 = p->frameHeight / p->mcuXRem;
} else {
@@ -255,15 +255,15 @@ s32 TMCJPEGDEC_scan_varinit(TMCCJPEGDecWork* work) {
p->remX = remX;
p->remY = remY;
p->mcuYCount = p->mcuYCount + ((u8)remX != 0 ? 1 : 0);
p->mcuXCount2 = p->mcuXCount2 + ((u8)remY != 0 ? 1 : 0);
p->mcuTotal = (u32)p->mcuYCount * (u32)p->mcuXCount2;
p->mcuYCount = p->mcuYCount + ((u8)remX != 0);
p->mcuXCount2 = p->mcuXCount2 + ((u8)remY != 0);
p->mcuTotal = (u32)p->mcuYCount * p->mcuXCount2;
for (idx = 0; idx < p->scanCompCount; idx++) {
u8 compId;
u32 blocks;
compId = work->compMap[idx];
compId = work->components.map[idx];
if (p->scanCompCount == 1) {
blocks = 1;
} else {
@@ -295,10 +295,10 @@ static inline void restartMcuPosition(TMCCJPEGDecWork* work, TMCCJPEGDecState* s
blockCount = mcuCount / stepY;
column = maxMCU / stepX;
position = blockCount * pitch + column + 1;
work->dcPredict[0] = 0;
work->dcPredict[1] = 0;
work->dcPredict[2] = 0;
work->dcPredict[3] = 0;
work->components.dcPredict[0] = 0;
work->components.dcPredict[1] = 0;
work->components.dcPredict[2] = 0;
work->components.dcPredict[3] = 0;
work->restartCnt = 0;
row = position / pitch;
remainder = position - row * pitch;
@@ -516,7 +516,7 @@ static s32 TMCJPEGDEC_parse_dht(s32 first, TMCCJPEGDecWork* work) {
s32 r;
TMCHuffParam tblSet;
scaleInfo = (TMCJpegTableInfo*)&work->scaleFlag;
scaleInfo = &work->tables;
memset(countBuf, 0, sizeof(countBuf));
@@ -592,8 +592,7 @@ static s32 TMCJPEGDEC_parse_dqt(TMCCJPEGDecWork* work) {
u32 data[64];
} CopyBlock64;
typedef struct { u32 coefficients[4][64]; } QuantizationTables;
QuantizationTables* scaleInfo;
TMCJpegTableInfo* scaleInfo;
u32 tblCopy[64];
u32* d;
u16 len;
@@ -602,7 +601,7 @@ static s32 TMCJPEGDEC_parse_dqt(TMCCJPEGDecWork* work) {
d = tblCopy;
*(CopyBlock64*)d = *(CopyBlock64*)scJpegAanScale;
scaleInfo = (QuantizationTables*)&work->scaleFlag;
scaleInfo = &work->tables;
r = TMCJPEGDEC_get_wbyte(&len, work);
if (r < 0) {
@@ -628,7 +627,7 @@ static s32 TMCJPEGDEC_parse_dqt(TMCCJPEGDecWork* work) {
return -0x41;
}
((TMCJpegTableInfo*)scaleInfo)->quantTblFlag[qtInfo] = 1;
scaleInfo->quantTblFlag[qtInfo] = 1;
zigPtr = TMCJPEGDEC_Zigzag_data;
for (zzIdx = 0; zzIdx < 64; zzIdx++) {
@@ -643,7 +642,7 @@ static s32 TMCJPEGDEC_parse_dqt(TMCCJPEGDecWork* work) {
return r;
}
val = (u32)byte * tblCopy[zz];
val = byte * tblCopy[zz];
scaleInfo->coefficients[qtInfo][zz] = val;
if (val == 0) {
return -0x41;
@@ -689,19 +688,10 @@ static inline s32 storeSampling(TMCJpegFrameInfo* frame, s32 index, u8 packed) {
return horizontal;
}
typedef struct {
u8 map[4];
u32 dcPredict[4];
u8 id[4];
u8 quantTable[4];
u8 dcTable[4];
u8 acTable[4];
} TMCFrameComponents;
static inline s32 validateFrameComponents(TMCCJPEGDecWork* work) {
s32 idx;
TMCJpegFrameInfo* frameInfo = (TMCJpegFrameInfo*)&work->frameWidth;
TMCFrameComponents* components = (TMCFrameComponents*)work->compMap;
TMCFrameComponents* components = &work->components;
for (idx = 0; idx < frameInfo->compCount; idx++) {
if (frameInfo->hSampFactor[idx] < 1 || frameInfo->hSampFactor[idx] > 4) {
return TMCC_ERROR_HEADER;
@@ -720,7 +710,7 @@ static s32 TMCJPEGDEC_parse_sof(TMCCJPEGDecWork* work) {
s32 maxHSamp;
s32 maxVSamp;
TMCJpegFrameInfo* frameInfo = (TMCJpegFrameInfo*)&work->frameWidth;
TMCFrameComponents* components = (TMCFrameComponents*)work->compMap;
TMCFrameComponents* components = &work->components;
u16 value;
u8 byte;
s32 r;
@@ -823,18 +813,10 @@ nextSample:
}
static s32 TMCJPEGDEC_parse_sos(TMCCJPEGDecWork* work) {
typedef struct {
u8 map[4];
u32 dcPredict[4];
u8 id[4];
u8 quantTable[4];
u8 dcTable[4];
u8 acTable[4];
} TMCComponentInfo;
s32 idx;
TMCComponentInfo* components;
TMCFrameComponents* components;
TMCJpegTableInfo* scalePtr;
TMCComponentInfo* mapPtr;
TMCFrameComponents* mapPtr;
s32 dcTbl;
s32 acTbl;
@@ -845,8 +827,8 @@ static s32 TMCJPEGDEC_parse_sos(TMCCJPEGDecWork* work) {
s32 ci;
u8 scanByte;
components = (TMCComponentInfo*)work->compMap;
scalePtr = (TMCJpegTableInfo*)&work->scaleFlag;
components = &work->components;
scalePtr = &work->tables;
r = TMCJPEGDEC_get_wbyte(&len, work);
if (r < 0) {
@@ -876,7 +858,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 = (TMCComponentInfo*)&components->map[idx];
mapPtr = (TMCFrameComponents*)&components->map[idx];
goto componentFound;
}
}
@@ -1125,10 +1107,10 @@ s32 TMCJPEGDEC_err_restart(TMCCJPEGDecWork* work) {
pitch = state->maxX;
val = work->mcuPos;
work->dcPredict[0] = 0;
work->dcPredict[1] = 0;
work->dcPredict[2] = 0;
work->dcPredict[3] = 0;
work->components.dcPredict[0] = 0;
work->components.dcPredict[1] = 0;
work->components.dcPredict[2] = 0;
work->components.dcPredict[3] = 0;
work->restartCnt = 0;
next = (u8)(val & 0xFF) * (s32)pitch + (val >> 16) + (s32)(u8)(rstDiff * interval);
@@ -1150,18 +1132,18 @@ s32 TMCJPEGDEC_err_restart(TMCCJPEGDecWork* work) {
}
#endif
void TMCJPEGDEC_set_entropytbl(TMCCJPEGDecWork* work, s32 idx, u8 data) {
void TMCJPEGDEC_set_entropytbl(TMCJpegTableInfo* work, s32 idx, u8 data) {
switch (idx) {
case 0: {
work->pDCACPtrs[0] = &work->zigzagData[8];
work->pDCACPtrs[2] = work->maxCodeDC0;
work->pDCACPtrs[1] = work->valPtrDC0;
work->pDCFast = work->huffDecTblDC0;
work->pDCHuffSym = work->maxCodeDC0;
work->pDCHuffTbl = work->valPtrDC0;
break;
}
case 1: {
work->pDCACPtrs[0] = work->huffDecTblDC1;
work->pDCACPtrs[2] = work->maxCodeDC1;
work->pDCACPtrs[1] = work->valPtrDC1;
work->pDCFast = work->huffDecTblDC1;
work->pDCHuffSym = work->maxCodeDC1;
work->pDCHuffTbl = work->valPtrDC1;
break;
}
}
@@ -1170,14 +1152,14 @@ void TMCJPEGDEC_set_entropytbl(TMCCJPEGDecWork* work, s32 idx, u8 data) {
goto ac1;
}
if ((s32)data < 1 && (s32)data >= 0) {
work->pDCACPtrs[4] = work->huffDecTblAC0;
*(void**)work->zigzagData = work->maxCodeAC0;
work->pDCACPtrs[5] = work->valPtrAC0;
work->pACFast = work->huffDecTblAC0;
work->pACHuffSym = work->maxCodeAC0;
work->pACHuffTbl = work->valPtrAC0;
}
return;
ac1:
work->pDCACPtrs[4] = work->huffDecTblAC1;
*(void**)work->zigzagData = work->maxCodeAC1;
work->pDCACPtrs[5] = work->valPtrAC1;
work->pACFast = work->huffDecTblAC1;
work->pACHuffSym = work->maxCodeAC1;
work->pACHuffTbl = work->valPtrAC1;
}

View File

@@ -10,7 +10,7 @@ static u8 clampU8(s32 v) {
}
static s8 clampS8(s32 v) {
return (v < 128 && v > -129) ? (s8)v : (v > 0) ? 127 : -128;
return (v < 128 && v > -129) ? v : (v > 0) ? 127 : -128;
}
void TMCJPEGDEC_IdctBlock4x4(s32* block, u8* conv_row_ptr, u16 pitch, s32 zigzag) {

View File

@@ -38,7 +38,7 @@ s32 TMCJPEGDEC_decode_iquant_rc(s32* block, u8* conv_row_ptr, u32* dc_predict_ro
s32* conv_row;
conv_row = (s32*)conv_row_ptr;
dcf = work->pDCFast;
dcf = work->tables.pDCFast;
if (work->bitCount <= 8) {
r = TMCJPEGDEC_load_buff(work);
if (r < 0) {
@@ -54,7 +54,7 @@ s32 TMCJPEGDEC_decode_iquant_rc(s32* block, u8* conv_row_ptr, u32* dc_predict_ro
work->bitCount -= val;
val = tmp;
} else {
val = TMCJPEGDEC_vl_decode_rc(work->pDCHuffTbl, work->pDCHuffSym, work);
val = TMCJPEGDEC_vl_decode_rc(work->tables.pDCHuffTbl, work->tables.pDCHuffSym, work);
if (val < 0) {
return val;
}
@@ -73,9 +73,9 @@ s32 TMCJPEGDEC_decode_iquant_rc(s32* block, u8* conv_row_ptr, u32* dc_predict_ro
*block = dc_predict_row_ptr[0] * conv_row[0];
ac_fast = work->pACFast;
ac_vl = work->pACHuffTbl;
ac_sym = work->pACHuffSym;
ac_fast = work->tables.pACFast;
ac_vl = work->tables.pACHuffTbl;
ac_sym = work->tables.pACHuffSym;
blk_size = work->blockSize;
blk_mul = work->blockSizeMul;

View File

@@ -0,0 +1,291 @@
# rx48 expression cleanup
Base: `7c64b0a1f94be5770d04288c93d0c668f43d4250`, branch `agent/w1005/rx48`.
Scope: TMC_JPEG except texturecvtr and buffer/idct_block_var.c. Excluded files may receive identifier renames only.
Acceptance: preserve complete source object bytes, every objdiff measure and per-function score, identical pools, and the full 43U DOL SHA1 `26116613f624061ba99c8d1a299aaa6efa85670d`. This expression-cleanup assignment supersedes the generic requirement to gain exact matches.
Fresh baseline: 1027 source objects saved under `/tmp/rx48-cleanup`; all 11 owned pools identical. Owned totals are 47/49 exact functions, 17724/20616 matched code bytes, and 632/632 matched data bytes. The two pre-existing EXIF mismatches must stay unchanged. Pre-existing untracked g2 logs are outside this change.
Prior evidence: `rx38.cleanup.md` records rejected direct-work member substitutions, public state field renaming, and control-flow/cast changes. This round tests typed component/table views and remaining independent expressions. Public init fields `unk_0x24` and `unk_0x2C` have out-of-scope users in `src/utility/iplJpegDecoder.cpp`; retain them. Unknown storage gets a semantic name only when uses prove its role.
## Trials
- KEEP component view: move existing TMCFrameComponents definition into internal header: all checked object bytes identical. Trial 001.
- KEEP decompmcu: address DC predictors through existing component view: all checked object bytes identical. Trial 002.
- KEEP decompmcu: quantization selector through component view: all checked object bytes identical. Trial 003.
- KEEP decompmcu: entropy selectors through component view: all checked object bytes identical. Trial 004.
- KEEP decompmcu: component base is a typed pointer throughout: all checked object bytes identical. Trial 005.
- REVERT decompmcu: block-count cursor starts at the frame member: jdec_main: TMCJPEGDEC_decompmcu. Trial 006.
- REVERT typed table layout: replace shifted work casts and overlapping placeholders with quantization and Huffman members: compile failure. Trial 007.
- KEEP typed table layout: replace shifted work casts and overlapping placeholders with quantization and Huffman members: all checked object bytes identical. Trial 008.
- KEEP internal header: name four existing alignment gaps: all checked object bytes identical. Trial 009.
- REVERT decompmcu: preserve typed frame base and use its block-count array: jdec_main: TMCJPEGDEC_decompmcu. Trial 010.
- REVERT decompmcu: direct block-count array instead of byte cursor: jdec_main: TMCJPEGDEC_decompmcu. Trial 011.
- REVERT decompmcu: cursor based on existing work block-count field: jdec_main: TMCJPEGDEC_decompmcu. Trial 012.
- KEEP work components: use a real nested member for all component metadata: all checked object bytes identical. Trial 013.
- KEEP scan parser: share the component type instead of a local duplicate: all checked object bytes identical. Trial 014.
- KEEP public EXIF header: name three proven alignment gaps: all checked object bytes identical. Trial 015.
- KEEP public EXIF info: name alignment after converterType: all checked object bytes identical. Trial 016.
- REVERT decompmcu: const typed frame while preserving byte cursor: jdec_main: TMCJPEGDEC_decompmcu. Trial 017.
- KEEP EXIF decoder state: type fields actually accessed by Setsize, converters and restart handling: all checked object bytes identical. Trial 018.
- REVERT public decoder state: name trailing alignment gap: iplNandSDWorker; iplNandSDCardManager. Trial 019.
## Layout evidence
The old table declaration contained shifted aliases. The table helpers received `work + 0x58` cast as a complete work object. Their apparent `zigzagData + 8`, `huffDecTblDC1`, and `valPtrDC0` accesses therefore addressed table-relative offsets `0x460`, `0x860`, and `0x1460`. The replacement defines those arrays at the actual helper addresses and passes `TMCJpegTableInfo*` throughout. Quantization coefficients occupy four 256-byte tables. Two untouched words retain reserved names because this source never accesses them.
EXIF state fields are proven by the existing `work->pState = (TMCCJPEGDecState*)pInfo` assignment and calls into Setsize, converters, and restart handling. Their offsets equal the public decoder-state members. Four opaque public ranges and the public decoder-state debug layout remain constrained.
Target MWCC compile-time assertions pass:
```text
MWCC layout PASS: 70 sizeof/offsetof assertions
sizeof(TMCCJPEGDecWork) = 0x19e8
sizeof(TMCFrameComponents) = 0x24
sizeof(TMCJpegTableInfo) = 0x1798
sizeof(TMCJpegFrameInfo) = 0x30
sizeof(TMCCJPEGDecInitParam) = 0x30
sizeof(TMCCJPEGDecState) = 0x6d4
sizeof(TMCCJPEGDecExifInfo) = 0x6d4
sizeof(TMCCJPEGDecExifData) = 0x67c
offsetof(TMCCJPEGDecWork, components) = 0x2c
offsetof(TMCCJPEGDecWork, components.dcPredict) = 0x30
offsetof(TMCCJPEGDecWork, components.id) = 0x40
offsetof(TMCCJPEGDecWork, components.quantTable) = 0x44
offsetof(TMCCJPEGDecWork, components.dcTable) = 0x48
offsetof(TMCCJPEGDecWork, components.acTable) = 0x4c
offsetof(TMCCJPEGDecWork, tables) = 0x58
offsetof(TMCCJPEGDecWork, tables.zigzagData) = 0x458
offsetof(TMCCJPEGDecWork, tables.pDCFast) = 0x498
offsetof(TMCCJPEGDecWork, tables.pDCHuffTbl) = 0x49c
offsetof(TMCCJPEGDecWork, tables.pDCHuffSym) = 0x4a0
offsetof(TMCCJPEGDecWork, tables.reservedDC) = 0x4a4
offsetof(TMCCJPEGDecWork, tables.pACFast) = 0x4a8
offsetof(TMCCJPEGDecWork, tables.pACHuffTbl) = 0x4ac
offsetof(TMCCJPEGDecWork, tables.pACHuffSym) = 0x4b0
offsetof(TMCCJPEGDecWork, tables.reservedAC) = 0x4b4
offsetof(TMCCJPEGDecWork, tables.quantTblFlag) = 0x17e8
offsetof(TMCCJPEGDecWork, tables.dcTblFlag) = 0x17ec
offsetof(TMCCJPEGDecWork, tables.acTblFlag) = 0x17ee
offsetof(TMCCJPEGDecWork, frameWidth) = 0x17f0
offsetof(TMCCJPEGDecWork, scanCompCount) = 0x180b
offsetof(TMCCJPEGDecWork, blockCount) = 0x180c
offsetof(TMCCJPEGDecWork, restartInterval) = 0x181a
offsetof(TMCCJPEGDecWork, idctPtr) = 0x1820
offsetof(TMCCJPEGDecWork, pConvRowPtrs) = 0x183c
offsetof(TMCCJPEGDecWork, convBuf) = 0x1858
offsetof(TMCCJPEGDecWork, pitch) = 0x19de
offsetof(TMCCJPEGDecWork, pState) = 0x19e4
offsetof(TMCJpegTableInfo, huffDecTblDC0) = 0x460
offsetof(TMCJpegTableInfo, huffDecTblDC1) = 0x860
offsetof(TMCJpegTableInfo, huffDecTblAC0) = 0xc60
offsetof(TMCJpegTableInfo, huffDecTblAC1) = 0x1060
offsetof(TMCJpegTableInfo, valPtrDC0) = 0x1460
offsetof(TMCJpegTableInfo, valPtrDC1) = 0x14a4
offsetof(TMCJpegTableInfo, valPtrAC0) = 0x14e8
offsetof(TMCJpegTableInfo, valPtrAC1) = 0x152c
offsetof(TMCJpegTableInfo, maxCodeDC0) = 0x1570
offsetof(TMCJpegTableInfo, maxCodeDC1) = 0x1580
offsetof(TMCJpegTableInfo, maxCodeAC0) = 0x1590
offsetof(TMCJpegTableInfo, maxCodeAC1) = 0x1690
offsetof(TMCCJPEGDecExifInfo, posX) - offsetof(TMCCJPEGDecState, posX) = 0x0
offsetof(TMCCJPEGDecExifInfo, posY) - offsetof(TMCCJPEGDecState, posY) = 0x0
offsetof(TMCCJPEGDecExifInfo, position) - offsetof(TMCCJPEGDecState, position) = 0x0
offsetof(TMCCJPEGDecExifInfo, maxX) - offsetof(TMCCJPEGDecState, maxX) = 0x0
offsetof(TMCCJPEGDecExifInfo, maxY) - offsetof(TMCCJPEGDecState, maxY) = 0x0
offsetof(TMCCJPEGDecExifInfo, stepX) - offsetof(TMCCJPEGDecState, stepX) = 0x0
offsetof(TMCCJPEGDecExifInfo, stepY) - offsetof(TMCCJPEGDecState, stepY) = 0x0
offsetof(TMCCJPEGDecExifInfo, stepXExt) - offsetof(TMCCJPEGDecState, stepXExt) = 0x0
offsetof(TMCCJPEGDecExifInfo, stepYExt) - offsetof(TMCCJPEGDecState, stepYExt) = 0x0
offsetof(TMCCJPEGDecExifInfo, dataSizeX) - offsetof(TMCCJPEGDecState, dataSizeX) = 0x0
offsetof(TMCCJPEGDecExifInfo, dataSizeY) - offsetof(TMCCJPEGDecState, dataSizeY) = 0x0
offsetof(TMCCJPEGDecExifInfo, componentCount) - offsetof(TMCCJPEGDecState, componentCount) = 0x0
offsetof(TMCCJPEGDecExifInfo, jpegWidth) - offsetof(TMCCJPEGDecState, jpegWidth) = 0x0
offsetof(TMCCJPEGDecExifInfo, jpegHeight) - offsetof(TMCCJPEGDecState, jpegHeight) = 0x0
offsetof(TMCCJPEGDecExifInfo, outputWidth) - offsetof(TMCCJPEGDecState, outputWidth) = 0x0
offsetof(TMCCJPEGDecExifInfo, outputHeight) - offsetof(TMCCJPEGDecState, outputHeight) = 0x0
offsetof(TMCCJPEGDecExifInfo, convWidth) - offsetof(TMCCJPEGDecState, convWidth) = 0x0
offsetof(TMCCJPEGDecExifInfo, convHeight) - offsetof(TMCCJPEGDecState, convHeight) = 0x0
offsetof(TMCCJPEGDecExifInfo, pTexBuffer) - offsetof(TMCCJPEGDecState, pTexBuffer) = 0x0
offsetof(TMCCJPEGDecExifInfo, pWorkBuf) - offsetof(TMCCJPEGDecState, pWorkBuf) = 0x0
offsetof(TMCCJPEGDecExifInfo, decodeResult) - offsetof(TMCCJPEGDecState, decodeResult) = 0x0
offsetof(TMCCJPEGDecExifInfo, converterType) - offsetof(TMCCJPEGDecState, converterType) = 0x0
```
First group quick gate: GATE PASS; 0 regressions, forbidden patterns, or readability warnings. All 1027 complete source objects still match the fresh baseline.
## Further expression trials
- KEEP IFD0/IFD1 rational values: derive denominator offset from scalar size: all checked object bytes identical. Trial 020.
- KEEP IFD0 transfer/date values: derive read bounds and copy length from field types: all checked object bytes identical. Trial 021.
- REVERT IFD0/IFD1 entries: use typed tag, type and value byte fields: exif_parse: TMCJPEGDEC_IFD0_tag_parse. Trial 022.
- REVERT IFD0/IFD1 ignored tags: return directly from the no-op cases: exif_parse: TMCJPEGDEC_IFD0_tag_parse, TMCJPEGDEC_IFD1_tag_parse. Trial 023.
- KEEP Huffman initialization: size all twelve table clears from typed arrays: all checked object bytes identical. Trial 024.
- KEEP buffer initialization: use SDK DEFAULT_ALIGN for both alignment checks: all checked object bytes identical. Trial 025.
- KEEP thumbnail buffer: do lookbehind arithmetic on the byte pointer: all checked object bytes identical. Trial 026.
- KEEP IFD0/IFD1 entries without changing IFD0 constness: use typed tag, type and value byte fields: all checked object bytes identical. Trial 027.
- KEEP EXIF traversal: derive directory-entry strides from the entry type: all checked object bytes identical. Trial 028.
- KEEP AC lookup: keep the table index without cancelling shifts: all checked object bytes identical. Trial 029.
- KEEP signed IDCT clamp: rely on the declared return type for narrowing: all checked object bytes identical. Trial 030.
- KEEP scan geometry: replace boolean-to-one ternaries with their comparisons: all checked object bytes identical. Trial 031.
- REVERT frame parser: compare component count without redundant signed promotions: jdec_main: TMCJPEGDEC_parse_sof. Trial 032.
- KEEP scan geometry: let byte fields perform assignment narrowing: all checked object bytes identical. Trial 033.
- KEEP scan geometry: remove duplicate unsigned product conversion: all checked object bytes identical. Trial 034.
- KEEP decompmcu: compare byte block count without explicit signed promotion: all checked object bytes identical. Trial 035.
- REVERT decompmcu: typed frame and block cursor after removing count promotion: jdec_main: TMCJPEGDEC_decompmcu. Trial 036.
- KEEP quantization parser: rely on unsigned table entry to promote byte product: all checked object bytes identical. Trial 037.
## Scope audit and remaining expressions
Reviewed all 11 owned units. `jpformat.c` contains fixed sampling and zigzag tables. `decapi.c` and `jdec.c` retain the already-tested rx38 expressions that change bytes. No owned source uses GX, NAND, ES, CARD, button-mask, or scene constants. The two buffer alignment checks now use the SDK's existing `DEFAULT_ALIGN`.
All 17 internal `unk_` declarations are gone. Eight public placeholder declarations became typed EXIF state members or named alignment gaps. Eleven public placeholders remain: two init fields have out-of-scope users, four opaque ranges have no proven role, and five decoder-state fields are constrained by the observed changes to unrelated debug objects. No excluded source file changed.
The table and component members replaced shifted work-pointer casts, quantization offsets, selector offsets, and pointer-slot indexing. The EXIF directory entry uses byte arrays because its values have file-selected endianness and may be unaligned. The IFD0 pointer retains its original mutability; adding const changed instructions.
The remaining `decompmcu` frame byte cursor is load-bearing. Trials 006, 010, 011, 012, 017, and 036 tested different member/cursor forms. Trial 036 has 113/113 instructions but 13 differences, all register allocation. It was reverted. The focused diff is saved in `/tmp/rx48-cleanup/trial-036.txt`.
Both existing nonmatching functions have at least three distinct compiled cleanup trials. IFD0: denominator size 020, transfer/date bounds 021, typed entries 022/027, direct returns 023. IFD1: denominator size 020, typed entries 022/027, direct returns 023. Their original mismatches remain unchanged; this task requires preservation, not new matches.
Accepted counts describe expression sites except layouts and placeholder declarations: four typed layouts, 25 placeholder declarations removed, 25 constant/size substitutions, seven independent cast simplifications, two boolean-ternary simplifications, and one cancelling-shift simplification. Casts and offsets eliminated as part of the typed layouts are counted with those layouts, not again. The 25 size substitutions comprise 12 table clears, two alignment checks, four rational offsets, four transfer/date bounds or increments, and three directory-entry strides.
## Final verification
Full clean gate, without `--quick`, passed for all 11 owned units. No source edits followed it. The fresh report and complete ELF hashes match the starting snapshot across all 1027 source units.
```text
Whole-object SHA256: 1027/1027 unchanged
Objdiff measures/sections/functions: 1027 units unchanged
Pools: 15/15 identical
Ctxdiff: 47/49 exact functions, two original EXIF mismatches unchanged
Owned matched code/data: 17724/632 bytes unchanged
main.dol SHA1: 26116613f624061ba99c8d1a299aaa6efa85670d
BYTE PRESERVATION PASS
MWCC layout PASS: 75 sizeof/offsetof assertions
```
The final layout pass adds EXIF entry checks: size 12, tag offset 0, type offset 2, count offset 4, value offset 8. The public-state overlay checks and internal work offsets above pass unchanged.
Before -> after: instruction-exact functions 47/49 -> 47/49; objdiff code 17724/20616 -> 17724/20616 bytes; data 632/632 -> 632/632 bytes.
Open matching work, unchanged:
- `TMCJPEGDEC_IFD0_tag_parse`: 99.49065%, 480/481 instructions, dispatch and register differences.
- `TMCJPEGDEC_IFD1_tag_parse`: 96.14876%, 239/242 instructions, dispatch and register differences.
Final gate command:
```sh
python3 /mnt/drive2/projects/wii-ipl-workers/_restore0928-tools/gate.py \
libs/RVLMiddleware/TMC_JPEG/src/buffer/mkhdec3 \
libs/RVLMiddleware/TMC_JPEG/src/buffer/buffer_system \
libs/RVLMiddleware/TMC_JPEG/src/buffer/getcode \
libs/RVLMiddleware/TMC_JPEG/src/api/decapi \
libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec \
libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec_main \
libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jpformat \
libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse \
libs/RVLMiddleware/TMC_JPEG/src/reschange/iqdec_resolution_change_a3 \
libs/RVLMiddleware/TMC_JPEG/src/reschange/idct_resolution_change_var \
libs/RVLMiddleware/TMC_JPEG/src/b65/iqdec_b65_frv32 \
--base 7c64b0a1f94be5770d04288c93d0c668f43d4250
```
```text
full build: ok
main.dol sha1: 26116613f624061ba99c8d1a299aaa6efa85670d
[libs/RVLMiddleware/TMC_JPEG/src/buffer/mkhdec3] pool: IDENTICAL
[libs/RVLMiddleware/TMC_JPEG/src/buffer/mkhdec3] objdiff: code 1228/1228 data None/None functions 2/2 fuzzy 100.0000 linked code 1228
[libs/RVLMiddleware/TMC_JPEG/src/buffer/mkhdec3] instruction-exact functions: 2/2
[libs/RVLMiddleware/TMC_JPEG/src/buffer/mkhdec3] section .text size 1228 match 100.0
[libs/RVLMiddleware/TMC_JPEG/src/buffer/mkhdec3] baseline: code 1228/1228 data None functions 2 fuzzy 100.0000
[libs/RVLMiddleware/TMC_JPEG/src/buffer/buffer_system] pool: IDENTICAL
[libs/RVLMiddleware/TMC_JPEG/src/buffer/buffer_system] objdiff: code 2444/2444 data None/None functions 10/10 fuzzy 100.0000 linked code 2444
[libs/RVLMiddleware/TMC_JPEG/src/buffer/buffer_system] instruction-exact functions: 10/10
[libs/RVLMiddleware/TMC_JPEG/src/buffer/buffer_system] section .text size 2444 match 100.0
[libs/RVLMiddleware/TMC_JPEG/src/buffer/buffer_system] baseline: code 2444/2444 data None functions 10 fuzzy 100.0000
[libs/RVLMiddleware/TMC_JPEG/src/buffer/getcode] pool: IDENTICAL
[libs/RVLMiddleware/TMC_JPEG/src/buffer/getcode] objdiff: code 316/316 data None/None functions 3/3 fuzzy 100.0000 linked code 316
[libs/RVLMiddleware/TMC_JPEG/src/buffer/getcode] instruction-exact functions: 3/3
[libs/RVLMiddleware/TMC_JPEG/src/buffer/getcode] section .text size 316 match 100.0
[libs/RVLMiddleware/TMC_JPEG/src/buffer/getcode] baseline: code 316/316 data None functions 3 fuzzy 100.0000
[libs/RVLMiddleware/TMC_JPEG/src/api/decapi] pool: IDENTICAL
[libs/RVLMiddleware/TMC_JPEG/src/api/decapi] objdiff: code 1100/1100 data None/None functions 3/3 fuzzy 100.0000 linked code 1100
[libs/RVLMiddleware/TMC_JPEG/src/api/decapi] instruction-exact functions: 3/3
[libs/RVLMiddleware/TMC_JPEG/src/api/decapi] section .text size 1100 match 100.0
[libs/RVLMiddleware/TMC_JPEG/src/api/decapi] baseline: code 1100/1100 data None functions 3 fuzzy 100.0000
[libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec] pool: IDENTICAL
[libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec] objdiff: code 1020/1020 data None/None functions 3/3 fuzzy 100.0000 linked code 1020
[libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec] instruction-exact functions: 3/3
[libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec] section .text size 1020 match 100.0
[libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec] baseline: code 1020/1020 data None functions 3 fuzzy 100.0000
[libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec_main] pool: IDENTICAL
[libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec_main] objdiff: code 5604/5604 data 256/256 functions 13/13 fuzzy 100.0000 linked code 5604
[libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec_main] instruction-exact functions: 13/13
[libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec_main] section .rodata size 256 match 100.0
[libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec_main] section .text size 5604 match 100.0
[libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec_main] baseline: code 5604/5604 data 256 functions 13 fuzzy 100.0000
[libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jpformat] pool: IDENTICAL
[libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jpformat] objdiff: code None/None data 376/376 functions 0/None fuzzy 100.0000 linked code 0
[libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jpformat] instruction-exact functions: 0/0
[libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jpformat] section .rodata size 368 match 100.0
[libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jpformat] section .sdata2 size 8 match 100.0
[libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jpformat] baseline: code None/None data 376 functions 0 fuzzy 100.0000
[libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse] pool: IDENTICAL
[libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse] objdiff: code 2196/5088 data None/None functions 4/6 fuzzy 99.0747 linked code 0
[libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse] instruction-exact functions: 4/6
[libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse] section .text size 5088 match 99.074684
[libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse] below 100: TMCJPEGDEC_IFD0_tag_parse 99.49065
[libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse] below 100: TMCJPEGDEC_IFD1_tag_parse 96.14876
[libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse] baseline: code 2196/5088 data None functions 4 fuzzy 99.0747
[libs/RVLMiddleware/TMC_JPEG/src/reschange/iqdec_resolution_change_a3] pool: IDENTICAL
[libs/RVLMiddleware/TMC_JPEG/src/reschange/iqdec_resolution_change_a3] objdiff: code 908/908 data None/None functions 2/2 fuzzy 100.0000 linked code 908
[libs/RVLMiddleware/TMC_JPEG/src/reschange/iqdec_resolution_change_a3] instruction-exact functions: 2/2
[libs/RVLMiddleware/TMC_JPEG/src/reschange/iqdec_resolution_change_a3] section .text size 908 match 100.0
[libs/RVLMiddleware/TMC_JPEG/src/reschange/iqdec_resolution_change_a3] baseline: code 908/908 data None functions 2 fuzzy 100.0000
[libs/RVLMiddleware/TMC_JPEG/src/reschange/idct_resolution_change_var] pool: IDENTICAL
[libs/RVLMiddleware/TMC_JPEG/src/reschange/idct_resolution_change_var] objdiff: code 1804/1804 data None/None functions 6/6 fuzzy 100.0000 linked code 1804
[libs/RVLMiddleware/TMC_JPEG/src/reschange/idct_resolution_change_var] instruction-exact functions: 6/6
[libs/RVLMiddleware/TMC_JPEG/src/reschange/idct_resolution_change_var] section .text size 1804 match 100.0
[libs/RVLMiddleware/TMC_JPEG/src/reschange/idct_resolution_change_var] baseline: code 1804/1804 data None functions 6 fuzzy 100.0000
[libs/RVLMiddleware/TMC_JPEG/src/b65/iqdec_b65_frv32] pool: IDENTICAL
[libs/RVLMiddleware/TMC_JPEG/src/b65/iqdec_b65_frv32] objdiff: code 1104/1104 data None/None functions 1/1 fuzzy 100.0000 linked code 1104
[libs/RVLMiddleware/TMC_JPEG/src/b65/iqdec_b65_frv32] instruction-exact functions: 1/1
[libs/RVLMiddleware/TMC_JPEG/src/b65/iqdec_b65_frv32] section .text size 1104 match 100.0
[libs/RVLMiddleware/TMC_JPEG/src/b65/iqdec_b65_frv32] baseline: code 1104/1104 data None functions 1 fuzzy 100.0000
regressions vs baseline: 0
global matched_code_percent: 93.99622 -> 93.99622
global fuzzy_match_percent: 99.81744 -> 99.81744
global complete_code_percent: 80.08451 -> 80.08451
global matched_data_percent: 99.99410 -> 99.99410
forbidden patterns added (net, per file): 0
readability warnings (net, per file; must be 0 in the final result): 0
GATE PASS
```
## Files and commits
```text
libs/RVLMiddleware/TMC_JPEG/include/tmc_jpeg.h
libs/RVLMiddleware/TMC_JPEG/include/tmc_jpeg_internal.h
libs/RVLMiddleware/TMC_JPEG/src/b65/iqdec_b65_frv32.c
libs/RVLMiddleware/TMC_JPEG/src/buffer/buffer_system.c
libs/RVLMiddleware/TMC_JPEG/src/buffer/getcode.c
libs/RVLMiddleware/TMC_JPEG/src/buffer/mkhdec3.c
libs/RVLMiddleware/TMC_JPEG/src/exif/exif_parse.c
libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec_main.c
libs/RVLMiddleware/TMC_JPEG/src/reschange/idct_resolution_change_var.c
libs/RVLMiddleware/TMC_JPEG/src/reschange/iqdec_resolution_change_a3.c
tools/decomp-assist/rx48.cleanup.md
```
```text
fee427cd refactor: type jpeg component and entropy table storage
e924ba6e refactor: describe jpeg exif decoder state fields
2fab68f0 refactor: use typed jpeg exif entries and field sizes
50ace99f refactor: derive jpeg buffer alignment and table clear sizes
05f1ddbf refactor: simplify jpeg geometry casts and huffman indexing
```
Final source review: no excluded files, existing assembly, configuration, or link status changed. The two reserved table words preserve existing storage; no padding was added. All 37 trials are logged. Raw frame access, existing public names, and remaining opaque ranges are retained for the measured code-generation, scope, or evidence constraints above.