Switch to zune-jpeg (#268)

]
This commit is contained in:
Jonathan Behrens authored and GitHub committed 2025-06-14 21:13:16 -07:00
1 parent b5d8ee5f86
commit dc2c67469b
5 files changed
+26 -32

No files matched your search

+4 -4
View File
@@ -9,14 +9,14 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
rust: ["1.70.0", stable, beta, nightly] rust: ["1.74.0", stable, beta, nightly]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: dtolnay/rust-toolchain@nightly - 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 - 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 run: cargo -Zminimal-versions generate-lockfile
- uses: dtolnay/rust-toolchain@v1 - uses: dtolnay/rust-toolchain@v1
@@ -29,7 +29,7 @@ jobs:
- name: build - name: build
run: cargo build -v run: cargo build -v
- name: test - name: test
if: ${{ matrix.rust != '1.70.0' }} if: ${{ matrix.rust != '1.74.0' }}
run: cargo test -v && cargo doc -v run: cargo test -v && cargo doc -v
rustfmt: rustfmt:
+2 -2
View File
@@ -5,7 +5,7 @@ edition = "2021"
resolver = "2" resolver = "2"
# note: when changed, also update test runner in `.github/workflows/rust.yml` # note: when changed, also update test runner in `.github/workflows/rust.yml`
rust-version = "1.70.0" rust-version = "1.74.0"
license = "MIT" license = "MIT"
description = "TIFF decoding and encoding library in pure Rust" description = "TIFF decoding and encoding library in pure Rust"
@@ -19,7 +19,7 @@ exclude = ["tests/images/*", "tests/fuzz_images/*"]
[dependencies] [dependencies]
half = { version = "2.4.1" } half = { version = "2.4.1" }
weezl = "0.1.0" weezl = "0.1.0"
jpeg = { package = "jpeg-decoder", version = "0.3.0", default-features = false } zune-jpeg = "0.4.17"
flate2 = "1.0.20" flate2 = "1.0.20"
zstd = { version = "0.13", optional = true } zstd = { version = "0.13", optional = true }
quick-error = "2.0.1" quick-error = "2.0.1"
+17 -15
View File
@@ -9,6 +9,7 @@ use crate::tags::{
use crate::{ColorType, TiffError, TiffFormatError, TiffResult, TiffUnsupportedError, UsageError}; use crate::{ColorType, TiffError, TiffFormatError, TiffResult, TiffUnsupportedError, UsageError};
use std::io::{self, Cursor, Read, Seek}; use std::io::{self, Cursor, Read, Seek};
use std::sync::Arc; use std::sync::Arc;
use zune_jpeg::zune_core;
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct StripDecodeState { pub(crate) struct StripDecodeState {
@@ -402,7 +403,7 @@ impl Image {
// bytes of the remaining JPEG data is removed because it follows `jpeg_tables`. // 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, // 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`). // 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) => { Some(jpeg_tables) => {
let mut reader = reader.take(compressed_length); let mut reader = reader.take(compressed_length);
reader.read_exact(&mut [0; 2])?; reader.read_exact(&mut [0; 2])?;
@@ -415,28 +416,28 @@ impl Image {
None => Box::new(reader.take(compressed_length)), 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 { match photometric_interpretation {
PhotometricInterpretation::RGB => { PhotometricInterpretation::RGB => {
decoder.set_color_transform(jpeg::ColorTransform::RGB) options =
} options.jpeg_set_out_colorspace(zune_core::colorspace::ColorSpace::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)
} }
PhotometricInterpretation::CMYK => { PhotometricInterpretation::CMYK => {
decoder.set_color_transform(jpeg::ColorTransform::CMYK) options = options
.jpeg_set_out_colorspace(zune_core::colorspace::ColorSpace::CMYK);
} }
PhotometricInterpretation::YCbCr => { 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( return Err(TiffError::UnsupportedError(
TiffUnsupportedError::UnsupportedInterpretation( TiffUnsupportedError::UnsupportedInterpretation(
photometric_interpretation, photometric_interpretation,
@@ -444,6 +445,7 @@ impl Image {
)); ));
} }
} }
decoder.set_options(options);
let data = decoder.decode()?; let data = decoder.decode()?;
+3 -8
View File
@@ -2,8 +2,8 @@ use std::io;
use std::str; use std::str;
use std::string; use std::string;
use jpeg::UnsupportedFeature;
use quick_error::quick_error; use quick_error::quick_error;
use weezl::LzwError;
use crate::decoder::ChunkType; use crate::decoder::ChunkType;
use crate::tags::{ use crate::tags::{
@@ -11,8 +11,6 @@ use crate::tags::{
}; };
use crate::ColorType; use crate::ColorType;
use crate::weezl::LzwError;
quick_error! { quick_error! {
/// Tiff error kinds. /// Tiff error kinds.
#[derive(Debug)] #[derive(Debug)]
@@ -159,9 +157,6 @@ quick_error! {
UnsupportedInterpretation(interpretation: PhotometricInterpretation) { UnsupportedInterpretation(interpretation: PhotometricInterpretation) {
display("unsupported photometric interpretation \"{interpretation:?}\"") display("unsupported photometric interpretation \"{interpretation:?}\"")
} }
UnsupportedJpegFeature(feature: UnsupportedFeature) {
display("unsupported JPEG feature {feature:?}")
}
MisalignedTileBoundaries { MisalignedTileBoundaries {
display("tile rows are not aligned to byte boundaries") display("tile rows are not aligned to byte boundaries")
} }
@@ -217,8 +212,8 @@ impl From<LzwError> for TiffError {
} }
} }
impl From<jpeg::Error> for TiffError { impl From<zune_jpeg::errors::DecodeErrors> for TiffError {
fn from(err: jpeg::Error) -> Self { fn from(err: zune_jpeg::errors::DecodeErrors) -> Self {
TiffError::FormatError(TiffFormatError::CompressedDataCorrupt(err.to_string())) TiffError::FormatError(TiffFormatError::CompressedDataCorrupt(err.to_string()))
} }
} }
-3
View File
@@ -6,9 +6,6 @@
//! # Related Links //! # Related Links
//! * <https://web.archive.org/web/20210108073850/https://www.adobe.io/open/standards/TIFF.html> - The TIFF specification //! * <https://web.archive.org/web/20210108073850/https://www.adobe.io/open/standards/TIFF.html> - The TIFF specification
extern crate jpeg;
extern crate weezl;
mod bytecast; mod bytecast;
pub mod decoder; pub mod decoder;
pub mod encoder; pub mod encoder;