From ce0fcde7445cc722921a72c7ab418d1f1eecc48b Mon Sep 17 00:00:00 2001 From: hyzboy Date: Mon, 29 Nov 2021 15:28:37 +0800 Subject: [PATCH] added few new formats, --- TextureFileCreaterCompress.cpp | 7 ++++-- TextureFileCreaterR.cpp | 1 + TextureFileCreaterRG.cpp | 1 + TextureFileCreaterRGBA.cpp | 46 +++++++++++++++++++++++++++++++--- main.cpp | 32 ++++++++++++++--------- pixel_format.cpp | 6 +++++ pixel_format.h | 6 +++++ 7 files changed, 82 insertions(+), 17 deletions(-) diff --git a/TextureFileCreaterCompress.cpp b/TextureFileCreaterCompress.cpp index ca84d58..45cf440 100644 --- a/TextureFileCreaterCompress.cpp +++ b/TextureFileCreaterCompress.cpp @@ -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 "<width()<<"x"<height(); + std::cout<<"Compress Image To: "<width()<<"x"<height()<<" "< class TextureFileCreaterR:public TextureFileCreater { diff --git a/TextureFileCreaterRG.cpp b/TextureFileCreaterRG.cpp index 6a82c82..191f987 100644 --- a/TextureFileCreaterRG.cpp +++ b/TextureFileCreaterRG.cpp @@ -1,5 +1,6 @@ #include"TextureFileCreater.h" #include"ILImage.h" +#include class TextureFileCreaterRG:public TextureFileCreater { diff --git a/TextureFileCreaterRGBA.cpp b/TextureFileCreaterRGBA.cpp index 4f053ec..770736f 100644 --- a/TextureFileCreaterRGBA.cpp +++ b/TextureFileCreaterRGBA.cpp @@ -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>4); + + ++target; + src+=4; + } + } + void RGBA8toRGBA4(uint16 *target,uint8 *src,uint size) { for(uint i=0;iwidth()<<"x"<height()<<" "<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(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 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 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); diff --git a/main.cpp b/main.cpp index 9acf299..7ee0095 100644 --- a/main.cpp +++ b/main.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #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"<\n" + "\tTexConv [/R:][/RG:][/RGB:][/RGBA:] [/s] [/mip] \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(); diff --git a/pixel_format.cpp b/pixel_format.cpp index 6264619..53a6c1d 100644 --- a/pixel_format.cpp +++ b/pixel_format.cpp @@ -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}, diff --git a/pixel_format.h b/pixel_format.h index f231471..84aa94a 100644 --- a/pixel_format.h +++ b/pixel_format.h @@ -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,