Skip to content

Commit

Permalink
Merge pull request image-rs#363 from andersk/io-error
Browse files Browse the repository at this point in the history
Update for stabilized io::Error
  • Loading branch information
ruuda committed Apr 2, 2015
2 parents c3b7a38 + 2ede7ab commit d7dff70
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 30 deletions.
6 changes: 1 addition & 5 deletions src/dynimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,7 @@ pub fn save_buffer<P>(path: P, buf: &[u8], width: u32, height: u32, color: color
"ppm" => ppm::PPMEncoder::new(fout).encode(buf, width, height, color),
format => Err(io::Error::new(
io::ErrorKind::InvalidInput,
"Unsupported image format.",
Some(format!(
"Image format image/{:?} is not supported.",
format
))
&format!("Unsupported image format image/{:?}", format)[..],
))
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/gif/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ where Container: Deref<Target=[u8]> + DerefMut {
height > <u16 as Int>::max_value() as u32 {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"Image dimensions are to large for the gif format.",
None
"Image dimensions are too large for the gif format.",
))
}
try!(w.write_u16::<LittleEndian>(width as u16));
Expand Down Expand Up @@ -331,8 +330,7 @@ where Container: Deref<Target=[u8]> + DerefMut {
if n < 64 {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"Unsupported number of colors.",
Some(format!("{} colors < 64 colors", n))
&format!("Unsupported number of colors: {} < 64", n)[..],
))
}
let nq = nq::NeuQuant::new(3, 256, &self.image);
Expand Down
11 changes: 5 additions & 6 deletions src/image.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::error::FromError;
use std::fmt;
use std::mem;
use std::io;
Expand All @@ -15,7 +14,7 @@ use animation::{Frame, Frames};
use dynimage::decoder_to_image;

/// An enumeration of Image Errors
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Debug)]
pub enum ImageError {
/// The Image is not formatted properly
FormatError(String),
Expand Down Expand Up @@ -58,14 +57,14 @@ impl fmt::Display for ImageError {
}
}

impl FromError<io::Error> for ImageError {
fn from_error(err: io::Error) -> ImageError {
impl From<io::Error> for ImageError {
fn from(err: io::Error) -> ImageError {
ImageError::IoError(err)
}
}

impl FromError<byteorder::Error> for ImageError {
fn from_error(err: byteorder::Error) -> ImageError {
impl From<byteorder::Error> for ImageError {
fn from(err: byteorder::Error) -> ImageError {
match err {
byteorder::Error::UnexpectedEOF => ImageError::ImageEnd,
byteorder::Error::Io(err) => ImageError::IoError(err),
Expand Down
6 changes: 1 addition & 5 deletions src/jpeg/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,7 @@ impl<'a, W: Write> JPEGEncoder<'a, W> {
color::ColorType::GrayA(8) => try!(self.encode_gray(image, width as usize, height as usize, 2)),
_ => return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"Unsupported color type. Use 8 bit per channel RGB(A) or Gray(A) instead.",
Some(format!(
"Color type {:?} is not suppored by this JPEG encoder.",
c
))
&format!("Unsupported color type {:?}. Use 8 bit per channel RGB(A) or Gray(A) instead.", c)[..],
))
};

Expand Down
4 changes: 1 addition & 3 deletions src/utils/bitstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ impl<R> BitReader for LsbReader<R> where R: Read {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"Cannot read more than 16 bits",
None
))
}
while self.bits < n {
Expand All @@ -104,7 +103,6 @@ impl<R> BitReader for MsbReader<R> where R: Read {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"Cannot read more than 16 bits",
None
))
}
while self.bits < n {
Expand Down Expand Up @@ -228,6 +226,6 @@ mod test {
let _ = writer.write_bits(datum, 10);
}
}
assert_eq!(&data, &compressed_data)
assert_eq!(&compressed_data, &data)
}
}
9 changes: 2 additions & 7 deletions src/utils/lzw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ impl DecodingDict {
}
None => return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"invalid code occured",
Some(format!("{} < {} expected", k, self.table.len()))
&format!("invalid code occured: {} < {} expected", k, self.table.len())[..],
))
}
self.buffer.push(cha);
Expand Down Expand Up @@ -138,11 +137,7 @@ where R: BitReader, W: Write {
} else {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"Invalid code",
Some(format!("expected {} <= {}",
code,
next_code)
)
&format!("Invalid code: expected {} <= {}", code, next_code)[..],
))
};
try!(w.write(data));
Expand Down

0 comments on commit d7dff70

Please sign in to comment.