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 *);
|
|
|
|
|
2020-08-06 18:18:34 +08:00
|
|
|
TextureFileCreater *CreateTextureFileCreaterCompress(const PixelFormat *,ILImage *);
|
|
|
|
|
|
|
|
using CTFC_FUNC=TextureFileCreater *(*)(const PixelFormat *,ILImage *);
|
|
|
|
|
|
|
|
static CTFC_FUNC CreateTFC[4]={CreateTextureFileCreaterR,CreateTextureFileCreaterRG,CreateTextureFileCreaterRGB,CreateTextureFileCreaterRGBA};
|
|
|
|
|
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
|
|
|
|
2020-08-06 18:18:34 +08:00
|
|
|
if(channels<0||channels>4)
|
2019-12-02 22:10:49 +08:00
|
|
|
{
|
|
|
|
LOG_ERROR(OS_TEXT("image format don't support "));
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
2020-08-06 18:18:34 +08:00
|
|
|
TextureFileCreater *tex_file_creater;
|
|
|
|
const PixelFormat *fmt=pf[channels-1];
|
|
|
|
|
|
|
|
if(fmt->format<ColorFormat::COMPRESS)
|
|
|
|
tex_file_creater=CreateTFC[channels-1](fmt,&image);
|
|
|
|
else
|
|
|
|
tex_file_creater=CreateTextureFileCreaterCompress(fmt,&image);
|
|
|
|
|
2019-12-02 22:10:49 +08:00
|
|
|
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
|
|
|
|