summaryrefslogtreecommitdiff
path: root/tvg/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tvg/src/lib.rs')
-rw-r--r--tvg/src/lib.rs33
1 files changed, 32 insertions, 1 deletions
diff --git a/tvg/src/lib.rs b/tvg/src/lib.rs
index 5cbe33c..011b5c7 100644
--- a/tvg/src/lib.rs
+++ b/tvg/src/lib.rs
@@ -11,7 +11,7 @@ mod commands;
mod header;
mod path;
-pub use colors::Rgba16;
+pub use colors::{Rgb565, Rgba16, Rgba8888, RgbaF32};
pub use header::SUPPORTED_VERSION;
pub struct TvgFile<C: Color> {
@@ -21,6 +21,7 @@ pub struct TvgFile<C: Color> {
}
impl<C: Color + std::fmt::Debug> TvgFile<C> {
+ /// Read a TinyVG file.
pub fn read_from(reader: &mut impl Read) -> Result<Self, TvgError> {
let header = TvgHeader::read(reader)?;
let color_table =
@@ -42,6 +43,34 @@ impl<C: Color + std::fmt::Debug> TvgFile<C> {
commands: commands.into_boxed_slice(),
})
}
+
+ /// Read a TinyVG file. If a Custom color encoding if found, use the specified encoding.
+ pub fn read_with_custom_encoding<Custom: Color>(
+ reader: &mut impl Read,
+ ) -> Result<Self, TvgError> {
+ let header = TvgHeader::read(reader)?;
+ let color_table = ColorTable::read_from_encoding_with_custom::<Custom>(
+ reader,
+ header.color_count(),
+ header.color_encoding(),
+ )?;
+
+ let mut commands = Vec::new();
+ loop {
+ let command = Command::read(reader, &header)?;
+ commands.push(command.clone());
+
+ if command.is_end_of_document() {
+ break;
+ }
+ }
+
+ Ok(Self {
+ header,
+ color_table,
+ commands: commands.into_boxed_slice(),
+ })
+ }
}
#[derive(Debug, Error)]
@@ -52,6 +81,8 @@ pub enum TvgError {
UnsupportedVersion(u8),
#[error("Found a coordinate range with an index of 3, which is invalid")]
InvalidCoordinateRange,
+ #[error("Found a Custom color encoding, which is unsupported")]
+ UnsupportedColorEncoding,
#[error("Found a command with an index of {}, which is invalid", .0)]
InvalidCommand(u8),
#[error("Found a style kind with an index of 3, which is invalid")]