//
// png_handle_PLTE from 0x86ca04 to 0x86cb88 (388 bytes)
//
// 3 xrefs:
// > png_push_read_chunk @ 0x862a76
// > png_read_info @ 0x8658f6
// > png_read_end @ 0x8673ba
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 12:02:55 +0000
//
int __fastcall png_handle_PLTE(int a1, int a2, unsigned int a3)
{
int v4; // r4
char v5; // r3
int result; // r0
int v8; // r7
char *v9; // r4
char v10; // r2
char v11; // r3
int v12; // r3
_BYTE v13[4]; // [sp+4h] [bp-304h] BYREF
_BYTE v14[3]; // [sp+8h] [bp-300h] BYREF
char v15; // [sp+Bh] [bp-2FDh] BYREF
v4 = *(_DWORD *)(a1 + 308);
if ( (v4 & 1) == 0 )
png_chunk_error(a1, "missing IHDR");
if ( (v4 & 2) != 0 )
png_chunk_error(a1, "duplicate");
if ( (v4 & 4) != 0 )
{
png_crc_finish((_DWORD *)a1, a3);
return png_chunk_benign_error(a1, "out of place");
}
v5 = *(_BYTE *)(a1 + 535);
*(_DWORD *)(a1 + 308) = v4 | 2;
if ( (v5 & 2) == 0 )
{
png_crc_finish((_DWORD *)a1, a3);
return png_chunk_benign_error(a1, "ignored in grayscale PNG");
}
if ( a3 > 0x300 || a3 != 3 * (a3 / 3) )
{
png_crc_finish((_DWORD *)a1, a3);
if ( *(_BYTE *)(a1 + 535) == 3 )
png_chunk_error(a1, "invalid");
return png_chunk_benign_error(a1, "invalid");
}
v8 = (int)a3 / 3;
if ( (int)a3 / 3 )
{
v9 = &v15;
do
{
v9 += 3;
png_crc_read((_DWORD *)a1, (int)v13, 3);
v10 = v13[1];
v11 = v13[2];
*(v9 - 6) = v13[0];
*(v9 - 5) = v10;
*(v9 - 4) = v11;
}
while ( v9 != &v14[3 * v8 + 3] );
}
png_crc_finish((_DWORD *)a1, 0);
result = png_set_PLTE(a1, a2, v14, v8);
if ( *(_WORD *)(a1 + 528) )
{
*(_WORD *)(a1 + 528) = 0;
if ( !a2 )
return png_chunk_benign_error(a1, "tRNS must be after");
}
else
{
if ( !a2 )
return result;
v12 = *(_DWORD *)(a2 + 8);
if ( (v12 & 0x10) == 0 )
goto LABEL_18;
*(_WORD *)(a1 + 528) = 0;
}
*(_WORD *)(a2 + 22) = 0;
result = png_chunk_benign_error(a1, "tRNS must be after");
v12 = *(_DWORD *)(a2 + 8);
LABEL_18:
if ( (v12 & 0x40) != 0 )
{
result = png_chunk_benign_error(a1, "hIST must be after");
v12 = *(_DWORD *)(a2 + 8);
}
if ( (v12 & 0x20) != 0 )
return png_chunk_benign_error(a1, "bKGD must be after");
return result;
}