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

Method loadPalette

framework/data.cpp:661–738  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

659}
660
661sp<Palette> DataImpl::loadPalette(const UString &path)
662{
663 std::lock_guard<std::recursive_mutex> l(this->paletteCacheLock);
664 if (path == "")
665 {
666 LogWarning("Invalid palette path");
667 return nullptr;
668 }
669
670 auto alias = this->paletteAliases.find(path);
671 if (alias != this->paletteAliases.end())
672 {
673 LogInfo("Using alias \"%s\" for \"%s\"", path, alias->second);
674 return this->loadPalette(alias->second);
675 }
676
677 // Use an uppercase version of the path for the cache key
678 UString cacheKey = to_upper(path);
679
680 auto pal = this->paletteCache[cacheKey].lock();
681 if (pal)
682 {
683 return pal;
684 }
685
686 pal = loadPCXPalette(*this, path);
687 if (pal)
688 {
689 LogInfo("Read \"%s\" as PCX palette", path);
690 this->paletteCache[cacheKey] = pal;
691 this->pinnedPalettes.push(pal);
692 this->pinnedPalettes.pop();
693 return pal;
694 }
695 pal = loadPNGPalette(*this, path);
696 if (pal)
697 {
698 LogInfo("Read \"%s\" as PNG palette", path);
699 this->paletteCache[cacheKey] = pal;
700 this->pinnedPalettes.push(pal);
701 this->pinnedPalettes.pop();
702 return pal;
703 }
704
705 sp<RGBImage> img = std::dynamic_pointer_cast<RGBImage>(this->loadImage(path));
706 if (img)
707 {
708 unsigned int idx = 0;
709 auto p = mksp<Palette>(img->size.x * img->size.y);
710 RGBImageLock src{img, ImageLockUse::Read};
711 for (unsigned int y = 0; y < img->size.y; y++)
712 {
713 for (unsigned int x = 0; x < img->size.x; x++)
714 {
715 Colour c = src.get(Vec2<int>{x, y});
716 p->setColour(idx, c);
717 idx++;
718 }

Callers 14

loadImageMethod · 0.95
writeImageMethod · 0.95
bulkExportPcksMethod · 0.80
AEquipScreenMethod · 0.80
VEquipScreenMethod · 0.80
BattleTileViewMethod · 0.80
CityTileViewMethod · 0.80
dumpPckFunction · 0.80
extractCitySceneryMethod · 0.80
main.cppFile · 0.80
runMethod · 0.80
displayInitialiseMethod · 0.80

Calls 9

loadImageMethod · 0.95
to_upperFunction · 0.85
loadPCXPaletteFunction · 0.85
loadApocPaletteFunction · 0.85
endMethod · 0.80
pushMethod · 0.80
popMethod · 0.80
setColourMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected