Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust: ["1.62.0", stable, beta, nightly]
rust: ["1.85.0", stable, beta, nightly]
features: ["", "std", "color_quant"]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
override: true
components: clippy
- name: build
run: >
Expand All @@ -28,22 +27,16 @@ jobs:
- name: test
run: >
cargo test --tests --benches --no-default-features --features "$FEATURES"
if: ${{ matrix.rust != '1.62.0' }}
if: ${{ matrix.rust != '1.85.0' }}
env:
FEATURES: ${{ matrix.features }}
rustfmt:
runs-on: ubuntu-latest
continue-on-error: false
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
override: true
components: rustfmt
- name: Run rustfmt check
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check

run: cargo fmt -- --check
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ readme = "README.md"
homepage = "https://github.com/image-rs/image-gif"
repository = "https://github.com/image-rs/image-gif"
documentation = "https://docs.rs/gif"
edition = "2021"
edition = "2024"
Comment thread
lilith marked this conversation as resolved.
resolver = "2"
include = ["src/**", "LICENSE-*", "README.md", "benches/*.rs"]
rust-version = "1.62"
rust-version = "1.85"

[lib]
bench = false
Expand Down
2 changes: 1 addition & 1 deletion benches/decode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{measurement::Measurement, BenchmarkGroup, BenchmarkId, Criterion, Throughput};
use criterion::{BenchmarkGroup, BenchmarkId, Criterion, Throughput, measurement::Measurement};
use gif::Decoder;
use std::hint::black_box;

Expand Down
2 changes: 0 additions & 2 deletions clippy.toml

This file was deleted.

2 changes: 1 addition & 1 deletion examples/parallel.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Reencodes GIF in parallel

