From 4fbbba2c644a29ee1b8f88c08d7b1597fafd69bc Mon Sep 17 00:00:00 2001 From: hyzboy Date: Mon, 6 Dec 2021 15:28:01 +0800 Subject: [PATCH] finished CubemapConvert codes, but not run test. --- ConvertImage.cpp | 2 +- CubemapConvert.cpp | 122 +++++++++++++++++++++------------ ILImageSupport.cpp | 5 +- TextureFileCreaterCompress.cpp | 2 +- 4 files changed, 85 insertions(+), 46 deletions(-) diff --git a/ConvertImage.cpp b/ConvertImage.cpp index bfbcba6..3fb4c83 100644 --- a/ConvertImage.cpp +++ b/ConvertImage.cpp @@ -19,7 +19,7 @@ bool ConvertImage(const OSString &filename,const ImageConvertConfig *cfg) const uint channels=image.channels(); - if(channels<0||channels>4) + if(channels<=0||channels>4) { LOG_ERROR(OS_TEXT("image format don't support ")); return(false); diff --git a/CubemapConvert.cpp b/CubemapConvert.cpp index e263018..bf1e0f7 100644 --- a/CubemapConvert.cpp +++ b/CubemapConvert.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include"ILImage.h" #include"TextureFileCreater.h" #include"ImageConvertConfig.h" @@ -11,76 +12,98 @@ using namespace hgl; using namespace hgl::filesystem; using namespace hgl::util; -bool ConvertImage(const OSString &filename,const ImageConvertConfig *cfg) +bool ConvertCubemap(const OSString &filename,const OSStringList &file_list,const ImageConvertConfig *cfg) { - ILImage image; + ILImage image[6]; - if(!image.LoadFile(filename)) - return(false); + uint width,height,channels,bits; + + for(int i=0;i<6;i++) + { + if(!image[i].LoadFile(file_list[i])) + return(false); + + if(i==0) + { + width=image[0].width(); + height=image[0].height(); + channels=image[0].channels(); + bits=image[0].bit(); + } + else + { + if(width!=image[i].width() + ||height!=image[i].height() + ||channels!=image[i].channels() + ||bits!=image[i].bit()) + { + LOG_ERROR(OS_TEXT("image formats can't batch")); + return(false); + } + } + } int miplevel=1; if(cfg->gen_mipmaps) - miplevel=hgl::GetMipLevel(image.width(),image.height()); + miplevel=hgl::GetMipLevel(width,height); - const uint channels=image.channels(); - - if(channels<0||channels>4) + if(channels<=0||channels>4) { LOG_ERROR(OS_TEXT("image format don't support ")); return(false); } - TextureFileCreater *tex_file_creater; const PixelFormat *fmt=cfg->pixel_fmt[channels-1]; - Image2D *origin_img=nullptr; - - if(fmt->formatWriteFileHeader(filename,TextureFileType::TexCubemap,miplevel)) - { - tex_file_creater->Delete(); - LOG_ERROR(OS_TEXT("Write file header failed.")); - return(false); - } - - tex_file_creater->InitFormat(); - - uint width=image.width(); - uint height=image.height(); uint total=0; uint bytes=0; - for(int i=0;iWrite(); + TextureFileCreater *tex_file_creater; - if(bytes<=0) + if(fmt->formatWriteFileHeader(filename,TextureFileType::TexCubemap,miplevel)) { tex_file_creater->Delete(); + LOG_ERROR(OS_TEXT("Write file header failed.")); return(false); } - total+=bytes; + tex_file_creater->InitFormat(); - if(i1)width>>=1; - if(height>1)height>>=1; + bytes=tex_file_creater->Write(); - image.Resize(width,height); + if(bytes<=0) + { + tex_file_creater->Delete(); + return(false); + } + + total+=bytes; + + if(i1)width>>=1; + if(height>1)height>>=1; + + image[face].Resize(width,height); + } } + + tex_file_creater->Close(); + + delete tex_file_creater; } LOG_INFO(OS_TEXT("pixel total length: ")+OSString::valueOf(total)+OS_TEXT(" bytes.")); - - tex_file_creater->Close(); - - delete tex_file_creater; return(true); } @@ -92,10 +115,10 @@ int os_main(int argc,os_char **argv) { std::cout<<"Cubemap to Texture Convert tools 1.2"<\n\n"; + "\tCubemapConv [/R:][/RG:][/RGB:][/RGBA:] [/mip] ,,,,,\n\n"; PrintFormatList(); return 0; @@ -115,9 +138,22 @@ int os_main(int argc,os_char **argv) CMP_RegisterHostPlugins(); CMP_InitializeBCLibrary(); - if(filesystem::FileCanRead(argv[argc-1])) + OSString out_filename=argv[argc-8]; + OSStringList file_list; + + for(int i=argc-7;iheight(); kernel_options.width =image->width(); kernel_options.fquality =1.0f;