Texture* DevILImageCodec::load(const RawDataContainer& data, Texture* result) { ilPushAttrib(IL_ORIGIN_SET); ilOriginFunc(IL_ORIGIN_UPPER_LEFT); ilEnable(IL_ORIGIN_SET); ILuint imgName; ilGenImages(1, &imgName); ilBindImage(imgName); if (IL_FALSE != ilLoadL(IL_TYPE_UNKNOWN, static_cast<const void*>(data.getDataPtr()), data.getSize())) { // get details about size of loaded image ILinfo imgInfo; memset(&imgInfo, 0, sizeof(ILinfo)); iluGetImageInfo(&imgInfo); // set dimensions of texture size_t width = imgInfo.Width; size_t height = imgInfo.Height; // allocate temp buffer to receive image data uchar* tmpBuff = new uchar[width * height * 4]; // get image data in required format Texture::PixelFormat cefmt; ILenum ilfmt; switch (imgInfo.Format) { case IL_RGBA: case IL_BGRA: ilfmt = IL_RGBA; cefmt = Texture::PF_RGBA; break; default: ilfmt = IL_RGB; cefmt = Texture::PF_RGB; break; }; ilCopyPixels(0, 0, 0, width, height, 1, ilfmt, IL_UNSIGNED_BYTE, static_cast<void*>(tmpBuff)); // delete DevIL image ilDeleteImages(1, &imgName); ilPopAttrib(); // create cegui texture CEGUI_TRY { result->loadFromMemory(tmpBuff, Size(width, height), cefmt); } CEGUI_CATCH(...) { delete [] tmpBuff; CEGUI_RETHROW; }
void ilState::Pop() { ilPopAttrib(); return; }
Texture* DevILImageCodec::load(const RawDataContainer& data, Texture* result) { ilPushAttrib(IL_ORIGIN_SET); ilOriginFunc(IL_ORIGIN_UPPER_LEFT); ilEnable(IL_ORIGIN_SET); ILuint imgName; ilGenImages(1, &imgName); ilBindImage(imgName); if (ilLoadL(IL_TYPE_UNKNOWN, (ILvoid*)data.getDataPtr(), data.getSize()) != IL_FALSE) { // get details about size of loaded image ILinfo imgInfo; memset(&imgInfo, 0, sizeof(ILinfo)); iluGetImageInfo(&imgInfo); // set dimensions of texture size_t width = imgInfo.Width; size_t height = imgInfo.Height; // allocate temp buffer to receive image data uchar* tmpBuff = new uchar[width * height * 4]; // get image data in required format Texture::PixelFormat cefmt; ILenum ilfmt; switch (imgInfo.Format) { case IL_RGBA: case IL_BGRA: ilfmt = IL_RGBA; cefmt = Texture::PF_RGBA; break; default: ilfmt = IL_RGB; cefmt = Texture::PF_RGB; break; }; ilCopyPixels(0, 0, 0, width, height, 1, ilfmt, IL_UNSIGNED_BYTE, (ILvoid*)tmpBuff); // delete DevIL image ilDeleteImages(1, &imgName); ilPopAttrib(); // create cegui texture try { result->loadFromMemory(tmpBuff, width, height, cefmt); } catch(...) { delete [] tmpBuff; throw; } // free temp buffer delete [] tmpBuff; return result; } // failed to load image properly. else { // delete DevIL image ilDeleteImages(1, &imgName); ilPopAttrib(); return 0; } }