//
// png_colorspace_set_gamma from 0xbc9870 to 0xbc9988 (280 bytes)
//
// 3 xrefs:
// > png_handle_gAMA @ 0xbdf6a4
// > png_set_gAMA_fixed @ 0xbe3868
// > ??> @ 0x55a40
//
// 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_colorspace_set_gamma(__int64 a1, __int64 a2, int a3)
{
__int64 result; // x0
int v7; // w1
const char *v8; // x1
int v9; // [xsp+3Ch] [xbp+3Ch] BYREF
if ( (unsigned int)(a3 - 16) > 0x2540BE30 )
{
LOWORD(result) = *(_WORD *)(a2 + 74);
v8 = "gamma value out of range";
goto LABEL_10;
}
if ( (*(_DWORD *)(a1 + 356) & 0x8000) != 0 )
{
result = *(unsigned __int16 *)(a2 + 74);
if ( (result & 8) == 0 )
goto LABEL_4;
v8 = "duplicate";
LABEL_10:
*(_WORD *)(a2 + 74) = result | 0x8000;
return png_chunk_report(a1, v8, 1);
}
result = *(unsigned __int16 *)(a2 + 74);
LABEL_4:
if ( (result & 0x8000) == 0 )
{
v7 = *(_DWORD *)a2;
if ( (result & 1) != 0 )
{
if ( !(unsigned int)png_muldiv(&v9, v7, 100000, a3) || png_gamma_significant(v9) )
{
if ( (*(_WORD *)(a2 + 74) & 0x20) != 0 )
return png_chunk_report(a1, "gamma value does not match sRGB", 2);
png_chunk_report(a1, "gamma value does not match libpng estimate", 0);
LODWORD(result) = *(unsigned __int16 *)(a2 + 74);
}
else
{
LODWORD(result) = *(unsigned __int16 *)(a2 + 74);
}
}
*(_DWORD *)a2 = a3;
result = (unsigned int)result | 9;
*(_WORD *)(a2 + 74) = result;
}
return result;
}