use gif::streaming_decoder::FrameDecoder;
use gif::DecodeOptions;
use gif::streaming_decoder::FrameDecoder;
use rayon::iter::ParallelBridge;
use rayon::iter::ParallelIterator;
use std::env;
Expand Down
20 changes: 16 additions & 4 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ impl Frame<'static> {
#[cfg(feature = "color_quant")]
#[track_caller]
pub fn from_rgba_speed(width: u16, height: u16, pixels: &mut [u8], speed: i32) -> Self {
assert_eq!(width as usize * height as usize * 4, pixels.len(), "Too much or too little pixel data for the given width and height to create a GIF Frame");
assert_eq!(
width as usize * height as usize * 4,
pixels.len(),
"Too much or too little pixel data for the given width and height to create a GIF Frame"
);
assert!(
speed >= 1 && speed <= 30,
"speed needs to be in the range [1, 30]"
Expand Down Expand Up @@ -296,7 +300,11 @@ impl Frame<'static> {
/// # Panics:
/// * If the length of pixels does not equal `width * height * 2`.
pub fn from_grayscale_with_alpha(width: u16, height: u16, pixels: &[u8]) -> Self {
assert_eq!(width as usize * height as usize * 2, pixels.len(), "Too much or too little pixel data for the given width and height to create a GIF Frame");
assert_eq!(
width as usize * height as usize * 2,
pixels.len(),
"Too much or too little pixel data for the given width and height to create a GIF Frame"
);

// Input is in LumaA format.
// Count the occurrences of all the colors, then pick the least common color as alpha.
Expand Down Expand Up @@ -333,7 +341,7 @@ impl Frame<'static> {
let least_used_color = color_frequencies
.iter()
.enumerate()
.min_by_key(|(_, &value)| value)
.min_by_key(|&(_, &value)| value)
.map(|(index, _)| index as u8)
.expect("input slice is empty");

Expand Down Expand Up @@ -474,7 +482,11 @@ impl Frame<'static> {
#[must_use]
#[track_caller]
pub fn from_rgb_speed(width: u16, height: u16, pixels: &[u8], speed: i32) -> Self {
assert_eq!(width as usize * height as usize * 3, pixels.len(), "Too much or too little pixel data for the given width and height to create a GIF Frame");
assert_eq!(
width as usize * height as usize * 3,
pixels.len(),
"Too much or too little pixel data for the given width and height to create a GIF Frame"
);
let mut vec: Vec<u8> = Vec::new();
vec.try_reserve_exact(pixels.len() + width as usize * height as usize)
.expect("OOM");
Expand Down
6 changes: 3 additions & 3 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::error;
use std::io;
use std::io::Write;

use weezl::{encode::Encoder as LzwEncoder, BitOrder};
use weezl::{BitOrder, encode::Encoder as LzwEncoder};

use crate::common::{AnyExtension, Block, DisposalMethod, Extension, Frame};
use crate::traits::WriteBytesExt;
Expand Down Expand Up @@ -201,7 +201,7 @@ impl<W: Write> Encoder<W> {
pub fn write_frame(&mut self, frame: &Frame<'_>) -> Result<(), EncodingError> {
if usize::from(frame.width)
.checked_mul(usize::from(frame.height))
.map_or(true, |size| frame.buffer.len() < size)
.is_none_or(|size| frame.buffer.len() < size)
{
return Err(EncodingError::FrameBufferTooSmallForDimensions);
}
Expand Down Expand Up @@ -235,7 +235,7 @@ impl<W: Write> Encoder<W> {
_ => {
return Err(EncodingError::from(
EncodingFormatError::MissingColorPalette,
))
));
}
};
let mut tmp = tmp_buf::<10>();
Expand Down
13 changes: 3 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,7 @@ pub mod streaming_decoder {
pub use crate::reader::{Decoded, FrameDataType, FrameDecoder, OutputBuffer, StreamingDecoder};
}

#[cfg(feature = "color_quant")]
macro_rules! insert_as_doc {
{ $content:expr } => {
#[allow(unused_doc_comments)]
#[doc = $content] extern "C" { }
}
}

// Provides the README.md as doc, to ensure the example works!
#[cfg(feature = "color_quant")]
insert_as_doc!(include_str!("../README.md"));
#[cfg(all(doctest, feature = "color_quant"))]
#[doc = include_str!("../README.md")]
mod _readme {}
8 changes: 2 additions & 6 deletions src/reader/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use core::iter;
use core::mem;

use super::decoder::{DecodingError, OutputBuffer, PLTE_CHANNELS};
use crate::common::Frame;
use crate::MemoryLimit;
use crate::common::Frame;

pub(crate) const N_CHANNELS: usize = 4;

Expand Down Expand Up @@ -148,11 +148,7 @@ impl PixelConverter {
rgba[1] = colors[1];
rgba[2] = colors[2];
rgba[3] = if let Some(t) = transparent {
if t == idx {
0x00
} else {
0xFF
}
if t == idx { 0x00 } else { 0xFF }
} else {
0xFF
};
Expand Down
6 changes: 3 additions & 3 deletions src/reader/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use core::num::NonZeroUsize;
use std::error;
use std::io;

use crate::MemoryLimit;
use crate::common::{AnyExtension, Block, DisposalMethod, Extension, Frame};
use crate::reader::DecodeOptions;
use crate::MemoryLimit;

use weezl::{decode::Decoder as LzwDecoder, BitOrder, LzwError, LzwStatus};
use weezl::{BitOrder, LzwError, LzwStatus, decode::Decoder as LzwDecoder};

/// GIF palettes are RGB
pub const PLTE_CHANNELS: usize = 3;
Expand Down Expand Up @@ -314,7 +314,7 @@ impl LzwReader {
}

pub fn has_ended(&self) -> bool {
self.decoder.as_ref().map_or(true, |e| e.has_ended())
self.decoder.as_ref().is_none_or(|e| e.has_ended())
}

pub fn decode_bytes(
Expand Down
4 changes: 2 additions & 2 deletions src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod decoder;

pub use self::decoder::{
Decoded, DecodingError, DecodingFormatError, FrameDataType, FrameDecoder, OutputBuffer,
StreamingDecoder, Version, PLTE_CHANNELS,
PLTE_CHANNELS, StreamingDecoder, Version,
};

pub use self::converter::ColorOutput;
Expand Down Expand Up @@ -347,7 +347,7 @@ where
None => {
return Err(DecodingError::format(
"file does not contain any image data",
))
));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/check_testimages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::collections::HashMap;
use std::fs::File;
use std::path::PathBuf;

use std::io::prelude::*;
use std::io::BufReader;
use std::io::prelude::*;

const BASE_PATH: [&str; 2] = [".", "tests"];

Expand Down
2 changes: 1 addition & 1 deletion tests/decode.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![cfg(feature = "std")]

use gif::{
streaming_decoder::{Decoded, OutputBuffer, StreamingDecoder},
DecodeOptions, Decoder, DisposalMethod, Encoder, Frame, Repeat,
streaming_decoder::{Decoded, OutputBuffer, StreamingDecoder},
};
use std::{fs::File, io::BufRead};

Expand Down
Loading