1 unstable release

0.1.0 Jul 7, 2022

#2269 in Encoding

Download history 676/week @ 2024-10-27 1554/week @ 2024-11-03 976/week @ 2024-11-10 1837/week @ 2024-11-17 862/week @ 2024-11-24 827/week @ 2024-12-01 139/week @ 2024-12-08 6631/week @ 2024-12-15 11941/week @ 2024-12-22 760/week @ 2024-12-29 873/week @ 2025-01-05 832/week @ 2025-01-12 940/week @ 2025-01-19 796/week @ 2025-01-26 1015/week @ 2025-02-02 1404/week @ 2025-02-09

4,273 downloads per month
Used in 3 crates (2 directly)

MIT license

52KB
1.5K SLoC

sixel-tokenizer

This is a tokenizer for serialized Sixel images, for more info on the protocol, see: https://vt100.net/docs/vt3xx-gp/chapter14.html

Parser should be given sixel bytes one by one and a callback. The callback is called with a SixelEvent zero or more times per byte when relevant.

Example

use sixel_tokenizer::Parser;

fn main() {
    let sample = "
        \u{1b}Pq
        \"2;1;100;200
        #0;2;0;0;0#1;2;100;100;0#2;2;0;100;0
        #1~~@@vv@@~~@@~~$
        #2??}}GG}}??}}??-
        #1!14@
        \u{1b}\\
    ";
    let sample_bytes = sample.as_bytes();
    let mut events = vec![];
    let mut parser = Parser::new();
    for byte in sample_bytes {
        parser.advance(&byte, |sixel_event| events.push(sixel_event));
    }
    let mut snapshot = String::new();
    for event in events {
        snapshot.push_str(&format!("{:?}", event));
        snapshot.push('\n');
    }
    println!("{}", snapshot);
}

This program will print:

Dcs { macro_parameter: None, transparent_background: None, horizontal_pixel_distance: None }
RasterAttribute { pan: 2, pad: 1, ph: Some(100), pv: Some(200) }
ColorIntroducer { color_number: 0, color_coordinate_system: Some(RGB(0, 0, 0)) }
ColorIntroducer { color_number: 1, color_coordinate_system: Some(RGB(100, 100, 0)) }
ColorIntroducer { color_number: 2, color_coordinate_system: Some(RGB(0, 100, 0)) }
ColorIntroducer { color_number: 1, color_coordinate_system: None }
Data { byte: 126 }
...
GotoNextLine
ColorIntroducer { color_number: 1, color_coordinate_system: None }
Repeat { repeat_count: 14, byte_to_repeat: 64 }
End

License

MIT

Dependencies

~270–710KB
~16K SLoC