//
// png_write_tRNS from 0x664e88 to 0x66504a (450 bytes)
//
// 1 xrefs:
// > png_write_info @ 0x661ad2
//
// 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_write_tRNS(int a1, int a2, int a3, int a4, int a5)
{
int v7; // r1
_BYTE v11[2]; // [sp+8h] [bp-10h] BYREF
_BYTE v12[2]; // [sp+Ah] [bp-Eh] BYREF
_BYTE v13[4]; // [sp+Ch] [bp-Ch] BYREF
_BYTE v14[4]; // [sp+10h] [bp-8h] BYREF
_BYTE v15[4]; // [sp+14h] [bp-4h] BYREF
if ( a5 == 3 )
{
if ( a4 > 0 && a4 <= *(unsigned __int16 *)(a1 + 520) )
{
*(_DWORD *)(a1 + 900) = 34;
png_save_uint_32(v14, a4);
png_save_uint_32(v15, 1951551059);
png_write_data(a1);
*(_DWORD *)(a1 + 476) = 1951551059;
png_reset_crc(a1);
png_calculate_crc((_DWORD *)a1, (int)v15, 4);
*(_DWORD *)(a1 + 900) = 66;
png_write_chunk_data((_DWORD *)a1, a2, a4);
return png_write_chunk_end(a1);
}
else
{
return png_app_warning(a1, "Invalid number of transparent colors specified");
}
}
else if ( a5 )
{
if ( a5 == 2 )
{
png_save_uint_16(v11, *(_WORD *)(a3 + 2));
png_save_uint_16(v12, *(_WORD *)(a3 + 4));
png_save_uint_16(v13, *(_WORD *)(a3 + 6));
if ( *(_BYTE *)(a1 + 536) == 8 && v11[0] | v12[0] | v13[0] )
{
return png_app_warning(a1, "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
}
else
{
*(_DWORD *)(a1 + 900) = 34;
png_save_uint_32(v14, 6);
png_save_uint_32(v15, 1951551059);
png_write_data(a1);
*(_DWORD *)(a1 + 476) = 1951551059;
png_reset_crc(a1);
png_calculate_crc((_DWORD *)a1, (int)v15, 4);
*(_DWORD *)(a1 + 900) = 66;
png_write_chunk_data((_DWORD *)a1, (int)v11, 6);
return png_write_chunk_end(a1);
}
}
else
{
return png_app_warning(a1, "Can't write tRNS with an alpha channel");
}
}
else
{
v7 = *(unsigned __int16 *)(a3 + 8);
if ( v7 < 1 << *(_BYTE *)(a1 + 536) )
{
png_save_uint_16(v11, v7);
*(_DWORD *)(a1 + 900) = 34;
png_save_uint_32(v14, 2);
png_save_uint_32(v15, 1951551059);
png_write_data(a1);
*(_DWORD *)(a1 + 476) = 1951551059;
png_reset_crc(a1);
png_calculate_crc((_DWORD *)a1, (int)v15, 4);
*(_DWORD *)(a1 + 900) = 66;
png_write_chunk_data((_DWORD *)a1, (int)v11, 2);
return png_write_chunk_end(a1);
}
else
{
return png_app_warning(a1, "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
}
}
}