//
// png_set_tRNS from 0xbe4820 to 0xbe4958 (312 bytes)
//
// 3 xrefs:
// > png_handle_tRNS @ 0xbe06c0
// > sub_BE6640 @ 0xbe687c
// > ??> @ 0x74fe8
//
// 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
//
__int64 __fastcall png_set_tRNS(__int64 result, __int64 a2, const void *a3, int a4, __int64 a5)
{
__int64 v5; // x20
int v9; // w0
__int16 v10; // w0
int v11; // w0
__int64 v12; // [xsp+38h] [xbp+38h]
__int64 v13; // [xsp+38h] [xbp+38h]
v5 = result;
if ( result && a2 )
{
if ( a3 )
{
v12 = a5;
png_free_data(result, a2, 0x2000, 0);
result = (__int64)png_malloc(v5, 0x100u);
*(_QWORD *)(a2 + 184) = result;
*(_QWORD *)(v5 + 816) = result;
a5 = v12;
if ( (unsigned int)(a4 - 1) <= 0xFF )
{
result = (__int64)memcpy((void *)result, a3, a4);
a5 = v12;
}
}
if ( a5 )
{
v9 = 1 << *(_BYTE *)(a2 + 36);
if ( *(_BYTE *)(a2 + 37) )
{
if ( *(_BYTE *)(a2 + 37) != 2
|| v9 >= *(unsigned __int16 *)(a5 + 2)
&& v9 >= *(unsigned __int16 *)(a5 + 4)
&& v9 >= *(unsigned __int16 *)(a5 + 6) )
{
LABEL_9:
v10 = a4;
*(_QWORD *)(a2 + 192) = *(_QWORD *)a5;
if ( !a4 )
v10 = 1;
*(_WORD *)(a2 + 200) = *(_WORD *)(a5 + 8);
*(_WORD *)(a2 + 34) = v10;
goto LABEL_12;
}
}
else if ( v9 >= *(unsigned __int16 *)(a5 + 8) )
{
goto LABEL_9;
}
v13 = a5;
png_warning(v5, "tRNS chunk has out-of-range samples for bit_depth");
a5 = v13;
goto LABEL_9;
}
*(_WORD *)(a2 + 34) = a4;
if ( a4 )
{
LABEL_12:
v11 = *(_DWORD *)(a2 + 284);
*(_DWORD *)(a2 + 8) |= 0x10u;
result = v11 | 0x2000u;
*(_DWORD *)(a2 + 284) = result;
}
}
return result;
}