2019-12-02 22:10:49 +08:00
|
|
|
#pragma once
|
|
|
|
#include<IL/il.h>
|
2020-09-03 21:14:20 +08:00
|
|
|
#include<hgl/type/String.h>
|
2021-12-06 10:47:34 +08:00
|
|
|
#include"Image2D.h"
|
2019-12-02 22:10:49 +08:00
|
|
|
|
|
|
|
using namespace hgl;
|
|
|
|
|
|
|
|
class ILImage
|
|
|
|
{
|
|
|
|
ILuint il_index;
|
2019-12-30 16:48:15 +08:00
|
|
|
ILuint il_width,il_height,il_depth;
|
2019-12-02 22:10:49 +08:00
|
|
|
ILuint il_bit,il_format,il_type;
|
|
|
|
|
|
|
|
uint channel_count;
|
|
|
|
|
2021-01-18 15:11:19 +08:00
|
|
|
void Refresh();
|
|
|
|
|
2019-12-02 22:10:49 +08:00
|
|
|
private:
|
|
|
|
|
|
|
|
bool Convert(ILuint,ILuint);
|
|
|
|
|
|
|
|
void *GetData(ILuint,ILuint);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2020-10-25 21:22:18 +08:00
|
|
|
const ILuint width ()const{return ilGetInteger(IL_IMAGE_WIDTH);}
|
|
|
|
const ILuint height ()const{return ilGetInteger(IL_IMAGE_HEIGHT);}
|
|
|
|
const ILuint depth ()const{return ilGetInteger(IL_IMAGE_DEPTH);}
|
2019-12-30 16:48:15 +08:00
|
|
|
const ILuint bit ()const{return il_bit;}
|
|
|
|
const ILuint format ()const{return il_format;}
|
|
|
|
const ILuint type ()const{return il_type;}
|
2019-12-02 22:10:49 +08:00
|
|
|
|
2020-10-25 21:22:18 +08:00
|
|
|
const ILuint pixel_total()const{return width()*height()*depth();}
|
2019-12-02 22:10:49 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
const uint channels()const{return channel_count;} //通道数量
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
ILImage();
|
2021-01-18 15:11:19 +08:00
|
|
|
ILImage(ILImage *);
|
2019-12-02 22:10:49 +08:00
|
|
|
~ILImage();
|
|
|
|
|
|
|
|
bool LoadFile(const OSString &);
|
|
|
|
|
|
|
|
void Bind();
|
2021-01-18 15:11:19 +08:00
|
|
|
void Copy(ILImage *);
|
2019-12-30 16:48:15 +08:00
|
|
|
|
2021-12-06 10:47:34 +08:00
|
|
|
// Image2D *CreateImage2D();
|
2019-12-31 13:44:09 +08:00
|
|
|
|
2021-12-06 10:47:34 +08:00
|
|
|
bool Resize(uint,uint);
|
2020-10-25 21:22:18 +08:00
|
|
|
|
2020-01-08 15:54:58 +08:00
|
|
|
void *ToRGB(ILuint type=IL_UNSIGNED_BYTE);
|
|
|
|
void *ToGray(ILuint type=IL_UNSIGNED_BYTE);
|
2019-12-02 22:10:49 +08:00
|
|
|
|
|
|
|
void *GetR(ILuint type);
|
|
|
|
|
|
|
|
void *GetRG(ILuint type){return GetData(IL_LUMINANCE_ALPHA,type);}
|
|
|
|
void *GetRGB(ILuint type){return GetData(IL_RGB,type);}
|
2020-08-08 22:20:46 +08:00
|
|
|
void *GetRGBA(ILuint type);
|
2019-12-31 13:44:09 +08:00
|
|
|
|
|
|
|
void *GetLum(ILuint type){return GetData(IL_LUMINANCE,type);}
|
2020-10-25 21:22:18 +08:00
|
|
|
|
2022-11-08 19:11:55 +08:00
|
|
|
void *GetAlpha(ILuint type);
|
|
|
|
|
2020-10-25 21:22:18 +08:00
|
|
|
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 ConvertToRGB(ILuint type){return Convert(IL_RGB,type);}
|
|
|
|
bool ConvertToRGBA(ILuint type){return Convert(IL_RGBA,type);}
|
|
|
|
bool ConvertToLum(ILuint type){return Convert(IL_LUMINANCE,type);}
|
2019-12-02 22:10:49 +08:00
|
|
|
};//class ILImage
|
2020-01-02 21:40:06 +08:00
|
|
|
|
2020-01-08 15:54:58 +08:00
|
|
|
bool SaveImageToFile(const OSString &filename,ILuint w,ILuint h,const float scale,ILuint c,ILuint t,void *data);
|
2020-06-19 22:08:55 +08:00
|
|
|
|
|
|
|
inline bool SaveImageToFile(const OSString &filename,ILuint w,ILuint h,ILuint c,ILuint t,void *data)
|
|
|
|
{
|
|
|
|
return SaveImageToFile(filename,w,h,1.0,c,t,data);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool SaveImageToFile(const OSString &filename,ILuint w,ILuint h,ILuint c,void *data)
|
|
|
|
{
|
|
|
|
return SaveImageToFile(filename,w,h,1.0,c,IL_UNSIGNED_BYTE,data);
|
|
|
|
}
|