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

Method writeImage

framework/data.cpp:763–849  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

761}
762
763bool DataImpl::writeImage(UString systemPath, sp<Image> image, sp<Palette> palette)
764{
765 auto outPath = fs::path(systemPath);
766 auto outDir = outPath.parent_path();
767 if (!outDir.empty())
768 {
769 if (!fs::exists(outDir))
770 {
771 try
772 {
773 fs::create_directories(outDir);
774 }
775 // Just catch any problem and continue anyway?
776 catch (fs::filesystem_error &e)
777 {
778 LogWarning("create_directories failed with \"%s\"", e.what());
779 }
780 }
781 else if (!fs::is_directory(outDir))
782 {
783 LogWarning("Cannot open %s: %s is not a directory", outPath, outDir);
784 return false;
785 }
786 }
787 std::ofstream outFile(systemPath, std::ios::binary);
788 if (!outFile)
789 {
790 LogWarning("Failed to open \"%s\" for writing", systemPath);
791 return false;
792 }
793
794 for (auto &writer : imageWriters)
795 {
796 auto palImg = std::dynamic_pointer_cast<PaletteImage>(image);
797 auto rgbImg = std::dynamic_pointer_cast<RGBImage>(image);
798 if (palImg)
799 {
800 if (!palette)
801 {
802 UString defaultPalettePath = "xcom3/ufodata/pal_01.dat";
803 LogInfo("Loading default palette \"%s\"", defaultPalettePath);
804 palette = this->loadPalette(defaultPalettePath);
805 if (!palette)
806 {
807 LogWarning("Failed to write palette image - no palette supplied and failed to "
808 "load default");
809 return false;
810 }
811 }
812 if (writer->writeImage(palImg, outFile, palette))
813 {
814 LogInfo("Successfully wrote palette image \"%s\" using \"%s\"", systemPath,
815 writer->getName());
816 return true;
817 }
818 else
819 {
820 LogWarning("Failed to write palette image \"%s\" using \"%s\"", systemPath,

Callers 10

bulkExportPcksMethod · 0.45
eventOccurredMethod · 0.45
eventOccurredMethod · 0.45
mainFunction · 0.45
dumpLofTempsFunction · 0.45
dumpRawFunction · 0.45
dumpPckFunction · 0.45
dumpPcxFunction · 0.45
main.cppFile · 0.45
processEventsMethod · 0.45

Calls 3

loadPaletteMethod · 0.95
emptyMethod · 0.80
getNameMethod · 0.45

Tested by

no test coverage detected