diff --git a/ILImage.h b/ILImage.h index 4733a87..0ef03e1 100644 --- a/ILImage.h +++ b/ILImage.h @@ -12,6 +12,8 @@ class ILImage uint channel_count; + void Refresh(); + private: bool Convert(ILuint,ILuint); @@ -36,11 +38,13 @@ public: public: ILImage(); + ILImage(ILImage *); ~ILImage(); bool LoadFile(const OSString &); void Bind(); + void Copy(ILImage *); bool Resize(uint,uint); diff --git a/ILImageSupport.cpp b/ILImageSupport.cpp index d945b16..f7cf9b5 100644 --- a/ILImageSupport.cpp +++ b/ILImageSupport.cpp @@ -52,11 +52,72 @@ ILImage::ILImage() ilGenImages(1,&il_index); } +ILImage::ILImage(ILImage *img):ILImage() +{ + ilGenImages(1,&il_index); + Bind(); + ilCopyImage(img->il_index); + Refresh(); +} + ILImage::~ILImage() { ilDeleteImages(1,&il_index); } +void ILImage::Copy(ILImage *img) +{ + ilCopyImage(img->il_index); + Refresh(); +} + +void ILImage::Refresh() +{ + il_width =ilGetInteger(IL_IMAGE_WIDTH); + il_height =ilGetInteger(IL_IMAGE_HEIGHT); + il_depth =ilGetInteger(IL_IMAGE_DEPTH); + il_bit =ilGetInteger(IL_IMAGE_BITS_PER_PIXEL); + il_format =ilGetInteger(IL_IMAGE_FORMAT); + il_type =ilGetInteger(IL_IMAGE_TYPE); + + if(ilGetInteger(IL_IMAGE_ORIGIN)==IL_ORIGIN_LOWER_LEFT) + iluFlipImage(); + + if(il_format==IL_COLOR_INDEX) + { + uint il_pattle=ilGetInteger(IL_PALETTE_TYPE); + + if(il_pattle==IL_PAL_RGB24||il_pattle==IL_PAL_BGR24 + ||il_pattle==IL_PAL_RGB32||il_pattle==IL_PAL_BGR32) + { + channel_count=3; + il_format=IL_RGB; + il_type=IL_UNSIGNED_BYTE; + ilConvertImage(il_format,il_type); + } + else + if(il_pattle==IL_PAL_RGBA32||il_pattle==IL_PAL_BGRA32) + { + channel_count=4; + il_format=IL_RGBA; + il_type=IL_UNSIGNED_BYTE; + ilConvertImage(il_format,il_type); + } + else + { + LOG_ERROR("Don't support the pattle format."); + } + } + + il_bit =ilGetInteger(IL_IMAGE_BITS_PER_PIXEL); + + if(il_format==IL_LUMINANCE||il_format==IL_ALPHA)channel_count=1;else + if(il_format==IL_LUMINANCE_ALPHA) channel_count=2;else + if(il_format==IL_RGB||il_format==IL_BGR) channel_count=3;else + if(il_format==IL_RGBA||il_format==IL_BGRA) channel_count=4;else + channel_count=0; +} + constexpr ILenum format_by_channel[]= { IL_LUMINANCE, @@ -154,15 +215,7 @@ bool ILImage::LoadFile(const OSString &filename) LOG_INFO(OS_TEXT("\nFile: ")+filename); - il_width =ilGetInteger(IL_IMAGE_WIDTH); - il_height =ilGetInteger(IL_IMAGE_HEIGHT); - il_depth =ilGetInteger(IL_IMAGE_DEPTH); - il_bit =ilGetInteger(IL_IMAGE_BITS_PER_PIXEL); - il_format =ilGetInteger(IL_IMAGE_FORMAT); - il_type =ilGetInteger(IL_IMAGE_TYPE); - - if(ilGetInteger(IL_IMAGE_ORIGIN)==IL_ORIGIN_LOWER_LEFT) - iluFlipImage(); + Refresh(); LOG_INFO(OS_TEXT("\t width: ")+OSString::valueOf(il_width)); LOG_INFO(OS_TEXT("\theight: ")+OSString::valueOf(il_height)); @@ -171,41 +224,6 @@ bool ILImage::LoadFile(const OSString &filename) LOG_INFO(OS_TEXT("\tformat: ")+GetILFormatName(il_format)); LOG_INFO(OS_TEXT("\t type: ")+GetILTypeName(il_type)); - if(il_format==IL_COLOR_INDEX) - { - uint il_pattle=ilGetInteger(IL_PALETTE_TYPE); - - if(il_pattle==IL_PAL_RGB24||il_pattle==IL_PAL_BGR24 - ||il_pattle==IL_PAL_RGB32||il_pattle==IL_PAL_BGR32) - { - channel_count=3; - il_format=IL_RGB; - il_type=IL_UNSIGNED_BYTE; - ilConvertImage(il_format,il_type); - return(true); - } - else - if(il_pattle==IL_PAL_RGBA32||il_pattle==IL_PAL_BGRA32) - { - channel_count=4; - il_format=IL_RGBA; - il_type=IL_UNSIGNED_BYTE; - ilConvertImage(il_format,il_type); - return(true); - } - else - { - LOG_ERROR("Don't support the pattle format."); - return(false); - } - } - - if(il_format==IL_LUMINANCE||il_format==IL_ALPHA)channel_count=1;else - if(il_format==IL_LUMINANCE_ALPHA) channel_count=2;else - if(il_format==IL_RGB||il_format==IL_BGR) channel_count=3;else - if(il_format==IL_RGBA||il_format==IL_BGRA) channel_count=4;else - channel_count=0; - return(true); }