| 1322 | } |
| 1323 | |
| 1324 | bool CAImage::initWithImageFileThreadSafe(const std::string& fullPath) |
| 1325 | { |
| 1326 | unsigned long pSize = 0; |
| 1327 | unsigned char* data = CCFileUtils::sharedFileUtils()->getFileData(fullPath.c_str(), "rb", &pSize); |
| 1328 | bool ret = false; |
| 1329 | |
| 1330 | do |
| 1331 | { |
| 1332 | CC_BREAK_IF(! data || pSize <= 0); |
| 1333 | |
| 1334 | unsigned char* unpackedData = NULL; |
| 1335 | unsigned long unpackedLen = 0; |
| 1336 | |
| 1337 | unpackedData = const_cast<unsigned char*>(data); |
| 1338 | unpackedLen = pSize; |
| 1339 | |
| 1340 | Format type = this->detectFormat(unpackedData, unpackedLen); |
| 1341 | |
| 1342 | switch (type) |
| 1343 | { |
| 1344 | case JPG: |
| 1345 | ret = this->initWithJpgData(unpackedData, unpackedLen); |
| 1346 | break; |
| 1347 | case PNG: |
| 1348 | ret = this->initWithPngData(unpackedData, unpackedLen); |
| 1349 | break; |
| 1350 | case GIF: |
| 1351 | ret = this->initWithGifData(unpackedData, unpackedLen); |
| 1352 | break; |
| 1353 | case TIFF: |
| 1354 | ret = this->initWithTiffData(unpackedData, unpackedLen); |
| 1355 | break; |
| 1356 | case WEBP: |
| 1357 | ret = this->initWithWebpData(unpackedData, unpackedLen); |
| 1358 | break; |
| 1359 | case ETC: |
| 1360 | ret = this->initWithETCData(unpackedData, unpackedLen); |
| 1361 | break; |
| 1362 | default: |
| 1363 | { |
| 1364 | ret = false; |
| 1365 | break; |
| 1366 | } |
| 1367 | } |
| 1368 | |
| 1369 | if (ret) |
| 1370 | { |
| 1371 | this->convertToRawData(); |
| 1372 | } |
| 1373 | |
| 1374 | if(unpackedData != data) |
| 1375 | { |
| 1376 | free(unpackedData); |
| 1377 | } |
| 1378 | |
| 1379 | } while (0); |
| 1380 | |
| 1381 | return ret; |
no test coverage detected