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
17 public:
18 IndexPixel() : index_{0} {}
19
20 // NOLINTNEXTLINE(google-explicit-constructor)
21 IndexPixel(std::size_t index) : index_{index}
22 {
23 // No invariant check on `index_ < palette::max_size` here, because in true-color output mode we accept up to
24 // 8-bit index pixels. Even though pokeemerald only cares about the lower four bits, the upper four bits encode
25 // the palette index, which is what lets us save a non-greyscale png.
26 }
27
28 bool operator==(const IndexPixel &other) const = default;
29
30 auto operator<=>(const IndexPixel &) const = default;
31
40 [[nodiscard]] bool is_transparent() const
41 {
42 return color_index() == 0;
43 }
44
52 [[nodiscard]] std::size_t index() const
53 {
54 return index_;
55 }
56
67 [[nodiscard]] std::size_t color_index() const
68 {
69 return index_ & 0x0F;
70 }
71
82 [[nodiscard]] std::size_t palette_index() const
83 {
84 return index_ >> 4;
85 }
86
87 private:
88 std::size_t index_;
89};
90
91} // 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.