From 0a3c620c0b459d0effff1468aa3e4cf811c2b004 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sat, 8 Aug 2020 22:20:46 +0800 Subject: [PATCH] fix RGBA --- ILImage.h | 4 +--- ILImageSupport.cpp | 27 +++++++++++++++++++++++++++ TextureFileCreater.cpp | 2 +- TextureFileCreaterCompress.cpp | 22 ++++++++++------------ pixel_format.cpp | 3 +-- pixel_format.h | 3 +-- 6 files changed, 41 insertions(+), 20 deletions(-) diff --git a/ILImage.h b/ILImage.h index 249b764..303d907 100644 --- a/ILImage.h +++ b/ILImage.h @@ -51,9 +51,7 @@ public: void *GetRG(ILuint type){return GetData(IL_LUMINANCE_ALPHA,type);} void *GetRGB(ILuint type){return GetData(IL_RGB,type);} -// void *GetBGR(ILuint type){return GetData(IL_BGR,type);} - void *GetRGBA(ILuint type){return GetData(IL_RGBA,type);} -// void *GetBGRA(ILuint type){return GetData(IL_BGRA,type);} + void *GetRGBA(ILuint type); void *GetLum(ILuint type){return GetData(IL_LUMINANCE,type);} };//class ILImage diff --git a/ILImageSupport.cpp b/ILImageSupport.cpp index 7f57647..722c621 100644 --- a/ILImageSupport.cpp +++ b/ILImageSupport.cpp @@ -240,3 +240,30 @@ void *ILImage::GetData(ILuint format,ILuint type) return ilGetData(); } + +template void MixRGBA(T *rgba,T *alpha,int size) +{ + int i; + + for(i=0;i((uint8 *)data,(uint8 *)alpha,size);else + if(type==IL_UNSIGNED_SHORT ||type==IL_SHORT||type==IL_HALF )MixRGBA((uint16 *)data,(uint16 *)alpha,size);else + if(type==IL_UNSIGNED_INT ||type==IL_INT ||type==IL_FLOAT)MixRGBA((uint32 *)data,(uint32 *)alpha,size);else + if(type==IL_DOUBLE )MixRGBA((uint64 *)data,(uint64 *)alpha,size);else + return(nullptr); + + return data; +} \ No newline at end of file diff --git a/TextureFileCreater.cpp b/TextureFileCreater.cpp index ca6c0ec..59cef72 100644 --- a/TextureFileCreater.cpp +++ b/TextureFileCreater.cpp @@ -104,7 +104,7 @@ bool TextureFileCreater::Write(void *data) if(fmt->format>ColorFormat::COMPRESS) { dos->WriteUint8(0); - dos->WriteUint16(uint(fmt->format)-uint(ColorFormat::COMPRESS)); + dos->WriteUint32(uint(fmt->format)-uint(ColorFormat::COMPRESS)); dos->WriteUint32(total_bytes); } else diff --git a/TextureFileCreaterCompress.cpp b/TextureFileCreaterCompress.cpp index 368e46c..06cde44 100644 --- a/TextureFileCreaterCompress.cpp +++ b/TextureFileCreaterCompress.cpp @@ -1,8 +1,8 @@ #include"TextureFileCreater.h" #include"ILImage.h" #include -#include -#include +#include"CMP_CompressonatorLib/Common.h" +#include"CMP_CompressonatorLib/Compressonator.h" void CMP_RegisterHostPlugins(); CMP_ERROR CMP_API CMP_DestroyComputeLibrary(bool forceclose = false); @@ -25,7 +25,7 @@ public: const int channels=image->channels(); const int type=image->type(); - memset(&MipSetIn, 0, sizeof(MipSet)); + hgl_zero(MipSetIn); CMP_ChannelFormat cf; CMP_TextureDataType tdt; @@ -126,7 +126,7 @@ public: } MipSetIn.m_nMipLevels = 1; - MipSetIn.m_format = CMP_FORMAT_RGBA_8888; + MipSetIn.m_format = fmt; CMP_BYTE* pData = CMips.GetMipLevel(&MipSetIn,0)->m_pbData; @@ -144,12 +144,11 @@ public: void InitOption() { - memset(&kernel_options,0,sizeof(KernelOptions)); + hgl_zero(kernel_options); constexpr CMP_FORMAT fmt_list[]= { - CMP_FORMAT_BC1, //ColorFormat::BC1RGB - CMP_FORMAT_BC1, //ColorFormat::BC1RGBA + CMP_FORMAT_BC1, //ColorFormat::BC1 CMP_FORMAT_BC2, //ColorFormat::BC2 CMP_FORMAT_BC3, //ColorFormat::BC3 CMP_FORMAT_BC4, //ColorFormat::BC4 @@ -161,8 +160,7 @@ public: constexpr char fmt_name_list[][8]= { - "BC1RGB", - "BC1RGBA", + "BC1", "BC2", "BC3", "BC4", @@ -172,14 +170,14 @@ public: "BC7" }; - const int fmt_index=size_t(fmt->format)-size_t(ColorFormat::BC1RGB); + const int fmt_index=size_t(fmt->format)-size_t(ColorFormat::BC1); kernel_options.height =image->height(); kernel_options.width =image->width(); kernel_options.fquality =1.0f; kernel_options.format =fmt_list[fmt_index]; kernel_options.encodeWith =CMP_HPC; - kernel_options.threads =4; + kernel_options.threads =8; kernel_options.getPerfStats =false; kernel_options.getDeviceInfo=false; @@ -199,7 +197,7 @@ public: CMP_RegisterHostPlugins(); CMP_InitializeBCLibrary(); - memset(&MipSetOut,0,sizeof(MipSet)); + hgl_zero(MipSetOut); CMP_ProcessTexture(&MipSetIn,&MipSetOut,kernel_options,&TextureFileCreaterCompress::CMP_Feedback_Proc); diff --git a/pixel_format.cpp b/pixel_format.cpp index 33e0b4a..bcb97ee 100644 --- a/pixel_format.cpp +++ b/pixel_format.cpp @@ -51,8 +51,7 @@ namespace hgl {ColorFormat::COMPRESS, "COMPRESS", 0,{ 0 , 0 , 0 , 0 },{ 0, 0, 0, 0},ColorDataType::NONE}, - {ColorFormat::BC1RGB, "BC1RGB", 0,{ 0 , 0 , 0 , 0 },{ 0, 0, 0, 0},ColorDataType::NONE}, - {ColorFormat::BC1RGBA, "BC1RGBA", 0,{ 0 , 0 , 0 , 0 },{ 0, 0, 0, 0},ColorDataType::NONE}, + {ColorFormat::BC1, "BC1", 0,{ 0 , 0 , 0 , 0 },{ 0, 0, 0, 0},ColorDataType::NONE}, {ColorFormat::BC2, "BC2", 0,{ 0 , 0 , 0 , 0 },{ 0, 0, 0, 0},ColorDataType::NONE}, {ColorFormat::BC3, "BC3", 0,{ 0 , 0 , 0 , 0 },{ 0, 0, 0, 0},ColorDataType::NONE}, {ColorFormat::BC4, "BC4", 0,{ 0 , 0 , 0 , 0 },{ 0, 0, 0, 0},ColorDataType::NONE}, diff --git a/pixel_format.h b/pixel_format.h index e39317b..921a3e7 100644 --- a/pixel_format.h +++ b/pixel_format.h @@ -37,8 +37,7 @@ enum class ColorFormat COMPRESS, - BC1RGB, - BC1RGBA, + BC1, BC2, BC3, BC4,