From 81054fbb570f46d06eede4d3ce63c5bcd38451ae Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Sat, 23 Mar 2024 13:51:57 -0700 Subject: [PATCH 1/7] Switch to zune-jpeg --- Cargo.toml | 2 +- src/decoder/image.rs | 30 ++++++++++++++---------------- src/error.rs | 16 +++++----------- src/lib.rs | 3 --- 4 files changed, 20 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 91978e5e..dc082ff2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ exclude = ["tests/images/*", "tests/fuzz_images/*"] [dependencies] half = { version = "2.4.1" } weezl = "0.1.0" -jpeg = { package = "jpeg-decoder", version = "0.3.0", default-features = false } +zune-jpeg = "0.4.11" flate2 = "1.0.20" zstd = { version = "0.13", optional = true } diff --git a/src/decoder/image.rs b/src/decoder/image.rs index 6133fa1e..47882582 100644 --- a/src/decoder/image.rs +++ b/src/decoder/image.rs @@ -9,6 +9,7 @@ use crate::tags::{ use crate::{ColorType, TiffError, TiffFormatError, TiffResult, TiffUnsupportedError, UsageError}; use std::io::{self, Cursor, Read, Seek}; use std::sync::Arc; +use zune_jpeg::zune_core; #[derive(Debug)] pub(crate) struct StripDecodeState { @@ -402,7 +403,7 @@ impl Image { // bytes of the remaining JPEG data is removed because it follows `jpeg_tables`. // Similary, `jpeg_tables` ends with a `EOI` (HEX: `0xFFD9`) or __end of image__ marker, // this has to be removed as well (last two bytes of `jpeg_tables`). - let jpeg_reader = match jpeg_tables { + let mut jpeg_reader = match jpeg_tables { Some(jpeg_tables) => { let mut reader = reader.take(compressed_length); reader.read_exact(&mut [0; 2])?; @@ -415,28 +416,25 @@ impl Image { None => Box::new(reader.take(compressed_length)), }; - let mut decoder = jpeg::Decoder::new(jpeg_reader); + let mut jpeg_data = Vec::new(); + jpeg_reader.read_to_end(&mut jpeg_data)?; + let mut decoder = zune_jpeg::JpegDecoder::new(jpeg_data); + let mut options: zune_core::options::DecoderOptions = Default::default(); match photometric_interpretation { PhotometricInterpretation::RGB => { - decoder.set_color_transform(jpeg::ColorTransform::RGB) - } - PhotometricInterpretation::WhiteIsZero => { - decoder.set_color_transform(jpeg::ColorTransform::None) - } - PhotometricInterpretation::BlackIsZero => { - decoder.set_color_transform(jpeg::ColorTransform::None) - } - PhotometricInterpretation::TransparencyMask => { - decoder.set_color_transform(jpeg::ColorTransform::None) + options = options.jpeg_set_out_colorspace(zune_core::colorspace::ColorSpace::RGB); } PhotometricInterpretation::CMYK => { - decoder.set_color_transform(jpeg::ColorTransform::CMYK) + options = options.jpeg_set_out_colorspace(zune_core::colorspace::ColorSpace::CMYK); } PhotometricInterpretation::YCbCr => { - decoder.set_color_transform(jpeg::ColorTransform::YCbCr) + options = options.jpeg_set_out_colorspace(zune_core::colorspace::ColorSpace::YCbCr); } - photometric_interpretation => { + PhotometricInterpretation::WhiteIsZero + | PhotometricInterpretation::BlackIsZero + | PhotometricInterpretation::TransparencyMask => {} + PhotometricInterpretation::RGBPalette | PhotometricInterpretation::CIELab => { return Err(TiffError::UnsupportedError( TiffUnsupportedError::UnsupportedInterpretation( photometric_interpretation, @@ -444,9 +442,9 @@ impl Image { )); } } + decoder.set_options(options); let data = decoder.decode()?; - Box::new(Cursor::new(data)) } method => { diff --git a/src/error.rs b/src/error.rs index 8cd3fdd0..335e44f8 100644 --- a/src/error.rs +++ b/src/error.rs @@ -6,15 +6,13 @@ use std::str; use std::string; use std::sync::Arc; -use jpeg::UnsupportedFeature; - use crate::decoder::{ifd::Value, ChunkType}; use crate::tags::{ CompressionMethod, PhotometricInterpretation, PlanarConfiguration, SampleFormat, Tag, }; use crate::ColorType; -use crate::weezl::LzwError; +use weezl::LzwError; /// Tiff error kinds. #[derive(Debug)] @@ -166,7 +164,6 @@ pub enum TiffUnsupportedError { UnsupportedPlanarConfig(Option), UnsupportedDataType, UnsupportedInterpretation(PhotometricInterpretation), - UnsupportedJpegFeature(UnsupportedFeature), MisalignedTileBoundaries, } @@ -223,9 +220,6 @@ impl fmt::Display for TiffUnsupportedError { interpretation ) } - UnsupportedJpegFeature(ref unsupported_feature) => { - write!(fmt, "Unsupported JPEG feature {:?}", unsupported_feature) - } MisalignedTileBoundaries => write!(fmt, "Tile rows are not aligned to byte boundaries"), } } @@ -360,11 +354,11 @@ impl From for TiffError { #[derive(Debug, Clone)] pub struct JpegDecoderError { - inner: Arc, + inner: Arc, } impl JpegDecoderError { - fn new(error: jpeg::Error) -> Self { + fn new(error: zune_jpeg::errors::DecodeErrors) -> Self { Self { inner: Arc::new(error), } @@ -389,8 +383,8 @@ impl From for TiffError { } } -impl From for TiffError { - fn from(error: jpeg::Error) -> Self { +impl From for TiffError { + fn from(error: zune_jpeg::errors::DecodeErrors) -> Self { JpegDecoderError::new(error).into() } } diff --git a/src/lib.rs b/src/lib.rs index a4522ced..fb48a842 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,9 +6,6 @@ //! # Related Links //! * - The TIFF specification -extern crate jpeg; -extern crate weezl; - mod bytecast; pub mod decoder; pub mod encoder; From 14b4ba5ae09353cb81b79061cc47d244fc46cc4c Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Sun, 8 Jun 2025 18:32:50 -0700 Subject: [PATCH 2/7] Update dependency --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index dc082ff2..d3d6f646 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ exclude = ["tests/images/*", "tests/fuzz_images/*"] [dependencies] half = { version = "2.4.1" } weezl = "0.1.0" -zune-jpeg = "0.4.11" +zune-jpeg = "0.4.16" flate2 = "1.0.20" zstd = { version = "0.13", optional = true } From 6c855fb6e0cfe3837805304061e64242e14bda75 Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Sun, 8 Jun 2025 18:32:55 -0700 Subject: [PATCH 3/7] Fix formatting --- src/decoder/image.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/decoder/image.rs b/src/decoder/image.rs index 47882582..94cda96f 100644 --- a/src/decoder/image.rs +++ b/src/decoder/image.rs @@ -423,13 +423,16 @@ impl Image { let mut options: zune_core::options::DecoderOptions = Default::default(); match photometric_interpretation { PhotometricInterpretation::RGB => { - options = options.jpeg_set_out_colorspace(zune_core::colorspace::ColorSpace::RGB); + options = + options.jpeg_set_out_colorspace(zune_core::colorspace::ColorSpace::RGB); } PhotometricInterpretation::CMYK => { - options = options.jpeg_set_out_colorspace(zune_core::colorspace::ColorSpace::CMYK); + options = options + .jpeg_set_out_colorspace(zune_core::colorspace::ColorSpace::CMYK); } PhotometricInterpretation::YCbCr => { - options = options.jpeg_set_out_colorspace(zune_core::colorspace::ColorSpace::YCbCr); + options = options + .jpeg_set_out_colorspace(zune_core::colorspace::ColorSpace::YCbCr); } PhotometricInterpretation::WhiteIsZero | PhotometricInterpretation::BlackIsZero From 10ae55df9753172241e077a0061293ef6beea9aa Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Sun, 8 Jun 2025 18:37:45 -0700 Subject: [PATCH 4/7] Revert whitespace change --- src/decoder/image.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/decoder/image.rs b/src/decoder/image.rs index 94cda96f..6f70ead7 100644 --- a/src/decoder/image.rs +++ b/src/decoder/image.rs @@ -448,6 +448,7 @@ impl Image { decoder.set_options(options); let data = decoder.decode()?; + Box::new(Cursor::new(data)) } method => { From 02848983c00ecc2226e10c7a1b69a10157763bf6 Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Sun, 8 Jun 2025 18:58:02 -0700 Subject: [PATCH 5/7] Bump MSRV --- .github/workflows/rust.yml | 8 ++++---- Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 109e5fbf..d8b6af1b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -9,14 +9,14 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - rust: ["1.70.0", stable, beta, nightly] + rust: ["1.74.0", stable, beta, nightly] steps: - uses: actions/checkout@v2 - uses: dtolnay/rust-toolchain@nightly - if: ${{ matrix.rust == '1.70.0' }} + if: ${{ matrix.rust == '1.74.0' }} - name: Generate Cargo.lock with minimal-version dependencies - if: ${{ matrix.rust == '1.70.0' }} + if: ${{ matrix.rust == '1.74.0' }} run: cargo -Zminimal-versions generate-lockfile - uses: dtolnay/rust-toolchain@v1 @@ -29,7 +29,7 @@ jobs: - name: build run: cargo build -v - name: test - if: ${{ matrix.rust != '1.70.0' }} + if: ${{ matrix.rust != '1.74.0' }} run: cargo test -v && cargo doc -v rustfmt: diff --git a/Cargo.toml b/Cargo.toml index d3d6f646..b2616dd7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" resolver = "2" # note: when changed, also update test runner in `.github/workflows/rust.yml` -rust-version = "1.70.0" +rust-version = "1.74.0" license = "MIT" description = "TIFF decoding and encoding library in pure Rust" From e9d35d3b33158b1bd5b902dcd3750f247418e9b5 Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Sat, 14 Jun 2025 21:08:39 -0700 Subject: [PATCH 6/7] Increase zune-jpeg version Co-authored-by: Sergey "Shnatsel" Davidoff --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 6fa76b15..30677d57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ exclude = ["tests/images/*", "tests/fuzz_images/*"] [dependencies] half = { version = "2.4.1" } weezl = "0.1.0" -zune-jpeg = "0.4.16" +zune-jpeg = "0.4.17" flate2 = "1.0.20" zstd = { version = "0.13", optional = true } quick-error = "2.0.1" From 50ffba77d2963582053f7d323b549851cfa5093d Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Sat, 14 Jun 2025 21:10:34 -0700 Subject: [PATCH 7/7] Fix formatting --- src/error.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/error.rs b/src/error.rs index b8376940..5a2bbf71 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,7 +1,9 @@ use std::io; use std::str; use std::string; + use quick_error::quick_error; +use weezl::LzwError; use crate::decoder::ChunkType; use crate::tags::{ @@ -9,8 +11,6 @@ use crate::tags::{ }; use crate::ColorType; -use weezl::LzwError; - quick_error! { /// Tiff error kinds. #[derive(Debug)]