//
// png_write_bKGD from 0x8750dc to 0x87529a (446 bytes)
//
// 1 xrefs:
// > png_write_info @ 0x871b66
//
// 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:03:01 +0000
//
int __fastcall png_write_bKGD(int a1, unsigned __int8 *a2, int a3)
{
int v5; // r1
_BYTE v7[2]; // [sp+8h] [bp-10h] BYREF
_BYTE v8[2]; // [sp+Ah] [bp-Eh] BYREF
_BYTE v9[4]; // [sp+Ch] [bp-Ch] BYREF
_BYTE v10[4]; // [sp+10h] [bp-8h] BYREF
_BYTE v11[4]; // [sp+14h] [bp-4h] BYREF
if ( a3 == 3 )
{
if ( *(_WORD *)(a1 + 520) )
{
if ( *(unsigned __int16 *)(a1 + 520) > (unsigned int)*a2 )
{
v7[0] = *a2;
LABEL_11:
*(_DWORD *)(a1 + 900) = 34;
png_save_uint_32(v10, 1);
png_save_uint_32(v11, 1649100612);
png_write_data(a1);
*(_DWORD *)(a1 + 476) = 1649100612;
png_reset_crc(a1);
png_calculate_crc((_DWORD *)a1, (int)v11, 4);
*(_DWORD *)(a1 + 900) = 66;
png_write_chunk_data((_DWORD *)a1, (int)v7, 1);
return png_write_chunk_end(a1);
}
}
else if ( (*(_DWORD *)(a1 + 808) & 1) != 0 )
{
v7[0] = *a2;
goto LABEL_11;
}
return png_warning(a1, "Invalid background palette index");
}
if ( (a3 & 2) != 0 )
{
png_save_uint_16(v7, *((_WORD *)a2 + 1));
png_save_uint_16(v8, *((_WORD *)a2 + 2));
png_save_uint_16(v9, *((_WORD *)a2 + 3));
if ( *(_BYTE *)(a1 + 536) == 8 && v7[0] | v8[0] | v9[0] )
{
return png_warning(a1, "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
}
else
{
*(_DWORD *)(a1 + 900) = 34;
png_save_uint_32(v10, 6);
png_save_uint_32(v11, 1649100612);
png_write_data(a1);
*(_DWORD *)(a1 + 476) = 1649100612;
png_reset_crc(a1);
png_calculate_crc((_DWORD *)a1, (int)v11, 4);
*(_DWORD *)(a1 + 900) = 66;
png_write_chunk_data((_DWORD *)a1, (int)v7, 6);
return png_write_chunk_end(a1);
}
}
else
{
v5 = *((unsigned __int16 *)a2 + 4);
if ( v5 >= 1 << *(_BYTE *)(a1 + 536) )
{
return png_warning(a1, "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
}
else
{
png_save_uint_16(v7, v5);
*(_DWORD *)(a1 + 900) = 34;
png_save_uint_32(v10, 2);
png_save_uint_32(v11, 1649100612);
png_write_data(a1);
*(_DWORD *)(a1 + 476) = 1649100612;
png_reset_crc(a1);
png_calculate_crc((_DWORD *)a1, (int)v11, 4);
*(_DWORD *)(a1 + 900) = 66;
png_write_chunk_data((_DWORD *)a1, (int)v7, 2);
return png_write_chunk_end(a1);
}
}
}