| 382 | } |
| 383 | |
| 384 | sp<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; |