//
// sub_653A0C from 0x653a0c to 0x653bd0 (452 bytes)
//
// 3 xrefs:
// > sub_654424 @ 0x65493a
// > sub_654424 @ 0x654952
// > sub_654424 @ 0x65496a
//
// 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
//
unsigned int __fastcall sub_653A0C(int ***a1, int a2, int a3, int a4, int a5, int a6)
{
int v9; // r4
int v10; // r2
unsigned int v11; // r4
int v13; // r10
int v14; // r0
int v15; // r10
int v16; // r0
if ( a3 == 3 )
a3 = (int)a1[8];
v9 = a5;
if ( !a3 )
{
v15 = *(_DWORD *)(***a1 + 924);
if ( png_gamma_significant(v15) )
{
if ( v15 > 99999 || v15 && png_gamma_significant((11 * v15 + 2) / 5) )
{
a1[8] = (int **)(&dword_0 + 3);
v16 = png_reciprocal(v15);
a3 = (int)a1[8];
a1[9] = (int **)v16;
}
else
{
a3 = 1;
a1[8] = (int **)(&dword_0 + 1);
}
}
else
{
a3 = 4;
a1[8] = (int **)byte_4;
}
}
switch ( a3 )
{
case 1:
a2 = png_sRGB_table[a2];
goto LABEL_6;
case 2:
goto LABEL_6;
case 3:
a2 = png_gamma_16bit_correct(257 * a2, (int)a1[9]);
LABEL_6:
if ( a6 == 3 )
v10 = (int)a1[8];
else
v10 = a6;
if ( v10 )
goto LABEL_10;
goto LABEL_18;
case 4:
a2 *= 257;
if ( a6 == 3 )
v10 = (int)a1[8];
else
v10 = a6;
if ( !v10 )
{
LABEL_18:
v13 = *(_DWORD *)(***a1 + 924);
if ( png_gamma_significant(v13) )
{
if ( v13 > 99999 || v13 && png_gamma_significant((11 * v13 + 2) / 5) )
{
a1[8] = (int **)(&dword_0 + 3);
v14 = png_reciprocal(v13);
v10 = (int)a1[8];
a1[9] = (int **)v14;
}
else
{
v10 = 1;
a1[8] = (int **)(&dword_0 + 1);
}
}
else
{
v10 = 4;
a1[8] = (int **)byte_4;
}
}
LABEL_10:
switch ( v10 )
{
case 1:
v9 = png_sRGB_table[a5];
goto LABEL_12;
case 2:
goto LABEL_12;
case 3:
v9 = png_gamma_16bit_correct(257 * a5, (int)a1[9]);
LABEL_12:
v11 = a4 * a2 + (255 - a4) * v9;
if ( a6 != 2 )
return (unsigned __int16)(png_sRGB_base[v11 >> 15] + (((v11 & 0x7FFF) * png_sRGB_delta[v11 >> 15]) >> 12)) >> 8;
return (257 * v11 + 0x8000 + ((257 * v11) >> 16)) >> 16;
case 4:
v11 = a4 * a2 + (255 - a4) * 257 * a5;
if ( a6 == 2 )
return (257 * v11 + 0x8000 + ((257 * v11) >> 16)) >> 16;
else
return (unsigned __int16)(png_sRGB_base[v11 >> 15] + (((v11 & 0x7FFF) * png_sRGB_delta[v11 >> 15]) >> 12)) >> 8;
default:
png_error(***a1, "unexpected encoding (internal error)");
}
default:
png_error(***a1, "unexpected encoding (internal error)");
}
}