2019-11-28 01:44:50 +08:00
|
|
|
|
#include<il/il.h>
|
2019-11-26 17:27:48 +08:00
|
|
|
|
#include<il/ilu.h>
|
|
|
|
|
#include<iostream>
|
2019-12-02 13:15:42 +08:00
|
|
|
|
#include<hgl/util/cmd/CmdParse.h>
|
2019-11-26 17:27:48 +08:00
|
|
|
|
#include"pixel_format.h"
|
|
|
|
|
#include<hgl/type/DataType.h>
|
|
|
|
|
#include<hgl/type/StrChar.h>
|
2019-11-28 21:40:06 +08:00
|
|
|
|
#include<hgl/Time.h>
|
|
|
|
|
#include<hgl/filesystem/EnumFile.h>
|
|
|
|
|
#include<hgl/log/LogInfo.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
|
|
|
|
|
2019-11-26 17:54:02 +08:00
|
|
|
|
bool sub_folder =false;
|
2019-11-26 17:27:48 +08:00
|
|
|
|
|
2019-11-26 17:54:02 +08:00
|
|
|
|
const PixelFormat * pixel_fmt[4] ={nullptr,nullptr,nullptr,nullptr}; //选中格式
|
|
|
|
|
bool gen_mipmaps =false; //是否产生mipmaps
|
2019-11-26 17:27:48 +08:00
|
|
|
|
|
2019-11-26 17:54:02 +08:00
|
|
|
|
bool use_color_key =false; //是否使用ColorKey
|
|
|
|
|
uint8 color_key[3]; //ColorKey颜色
|
|
|
|
|
|
2019-12-02 13:15:42 +08:00
|
|
|
|
const PixelFormat *ParseParamFormat(const CmdParse &cmd,const os_char *flag,const PixelFormat *default_format)
|
2019-11-26 17:27:48 +08:00
|
|
|
|
{
|
2019-12-02 13:15:42 +08:00
|
|
|
|
OSString fmtstr;
|
2019-11-26 17:27:48 +08:00
|
|
|
|
|
2019-12-02 13:15:42 +08:00
|
|
|
|
if(!cmd.GetString(flag,fmtstr))return(default_format);
|
2019-11-26 17:27:48 +08:00
|
|
|
|
|
|
|
|
|
const PixelFormat *result=GetPixelFormat(fmtstr.c_str());
|
|
|
|
|
|
|
|
|
|
if(result)return(result);
|
|
|
|
|
|
2019-12-02 13:15:42 +08:00
|
|
|
|
LOG_INFO(OS_TEXT("[FORMAT ERROR] Don't support ")+fmtstr+OS_TEXT(" format."));
|
2019-11-27 19:45:08 +08:00
|
|
|
|
|
2019-11-26 17:27:48 +08:00
|
|
|
|
return default_format;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-02 13:15:42 +08:00
|
|
|
|
void ParseParamFormat(const CmdParse &cmd)
|
2019-11-26 17:27:48 +08:00
|
|
|
|
{
|
|
|
|
|
//指定格式
|
2019-12-02 13:15:42 +08:00
|
|
|
|
pixel_fmt[0]=ParseParamFormat(cmd,OS_TEXT("/R:"), GetPixelFormat(ColorFormat::R8UN));
|
|
|
|
|
pixel_fmt[1]=ParseParamFormat(cmd,OS_TEXT("/RG:"), GetPixelFormat(ColorFormat::RG8UN));
|
|
|
|
|
pixel_fmt[2]=ParseParamFormat(cmd,OS_TEXT("/RGB:"), GetPixelFormat(ColorFormat::RGB565));
|
|
|
|
|
pixel_fmt[3]=ParseParamFormat(cmd,OS_TEXT("/RGBA:"), GetPixelFormat(ColorFormat::RGBA8UN));
|
2019-11-27 19:45:08 +08:00
|
|
|
|
|
|
|
|
|
for(uint i=0;i<4;i++)
|
|
|
|
|
std::cout<<i<<": "<<pixel_fmt[i]->name<<std::endl;
|
2019-11-26 17:27:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-02 13:15:42 +08:00
|
|
|
|
void ParamColorKey(const CmdParse &cmd)
|
2019-11-26 17:27:48 +08:00
|
|
|
|
{
|
2019-12-02 13:15:42 +08:00
|
|
|
|
OSString ckstr;
|
2019-11-26 17:27:48 +08:00
|
|
|
|
|
2019-12-02 13:15:42 +08:00
|
|
|
|
if(!cmd.GetString(OS_TEXT("/ColorKey:"),ckstr))return;
|
2019-11-26 17:27:48 +08:00
|
|
|
|
|
|
|
|
|
char rgbstr[6];
|
|
|
|
|
|
|
|
|
|
hgl_cpy(rgbstr,ckstr.c_str(),6); //注意:hgl_cpy是跨类型复制的,不要替换成strcpy或memcpy
|
|
|
|
|
|
|
|
|
|
ParseHexStr(color_key[0],rgbstr+0);
|
|
|
|
|
ParseHexStr(color_key[1],rgbstr+2);
|
|
|
|
|
ParseHexStr(color_key[2],rgbstr+4);
|
|
|
|
|
|
|
|
|
|
use_color_key=true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-28 21:40:06 +08:00
|
|
|
|
class EnumConvertImage:public EnumFile
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
uint convert_count=0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
void ProcFile(EnumFileConfig *efc,FileInfo &fi) override
|
|
|
|
|
{
|
|
|
|
|
//ConvertImage(fi.fullname);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
const uint GetConvertCount()const{return convert_count;}
|
|
|
|
|
};//class EnumConvertImage:public EnumFile
|
|
|
|
|
|
|
|
|
|
#if HGL_OS == HGL_OS_Windows
|
2019-12-02 13:15:42 +08:00
|
|
|
|
int wmain(int argc,wchar_t **argv)
|
2019-11-28 21:40:06 +08:00
|
|
|
|
#else
|
2019-11-26 17:27:48 +08:00
|
|
|
|
int main(int argc,char **argv)
|
2019-11-28 21:40:06 +08:00
|
|
|
|
#endif//
|
2019-11-26 17:27:48 +08:00
|
|
|
|
{
|
|
|
|
|
std::cout<<"Image to Texture Convert tools 1.1"<<std::endl<<std::endl;
|
|
|
|
|
|
|
|
|
|
if(argc<=1)
|
|
|
|
|
{
|
|
|
|
|
std::cout<< "Command format:\n"
|
2019-11-27 19:45:08 +08:00
|
|
|
|
"\tTexConv [/R:][/RG:][/RGB:][/RGBA:] [/s] [/mip] <filename or pathname>\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;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-02 13:15:42 +08:00
|
|
|
|
CmdParse cp(argc,argv);
|
2019-11-26 17:27:48 +08:00
|
|
|
|
|
2019-12-02 13:15:42 +08:00
|
|
|
|
if(cp.Find(OS_TEXT("/s"))!=-1)sub_folder=true; //检测是否处理子目录
|
|
|
|
|
if(cp.Find(OS_TEXT("/mip"))!=-1)gen_mipmaps=true; //检测是否生成mipmaps
|
2019-11-26 17:27:48 +08:00
|
|
|
|
|
2019-11-26 17:54:02 +08:00
|
|
|
|
ParamColorKey(cp);
|
2019-11-28 01:44:50 +08:00
|
|
|
|
ParseParamFormat(cp); //检测推荐格式
|
2019-11-26 17:27:48 +08:00
|
|
|
|
|
|
|
|
|
ilInit();
|
|
|
|
|
|
2019-11-28 21:40:06 +08:00
|
|
|
|
double start_time=GetMicroTime();
|
|
|
|
|
double end_time;
|
|
|
|
|
|
2019-12-02 13:15:42 +08:00
|
|
|
|
OSString cur_path;
|
|
|
|
|
|
|
|
|
|
GetCurrentPath(cur_path);
|
|
|
|
|
|
2019-11-28 21:40:06 +08:00
|
|
|
|
EnumFileConfig efc(cur_path);
|
|
|
|
|
|
|
|
|
|
efc.find_name =OSString(argv[1]);
|
|
|
|
|
efc.proc_file =true;
|
|
|
|
|
efc.sub_folder =sub_folder;
|
|
|
|
|
|
|
|
|
|
EnumConvertImage eci;
|
2019-12-02 13:15:42 +08:00
|
|
|
|
|
2019-11-28 21:40:06 +08:00
|
|
|
|
eci.Enum(&efc);
|
|
|
|
|
|
|
|
|
|
end_time=GetTime();
|
2019-11-26 17:27:48 +08:00
|
|
|
|
|
2019-11-28 21:40:06 +08:00
|
|
|
|
LOG_INFO(OS_TEXT("总计转换图片")+OSString(eci.GetConvertCount())
|
2019-12-02 13:15:42 +08:00
|
|
|
|
+OS_TEXT("张,总计耗时")+OSString(end_time-start_time)+OS_TEXT("秒"));
|
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
|
|
|
|
}
|