//
// sub_6B2FE0 from 0x6b2fe0 to 0x6b3578 (1432 bytes)
//
// 3 xrefs:
// > TIFFReadDirectory @ 0x6b2204
// > TIFFReadDirectory @ 0x6b23bc
// > TIFFReadDirectory @ 0x6b24a4
//
// 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
//
int __fastcall sub_6B2FE0(_DWORD *a1, int a2, unsigned __int16 a3)
{
__int64 v4; // r2
int v5; // r12
unsigned __int64 v6; // r2
int v11; // [sp+14h] [bp-50h]
_DWORD *v12; // [sp+18h] [bp-4Ch]
unsigned int m; // [sp+1Ch] [bp-48h]
unsigned int v14; // [sp+1Ch] [bp-48h]
unsigned int i; // [sp+1Ch] [bp-48h]
unsigned int j; // [sp+1Ch] [bp-48h]
__int64 v17; // [sp+20h] [bp-44h]
unsigned __int64 v18; // [sp+20h] [bp-44h]
unsigned __int64 v19; // [sp+28h] [bp-3Ch]
unsigned __int16 k; // [sp+32h] [bp-32h]
int v21; // [sp+34h] [bp-30h]
unsigned __int64 v22; // [sp+38h] [bp-2Ch]
__int64 v23; // [sp+40h] [bp-24h]
__int64 v24; // [sp+48h] [bp-1Ch]
int v25; // [sp+54h] [bp-10h]
v12 = a1 + 10;
TIFFFillStriles(a1);
if ( v12[34] )
TIFFfree(v12[34]);
v12[34] = TIFFCheckMalloc(a1, v12[32], 8, "for \"StripByteCounts\" array");
if ( !v12[34] )
return -1;
if ( *((_WORD *)v12 + 24) == 1 )
{
if ( (a1[3] & 0x400) != 0 )
{
v23 = TIFFTileSize64(a1);
for ( i = 0; v12[32] > i; ++i )
*(_QWORD *)(v12[34] + 8 * i) = v23;
}
else
{
v24 = TIFFScanlineSize64(a1);
v25 = v12[5] / v12[31];
for ( j = 0; v12[32] > j; ++j )
*(_QWORD *)(v12[34] + 8 * j) = v24 * (unsigned int)v25;
}
}
else
{
v19 = ((__int64 (__fastcall *)(_DWORD))a1[162])(a1[157]);
if ( (a1[3] & 0x80000) != 0 )
v17 = 20 * (unsigned int)a3 + 32;
else
v17 = 12 * (unsigned int)a3 + 14;
v11 = a2;
for ( k = a3; k; --k )
{
TIFFDataWidth(*(unsigned __int16 *)(v11 + 2));
v21 = TIFFDataWidth(*(unsigned __int16 *)(v11 + 2));
if ( !v21 )
{
TIFFErrorExt(
a1[157],
"EstimateStripByteCounts",
"Cannot determine size of unknown tag type %d",
*(unsigned __int16 *)(v11 + 2));
return -1;
}
v4 = *(_QWORD *)(v11 + 8);
v5 = v21 * HIDWORD(v4);
v6 = (unsigned int)v21 * (unsigned __int64)(unsigned int)v4;
HIDWORD(v6) += v5;
v22 = v6;
if ( (a1[3] & 0x80000) != 0 )
{
if ( v6 <= 8 )
v22 = 0;
}
else if ( v6 <= 4 )
{
v22 = 0;
}
v17 += v22;
v11 += 24;
}
v18 = v19 - v17;
if ( *((_WORD *)v12 + 43) == 2 )
v18 /= *((unsigned __int16 *)v12 + 29);
for ( m = 0; v12[32] > m; ++m )
*(_QWORD *)(v12[34] + 8 * m) = v18;
v14 = m - 1;
if ( v19 < *(_QWORD *)(v12[33] + 8 * v14) + *(_QWORD *)(v12[34] + 8 * v14) )
*(_QWORD *)(v12[34] + 8 * v14) = v19 - *(_QWORD *)(v12[33] + 8 * v14);
}
a1[10] |= 0x1000000u;
if ( (a1[10] & 0x20000) == 0 )
v12[15] = v12[5];
return 1;
}