//
// cocos2d::CCImage::_initWithPngData from 0x5e1aa0 to 0x5e1cca (554 bytes)
//
// 1 xrefs:
// > cocos2d::CCImage::initWithImageData @ 0x5e1e86
//
// 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)
{
int v3; // r0
int v4; // r1
struct __jmp_buf_tag *v5; // r0
unsigned __int16 image_width; // r0
int v7; // r1
unsigned __int16 image_height; // r0
int v9; // r1
int bit_depth; // r0
int v11; // r1
int color_type; // r0
char v13; // r4
int m_nHeight; // r0
unsigned __int8 **v15; // r5
unsigned int rowbytes; // r4
unsigned __int8 *v17; // r0
unsigned __int8 **v18; // r2
unsigned __int8 **v19; // r3
int v20; // r0
unsigned int v21; // lr
unsigned __int8 *m_pData; // r3
unsigned __int8 *v23; // r6
unsigned int v24; // r1
unsigned __int8 *v25; // r12
int v26; // r8
bool v29; // [sp+4h] [bp-38h]
int v32; // [sp+18h] [bp-24h] BYREF
int info_struct; // [sp+1Ch] [bp-20h]
_DWORD v34[3]; // [sp+20h] [bp-1Ch] BYREF
int v35; // [sp+2Ch] [bp-10h] BYREF
int v36; // [sp+30h] [bp-Ch]
v29 = 0;
v35 = 0;
v36 = 0;
v32 = 0;
info_struct = 0;
if ( a3 > 7 )
{
v3 = *(_DWORD *)a2;
v4 = *((_DWORD *)a2 + 1);
v35 = v3;
v36 = v4;
if ( !png_sig_cmp(&v35, 0, 8) )
{
v32 = png_create_read_struct("1.6.16", 0, 0, 0);
if ( v32 )
{
info_struct = png_create_info_struct();
if ( info_struct )
{
v5 = (struct __jmp_buf_tag *)png_set_longjmp_fn(v32, &longjmp, 256);
if ( !setjmp(v5) )
{
v34[2] = 0;
v34[0] = a2;
v34[1] = a3;
png_set_read_fn(v32, v34, sub_5E1868);
png_read_info(v32, info_struct);
image_width = png_get_image_width(v32, info_struct);
v7 = info_struct;
a1->m_nWidth = image_width;
image_height = png_get_image_height(v32, v7);
v9 = info_struct;
a1->m_nHeight = image_height;
bit_depth = png_get_bit_depth(v32, v9);
v11 = info_struct;
a1->m_nBitsPerComponent = bit_depth;
color_type = png_get_color_type(v32, v11);
v13 = color_type;
if ( color_type == 3 )
{
png_set_palette_to_rgb(v32);
}
else if ( !color_type && a1->m_nBitsPerComponent <= 7 )
{
png_set_expand_gray_1_2_4_to_8(v32);
}
if ( png_get_valid(v32, info_struct, 16) )
png_set_tRNS_to_alpha(v32);
if ( a1->m_nBitsPerComponent == 16 )
png_set_strip_16(v32);
if ( (v13 & 0xFB) == 0 )
png_set_gray_to_rgb(v32);
m_nHeight = a1->m_nHeight;
a1->m_nBitsPerComponent = 8;
v15 = (unsigned __int8 **)malloc(4 * m_nHeight);
png_read_update_info(v32, info_struct);
rowbytes = png_get_rowbytes(v32, info_struct);
v17 = (unsigned __int8 *)operator new[](a1->m_nHeight * rowbytes);
v18 = v15;
a1->m_pData = v17;
v19 = &v15[a1->m_nHeight];
while ( v18 != v19 )
{
*v18++ = v17;
v17 += rowbytes;
}
png_read_image(v32, v15);
png_read_end(v32, 0);
if ( rowbytes / a1->m_nWidth == 4 )
{
v20 = 0;
a1->m_bHasAlpha = 1;
v21 = a1->m_nHeight;
m_pData = a1->m_pData;
while ( (unsigned __int16)v20 < v21 )
{
v23 = m_pData;
v24 = 0;
while ( 1 )
{
m_pData = v23;
if ( v24 >= rowbytes )
break;
v25 = &v15[v20][v24];
v24 += 4;
v26 = v25[3];
*(_DWORD *)v23 = (v25[1] * (v26 + 1)) & 0xFFFFFF00
| (((v26 + 1) * (unsigned int)*v25) >> 8)
| (v26 << 24)
| (((v26 + 1) * v25[2]) >> 8 << 16);
v23 += 4;
}
++v20;
}
a1->m_bPreMulti = 1;
}
if ( v15 )
free(v15);
v29 = 1;
}
}
}
}
}
if ( v32 )
png_destroy_read_struct(&v32);
return v29;
}