//
// sub_654424 from 0x654424 to 0x6555ae (4490 bytes)
//
// 0 xrefs:
//
// 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_654424(int ***a1)
{
int ***v1; // r4
int *v2; // r6
int v3; // r3
int v4; // r2
int v5; // r2
int **v6; // r3
unsigned int v7; // r11
__int16 v8; // r3
int v9; // r1
unsigned int v10; // r10
int v11; // r6
unsigned int v12; // r5
unsigned int v13; // r10
unsigned __int8 *v14; // r7
bool v15; // r8
_BYTE *v16; // r3
_BYTE *v17; // r9
unsigned int v18; // r6
int v19; // r11
int v20; // r3
unsigned int v22; // r0
int v23; // r2
int v24; // r1
unsigned int v25; // r3
unsigned int v26; // r1
unsigned int v27; // r3
unsigned int v28; // r8
unsigned int v29; // r11
unsigned int j; // r10
int k; // r6
unsigned int v32; // r1
unsigned int v33; // r7
unsigned int v34; // r3
unsigned int v35; // r3
int v36; // r7
unsigned int v37; // r6
unsigned int v38; // r10
_BOOL4 v40; // r3
bool v41; // zf
unsigned int v42; // r1
unsigned int n; // r5
unsigned int v44; // r1
unsigned int v45; // r2
unsigned int v46; // r3
int v47; // r3
unsigned int i; // r7
unsigned int v49; // r1
unsigned int v50; // r2
unsigned int v51; // r3
bool v52; // zf
unsigned int v53; // r3
int v54; // r3
int m; // r1
int v56; // lr
_BOOL4 v57; // r6
unsigned __int16 v58; // r7
int v59; // r3
int v60; // r2
int *v61; // r3
int v62; // r3
unsigned int v63; // r6
int v64; // lr
int v65; // r3
unsigned int v66; // r6
int v67; // r7
unsigned int v68; // r0
unsigned int v69; // r3
size_t v70; // r6
__int16 v71; // r3
__int16 v72; // r2
__int16 v73; // r1
unsigned int v74; // r8
unsigned int v75; // r5
int v76; // r3
unsigned int v77; // r1
unsigned int v78; // r3
unsigned int v79; // r2
unsigned int v80; // r0
unsigned int v81; // r8
unsigned int v82; // r10
unsigned int v83; // r5
unsigned int v84; // r10
unsigned int v85; // r7
unsigned int v86; // r11
unsigned int v87; // r1
int v88; // r6
int v89; // r7
int v90; // r3
int v91; // r8
__int64 v92; // r2
unsigned int v93; // r10
int v94; // r3
int v95; // r7
int v96; // r6
int v97; // r3
int v98; // r7
unsigned int v99; // r1
int v100; // r4
unsigned int v101; // r10
int v102; // r4
int v103; // r2
unsigned int v104; // r6
int v105; // r3
int v106; // r12
int v107; // r3
int v108; // r10
unsigned int v109; // r11
int **v110; // r7
int **v111; // r3
int v112; // r8
int v113; // r5
int v114; // r0
unsigned int v115; // r0
unsigned int v116; // r5
unsigned int v117; // r6
int v118; // r3
int v119; // r1
int *v120; // r2
unsigned int v121; // r3
int v122; // r7
int v123; // r12
int v124; // lr
unsigned int v125; // r3
int **v126; // r2
int v127; // r7
int v128; // r2
int v129; // r7
int v130; // r2
int v131; // r2
int v132; // r9
int v133; // r7
int v134; // r2
unsigned int v135; // r3
int v136; // r7
unsigned int v137; // r2
int v138; // r0
int v139; // r0
int v140; // r2
unsigned int v141; // r3
int v142; // r2
unsigned int v143; // r3
unsigned int v144; // [sp+0h] [bp-5Ch]
unsigned int v145; // [sp+0h] [bp-5Ch]
unsigned int v146; // [sp+0h] [bp-5Ch]
unsigned int v147; // [sp+0h] [bp-5Ch]
unsigned int v148; // [sp+0h] [bp-5Ch]
unsigned int v149; // [sp+4h] [bp-58h]
int v150; // [sp+10h] [bp-4Ch]
int **v151; // [sp+14h] [bp-48h]
int v152; // [sp+18h] [bp-44h]
unsigned int v153; // [sp+18h] [bp-44h]
int v154; // [sp+18h] [bp-44h]
int v155; // [sp+1Ch] [bp-40h]
unsigned int v156; // [sp+1Ch] [bp-40h]
unsigned int v157; // [sp+1Ch] [bp-40h]
int v158; // [sp+1Ch] [bp-40h]
int v159; // [sp+20h] [bp-3Ch]
int v160; // [sp+20h] [bp-3Ch]
unsigned int v161; // [sp+24h] [bp-38h]
unsigned int v162; // [sp+24h] [bp-38h]
int v163; // [sp+24h] [bp-38h]
int v164; // [sp+24h] [bp-38h]
unsigned int v165; // [sp+28h] [bp-34h]
int ***v166; // [sp+2Ch] [bp-30h]
int v167; // [sp+30h] [bp-2Ch]
int v168; // [sp+30h] [bp-2Ch]
int v169; // [sp+34h] [bp-28h]
int v170; // [sp+34h] [bp-28h]
int v171; // [sp+38h] [bp-24h]
int v172; // [sp+38h] [bp-24h]
int v173; // [sp+3Ch] [bp-20h]
unsigned int v174; // [sp+44h] [bp-18h]
_BYTE v175[2]; // [sp+4Ch] [bp-10h] BYREF
__int16 v176; // [sp+4Eh] [bp-Eh]
__int16 v177; // [sp+50h] [bp-Ch]
__int16 v178; // [sp+52h] [bp-Ah]
__int16 v179; // [sp+54h] [bp-8h]
v1 = a1;
v151 = *a1;
v2 = (*a1)[4];
v3 = ***a1;
if ( ((unsigned __int8)v2 & 4) != 0 )
v4 = 2;
else
v4 = 1;
v155 = v4;
v5 = *(unsigned __int8 *)(v3 + 535);
v150 = ***a1;
if ( ((v5 & 4) != 0 || *(_WORD *)(v3 + 528)) && ((unsigned __int8)v2 & 1) == 0 )
{
if ( v155 == 2 )
{
v7 = (unsigned int)(*a1)[4] & 1;
v152 = v7;
v159 = v7;
}
else
{
v6 = a1[4];
if ( !v6 )
png_error(v150, "a background color must be supplied to remove alpha/transparency");
v152 = *((unsigned __int8 *)v6 + 1);
if ( ((unsigned __int8)v2 & 2) != 0 )
{
v7 = *((unsigned __int8 *)v6 + 2);
v159 = *(unsigned __int8 *)v6;
}
else
{
v7 = *((unsigned __int8 *)v6 + 1);
v159 = v7;
}
}
}
else if ( v155 == 2 )
{
v7 = 0xFFFF;
v152 = 0xFFFF;
v159 = 0xFFFF;
}
else
{
v7 = 255;
v152 = 255;
v159 = 255;
}
v8 = *(_WORD *)(v150 + 998);
if ( (v8 & 1) == 0 )
{
if ( *(_BYTE *)(v150 + 536) == 16 )
{
v9 = 45455;
if ( ((unsigned int)v151[5] & 4) == 0 )
v9 = 100000;
}
else
{
v9 = 45455;
}
*(_DWORD *)(v150 + 924) = v9;
*(_WORD *)(v150 + 998) = v8 | 1;
}
switch ( v5 )
{
case 0:
v35 = *(unsigned __int8 *)(v150 + 536);
if ( v35 > 8 )
{
if ( (unsigned int)v151[6] <= 0xFF )
png_error(v150, "gray[16] color-map: too few entries");
for ( i = 0; i != 256; ++i )
{
v145 = i;
v49 = i;
v50 = i;
v51 = i;
sub_6535E0(v1, v49, v50, v51, v145, 1);
}
if ( !*(_WORD *)(v150 + 528) )
goto LABEL_159;
if ( ((unsigned __int8)v2 & 1) != 0 )
{
v53 = 0;
}
else
{
v52 = v152 == v7;
if ( v152 == v7 )
v52 = v159 == v152;
v47 = v155;
if ( v52 )
{
LABEL_96:
if ( v47 == 2 )
{
v134 = v152;
v146 = v152;
v135 = v152;
v152 = (unsigned __int8)((unsigned __int16)(png_sRGB_base[(unsigned int)(255 * v152) >> 15]
+ ((((255 * v152) & 0x7FFF)
* (unsigned int)png_sRGB_delta[(unsigned int)(255 * v152) >> 15]) >> 12)) >> 8);
sub_653BE8((unsigned int)v1, v152, v134, v135, v146, 0xFFFFu, v155);
}
v10 = 256;
v175[0] = 0;
v11 = 0;
v178 = v152;
v12 = 256;
v177 = v152;
v176 = v152;
v179 = v152;
png_set_background_fixed(v150, v175, 1, 0, 0);
goto LABEL_57;
}
v53 = 0xFFFF;
if ( v155 != 2 )
v53 = 255;
}
v11 = 2;
v12 = 256;
v10 = 254;
sub_653BE8((unsigned int)v1, 0xFEu, v159, v152, v7, v53, v155);
goto LABEL_169;
}
v12 = 1 << v35;
if ( 1 << v35 > (unsigned int)v151[6] )
png_error(v150, "gray[8] color-map: too few entries");
if ( *(_WORD *)(v150 + 528) )
{
v36 = *(unsigned __int16 *)(v150 + 640);
if ( ((unsigned __int8)v2 & 1) != 0 )
{
v162 = 0;
}
else
{
v90 = 0xFFFF;
if ( v155 != 2 )
v90 = 255;
v162 = v90;
}
}
else
{
v162 = *(unsigned __int16 *)(v150 + 528);
v36 = 256;
}
v37 = 0;
v38 = 0;
do
{
if ( v38 == v36 )
sub_653BE8((unsigned int)v1, v38, v159, v152, v7, v162, v155);
else
sub_6535E0(v1, v38, v37, v37, v37, 3);
++v38;
v37 += 0xFF / (v12 - 1);
}
while ( v38 != v12 );
goto LABEL_42;
case 2:
case 6:
if ( ((unsigned __int8)v2 & 2) != 0 )
{
if ( v5 != 6 && !*(_WORD *)(v150 + 528) )
{
if ( (unsigned int)v151[6] <= 0xD7 )
png_error(v150, "rgb color-map: too few entries");
v28 = *(unsigned __int16 *)(v150 + 528);
v12 = v28;
do
{
v29 = v12;
for ( j = 0; j != 306; j += 51 )
{
for ( k = 0; k != 6; ++k )
{
v32 = k + v29;
v33 = 51 * k;
sub_6535E0(v1, v32, v28, j, v33, 1);
}
v29 += 6;
}
v12 += 36;
v28 += 51;
}
while ( v12 != 216 );
v10 = 256;
v11 = 3;
goto LABEL_57;
}
if ( ((unsigned __int8)v2 & 1) != 0 )
{
if ( (unsigned int)v151[6] <= 0xF3 )
png_error(v150, "rgb+alpha color-map: too few entries");
v81 = 0;
v82 = sub_654058(a1);
sub_6532D4(v1, v82, 0xFFu, 0xFFu, 255, 0);
v157 = v82;
v83 = v82 + 10;
v153 = v82 + 37;
do
{
v84 = v83 - 9;
v85 = 0;
do
{
v86 = v84 + 3;
v87 = v84;
v88 = 0;
do
{
++v84;
sub_6532D4(v1, v87, v81, v85, v88, 128);
v88 = (2 * v88) | 0x7F;
v87 = v84;
}
while ( v84 != v86 );
v85 = (2 * v85) | 0x7F;
}
while ( v83 != v84 );
v83 = v84 + 9;
v81 = (2 * v81) | 0x7F;
}
while ( v84 + 9 != v153 );
v12 = v84;
v10 = v157;
v11 = 4;
}
else
{
v70 = (((unsigned __int8)v2 & 3) + 1) * (((unsigned __int8)((unsigned __int8)v2 & 4) >> 2) + 1);
if ( (unsigned int)v151[6] <= 0xF3 )
png_error(v150, "rgb-alpha color-map: too few entries");
v12 = sub_654058(a1);
sub_653BE8((unsigned int)v1, v12, v159, v152, v7, 0, v155);
if ( v155 == 2 )
{
v72 = (unsigned __int8)((unsigned __int16)(png_sRGB_base[(unsigned int)(255 * v159) >> 15]
+ ((((255 * v159) & 0x7FFF)
* (unsigned int)png_sRGB_delta[(unsigned int)(255 * v159) >> 15]) >> 12)) >> 8);
v71 = (unsigned __int8)((unsigned __int16)(png_sRGB_base[(unsigned int)(255 * v152) >> 15]
+ ((((255 * v152) & 0x7FFF)
* (unsigned int)png_sRGB_delta[(unsigned int)(255 * v152) >> 15]) >> 12)) >> 8);
v73 = (unsigned __int8)((unsigned __int16)(png_sRGB_base[(255 * v7) >> 15]
+ ((((255 * v7) & 0x7FFF) * png_sRGB_delta[(255 * v7) >> 15]) >> 12)) >> 8);
}
else
{
v71 = v152;
v72 = v159;
v73 = v152;
}
if ( !memcmp(
(char *)v1[3] + v70 * v12,
(char *)v1[3]
+ v70
* (unsigned __int8)(((unsigned __int16)(5 * v73 + 130) >> 8)
+ 6
* (((unsigned __int16)(5 * v71 + 130) >> 8)
+ 6 * ((unsigned __int16)(5 * v72 + 130) >> 8))),
v70) )
{
v177 = v152;
v10 = 256;
v179 = v152;
v175[0] = 0;
v11 = 3;
v178 = v7;
v176 = v159;
png_set_background_fixed(v150, v175, 1, 0, 0);
goto LABEL_57;
}
v169 = 3;
v167 = 0;
v74 = v12 + 1;
v174 = v12;
do
{
v171 = 3;
v163 = 0;
v173 = png_sRGB_table[v167] << 7;
do
{
v75 = 0;
do
{
++v74;
v76 = v159;
if ( v155 != 2 )
v76 = png_sRGB_table[v159];
while ( 1 )
{
v77 = v74 - 1;
v78 = 127 * v76 + v173;
if ( v155 != 2 )
break;
v136 = png_sRGB_table[v75];
v75 = (2 * v75) | 0x7F;
v137 = 257 * (127 * v152 + (png_sRGB_table[v163] << 7));
sub_653BE8(
(unsigned int)v1,
v77,
(257 * v78 + 0x8000 + ((257 * v78) >> 16)) >> 16,
(v137 + 0x8000 + HIWORD(v137)) >> 16,
(257 * (127 * v7 + (v136 << 7)) + 0x8000 + ((257 * (127 * v7 + (v136 << 7))) >> 16)) >> 16,
0,
2);
if ( v75 > 0xFF )
goto LABEL_153;
++v74;
v76 = v159;
}
v79 = 127 * png_sRGB_table[v7] + (png_sRGB_table[v75] << 7);
v80 = 127 * png_sRGB_table[v152] + (png_sRGB_table[v163] << 7);
v75 = (2 * v75) | 0x7F;
sub_653BE8(
(unsigned int)v1,
v77,
(unsigned __int16)(png_sRGB_base[v78 >> 15] + (((v78 & 0x7FFF) * png_sRGB_delta[v78 >> 15]) >> 12)) >> 8,
(unsigned __int16)(png_sRGB_base[v80 >> 15] + (((v80 & 0x7FFF) * png_sRGB_delta[v80 >> 15]) >> 12)) >> 8,
(unsigned __int16)(png_sRGB_base[v79 >> 15] + (((v79 & 0x7FFF) * png_sRGB_delta[v79 >> 15]) >> 12)) >> 8,
0,
1);
}
while ( v75 <= 0xFF );
LABEL_153:
v163 = (2 * v163) | 0x7F;
--v171;
}
while ( v171 );
v167 = (2 * v167) | 0x7F;
--v169;
}
while ( v169 );
v11 = 4;
v10 = v174;
v12 = v74;
}
goto LABEL_169;
}
png_set_rgb_to_gray_fixed(v150, 1, -1, -1);
v54 = *(unsigned __int8 *)(v150 + 535);
if ( v54 == 6 || *(_WORD *)(v150 + 528) )
{
if ( ((unsigned __int8)v2 & 1) != 0 )
{
if ( (unsigned int)v151[6] <= 0xFF )
png_error(v150, "rgb[ga] color-map: too few entries");
v10 = 231;
v11 = 1;
v12 = sub_654280(v1);
LABEL_169:
if ( !*(_WORD *)(v150 + 528) || (*(_BYTE *)(v150 + 535) & 4) != 0 )
goto LABEL_57;
v89 = 1;
goto LABEL_172;
}
if ( (unsigned int)v151[6] <= 0xFF )
LABEL_301:
png_error(v150, "rgb[gray] color-map: too few entries");
if ( v54 != 6 && !*(_WORD *)(v150 + 528) )
goto LABEL_114;
v107 = *(_DWORD *)(v150 + 924);
if ( v107 <= 99999 && (!v107 || !png_gamma_significant((11 * v107 + 2) / 5)) )
goto LABEL_114;
v108 = 0;
v109 = 0;
while ( 1 )
{
v110 = *v1;
v111 = v1[8];
if ( ((unsigned int)(*v1)[4] & 4) != 0 )
v112 = 2;
else
v112 = 1;
if ( !v111 )
{
v113 = *(_DWORD *)(**v110 + 924);
if ( !png_gamma_significant(v113) )
{
v1[8] = (int **)byte_4;
goto LABEL_230;
}
if ( v113 <= (int)&stru_1869C.st_name + 3 && (!v113 || !png_gamma_significant((11 * v113 + 2) / 5)) )
{
v1[8] = (int **)(&dword_0 + 1);
LABEL_264:
if ( v112 != 2 )
{
v115 = v109;
v116 = v109;
v117 = v109;
goto LABEL_268;
}
v117 = png_sRGB_table[v109];
v115 = v117;
v116 = v117;
goto LABEL_231;
}
v1[8] = (int **)(&dword_0 + 3);
v114 = png_reciprocal(v113);
v111 = v1[8];
v1[9] = (int **)v114;
}
if ( v111 == (int **)((char *)&dword_0 + 3) )
{
v132 = (int)v1[9];
v117 = png_gamma_16bit_correct(v108, v132);
v116 = png_gamma_16bit_correct(v108, v132);
v115 = png_gamma_16bit_correct(v108, v132);
if ( v112 != 2 )
{
v117 = (unsigned __int8)((unsigned __int16)(png_sRGB_base[(255 * v117) >> 15]
+ ((((255 * v117) & 0x7FFF) * png_sRGB_delta[(255 * v117) >> 15]) >> 12)) >> 8);
v116 = (unsigned __int8)((unsigned __int16)(png_sRGB_base[(255 * v116) >> 15]
+ ((((255 * (_WORD)v116) & 0x7FFF)
* (unsigned int)png_sRGB_delta[(255 * v116) >> 15]) >> 12)) >> 8);
v115 = (unsigned __int8)((unsigned __int16)(png_sRGB_base[(255 * v115) >> 15]
+ ((((255 * v115) & 0x7FFF) * png_sRGB_delta[(255 * v115) >> 15]) >> 12)) >> 8);
LABEL_268:
v119 = 255;
goto LABEL_234;
}
goto LABEL_231;
}
if ( v111 != (int **)byte_4 )
{
if ( v111 != (int **)((char *)&dword_0 + 1) )
{
if ( v111 != (int **)((char *)&dword_0 + 2) )
png_error(**v110, "bad encoding (internal error)");
v115 = v109;
v116 = v109;
v117 = v109;
v118 = 1;
v119 = 255;
goto LABEL_232;
}
goto LABEL_264;
}
LABEL_230:
v115 = v108;
v116 = v108;
v117 = v108;
LABEL_231:
v118 = 255;
v119 = 0xFFFF;
LABEL_232:
if ( v112 == 1 )
{
v119 = v118;
v117 = (unsigned __int8)((unsigned __int16)(png_sRGB_base[(255 * v117) >> 15]
+ ((((255 * v117) & 0x7FFF) * png_sRGB_delta[(255 * v117) >> 15]) >> 12)) >> 8);
v116 = (unsigned __int8)((unsigned __int16)(png_sRGB_base[(255 * v116) >> 15]
+ ((((255 * v116) & 0x7FFF) * png_sRGB_delta[(255 * v116) >> 15]) >> 12)) >> 8);
v115 = (unsigned __int8)((unsigned __int16)(png_sRGB_base[(255 * v115) >> 15]
+ ((((255 * v115) & 0x7FFF) * png_sRGB_delta[(255 * v115) >> 15]) >> 12)) >> 8);
}
LABEL_234:
v120 = v110[4];
v121 = __clz(((unsigned __int8)v120 & 0x21) - 33);
v122 = (unsigned __int8)v120 & 3;
if ( ((unsigned __int8)v120 & 0x10) != 0 )
v123 = 0;
else
v123 = 2;
if ( ((unsigned __int8)v120 & 0x10) != 0 )
v124 = 2;
else
v124 = 0;
v125 = v121 >> 5;
v126 = v1[3];
v127 = v122 + 1;
if ( v112 == 2 )
{
v131 = (int)v126 + v109 * 2 * v127;
switch ( v127 )
{
case 3:
goto LABEL_273;
case 4:
if ( v125 )
v133 = 0;
else
v133 = 6;
*(_WORD *)(v131 + v133) = v119;
LABEL_273:
if ( v119 != 0xFFFF )
{
v115 = (v119 * v115 + 0x7FFF) / 0xFFFF;
v116 = (v119 * v116 + 0x7FFF) / 0xFFFF;
v117 = (v119 * v117 + 0x7FFF) / 0xFFFF;
}
*(_WORD *)(v131 + 2 * (v123 + v125)) = v115;
*(_WORD *)(v131 + 2 * (v125 + 1)) = v116;
*(_WORD *)(v131 + 2 * (v124 + v125)) = v117;
goto LABEL_246;
case 2:
*(_WORD *)(v131 + 2 * (v125 ^ 1)) = v119;
break;
}
if ( v119 != 0xFFFF )
v116 = (v119 * v116 + 0x7FFF) / 0xFFFF;
*(_WORD *)(v131 + 2 * v125) = v116;
}
else
{
v128 = (int)v126 + v127 * v109;
if ( v127 != 3 )
{
if ( v127 != 4 )
{
if ( v127 == 2 )
*(_BYTE *)(v128 + (v125 ^ 1)) = v119;
*(_BYTE *)(v128 + v125) = v116;
goto LABEL_246;
}
if ( v125 )
v129 = 0;
else
v129 = 3;
*(_BYTE *)(v128 + v129) = v119;
}
v130 = v128 + v125;
*(_BYTE *)(v130 + v123) = v115;
*(_BYTE *)(v130 + 1) = v116;
*(_BYTE *)(v130 + v124) = v117;
}
LABEL_246:
++v109;
v108 += 257;
if ( v109 == 256 )
{
if ( *(_BYTE *)(v150 + 535) != 6 )
{
v11 = *(unsigned __int16 *)(v150 + 528);
if ( !*(_WORD *)(v150 + 528) )
{
v10 = 256;
v12 = 256;
v34 = *(unsigned __int8 *)(v150 + 536);
goto LABEL_58;
}
}
if ( v155 == 1 )
v138 = png_sRGB_table[v152];
else
v138 = v152;
v89 = 3;
v139 = png_gamma_16bit_correct(v138, *(_DWORD *)(v150 + 924));
v140 = v152;
v147 = v152;
v141 = v152;
v152 = (unsigned int)(255 * v139 + 32895) >> 16;
sub_653BE8((unsigned int)v1, v152, v140, v141, v147, 0, v155);
LABEL_282:
v11 = 0;
v175[0] = 0;
v178 = v152;
v177 = v152;
v176 = v152;
v179 = v152;
png_set_background_fixed(v150, v175, 1, 0, 0);
if ( !*(_WORD *)(v150 + 528) )
{
v10 = 256;
v11 = *(unsigned __int16 *)(v150 + 528);
v12 = 256;
goto LABEL_173;
}
v10 = 256;
v12 = 256;
if ( (*(_BYTE *)(v150 + 535) & 4) != 0 )
goto LABEL_173;
v11 = *(_BYTE *)(v150 + 535) & 4;
v12 = 256;
LABEL_172:
png_set_tRNS_to_alpha(v150);
LABEL_173:
if ( v89 == 1 )
goto LABEL_57;
v34 = *(unsigned __int8 *)(v150 + 536);
goto LABEL_58;
}
}
}
if ( (unsigned int)v151[6] <= 0xFF )
goto LABEL_301;
LABEL_114:
for ( m = 0; m != 256; ++m )
{
v61 = (*v1)[4];
if ( ((unsigned __int8)v61 & 4) != 0 )
{
v56 = (unsigned int)(*v1)[4] & 0x10;
v57 = ((unsigned int)(*v1)[4] & 0x21) == 33;
v58 = png_sRGB_table[m];
if ( ((unsigned __int8)v61 & 0x10) != 0 )
{
v59 = ((unsigned int)(*v1)[4] & 3) + 1;
v60 = (int)v1[3] + m * 2 * v59;
if ( ((unsigned int)(*v1)[4] & 3) == 2 )
{
v105 = 0;
v56 = 2;
goto LABEL_206;
}
if ( ((unsigned int)(*v1)[4] & 3) == 3 )
{
v105 = 0;
v56 = 2;
LABEL_202:
if ( ((unsigned int)(*v1)[4] & 0x21) == 0x21 )
v106 = 0;
else
v106 = 6;
*(_WORD *)(v60 + v106) = -1;
LABEL_206:
*(_WORD *)(v60 + 2 * (v105 + v57)) = v58;
*(_WORD *)(v60 + 2 * (v57 + 1)) = v58;
*(_WORD *)(v60 + 2 * (v56 + v57)) = v58;
continue;
}
}
else
{
v59 = ((unsigned int)(*v1)[4] & 3) + 1;
v60 = (int)v1[3] + m * 2 * v59;
if ( ((unsigned int)(*v1)[4] & 3) == 2 )
{
v105 = 2;
goto LABEL_206;
}
if ( ((unsigned int)(*v1)[4] & 3) == 3 )
{
v105 = 2;
goto LABEL_202;
}
}
if ( v59 == 2 )
*(_WORD *)(v60 + 2 * (((unsigned int)(*v1)[4] & 0x21) != 33)) = -1;
*(_WORD *)(v60 + 2 * v57) = v58;
}
else
{
v62 = (unsigned int)(*v1)[4] & 0x10;
v63 = __clz(((unsigned int)(*v1)[4] & 0x21) - 33);
if ( v62 )
v64 = 0;
else
v64 = 2;
if ( v62 )
v65 = 2;
else
v65 = 0;
v66 = v63 >> 5;
v67 = (int)v1[3] + (((unsigned int)(*v1)[4] & 3) + 1) * m;
switch ( (unsigned int)(*v1)[4] & 3 )
{
case 2u:
goto LABEL_198;
case 3u:
if ( v66 )
v103 = 0;
else
v103 = 3;
*(_BYTE *)(v67 + v103) = -1;
LABEL_198:
v104 = v66 + v67;
*(_BYTE *)(v104 + v64) = m;
*(_BYTE *)(v104 + 1) = m;
*(_BYTE *)(v104 + v65) = m;
continue;
case 1u:
*(_BYTE *)(v67 + (v66 ^ 1)) = -1;
break;
}
*(_BYTE *)(v67 + v66) = m;
}
}
if ( *(_BYTE *)(v150 + 535) == 6 || *(_WORD *)(v150 + 528) )
{
if ( v155 == 2 )
{
v142 = v152;
v89 = 1;
v148 = v152;
v143 = v152;
v152 = (unsigned __int8)((unsigned __int16)(png_sRGB_base[(unsigned int)(255 * v152) >> 15]
+ ((((255 * v152) & 0x7FFF)
* (unsigned int)png_sRGB_delta[(unsigned int)(255 * v152) >> 15]) >> 12)) >> 8);
sub_653BE8((unsigned int)v1, v152, v142, v143, v148, 0, 2);
}
else
{
v89 = 1;
}
goto LABEL_282;
}
LABEL_159:
v10 = 256;
v11 = 0;
v12 = 256;
LABEL_57:
png_set_alpha_mode_fixed(v150, 0, 220000);
v34 = *(unsigned __int8 *)(v150 + 536);
LABEL_58:
if ( v34 > 8 )
goto LABEL_44;
LABEL_59:
if ( v12 > 0x100 || (unsigned int)v151[6] < v12 )
png_error(v150, "color map overflow (BAD internal error)");
v151[6] = (int *)v12;
switch ( v11 )
{
case 1:
if ( v10 != 231 )
goto LABEL_81;
goto LABEL_76;
case 2:
v40 = v10 >= v12;
if ( v10 != 254 )
v40 = 1;
if ( v40 )
goto LABEL_81;
goto LABEL_76;
case 4:
if ( v10 != 216 )
goto LABEL_81;
goto LABEL_76;
default:
if ( v10 != 256 )
LABEL_81:
png_error(v150, "bad background index (internal error)");
LABEL_76:
v1[10] = (int **)v11;
return 1;
}
case 3:
v13 = *(unsigned __int16 *)(v150 + 528);
if ( *(_WORD *)(v150 + 528) )
{
v16 = *(_BYTE **)(v150 + 628);
v14 = *(unsigned __int8 **)(v150 + 516);
if ( v16 )
{
v15 = !((unsigned __int8)v2 & 1);
LABEL_25:
v12 = *(unsigned __int16 *)(v150 + 520);
if ( v12 >= 0x100 )
v12 = 256;
if ( (unsigned int)v151[6] < v12 )
png_error(v150, "palette color-map: too few entries");
if ( v12 )
{
v161 = v7;
v17 = v16;
v18 = 0;
v19 = v155;
do
{
while ( 1 )
{
if ( v18 < v13 && v15 )
{
v20 = (unsigned __int8)*v17;
if ( v20 != 255 )
break;
}
v22 = v14[2];
v23 = *v14;
++v17;
if ( v13 <= v18 )
v24 = 255;
else
v24 = (unsigned __int8)*(v17 - 1);
v25 = v14[1];
v14 += 3;
v149 = v24;
v26 = v18++;
sub_653BE8((unsigned int)v1, v26, v23, v25, v22, v149, 3);
if ( v18 == v12 )
goto LABEL_42;
}
if ( *v17 )
{
v165 = sub_653A0C(v1, *v14, 3, v20, v159, v19);
v156 = sub_653A0C(v1, v14[1], 3, (unsigned __int8)*v17, v152, v19);
v68 = sub_653A0C(v1, v14[2], 3, (unsigned __int8)*v17, v161, v19);
v69 = (unsigned __int8)*v17;
if ( v19 == 2 )
v69 *= 257;
sub_653BE8((unsigned int)v1, v18, v165, v156, v68, v69, v19);
}
else
{
sub_653BE8((unsigned int)v1, v18, v159, v152, v161, 0, v19);
}
++v18;
++v17;
v14 += 3;
}
while ( v18 != v12 );
}
LABEL_42:
v27 = *(unsigned __int8 *)(v150 + 536);
if ( v27 <= 7 )
{
v10 = 256;
v11 = 0;
png_set_packing(v150);
v34 = *(unsigned __int8 *)(v150 + 536);
goto LABEL_58;
}
v10 = 256;
v11 = 0;
if ( v27 <= 8 )
goto LABEL_59;
LABEL_44:
png_set_scale_16(v150);
goto LABEL_59;
}
}
else
{
v14 = *(unsigned __int8 **)(v150 + 516);
}
v15 = 0;
v16 = nullptr;
v13 = 0;
goto LABEL_25;
case 4:
if ( ((unsigned __int8)v2 & 1) != 0 )
{
if ( (unsigned int)v151[6] <= 0xFF )
png_error(v150, "gray+alpha color-map: too few entries");
v10 = 231;
v11 = 1;
v12 = sub_654280(a1);
goto LABEL_57;
}
if ( ((unsigned __int8)v2 & 2) != 0 )
{
v41 = v152 == v7;
if ( v152 == v7 )
v41 = v159 == v152;
if ( !v41 )
{
v42 = 0;
if ( (unsigned int)v151[6] <= 0xFF )
png_error(v150, "ga-alpha color-map: too few entries");
v91 = 115;
do
{
v92 = 464823301LL * (unsigned int)v91;
v93 = v42 + 1;
LODWORD(v92) = v91 - HIDWORD(v92);
v91 += 256;
sub_6535E0(
v1,
v42,
(HIDWORD(v92) + ((unsigned int)v92 >> 1)) >> 7,
(HIDWORD(v92) + ((unsigned int)v92 >> 1)) >> 7,
(HIDWORD(v92) + ((unsigned int)v92 >> 1)) >> 7,
1);
v42 = v93;
}
while ( v93 != 231 );
if ( v155 == 2 )
{
sub_653BE8((unsigned int)v1, 0xE7u, v159, v152, v7, 0xFFFFu, 2);
}
else
{
sub_653BE8((unsigned int)v1, 0xE7u, v159, v152, v7, 0xFFu, 1);
v7 = png_sRGB_table[v7];
v159 = png_sRGB_table[v159];
v152 = png_sRGB_table[v152];
}
v172 = -51 * v159;
v160 = 204 * v159;
v170 = -51 * v152;
v154 = 204 * v152;
v166 = v1;
v158 = 204 * v7;
v94 = 1;
v168 = 1;
do
{
v95 = 3 * v94;
v96 = 0;
v97 = 6 * v94;
v98 = 17 * v95;
v99 = v97 + 226;
v164 = v97 + 232;
do
{
v100 = png_sRGB_table[v96];
v101 = v99 + 1;
v96 += 51;
v102 = v98 * v100;
sub_6535E0(
v166,
v99,
(unsigned __int16)(png_sRGB_base[(unsigned int)(v102 + v160) >> 15]
+ (((((_WORD)v102 + (_WORD)v160) & 0x7FFF)
* (unsigned int)png_sRGB_delta[(unsigned int)(v102 + v160) >> 15]) >> 12)) >> 8,
(unsigned __int16)(png_sRGB_base[(unsigned int)(v102 + v154) >> 15]
+ ((((v102 + v154) & 0x7FFF)
* (unsigned int)png_sRGB_delta[(unsigned int)(v102 + v154) >> 15]) >> 12)) >> 8,
(unsigned __int16)(png_sRGB_base[(unsigned int)(v102 + v158) >> 15]
+ ((((v102 + v158) & 0x7FFF)
* (unsigned int)png_sRGB_delta[(unsigned int)(v102 + v158) >> 15]) >> 12)) >> 8,
1);
v99 = v101;
}
while ( v101 != v164 );
v160 += v172;
v94 = v168 + 1;
v41 = v168++ == 4;
v154 += v170;
v158 -= 51 * v7;
}
while ( !v41 );
v10 = 231;
v11 = 1;
v1 = v166;
v12 = 256;
goto LABEL_57;
}
}
if ( (unsigned int)v151[6] <= 0xFF )
png_error(v150, "gray-alpha color-map: too few entries");
for ( n = 0; n != 256; ++n )
{
v144 = n;
v44 = n;
v45 = n;
v46 = n;
sub_6535E0(v1, v44, v45, v46, v144, 1);
}
v47 = v155;
goto LABEL_96;
default:
png_error(v150, "invalid PNG color type");
}
}