tinyvg_rs/
lib.rs

1pub mod header;
2pub mod common;
3pub mod color_table;
4pub mod commands;
5
6use crate::color_table::{parse_color_table, ColorTable};
7use crate::commands::{parse_draw_commands, DrawCommand};
8use crate::header::{CoordinateRange, TinyVgHeader};
9use std::io::{Cursor};
10
11#[derive(Debug, PartialEq)]
12pub enum TinyVgParseError {
13    None,
14    InvalidHeader,
15    InvalidColorTable,
16    InvalidCommand,
17}
18
19#[derive(Debug)]
20pub struct TinyVg {
21    pub header: TinyVgHeader,
22    pub color_table: ColorTable,
23    pub draw_commands: Vec<DrawCommand>
24}
25
26impl TinyVg {
27
28    pub fn from_bytes(data: &[u8]) -> Result<TinyVg, TinyVgParseError> {
29        let mut cursor = Cursor::new(data);
30
31        let header = TinyVgHeader::parse(&mut cursor)?;
32        let color_table = parse_color_table(&mut cursor, &header)?;
33        let draw_commands: Vec<DrawCommand> = parse_draw_commands(&mut cursor, &header)?;
34
35        Ok(TinyVg {
36            header,
37            color_table,
38            draw_commands,
39        })
40    }
41}