2019-12-02 22:10:49 +08:00
|
|
|
#include"TextureFileCreater.h"
|
|
|
|
#include"ILImage.h"
|
|
|
|
#include<hgl/log/LogInfo.h>
|
2023-02-07 23:03:54 +08:00
|
|
|
#include<hgl/color/ColorFormat.h>
|
2019-12-02 22:10:49 +08:00
|
|
|
|
|
|
|
class TextureFileCreaterRGB:public TextureFileCreater
|
|
|
|
{
|
2020-10-25 21:22:18 +08:00
|
|
|
ILuint type;
|
|
|
|
|
2019-12-02 22:10:49 +08:00
|
|
|
public:
|
|
|
|
|
|
|
|
using TextureFileCreater::TextureFileCreater;
|
|
|
|
|
2020-10-25 21:22:18 +08:00
|
|
|
public:
|
|
|
|
|
2021-12-07 18:18:22 +08:00
|
|
|
bool InitFormat(ILImage* img) override
|
2020-10-25 21:22:18 +08:00
|
|
|
{
|
2021-12-07 18:18:22 +08:00
|
|
|
image = img;
|
|
|
|
|
2020-10-25 21:22:18 +08:00
|
|
|
if(pixel_format->format==ColorFormat::RGB32U
|
|
|
|
||pixel_format->format==ColorFormat::RGB32I
|
|
|
|
||pixel_format->format==ColorFormat::RGB32F)
|
|
|
|
{
|
|
|
|
if(!ToILType(type,pixel_format->bits[0],pixel_format->type))
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
else if(pixel_format->format==ColorFormat::RGB565)
|
|
|
|
{
|
|
|
|
type=IL_UNSIGNED_BYTE;
|
|
|
|
}
|
|
|
|
else if(pixel_format->format==ColorFormat::B10GR11UF)
|
|
|
|
{
|
|
|
|
type=IL_HALF;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG_ERROR(OS_TEXT("Don't support this RGB format"));
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return image->ConvertToRGB(type);
|
|
|
|
}
|
|
|
|
|
2019-12-02 22:10:49 +08:00
|
|
|
public:
|
|
|
|
|
2020-10-25 21:22:18 +08:00
|
|
|
uint32 Write() override
|
2019-12-02 22:10:49 +08:00
|
|
|
{
|
2020-10-25 21:22:18 +08:00
|
|
|
const uint total_bytes=(pixel_format->total_bits*image->pixel_total())>>3;
|
|
|
|
|
|
|
|
std::cout<<"Convert Image To: "<<image->width()<<"x"<<image->height()<<" "<<total_bytes<<" bytes."<<std::endl;
|
2019-12-02 22:10:49 +08:00
|
|
|
|
2020-10-25 21:22:18 +08:00
|
|
|
if(pixel_format->format==ColorFormat::RGB32U
|
|
|
|
||pixel_format->format==ColorFormat::RGB32I
|
|
|
|
||pixel_format->format==ColorFormat::RGB32F)
|
|
|
|
{
|
2019-12-02 22:10:49 +08:00
|
|
|
void *origin_rgb=image->GetRGB(type);
|
|
|
|
|
2020-10-25 21:22:18 +08:00
|
|
|
return TextureFileCreater::Write(origin_rgb,total_bytes);
|
2019-12-02 22:10:49 +08:00
|
|
|
}
|
2020-10-25 21:22:18 +08:00
|
|
|
else if(pixel_format->format==ColorFormat::RGB565)
|
2019-12-02 22:10:49 +08:00
|
|
|
{
|
|
|
|
void *origin_rgb=image->GetRGB(IL_UNSIGNED_BYTE);
|
|
|
|
|
2020-10-25 21:22:18 +08:00
|
|
|
AutoDeleteArray<uint16> rgb565(image->pixel_total());
|
2019-12-02 22:10:49 +08:00
|
|
|
|
|
|
|
RGB8toRGB565(rgb565,(uint8 *)origin_rgb,image->pixel_total());
|
|
|
|
|
2020-10-25 21:22:18 +08:00
|
|
|
return TextureFileCreater::Write(rgb565,total_bytes);
|
2019-12-02 22:10:49 +08:00
|
|
|
}
|
2020-10-25 21:22:18 +08:00
|
|
|
else if(pixel_format->format==ColorFormat::B10GR11UF)
|
2019-12-04 20:47:58 +08:00
|
|
|
{
|
|
|
|
void *origin_rgb=image->GetRGB(IL_HALF);
|
|
|
|
|
2020-10-25 21:22:18 +08:00
|
|
|
AutoDeleteArray<uint32> b10gr11(image->pixel_total());
|
2019-12-04 20:47:58 +08:00
|
|
|
|
|
|
|
RGB16FtoB10GR11UF(b10gr11,(uint16 *)origin_rgb,image->pixel_total());
|
|
|
|
|
2020-10-25 21:22:18 +08:00
|
|
|
return TextureFileCreater::Write(b10gr11,total_bytes);
|
2019-12-04 20:47:58 +08:00
|
|
|
}
|
2019-12-02 22:10:49 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG_ERROR(OS_TEXT("Don't support this RGB format"));
|
2020-10-25 21:22:18 +08:00
|
|
|
return(0);
|
2019-12-02 22:10:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};//class TextureFileCreaterRGB:public TextureFileCreater
|
|
|
|
|
2021-12-07 18:18:22 +08:00
|
|
|
TextureFileCreater *CreateTextureFileCreaterRGB(const PixelFormat *pf)
|
2019-12-02 22:10:49 +08:00
|
|
|
{
|
2021-12-07 18:18:22 +08:00
|
|
|
return(new TextureFileCreaterRGB(pf));
|
2019-12-02 22:10:49 +08:00
|
|
|
}
|