//
// sub_6E6E94 from 0x6e6e94 to 0x6e7220 (908 bytes)
//
// 9 xrefs:
// > TIFFInitPixarLog @ 0x6e7a34
// > TIFFInitPixarLog @ 0x6e7a38
// > TIFFInitPixarLog @ 0x6e7a44
// > TIFFInitPixarLog @ 0x6e7a48
// > TIFFInitPixarLog @ 0x6e7a54
// > TIFFInitPixarLog @ 0x6e7a58
// > ??> @ 0x6e7b68
// > ??> @ 0x6e7b6c
// > ??> @ 0x6e7b70
//
// 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_6E6E94(_DWORD *a1, unsigned __int8 *a2, unsigned int a3)
{
int v3; // r3
_DWORD *v8; // [sp+18h] [bp-1Ch]
int v9; // [sp+1Ch] [bp-18h]
int v10; // [sp+20h] [bp-14h]
signed int v11; // [sp+24h] [bp-10h]
int v12; // [sp+28h] [bp-Ch]
__int16 *v13; // [sp+2Ch] [bp-8h]
v8 = a1 + 10;
v9 = a1[144];
switch ( *(_DWORD *)(v9 + 132) )
{
case 0:
case 1:
v11 = a3;
goto LABEL_5;
case 2:
case 3:
case 4:
v11 = a3 >> 1;
goto LABEL_5;
case 5:
v11 = a3 >> 2;
LABEL_5:
v12 = a1[14] * *(unsigned __int16 *)(v9 + 124);
v10 = 0;
v13 = *(__int16 **)(v9 + 120);
break;
default:
goto LABEL_9;
}
while ( v10 < v11 )
{
v3 = *(_DWORD *)(v9 + 132);
if ( v3 == 4 )
{
sub_6E6230(a2, v12, *(unsigned __int16 *)(v9 + 124), v13, *(_DWORD *)(v9 + 164));
a2 += 2 * v12;
}
else if ( v3 == 5 )
{
sub_6E4B04(
COERCE_DOUBLE(__PAIR64__(v12, (unsigned int)a2)),
*(unsigned __int16 *)(v9 + 124),
v13,
*(_DWORD *)(v9 + 160));
a2 += 4 * v12;
}
else
{
if ( v3 )
{
LABEL_9:
TIFFErrorExt(
a1[157],
(int)"PixarLogEncode",
"%d bit input not supported in PixarLog",
*((unsigned __int16 *)v8 + 22));
return 0;
}
sub_6E6894(a2, v12, *(unsigned __int16 *)(v9 + 124), v13, *(_DWORD *)(v9 + 168));
a2 += v12;
}
v10 += v12;
v13 += v12;
}
*(_DWORD *)(v9 + 64) = *(_DWORD *)(v9 + 120);
*(_DWORD *)(v9 + 68) = 2 * v11;
if ( *(_DWORD *)(v9 + 68) >> 1 == v11 )
{
do
{
if ( j_deflate(v9 + 64, 0) )
{
TIFFErrorExt(a1[157], (int)"PixarLogEncode", "Encoder error: %s", *(const char **)(v9 + 88));
return 0;
}
if ( !*(_DWORD *)(v9 + 80) )
{
a1[152] = a1[148];
TIFFFlushData1(a1);
*(_DWORD *)(v9 + 76) = a1[147];
*(_DWORD *)(v9 + 80) = a1[148];
}
}
while ( *(_DWORD *)(v9 + 68) );
return 1;
}
else
{
TIFFErrorExt(a1[157], (int)"PixarLogEncode", "ZLib cannot deal with buffers this size");
return 0;
}
}