0x0047221F
| 9 | |
| 10 | // 0x0047221F |
| 11 | ImageTableResult loadImageTable(std::span<const std::byte> data) |
| 12 | { |
| 13 | if (data.size() < sizeof(Gfx::G1Header)) |
| 14 | { |
| 15 | throw Exception::OutOfRange(); |
| 16 | } |
| 17 | auto remainingData = data; |
| 18 | const auto g1Header = *reinterpret_cast<const Gfx::G1Header*>(remainingData.data()); |
| 19 | remainingData = remainingData.subspan(sizeof(Gfx::G1Header)); |
| 20 | |
| 21 | const ImageTableResult res = { _totalNumImages, static_cast<uint32_t>(sizeof(Gfx::G1Header) + g1Header.numEntries * sizeof(Gfx::G1Element32) + g1Header.totalSize) }; |
| 22 | |
| 23 | if (remainingData.size() < sizeof(Gfx::G1Element32) * g1Header.numEntries) |
| 24 | { |
| 25 | throw Exception::OutOfRange(); |
| 26 | } |
| 27 | const auto* g32Ptr = reinterpret_cast<const Gfx::G1Element32*>(remainingData.data()); |
| 28 | remainingData = remainingData.subspan(sizeof(Gfx::G1Element32) * g1Header.numEntries); |
| 29 | // Urgh messy... |
| 30 | auto* const imageDataBegin = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(remainingData.data())); |
| 31 | |
| 32 | for (uint32_t i = 0; i < g1Header.numEntries; ++i, ++g32Ptr) |
| 33 | { |
| 34 | auto g1Element = Gfx::G1Element(*g32Ptr); |
| 35 | g1Element.offset = imageDataBegin + g32Ptr->offset; |
| 36 | if (g1Element.hasFlags(Gfx::G1ElementFlags::duplicatePrevious)) |
| 37 | { |
| 38 | g1Element = *Gfx::getG1Element(_totalNumImages + i - 1); |
| 39 | g1Element.xOffset += g32Ptr->xOffset; |
| 40 | g1Element.yOffset += g32Ptr->yOffset; |
| 41 | } |
| 42 | *Gfx::getG1Element(_totalNumImages + i) = g1Element; |
| 43 | } |
| 44 | _totalNumImages += g1Header.numEntries; |
| 45 | return res; |
| 46 | } |
| 47 | |
| 48 | uint32_t getTotalNumImages() |
| 49 | { |
no test coverage detected