//
// jpeg_calc_jpeg_dimensions from 0xc0042c to 0xc00948 (1308 bytes)
//
// 2 xrefs:
// > jinit_c_master_control @ 0xc00e80
// > ??> @ 0x68a90
//
// 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 jpeg_calc_jpeg_dimensions(__int64 a1)
{
unsigned int v1; // w2
int v3; // w0
unsigned int v4; // w3
unsigned int v5; // w1
__int64 result; // x0
void (__fastcall **v7)(__int64); // x1
int v8; // w1
v1 = *(_DWORD *)(a1 + 48);
if ( !HIBYTE(v1) && !*(_BYTE *)(a1 + 55) )
{
v3 = *(_DWORD *)(a1 + 476);
v4 = *(_DWORD *)(a1 + 72);
v5 = v3 * *(_DWORD *)(a1 + 76);
if ( v4 < v5 )
goto LABEL_4;
LABEL_20:
v8 = *(_DWORD *)(a1 + 52);
*(_DWORD *)(a1 + 80) = v1 * v3;
result = (unsigned int)(v3 * v8);
*(_DWORD *)(a1 + 84) = result;
*(_DWORD *)(a1 + 360) = 1;
*(_DWORD *)(a1 + 364) = 1;
return result;
}
v7 = *(void (__fastcall ***)(__int64))a1;
*((_DWORD *)v7 + 11) = 65500;
*((_DWORD *)v7 + 10) = 42;
(**(void (__fastcall ***)(__int64))a1)(a1);
v3 = *(_DWORD *)(a1 + 476);
v4 = *(_DWORD *)(a1 + 72);
v1 = *(_DWORD *)(a1 + 48);
v5 = v3 * *(_DWORD *)(a1 + 76);
if ( v4 >= v5 )
goto LABEL_20;
LABEL_4:
if ( v5 <= 2 * v4 )
{
*(_DWORD *)(a1 + 80) = jdiv_round_up(v1 * (__int64)v3, 2);
result = jdiv_round_up(*(unsigned int *)(a1 + 52) * (__int64)*(int *)(a1 + 476), 2);
*(_DWORD *)(a1 + 84) = result;
*(_DWORD *)(a1 + 360) = 2;
*(_DWORD *)(a1 + 364) = 2;
}
else if ( v5 <= 3 * v4 )
{
*(_DWORD *)(a1 + 80) = jdiv_round_up(v1 * (__int64)v3, 3);
result = jdiv_round_up(*(unsigned int *)(a1 + 52) * (__int64)*(int *)(a1 + 476), 3);
*(_DWORD *)(a1 + 84) = result;
*(_DWORD *)(a1 + 360) = 3;
*(_DWORD *)(a1 + 364) = 3;
}
else if ( v5 <= 4 * v4 )
{
*(_DWORD *)(a1 + 80) = jdiv_round_up(v1 * (__int64)v3, 4);
result = jdiv_round_up(*(unsigned int *)(a1 + 52) * (__int64)*(int *)(a1 + 476), 4);
*(_DWORD *)(a1 + 84) = result;
*(_DWORD *)(a1 + 360) = 4;
*(_DWORD *)(a1 + 364) = 4;
}
else if ( v5 <= 5 * v4 )
{
*(_DWORD *)(a1 + 80) = jdiv_round_up(v1 * (__int64)v3, 5);
result = jdiv_round_up(*(unsigned int *)(a1 + 52) * (__int64)*(int *)(a1 + 476), 5);
*(_DWORD *)(a1 + 84) = result;
*(_DWORD *)(a1 + 360) = 5;
*(_DWORD *)(a1 + 364) = 5;
}
else if ( v5 <= 6 * v4 )
{
*(_DWORD *)(a1 + 80) = jdiv_round_up(v1 * (__int64)v3, 6);
result = jdiv_round_up(*(unsigned int *)(a1 + 52) * (__int64)*(int *)(a1 + 476), 6);
*(_DWORD *)(a1 + 84) = result;
*(_DWORD *)(a1 + 360) = 6;
*(_DWORD *)(a1 + 364) = 6;
}
else if ( v5 <= 7 * v4 )
{
*(_DWORD *)(a1 + 80) = jdiv_round_up(v1 * (__int64)v3, 7);
result = jdiv_round_up(*(unsigned int *)(a1 + 52) * (__int64)*(int *)(a1 + 476), 7);
*(_DWORD *)(a1 + 84) = result;
*(_DWORD *)(a1 + 360) = 7;
*(_DWORD *)(a1 + 364) = 7;
}
else if ( v5 <= 8 * v4 )
{
*(_DWORD *)(a1 + 80) = jdiv_round_up(v1 * (__int64)v3, 8);
result = jdiv_round_up(*(unsigned int *)(a1 + 52) * (__int64)*(int *)(a1 + 476), 8);
*(_DWORD *)(a1 + 84) = result;
*(_DWORD *)(a1 + 360) = 8;
*(_DWORD *)(a1 + 364) = 8;
}
else if ( v5 <= 9 * v4 )
{
*(_DWORD *)(a1 + 80) = jdiv_round_up(v1 * (__int64)v3, 9);
result = jdiv_round_up(*(unsigned int *)(a1 + 52) * (__int64)*(int *)(a1 + 476), 9);
*(_DWORD *)(a1 + 84) = result;
*(_DWORD *)(a1 + 360) = 9;
*(_DWORD *)(a1 + 364) = 9;
}
else if ( v5 <= 10 * v4 )
{
*(_DWORD *)(a1 + 80) = jdiv_round_up(v1 * (__int64)v3, 10);
result = jdiv_round_up(*(unsigned int *)(a1 + 52) * (__int64)*(int *)(a1 + 476), 10);
*(_DWORD *)(a1 + 84) = result;
*(_DWORD *)(a1 + 360) = 10;
*(_DWORD *)(a1 + 364) = 10;
}
else if ( v5 <= 11 * v4 )
{
*(_DWORD *)(a1 + 80) = jdiv_round_up(v1 * (__int64)v3, 11);
result = jdiv_round_up(*(unsigned int *)(a1 + 52) * (__int64)*(int *)(a1 + 476), 11);
*(_DWORD *)(a1 + 84) = result;
*(_DWORD *)(a1 + 360) = 11;
*(_DWORD *)(a1 + 364) = 11;
}
else if ( v5 <= 12 * v4 )
{
*(_DWORD *)(a1 + 80) = jdiv_round_up(v1 * (__int64)v3, 12);
result = jdiv_round_up(*(unsigned int *)(a1 + 52) * (__int64)*(int *)(a1 + 476), 12);
*(_DWORD *)(a1 + 84) = result;
*(_DWORD *)(a1 + 360) = 12;
*(_DWORD *)(a1 + 364) = 12;
}
else if ( v5 <= 13 * v4 )
{
*(_DWORD *)(a1 + 80) = jdiv_round_up(v1 * (__int64)v3, 13);
result = jdiv_round_up(*(unsigned int *)(a1 + 52) * (__int64)*(int *)(a1 + 476), 13);
*(_DWORD *)(a1 + 84) = result;
*(_DWORD *)(a1 + 360) = 13;
*(_DWORD *)(a1 + 364) = 13;
}
else if ( v5 <= 14 * v4 )
{
*(_DWORD *)(a1 + 80) = jdiv_round_up(v1 * (__int64)v3, 14);
result = jdiv_round_up(*(unsigned int *)(a1 + 52) * (__int64)*(int *)(a1 + 476), 14);
*(_DWORD *)(a1 + 84) = result;
*(_DWORD *)(a1 + 360) = 14;
*(_DWORD *)(a1 + 364) = 14;
}
else if ( v5 <= 15 * v4 )
{
*(_DWORD *)(a1 + 80) = jdiv_round_up(v1 * (__int64)v3, 15);
result = jdiv_round_up(*(unsigned int *)(a1 + 52) * (__int64)*(int *)(a1 + 476), 15);
*(_DWORD *)(a1 + 84) = result;
*(_DWORD *)(a1 + 360) = 15;
*(_DWORD *)(a1 + 364) = 15;
}
else
{
*(_DWORD *)(a1 + 80) = jdiv_round_up(v1 * (__int64)v3, 16);
result = jdiv_round_up(*(unsigned int *)(a1 + 52) * (__int64)*(int *)(a1 + 476), 16);
*(_DWORD *)(a1 + 84) = result;
*(_DWORD *)(a1 + 360) = 16;
*(_DWORD *)(a1 + 364) = 16;
}
return result;
}