added few new formats,

This commit is contained in:
hyzboy 2021-11-29 15:28:37 +08:00
parent eafa403f57
commit ce0fcde744
7 changed files with 82 additions and 17 deletions

View File

@ -19,6 +19,7 @@ class TextureFileCreaterCompress:public TextureFileCreater
CMP_TextureDataType tdt;
CMP_FORMAT source_fmt;
CMP_FORMAT target_fmt;
std::string target_fmt_name;
public:
@ -60,8 +61,10 @@ public:
const int fmt_index=size_t(pixel_format->format)-size_t(ColorFormat::BC1RGB);
target_fmt=fmt_list[fmt_index];
target_fmt_name=fmt_name_list[fmt_index];
std::cout<<"Compress Image to "<<fmt_name_list[fmt_index]<<" Format."<<std::endl;
std::cout<<"Compress Image to "<<target_fmt_name.c_str()<<" Format."<<std::endl;
if(type==IL_UNSIGNED_BYTE ){cf=CF_8bit; pixel_bytes=1;}else
if(type==IL_UNSIGNED_SHORT ){cf=CF_16bit; pixel_bytes=2;}else
@ -223,7 +226,7 @@ public:
kernel_options.getPerfStats =false;
kernel_options.getDeviceInfo=false;
std::cout<<"Compress Image To: "<<image->width()<<"x"<<image->height();
std::cout<<"Compress Image To: "<<image->width()<<"x"<<image->height()<<" "<<target_fmt_name.c_str()<<" format";
}
static bool CMP_API CMP_Feedback_Proc(CMP_FLOAT fProgress, CMP_DWORD_PTR pUser1, CMP_DWORD_PTR pUser2)

View File

