TexConv/ConvertImage.cpp

51 lines
1.4 KiB
C++
Raw Normal View History

2019-12-03 11:49:02 +08:00
#include<hgl/log/LogInfo.h>
2019-12-02 22:10:49 +08:00
#include"ILImage.h"
#include"TextureFileCreater.h"
TextureFileCreater *CreateTextureFileCreaterR(const PixelFormat *,ILImage *);
TextureFileCreater *CreateTextureFileCreaterRG(const PixelFormat *,ILImage *);
TextureFileCreater *CreateTextureFileCreaterRGB(const PixelFormat *,ILImage *);
TextureFileCreater *CreateTextureFileCreaterRGBA(const PixelFormat *,ILImage *);
2019-12-03 11:49:02 +08:00
bool ConvertImage(const OSString &filename,const PixelFormat **pf)
2019-12-02 22:10:49 +08:00
{
2019-12-03 11:49:02 +08:00
ILImage image;
2019-12-02 22:10:49 +08:00
2019-12-03 11:49:02 +08:00
if(!image.LoadFile(filename))
2019-12-02 22:10:49 +08:00
return(false);
2019-12-03 11:49:02 +08:00
image.Bind();
2019-12-02 22:10:49 +08:00
2019-12-03 11:49:02 +08:00
const uint channels=image.channels();
2019-12-02 22:10:49 +08:00
TextureFileCreater *tex_file_creater;
2019-12-03 11:49:02 +08:00
if(channels==1)tex_file_creater=CreateTextureFileCreaterR(pf[0],&image);else
if(channels==2)tex_file_creater=CreateTextureFileCreaterRG(pf[1],&image);else
if(channels==3)tex_file_creater=CreateTextureFileCreaterRGB(pf[2],&image);else
if(channels==4)tex_file_creater=CreateTextureFileCreaterRGBA(pf[3],&image);else
2019-12-02 22:10:49 +08:00
{
LOG_ERROR(OS_TEXT("image format don't support "));
return(false);
}
if(!tex_file_creater->WriteFileHeader(filename))
{
tex_file_creater->Delete();
LOG_ERROR(OS_TEXT("Write file header failed."));
return(false);
}
if(!tex_file_creater->Write())
{
tex_file_creater->Delete();
return(false);
}
tex_file_creater->Close();
delete tex_file_creater;
return(true);
}
2019-12-03 11:49:02 +08:00