mirror of
https://github.com/Dangoware/sqp.git
synced 2025-04-19 07:12:55 -05:00
Improved documentation
This commit is contained in:
parent
0d45926e73
commit
e063bc431a
2 changed files with 30 additions and 23 deletions
|
@ -64,11 +64,11 @@ pub mod header;
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use picture::SquishyPicture;
|
pub use picture::SquishyPicture;
|
||||||
|
|
||||||
|
#[doc(inline)]
|
||||||
|
pub use picture::open;
|
||||||
|
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use header::ColorFormat;
|
pub use header::ColorFormat;
|
||||||
|
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use header::CompressionType;
|
pub use header::CompressionType;
|
||||||
|
|
||||||
#[doc(inline)]
|
|
||||||
pub use picture::open;
|
|
||||||
|
|
|
@ -27,25 +27,25 @@ pub enum Error {
|
||||||
|
|
||||||
/// The basic Squishy Picture type for manipulation in-memory.
|
/// The basic Squishy Picture type for manipulation in-memory.
|
||||||
pub struct SquishyPicture {
|
pub struct SquishyPicture {
|
||||||
pub header: Header,
|
header: Header,
|
||||||
pub bitmap: Vec<u8>,
|
bitmap: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SquishyPicture {
|
impl SquishyPicture {
|
||||||
/// Create a DPF from raw bytes in a particular [`ColorFormat`].
|
/// Create a DPF from raw bytes in a particular [`ColorFormat`].
|
||||||
///
|
///
|
||||||
/// The quality parameter does nothing if the compression type is not
|
/// The quality parameter does nothing if the compression type is not
|
||||||
/// lossy, so it should be set to None.
|
/// lossy, so it must be set to None.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```ignore
|
/// ```
|
||||||
/// let sqp = SquishyPicture::from_raw(
|
/// let sqp = sqp::SquishyPicture::from_raw(
|
||||||
/// input.width(),
|
/// 1920,
|
||||||
/// input.height(),
|
/// 1080,
|
||||||
/// ColorFormat::Rgba32,
|
/// sqp::ColorFormat::Rgba8,
|
||||||
/// CompressionType::LossyDct,
|
/// sqp::CompressionType::LossyDct,
|
||||||
/// Some(80),
|
/// Some(80),
|
||||||
/// input.as_raw().clone()
|
/// vec![0u8; (1920 * 1080) * 4]
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
pub fn from_raw(
|
pub fn from_raw(
|
||||||
|
@ -85,13 +85,13 @@ impl SquishyPicture {
|
||||||
/// lossy image with a given quality.
|
/// lossy image with a given quality.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```ignore
|
/// ```
|
||||||
/// let sqp = SquishyPicture::from_raw_lossy(
|
/// let sqp = sqp::SquishyPicture::from_raw_lossy(
|
||||||
/// input.width(),
|
/// 1920,
|
||||||
/// input.height(),
|
/// 1080,
|
||||||
/// ColorFormat::Rgba32,
|
/// sqp::ColorFormat::Rgba8,
|
||||||
/// 80,
|
/// 80,
|
||||||
/// input.as_raw().clone()
|
/// vec![0u8; (1920 * 1080) * 4]
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
pub fn from_raw_lossy(
|
pub fn from_raw_lossy(
|
||||||
|
@ -117,10 +117,10 @@ impl SquishyPicture {
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```ignore
|
/// ```ignore
|
||||||
/// let sqp = SquishyPicture::from_raw_lossless(
|
/// let sqp = SquishyPicture::from_raw_lossless(
|
||||||
/// input.width(),
|
/// 1920,
|
||||||
/// input.height(),
|
/// 1080,
|
||||||
/// ColorFormat::Rgba32,
|
/// sqp::ColorFormat::Rgba8,
|
||||||
/// input.as_raw().clone()
|
/// vec![0u8; (1920 * 1080) * 4]
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
pub fn from_raw_lossless(
|
pub fn from_raw_lossless(
|
||||||
|
@ -191,6 +191,8 @@ impl SquishyPicture {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Encode and write the image out to a file.
|
/// Encode and write the image out to a file.
|
||||||
|
///
|
||||||
|
/// Convenience method over [`SquishyPicture::encode`]
|
||||||
pub fn save<P: ?Sized + AsRef<std::path::Path>>(&self, path: &P) -> Result<(), Error> {
|
pub fn save<P: ?Sized + AsRef<std::path::Path>>(&self, path: &P) -> Result<(), Error> {
|
||||||
let mut out_file = BufWriter::new(File::create(path.as_ref())?);
|
let mut out_file = BufWriter::new(File::create(path.as_ref())?);
|
||||||
|
|
||||||
|
@ -232,6 +234,11 @@ impl SquishyPicture {
|
||||||
|
|
||||||
Ok(Self { header, bitmap })
|
Ok(Self { header, bitmap })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the underlying raw buffer as a reference
|
||||||
|
pub fn as_raw(&self) -> &Vec<u8> {
|
||||||
|
&self.bitmap
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decode_varint_stream(stream: &[u8]) -> Vec<i16> {
|
fn decode_varint_stream(stream: &[u8]) -> Vec<i16> {
|
||||||
|
|
Loading…
Reference in a new issue