6#include "TinyGPU/Surface/ISurface.h"
8#if defined(ARDUINO) || __has_include
(<Print.h>)
16 virtual size_t write(uint8_t c) = 0;
17 size_t write(
const uint8_t* buf, size_t n) {
19 for (size_t i = 0; i < n; ++i) written += write(buf[i]);
22 virtual void flush() {}
30
31
32
33
34
35
36
37
38
39template <
typename RGB_T =
RGB565>
49 bool begin(
const ISurface<RGB_T>& surface, uint16_t fps = 30,
50 uint32_t frameCount = 0) {
53 width_ =
static_cast<uint32_t>(surface.width());
54 height_ =
static_cast<uint32_t>(surface.height());
60 fps_ = fps == 0 ? 1 : fps;
84 bool add(
const ISurface<RGB_T>& surface) {
117 return ((width * 2U) + 3U) & ~0x3U;
122 return dataSize + (dataSize & 0x1U);
139 const uint32_t avihSize = 56;
140 const uint32_t strhSize = 56;
141 const uint32_t strfSize = 52;
142 const uint32_t avihChunkSize = 8 + avihSize;
143 const uint32_t strhChunkSize = 8 + strhSize;
144 const uint32_t strfChunkSize = 8 + strfSize;
145 const uint32_t strlListSize = 4 + strhChunkSize + strfChunkSize;
146 const uint32_t strlChunkSize = 8 + strlListSize;
147 const uint32_t hdrlListSize = 4 + avihChunkSize + strlChunkSize;
148 const uint32_t hdrlChunkSize = 8 + hdrlListSize;
151 const uint32_t moviListSize =
154 const uint32_t moviChunkSize = 8 + moviListSize;
155 const uint32_t idx1Size =
158 const uint32_t riffSize =
160 ? 4 + hdrlChunkSize + moviChunkSize
161 : 4 + hdrlChunkSize + moviChunkSize + idx1ChunkSize;
162 const uint32_t microsecondsPerFrame = 1000000UL /
fps_;
164 const uint32_t suggestedBufferSize =
frameSize_;
239 const uint32_t width =
static_cast<uint32_t>(surface.width());
240 const uint32_t height =
static_cast<uint32_t>(surface.height());
242 const uint8_t padByte = 0;
244 for (uint32_t row = 0; row < height; ++row) {
245 const uint32_t sourceY = height - 1U - row;
246 for (uint32_t x = 0; x < width; ++x) {
250 writeU16(surface.getPixel(x, sourceY).getValueSwapped()
);
252 for (uint32_t padding = width * 2U; padding < rowStride; ++padding) {
253 writeBytes(&padByte, 1);
266 uint32_t moviOffset = 4;
278 writeBytes(
reinterpret_cast<
const uint8_t*>(value), 4);
286 const uint8_t bytes[2] = {
static_cast<uint8_t>(value & 0xFFU),
287 static_cast<uint8_t>((value >> 8) & 0xFFU)};
288 writeBytes(bytes,
sizeof(bytes));
293 const uint8_t bytes[4] = {
static_cast<uint8_t>(value & 0xFFU),
294 static_cast<uint8_t>((value >> 8) & 0xFFU),
295 static_cast<uint8_t>((value >> 16) & 0xFFU),
296 static_cast<uint8_t>((value >> 24) & 0xFFU)};
297 writeBytes(bytes,
sizeof(bytes));
302 out_.write(data, length);
Writes a simple AVI movie containing RGB565 frames.
Definition: AVIWriter.h:40
uint32_t width_
Definition: AVIWriter.h:106
void writeIndex()
Writes the idx1 frame index when a frame count was provided.
Definition: AVIWriter.h:259
uint32_t frameSize_
Definition: AVIWriter.h:110
static uint32_t paddedChunkSize(uint32_t dataSize)
Returns the data size rounded up to an even AVI chunk length.
Definition: AVIWriter.h:121
uint32_t rowStride_
Definition: AVIWriter.h:109
uint16_t fps_
Definition: AVIWriter.h:108
void writeHeader()
Writes the RIFF, AVI, stream, and movi headers.
Definition: AVIWriter.h:138
void writeU8(uint8_t value)
Writes a single byte to the output stream.
Definition: AVIWriter.h:282
bool begin(const ISurface< RGB_T > &surface, uint16_t fps=30, uint32_t frameCount=0)
Definition: AVIWriter.h:49
uint32_t height_
Definition: AVIWriter.h:107
void writeU32(uint32_t value)
Writes a 32-bit little-endian value to the output stream.
Definition: AVIWriter.h:292
void writeU16(uint16_t value)
Writes a 16-bit little-endian value to the output stream.
Definition: AVIWriter.h:285
void writeFrame(const ISurface< RGB_T > &surface)
Writes one surface as a bottom-up padded RGB565 AVI frame.
Definition: AVIWriter.h:238
void resetState()
Resets the writer state after finishing or aborting a stream.
Definition: AVIWriter.h:126
static uint32_t frameRowStride(uint32_t width)
Returns the padded byte stride of one RGB565 frame row.
Definition: AVIWriter.h:116
uint32_t expectedFrameCount_
Definition: AVIWriter.h:111
bool isOpen_
Definition: AVIWriter.h:113
void writeBytes(const uint8_t *data, size_t length)
Writes a raw byte sequence to the output stream.
Definition: AVIWriter.h:301
bool add(const ISurface< RGB_T > &surface)
Appends one RGB565 frame to the AVI stream.
Definition: AVIWriter.h:84
uint32_t frameCount_
Definition: AVIWriter.h:112
void end()
Finalizes the AVI stream and writes the optional frame index.
Definition: AVIWriter.h:72
void writeFourCC(const char *value)
Writes a four-character AVI chunk identifier.
Definition: AVIWriter.h:277
AVIWriter(Print &out)
Creates an AVI writer that streams data to the provided Print output.
Definition: AVIWriter.h:43
~AVIWriter()
Finalizes the AVI stream if it is still open.
Definition: AVIWriter.h:45
Print & out_
Definition: AVIWriter.h:105
RGB color stored in 16-bit RGB565 format, byte-swapped from the conventional bit layout.
Definition: RGB565.h:24
Definition: DSIBusESP32.h:19