supported convert from alpha channel

This commit is contained in:
HuYingzhuo(hugo/hyzboy) 2022-11-08 19:11:55 +08:00
parent 148eca854f
commit a3df5d9471
5 changed files with 39 additions and 8 deletions

View File

@ -5,11 +5,18 @@ project(TexConv)
add_definitions(-DUNICODE -D_UNICODE) add_definitions(-DUNICODE -D_UNICODE)
if(WIN32) if(WIN32)
find_package(DevIL)
include_directories(${IL_INCLUDE_DIR}) include_directories("${CMAKE_CURRENT_SOURCE_DIR}/DevIL Windows SDK/include")
SET(HGL_DEVIL_LIB ${IL_LIBRARIES} ${ILU_LIBRARIES}) IF(HGL_BITS EQUAL 32)
SET(DEVIL_LIBRARY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/DevIL Windows SDK/lib/x86/unicode/Release")
else()
SET(DEVIL_LIBRARY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/DevIL Windows SDK/lib/x64/unicode/Release")
endif()
SET(HGL_DEVIL_LIB ${DEVIL_LIBRARY_PATH}/DevIL.lib
${DEVIL_LIBRARY_PATH}/ILU.lib
${DEVIL_LIBRARY_PATH}/ILUT.lib)
endif(WIN32) endif(WIN32)
include_directories(CMP_CompressonatorLib) include_directories(CMP_CompressonatorLib)
@ -89,7 +96,6 @@ target_link_libraries(ComboTexture PRIVATE CMCore CMPlatform CMUtil ${HGL_DEVIL_
add_executable(DFGen DistanceFieldGenerater.cpp ILImage.h ILImageSupport.cpp) add_executable(DFGen DistanceFieldGenerater.cpp ILImage.h ILImageSupport.cpp)
target_link_libraries(DFGen PRIVATE CMCore CMPlatform CMUtil ${HGL_DEVIL_LIB}) target_link_libraries(DFGen PRIVATE CMCore CMPlatform CMUtil ${HGL_DEVIL_LIB})
macro(texture_tool_project project_name) macro(texture_tool_project project_name)
set_property(TARGET ${project_name} PROPERTY FOLDER "CM/Tools/Texture") set_property(TARGET ${project_name} PROPERTY FOLDER "CM/Tools/Texture")
endmacro() endmacro()

View File

@ -125,29 +125,45 @@ namespace df
int os_main(int argc,os_char **argv) int os_main(int argc,os_char **argv)
{ {
std::cout<<"Distance Field Generater v1.0"<<std::endl<<std::endl; os_out<<OS_TEXT("Distance Field Generater v1.1")<<std::endl;
os_out<<std::endl;
if(argc<2) if(argc<2)
{ {
std::cout<<"example: DFGen 1.png"<<std::endl<<std::endl; os_out<<OS_TEXT("example: DFGen 1.png [alpha]")<<std::endl<<std::endl;
return 0; return 0;
} }
logger::InitLogger(OS_TEXT("DFGen"));
ilInit(); ilInit();
ILImage img; ILImage img;
bool use_alpha=false;
if(!img.LoadFile(argv[1])) if(!img.LoadFile(argv[1]))
{ {
std::cerr<<"open file failed."<<std::endl; os_err<<OS_TEXT("open file <")<<argv[1]<<OS_TEXT("> failed.")<<std::endl;
return -1; return -1;
} }
if(img.channels()==1) if(img.channels()==1)
{ {
} }
else
if(img.channels()==4)
{
if(argc==3)
{
if(argv[2][0]=='a'
||argv[2][0]=='A')
use_alpha=true;
}
}
const uint8 *op=(const uint8 *)img.ToGray(); os_out <<(use_alpha?OS_TEXT("use alpha data."):OS_TEXT("use luminance data."))<<std::endl;
const uint8 *op=(const uint8 *)(use_alpha?img.GetAlpha(IL_UNSIGNED_BYTE):img.ToGray());
AutoDelete<df::Grid> grid1=new df::Grid(img.width(),img.height()); AutoDelete<df::Grid> grid1=new df::Grid(img.width(),img.height());
AutoDelete<df::Grid> grid2=new df::Grid(img.width(),img.height()); AutoDelete<df::Grid> grid2=new df::Grid(img.width(),img.height());

View File

@ -62,6 +62,8 @@ public:
void *GetLum(ILuint type){return GetData(IL_LUMINANCE,type);} void *GetLum(ILuint type){return GetData(IL_LUMINANCE,type);}
void *GetAlpha(ILuint type);
bool ConvertToR(ILuint type){return (il_format==IL_LUMINANCE?Convert(IL_LUMINANCE,type):Convert(IL_ALPHA,type));} bool ConvertToR(ILuint type){return (il_format==IL_LUMINANCE?Convert(IL_LUMINANCE,type):Convert(IL_ALPHA,type));}
bool ConvertToRG(ILuint type){return Convert(IL_LUMINANCE_ALPHA,type);} bool ConvertToRG(ILuint type){return Convert(IL_LUMINANCE_ALPHA,type);}
bool ConvertToRGB(ILuint type){return Convert(IL_RGB,type);} bool ConvertToRGB(ILuint type){return Convert(IL_RGB,type);}

View File

@ -343,6 +343,11 @@ void *ILImage::ToGray(ILuint type)
return ilGetData(); return ilGetData();
} }
void *ILImage::GetAlpha(ILuint type)
{
return ilGetAlpha(type);
}
void *ILImage::GetR(ILuint type) void *ILImage::GetR(ILuint type)
{ {
if(il_format==IL_ALPHA)return ilGetAlpha(type); if(il_format==IL_ALPHA)return ilGetAlpha(type);

View File

@ -60,6 +60,8 @@ int os_main(int argc,os_char **argv)
return 0; return 0;
} }
logger::InitLogger(OS_TEXT("TexConv"));
CmdParse cp(argc,argv); CmdParse cp(argc,argv);
ImageConvertConfig icc; ImageConvertConfig icc;