21template <
typename StreamType,
int8_t bits_per_pixel>
24template <
typename StreamType>
29template <
typename StreamType>
34template <
typename StreamType>
39template <
typename StreamType>
44template <
typename StreamType>
50 if ((
datum & roo::byte{0x80}) == roo::byte{0})
return result;
54template <
typename Resource,
typename ColorMode,
55 int8_t bits_per_pixel = ColorMode::bits_per_pixel,
61template <
typename Resource,
typename ColorMode,
int8_t bits_per_pixel>
73 color_mode_(color_mode) {}
84 while (
n-- > 0) next();
88 if (remaining_items_ == 0) {
90 roo::byte data = input_.read();
91 run_ = ((data & roo::byte{0x80}) != roo::byte{0});
92 if ((data & roo::byte{0x40}) == roo::byte{0}) {
93 remaining_items_ = (
int)(data & roo::byte{0x3F}) + 1;
96 read_varint(input_, (
int)(data & roo::byte{0x3F})) + 1;
99 run_value_ = read_color();
104 if (remaining_items_ == 0) {
116 return color_mode_.toArgbColor(read(input_));
120 int remaining_items_;
123 ColorMode color_mode_;
128template <
typename Resource,
typename ColorMode,
int8_t bits_per_pixel>
132 static constexpr int pixels_per_byte = 8 / bits_per_pixel;
142 color_mode_(color_mode) {}
153 while (
n-- > 0) next();
157 if (remaining_items_ == 0) {
160 run_ = ((data & 0x80) != 0);
161 if ((data & 0x40) == 0) {
162 remaining_items_ = pixels_per_byte * ((data & 0x3F) + 1);
165 pixels_per_byte * (
read_varint(input_, data & 0x3F) + 1);
172 value_[pixels_per_byte - 1 - remaining_items_ % pixels_per_byte];
173 if (!run_ && remaining_items_ != 0 &&
174 remaining_items_ % pixels_per_byte == 0) {
183 io.loadBulk(color_mode_, input_.read(), value_);
187 int remaining_items_;
190 Color value_[pixels_per_byte];
191 ColorMode color_mode_;
197template <
typename Resource>
218 while (--count >= 0)
next();
222 if (remaining_items_ == 0) {
227 run_rgb_ = (data >> 7);
233 alpha_mode_ = (data & 0x60) >> 5;
234 switch (alpha_mode_) {
238 data & 0x10 ? read_varint(data & 0x0F) : data & 0x0F;
239 remaining_items_ <<= 1;
243 remaining_items_ = read_varint((data & 0x10) >> 4);
244 alpha_buf_ = (data & 0x0F) * 0x11;
249 data & 0x10 ? read_varint(data & 0x0F) : data & 0x0F;
254 data & 0x10 ? read_varint(data & 0x0F) : data & 0x0F;
259 run_value_ = read_color();
260 run_value_.
set_a(alpha_buf_);
265 if (alpha_mode_ == 0) {
266 if (remaining_items_ & 1) {
267 alpha_buf_ = input_.read();
268 run_value_.
set_a((alpha_buf_ >> 4) * 0x11);
270 run_value_.
set_a((alpha_buf_ & 0xF) * 0x11);
276 if (alpha_mode_ == 0) {
278 if (remaining_items_ & 1) {
279 alpha_buf_ = input_.read();
280 c.set_a((alpha_buf_ >> 4) * 0x11);
282 c.set_a((alpha_buf_ & 0xF) * 0x11);
306 StreamType<Resource> input_;
307 int remaining_items_;
314template <
typename StreamType>
323 return (
uint8_t)(buffer_ & roo::byte{0x0F});
325 buffer_ = input_.read();
327 return (
uint8_t)(buffer_ >> 4);
331 bool ok()
const {
return input_.status() == roo_io::kOk; }
341template <
typename Resource,
typename ColorMode,
342 int8_t bits_per_pixel = ColorMode::bits_per_pixel>
350template <
typename Resource,
typename ColorMode>
361 color_mode_(color_mode) {}
398 if (remaining_items_ == 0) {
405 remaining_items_ = 2;
406 run_value_ =
color(reader_.next());
408 remaining_items_ = 3;
409 run_value_ =
color(reader_.next());
412 remaining_items_ = 1;
415 }
else if (
nibble == 0x8) {
421 run_value_ =
color(reader_.next());
425 remaining_items_ = count + 2;
430 remaining_items_ =
nibble & 0x7;
432 run_value_ = color_mode_.color();
434 run_value_.set_a(0x0);
441 if (remaining_items_ == 0) {
446 return color(reader_.next());
451 while (
n-- > 0) next();
456 bool ok()
const {
return reader_.ok(); }
471 NibbleReader<StreamType<Resource>> reader_;
472 uint32_t remaining_items_;
475 ColorMode color_mode_;
ARGB8888 color stored as a 32-bit unsigned integer.
void set_a(uint8_t a)
Set alpha channel.
Stream of pixels in row-major order.
16-bit RGB565 color mode (opaque).
constexpr Color toArgbColor(uint16_t in) const __attribute__((always_inline))
NibbleReader(StreamType input)
RleStream4bppxBiased(StreamType< Resource > input, const ColorMode &color_mode)
TransparencyMode transparency() const
void Read(Color *buf, uint16_t size) override
Read up to size pixels into buf.
void Skip(uint32_t n) override
Skip count pixels.
RleStream4bppxBiased(const Resource &input, const ColorMode &color_mode)
RleStreamRgb565Alpha4(const Resource &input)
void Read(Color *buf, uint16_t size) override
Read up to size pixels into buf.
void Skip(uint32_t count) override
Skip count pixels.
RleStreamRgb565Alpha4(StreamType< Resource > input)
uint32_t read_varint(StreamType &in, uint32_t result)
Defines 140 opaque HTML named colors.
decltype(std::declval< Resource >().iterator()) StreamType
Stream type produced by a resource iterable.
TransparencyMode
Transparency information for a stream or color mode.
uint16_t operator()(StreamType &in) const
uint32_t operator()(StreamType &in) const
uint32_t operator()(StreamType &in) const
uint8_t operator()(StreamType &in) const