//
// png_handle_cHRM from 0x65cda8 to 0x65cfc4 (540 bytes)
//
// 3 xrefs:
// > png_push_read_chunk @ 0x652a32
// > png_read_info @ 0x65588e
// > png_read_end @ 0x657386
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
int __fastcall png_handle_cHRM(int a1, int a2, unsigned int a3)
{
int v4; // r3
int result; // r0
int v7; // r12
int v8; // lr
int v9; // r3
int v10; // r6
int v11; // r4
int v12; // r10
int v13; // r1
bool v14; // nf
int v15; // r2
int v16; // r3
_BYTE v17[28]; // [sp+0h] [bp-44h] BYREF
unsigned __int8 v18; // [sp+1Ch] [bp-28h]
unsigned __int8 v19; // [sp+1Dh] [bp-27h]
unsigned __int8 v20; // [sp+1Eh] [bp-26h]
unsigned __int8 v21; // [sp+1Fh] [bp-25h]
int v22[5]; // [sp+20h] [bp-24h] BYREF
int v23; // [sp+34h] [bp-10h]
int v24; // [sp+38h] [bp-Ch]
int v25; // [sp+3Ch] [bp-8h]
v4 = *(_DWORD *)(a1 + 308);
if ( (v4 & 1) == 0 )
png_chunk_error(a1, "missing IHDR");
if ( (v4 & 6) != 0 )
{
png_crc_finish((_DWORD *)a1, a3);
return png_chunk_benign_error(a1, "out of place");
}
if ( a3 != 32 )
{
png_crc_finish((_DWORD *)a1, a3);
return png_chunk_benign_error(a1, "invalid");
}
png_crc_read((_DWORD *)a1, (int)v17, 32);
result = png_crc_finish((_DWORD *)a1, 0);
if ( !result )
{
v7 = (v17[1] << 16) + (v17[0] << 24) + v17[3] + (v17[2] << 8);
v8 = v17[7] + (v17[5] << 16) + (v17[4] << 24) + (v17[6] << 8);
if ( v7 >= 0 )
{
v9 = 0;
}
else
{
v9 = 1;
v7 = -1;
}
v10 = v17[11] + (v17[9] << 16) + (v17[8] << 24) + (v17[10] << 8);
if ( v8 < 0 )
{
v9 = 1;
v8 = -1;
}
v11 = (v17[13] << 16) + (v17[12] << 24) + v17[15] + (v17[14] << 8);
if ( v10 < 0 )
{
v9 = 1;
v10 = -1;
}
v12 = (v17[17] << 16) + (v17[16] << 24) + v17[19] + (v17[18] << 8);
if ( v11 < 0 )
{
v9 = 1;
v11 = -1;
}
v13 = (v17[21] << 16) + (v17[20] << 24) + v17[23] + (v17[22] << 8);
if ( v12 < 0 )
{
v9 = 1;
v12 = -1;
}
v14 = v13 < 0;
v22[1] = v11;
if ( v13 < 0 )
v13 = -1;
v22[3] = v13;
v24 = v7;
if ( v14 )
v9 = 1;
v25 = v8;
v22[0] = v10;
v22[2] = v12;
v15 = (v17[25] << 16) + (v17[24] << 24) + v17[27] + (v17[26] << 8);
result = v21;
if ( v15 < 0 )
{
v15 = -1;
v9 = 1;
}
v22[4] = v15;
if ( (v19 << 16) + (v18 << 24) + v21 + (v20 << 8) < 0 )
{
v23 = -1;
}
else
{
v23 = (v19 << 16) + (v18 << 24) + v21 + (v20 << 8);
if ( !v9 )
{
v16 = *(unsigned __int16 *)(a1 + 998);
if ( (v16 & 0x8000) == 0 )
{
if ( (v16 & 0x10) != 0 )
{
*(_WORD *)(a1 + 998) = ~((unsigned int)~(v16 << 17) >> 17);
png_colorspace_sync(a1, a2);
return png_chunk_benign_error(a1, "duplicate");
}
else
{
*(_WORD *)(a1 + 998) = v16 | 0x10;
png_colorspace_set_chromaticities(a1, a1 + 924, v22, 1);
return png_colorspace_sync(a1, a2);
}
}
return result;
}
}
return png_chunk_benign_error(a1, "invalid values");
}
return result;
}