Class GifWriter¶
Defined in File image_io.h
Class Documentation¶
-
class GifWriter¶
Writes an animated GIF one frame at a time, so only a single frame is held in memory while encoding.
Each frame gets its own palette; frames loop forever.
Public Functions
-
GifWriter(const std::string &filename, size_t width, size_t height)¶
Open a GIF file for writing.
- Parameters:
filename[in] the GIF file to write; overwritten if it exists.
width[in] width in pixels that every frame must have.
height[in] height in pixels that every frame must have.
- Throws:
std::invalid_argument – if the dimensions are invalid.
std::runtime_error – if the file can’t be opened.
-
void add_frame(Eigen::TensorMap<const core::rgb_img_t<uint8_t>> frame, double duration_ms)¶
Encode and append a frame.
GIF delays are stored in hundredths of a second. Rounding is carried over between frames so the total duration doesn’t drift, and every frame is shown for at least one hundredth of a second.
- Parameters:
frame[in] the frame, with shape (height, width, 3) for RGB or (height, width, 4) for RGBA; alpha is ignored.
duration_ms[in] how long to show the frame, in milliseconds.
- Throws:
std::invalid_argument – if the frame shape doesn’t match the writer.
std::runtime_error – if the writer is closed or encoding fails.
-
void close()¶
Write the end of the file and close it.
Further calls have no effect.
- Throws:
std::runtime_error – if the file can’t be written.
-
size_t width() const¶
- Returns:
the frame width in pixels.
-
size_t height() const¶
- Returns:
the frame height in pixels.
-
GifWriter(const std::string &filename, size_t width, size_t height)¶