switch size data types to u16
The binary protocol is limited to using u16's so limit everything to that.
This commit is contained in:
@@ -129,7 +129,7 @@ impl<'a: 'b, 'b> ArgHandler<'a> {
|
|||||||
|
|
||||||
/// Get the image size.
|
/// Get the image size.
|
||||||
/// Use the given default value if not set.
|
/// 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
|
self.matches
|
||||||
.value_of("width")
|
.value_of("width")
|
||||||
@@ -143,15 +143,15 @@ impl<'a: 'b, 'b> ArgHandler<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the image offset.
|
/// Get the image offset.
|
||||||
pub fn offset(&self) -> (u32, u32) {
|
pub fn offset(&self) -> (u16, u16) {
|
||||||
(
|
(
|
||||||
self.matches
|
self.matches
|
||||||
.value_of("x")
|
.value_of("x")
|
||||||
.map(|x| x.parse::<u32>().expect("Invalid X offset"))
|
.map(|x| x.parse::<u16>().expect("Invalid X offset"))
|
||||||
.unwrap_or(0),
|
.unwrap_or(0),
|
||||||
self.matches
|
self.matches
|
||||||
.value_of("y")
|
.value_of("y")
|
||||||
.map(|y| y.parse::<u32>().expect("Invalid Y offset"))
|
.map(|y| y.parse::<u16>().expect("Invalid Y offset"))
|
||||||
.unwrap_or(0),
|
.unwrap_or(0),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ impl ImageManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Instantiate the image manager, and load the images from the given paths.
|
/// 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
|
// Show a status message
|
||||||
println!("Load and process {} image(s)...", paths.len());
|
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
|
/// 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
|
// Create a path instance
|
||||||
let path = Path::new(&path);
|
let path = Path::new(&path);
|
||||||
|
|
||||||
@@ -97,5 +97,5 @@ fn load_image(path: &str, size: (u32, u32)) -> DynamicImage {
|
|||||||
let image = image::open(&path).unwrap();
|
let image = image::open(&path).unwrap();
|
||||||
|
|
||||||
// Resize the image to fit the screen
|
// 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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ fn start<'a>(arg_handler: &ArgHandler<'a>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gather important facts about the host.
|
/// 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
|
// Set up a client, and get the screen size
|
||||||
let size = Client::connect(arg_handler.host().to_string(), false)?.read_screen_size()?;
|
let size = Client::connect(arg_handler.host().to_string(), false)?.read_screen_size()?;
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,12 @@ impl Handle {
|
|||||||
/// Push an image update.
|
/// Push an image update.
|
||||||
pub fn update_image(&self, full_image: &mut DynamicImage) {
|
pub fn update_image(&self, full_image: &mut DynamicImage) {
|
||||||
// Crop the image to the area
|
// 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
|
// Push a new image to the thread
|
||||||
// TODO: return this result
|
// TODO: return this result
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use rect::Rect;
|
|||||||
pub struct Painter {
|
pub struct Painter {
|
||||||
client: Option<Client>,
|
client: Option<Client>,
|
||||||
area: Rect,
|
area: Rect,
|
||||||
offset: (u32, u32),
|
offset: (u16, u16),
|
||||||
image: Option<DynamicImage>,
|
image: Option<DynamicImage>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ impl Painter {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
client: Option<Client>,
|
client: Option<Client>,
|
||||||
area: Rect,
|
area: Rect,
|
||||||
offset: (u32, u32),
|
offset: (u16, u16),
|
||||||
image: Option<DynamicImage>,
|
image: Option<DynamicImage>,
|
||||||
) -> Painter {
|
) -> Painter {
|
||||||
Painter {
|
Painter {
|
||||||
@@ -62,7 +62,7 @@ impl Painter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the pixel at this location
|
// 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
|
// Get the channels
|
||||||
let channels = pixel.channels();
|
let channels = pixel.channels();
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ pub struct Canvas {
|
|||||||
host: String,
|
host: String,
|
||||||
painter_count: usize,
|
painter_count: usize,
|
||||||
painter_handles: Vec<Handle>,
|
painter_handles: Vec<Handle>,
|
||||||
size: (u32, u32),
|
size: (u16, u16),
|
||||||
offset: (u32, u32),
|
offset: (u16, u16),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Canvas {
|
impl Canvas {
|
||||||
@@ -24,8 +24,8 @@ impl Canvas {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
host: &str,
|
host: &str,
|
||||||
painter_count: usize,
|
painter_count: usize,
|
||||||
size: (u32, u32),
|
size: (u16, u16),
|
||||||
offset: (u32, u32),
|
offset: (u16, u16),
|
||||||
binary: bool,
|
binary: bool,
|
||||||
) -> Canvas {
|
) -> Canvas {
|
||||||
// Initialize the object
|
// Initialize the object
|
||||||
@@ -52,10 +52,10 @@ impl Canvas {
|
|||||||
// Spawn some painters
|
// Spawn some painters
|
||||||
for i in 0..self.painter_count {
|
for i in 0..self.painter_count {
|
||||||
// Determine the slice width
|
// 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
|
// 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
|
// Spawn the painter
|
||||||
self.spawn_painter(painter_area, binary);
|
self.spawn_painter(painter_area, binary);
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ impl Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Write a pixel to the given stream.
|
/// 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 {
|
if self.binary {
|
||||||
self.write_command(
|
self.write_command(
|
||||||
&[
|
&[
|
||||||
@@ -74,7 +74,7 @@ impl Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Read the size of the screen.
|
/// 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
|
// Read the screen size
|
||||||
let data = self
|
let data = self
|
||||||
.write_read_command(b"SIZE")
|
.write_read_command(b"SIZE")
|
||||||
@@ -87,10 +87,10 @@ impl Client {
|
|||||||
match re.captures(&data) {
|
match re.captures(&data) {
|
||||||
Some(matches) => Ok((
|
Some(matches) => Ok((
|
||||||
matches[1]
|
matches[1]
|
||||||
.parse::<u32>()
|
.parse::<u16>()
|
||||||
.expect("Failed to parse screen width, received malformed data"),
|
.expect("Failed to parse screen width, received malformed data"),
|
||||||
matches[2]
|
matches[2]
|
||||||
.parse::<u32>()
|
.parse::<u16>()
|
||||||
.expect("Failed to parse screen height, received malformed data"),
|
.expect("Failed to parse screen height, received malformed data"),
|
||||||
)),
|
)),
|
||||||
None => Err(Error::new(
|
None => Err(Error::new(
|
||||||
|
|||||||
10
src/rect.rs
10
src/rect.rs
@@ -2,14 +2,14 @@
|
|||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct Rect {
|
pub struct Rect {
|
||||||
// TODO: Make these properties private
|
// TODO: Make these properties private
|
||||||
pub x: u32,
|
pub x: u16,
|
||||||
pub y: u32,
|
pub y: u16,
|
||||||
pub w: u32,
|
pub w: u16,
|
||||||
pub h: u32,
|
pub h: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Rect {
|
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 }
|
Rect { x, y, w, h }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user