Skip to content

Commit

Permalink
Stop shrinking GIFs for now
Browse files Browse the repository at this point in the history
Shrinking GIFs to PNGs removes all their animations, so optimally we'd
like to shrink them to GIFs and retain their animation. However it looks
like the image crate is brushing over too many properties of GIFs. This
makes it infeasible to do this without breaking GIFs. We could
eventually look into using the underlying gif crate directly. For now
we'll just not shrink GIFs at all.
  • Loading branch information
CryZe committed Apr 11, 2020
1 parent 7d116c4 commit 002b7ed
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 002b7ed

Please sign in to comment.