MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / loadImage

Method loadImage

framework/data.cpp:384–659  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

382}
383
384sp<Image> DataImpl::loadImage(const UString &path, bool lazy)
385{
386 std::lock_guard<std::recursive_mutex> l(this->imageCacheLock);
387 if (path == "")
388 {
389 return nullptr;
390 }
391
392 auto alias = this->imageAliases.find(path);
393 if (alias != this->imageAliases.end())
394 {
395 LogInfo("Using alias \"%s\" for \"%s\"", path, alias->second);
396 return this->loadImage(alias->second, lazy);
397 }
398
399 // Use an uppercase version of the path for the cache key
400 UString cacheKey = to_upper(path);
401 sp<Image> img;
402 // Don't cache lazy loading image wrappers, the image data when really loaded will go through
403 // the cache as normal, but we don't want to think we've loaded an image when it's just a lazy
404 // wrapper
405 if (!lazy)
406 {
407 img = this->imageCache[cacheKey].lock();
408 }
409 if (img)
410 {
411 return img;
412 }
413
414 // Only trace stuff that misses the cache
415
416 if (lazy)
417 {
418 img = mksp<LazyImage>();
419 }
420 else if (path.substr(0, 4) == "RAW:")
421 {
422 auto splitString = split(path, ":");
423 // Raw resources come in the format:
424 //"RAW:PATH:WIDTH:HEIGHT[:PALETTE]"
425 // or
426 //"RAW:PATH:WIDTH:HEIGHT:INDEX[:PALETTE]" (for imagesets)
427 if (splitString.size() != 4 && splitString.size() != 5 && splitString.size() != 6)
428 {
429 LogError("Invalid RAW resource string: \"%s\"", path);
430 return nullptr;
431 }
432
433 sp<PaletteImage> pImg;
434 size_t palettePos;
435 if (splitString.size() >= 5 && Strings::isInteger(splitString[4]))
436 {
437 auto imageSet = this->loadImageSet(splitString[0] + ":" + splitString[1] + ":" +
438 splitString[2] + ":" + splitString[3]);
439 if (!imageSet)
440 {
441 return nullptr;

Callers 15

loadPaletteMethod · 0.95
serializeInFunction · 0.45
FormPreviewMethod · 0.45
updateImageMethod · 0.45
LocationScreenMethod · 0.45
initMethod · 0.45
renderBaseMethod · 0.45
drawMiniBaseMethod · 0.45
createMapRowBuildingMethod · 0.45
createMapRowVehicleMethod · 0.45
createMapRowBaseMethod · 0.45
AEquipScreenMethod · 0.45

Calls 13

loadImageSetMethod · 0.95
loadPaletteMethod · 0.95
loadVoxelSliceMethod · 0.95
to_upperFunction · 0.85
splitFunction · 0.85
endMethod · 0.80
toRGBImageMethod · 0.80
getBitMethod · 0.80
openMethod · 0.80
pushMethod · 0.80
popMethod · 0.80
sizeMethod · 0.45

Tested by 1

testImageFunction · 0.36