Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 4 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.16"
flate2 = "1.0.20"
zstd = { version = "0.13", optional = true }

Expand Down
32 changes: 17 additions & 15 deletions src/decoder/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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])?;
Expand All @@ -415,35 +416,36 @@ 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,
),
));
}
}
decoder.set_options(options);

let data = decoder.decode()?;

Expand Down
16 changes: 5 additions & 11 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -166,7 +164,6 @@ pub enum TiffUnsupportedError {
UnsupportedPlanarConfig(Option<PlanarConfiguration>),
UnsupportedDataType,
UnsupportedInterpretation(PhotometricInterpretation),
UnsupportedJpegFeature(UnsupportedFeature),
MisalignedTileBoundaries,
}

Expand Down Expand Up @@ -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"),
}
}
Expand Down Expand Up @@ -360,11 +354,11 @@ impl From<LzwError> for TiffError {

#[derive(Debug, Clone)]
pub struct JpegDecoderError {
inner: Arc<jpeg::Error>,
inner: Arc<zune_jpeg::errors::DecodeErrors>,
}

impl JpegDecoderError {
fn new(error: jpeg::Error) -> Self {
fn new(error: zune_jpeg::errors::DecodeErrors) -> Self {
Self {
inner: Arc::new(error),
}
Expand All @@ -389,8 +383,8 @@ impl From<JpegDecoderError> for TiffError {
}
}

impl From<jpeg::Error> for TiffError {
fn from(error: jpeg::Error) -> Self {
impl From<zune_jpeg::errors::DecodeErrors> for TiffError {
fn from(error: zune_jpeg::errors::DecodeErrors) -> Self {
JpegDecoderError::new(error).into()
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
//! # Related Links
//! * <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;
pub mod decoder;
pub mod encoder;
Expand Down
Loading