| 519 | } |
| 520 | |
| 521 | sImage cGraphics_Amiga::DecodeIFF(const std::string& pFilename) { |
| 522 | sImage Result; |
| 523 | auto File = g_Resource->fileGet(pFilename); |
| 524 | auto DataPtr = File->data(); |
| 525 | |
| 526 | if (!DataPtr || readBEDWord(DataPtr) != 'FORM') |
| 527 | return Result; |
| 528 | DataPtr += 4; |
| 529 | size_t FileSize = readBEDWord(DataPtr); |
| 530 | DataPtr += 4; |
| 531 | |
| 532 | if (readBEDWord(DataPtr) != 'ILBM') |
| 533 | return Result; |
| 534 | |
| 535 | DataPtr += 4; |
| 536 | FileSize -= 4; |
| 537 | |
| 538 | uint32 Header = 0; |
| 539 | uint32 Size = 0; |
| 540 | |
| 541 | while (FileSize > 8) { |
| 542 | Header = readBEDWord(DataPtr); |
| 543 | DataPtr += 4; FileSize -= 4; |
| 544 | Size = readBEDWord(DataPtr); |
| 545 | DataPtr += 4; FileSize -= 4; |
| 546 | |
| 547 | switch (Header) { |
| 548 | case 'BMHD': |
| 549 | Result.mDimension.mWidth = readBEWord(DataPtr); DataPtr += 2; |
| 550 | Result.mDimension.mHeight = readBEWord(DataPtr); DataPtr += 2; |
| 551 | DataPtr += 2; DataPtr += 2; // X, Y |
| 552 | Result.mPlanes = *DataPtr++; |
| 553 | DataPtr++; // Mask |
| 554 | DataPtr++; // Compression |
| 555 | DataPtr += 2; ++DataPtr; ++DataPtr; ++DataPtr; |
| 556 | DataPtr += 2; DataPtr += 2; |
| 557 | FileSize -= Size; |
| 558 | break; |
| 559 | |
| 560 | case 'BODY': { |
| 561 | // + 2 is because the amiga does writing after the end of the image |
| 562 | Result.mData->resize(Result.mDimension.WidthByHeight() * (Result.mPlanes + 2)); |
| 563 | |
| 564 | int16 Width = Result.mDimension.mWidth + 0x0F; |
| 565 | Width >>= 4; |
| 566 | Width <<= 1; |
| 567 | |
| 568 | int16 Height = Result.mDimension.mHeight - 1; |
| 569 | |
| 570 | uint8* pDataDest = Result.mData->data(); |
| 571 | |
| 572 | for (int16 Y = Height; Y >= 0; --Y) { |
| 573 | uint8* DataDest = pDataDest; |
| 574 | |
| 575 | for (int8 Plane = 0; Plane < Result.mPlanes; ++Plane) { |
| 576 | |
| 577 | for (int16 X = Width; X > 0;) { |
| 578 | --FileSize; |
nothing calls this directly
no test coverage detected