| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <bit> | ||
| 2 | #include <blp/blp.hpp> | ||
| 3 | #include "assets_mpq_importer/blp.hpp" | ||
| 4 | |||
| 5 | namespace assmpq::blp { | ||
| 6 | |||
| 7 | enum class ColorShift : uint8_t { | ||
| 8 | Red = 24U, | ||
| 9 | Green = 16U, | ||
| 10 | Blue = 8U, | ||
| 11 | Alpha = 0U | ||
| 12 | }; | ||
| 13 | |||
| 14 | template<ColorShift SHIFT> | ||
| 15 | 57344 | inline auto get_color(uint32_t rgba)-> float | |
| 16 | { | ||
| 17 | static constexpr uint32_t kByteMask = 0xFF; | ||
| 18 | static constexpr float kColorBase = 255.0F; | ||
| 19 | 57344 | return static_cast<float>((rgba >> static_cast<uint8_t>(SHIFT)) & kByteMask) / kColorBase; | |
| 20 | } | ||
| 21 | |||
| 22 | 22 | auto get_mipmap_buffer_rgba(const wc3lib::blp::Blp::MipMap& mipmap) | |
| 23 | -> std::vector<uint32_t> | ||
| 24 | { | ||
| 25 | 22 | const size_t width = mipmap.width(); | |
| 26 | 22 | const size_t height = mipmap.height(); | |
| 27 |
1/2✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
|
66 | std::vector<uint32_t> colors_buffer(width * height * kRgbaChannels); |
| 28 | |||
| 29 |
2/2✓ Branch 0 taken 286 times.
✓ Branch 1 taken 22 times.
|
308 | for (uint32_t iy = 0; iy < height; ++iy) { |
| 30 |
2/2✓ Branch 0 taken 7168 times.
✓ Branch 1 taken 286 times.
|
7454 | for (uint32_t ix = 0; ix < width; ++ix) { |
| 31 | 7168 | const size_t idx = (iy * width) + ix; | |
| 32 |
2/4✓ Branch 2 taken 7168 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 7168 times.
✗ Branch 7 not taken.
|
7168 | const uint32_t rgba = mipmap.colorAt(ix, iy).rgba(); |
| 33 | 7168 | colors_buffer[idx] = std::byteswap(rgba); | |
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | 22 | return colors_buffer; | |
| 38 | ✗ | } | |
| 39 | |||
| 40 | 2 | auto get_paletted_mipmap_buffer_rgba( | |
| 41 | const wc3lib::blp::Blp::MipMap& mipmap, | ||
| 42 | const wc3lib::blp::Blp::ColorPtr& palette) | ||
| 43 | -> std::vector<uint32_t> | ||
| 44 | { | ||
| 45 | 2 | const size_t width = mipmap.width(); | |
| 46 | 2 | const size_t height = mipmap.height(); | |
| 47 | |||
| 48 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
6 | std::vector<uint32_t> colors_buffer(width * height * kRgbaChannels); |
| 49 | |||
| 50 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 2 times.
|
66 | for (uint32_t iy = 0; iy < height; ++iy) { |
| 51 |
2/2✓ Branch 0 taken 2048 times.
✓ Branch 1 taken 64 times.
|
2112 | for (uint32_t ix = 0; ix < width; ++ix) { |
| 52 | 2048 | const size_t idx = (iy * width) + ix; | |
| 53 |
2/4✓ Branch 2 taken 2048 times.
✗ Branch 3 not taken.
✓ Branch 8 taken 2048 times.
✗ Branch 9 not taken.
|
2048 | const uint32_t rgba = mipmap.colorAt(ix, iy).paletteColor(palette.get()); |
| 54 | 2048 | colors_buffer[idx] = std::byteswap(rgba); | |
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | 2 | return colors_buffer; | |
| 59 | ✗ | } | |
| 60 | |||
| 61 | 21 | auto get_mipmap_buffer_float(const wc3lib::blp::Blp::MipMap& mipmap) | |
| 62 | -> std::vector<float> | ||
| 63 | { | ||
| 64 | 21 | const size_t width = mipmap.width(); | |
| 65 | 21 | const size_t height = mipmap.height(); | |
| 66 |
1/2✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
|
63 | std::vector<float> colors_buffer(width * height * kRgbaChannels); |
| 67 | |||
| 68 | 21 | const size_t offset_r = width * height * 0; | |
| 69 | 21 | const size_t offset_g = width * height * 1; | |
| 70 | 21 | const size_t offset_b = width * height * 2; | |
| 71 | 21 | const size_t offset_a = width * height * 3; | |
| 72 | |||
| 73 |
2/2✓ Branch 0 taken 254 times.
✓ Branch 1 taken 21 times.
|
275 | for (uint32_t iy = 0; iy < height; ++iy) { |
| 74 |
2/2✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 254 times.
|
6398 | for (uint32_t ix = 0; ix < width; ++ix) { |
| 75 | 6144 | const size_t idx = (iy * width) + ix; | |
| 76 |
2/4✓ Branch 2 taken 6144 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 6144 times.
✗ Branch 7 not taken.
|
6144 | const uint32_t rgba = mipmap.colorAt(ix, iy).rgba(); |
| 77 | |||
| 78 | 6144 | colors_buffer[idx + offset_r] = get_color<ColorShift::Red>(rgba); | |
| 79 | 6144 | colors_buffer[idx + offset_g] = get_color<ColorShift::Green>(rgba); | |
| 80 | 6144 | colors_buffer[idx + offset_b] = get_color<ColorShift::Blue>(rgba); | |
| 81 | 6144 | colors_buffer[idx + offset_a] = get_color<ColorShift::Alpha>(rgba); | |
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | 21 | return colors_buffer; | |
| 86 | ✗ | } | |
| 87 | |||
| 88 | 1 | auto get_paletted_mipmap_buffer_float( | |
| 89 | const wc3lib::blp::Blp::MipMap& mipmap, | ||
| 90 | const wc3lib::blp::Blp::ColorPtr& palette) | ||
| 91 | -> std::vector<float> | ||
| 92 | { | ||
| 93 | 1 | const size_t width = mipmap.width(); | |
| 94 | 1 | const size_t height = mipmap.height(); | |
| 95 | |||
| 96 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
3 | std::vector<float> colors_buffer(width * height * kRgbaChannels); |
| 97 | |||
| 98 | 1 | const size_t offset_r = width * height * 0; | |
| 99 | 1 | const size_t offset_g = width * height * 1; | |
| 100 | 1 | const size_t offset_b = width * height * 2; | |
| 101 | 1 | const size_t offset_a = width * height * 3; | |
| 102 | |||
| 103 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 1 times.
|
33 | for (uint32_t iy = 0; iy < height; ++iy) { |
| 104 |
2/2✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 32 times.
|
1056 | for (uint32_t ix = 0; ix < width; ++ix) { |
| 105 | 1024 | const size_t idx = (iy * width) + ix; | |
| 106 |
2/4✓ Branch 2 taken 1024 times.
✗ Branch 3 not taken.
✓ Branch 8 taken 1024 times.
✗ Branch 9 not taken.
|
1024 | const uint32_t rgba = mipmap.colorAt(ix, iy).paletteColor(palette.get()); |
| 107 | |||
| 108 | 1024 | colors_buffer[idx + offset_r] = get_color<ColorShift::Red>(rgba); | |
| 109 | 1024 | colors_buffer[idx + offset_g] = get_color<ColorShift::Green>(rgba); | |
| 110 | 1024 | colors_buffer[idx + offset_b] = get_color<ColorShift::Blue>(rgba); | |
| 111 | 1024 | colors_buffer[idx + offset_a] = get_color<ColorShift::Alpha>(rgba); | |
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | 1 | return colors_buffer; | |
| 116 | ✗ | } | |
| 117 | |||
| 118 | } // namespace assmpq::blp | ||
| 119 |