Porytiles
Loading...
Searching...
No Matches
index_pixel.hpp
Go to the documentation of this file.
1#pragma once
2
3// ReSharper disable once CppUnusedIncludeDirective
4#include <compare>
5
6namespace porytiles {
7
19 public:
20 IndexPixel() : index_{0} {}
21
22 // NOLINTNEXTLINE(google-explicit-constructor)
23 IndexPixel(std::size_t index) : index_{index}
24 {
25 /*
26 * No invariant check on `index_ < pal::max_size` here, because in true-color output mode we accept up to 8-bit
27 * index pixels. Even though pokeemerald only cares about the lower four bits, the upper four bits encode the
28 * pal index, which is what lets us save a non-greyscale png.
29 */
30 }
31
32 bool operator==(const IndexPixel &other) const = default;
33
34 auto operator<=>(const IndexPixel &) const = default;
35
46 [[nodiscard]] bool is_transparent() const
47 {
48 return color_index() == 0;
49 }
50
60 [[nodiscard]] std::size_t index() const
61 {
62 return index_;
63 }
64
77 [[nodiscard]] std::size_t color_index() const
78 {
79 return index_ & 0x0F;
80 }
81
94 [[nodiscard]] std::size_t palette_index() const
95 {
96 return index_ >> 4;
97 }
98
99 private:
100 std::size_t index_;
101};
102
103} // namespace porytiles
Represents an indexed color pixel.
auto operator<=>(const IndexPixel &) const =default
bool operator==(const IndexPixel &other) const =default
IndexPixel(std::size_t index)
std::size_t palette_index() const
Returns the palette index (upper 4 bits).
std::size_t color_index() const
Returns the color index within a palette (lower 4 bits).
bool is_transparent() const
Checks if this indexed pixel is transparent.
std::size_t index() const
Returns the raw index value.