| 626 | |
| 627 | |
| 628 | ILboolean PsdGetData(PSDHEAD *Head, void *Buffer, ILboolean Compressed) |
| 629 | { |
| 630 | ILuint c, x, y, i, Size, ReadResult, NumChan; |
| 631 | ILubyte *Channel = NULL; |
| 632 | ILushort *ShortPtr; |
| 633 | ILuint *ChanLen = NULL; |
| 634 | |
| 635 | // Added 01-07-2009: This is needed to correctly load greyscale and |
| 636 | // paletted images. |
| 637 | switch (Head->Mode) |
| 638 | { |
| 639 | case 1: |
| 640 | case 2: |
| 641 | NumChan = 1; |
| 642 | break; |
| 643 | default: |
| 644 | NumChan = 3; |
| 645 | } |
| 646 | |
| 647 | Channel = (ILubyte*)ialloc(Head->Width * Head->Height * iCurImage->Bpc); |
| 648 | if (Channel == NULL) { |
| 649 | return IL_FALSE; |
| 650 | } |
| 651 | ShortPtr = (ILushort*)Channel; |
| 652 | |
| 653 | // @TODO: Add support for this in, though I have yet to run across a .psd |
| 654 | // file that uses this. |
| 655 | if (Compressed && iCurImage->Type == IL_UNSIGNED_SHORT) { |
| 656 | ilSetError(IL_FORMAT_NOT_SUPPORTED); |
| 657 | return IL_FALSE; |
| 658 | } |
| 659 | |
| 660 | if (!Compressed) { |
| 661 | if (iCurImage->Bpc == 1) { |
| 662 | for (c = 0; c < NumChan; c++) { |
| 663 | i = 0; |
| 664 | if (iread(Channel, Head->Width * Head->Height, 1) != 1) { |
| 665 | ifree(Channel); |
| 666 | return IL_FALSE; |
| 667 | } |
| 668 | for (y = 0; y < Head->Height * iCurImage->Bps; y += iCurImage->Bps) { |
| 669 | for (x = 0; x < iCurImage->Bps; x += iCurImage->Bpp, i++) { |
| 670 | iCurImage->Data[y + x + c] = Channel[i]; |
| 671 | } |
| 672 | } |
| 673 | } |
| 674 | // Accumulate any remaining channels into a single alpha channel |
| 675 | //@TODO: This needs to be changed for greyscale images. |
| 676 | for (; c < Head->Channels; c++) { |
| 677 | i = 0; |
| 678 | if (iread(Channel, Head->Width * Head->Height, 1) != 1) { |
| 679 | ifree(Channel); |
| 680 | return IL_FALSE; |
| 681 | } |
| 682 | for (y = 0; y < Head->Height * iCurImage->Bps; y += iCurImage->Bps) { |
| 683 | for (x = 0; x < iCurImage->Bps; x += iCurImage->Bpp, i++) { |
| 684 | float curVal = ubyte_to_float(iCurImage->Data[y + x + 3]); |
| 685 | float newVal = ubyte_to_float(Channel[i]); |
no test coverage detected