Skip to content

Commit

Permalink
Merge pull request #322 from CryZe/dont-shrink-gifs
Browse files Browse the repository at this point in the history
Stop shrinking GIFs for now
  • Loading branch information
CryZe authored Apr 11, 2020
2 parents 7d116c4 + 002b7ed commit ff59c3b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ tokio = { version = "0.2", features = ["macros"] }
default = ["image-shrinking", "std"]
doesnt-have-atomics = []
std = ["byteorder", "chrono/std", "chrono/clock", "image", "indexmap", "livesplit-hotkey/std", "palette/std", "parking_lot", "quick-xml", "serde_json", "serde/std", "snafu/std", "utf-8"]
more-image-formats = ["image/webp", "image/pnm", "image/ico", "image/jpeg", "image/gif", "image/tiff", "image/tga", "image/bmp", "image/hdr"]
more-image-formats = ["image/webp", "image/pnm", "image/ico", "image/jpeg", "image/tiff", "image/tga", "image/bmp", "image/hdr"]
image-shrinking = ["std", "bytemuck", "more-image-formats"]
rendering = ["std", "more-image-formats", "euclid", "lyon", "rusttype", "smallvec"]
software-rendering = ["rendering", "euc", "vek", "derive_more/mul"]
Expand Down
10 changes: 7 additions & 3 deletions src/settings/image/shrinking.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloc::borrow::Cow;
use image::{
bmp, gif, guess_format, hdr, ico, jpeg, load_from_memory_with_format, png, pnm, tiff, webp,
bmp, guess_format, hdr, ico, jpeg, load_from_memory_with_format, png, pnm, tiff, webp,
DynamicImage, GenericImageView, ImageDecoder, ImageError, ImageFormat,
};
use std::io::Cursor;
Expand All @@ -12,17 +12,21 @@ fn shrink_inner(data: &[u8], max_dim: u32) -> Result<Cow<'_, [u8]>, ImageError>
let (width, height) = match format {
ImageFormat::Png => png::PngDecoder::new(cursor)?.dimensions(),
ImageFormat::Jpeg => jpeg::JpegDecoder::new(cursor)?.dimensions(),
ImageFormat::Gif => gif::GifDecoder::new(cursor)?.dimensions(),
ImageFormat::WebP => webp::WebPDecoder::new(cursor)?.dimensions(),
ImageFormat::Tiff => tiff::TiffDecoder::new(cursor)?.dimensions(),
ImageFormat::Bmp => bmp::BmpDecoder::new(cursor)?.dimensions(),
ImageFormat::Ico => ico::IcoDecoder::new(cursor)?.dimensions(),
ImageFormat::Hdr => hdr::HDRAdapter::new(cursor)?.dimensions(),
ImageFormat::Pnm => pnm::PnmDecoder::new(cursor)?.dimensions(),
// FIXME: For GIF we would need to properly shrink the whole animation.
// The image crate can't properly handle this at this point in time.
// Some properties are not translated over properly it seems. We could
// shrink GIFs that are a single frame, but we also can't tell how many
// frames there are.
// TGA doesn't have a Header.
// DDS isn't a format we really care for.
// And the image format is non-exhaustive.
ImageFormat::Tga | ImageFormat::Dds | _ => return Ok(data.into()),
ImageFormat::Gif | ImageFormat::Tga | ImageFormat::Dds | _ => return Ok(data.into()),
};

let is_too_large = width > max_dim || height > max_dim;
Expand Down

0 comments on commit ff59c3b

Please sign in to comment.