//
// cocos2d::CCRenderTexture::newCCImage from 0x5d89a8 to 0x5d8ab6 (270 bytes)
//
// 3 xrefs:
// > cocos2d::CCRenderTexture::listenToBackground @ 0x5d8ad0
// > cocos2d::CCRenderTexture::saveToFile @ 0x5d8b22
// > cocos2d::CCRenderTexture::saveToFile @ 0x5d8b56
//
// 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
//
cocos2d::CCImage *cocos2d::CCRenderTexture::newCCImage(cocos2d::CCRenderTexture *a1, bool a2)
{
cocos2d::CCImage *result; // r0
_BOOL4 v4; // r11
const cocos2d::CCSize *ContentSizeInPixels; // r0
GLsizei width; // r5
GLsizei height; // s15
cocos2d::CCImage *v8; // r4
char *v9; // r10
char *pixels; // r8
int v11; // r9
size_t v12; // r12
char *v13; // r3
GLsizei v14; // r11
char *v15; // r0
size_t v16; // [sp+1Ch] [bp-8h]
result = (cocos2d::CCImage *)a1->m_pTexture;
v4 = a2;
if ( result )
{
ContentSizeInPixels = cocos2d::CCTexture2D::getContentSizeInPixels((cocos2d::CCTexture2D *)result);
width = (int)ContentSizeInPixels->width;
height = (int)ContentSizeInPixels->height;
v8 = (cocos2d::CCImage *)operator new(0x48u);
cocos2d::CCImage::CCImage(v8);
v9 = (char *)operator new[](4 * height * width);
pixels = (char *)operator new[](4 * height * width);
cocos2d::CCRenderTexture::begin(a1);
glPixelStorei(0xD05u, 1);
glReadPixels(0, 0, width, height, 0x1908u, 0x1401u, pixels);
cocos2d::CCRenderTexture::end(a1);
if ( v4 )
{
v11 = 0;
v12 = 4 * width;
v13 = v9;
v14 = 0;
while ( 1 )
{
v11 -= 4 * width;
if ( v14 >= height )
break;
v16 = v12;
++v14;
v15 = (char *)memcpy(v13, &pixels[4 * width + 4 * width * (height - 1) + v11], v12);
v12 = v16;
v13 = &v15[v16];
}
cocos2d::CCImage::initWithImageData(v8, v9, 4 * height * width, kFmtRawData, width, height, 8, 0);
}
else
{
cocos2d::CCImage::initWithImageData(v8, pixels, 4 * height * width, kFmtRawData, width, height, 8, 0);
}
operator delete[](v9);
operator delete[](pixels);
return v8;
}
return result;
}