//
// sub_6E1354 from 0x6e1354 to 0x6e164c (760 bytes)
//
// 9 xrefs:
// > TIFFInitPackBits @ 0x6e1684
// > TIFFInitPackBits @ 0x6e1688
// > TIFFInitPackBits @ 0x6e1694
// > TIFFInitPackBits @ 0x6e1698
// > TIFFInitPackBits @ 0x6e16a4
// > TIFFInitPackBits @ 0x6e16a8
// > ??> @ 0x6e1714
// > ??> @ 0x6e1718
// > ??> @ 0x6e171c
//
// 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_6E1354(_DWORD *a1, _BYTE *a2, int a3)
{
char *v9; // [sp+10h] [bp-14h]
int v10; // [sp+14h] [bp-10h]
int v11; // [sp+18h] [bp-Ch]
int v12; // [sp+18h] [bp-Ch]
int v13; // [sp+18h] [bp-Ch]
char v14; // [sp+1Ch] [bp-8h]
v9 = (char *)a1[151];
v10 = a1[152];
while ( v10 > 0 && a3 > 0 )
{
v11 = (unsigned __int8)*v9++;
--v10;
if ( v11 > 127 )
v11 -= 256;
if ( v11 >= 0 )
{
if ( v11 + 1 > a3 )
{
TIFFWarningExt(a1[157], "PackBitsDecode", "Discarding %lu bytes to avoid buffer overrun", v11 - a3 + 1);
v11 = a3 - 1;
}
if ( v11 + 1 > v10 )
{
TIFFWarningExt(a1[157], "PackBitsDecode", "Terminating PackBitsDecode due to lack of data.");
break;
}
v13 = v11 + 1;
TIFFmemcpy(a2, v9, v13);
a2 += v13;
a3 -= v13;
v9 += v13;
v10 -= v13;
}
else if ( v11 != -128 )
{
v12 = 1 - v11;
if ( a3 < v12 )
{
TIFFWarningExt(a1[157], "PackBitsDecode", "Discarding %lu bytes to avoid buffer overrun", v12 - a3);
v12 = a3;
}
a3 -= v12;
v14 = *v9++;
--v10;
while ( v12-- > 0 )
*a2++ = v14;
}
}
a1[151] = v9;
a1[152] = v10;
if ( a3 <= 0 )
return 1;
TIFFErrorExt(a1[157], (int)"PackBitsDecode", "Not enough data for scanline %lu", a1[111]);
return 0;
}