//
// cocos2d::CCImage::_initWithPngData from 0x18007b5c0 to 0x18007b919 (857 bytes)
//
// 6 xrefs:
// > cocos2d::CCImage::initWithImageData @ 0x18007ca98
// > cocos2d::CCImage::initWithImageFile @ 0x18007cb94
// > cocos2d::CCImage::initWithImageFile @ 0x18007cbf4
// > cocos2d::CCImage::initWithImageFileThreadSafe @ 0x18007cd1b
// > ??> @ 0x1801438a8
// > ??> @ 0x1801b4d40
//
// 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
//
__int64 __fastcall cocos2d::CCImage::_initWithPngData(cocos2d::CCImage *this, _QWORD *a2, int a3)
{
unsigned __int8 v3; // bl
__int64 v4; // rax
__int64 v5; // rax
cocos2d::CCImage *v6; // rdi
char color_type; // bl
char *v8; // r12
unsigned int rowbytes; // esi
unsigned __int8 *v10; // rax
unsigned __int16 m_nHeight; // r9
unsigned __int16 v12; // dx
char *v13; // r8
__int64 v14; // rcx
unsigned __int16 v15; // bx
unsigned int *i; // r14
unsigned int v17; // r11d
char *v18; // r15
int v19; // r10d
__int64 v20; // rax
unsigned int v21; // r9d
__int64 *p_info_struct; // rdx
__int64 v24; // [rsp+0h] [rbp-70h] BYREF
char v25; // [rsp+20h] [rbp-50h]
__int64 v26; // [rsp+28h] [rbp-48h] BYREF
__int64 info_struct; // [rsp+30h] [rbp-40h] BYREF
int v28; // [rsp+38h] [rbp-38h]
_QWORD *v29; // [rsp+40h] [rbp-30h]
cocos2d::CCImage *v30; // [rsp+48h] [rbp-28h]
_QWORD *v31; // [rsp+50h] [rbp-20h] BYREF
int v32; // [rsp+58h] [rbp-18h]
int v33; // [rsp+5Ch] [rbp-14h]
__int64 v34; // [rsp+60h] [rbp-10h] BYREF
v30 = this;
v3 = 0;
v29 = a2;
v28 = a3;
v25 = 0;
v34 = 0;
v26 = 0;
info_struct = 0;
if ( a3 >= 8 )
{
v34 = *a2;
if ( !(unsigned int)png_sig_cmp(&v34, 0, 8) )
{
v4 = png_create_read_struct("1.6.40", 0, 0, 0);
v26 = v4;
if ( v4 )
{
info_struct = png_create_info_struct(v4);
if ( info_struct )
{
v5 = png_set_longjmp_fn(v26, longjmp, 256);
if ( (unsigned int)_intrinsic_setjmp(v5, &v24) )
goto LABEL_31;
v31 = v29;
v32 = v28;
v33 = 0;
png_set_read_fn(v26, &v31, &sub_18007D0D0);
png_read_info(v26, info_struct);
v6 = v30;
v6->m_nWidth = png_get_image_width(v26, info_struct);
v6->m_nHeight = png_get_image_height(v26, info_struct);
v6->m_nBitsPerComponent = (unsigned __int8)png_get_bit_depth(v26, info_struct);
color_type = png_get_color_type(v26, info_struct);
if ( color_type == 3 )
png_set_palette_to_rgb(v26);
if ( !color_type && v6->m_nBitsPerComponent < 8 )
png_set_expand_gray_1_2_4_to_8(v26);
if ( (unsigned int)png_get_valid(v26, info_struct, 16) )
png_set_tRNS_to_alpha(v26);
if ( v6->m_nBitsPerComponent == 16 )
png_set_strip_16(v26);
if ( (color_type & 0xFB) == 0 )
png_set_gray_to_rgb(v26);
v6->m_nBitsPerComponent = 8;
v8 = (char *)malloc(8LL * v6->m_nHeight);
png_read_update_info(v26, info_struct);
rowbytes = png_get_rowbytes(v26, info_struct);
v10 = (unsigned __int8 *)operator new(rowbytes * v6->m_nHeight);
v6->m_pData = v10;
if ( !v10 )
{
LABEL_31:
v3 = v25;
}
else
{
m_nHeight = v6->m_nHeight;
v12 = 0;
if ( m_nHeight )
{
v13 = v8;
do
{
v13 += 8;
v14 = rowbytes * v12++;
*((_QWORD *)v13 - 1) = &v10[v14];
}
while ( v12 < m_nHeight );
}
png_read_image(v26, v8);
png_read_end(v26, 0);
if ( rowbytes / v6->m_nWidth == 4 )
{
v6->m_bHasAlpha = 1;
v15 = 0;
for ( i = (unsigned int *)v6->m_pData; v15 < v6->m_nHeight; ++v15 )
{
if ( rowbytes )
{
v17 = 2;
v18 = &v8[8 * v15];
do
{
v19 = *(unsigned __int8 *)(v17 + 1 + *(_QWORD *)v18);
v20 = v17 - 2;
v21 = ((v19 + 1) * *(unsigned __int8 *)(v17 - 1 + *(_QWORD *)v18)) & 0xFFFFFF00
| ((((v19 + 1) * *(unsigned __int8 *)(v17 + *(_QWORD *)v18)) & 0xFFFFFF00) << 8);
v17 += 4;
*i++ = (v19 << 24)
| (((v19 + 1) * (unsigned int)*(unsigned __int8 *)(v20 + *(_QWORD *)v18)) >> 8)
| v21;
}
while ( v17 - 2 < rowbytes );
}
}
v6->m_bPreMulti = 1;
}
if ( v8 )
free(v8);
v3 = 1;
v25 = 1;
}
}
}
}
}
if ( v26 )
{
p_info_struct = &info_struct;
if ( !info_struct )
p_info_struct = nullptr;
png_destroy_read_struct(&v26, p_info_struct, 0);
}
return v3;
}