2019-12-02 22:10:49 +08:00
|
|
|
|
#include<iostream>
|
2019-12-02 22:24:06 +08:00
|
|
|
|
#include<IL/il.h>
|
2023-09-22 23:22:04 +08:00
|
|
|
|
#include<IL/ilu.h>
|
2023-09-21 23:40:46 +08:00
|
|
|
|
#include<hgl/log/LogInfo.h>
|
2019-12-02 13:15:42 +08:00
|
|
|
|
#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>
|
2020-08-06 18:18:34 +08:00
|
|
|
|
#include"CMP_CompressonatorLib/Compressonator.h"
|
2021-12-06 12:07:38 +08:00
|
|
|
|
#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;
|
2019-12-02 13:15:42 +08:00
|
|
|
|
using namespace hgl::util;
|
2019-11-26 17:27:48 +08:00
|
|
|
|
|
2021-12-06 12:07:38 +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();
|
|
|
|
|
|
2021-12-06 12:07:38 +08:00
|
|
|
|
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:
|
|
|
|
|
|
2021-12-06 12:07:38 +08:00
|
|
|
|
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;}
|
2021-12-06 12:07:38 +08:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2023-09-22 23:22:04 +08:00
|
|
|
|
std::cout<<"Image to Texture Convert tools 1.3b"<<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"
|
2019-11-27 19:45:08 +08:00
|
|
|
|
"\n";
|
2019-11-26 17:27:48 +08:00
|
|
|
|
|
2019-11-27 19:45:08 +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"));
|
|
|
|
|
|
2019-12-02 13:15:42 +08:00
|
|
|
|
CmdParse cp(argc,argv);
|
2019-11-26 17:27:48 +08:00
|
|
|
|
|
2021-12-06 12:07:38 +08:00
|
|
|
|
ImageConvertConfig icc;
|
|
|
|
|
|
2019-12-02 13:15:42 +08:00
|
|
|
|
if(cp.Find(OS_TEXT("/s"))!=-1)sub_folder=true; //检测是否处理子目录
|
2021-12-06 12:07:38 +08:00
|
|
|
|
if(cp.Find(OS_TEXT("/mip"))!=-1)icc.gen_mipmaps=true; //检测是否生成mipmaps
|
2019-11-26 17:27:48 +08:00
|
|
|
|
|
2021-12-06 12:07:38 +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();
|
2023-09-22 23:22:04 +08:00
|
|
|
|
iluImageParameter(ILU_FILTER,ILU_SCALE_MITCHELL);
|
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]))
|
|
|
|
|
{
|
2021-12-06 12:07:38 +08:00
|
|
|
|
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]);
|
2019-12-02 13:15:42 +08:00
|
|
|
|
|
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
|
|
|
|
|
2021-12-06 12:07:38 +08:00
|
|
|
|
EnumConvertImage eci(&icc);
|
2019-12-02 13:15:42 +08:00
|
|
|
|
|
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;
|
|
|
|
|
|
2023-09-21 23:40:46 +08:00
|
|
|
|
const OSString time_gap_str=OSString::floatOf(time_gap,2);
|
2019-11-26 17:27:48 +08:00
|
|
|
|
|
2023-02-07 23:03:26 +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
|
|
|
|
}
|
2022-08-04 10:52:49 +08:00
|
|
|
|
|
2020-10-25 21:22:18 +08:00
|
|
|
|
CMP_ShutdownBCLibrary();
|
2019-11-26 17:27:48 +08:00
|
|
|
|
ilShutDown();
|
2019-11-27 19:45:08 +08:00
|
|
|
|
return 0;
|
2019-11-26 17:27:48 +08:00
|
|
|
|
}
|