//
// sub_6E41CC from 0x6e41cc to 0x6e4774 (1448 bytes)
//
// 9 xrefs:
// > TIFFInitPixarLog @ 0x6e79d4
// > TIFFInitPixarLog @ 0x6e79d8
// > TIFFInitPixarLog @ 0x6e79e4
// > TIFFInitPixarLog @ 0x6e79e8
// > TIFFInitPixarLog @ 0x6e79f4
// > TIFFInitPixarLog @ 0x6e79f8
// > ??> @ 0x6e7b50
// > ??> @ 0x6e7b54
// > ??> @ 0x6e7b58
//
// 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_6E41CC(int a1, __int16 *a2, unsigned int a3)
{
int v7; // [sp+1Ch] [bp-20h]
int v8; // [sp+20h] [bp-1Ch]
int v9; // [sp+24h] [bp-18h]
signed int v10; // [sp+28h] [bp-14h]
int v11; // [sp+2Ch] [bp-10h]
unsigned __int16 *v12; // [sp+30h] [bp-Ch]
int v13; // [sp+34h] [bp-8h]
v7 = a1 + 40;
v8 = *(_DWORD *)(a1 + 576);
switch ( *(_DWORD *)(v8 + 132) )
{
case 0:
case 1:
v10 = a3;
goto LABEL_6;
case 2:
case 3:
case 4:
v10 = a3 >> 1;
goto LABEL_6;
case 5:
v10 = a3 >> 2;
LABEL_6:
v11 = *(_DWORD *)(a1 + 56) * *(unsigned __int16 *)(v8 + 124);
if ( !v8 )
_assert2();
*(_DWORD *)(v8 + 76) = *(_DWORD *)(v8 + 120);
*(_DWORD *)(v8 + 80) = 2 * v10;
if ( *(_DWORD *)(v8 + 80) != 2 * v10 )
{
TIFFErrorExt(*(_DWORD *)(a1 + 628), (int)"PixarLogDecode", "ZLib cannot deal with buffers this size");
return 0;
}
break;
default:
TIFFErrorExt(
*(_DWORD *)(a1 + 628),
(int)"PixarLogDecode",
"%d bit input not supported in PixarLog",
*(unsigned __int16 *)(a1 + 84));
return 0;
}
do
{
v13 = j_inflate(v8 + 64, 1);
if ( v13 == 1 )
break;
if ( v13 == -3 )
{
TIFFErrorExt(
*(_DWORD *)(a1 + 628),
(int)"PixarLogDecode",
"Decoding error at scanline %lu, %s",
*(_DWORD *)(a1 + 444),
*(const char **)(v8 + 88));
if ( j_inflateSync(v8 + 64) )
return 0;
}
else if ( v13 )
{
TIFFErrorExt(*(_DWORD *)(a1 + 628), (int)"PixarLogDecode", "ZLib error: %s", *(const char **)(v8 + 88));
return 0;
}
}
while ( *(_DWORD *)(v8 + 80) );
if ( *(_DWORD *)(v8 + 80) )
{
TIFFErrorExt(
*(_DWORD *)(a1 + 628),
(int)"PixarLogDecode",
"Not enough data at scanline %lu (short %llu bytes)",
*(_DWORD *)(a1 + 444),
(unsigned __int64)*(unsigned int *)(v8 + 80));
return 0;
}
else
{
v12 = *(unsigned __int16 **)(v8 + 120);
if ( (*(_DWORD *)(a1 + 12) & 0x80) != 0 )
TIFFSwabArrayOfShort(v12, v10);
if ( v10 % v11 )
{
TIFFWarningExt(
*(_DWORD *)(a1 + 628),
"PixarLogDecode",
"stride %lu is not a multiple of sample count, %lu, data truncated.",
v11,
v10);
v10 -= v10 % v11;
}
v9 = 0;
while ( 2 )
{
if ( v9 < v10 )
{
switch ( *(_DWORD *)(v8 + 132) )
{
case 0:
sub_6E2C1C(v12, v11, *(unsigned __int16 *)(v8 + 124), a2, *(_DWORD *)(v8 + 156));
a2 = (__int16 *)((char *)a2 + v11);
goto LABEL_32;
case 1:
sub_6E303C(v12, v11, *(unsigned __int16 *)(v8 + 124), a2, *(_DWORD *)(v8 + 156));
a2 = (__int16 *)((char *)a2 + v11);
goto LABEL_32;
case 2:
sub_6E283C(v12, v11, *(unsigned __int16 *)(v8 + 124), a2);
a2 += v11;
goto LABEL_32;
case 3:
sub_6E1BA0(v12, v11, *(unsigned __int16 *)(v8 + 124), a2, *(_DWORD *)(v8 + 148));
a2 += v11;
goto LABEL_32;
case 4:
sub_6E23DC(v12, v11, *(unsigned __int16 *)(v8 + 124), a2, *(_DWORD *)(v8 + 152));
a2 += v11;
goto LABEL_32;
case 5:
sub_6E1738(v12, v11, *(unsigned __int16 *)(v8 + 124), a2, *(_DWORD *)(v8 + 148));
a2 += 2 * v11;
LABEL_32:
v9 += v11;
v12 += v11;
continue;
default:
TIFFErrorExt(
*(_DWORD *)(a1 + 628),
(int)"PixarLogDecode",
"Unsupported bits/sample: %d",
*(unsigned __int16 *)(v7 + 44));
return 0;
}
}
return 1;
}
}
}