| 370 | |
| 371 | |
| 372 | ILboolean iLoadDdsInternal() |
| 373 | { |
| 374 | ILuint BlockSize = 0; |
| 375 | ILuint CompFormat; |
| 376 | |
| 377 | CompData = NULL; |
| 378 | Image = NULL; |
| 379 | |
| 380 | if (iCurImage == NULL) { |
| 381 | ilSetError(IL_ILLEGAL_OPERATION); |
| 382 | return IL_FALSE; |
| 383 | } |
| 384 | |
| 385 | if (!iGetDdsHead(&Head)) { |
| 386 | ilSetError(IL_INVALID_FILE_HEADER); |
| 387 | return IL_FALSE; |
| 388 | } |
| 389 | if (!iCheckDds(&Head)) { |
| 390 | ilSetError(IL_INVALID_FILE_HEADER); |
| 391 | return IL_FALSE; |
| 392 | } |
| 393 | |
| 394 | BlockSize = DecodePixelFormat(&CompFormat); |
| 395 | if (CompFormat == PF_UNKNOWN) { |
| 396 | ilSetError(IL_INVALID_FILE_HEADER); |
| 397 | return IL_FALSE; |
| 398 | } |
| 399 | Check16BitComponents(&Head); |
| 400 | |
| 401 | // Microsoft bug, they're not following their own documentation. |
| 402 | if (!(Head.Flags1 & (DDS_LINEARSIZE | DDS_PITCH)) |
| 403 | || Head.LinearSize == 0) { |
| 404 | Head.Flags1 |= DDS_LINEARSIZE; |
| 405 | Head.LinearSize = BlockSize; |
| 406 | } |
| 407 | |
| 408 | Image = iCurImage; |
| 409 | if (Head.ddsCaps1 & DDS_COMPLEX) { |
| 410 | if (Head.ddsCaps2 & DDS_CUBEMAP) { |
| 411 | if (!iLoadDdsCubemapInternal(CompFormat)) |
| 412 | return IL_FALSE; |
| 413 | return IL_TRUE; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | Width = Head.Width; |
| 418 | Height = Head.Height; |
| 419 | Depth = Head.Depth; |
| 420 | AdjustVolumeTexture(&Head, CompFormat); |
| 421 | |
| 422 | if (!ReadData()) |
| 423 | return IL_FALSE; |
| 424 | if (!AllocImage(CompFormat)) { |
| 425 | if (CompData) { |
| 426 | ifree(CompData); |
| 427 | CompData = NULL; |
| 428 | } |
| 429 | return IL_FALSE; |
no test coverage detected