7#include "TinyJPEGDecoder.h"
8#include "TinyJPEGEncoder.h"
70 bool isValid(
const uint8_t *data,
size_t len)
override {
71 return len >= 2 && data[0] == 0xFF && data[1] == 0xD8;
84 LOGW(
"MJPEGDecoder: unsupported VideoFormat %d - only RGB565",
116 bool begin()
override {
return true; }
122 size_t write(
const uint8_t *data,
size_t len)
override {
142 if (
pos == 0)
return;
147 uint16_t w = 0, h = 0;
150 LOGE(
"MJPEGDecoder: could not determine JPEG size");
160 LOGE(
"MJPEGDecoder: frame buffer allocation failed");
181 bool isKeyFrame(
const uint8_t *data,
size_t len)
override {
return true; }
198 static bool onBlock(tinyjpeg::TinyJPEGDecoder &decoder, int16_t x,
199 int16_t y, uint16_t w, uint16_t h, uint16_t *data) {
200 return static_cast<MJPEGDecoder *
>(decoder.getUserData())
201 ->writeBlock(x, y, w, h, data);
210 bool writeBlock(int16_t x, int16_t y, uint16_t w, uint16_t h,
212 if (x < 0 || y < 0)
return true;
215 if ((uint32_t)x >= max_x || (uint32_t)y >= max_y)
return true;
216 uint32_t win_w = std::min((uint32_t)w, max_x - (uint32_t)x);
217 uint32_t win_h = std::min((uint32_t)h, max_y - (uint32_t)y);
219 for (uint32_t row = 0; row < win_h; row++) {
220 memcpy(dst + ((uint32_t)y + row) * max_x + (uint32_t)x,
221 data + row * w, win_w *
sizeof(uint16_t));
228 if (
p_out !=
nullptr) result =
p_out->write(data, len);
279 LOGW(
"MJPEGEncoder: unsupported VideoFormat %d", (
int)format);
306 if (size >
jpeg.size())
jpeg.resize(size);
311 LOGE(
"MJPEGEncoder: setSize() was not called");
315 return jpeg.data() !=
nullptr;
324 size_t write(
const uint8_t *data,
size_t len)
override {
327 if (expected == 0 || len < expected) {
328 LOGE(
"MJPEGEncoder: %u bytes, expected %u", (
unsigned)len,
334 JERESULT rc =
encode(data, size);
339 if (
jpeg.data() ==
nullptr) {
340 LOGE(
"MJPEGEncoder: buffer allocation failed");
346 LOGE(
"MJPEGEncoder: encoding failed (%d)", (
int)rc);
369 JERESULT
encode(
const uint8_t *data,
size_t &size) {
VideoFormat
Video codec/pixel-format identifier, shared by two unrelated uses: the (single) video stream of a con...
Definition VideoOutput.h:29
size_t videoFrameSizeBytes(VideoFormat format, uint16_t width, uint16_t height)
Fixed per-frame size (bytes) for a raw/uncompressed VideoFormat at the given resolution - 0 for compr...
Definition Video.h:27
@ MJPEG
Definition VideoOutput.h:31
@ RGB888
Definition VideoOutput.h:37
@ RGB565
Definition VideoOutput.h:35
@ RGB666
Definition VideoOutput.h:36