//
// png_set_rgb_to_gray_fixed from 0xe4e990 to 0xe4eadc (332 bytes)
//
// 4 xrefs:
// > sub_E47DAC @ 0xe4843c
// > png_read_row @ 0xe49f3c
// > png_set_rgb_to_gray @ 0xe4eb38
// > ??> @ 0xad4e8
//
// This function is hookable on this platform (idp: arm, 32 bit: False, 64 bit: True!
//
// 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 13:10:09 +0000
//
__int64 __fastcall png_set_rgb_to_gray_fixed(__int64 result, int a2, int a3, int a4)
{
__int64 v4; // x4
int v5; // w5
__int64 v6; // x19
int v7; // w0
const char *v8; // x1
v4 = result;
if ( !result )
return result;
v5 = *(_DWORD *)(result + 360);
if ( (v5 & 0x40) != 0 )
{
v8 = "invalid after png_start_read_image or png_read_update_info";
return png_app_error(result, v8);
}
if ( (*(_DWORD *)(result + 356) & 1) == 0 )
{
v8 = "invalid before the PNG header has been read";
return png_app_error(result, v8);
}
*(_DWORD *)(result + 360) = v5 | 0x4000;
v6 = result;
switch ( a2 )
{
case 2:
v7 = *(_DWORD *)(result + 364) | 0x400000;
*(_DWORD *)(v4 + 364) = v7;
break;
case 3:
v7 = *(_DWORD *)(result + 364) | 0x200000;
*(_DWORD *)(v4 + 364) = v7;
break;
case 1:
v7 = *(_DWORD *)(result + 364) | 0x600000;
*(_DWORD *)(v4 + 364) = v7;
break;
default:
png_error(result, "invalid error action to rgb_to_gray");
}
if ( *(_BYTE *)(v6 + 687) == 3 )
*(_DWORD *)(v6 + 364) = v7 | 0x1000;
if ( (a3 & 0x80000000) == 0 && (a4 & 0x80000000) == 0 )
{
if ( a3 + a4 <= 100000 )
{
*(_WORD *)(v6 + 1100) = (175921861 * (unsigned __int64)((a4 & 0x1FFFFu) << 10)) >> 39;
*(_WORD *)(v6 + 1098) = (175921861 * (unsigned __int64)((a3 & 0x1FFFFu) << 10)) >> 39;
*(_BYTE *)(v6 + 1097) = 1;
return 1;
}
png_app_warning(v6, "ignoring out of range rgb_to_gray coefficients");
}
result = *(_QWORD *)(v6 + 1096);
if ( (result & 0xFFFFFFFF0000LL) == 0 )
{
*(_WORD *)(v6 + 1098) = 6968;
result = 23434;
*(_WORD *)(v6 + 1100) = 23434;
}
return result;
}