//
// cocos2d::CCImage::_initWithPngData from 0xd7ce00 to 0xd7d2ac (1196 bytes)
//
// 2 xrefs:
// > cocos2d::CCImage::initWithImageData @ 0xd7d614
// > ??> @ 0xa3018
//
// This function is hookable on this platform (idp: arm, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 13:08:08 +0000
//
__int64 __fastcall cocos2d::CCImage::_initWithPngData(cocos2d::CCImage *this, __int64 *a2, int a3)
{
__int64 v3; // x1
__int64 *p_info_struct; // x1
struct __jmp_buf_tag *v6; // x0
__int16 image_width; // w0
__int64 v8; // x1
int bit_depth; // w2
__int64 v10; // x1
__int64 v11; // x0
int color_type; // w19
__int64 v13; // x0
int64x2_t *v14; // x20
unsigned int rowbytes; // w21
unsigned __int64 v16; // x0
unsigned int v17; // w2
unsigned int v18; // w3
unsigned int v19; // w1
int16x8_t v20; // q7
int32x4_t v21; // q6
int64x2_t v22; // q3
int64x2_t *v23; // x4
int16x8_t v24; // q2
int v25; // w5
int32x4_t v26; // q1
int64x2_t *v27; // x8
int32x4_t v28; // q0
int64x2_t *v29; // x7
int64x2_t *v30; // x6
int32x4_t v31; // q1
int32x4_t v32; // q0
int64x2_t v33; // off
int64x2_t v34; // q5
int64x2_t v35; // q1
int64x2_t v36; // q4
unsigned int v37; // w3
unsigned int v38; // w1
unsigned int v39; // w9
int v40; // w0
unsigned int *v41; // x6
unsigned int v42; // w1
unsigned __int64 *v43; // x8
__int64 v44; // x2
__int64 v45; // x7
int v46; // w4
int v47; // w3
unsigned __int8 v51; // [xsp+4Ch] [xbp+4Ch]
__int64 v52; // [xsp+50h] [xbp+50h] BYREF
__int64 info_struct; // [xsp+58h] [xbp+58h] BYREF
_QWORD v54[2]; // [xsp+60h] [xbp+60h] BYREF
__int64 v55; // [xsp+70h] [xbp+70h] BYREF
v3 = 0;
v55 = 0;
v52 = 0;
info_struct = 0;
v51 = 0;
if ( a3 > 7 )
{
v55 = *a2;
if ( (unsigned int)png_sig_cmp(&v55, 0, 8) )
goto LABEL_8;
v52 = png_create_read_struct("1.6.16", 0, 0, 0);
if ( !v52 )
return v51;
info_struct = png_create_info_struct();
if ( !info_struct || (v6 = (struct __jmp_buf_tag *)png_set_longjmp_fn(v52, &longjmp, 256), setjmp(v6)) )
{
LABEL_8:
v3 = v52;
goto LABEL_2;
}
v54[0] = a2;
v54[1] = (unsigned int)a3;
png_set_read_fn(v52, v54, sub_D7CA40);
png_read_info(v52, info_struct);
image_width = png_get_image_width(v52, info_struct);
v8 = info_struct;
*((_WORD *)this + 28) = image_width;
*((_WORD *)this + 29) = png_get_image_height(v52, v8);
bit_depth = (unsigned __int8)png_get_bit_depth(v52, info_struct);
v10 = info_struct;
v11 = v52;
*((_DWORD *)this + 15) = bit_depth;
color_type = (unsigned __int8)png_get_color_type(v11, v10);
if ( color_type == 3 )
{
png_set_palette_to_rgb(v52);
}
else if ( !color_type && *((int *)this + 15) <= 7 )
{
png_set_expand_gray_1_2_4_to_8(v52);
}
if ( (unsigned int)png_get_valid(v52, info_struct, 16) )
png_set_tRNS_to_alpha(v52);
if ( *((_DWORD *)this + 15) == 16 )
png_set_strip_16(v52);
if ( (color_type & 0xFFFFFFFB) == 0 )
png_set_gray_to_rgb(v52);
v13 = *((unsigned __int16 *)this + 29);
*((_DWORD *)this + 15) = 8;
v14 = (int64x2_t *)malloc(8 * v13);
png_read_update_info(v52, info_struct);
rowbytes = png_get_rowbytes(v52, info_struct);
v16 = operator new[](*((unsigned __int16 *)this + 29) * rowbytes);
*((_QWORD *)this + 8) = v16;
v17 = *((unsigned __int16 *)this + 29);
if ( *((_WORD *)this + 29) )
{
v18 = ((unsigned __int16)(v17 - 8) >> 3) + 1;
v19 = 8 * (v18 & 0x1FFF);
if ( (unsigned __int16)(v17 - 1) <= 6u )
{
v19 = 0;
goto LABEL_28;
}
v20.n128_u64[0] = 0x8000800080008LL;
v20.n128_u64[1] = 0x8000800080008LL;
v21 = vdupq_n_s32(rowbytes);
v22 = vdupq_n_s64(v16);
v23 = v14;
v24 = (int16x8_t)xmmword_D7D2B0;
v25 = 0;
do
{
v26 = vmovl_u16((uint16x4_t)v24.n128_u64[0]);
v27 = v23;
v28 = vmovl_high_u16(v24);
v29 = v23 + 2;
v30 = v23 + 3;
++v25;
v24 = vaddq_s16(v24, v20);
v31 = vmulq_s32(v26, v21);
v23 += 4;
v32 = vmulq_s32(v28, v21);
v33.n128_u64[0] = v31.n128_u32[0];
v33.n128_u64[1] = v31.n128_u32[1];
v34 = v33;
v33.n128_u64[0] = v31.n128_u32[2];
v33.n128_u64[1] = v31.n128_u32[3];
v35 = v33;
v33.n128_u64[0] = v32.n128_u32[0];
v33.n128_u64[1] = v32.n128_u32[1];
v36 = v33;
v33.n128_u64[0] = v32.n128_u32[2];
v33.n128_u64[1] = v32.n128_u32[3];
*v27 = vaddq_s64(v22, v34);
v27[1] = vaddq_s64(v22, v35);
*v29 = vaddq_s64(v22, v36);
*v30 = vaddq_s64(v22, v33);
}
while ( v18 > (unsigned __int16)v25 );
if ( v17 != v19 )
{
LABEL_28:
v14[v19 / 2].n128_u64[0] = v16 + v19 * rowbytes;
if ( (unsigned __int16)(v19 + 1) < v17 )
{
v14->n128_u64[(unsigned __int16)(v19 + 1)] = v16 + (unsigned __int16)(v19 + 1) * rowbytes;
if ( v17 > (unsigned __int16)(v19 + 2) )
{
v14->n128_u64[(unsigned __int16)(v19 + 2)] = v16 + (unsigned __int16)(v19 + 2) * rowbytes;
if ( (unsigned __int16)(v19 + 3) < v17 )
{
v14->n128_u64[(unsigned __int16)(v19 + 3)] = v16 + (unsigned __int16)(v19 + 3) * rowbytes;
if ( (unsigned __int16)(v19 + 4) < v17 )
{
v37 = (unsigned __int16)(v19 + 5);
v14->n128_u64[(unsigned __int16)(v19 + 4)] = v16 + (unsigned __int16)(v19 + 4) * rowbytes;
if ( v17 > v37 )
{
v38 = (unsigned __int16)(v19 + 6);
v14->n128_u64[v37] = v16 + v37 * rowbytes;
if ( v17 > v38 )
v14->n128_u64[v38] = v16 + v38 * rowbytes;
}
}
}
}
}
}
}
png_read_image(v52, v14);
png_read_end(v52, 0);
if ( rowbytes / *((unsigned __int16 *)this + 28) == 4 )
{
LOWORD(v39) = 0;
v40 = *((unsigned __int16 *)this + 29);
*((_BYTE *)this + 72) = 1;
v41 = *((unsigned int **)this + 8);
if ( v40 )
{
do
{
if ( rowbytes )
{
v42 = 0;
v43 = &v14->n128_u64[(unsigned __int16)v39];
do
{
v44 = v42 + 1;
v45 = v42 + 2;
v46 = *(unsigned __int8 *)(*v43 + v42 + 3);
v47 = *(unsigned __int8 *)(*v43 + v42);
v42 += 4;
*v41++ = ((v46 + 1) * *(unsigned __int8 *)(*v43 + v44)) & 0xFFFFFF00
| ((unsigned int)(v47 * (v46 + 1)) >> 8)
| (v46 << 24)
| (((v46 + 1) * *(unsigned __int8 *)(*v43 + v45)) >> 8 << 16);
}
while ( rowbytes > v42 );
}
v39 = (unsigned __int16)(v39 + 1);
}
while ( *((unsigned __int16 *)this + 29) > v39 );
}
*((_BYTE *)this + 73) = 1;
}
if ( v14 )
free(v14);
v3 = v52;
v51 = 1;
}
LABEL_2:
if ( v3 )
{
p_info_struct = nullptr;
if ( info_struct )
p_info_struct = &info_struct;
png_destroy_read_struct(&v52, p_info_struct, 0);
}
return v51;
}