Implement efficient encoding to generic streams

This commit is contained in:
Ivan Smirnov 2022-01-03 01:11:01 +03:00
commit ae6d410374
3 changed files with 68 additions and 30 deletions

View file

@ -1,4 +1,5 @@
use crate::consts::{QOI_OP_DIFF, QOI_OP_LUMA, QOI_OP_RGB, QOI_OP_RGBA};
use crate::error::Result;
use crate::utils::Writer;
#[derive(Copy, Clone, PartialEq, Eq)]
@ -118,7 +119,7 @@ impl<const N: usize> Pixel<N> {
}
#[inline]
pub fn encode_into<W: Writer>(&self, px_prev: Self, buf: W) -> W::Output {
pub fn encode_into<W: Writer>(&self, px_prev: Self, buf: W) -> Result<W> {
if N == 3 || self.a_or(0) == px_prev.a_or(0) {
let vg = self.g().wrapping_sub(px_prev.g());
let vg_32 = vg.wrapping_add(32);