//
// cocos2d::CCImage::_initWithPngData from 0xb0be40 to 0xb0c2dc (1180 bytes)
//
// 2 xrefs:
// > cocos2d::CCImage::initWithImageData @ 0xb0c644
// > ??> @ 0x79f68
//
// 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
//
bool cocos2d::CCImage::_initWithPngData(cocos2d::CCImage *a1, void *a2, int a3)
{
__int64 v3; // x1
__int64 *p_info_struct; // x1
struct __jmp_buf_tag *v6; // x0
unsigned __int16 image_width; // w0
__int64 v8; // x1
int bit_depth; // w2
__int64 v10; // x1
__int64 v11; // x0
int color_type; // w19
__int64 m_nHeight; // x0
int64x2_t *v14; // x20
unsigned int rowbytes; // w21
unsigned __int8 *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
__int64 v39; // x8
unsigned int v40; // w9
unsigned __int8 *m_pData; // x6
__int64 v42; // x5
unsigned int v43; // w1
__int64 v44; // x2
__int64 v45; // x0
__int64 v46; // x7
int v47; // w3
int v48; // w4
bool v52; // [xsp+4Ch] [xbp+4Ch]
__int64 v53; // [xsp+50h] [xbp+50h] BYREF
__int64 info_struct; // [xsp+58h] [xbp+58h] BYREF
_QWORD v55[2]; // [xsp+60h] [xbp+60h] BYREF
__int64 v56; // [xsp+70h] [xbp+70h] BYREF
v3 = 0;
v56 = 0;
v53 = 0;
info_struct = 0;
v52 = 0;
if ( a3 > 7 )
{
v56 = *(_QWORD *)a2;
if ( (unsigned int)png_sig_cmp(&v56, 0, 8) )
goto LABEL_8;
v53 = png_create_read_struct("1.6.16", 0, 0, 0);
if ( !v53 )
return v52;
info_struct = png_create_info_struct();
if ( !info_struct || (v6 = (struct __jmp_buf_tag *)png_set_longjmp_fn(v53, &longjmp, 256), setjmp(v6)) )
{
LABEL_8:
v3 = v53;
goto LABEL_2;
}
v55[0] = a2;
v55[1] = (unsigned int)a3;
png_set_read_fn(v53, v55, sub_B0BAC8);
png_read_info(v53, info_struct);
image_width = png_get_image_width(v53, info_struct);
v8 = info_struct;
a1->m_nWidth = image_width;
a1->m_nHeight = png_get_image_height(v53, v8);
bit_depth = (unsigned __int8)png_get_bit_depth(v53, info_struct);
v10 = info_struct;
v11 = v53;
a1->m_nBitsPerComponent = bit_depth;
color_type = (unsigned __int8)png_get_color_type(v11, v10);
if ( color_type == 3 )
{
png_set_palette_to_rgb(v53);
}
else if ( !color_type && a1->m_nBitsPerComponent <= 7 )
{
png_set_expand_gray_1_2_4_to_8(v53);
}
if ( (unsigned int)png_get_valid(v53, info_struct, 16) )
png_set_tRNS_to_alpha(v53);
if ( a1->m_nBitsPerComponent == 16 )
png_set_strip_16(v53);
if ( (color_type & 0xFFFFFFFB) == 0 )
png_set_gray_to_rgb(v53);
m_nHeight = a1->m_nHeight;
a1->m_nBitsPerComponent = 8;
v14 = (int64x2_t *)malloc(8 * m_nHeight);
png_read_update_info(v53, info_struct);
rowbytes = png_get_rowbytes(v53, info_struct);
v16 = (unsigned __int8 *)operator new[](a1->m_nHeight * rowbytes);
a1->m_pData = v16;
v17 = a1->m_nHeight;
if ( a1->m_nHeight )
{
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((unsigned __int64)v16);
v23 = v14;
v24 = (int16x8_t)xmmword_B0C2E0;
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 ( v19 != v17 )
{
LABEL_28:
v14[v19 / 2].n128_u64[0] = (unsigned __int64)&v16[v19 * rowbytes];
if ( (unsigned __int16)(v19 + 1) < v17 )
{
v14->n128_u64[(unsigned __int16)(v19 + 1)] = (unsigned __int64)&v16[(unsigned __int16)(v19 + 1) * rowbytes];
if ( v17 > (unsigned __int16)(v19 + 2) )
{
v14->n128_u64[(unsigned __int16)(v19 + 2)] = (unsigned __int64)&v16[(unsigned __int16)(v19 + 2) * rowbytes];
if ( (unsigned __int16)(v19 + 3) < v17 )
{
v14->n128_u64[(unsigned __int16)(v19 + 3)] = (unsigned __int64)&v16[(unsigned __int16)(v19 + 3) * rowbytes];
if ( (unsigned __int16)(v19 + 4) < v17 )
{
v37 = (unsigned __int16)(v19 + 5);
v14->n128_u64[(unsigned __int16)(v19 + 4)] = (unsigned __int64)&v16[(unsigned __int16)(v19 + 4)
* rowbytes];
if ( v17 > v37 )
{
v38 = (unsigned __int16)(v19 + 6);
v14->n128_u64[v37] = (unsigned __int64)&v16[v37 * rowbytes];
if ( v17 > v38 )
v14->n128_u64[v38] = (unsigned __int64)&v16[v38 * rowbytes];
}
}
}
}
}
}
}
png_read_image(v53, v14);
png_read_end(v53, 0);
if ( rowbytes / a1->m_nWidth == 4 )
{
v39 = 0;
v40 = a1->m_nHeight;
a1->m_bHasAlpha = 1;
m_pData = a1->m_pData;
if ( v40 )
{
do
{
if ( rowbytes )
{
v42 = v14->n128_i64[v39];
v43 = 0;
do
{
v44 = v43 + 3;
v45 = v43 + 1;
v46 = v43 + 2;
v47 = *(unsigned __int8 *)(v42 + v43);
v43 += 4;
v48 = *(unsigned __int8 *)(v42 + v44);
*(_DWORD *)m_pData = ((v48 + 1) * *(unsigned __int8 *)(v42 + v45)) & 0xFFFFFF00
| ((unsigned int)(v47 * (v48 + 1)) >> 8)
| (v48 << 24)
| (((v48 + 1) * *(unsigned __int8 *)(v42 + v46)) >> 8 << 16);
m_pData += 4;
}
while ( rowbytes > v43 );
}
++v39;
}
while ( v40 > (unsigned __int16)v39 );
}
a1->m_bPreMulti = 1;
}
if ( v14 )
free(v14);
v3 = v53;
v52 = 1;
}
LABEL_2:
if ( v3 )
{
p_info_struct = nullptr;
if ( info_struct )
p_info_struct = &info_struct;
png_destroy_read_struct(&v53, p_info_struct, 0);
}
return v52;
}