diff --git a/changes.txt b/changes.txt index 85616d0a..e9aeb8a5 100644 --- a/changes.txt +++ b/changes.txt @@ -1,6 +1,7 @@ -------------------------- Changes in 1.9 (not yet released) +- CImageLoaderBMP now supports loading 1-bit images with palette data - Hardware meshbuffers are now deleted when they hold the last reference to a meshbuffer - Variable order inside SMaterial and SMaterialLayer changed for better packing - line3d::getClosestPoint can now chose between using line or line segment diff --git a/source/Irrlicht/CColorConverter.cpp b/source/Irrlicht/CColorConverter.cpp index 93dd19a1..b464cc72 100644 --- a/source/Irrlicht/CColorConverter.cpp +++ b/source/Irrlicht/CColorConverter.cpp @@ -12,7 +12,7 @@ namespace video { //! converts a monochrome bitmap to A1R5G5B5 data -void CColorConverter::convert1BitTo16Bit(const u8* in, s16* out, u32 width, u32 height, u32 linepad, bool flip) +void CColorConverter::convert1BitTo16Bit(const u8* in, s16* out, u32 width, u32 height, u32 linepad, bool flip, s16 col0, s16 col1) { if (!in || !out) return; @@ -28,7 +28,7 @@ void CColorConverter::convert1BitTo16Bit(const u8* in, s16* out, u32 width, u32 for (u32 x=0; x>shift & 0x01 ? (s16)0xffff : (s16)0x8000; + out[x] = *in>>shift & 0x01 ? col1 : col0; if ((--shift)<0) // 8 pixel done { diff --git a/source/Irrlicht/CColorConverter.h b/source/Irrlicht/CColorConverter.h index 37e189eb..df26e16e 100644 --- a/source/Irrlicht/CColorConverter.h +++ b/source/Irrlicht/CColorConverter.h @@ -18,7 +18,7 @@ class CColorConverter public: //! converts a monochrome bitmap to A1R5G5B5 - static void convert1BitTo16Bit(const u8* in, s16* out, u32 width, u32 height, u32 linepad=0, bool flip=false); + static void convert1BitTo16Bit(const u8* in, s16* out, u32 width, u32 height, u32 linepad=0, bool flip=false, s16 col0=(s16)0x8000, s16 col1=(s16)0xffff); //! converts a 4 bit palettized image to A1R5G5B5 static void convert4BitTo16Bit(const u8* in, s16* out, u32 width, u32 height, const s32* palette, u32 linepad=0, bool flip=false); @@ -32,7 +32,7 @@ public: //! converts a 8 bit palettized or non palettized image (A8) into A8R8G8B8 static void convert8BitTo32Bit(const u8* in, u8* out, u32 width, u32 height, const u8* palette, u32 linepad = 0, bool flip=false); - //! converts R8G8B8 16 bit data to A1R5G5B5 data + //! converts 16bit data to 16bit data (can flip and do endian conversion) static void convert16BitTo16Bit(const s16* in, s16* out, u32 width, u32 height, u32 linepad=0, bool flip=false); //! copies R8G8B8 24 bit data to 24 data, and flips and diff --git a/source/Irrlicht/CImageLoaderBMP.cpp b/source/Irrlicht/CImageLoaderBMP.cpp index 8fdb309e..4fd94f3c 100644 --- a/source/Irrlicht/CImageLoaderBMP.cpp +++ b/source/Irrlicht/CImageLoaderBMP.cpp @@ -414,7 +414,20 @@ IImage* CImageLoaderBMP::loadImage(io::IReadFile* file) const case 1: image = new CImage(ECF_A1R5G5B5, dim); if (image) - CColorConverter::convert1BitTo16Bit(bmpData, (s16*)image->getData(), header.Width, header.Height, pitch, true); + { + s16 colors[2] = {(s16)0x8000, (s16)0xffff }; // off: only alpha set, on: all white + if ( paletteSize == 1 ) + { + u8 in = 0; + CColorConverter::convert8BitTo16Bit(&in, colors, 1, 1, paletteData); + } + else if ( paletteSize >= 2 ) + { + u8 in[2] = { 0, 1 }; + CColorConverter::convert8BitTo16Bit(in, colors, 2, 1, paletteData); + } + CColorConverter::convert1BitTo16Bit(bmpData, (s16*)image->getData(), header.Width, header.Height, pitch, true, colors[0], colors[1]); + } break; case 4: image = new CImage(ECF_A1R5G5B5, dim);