diff options
author | Hop311 <Hop3114@gmail.com> | 2023-12-25 13:14:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-25 13:14:37 +0100 |
commit | dcef842d5e070854913f9e61e4a1f485870ae703 (patch) | |
tree | 5b701a37faee6faa670ae186a97c218e1ad3455c /src/openvic-simulation | |
parent | bf4e7368600bb425b6612231fbb84de34ec99a27 (diff) | |
parent | 72b92d5a9f472b714e098756bf9ce5957843d198 (diff) |
Merge pull request #104 from OpenVicProject/fix/bmp
Add `BMP::palette_colour_t` as uint32_t
Diffstat (limited to 'src/openvic-simulation')
-rw-r--r-- | src/openvic-simulation/utility/BMP.cpp | 4 | ||||
-rw-r--r-- | src/openvic-simulation/utility/BMP.hpp | 10 |
2 files changed, 9 insertions, 5 deletions
diff --git a/src/openvic-simulation/utility/BMP.cpp b/src/openvic-simulation/utility/BMP.cpp index 83d26c4..4c220da 100644 --- a/src/openvic-simulation/utility/BMP.cpp +++ b/src/openvic-simulation/utility/BMP.cpp @@ -110,7 +110,7 @@ bool BMP::read_header() { palette_size = header.bits_per_pixel > PALETTE_BITS_PER_PIXEL_LIMIT ? 0 // Use header.num_colours if it's greater than 0 and at most 1 << header.bits_per_pixel - : (0 < header.num_colours && header.num_colours - 1 >> header.bits_per_pixel == 0 + : (0 < header.num_colours && (header.num_colours - 1) >> header.bits_per_pixel == 0 ? header.num_colours : 1 << header.bits_per_pixel); const uint32_t expected_offset = palette_size * PALETTE_COLOUR_SIZE + sizeof(header); @@ -182,7 +182,7 @@ uint16_t BMP::get_bits_per_pixel() const { return header.bits_per_pixel; } -std::vector<colour_t> const& BMP::get_palette() const { +std::vector<BMP::palette_colour_t> const& BMP::get_palette() const { if (!palette_read) { Logger::warning("Trying to get BMP palette before loading"); } diff --git a/src/openvic-simulation/utility/BMP.hpp b/src/openvic-simulation/utility/BMP.hpp index c08ac99..eddfc91 100644 --- a/src/openvic-simulation/utility/BMP.hpp +++ b/src/openvic-simulation/utility/BMP.hpp @@ -32,14 +32,18 @@ namespace OpenVic { } header; #pragma pack(pop) + public: + using palette_colour_t = uint32_t; + + private: std::ifstream file; bool header_validated = false, palette_read = false, pixel_data_read = false; uint32_t palette_size = 0; - std::vector<colour_t> palette; + std::vector<palette_colour_t> palette; std::vector<uint8_t> pixel_data; public: - static constexpr uint32_t PALETTE_COLOUR_SIZE = sizeof(colour_t); + static constexpr uint32_t PALETTE_COLOUR_SIZE = sizeof(palette_colour_t); BMP() = default; ~BMP(); @@ -54,7 +58,7 @@ namespace OpenVic { int32_t get_width() const; int32_t get_height() const; uint16_t get_bits_per_pixel() const; - std::vector<colour_t> const& get_palette() const; + std::vector<palette_colour_t> const& get_palette() const; std::vector<uint8_t> const& get_pixel_data() const; }; } |