Big batch of renames: strip qoi prefix everywhere
This commit is contained in:
parent
cb10dd3629
commit
328cfac40d
13 changed files with 73 additions and 72 deletions
|
|
@ -22,9 +22,7 @@ const QOI_OP_DIFF_END: u8 = QOI_OP_DIFF | 0x3f;
|
|||
const QOI_OP_LUMA_END: u8 = QOI_OP_LUMA | 0x3f;
|
||||
|
||||
#[inline]
|
||||
fn qoi_decode_impl_slice<const N: usize, const RGBA: bool>(
|
||||
data: &[u8], out: &mut [u8],
|
||||
) -> Result<usize>
|
||||
fn decode_impl_slice<const N: usize, const RGBA: bool>(data: &[u8], out: &mut [u8]) -> Result<usize>
|
||||
where
|
||||
Pixel<N>: SupportedChannels,
|
||||
[u8; N]: Pod,
|
||||
|
|
@ -92,14 +90,14 @@ where
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn qoi_decode_impl_slice_all(
|
||||
fn decode_impl_slice_all(
|
||||
data: &[u8], out: &mut [u8], channels: u8, src_channels: u8,
|
||||
) -> Result<usize> {
|
||||
match (channels, src_channels) {
|
||||
(3, 3) => qoi_decode_impl_slice::<3, false>(data, out),
|
||||
(3, 4) => qoi_decode_impl_slice::<3, true>(data, out),
|
||||
(4, 3) => qoi_decode_impl_slice::<4, false>(data, out),
|
||||
(4, 4) => qoi_decode_impl_slice::<4, true>(data, out),
|
||||
(3, 3) => decode_impl_slice::<3, false>(data, out),
|
||||
(3, 4) => decode_impl_slice::<3, true>(data, out),
|
||||
(4, 3) => decode_impl_slice::<4, false>(data, out),
|
||||
(4, 4) => decode_impl_slice::<4, true>(data, out),
|
||||
_ => {
|
||||
cold();
|
||||
Err(Error::InvalidChannels { channels })
|
||||
|
|
@ -108,33 +106,33 @@ fn qoi_decode_impl_slice_all(
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn qoi_decode_to_buf(buf: impl AsMut<[u8]>, data: impl AsRef<[u8]>) -> Result<Header> {
|
||||
let mut decoder = QoiDecoder::new(&data)?;
|
||||
pub fn decode_to_buf(buf: impl AsMut<[u8]>, data: impl AsRef<[u8]>) -> Result<Header> {
|
||||
let mut decoder = Decoder::new(&data)?;
|
||||
decoder.decode_to_buf(buf)?;
|
||||
Ok(*decoder.header())
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[inline]
|
||||
pub fn qoi_decode_to_vec(data: impl AsRef<[u8]>) -> Result<(Header, Vec<u8>)> {
|
||||
let mut decoder = QoiDecoder::new(&data)?;
|
||||
pub fn decode_to_vec(data: impl AsRef<[u8]>) -> Result<(Header, Vec<u8>)> {
|
||||
let mut decoder = Decoder::new(&data)?;
|
||||
let out = decoder.decode_to_vec()?;
|
||||
Ok((*decoder.header(), out))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn qoi_decode_header(data: impl AsRef<[u8]>) -> Result<Header> {
|
||||
pub fn decode_header(data: impl AsRef<[u8]>) -> Result<Header> {
|
||||
Header::decode(data)
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct QoiDecoder<'a> {
|
||||
pub struct Decoder<'a> {
|
||||
data: &'a [u8],
|
||||
header: Header,
|
||||
channels: Channels,
|
||||
}
|
||||
|
||||
impl<'a> QoiDecoder<'a> {
|
||||
impl<'a> Decoder<'a> {
|
||||
#[inline]
|
||||
pub fn new(data: &'a (impl AsRef<[u8]> + ?Sized)) -> Result<Self> {
|
||||
let data = data.as_ref();
|
||||
|
|
@ -171,7 +169,7 @@ impl<'a> QoiDecoder<'a> {
|
|||
if unlikely(buf.len() < size) {
|
||||
return Err(Error::OutputBufferTooSmall { size: buf.len(), required: size });
|
||||
}
|
||||
let n_read = qoi_decode_impl_slice_all(
|
||||
let n_read = decode_impl_slice_all(
|
||||
self.data,
|
||||
buf,
|
||||
self.channels.as_u8(),
|
||||
|
|
@ -191,7 +189,7 @@ impl<'a> QoiDecoder<'a> {
|
|||
|
||||
#[cfg(any(feature = "std"))]
|
||||
#[inline]
|
||||
fn qoi_decode_impl_stream<R: Read, const N: usize, const RGBA: bool>(
|
||||
fn decode_impl_stream<R: Read, const N: usize, const RGBA: bool>(
|
||||
data: &mut R, out: &mut [u8],
|
||||
) -> Result<()>
|
||||
where
|
||||
|
|
@ -261,14 +259,14 @@ where
|
|||
|
||||
#[cfg(feature = "std")]
|
||||
#[inline]
|
||||
fn qoi_decode_impl_stream_all<R: Read>(
|
||||
fn decode_impl_stream_all<R: Read>(
|
||||
data: &mut R, out: &mut [u8], channels: u8, src_channels: u8,
|
||||
) -> Result<()> {
|
||||
match (channels, src_channels) {
|
||||
(3, 3) => qoi_decode_impl_stream::<_, 3, false>(data, out),
|
||||
(3, 4) => qoi_decode_impl_stream::<_, 3, true>(data, out),
|
||||
(4, 3) => qoi_decode_impl_stream::<_, 4, false>(data, out),
|
||||
(4, 4) => qoi_decode_impl_stream::<_, 4, true>(data, out),
|
||||
(3, 3) => decode_impl_stream::<_, 3, false>(data, out),
|
||||
(3, 4) => decode_impl_stream::<_, 3, true>(data, out),
|
||||
(4, 3) => decode_impl_stream::<_, 4, false>(data, out),
|
||||
(4, 4) => decode_impl_stream::<_, 4, true>(data, out),
|
||||
_ => {
|
||||
cold();
|
||||
Err(Error::InvalidChannels { channels })
|
||||
|
|
@ -277,14 +275,14 @@ fn qoi_decode_impl_stream_all<R: Read>(
|
|||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub struct QoiStreamDecoder<R> {
|
||||
pub struct StreamDecoder<R> {
|
||||
reader: R,
|
||||
header: Header,
|
||||
channels: Channels,
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<R: Read> QoiStreamDecoder<R> {
|
||||
impl<R: Read> StreamDecoder<R> {
|
||||
#[inline]
|
||||
pub fn new(mut reader: R) -> Result<Self> {
|
||||
let mut b = [0; QOI_HEADER_SIZE];
|
||||
|
|
@ -325,7 +323,7 @@ impl<R: Read> QoiStreamDecoder<R> {
|
|||
if unlikely(buf.len() < size) {
|
||||
return Err(Error::OutputBufferTooSmall { size: buf.len(), required: size });
|
||||
}
|
||||
qoi_decode_impl_stream_all(
|
||||
decode_impl_stream_all(
|
||||
&mut self.reader,
|
||||
buf,
|
||||
self.channels.as_u8(),
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use crate::utils::GenericWriter;
|
|||
use crate::utils::{unlikely, BytesMut, Writer};
|
||||
|
||||
#[allow(clippy::cast_possible_truncation, unused_assignments)]
|
||||
fn qoi_encode_impl<W: Writer, const N: usize>(mut buf: W, data: &[u8]) -> Result<usize>
|
||||
fn encode_impl<W: Writer, const N: usize>(mut buf: W, data: &[u8]) -> Result<usize>
|
||||
where
|
||||
Pixel<N>: SupportedChannels,
|
||||
{
|
||||
|
|
@ -70,15 +70,15 @@ where
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn qoi_encode_impl_all<W: Writer>(out: W, data: &[u8], channels: Channels) -> Result<usize> {
|
||||
fn encode_impl_all<W: Writer>(out: W, data: &[u8], channels: Channels) -> Result<usize> {
|
||||
match channels {
|
||||
Channels::Rgb => qoi_encode_impl::<_, 3>(out, data),
|
||||
Channels::Rgba => qoi_encode_impl::<_, 4>(out, data),
|
||||
Channels::Rgb => encode_impl::<_, 3>(out, data),
|
||||
Channels::Rgba => encode_impl::<_, 4>(out, data),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn encoded_size_limit(width: u32, height: u32, channels: impl Into<u8>) -> usize {
|
||||
pub fn encode_size_limit(width: u32, height: u32, channels: impl Into<u8>) -> usize {
|
||||
let (width, height) = (width as usize, height as usize);
|
||||
let n_pixels = width.saturating_mul(height);
|
||||
QOI_HEADER_SIZE
|
||||
|
|
@ -88,24 +88,24 @@ pub fn encoded_size_limit(width: u32, height: u32, channels: impl Into<u8>) -> u
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn qoi_encode_to_buf(
|
||||
pub fn encode_to_buf(
|
||||
buf: impl AsMut<[u8]>, data: impl AsRef<[u8]>, width: u32, height: u32,
|
||||
) -> Result<usize> {
|
||||
QoiEncoder::new(&data, width, height)?.encode_to_buf(buf)
|
||||
Encoder::new(&data, width, height)?.encode_to_buf(buf)
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "alloc", feature = "std"))]
|
||||
#[inline]
|
||||
pub fn qoi_encode_to_vec(data: impl AsRef<[u8]>, width: u32, height: u32) -> Result<Vec<u8>> {
|
||||
QoiEncoder::new(&data, width, height)?.encode_to_vec()
|
||||
pub fn encode_to_vec(data: impl AsRef<[u8]>, width: u32, height: u32) -> Result<Vec<u8>> {
|
||||
Encoder::new(&data, width, height)?.encode_to_vec()
|
||||
}
|
||||
|
||||
pub struct QoiEncoder<'a> {
|
||||
pub struct Encoder<'a> {
|
||||
data: &'a [u8],
|
||||
header: Header,
|
||||
}
|
||||
|
||||
impl<'a> QoiEncoder<'a> {
|
||||
impl<'a> Encoder<'a> {
|
||||
#[inline]
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
pub fn new(data: &'a (impl AsRef<[u8]> + ?Sized), width: u32, height: u32) -> Result<Self> {
|
||||
|
|
@ -138,27 +138,27 @@ impl<'a> QoiEncoder<'a> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn encoded_size_limit(&self) -> usize {
|
||||
self.header.encoded_size_limit()
|
||||
pub fn encode_size_limit(&self) -> usize {
|
||||
self.header.encode_size_limit()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn encode_to_buf(&self, mut buf: impl AsMut<[u8]>) -> Result<usize> {
|
||||
let buf = buf.as_mut();
|
||||
let size_required = self.encoded_size_limit();
|
||||
let size_required = self.encode_size_limit();
|
||||
if unlikely(buf.len() < size_required) {
|
||||
return Err(Error::OutputBufferTooSmall { size: buf.len(), required: size_required });
|
||||
}
|
||||
let (head, tail) = buf.split_at_mut(QOI_HEADER_SIZE); // can't panic
|
||||
head.copy_from_slice(&self.header.encode());
|
||||
let n_written = qoi_encode_impl_all(BytesMut::new(tail), self.data, self.header.channels)?;
|
||||
let n_written = encode_impl_all(BytesMut::new(tail), self.data, self.header.channels)?;
|
||||
Ok(QOI_HEADER_SIZE + n_written)
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "alloc", feature = "std"))]
|
||||
#[inline]
|
||||
pub fn encode_to_vec(&self) -> Result<Vec<u8>> {
|
||||
let mut out = vec![0_u8; self.encoded_size_limit()];
|
||||
let mut out = vec![0_u8; self.encode_size_limit()];
|
||||
let size = self.encode_to_buf(&mut out)?;
|
||||
out.truncate(size);
|
||||
Ok(out)
|
||||
|
|
@ -169,7 +169,7 @@ impl<'a> QoiEncoder<'a> {
|
|||
pub fn encode_to_stream<W: Write>(&self, writer: &mut W) -> Result<usize> {
|
||||
writer.write_all(&self.header.encode())?;
|
||||
let n_written =
|
||||
qoi_encode_impl_all(GenericWriter::new(writer), self.data, self.header.channels)?;
|
||||
encode_impl_all(GenericWriter::new(writer), self.data, self.header.channels)?;
|
||||
Ok(n_written + QOI_HEADER_SIZE)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use core::convert::TryInto;
|
|||
use bytemuck::cast_slice;
|
||||
|
||||
use crate::consts::{QOI_HEADER_SIZE, QOI_MAGIC, QOI_PIXELS_MAX};
|
||||
use crate::encoded_size_limit;
|
||||
use crate::encode_size_limit;
|
||||
use crate::error::{Error, Result};
|
||||
use crate::types::{Channels, ColorSpace};
|
||||
use crate::utils::unlikely;
|
||||
|
|
@ -112,7 +112,7 @@ impl Header {
|
|||
///
|
||||
/// This comes useful when pre-allocating a buffer to encode the image into.
|
||||
#[inline]
|
||||
pub fn encoded_size_limit(&self) -> usize {
|
||||
encoded_size_limit(self.width, self.height, self.channels)
|
||||
pub fn encode_size_limit(&self) -> usize {
|
||||
encode_size_limit(self.width, self.height, self.channels)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
10
src/lib.rs
10
src/lib.rs
|
|
@ -26,14 +26,14 @@ mod utils;
|
|||
pub mod consts;
|
||||
|
||||
#[cfg(any(feature = "alloc", feature = "std"))]
|
||||
pub use crate::decode::qoi_decode_to_vec;
|
||||
pub use crate::decode::decode_to_vec;
|
||||
#[cfg(feature = "std")]
|
||||
pub use crate::decode::QoiStreamDecoder;
|
||||
pub use crate::decode::{qoi_decode_header, qoi_decode_to_buf, QoiDecoder};
|
||||
pub use crate::decode::StreamDecoder;
|
||||
pub use crate::decode::{decode_header, decode_to_buf, Decoder};
|
||||
|
||||
#[cfg(any(feature = "alloc", feature = "std"))]
|
||||
pub use crate::encode::qoi_encode_to_vec;
|
||||
pub use crate::encode::{encoded_size_limit, qoi_encode_to_buf, QoiEncoder};
|
||||
pub use crate::encode::encode_to_vec;
|
||||
pub use crate::encode::{encode_size_limit, encode_to_buf, Encoder};
|
||||
pub use crate::error::{Error, Result};
|
||||
pub use crate::header::Header;
|
||||
pub use crate::types::{Channels, ColorSpace};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue