| 785 | } |
| 786 | |
| 787 | bool LoadBMPPalette(std::vector<u32>& palette, const u8* data, u32 palette_offset, const BMPInfoHeader& info_header) |
| 788 | { |
| 789 | // 1 bit format doesn't use a palette in the traditional sense |
| 790 | if (info_header.bit_count == 1) |
| 791 | { |
| 792 | palette = {0xFFFFFFFF, 0xFF000000}; |
| 793 | return true; |
| 794 | } |
| 795 | |
| 796 | const u32 num_colors = (info_header.clr_used > 0) ? info_header.clr_used : (1u << info_header.bit_count); |
| 797 | |
| 798 | // Make sure that we don't have an unreasonably large palette |
| 799 | if (num_colors > 256) |
| 800 | { |
| 801 | Console.Error("Invalid palette size: %u", num_colors); |
| 802 | return false; |
| 803 | } |
| 804 | |
| 805 | palette.clear(); |
| 806 | palette.reserve(num_colors); |
| 807 | |
| 808 | const u8* palette_data = data + sizeof(BMPFileHeader) + info_header.size; |
| 809 | |
| 810 | for (u32 i = 0; i < num_colors; i++) |
| 811 | { |
| 812 | const u8* color = palette_data + (i * 4); |
| 813 | const u8 b = color[0]; |
| 814 | const u8 g = color[1]; |
| 815 | const u8 r = color[2]; |
| 816 | palette.push_back(r | (g << 8) | (b << 16) | 0xFF000000u); |
| 817 | } |
| 818 | |
| 819 | return true; |
| 820 | } |
| 821 | |
| 822 | bool LoadUncompressedBMP(u32* pixels, const u8* src, const u8* data, u32 width, u32 height, const BMPInfoHeader& info_header, const std::vector<u32>& palette, bool flip_vertical, u32 red_mask = 0, u32 green_mask = 0, u32 blue_mask = 0, u32 alpha_mask = 0, bool use_alpha = false) |
| 823 | { |
no test coverage detected