bool Image::initWithImageFileThreadSafe(const char *fullpath) { bool ret = false; KDint32 dataLen = 0; unsigned char *buffer = FileUtils::getInstance()->getFileData(fullpath, "rb", &dataLen); if (buffer != NULL && dataLen > 0) { ret = initWithImageData(buffer, dataLen); } kdFree(buffer); return ret; }
bool Cc3dImage::initWithImageFile(const char * strPath) { bool bRet = false; unsigned long nSize = 0; std::string fullPath = Cc3dFileUtils::sharedFileUtils()->getFullPath(strPath); unsigned char* pBuffer = Cc3dFileUtils::sharedFileUtils()->getFileData(fullPath.c_str(), "rb", &nSize); if (pBuffer != NULL && nSize > 0) { bRet = initWithImageData(pBuffer, nSize); } if(pBuffer) { delete[] (pBuffer); pBuffer = NULL; } return bRet; }
bool Image::initWithImageFile(const char * strPath) { bool bRet = false; std::string fullPath = FileUtils::getInstance()->fullPathForFilename(strPath); #ifdef EMSCRIPTEN // Emscripten includes a re-implementation of SDL that uses HTML5 canvas // operations underneath. Consequently, loading images via IMG_Load (an SDL // API) will be a lot faster than running libpng et al as compiled with // Emscripten. SDL_Surface *iSurf = IMG_Load(fullPath.c_str()); int size = 4 * (iSurf->w * iSurf->h); bRet = initWithRawData((const unsigned char*)iSurf->pixels, size, iSurf->w, iSurf->h, 8, true); unsigned int *tmp = (unsigned int *)m_pData; int nrPixels = iSurf->w * iSurf->h; for (int i = 0; i < nrPixels; i++) { unsigned char *p = m_pData + i * 4; tmp[i] = CC_RGB_PREMULTIPLY_ALPHA(p[0], p[1], p[2], p[3]); } SDL_FreeSurface(iSurf); #else KDint32 bufferLen = 0; unsigned char* buffer = FileUtils::getInstance()->getFileData(fullPath.c_str(), "rb", &bufferLen); if (buffer != nullptr && bufferLen > 0) { bRet = initWithImageData(buffer, bufferLen); } kdFree(buffer); #endif // EMSCRIPTEN return bRet; }
bool CCImage::initWithImageFileThreadSafe(const char *fullpath, EImageFormat imageType) { CC_UNUSED_PARAM(imageType); CCFileData data(fullpath, "rb"); return initWithImageData(data.getBuffer(), data.getSize(), imageType); }
bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = eFmtPng*/) { CC_UNUSED_PARAM(eImgFmt); CCFileData data(CCFileUtils::fullPathFromRelativePath(strPath), "rb"); return initWithImageData(data.getBuffer(), data.getSize(), eImgFmt); }