Skip to content

Commit 0774c0e

Browse files
committed
Standardize on 'virtual' normalized screen/input coordinate name
1 parent d1b13ed commit 0774c0e

4 files changed

Lines changed: 30 additions & 57 deletions

File tree

src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ use ghostwriter::{
2323
};
2424

2525
// Output dimensions remain the same for both devices
26-
const REMARKABLE_WIDTH: u32 = 768;
27-
const REMARKABLE_HEIGHT: u32 = 1024;
26+
const VIRTUAL_WIDTH: u32 = 768;
27+
const VIRTUAL_HEIGHT: u32 = 1024;
2828

2929
#[derive(Embed)]
3030
#[folder = "prompts/"]
@@ -191,7 +191,7 @@ fn draw_svg(
191191
) -> Result<()> {
192192
info!("Drawing SVG to the screen.");
193193
keyboard.progress_end()?;
194-
let bitmap = svg_to_bitmap(svg_data, REMARKABLE_WIDTH, REMARKABLE_HEIGHT)?;
194+
let bitmap = svg_to_bitmap(svg_data, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)?;
195195
if let Some(save_bitmap) = save_bitmap {
196196
write_bitmap_to_file(&bitmap, save_bitmap)?;
197197
}

src/pen.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use std::time::Duration;
77
use crate::device::DeviceModel;
88

99
// Output dimensions remain the same for both devices
10-
const REMARKABLE_WIDTH: u32 = 768;
11-
const REMARKABLE_HEIGHT: u32 = 1024;
10+
const VIRTUAL_WIDTH: u32 = 768;
11+
const VIRTUAL_HEIGHT: u32 = 1024;
1212

1313
pub struct Pen {
1414
device: Option<Device>,
@@ -181,8 +181,8 @@ impl Pen {
181181

182182
fn screen_to_input(&self, (x, y): (i32, i32)) -> (i32, i32) {
183183
// Swap and normalize the coordinates
184-
let x_normalized = x as f32 / REMARKABLE_WIDTH as f32;
185-
let y_normalized = y as f32 / REMARKABLE_HEIGHT as f32;
184+
let x_normalized = x as f32 / VIRTUAL_WIDTH as f32;
185+
let y_normalized = y as f32 / VIRTUAL_HEIGHT as f32;
186186

187187
match self.device_model {
188188
DeviceModel::RemarkablePaperPro => {

src/screenshot.rs

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use image::ImageEncoder;
1111

1212
use crate::device::DeviceModel;
1313

14-
const OUTPUT_WIDTH: u32 = 768;
15-
const OUTPUT_HEIGHT: u32 = 1024;
14+
const VIRTUAL_WIDTH: u32 = 768;
15+
const VIRTUAL_HEIGHT: u32 = 1024;
1616

1717
pub struct Screenshot {
1818
data: Vec<u8>,
@@ -196,12 +196,12 @@ impl Screenshot {
196196
debug!("Encoding raw image data to PNG");
197197
let png_data = self.encode_png(&data)?;
198198

199-
// Resize the PNG to OUTPUT_WIDTH x OUTPUT_HEIGHT
200-
debug!("Resizing image to {}x{}", OUTPUT_WIDTH, OUTPUT_HEIGHT);
199+
// Resize the PNG to VIRTUAL_WIDTH x VIRTUAL_HEIGHT
200+
debug!("Resizing image to {}x{}", VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
201201
let img = image::load_from_memory(&png_data)?;
202202
let resized_img = img.resize_exact(
203-
OUTPUT_WIDTH,
204-
OUTPUT_HEIGHT,
203+
VIRTUAL_WIDTH,
204+
VIRTUAL_HEIGHT,
205205
image::imageops::FilterType::Nearest,
206206
);
207207

@@ -215,18 +215,16 @@ impl Screenshot {
215215
DeviceModel::RemarkablePaperPro => {
216216
encoder.write_image(
217217
resized_img.as_rgba8().unwrap().as_raw(),
218-
OUTPUT_WIDTH,
219-
OUTPUT_HEIGHT,
218+
VIRTUAL_WIDTH,
219+
VIRTUAL_HEIGHT,
220220
image::ExtendedColorType::Rgba8,
221221
)?;
222-
// left: 3145728
223-
// right: 3130368
224222
}
225223
_ => {
226224
encoder.write_image(
227225
resized_img.as_luma8().unwrap().as_raw(),
228-
OUTPUT_WIDTH,
229-
OUTPUT_HEIGHT,
226+
VIRTUAL_WIDTH,
227+
VIRTUAL_HEIGHT,
230228
image::ExtendedColorType::L8,
231229
)?;
232230
}
@@ -279,35 +277,10 @@ impl Screenshot {
279277
fn encode_png_rmpp(&self, raw_data: &[u8]) -> Result<Vec<u8>> {
280278
let width = self.screen_width();
281279
let height = self.screen_height();
282-
283-
// // Extract grayscale from RGBA data (using average of RGB)
284-
// let mut processed = vec![0u8; (width * height) as usize];
285-
//
286-
// for y in 0..height {
287-
// for x in 0..width {
288-
// let pixel_idx = ((y * width + x) * 4) as usize;
289-
//
290-
// // Get RGB values (skip alpha)
291-
// let r = raw_data[pixel_idx] as u16;
292-
// let g = raw_data[pixel_idx + 1] as u16;
293-
// let b = raw_data[pixel_idx + 2] as u16;
294-
//
295-
// // Convert to grayscale using average
296-
// // let gray = ((r + g + b) / 3) as u8;
297-
//
298-
// // Apply curves and store
299-
// processed[(y * width + x) as usize] = Self::apply_curves(gray);
300-
// }
301-
// }
302-
//
303-
// let img = GrayImage::from_raw(width, height, processed)
304-
// .ok_or_else(|| anyhow::anyhow!("Failed to create image from raw data"))?;
305-
//
306280
let mut png_data = Vec::new();
307281
let encoder = image::codecs::png::PngEncoder::new(&mut png_data);
308282
debug!("Encoding {}x{} image", width, height);
309283
encoder.write_image(raw_data, width, height, image::ExtendedColorType::Rgba8)?;
310-
311284
Ok(png_data)
312285
}
313286

src/touch.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use std::time::Duration;
88
use crate::device::DeviceModel;
99

1010
// Output dimensions remain the same for both devices
11-
const REMARKABLE_WIDTH: u16 = 768;
12-
const REMARKABLE_HEIGHT: u16 = 1024;
11+
const VIRTUAL_WIDTH: u16 = 768;
12+
const VIRTUAL_HEIGHT: u16 = 1024;
1313

1414
// Event codes
1515
const ABS_MT_SLOT: u16 = 47;
@@ -72,7 +72,7 @@ impl Touch {
7272
}
7373
if event.code() == ABS_MT_TRACKING_ID {
7474
if event.value() == -1 {
75-
let (x, y) = self.input_to_screen((position_x, position_y));
75+
let (x, y) = self.input_to_virtual((position_x, position_y));
7676
debug!("Touch release detected at ({}, {}) normalized ({}, {})", position_x, position_y, x, y);
7777
if x > 700 && y < 25 {
7878
debug!("Touch release in target zone!");
@@ -85,7 +85,7 @@ impl Touch {
8585
}
8686

8787
pub fn touch_start(&mut self, xy: (i32, i32)) -> Result<()> {
88-
let (x, y) = self.screen_to_input(xy);
88+
let (x, y) = self.virtual_to_input(xy);
8989
if let Some(device) = &mut self.device {
9090
trace!("touch_start at ({}, {})", x, y);
9191
// sleep(Duration::from_millis(100));
@@ -119,7 +119,7 @@ impl Touch {
119119
}
120120

121121
pub fn goto_xy(&mut self, xy: (i32, i32)) -> Result<()> {
122-
let (x, y) = self.screen_to_input(xy);
122+
let (x, y) = self.virtual_to_input(xy);
123123
if let Some(device) = &mut self.device {
124124
device.send_events(&[
125125
InputEvent::new(EventType::ABSOLUTE, ABS_MT_SLOT, 0),
@@ -157,10 +157,10 @@ impl Touch {
157157
}
158158
}
159159

160-
fn screen_to_input(&self, (x, y): (i32, i32)) -> (i32, i32) {
160+
fn virtual_to_input(&self, (x, y): (i32, i32)) -> (i32, i32) {
161161
// Swap and normalize the coordinates
162-
let x_normalized = x as f32 / REMARKABLE_WIDTH as f32;
163-
let y_normalized = y as f32 / REMARKABLE_HEIGHT as f32;
162+
let x_normalized = x as f32 / VIRTUAL_WIDTH as f32;
163+
let y_normalized = y as f32 / VIRTUAL_HEIGHT as f32;
164164

165165
match self.device_model {
166166
DeviceModel::RemarkablePaperPro => {
@@ -177,21 +177,21 @@ impl Touch {
177177
}
178178
}
179179

180-
fn input_to_screen(&self, (x, y): (i32, i32)) -> (i32, i32) {
180+
fn input_to_virtual(&self, (x, y): (i32, i32)) -> (i32, i32) {
181181
// Swap and normalize the coordinates
182182
let x_normalized = x as f32 / self.screen_width() as f32;
183183
let y_normalized = y as f32 / self.screen_height() as f32;
184184

185185
match self.device_model {
186186
DeviceModel::RemarkablePaperPro => {
187-
let x_input = (x_normalized * REMARKABLE_WIDTH as f32) as i32;
188-
let y_input = (y_normalized * REMARKABLE_HEIGHT as f32) as i32;
187+
let x_input = (x_normalized * VIRTUAL_WIDTH as f32) as i32;
188+
let y_input = (y_normalized * VIRTUAL_HEIGHT as f32) as i32;
189189
(x_input, y_input)
190190
}
191191
_ => {
192192
// RM2 coordinate transformation
193-
let x_input = (x_normalized * REMARKABLE_WIDTH as f32) as i32;
194-
let y_input = ((1.0 - y_normalized) * REMARKABLE_HEIGHT as f32) as i32;
193+
let x_input = (x_normalized * VIRTUAL_WIDTH as f32) as i32;
194+
let y_input = ((1.0 - y_normalized) * VIRTUAL_HEIGHT as f32) as i32;
195195
(x_input, y_input)
196196
}
197197
}

0 commit comments

Comments
 (0)