TexConv/main.cpp

112 lines
2.6 KiB
C++
Raw Normal View History

2019-12-02 22:10:49 +08:00
#include<iostream>
2019-12-02 22:24:06 +08:00
#include<IL/il.h>
#include<hgl/util/cmd/CmdParse.h>
2019-11-28 21:40:06 +08:00
#include<hgl/Time.h>
2021-11-29 15:28:37 +08:00
#include<hgl/filesystem/FileSystem.h>
2019-11-28 21:40:06 +08:00
#include<hgl/filesystem/EnumFile.h>
#include"CMP_CompressonatorLib/Compressonator.h"
#include"ImageConvertConfig.h"
#include"ParamParse.h"
2019-11-26 17:27:48 +08:00
using namespace hgl;
2019-11-28 21:40:06 +08:00
using namespace hgl::filesystem;
using namespace hgl::util;
2019-11-26 17:27:48 +08:00
bool sub_folder =false;
2019-11-26 17:54:02 +08:00
2020-10-25 21:22:18 +08:00
void CMP_RegisterHostPlugins();
bool ConvertImage(const OSString &filename,const ImageConvertConfig *cfg);
2019-11-26 17:27:48 +08:00
2019-11-28 21:40:06 +08:00
class EnumConvertImage:public EnumFile
{
private:
ImageConvertConfig *cfg;
2019-11-28 21:40:06 +08:00
uint convert_count=0;
protected:
void ProcFile(EnumFileConfig *efc,FileInfo &fi) override
{
2021-12-13 13:47:08 +08:00
if(ConvertImage(fi.fullname,cfg))
++convert_count;
2019-11-28 21:40:06 +08:00
}
public:
const uint GetConvertCount()const{return convert_count;}
EnumConvertImage(ImageConvertConfig *icc)
{
cfg=icc;
}
2019-11-28 21:40:06 +08:00
};//class EnumConvertImage:public EnumFile
2020-06-04 17:41:10 +08:00
int os_main(int argc,os_char **argv)
2019-11-26 17:27:48 +08:00
{
2022-06-23 18:33:52 +08:00
std::cout<<"Image to Texture Convert tools 1.3a"<<std::endl<<std::endl;
2019-11-26 17:27:48 +08:00
if(argc<=1)
{
std::cout<< "Command format:\n"
2021-11-29 15:28:37 +08:00
"\tTexConv [/R:][/RG:][/RGB:][/RGBA:] [/s] [/mip] <pathname or filename>\n"
2019-11-26 17:27:48 +08:00
"\n"
"Params:\n"
"\t/s : proc sub-directory\n"
"\n";
2019-11-26 17:27:48 +08:00
PrintFormatList();
2019-11-26 17:27:48 +08:00
return 0;
}
2022-11-08 19:11:55 +08:00
logger::InitLogger(OS_TEXT("TexConv"));
CmdParse cp(argc,argv);
2019-11-26 17:27:48 +08:00
ImageConvertConfig icc;
if(cp.Find(OS_TEXT("/s"))!=-1)sub_folder=true; //检测是否处理子目录
if(cp.Find(OS_TEXT("/mip"))!=-1)icc.gen_mipmaps=true; //检测是否生成mipmaps
2019-11-26 17:27:48 +08:00
ParseParamColorKey(&icc,cp);
ParseParamFormat(&icc,cp); //检测推荐格式
2021-12-06 10:47:34 +08:00
2019-11-26 17:27:48 +08:00
ilInit();
2020-10-25 21:22:18 +08:00
CMP_RegisterHostPlugins();
CMP_InitializeBCLibrary();
2019-11-26 17:27:48 +08:00
2021-11-29 15:28:37 +08:00
if(filesystem::FileCanRead(argv[argc-1]))
{
ConvertImage(argv[argc-1],&icc);
2021-11-29 15:28:37 +08:00
}
else
{
double start_time=GetMicroTime();
double end_time;
2019-11-28 21:40:06 +08:00
2021-11-29 15:28:37 +08:00
EnumFileConfig efc(argv[argc-1]);
2021-11-29 15:28:37 +08:00
efc.proc_file =true;
efc.sub_folder =sub_folder;
2019-11-28 21:40:06 +08:00
EnumConvertImage eci(&icc);
2021-11-29 15:28:37 +08:00
eci.Enum(&efc);
2019-11-28 21:40:06 +08:00
2021-11-29 17:44:12 +08:00
end_time=GetMicroTime();
const double time_gap=(end_time-start_time)/1000000;
const OSString time_gap_str=OSString::numberOf(time_gap);
2019-11-26 17:27:48 +08:00
LOG_INFO(OS_TEXT("Total converted ")+OSString::numberOf(eci.GetConvertCount())
2021-11-29 17:44:12 +08:00
+OS_TEXT(" textures for ")+time_gap_str.c_str()+OS_TEXT(" seconds."));
2021-11-29 15:28:37 +08:00
}
2020-10-25 21:22:18 +08:00
CMP_ShutdownBCLibrary();
2019-11-26 17:27:48 +08:00
ilShutDown();
return 0;
2019-11-26 17:27:48 +08:00
}