15 return static_cast<int>((
static_cast<uint32_t>(n) *
static_cast<uint32_t>(target) + source - 1) /
37 return "Invalid type";
39 return "Unsupported format";
41 return "Out of memory";
43 return "Internal decoder error";
47 return "Unknown error";
52static constexpr uint32_t DECODE_TIME_LIMIT_MS = 15;
54static constexpr uint32_t DECODE_TIME_CHECK_STEPS = 64;
162 bool set_size(
int width,
int height);
176 void draw(
int x,
int y,
int w,
int h,
const Color &color);
Fixed-capacity vector - sized once through init() or try_init(); push_back never reallocates This avo...
Input that a decoder reads itself as it goes, so the whole image never has to be in memory at once.
virtual ~DecodeSource()=default
virtual int32_t read(uint8_t *buf, uint32_t len)=0
Read up to len bytes at the current position.
virtual bool seek(uint32_t position)=0
Move to a position counted from the start. Returns false on error.
Class to abstract decoding different image formats.
FixedVector< uint16_t > x_boundaries_
void prepare_draw_(int width, int height)
Draw a source of width x height over the whole buffer from now on.
virtual bool knows_end() const
Whether is_finished() can tell a complete image from a cut-off one.
virtual void reset()
Reset the decoder state, ending any decoding session.
size_t get_decoded_bytes() const
Bytes of the image the decoder has used so far.
ImageDecoder(RuntimeImage *image, ImageFormat format)
Construct a new Image Decoder object.
void draw_rgb565_(int x, int y, int w, int h, uint16_t rgb565)
Paint a block of source pixels in one color straight into the buffer. Only while uses_direct_rgb565()...
const ImageFormat format_
bool resize_image_(int width, int height)
Resize the image for a width x height source, without preparing to draw. prepare_draw_() must follow.
uint8_t * image_buffer_() const
The image's pixel buffer, for decoders that write their output straight into it.
bool is_active() const
Check if a decoding session is in progress (prepare() called, reset() not yet).
virtual bool is_finished() const
Check if the decoder has finished processing.
virtual ~ImageDecoder()=default
virtual int decode(uint8_t *buffer, size_t size)=0
Decode a part of the image.
virtual int begin_source(DecodeSource *source)
Start decoding from a source the decoder reads itself.
void draw(int x, int y, int w, int h, const Color &color)
Fill a rectangle on the display_buffer using the defined color.
ImageFormat get_format() const
Get the image format handled by this decoder.
FixedVector< uint16_t > y_boundaries_
bool uses_direct_rgb565() const
The image is opaque RGB565, so draw() writes it straight into the buffer.
bool set_size(int width, int height)
Request the image to be resized once the actual dimensions are known.
virtual bool supports_source() const
Whether this decoder can read a DecodeSource itself, a step at a time, instead of being fed data.
virtual int prepare(size_t expected_size)
Initialize the decoder, starting a new decoding session.
virtual int decode_step()
Decode a little more of an image started with begin_source(), keeping each call short.
bool image_is_big_endian_() const
A dynamic image that can be loaded and decoded at runtime.
@ DECODE_ERROR_INTERNAL_DECODER_ERROR
@ DECODE_ERROR_OUT_OF_MEMORY
@ DECODE_ERROR_UNSUPPORTED_FORMAT
@ DECODE_ERROR_INVALID_TYPE
ImageFormat
Image format types that can be decoded dynamically.
DecodeStep
Results of ImageDecoder::decode_step() other than a DecodeError.
int scale_boundary(int n, int source, int target)
The first of target pixels that pixel n of source paints, rounded up: ceil(n * target / source).
constexpr const char * decode_error_to_string(int error)