| 473 | |
| 474 | |
| 475 | ILubyte *CompressTo88(ILimage *Image) |
| 476 | { |
| 477 | ILimage *TempImage; |
| 478 | ILubyte *Data; |
| 479 | ILuint i, j; |
| 480 | |
| 481 | if ((Image->Type != IL_UNSIGNED_BYTE && Image->Type != IL_BYTE) || Image->Format == IL_COLOUR_INDEX) { |
| 482 | TempImage = iConvertImage(iCurImage, IL_BGR, IL_UNSIGNED_BYTE); // @TODO: Needs to be BGRA. |
| 483 | if (TempImage == NULL) |
| 484 | return NULL; |
| 485 | } |
| 486 | else { |
| 487 | TempImage = Image; |
| 488 | } |
| 489 | |
| 490 | Data = (ILubyte*)ialloc(iCurImage->Width * iCurImage->Height * 2 * iCurImage->Depth); |
| 491 | if (Data == NULL) { |
| 492 | if (TempImage != Image) |
| 493 | ilCloseImage(TempImage); |
| 494 | return NULL; |
| 495 | } |
| 496 | |
| 497 | //changed 20040623: Use TempImage's format :) |
| 498 | switch (TempImage->Format) |
| 499 | { |
| 500 | case IL_RGB: |
| 501 | for (i = 0, j = 0; i < TempImage->SizeOfData; i += 3, j += 2) { |
| 502 | Data[j ] = TempImage->Data[i+1]; |
| 503 | Data[j+1] = TempImage->Data[i ]; |
| 504 | } |
| 505 | break; |
| 506 | |
| 507 | case IL_RGBA: |
| 508 | for (i = 0, j = 0; i < TempImage->SizeOfData; i += 4, j += 2) { |
| 509 | Data[j ] = TempImage->Data[i+1]; |
| 510 | Data[j+1] = TempImage->Data[i ]; |
| 511 | } |
| 512 | break; |
| 513 | |
| 514 | case IL_BGR: |
| 515 | for (i = 0, j = 0; i < TempImage->SizeOfData; i += 3, j += 2) { |
| 516 | Data[j ] = TempImage->Data[i+1]; |
| 517 | Data[j+1] = TempImage->Data[i+2]; |
| 518 | } |
| 519 | break; |
| 520 | |
| 521 | case IL_BGRA: |
| 522 | for (i = 0, j = 0; i < TempImage->SizeOfData; i += 4, j += 2) { |
| 523 | Data[j ] = TempImage->Data[i+1]; |
| 524 | Data[j+1] = TempImage->Data[i+2]; |
| 525 | } |
| 526 | break; |
| 527 | |
| 528 | case IL_LUMINANCE: |
| 529 | case IL_LUMINANCE_ALPHA: |
| 530 | for (i = 0, j = 0; i < TempImage->SizeOfData; i++, j += 2) { |
| 531 | Data[j ] = Data[j+1] = 0; //??? Luminance is no normal map format... |
| 532 | } |
no test coverage detected