@ -1,5 +1,6 @@
#include"TextureFileCreater.h"
#include"ILImage.h"
#include<iostream>
class TextureFileCreaterR:public TextureFileCreater
{

View File

@ -1,5 +1,6 @@
#include"TextureFileCreater.h"
#include"ILImage.h"
#include<iostream>
class TextureFileCreaterRG:public TextureFileCreater
{

View File

@ -14,6 +14,8 @@ public:
{
if(pixel_format->format==ColorFormat::RGBA8
||pixel_format->format==ColorFormat::RGBA16
||pixel_format->format==ColorFormat::RGBA16U
||pixel_format->format==ColorFormat::RGBA16I
||pixel_format->format==ColorFormat::RGBA16F
||pixel_format->format==ColorFormat::RGBA32U
||pixel_format->format==ColorFormat::RGBA32I
@ -22,7 +24,8 @@ public:
if(!ToILType(type,pixel_format->bits[0],pixel_format->type))
return(nullptr);
}
else if(pixel_format->format==ColorFormat::BGRA4)
else if(pixel_format->format==ColorFormat::RGBA4
||pixel_format->format==ColorFormat::BGRA4)
{
type=IL_UNSIGNED_BYTE;
}
@ -43,6 +46,20 @@ public:
return image->ConvertToRGBA(type);
}
void RGBA8toBGRA4(uint16 *target,uint8 *src,uint size)
{
for(uint i=0;i<size;i++)
{
*target=((src[2]<<8)&0xF000)
|((src[1]<<4)&0xF00)
|((src[0] )&0xF0)
| (src[3]>>4);
++target;
src+=4;
}
}
void RGBA8toRGBA4(uint16 *target,uint8 *src,uint size)
{
for(uint i=0;i<size;i++)
@ -56,7 +73,7 @@ public:
src+=4;
}
}
void RGBA8toA1RGB5(uint16 *target,uint8 *src,uint size)
{
for(uint i=0;i<size;i++)
@ -94,7 +111,12 @@ public:
std::cout<<"Convert Image To: "<<image->width()<<"x"<<image->height()<<" "<<total_bytes<<" bytes."<<std::endl;
if(pixel_format->format==ColorFormat::RGBA8
||pixel_format->format==ColorFormat::RGBA8SN
||pixel_format->format==ColorFormat::RGBA8U
||pixel_format->format==ColorFormat::RGBA8I
||pixel_format->format==ColorFormat::RGBA16
||pixel_format->format==ColorFormat::RGBA16U
||pixel_format->format==ColorFormat::RGBA16I
||pixel_format->format==ColorFormat::RGBA16F
||pixel_format->format==ColorFormat::RGBA32U
||pixel_format->format==ColorFormat::RGBA32I
@ -104,16 +126,34 @@ public:
return TextureFileCreater::Write(origin_rgba,total_bytes);
}
else if(pixel_format->format==ColorFormat::ABGR8)
{
uint32 *origin_rgba=(uint32 *)(image->GetRGBA(type));
EndianSwap<uint32>(origin_rgba,image->pixel_total());
return TextureFileCreater::Write(origin_rgba,total_bytes);
}
else if(pixel_format->format==ColorFormat::BGRA4)
{
void *origin_rgba=image->GetRGBA(IL_UNSIGNED_BYTE);
AutoDeleteArray<uint16> bgra4(image->pixel_total());
RGBA8toRGBA4(bgra4,(uint8 *)origin_rgba,image->pixel_total());
RGBA8toBGRA4(bgra4,(uint8 *)origin_rgba,image->pixel_total());
return TextureFileCreater::Write(bgra4,total_bytes);
}
else if(pixel_format->format==ColorFormat::RGBA4)
{
void *origin_rgba=image->GetRGBA(IL_UNSIGNED_BYTE);
AutoDeleteArray<uint16> rgba4(image->pixel_total());
RGBA8toRGBA4(rgba4,(uint8 *)origin_rgba,image->pixel_total());
return TextureFileCreater::Write(rgba4,total_bytes);
}
else if(pixel_format->format==ColorFormat::A1RGB5)
{
void *origin_rgba=image->GetRGBA(IL_UNSIGNED_BYTE);

View File

@ -4,6 +4,7 @@
#include<hgl/type/DataType.h>
#include<hgl/type/StrChar.h>
#include<hgl/Time.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/filesystem/EnumFile.h>
#include<hgl/log/LogInfo.h>
#include"pixel_format.h"
@ -88,12 +89,12 @@ public:
int os_main(int argc,os_char **argv)
{
std::cout<<"Image to Texture Convert tools 1.1"<<std::endl<<std::endl;
std::cout<<"Image to Texture Convert tools 1.2"<<std::endl<<std::endl;
if(argc<=1)
{
std::cout<< "Command format:\n"
"\tTexConv [/R:][/RG:][/RGB:][/RGBA:] [/s] [/mip] <pathname>\n"
"\tTexConv [/R:][/RG:][/RGB:][/RGBA:] [/s] [/mip] <pathname or filename>\n"
"\n"
"Params:\n"
"\t/s : proc sub-directory\n"
@ -116,22 +117,29 @@ int os_main(int argc,os_char **argv)
CMP_RegisterHostPlugins();
CMP_InitializeBCLibrary();
double start_time=GetMicroTime();
double end_time;
if(filesystem::FileCanRead(argv[argc-1]))
{
ConvertImage(argv[argc-1],pixel_fmt,gen_mipmaps);
}
else
{
double start_time=GetMicroTime();
double end_time;
EnumFileConfig efc(argv[argc-1]);
EnumFileConfig efc(argv[argc-1]);
efc.proc_file =true;
efc.sub_folder =sub_folder;
efc.proc_file =true;
efc.sub_folder =sub_folder;
EnumConvertImage eci;
EnumConvertImage eci;
eci.Enum(&efc);
eci.Enum(&efc);
end_time=GetTime();
end_time=GetTime();
LOG_INFO(OS_TEXT("总计转换图片")+OSString::valueOf(eci.GetConvertCount())
+OS_TEXT("张,总计耗时")+OSString::valueOf(end_time-start_time)+OS_TEXT(""));
LOG_INFO(OS_TEXT("Total converted ")+OSString::valueOf(eci.GetConvertCount())
+OS_TEXT("textures for ")+OSString::valueOf(end_time-start_time)+OS_TEXT(" seconds."));
}
CMP_ShutdownBCLibrary();
ilShutDown();

View File

@ -22,6 +22,7 @@ namespace hgl
constexpr PixelFormat pf_list[]=
{
{ColorFormat::RGBA4, "RGBA4", 4,{'R','G','B','A'},{ 4, 4, 4, 4}, 16,ColorDataType::UNORM},
{ColorFormat::BGRA4, "BGRA4", 4,{'B','G','R','A'},{ 4, 4, 4, 4}, 16,ColorDataType::UNORM},
{ColorFormat::RGB565, "RGB565", 3,{'R','G','B', 0 },{ 5, 6, 5, 0}, 16,ColorDataType::UNORM},
{ColorFormat::A1RGB5, "A1RGB5", 4,{'A','R','G','B'},{ 1, 5, 5, 5}, 16,ColorDataType::UNORM},
@ -31,10 +32,15 @@ namespace hgl
{ColorFormat::RGBA8SN, "RGBA8S", 4,{'R','G','B','A'},{ 8, 8, 8, 8}, 32,ColorDataType::SNORM},
{ColorFormat::RGBA8U, "RGBA8U", 4,{'R','G','B','A'},{ 8, 8, 8, 8}, 32,ColorDataType::UINT},
{ColorFormat::RGBA8I, "RGBA8I", 4,{'R','G','B','A'},{ 8, 8, 8, 8}, 32,ColorDataType::SINT},
{ColorFormat::ABGR8, "ABGR8", 4,{'A','B','G','R'},{ 8, 8, 8, 8}, 32,ColorDataType::UNORM},
{ColorFormat::A2BGR10, "A2BGR10", 4,{'A','B','G','R'},{ 2,10,10,10}, 32,ColorDataType::UNORM},
{ColorFormat::R16, "R16", 1,{'R', 0 , 0 , 0 },{16, 0, 0, 0}, 16,ColorDataType::UNORM},
{ColorFormat::R16U, "R16U", 1,{'R', 0 , 0 , 0 },{16, 0, 0, 0}, 16,ColorDataType::UINT},
{ColorFormat::R16I, "R16I", 1,{'R', 0 , 0 , 0 },{16, 0, 0, 0}, 16,ColorDataType::SINT},
{ColorFormat::R16F, "R16F", 1,{'R', 0 , 0 , 0 },{16, 0, 0, 0}, 16,ColorDataType::SFLOAT},
{ColorFormat::RG16, "RG16", 2,{'R','G', 0 , 0 },{16,16, 0, 0}, 32,ColorDataType::UNORM},
{ColorFormat::RG16U, "RG16U", 2,{'R','G', 0 , 0 },{16,16, 0, 0}, 32,ColorDataType::UINT},
{ColorFormat::RG16I, "RG16I", 2,{'R','G', 0 , 0 },{16,16, 0, 0}, 32,ColorDataType::SINT},
{ColorFormat::RG16F, "RG16F", 2,{'R','G', 0 , 0 },{16,16, 0, 0}, 32,ColorDataType::SFLOAT},
{ColorFormat::RGBA16, "RGBA16", 4,{'R','G','B','A'},{16,16,16,16}, 64,ColorDataType::UNORM},
{ColorFormat::RGBA16SN, "RGBA16S", 4,{'R','G','B','A'},{16,16,16,16}, 64,ColorDataType::SNORM},

View File

@ -8,6 +8,7 @@ enum class ColorFormat
{
NONE=0,
RGBA4,
BGRA4,
RGB565,
A1RGB5,
@ -17,10 +18,15 @@ enum class ColorFormat
RGBA8SN,
RGBA8U,
RGBA8I,
ABGR8,
A2BGR10,
R16,
R16U,
R16I,
R16F,
RG16,
RG16U,
RG16I,
RG16F,
RGBA16,
RGBA16SN,