//
// TIFFWriteEncodedTile from 0x6f3f1c to 0x6f4440 (1316 bytes)
//
// 2 xrefs:
// > TIFFWriteTile @ 0x6f3f08
// > ??> @ 0x5898c
//
// 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 TIFFWriteEncodedTile(int a1, unsigned int a2, int a3, int a4)
{
__int64 v5; // r0
__int64 v6; // r2
unsigned int v7; // r3
unsigned int v8; // r3
unsigned __int16 v14; // [sp+1Eh] [bp-16h]
if ( (*(_DWORD *)(a1 + 12) & 0x40) == 0 && !TIFFWriteCheck(a1, 1, "TIFFWriteEncodedTile") )
return -1;
if ( *(_DWORD *)(a1 + 168) > a2 )
{
if ( (*(_DWORD *)(a1 + 12) & 0x10) != 0 && *(_DWORD *)(a1 + 588) || TIFFWriteBufferSetup(a1, 0, -1) )
{
*(_DWORD *)(a1 + 12) |= 0x100000u;
*(_DWORD *)(a1 + 492) = a2;
if ( *(_QWORD *)(*(_DWORD *)(a1 + 176) + 8 * a2) )
{
v5 = *(int *)(a1 + 592);
v6 = *(_QWORD *)(*(_DWORD *)(a1 + 176) + 8 * a2);
if ( (unsigned int)((int)v5 >> 31) <= HIDWORD(v6)
&& (HIDWORD(v5) != HIDWORD(v6) || (unsigned int)v5 <= (unsigned int)v6)
&& !TIFFWriteBufferSetup(
a1,
0,
(unsigned int)((*(_QWORD *)(*(_DWORD *)(a1 + 176) + 8 * a2) + 1024LL) >> 10) << 10) )
{
return -1;
}
*(_QWORD *)(a1 + 456) = 0;
}
*(_DWORD *)(a1 + 608) = 0;
*(_DWORD *)(a1 + 604) = *(_DWORD *)(a1 + 588);
if ( *(_DWORD *)(a1 + 60) >= (unsigned int)-*(_DWORD *)(a1 + 72) )
v7 = 0;
else
v7 = (unsigned int)(*(_DWORD *)(a1 + 60) + *(_DWORD *)(a1 + 72) - 1) / *(_DWORD *)(a1 + 72);
*(_DWORD *)(a1 + 444) = *(_DWORD *)(a1 + 72) * (a2 % v7);
if ( *(_DWORD *)(a1 + 56) >= (unsigned int)-*(_DWORD *)(a1 + 68) )
v8 = 0;
else
v8 = (unsigned int)(*(_DWORD *)(a1 + 56) + *(_DWORD *)(a1 + 68) - 1) / *(_DWORD *)(a1 + 68);
*(_DWORD *)(a1 + 488) = *(_DWORD *)(a1 + 68) * (a2 % v8);
if ( (*(_DWORD *)(a1 + 12) & 0x20) == 0 )
{
if ( !(*(int (__fastcall **)(int))(a1 + 516))(a1) )
return -1;
*(_DWORD *)(a1 + 12) |= 0x20u;
}
*(_DWORD *)(a1 + 12) &= ~0x1000u;
v14 = a2 / *(_DWORD *)(a1 + 164);
if ( (*(int (__fastcall **)(int, _DWORD))(a1 + 524))(a1, v14) )
{
if ( a4 <= 0 || *(_DWORD *)(a1 + 496) < a4 )
a4 = *(_DWORD *)(a1 + 496);
(*(void (__fastcall **)(int, int, int))(a1 + 652))(a1, a3, a4);
if ( (*(int (__fastcall **)(int, int, int, _DWORD))(a1 + 552))(a1, a3, a4, v14) )
{
if ( (*(int (__fastcall **)(int))(a1 + 528))(a1) )
{
if ( (*(_DWORD *)(a1 + 12) & *(unsigned __int16 *)(a1 + 94)) == 0 && (*(_DWORD *)(a1 + 12) & 0x100) == 0 )
TIFFReverseBits(*(unsigned __int8 **)(a1 + 588), *(_DWORD *)(a1 + 608));
if ( *(int *)(a1 + 608) <= 0 || sub_6F4D98(a1, a2, *(_DWORD *)(a1 + 588), *(_DWORD *)(a1 + 608)) )
{
*(_DWORD *)(a1 + 608) = 0;
*(_DWORD *)(a1 + 604) = *(_DWORD *)(a1 + 588);
return a4;
}
else
{
return -1;
}
}
else
{
return -1;
}
}
else
{
return 0;
}
}
else
{
return -1;
}
}
else
{
return -1;
}
}
else
{
TIFFErrorExt(
*(_DWORD *)(a1 + 628),
(int)"TIFFWriteEncodedTile",
"Tile %lu out of range, max %lu",
a2,
*(_DWORD *)(a1 + 168));
return -1;
}
}