#pragma once #include #include #include // Pulls complete JPEG files out of an arbitrary byte stream (single image, // MJPEG multipart, junk in between) by walking the marker structure, so an // EOI inside an EXIF thumbnail can't truncate a frame. typedef struct { int state; uint8_t marker; uint32_t remaining; uint8_t *out; size_t out_len, out_cap; size_t skipped; // bytes discarded while hunting for SOI } jpegframe_t; void jpegframe_init(jpegframe_t *f, uint8_t *out, size_t out_cap); void jpegframe_reset(jpegframe_t *f); // Consumes input; returns the number of bytes used. *complete is set when // out[0..out_len) holds a whole JPEG (unused input stays for the next call). // *overflow is set if a frame outgrew the buffer; the extractor then resyncs. size_t jpegframe_feed(jpegframe_t *f, const uint8_t *in, size_t n, bool *complete, bool *overflow);