File: README.md

package info (click to toggle)
rust-sixel-image 0.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 136 kB
  • sloc: makefile: 4
file content (64 lines) | stat: -rw-r--r-- 1,712 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 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`](https://github.com/zellij-org/sixel-tokenizer) sister crate).

# Example

## With all the serialized bytes ahead of time (option 1)
```rust
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)
```rust
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