#sixel #byte #data #interface #querying #serializing-deserializing #serialization

sixel-image

An interface for querying, manipulating and serializing/deserializing Sixel data

1 unstable release

0.1.0 Jul 7, 2022

#2420 in Encoding

Download history 785/week @ 2024-07-20 759/week @ 2024-07-27 693/week @ 2024-08-03 742/week @ 2024-08-10 674/week @ 2024-08-17 780/week @ 2024-08-24 762/week @ 2024-08-31 657/week @ 2024-09-07 782/week @ 2024-09-14 895/week @ 2024-09-21 839/week @ 2024-09-28 809/week @ 2024-10-05 796/week @ 2024-10-12 771/week @ 2024-10-19 692/week @ 2024-10-26 1433/week @ 2024-11-02

3,814 downloads per month
Used in 2 crates (via zellij-server)

MIT license

31KB
718 lines

sixel-image

This library provides an interface for querying, manipulating and serializing/deserializing sixel data.

There are several methods provided here to do this:

  1. If you already have all the serialized sixel bytes, construct SixelImage directly
  2. If you'd like to parse bytes in real time "on the wire", use SixelDeserializer (accompanied by the sixel-tokenizer sister crate).

Example

With all the serialized bytes ahead of time (option 1)

use sixel_image::SixelImage;

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 bytes = sample.as_bytes();

    let sixel_image = SixelImage::new(&bytes).unwrap();
    let serialized = sixel_image.serialize();
    println!("{:?}", serialized);
}

Parsing bytes "on the wire" (option 2)

use sixel_tokenizer::Parser;
use sixel_image::SixelDeserializer;

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 bytes = sample.as_bytes();
    let mut parser = Parser::new();
    let mut sixel_deserializer = SixelDeserializer::new();
    for byte in bytes {
        parser.advance(&byte, |sixel_event| {
            let _ = sixel_deserializer.handle_event(sixel_event);
        });
    }
    let sixel_image = sixel_deserializer.create_image().unwrap();
    let serialized = sixel_image.serialize();
    println!("{:?}", serialized);
}

License

MIT

Dependencies

~0.4–0.8MB
~19K SLoC