//
// cocos2d::CCImage::_saveImageToPNG from 0x7ebdc0 to 0x7ebfd8 (536 bytes)
//
// 1 xrefs:
// > cocos2d::CCImage::saveToFile @ 0x7ec3d4
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// 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 12:01:00 +0000
//
int __fastcall cocos2d::CCImage::_saveImageToPNG(cocos2d::CCImage *this, const char *filename, int a3)
{
int *p_info_struct; // r1
struct __jmp_buf_tag *v4; // r0
int v5; // r5
_DWORD *v6; // r0
_DWORD *v7; // r4
int v8; // r3
char *v9; // r0
int v10; // r2
void *v11; // r5
int v12; // r1
int i; // r1
int v14; // r3
int v15; // r3
int v16; // r3
int j; // r2
int k; // r3
FILE *stream; // [sp+20h] [bp-20h]
int v23; // [sp+34h] [bp-Ch] BYREF
int info_struct; // [sp+38h] [bp-8h] BYREF
if ( !filename )
return 0;
stream = fopen(filename, "wb");
if ( !stream )
return 0;
v23 = png_create_write_struct("1.6.16", 0, 0, 0);
if ( v23 )
{
info_struct = png_create_info_struct();
if ( !info_struct )
{
fclose(stream);
p_info_struct = nullptr;
LABEL_15:
png_destroy_write_struct(&v23, p_info_struct);
return 0;
}
v4 = (struct __jmp_buf_tag *)png_set_longjmp_fn(v23, &longjmp, 256);
if ( setjmp(v4) )
goto LABEL_14;
png_set_write_fn(v23, stream, sub_7EB6AA, sub_7EB69C);
if ( a3 || !*((_BYTE *)this + 64) )
png_set_IHDR(v23, info_struct, *((unsigned __int16 *)this + 26), *((unsigned __int16 *)this + 27), 8, 2, 0, 0, 0);
else
png_set_IHDR(v23, info_struct, *((unsigned __int16 *)this + 26), *((unsigned __int16 *)this + 27), 8, 6, 0, 0, 0);
png_write_info(v23, info_struct);
v5 = *((unsigned __int16 *)this + 27);
v6 = malloc(4 * v5);
v7 = v6;
if ( !v6 )
{
LABEL_14:
fclose(stream);
p_info_struct = &info_struct;
goto LABEL_15;
}
v8 = *((unsigned __int8 *)this + 64);
if ( *((_BYTE *)this + 64) )
{
if ( a3 )
{
v9 = (char *)operator new[](3 * *((unsigned __int16 *)this + 26) * v5);
v10 = 0;
v11 = v9;
while ( 1 )
{
v12 = *((unsigned __int16 *)this + 27);
if ( v10 >= v12 )
break;
for ( i = 0; ; ++i )
{
v14 = *((unsigned __int16 *)this + 26);
if ( i >= v14 )
break;
v9[3 * i + 3 * v14 * v10] = *(_BYTE *)(*((_DWORD *)this + 15) + 4 * (i + v14 * v10));
v15 = i + *((unsigned __int16 *)this + 26) * v10;
v9[3 * v15 + 1] = *(_BYTE *)(*((_DWORD *)this + 15) + 4 * v15 + 1);
v16 = i + *((unsigned __int16 *)this + 26) * v10;
v9[3 * v16 + 2] = *(_BYTE *)(*((_DWORD *)this + 15) + 4 * v16 + 2);
}
++v10;
}
for ( j = 0; j != v12; ++j )
v7[j] = &v9[3 * *((unsigned __int16 *)this + 26) * j];
png_write_image(v23, v7);
free(v7);
operator delete[](v11);
goto LABEL_34;
}
for ( k = 0; k < v5; ++k )
v6[k] = *((_DWORD *)this + 15) + 4 * *((unsigned __int16 *)this + 26) * k;
}
else
{
while ( v8 < v5 )
{
v6[v8] = 3 * *((unsigned __int16 *)this + 26) * v8 + *((_DWORD *)this + 15);
++v8;
}
}
png_write_image(v23, v6);
free(v7);
LABEL_34:
png_write_end(v23);
png_destroy_write_struct(&v23, &info_struct);
fclose(stream);
return 1;
}
fclose(stream);
return 0;
}