Function to intialize the mipmaps and determine the number of mipmaps.
| 255 | |
| 256 | // Function to intialize the mipmaps and determine the number of mipmaps. |
| 257 | ILboolean IwiInitMipmaps(ILimage *BaseImage, ILuint *NumMips) |
| 258 | { |
| 259 | ILimage *Image; |
| 260 | ILuint Width, Height, Mipmap; |
| 261 | |
| 262 | Image = BaseImage; |
| 263 | Width = BaseImage->Width; Height = BaseImage->Height; |
| 264 | Image->Origin = IL_ORIGIN_UPPER_LEFT; |
| 265 | |
| 266 | for (Mipmap = 0; Width != 1 && Height != 1; Mipmap++) { |
| 267 | // 1 is the smallest dimension possible. |
| 268 | Width = (Width >> 1) == 0 ? 1 : (Width >> 1); |
| 269 | Height = (Height >> 1) == 0 ? 1 : (Height >> 1); |
| 270 | |
| 271 | Image->Mipmaps = ilNewImageFull(Width, Height, 1, BaseImage->Bpp, BaseImage->Format, BaseImage->Type, NULL); |
| 272 | if (Image->Mipmaps == NULL) |
| 273 | return IL_FALSE; |
| 274 | Image = Image->Mipmaps; |
| 275 | |
| 276 | // ilNewImage does not set these. |
| 277 | Image->Format = BaseImage->Format; |
| 278 | Image->Type = BaseImage->Type; |
| 279 | // The origin is in the upper left. |
| 280 | Image->Origin = IL_ORIGIN_UPPER_LEFT; |
| 281 | } |
| 282 | |
| 283 | *NumMips = Mipmap; |
| 284 | return IL_TRUE; |
| 285 | } |
| 286 | |
| 287 | |
| 288 | ILboolean IwiReadImage(ILimage *BaseImage, IWIHEAD *Header, ILuint NumMips) |