Add qoi_encode_to_buf() and encode_size_required()

This commit is contained in:
Ivan Smirnov 2021-11-30 02:46:04 +00:00
commit 1bb6ee118c
3 changed files with 79 additions and 28 deletions

View file

@ -10,6 +10,7 @@ pub enum Error {
EmptyImage { width: u32, height: u32 },
BadEncodingDataSize { size: usize, expected: usize },
BadDecodingDataSize { size: usize },
OutputBufferTooSmall { size: usize, required: usize },
InvalidMagic { magic: u32 },
// TODO: invalid colorspace
}
@ -32,6 +33,9 @@ impl Display for Error {
let min_size = QOI_HEADER_SIZE + QOI_PADDING;
write!(f, "bad data size when decoding: {} (minimum required: {})", size, min_size)
}
Self::OutputBufferTooSmall { size, required } => {
write!(f, "output buffer size too small: {} (minimum required: {})", size, required)
}
Self::InvalidMagic { magic } => {
write!(f, "invalid magic: expected {:?}, got {:?}", QOI_MAGIC, magic)
}