//
// TIFFFillTile from 0x6ef210 to 0x6ef684 (1140 bytes)
//
// 2 xrefs:
// > TIFFReadEncodedTile @ 0x6eec14
// > ??> @ 0x587dc
//
// 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 TIFFFillTile(_DWORD *a1, int a2)
{
__int64 v3; // r2
_DWORD *v7; // [sp+1Ch] [bp-28h]
__int64 v8; // [sp+20h] [bp-24h]
v7 = a1 + 10;
if ( TIFFFillStriles() && a1[44] )
{
if ( (a1[3] & 0x20000) == 0 )
{
v8 = *(_QWORD *)(v7[34] + 8 * a2);
if ( !v8 )
{
TIFFErrorExt(a1[157], (int)"TIFFFillTile", "%llu: Invalid tile byte count, tile %lu", 0LL, a2);
return 0;
}
if ( (a1[3] & 0x800) != 0 && ((a1[3] & *((unsigned __int16 *)v7 + 27)) != 0 || (a1[3] & 0x100) != 0) )
{
if ( (a1[3] & 0x200) != 0 && a1[147] )
{
TIFFfree(a1[147]);
a1[147] = 0;
a1[148] = 0;
}
a1[3] &= ~0x200u;
v3 = (int)a1[154];
if ( HIDWORD(v8) > (int)v3 >> 31
|| HIDWORD(v8) == HIDWORD(v3) && (unsigned int)v8 > (unsigned int)v3
|| *(_QWORD *)(v7[33] + 8 * a2) > (unsigned __int64)((int)a1[154] - v8) )
{
a1[123] = -1;
return 0;
}
a1[148] = v8;
a1[147] = a1[153] + *(_DWORD *)(v7[33] + 8 * a2);
a1[149] = 0;
a1[150] = v8;
a1[3] |= 0x800000u;
}
else
{
if ( HIDWORD(v8) != (int)v8 >> 31 )
{
TIFFErrorExt(a1[157], (int)"TIFFFillTile", "Integer overflow");
return 0;
}
if ( a1[148] < (int)v8 )
{
a1[123] = -1;
if ( (a1[3] & 0x200) == 0 )
{
TIFFErrorExt(a1[157], (int)"TIFFFillTile", "Data buffer too small to hold tile %lu", a2);
return 0;
}
if ( !TIFFReadBufferSetup(a1, 0, v8) )
return 0;
}
if ( (a1[3] & 0x800000) != 0 )
{
a1[123] = -1;
if ( !TIFFReadBufferSetup(a1, 0, v8) )
return 0;
}
if ( sub_6EECA4((int)a1, a2, a1[147], v8, (int)"TIFFFillTile") != (_DWORD)v8 )
return 0;
a1[149] = 0;
a1[150] = v8;
if ( (a1[3] & *((unsigned __int16 *)v7 + 27)) == 0 && (a1[3] & 0x100) == 0 )
TIFFReverseBits(a1[147], a1[150]);
}
}
return sub_6EFA34(a1, a2);
}
return 0;
}