1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Convert PCX to PNG, Final touches, everything deactivated.

This commit is contained in:
krs 2022-11-19 00:03:46 +02:00
parent d1cdd7d59f
commit cca1f074bf
4 changed files with 57 additions and 85 deletions

View File

@ -20,7 +20,7 @@ VCMI_LIB_NAMESPACE_BEGIN
namespace bfs = boost::filesystem; namespace bfs = boost::filesystem;
const bool extractArchives = 1; const bool extractArchives = false;
ArchiveEntry::ArchiveEntry() ArchiveEntry::ArchiveEntry()
: offset(0), fullSize(0), compressedSize(0) : offset(0), fullSize(0), compressedSize(0)

View File

@ -26,16 +26,6 @@ namespace bfs = boost::filesystem;
typedef std::map<size_t, std::vector<JsonNode>> source_map; typedef std::map<size_t, std::vector<JsonNode>> source_map;
// ToDo: krs - temp location for this function. Need to move to right lib and see if it works on other platforms.
QString QStringFromPath(const bfs::path& filePath)
{
#ifdef _WIN32
return QString::fromStdWString(filePath.generic_wstring());
#else
return QString::fromStdString(filePath.native());
#endif
}
/// Class for def loading /// Class for def loading
/// After loading will store general info (palette and frame offsets) and pointer to file itself /// After loading will store general info (palette and frame offsets) and pointer to file itself
class DefFile class DefFile
@ -826,3 +816,12 @@ void Animation::createFlippedGroup(const size_t sourceGroup, const size_t target
*image = image->transformed(QTransform::fromScale(1, -1)); *image = image->transformed(QTransform::fromScale(1, -1));
} }
} }
QString QStringFromPath(const bfs::path& filePath)
{
#ifdef _WIN32
return QString::fromStdWString(filePath.generic_wstring());
#else
return QString::fromStdString(filePath.native());
#endif
}

View File

@ -83,7 +83,7 @@ public:
void load (size_t frame, size_t group = 0); void load (size_t frame, size_t group = 0);
void unload(size_t frame, size_t group = 0); void unload(size_t frame, size_t group = 0);
void exportBitmaps(const boost::filesystem::path& path, bool prependResourceName) const; void exportBitmaps(const boost::filesystem::path& path, bool prependResourceName = false) const;
//total count of frames in group (including not loaded) //total count of frames in group (including not loaded)
size_t size(size_t group = 0) const; size_t size(size_t group = 0) const;
@ -94,3 +94,6 @@ public:
void createFlippedGroup(const size_t sourceGroup, const size_t targetGroup); void createFlippedGroup(const size_t sourceGroup, const size_t targetGroup);
}; };
// ToDo: krs - temp location for this function. Need to move to right lib and see if it works on other platforms.
QString QStringFromPath(const boost::filesystem::path& filePath);

View File

@ -6,63 +6,54 @@
#include "../lib/VCMIDirs.h" #include "../lib/VCMIDirs.h"
#include "../lib/filesystem/Filesystem.h" #include "../lib/filesystem/Filesystem.h"
//#include "SDL.h" #include "BitmapHandler.h"
#include "Animation.h" #include "Animation.h"
//#include "CBitmapHandler.h"
#include "boost/filesystem/path.hpp" #include "boost/filesystem/path.hpp"
#include "boost/locale.hpp" #include "boost/locale.hpp"
namespace bfs = boost::filesystem; namespace bfs = boost::filesystem;
bool split_def_files = 1; bool split_def_files = false; // splits TwCrPort, CPRSMALL, FlagPort, ITPA, ITPt, Un32 and Un44 into individual PNG's
bool convert_pcx_to_bmp = 0; // converts Images from .pcx to bmp. Can be used when you have .pcx converted already bool convert_pcx_to_png = false; // converts single Images (found in Images folder) from .pcx to png.
bool delete_source_files = 0; // delete source files or leave a copy in place. bool delete_source_files = false; // delete source files after splitting / conversion.
// converts all pcx files into bmp (H3 saves images as .pcx) // converts all pcx files from /Images into PNG
//void convertPcxToBmp() void convertPcxToPng()
//{ {
// bfs::path extractedPath = VCMIDirs::get().userDataPath() / "extracted"; bfs::path imagesPath = VCMIDirs::get().userCachePath() / "extracted" / "Images";
// bfs::path imagesPath = extractedPath / "Images"; bfs::directory_iterator end_iter;
//
// bfs::directory_iterator end_iter;
//
// for ( bfs::directory_iterator dir_itr(imagesPath); dir_itr != end_iter; ++dir_itr )
// {
// try
// {
// if ( bfs::is_regular_file( dir_itr->status() ) )
// {
// std::string filename = dir_itr->path().filename().string();
// filename = boost::locale::to_lower(filename);
//
// if(filename.find(".pcx") != std::string::npos)
// {
// SDL_Surface *bitmap;
//
// bitmap = BitmapHandler::loadBitmap(filename);
//
// if(delete_source_files)
// bfs::remove(imagesPath / filename);
//
// bfs::path outFilePath = imagesPath / filename;
// outFilePath.replace_extension(".bmp");
// SDL_SaveBMP(bitmap, outFilePath.string().c_str());
// }
// }
// else
// {
// logGlobal->info(dir_itr->path().filename().string() + " [other]\n");
// }
// }
// catch ( const std::exception & ex )
// {
// logGlobal->info(dir_itr->path().filename().string() + " " + ex.what() + "\n");
// }
// }
//}
// splits a def file into individual parts for ( bfs::directory_iterator dir_itr(imagesPath); dir_itr != end_iter; ++dir_itr )
{
try
{
if (!bfs::is_regular_file(dir_itr->status()))
return;
std::string filePath = dir_itr->path().string();
std::string fileStem = dir_itr->path().stem().string();
std::string filename = dir_itr->path().filename().string();
filename = boost::locale::to_lower(filename);
if(filename.find(".pcx") != std::string::npos)
{
auto img = BitmapHandler::loadBitmap(filename);
bfs::path pngFilePath = imagesPath / (fileStem + ".png");
img.save(QStringFromPath(pngFilePath), "PNG");
if (delete_source_files)
bfs::remove(filePath);
}
}
catch ( const std::exception & ex )
{
logGlobal->info(dir_itr->path().filename().string() + " " + ex.what() + "\n");
}
}
}
// splits a def file into individual parts and converts the output to PNG format
void splitDefFile(std::string fileName, bfs::path spritesPath) void splitDefFile(std::string fileName, bfs::path spritesPath)
{ {
if (CResourceHandler::get()->existsResource(ResourceID("SPRITES/" + fileName))) if (CResourceHandler::get()->existsResource(ResourceID("SPRITES/" + fileName)))
@ -79,7 +70,7 @@ void splitDefFile(std::string fileName, bfs::path spritesPath)
logGlobal->error("Def File Split error! " + fileName); logGlobal->error("Def File Split error! " + fileName);
} }
// split def files, this way faction resources are independent // splits def files (TwCrPort, CPRSMALL, FlagPort, ITPA, ITPt, Un32 and Un44), this way faction resources are independent
void splitDefFiles() void splitDefFiles()
{ {
bfs::path extractedPath = VCMIDirs::get().userDataPath() / "extracted"; bfs::path extractedPath = VCMIDirs::get().userDataPath() / "extracted";
@ -100,27 +91,6 @@ void ConvertOriginalResourceFiles()
if (split_def_files) if (split_def_files)
splitDefFiles(); splitDefFiles();
//if (convert_pcx_to_bmp) if (convert_pcx_to_png)
// convertPcxToBmp(); convertPcxToPng();
} }