Skip to content

Commit

Permalink
fix(extracted): unknown image extension
Browse files Browse the repository at this point in the history
  • Loading branch information
francisdb committed May 9, 2024
1 parent 8c4b3ce commit 198de74
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/vpx/expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ fn write_images<P: AsRef<Path>>(vpx: &VPX, expanded_dir: &P) -> Result<(), Write
if let Some(jpeg) = &image.jpeg {
// Only if the actual image dimensions are different from
// the ones in the vpx file we add them to the json.
let dimensions_file = read_image_dimensions_from_file_steam(&file_name, jpeg)?;
let dimensions_file = read_image_dimensions_from_file_steam(&file_name, jpeg);
match dimensions_file {
Some((width_file, height_file)) => {
if image.width != width_file {
Expand Down Expand Up @@ -527,16 +527,17 @@ fn read_image_dimensions(file_path: &PathBuf) -> io::Result<Option<(u32, u32)>>
fn read_image_dimensions_from_file_steam(
file_name: &String,
jpeg: &ImageDataJpeg,
) -> io::Result<Option<(u32, u32)>> {
let format = image::ImageFormat::from_path(file_name).map_err(|e| {
io::Error::new(
io::ErrorKind::InvalidData,
format!("Failed to determine image format for {}: {}", file_name, e),
)
})?;
) -> Option<(u32, u32)> {
let format = match image::ImageFormat::from_path(file_name) {
Ok(format) => Some(format),
Err(e) => {
eprintln!("Failed to determine image format for {}: {}", file_name, e);
None
}
}?;
let cursor = std::io::Cursor::new(&jpeg.data);
let decoder = image::io::Reader::with_format(cursor, format);
let dimensions_file = match decoder.into_dimensions() {
match decoder.into_dimensions() {
Ok(dimensions) => Some(dimensions),
Err(image_error) => {
eprintln!(
Expand All @@ -545,8 +546,7 @@ fn read_image_dimensions_from_file_steam(
);
None
}
};
Ok(dimensions_file)
}
}

struct ImageBmp {
Expand Down

0 comments on commit 198de74

Please sign in to comment.