Skip to content

Commit a31c32e

Browse files
committed
File Format v3
1 parent 6e408a4 commit a31c32e

1 file changed

Lines changed: 31 additions & 29 deletions

File tree

src/main.rs

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,20 @@ impl Line {
3939
struct Point {
4040
x: f32,
4141
y: f32,
42+
speed: f32,
43+
direction: f32,
44+
width: f32,
4245
pressure: f32,
43-
rot_x: f32,
44-
rot_y: f32,
4546
}
4647
impl Point {
47-
fn new(f: (f32, f32, f32, f32, f32)) -> Point {
48+
fn new(f: (f32, f32, f32, f32, f32, f32)) -> Point {
4849
Point{
4950
x: f.0,
5051
y: f.1,
51-
pressure: f.2,
52-
rot_x: f.3,
53-
rot_y: f.4,
52+
speed: f.2,
53+
direction: f.3,
54+
width: f.4,
55+
pressure: f.5,
5456
}
5557
}
5658
}
@@ -95,21 +97,24 @@ fn parse_line_header(four_bytes: & mut std::slice::Chunks<u8>) -> Option<(i32, i
9597
None
9698
}
9799

98-
fn parse_point_header(four_bytes: & mut std::slice::Chunks<u8>) -> Option<(f32, f32, f32, f32, f32)> {
100+
fn parse_point_header(four_bytes: & mut std::slice::Chunks<u8>) -> Option<(f32, f32, f32, f32, f32, f32)> {
99101
// let mut four_bytes = chunk.clone();
100102
if let Some(x) = four_bytes.next() {
101103
if let Some(y) = four_bytes.next() {
102-
if let Some(pressure) = four_bytes.next() {
103-
if let Some(rot_x) = four_bytes.next() {
104-
if let Some(rot_y) = four_bytes.next() {
105-
// TODO verify range of values
106-
return Some((
107-
read_number_f32(x),
108-
read_number_f32(y),
109-
read_number_f32(pressure),
110-
read_number_f32(rot_x),
111-
read_number_f32(rot_y)
112-
));
104+
if let Some(speed) = four_bytes.next() {
105+
if let Some(direction) = four_bytes.next() {
106+
if let Some(width) = four_bytes.next() {
107+
if let Some(pressure) = four_bytes.next() {
108+
// TODO verify range of values
109+
return Some((
110+
read_number_f32(x),
111+
read_number_f32(y),
112+
read_number_f32(speed),
113+
read_number_f32(direction),
114+
read_number_f32(width),
115+
read_number_f32(pressure),
116+
));
117+
}
113118
}
114119
}
115120
}
@@ -179,27 +184,24 @@ fn read_pages(four_bytes: & mut std::slice::Chunks<u8>, _max_size_file: usize) -
179184
let mut pages = Vec::<Page>::default();
180185
// let mut four_bytes = chunk.clone();
181186

182-
if let Some(num_pages) = four_bytes.next() {
183-
for _p in 0..read_number_i32(num_pages) {
184-
println!("p: {} / {}", _p, read_number_i32(num_pages));
185-
let new_page = Page{
186-
layers: read_layers(four_bytes, _max_size_file)};
187-
pages.push(new_page);
188-
}
189-
}
187+
let num_pages = 1;
188+
println!("p: 0 / {}", num_pages);
189+
let new_page = Page{
190+
layers: read_layers(four_bytes, _max_size_file)};
191+
pages.push(new_page);
190192
pages
191193
}
192194

193195

194196
fn main() {
195197
let max_size_file = 1024 * 1024; // Bytes
196-
let line_file = include_bytes!("../aa90b0e7-5c1a-42fe-930f-dad9cf3363cc.lines");
198+
let line_file = include_bytes!("../aa90b0e7-5c1a-42fe-930f-dad9cf3363cc/0.rm");
197199
assert!(max_size_file >= line_file.len());
198200

199201
// print!("{}", String::from_utf8_lossy(line_file));
200202

201-
let header = line_file.iter().take(43).cloned().collect::<Vec<u8>>();
202-
assert_eq!(header, "reMarkable lines with selections and layers".as_bytes());
203+
let header = line_file.iter().take(33).cloned().collect::<Vec<u8>>();
204+
assert_eq!(header, "reMarkable .lines file, version=3".as_bytes());
203205

204206
let mut numbers = line_file[43..].chunks(4);
205207
// as std::slice::Windows<[u8;4]>;

0 commit comments

Comments
 (0)