diff --git a/src/arg_handler.rs b/src/arg_handler.rs index 1ea0f72..e94a8af 100644 --- a/src/arg_handler.rs +++ b/src/arg_handler.rs @@ -129,7 +129,7 @@ impl<'a: 'b, 'b> ArgHandler<'a> { /// Get the image size. /// Use the given default value if not set. - pub fn size(&self, def: Option<(u32, u32)>) -> (u32, u32) { + pub fn size(&self, def: Option<(u16, u16)>) -> (u16, u16) { ( self.matches .value_of("width") @@ -143,15 +143,15 @@ impl<'a: 'b, 'b> ArgHandler<'a> { } /// Get the image offset. - pub fn offset(&self) -> (u32, u32) { + pub fn offset(&self) -> (u16, u16) { ( self.matches .value_of("x") - .map(|x| x.parse::().expect("Invalid X offset")) + .map(|x| x.parse::().expect("Invalid X offset")) .unwrap_or(0), self.matches .value_of("y") - .map(|y| y.parse::().expect("Invalid Y offset")) + .map(|y| y.parse::().expect("Invalid Y offset")) .unwrap_or(0), ) } diff --git a/src/image_manager.rs b/src/image_manager.rs index feb28a9..20bd46c 100644 --- a/src/image_manager.rs +++ b/src/image_manager.rs @@ -28,7 +28,7 @@ impl ImageManager { } /// Instantiate the image manager, and load the images from the given paths. - pub fn load(paths: &[&str], size: (u32, u32)) -> ImageManager { + pub fn load(paths: &[&str], size: (u16, u16)) -> ImageManager { // Show a status message println!("Load and process {} image(s)...", paths.len()); @@ -84,7 +84,7 @@ impl ImageManager { } /// Load the image at the given path, and size it correctly -fn load_image(path: &str, size: (u32, u32)) -> DynamicImage { +fn load_image(path: &str, size: (u16, u16)) -> DynamicImage { // Create a path instance let path = Path::new(&path); @@ -97,5 +97,5 @@ fn load_image(path: &str, size: (u32, u32)) -> DynamicImage { let image = image::open(&path).unwrap(); // Resize the image to fit the screen - image.resize_exact(size.0, size.1, FilterType::Gaussian) + image.resize_exact(size.0 as u32, size.1 as u32, FilterType::Gaussian) } diff --git a/src/main.rs b/src/main.rs index 5a2d972..473a5e5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,7 +55,7 @@ fn start<'a>(arg_handler: &ArgHandler<'a>) { } /// Gather important facts about the host. -fn gather_host_facts(arg_handler: &ArgHandler) -> Result<(u32, u32), Error> { +fn gather_host_facts(arg_handler: &ArgHandler) -> Result<(u16, u16), Error> { // Set up a client, and get the screen size let size = Client::connect(arg_handler.host().to_string(), false)?.read_screen_size()?; diff --git a/src/painter/handle.rs b/src/painter/handle.rs index 6568ab2..1ebdbc2 100644 --- a/src/painter/handle.rs +++ b/src/painter/handle.rs @@ -31,7 +31,12 @@ impl Handle { /// Push an image update. pub fn update_image(&self, full_image: &mut DynamicImage) { // Crop the image to the area - let image = full_image.crop(self.area.x, self.area.y, self.area.w, self.area.h); + let image = full_image.crop( + self.area.x as u32, + self.area.y as u32, + self.area.w as u32, + self.area.h as u32, + ); // Push a new image to the thread // TODO: return this result diff --git a/src/painter/painter.rs b/src/painter/painter.rs index ea1f1b8..c337d13 100644 --- a/src/painter/painter.rs +++ b/src/painter/painter.rs @@ -11,7 +11,7 @@ use rect::Rect; pub struct Painter { client: Option, area: Rect, - offset: (u32, u32), + offset: (u16, u16), image: Option, } @@ -20,7 +20,7 @@ impl Painter { pub fn new( client: Option, area: Rect, - offset: (u32, u32), + offset: (u16, u16), image: Option, ) -> Painter { Painter { @@ -62,7 +62,7 @@ impl Painter { } // Get the pixel at this location - let pixel = image.get_pixel(x, y); + let pixel = image.get_pixel(x as u32, y as u32); // Get the channels let channels = pixel.channels(); diff --git a/src/pix/canvas.rs b/src/pix/canvas.rs index 984e8e0..ca66fd4 100644 --- a/src/pix/canvas.rs +++ b/src/pix/canvas.rs @@ -15,8 +15,8 @@ pub struct Canvas { host: String, painter_count: usize, painter_handles: Vec, - size: (u32, u32), - offset: (u32, u32), + size: (u16, u16), + offset: (u16, u16), } impl Canvas { @@ -24,8 +24,8 @@ impl Canvas { pub fn new( host: &str, painter_count: usize, - size: (u32, u32), - offset: (u32, u32), + size: (u16, u16), + offset: (u16, u16), binary: bool, ) -> Canvas { // Initialize the object @@ -52,10 +52,10 @@ impl Canvas { // Spawn some painters for i in 0..self.painter_count { // Determine the slice width - let width = self.size.0 / (self.painter_count as u32); + let width = self.size.0 / (self.painter_count as u16); // Define the area to paint per thread - let painter_area = Rect::from((i as u32) * width, 0, width, self.size.1); + let painter_area = Rect::from((i as u16) * width, 0, width, self.size.1); // Spawn the painter self.spawn_painter(painter_area, binary); diff --git a/src/pix/client.rs b/src/pix/client.rs index 80ad752..a0d1bd7 100644 --- a/src/pix/client.rs +++ b/src/pix/client.rs @@ -48,7 +48,7 @@ impl Client { } /// Write a pixel to the given stream. - pub fn write_pixel(&mut self, x: u32, y: u32, color: Color) -> Result<(), Error> { + pub fn write_pixel(&mut self, x: u16, y: u16, color: Color) -> Result<(), Error> { if self.binary { self.write_command( &[ @@ -74,7 +74,7 @@ impl Client { } /// Read the size of the screen. - pub fn read_screen_size(&mut self) -> Result<(u32, u32), Error> { + pub fn read_screen_size(&mut self) -> Result<(u16, u16), Error> { // Read the screen size let data = self .write_read_command(b"SIZE") @@ -87,10 +87,10 @@ impl Client { match re.captures(&data) { Some(matches) => Ok(( matches[1] - .parse::() + .parse::() .expect("Failed to parse screen width, received malformed data"), matches[2] - .parse::() + .parse::() .expect("Failed to parse screen height, received malformed data"), )), None => Err(Error::new( diff --git a/src/rect.rs b/src/rect.rs index baadf2c..d75ffab 100644 --- a/src/rect.rs +++ b/src/rect.rs @@ -2,14 +2,14 @@ #[derive(Copy, Clone)] pub struct Rect { // TODO: Make these properties private - pub x: u32, - pub y: u32, - pub w: u32, - pub h: u32, + pub x: u16, + pub y: u16, + pub w: u16, + pub h: u16, } impl Rect { - pub fn from(x: u32, y: u32, w: u32, h: u32) -> Rect { + pub fn from(x: u16, y: u16, w: u16, h: u16) -> Rect { Rect { x, y, w, h } } }