//
// cocos2d::CCImage::_saveImageToJPG from 0xd7ddb0 to 0xd7e024 (628 bytes)
//
// 2 xrefs:
// > cocos2d::CCImage::saveToFile @ 0xd7e48c
// > ??> @ 0x5dbe0
//
// 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::_saveImageToJPG(cocos2d::CCImage *this, const char *a2)
{
FILE *v4; // x0
FILE *v5; // x21
int v6; // w2
int v7; // w0
int v8; // w19
unsigned int j; // w0
_BYTE *v11; // x23
int v12; // w2
int v13; // w0
int v14; // w3
int v15; // w1
int v16; // w0
int v17; // w0
unsigned int i; // w0
char *v19; // [xsp+50h] [xbp+50h] BYREF
_BYTE v20[168]; // [xsp+58h] [xbp+58h] BYREF
_QWORD v21[6]; // [xsp+100h] [xbp+100h] BYREF
int v22; // [xsp+130h] [xbp+130h]
unsigned int v23; // [xsp+134h] [xbp+134h]
int v24; // [xsp+138h] [xbp+138h]
int v25; // [xsp+13Ch] [xbp+13Ch]
unsigned int v26; // [xsp+258h] [xbp+258h]
if ( !a2 )
return 0;
v21[0] = jpeg_std_error(v20);
jpeg_CreateCompress(v21);
v4 = fopen(a2, "wb");
v5 = v4;
if ( !v4 )
return 0;
jpeg_stdio_dest(v21, v4);
v6 = *((unsigned __int16 *)this + 28);
v23 = *((unsigned __int16 *)this + 29);
v24 = 3;
v22 = v6;
v25 = 2;
jpeg_set_defaults(v21);
jpeg_start_compress(v21, 1);
v7 = *((unsigned __int16 *)this + 28);
v8 = 3 * v7;
if ( *((_BYTE *)this + 72) )
{
v11 = (_BYTE *)operator new[](3 * v7 * *((unsigned __int16 *)this + 29));
v12 = *((unsigned __int16 *)this + 29);
if ( *((_WORD *)this + 29) )
{
v13 = *((unsigned __int16 *)this + 28);
v14 = 0;
do
{
v15 = 0;
if ( v13 )
{
do
{
v11[3 * v15 + 3 * v14 * v13] = *(_BYTE *)(*((_QWORD *)this + 8) + 4 * (v15 + v14 * v13));
v16 = v15 + *((unsigned __int16 *)this + 28) * v14;
v11[3 * v16 + 1] = *(_BYTE *)(*((_QWORD *)this + 8) + 4 * v16 + 1LL);
v17 = v15 + *((unsigned __int16 *)this + 28) * v14;
++v15;
v11[3 * v17 + 2] = *(_BYTE *)(*((_QWORD *)this + 8) + 4 * v17 + 2LL);
v13 = *((unsigned __int16 *)this + 28);
}
while ( v13 > v15 );
v12 = *((unsigned __int16 *)this + 29);
}
++v14;
}
while ( v12 > v14 );
}
for ( i = v26; v26 < v23; i = v26 )
{
v19 = &v11[i * v8];
jpeg_write_scanlines(v21, &v19, 1);
}
operator delete[](v11);
jpeg_finish_compress(v21);
fclose(v5);
jpeg_destroy_compress(v21);
return 1;
}
else
{
for ( j = v26; v26 < v23; j = v26 )
{
v19 = (char *)(*((_QWORD *)this + 8) + j * v8);
jpeg_write_scanlines(v21, &v19, 1);
}
jpeg_finish_compress(v21);
fclose(v5);
jpeg_destroy_compress(v21);
return 1;
}
}