Skip to content

Commit 2cb2a22

Browse files
committed
Update tiff to v0.5
1 parent 1eac5ba commit 2cb2a22

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ gif = { version = "0.10.0", optional = true }
3030
jpeg = { package = "jpeg-decoder", version = "0.1.17", default-features = false, optional = true }
3131
png = { version = "0.16.0", optional = true }
3232
scoped_threadpool = { version = "0.1", optional = true }
33-
tiff = { version = "0.4.0", optional = true }
33+
tiff = { version = "0.5.0", optional = true }
3434

3535
[dev-dependencies]
3636
crc32fast = "1.2.0"

Cargo.toml.public-private-dependencies

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ gif = { version = "0.10.0", optional = true }
3434
jpeg = { package = "jpeg-decoder", version = "0.1.17", default-features = false, optional = true }
3535
png = { version = "0.16.0", optional = true }
3636
scoped_threadpool = { version = "0.1", optional = true }
37-
tiff = { version = "0.4.0", optional = true }
37+
tiff = { version = "0.5.0", optional = true }
3838

3939
[dev-dependencies]
4040
crc32fast = "1.2.0"

src/tiff.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ use std::io::{self, Cursor, Read, Write, Seek};
1313
use std::marker::PhantomData;
1414
use std::mem;
1515

16-
use byteorder::{NativeEndian, ByteOrder};
17-
1816
use crate::color::{ColorType, ExtendedColorType};
1917
use crate::error::{
2018
DecodingError, EncodingError, ImageError, ImageResult, LimitError, LimitErrorKind,
2119
ParameterError, ParameterErrorKind, UnsupportedError, UnsupportedErrorKind,
2220
};
2321
use crate::image::{ImageDecoder, ImageEncoder, ImageFormat};
24-
use crate::utils::vec_u16_into_u8;
22+
use crate::utils;
2523

2624
/// Decoder for TIFF images.
2725
pub struct TiffDecoder<R>
@@ -78,7 +76,7 @@ impl ImageError {
7876
fn from_tiff_decode(err: tiff::TiffError) -> ImageError {
7977
match err {
8078
tiff::TiffError::IoError(err) => ImageError::IoError(err),
81-
err @ tiff::TiffError::FormatError(_) => {
79+
err @ tiff::TiffError::FormatError(_) | err @ tiff::TiffError::IntSizeError => {
8280
ImageError::Decoding(DecodingError::new(ImageFormat::Tiff.into(), err))
8381
}
8482
tiff::TiffError::UnsupportedError(desc) => {
@@ -96,7 +94,7 @@ impl ImageError {
9694
fn from_tiff_encode(err: tiff::TiffError) -> ImageError {
9795
match err {
9896
tiff::TiffError::IoError(err) => ImageError::IoError(err),
99-
err @ tiff::TiffError::FormatError(_) => {
97+
err @ tiff::TiffError::FormatError(_) | err @ tiff::TiffError::IntSizeError => {
10098
ImageError::Encoding(EncodingError::new(ImageFormat::Tiff.into(), err))
10199
}
102100
tiff::TiffError::UnsupportedError(desc) => {
@@ -146,7 +144,9 @@ impl<'a, R: 'a + Read + Seek> ImageDecoder<'a> for TiffDecoder<R> {
146144
.map_err(ImageError::from_tiff_decode)?
147145
{
148146
tiff::decoder::DecodingResult::U8(v) => v,
149-
tiff::decoder::DecodingResult::U16(v) => vec_u16_into_u8(v),
147+
tiff::decoder::DecodingResult::U16(v) => utils::vec_u16_into_u8(v),
148+
tiff::decoder::DecodingResult::U32(v) => utils::vec_u32_into_u8(v),
149+
tiff::decoder::DecodingResult::U64(v) => utils::vec_u64_into_u8(v),
150150
};
151151

152152
Ok(TiffReader(Cursor::new(buf), PhantomData))
@@ -163,7 +163,13 @@ impl<'a, R: 'a + Read + Seek> ImageDecoder<'a> for TiffDecoder<R> {
163163
buf.copy_from_slice(&v);
164164
}
165165
tiff::decoder::DecodingResult::U16(v) => {
166-
NativeEndian::write_u16_into(&v, buf);
166+
buf.copy_from_slice(bytemuck::cast_slice(&v));
167+
}
168+
tiff::decoder::DecodingResult::U32(v) => {
169+
buf.copy_from_slice(bytemuck::cast_slice(&v));
170+
}
171+
tiff::decoder::DecodingResult::U64(v) => {
172+
buf.copy_from_slice(bytemuck::cast_slice(&v));
167173
}
168174
}
169175
Ok(())

src/utils/mod.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! Utilities
22
3-
use byteorder::{NativeEndian, ByteOrder};
43
use num_iter::range_step;
5-
use std::mem;
64
use std::iter::repeat;
75

86
#[inline(always)]
@@ -69,15 +67,30 @@ pub(crate) fn expand_bits(bit_depth: u8, row_size: u32, buf: &[u8]) -> Vec<u8> {
6967
// When no image formats that use it are enabled
7068
pub(crate) fn vec_u16_into_u8(vec: Vec<u16>) -> Vec<u8> {
7169
// Do this way until we find a way to not alloc/dealloc but get llvm to realloc instead.
72-
vec_u16_copy_u8(&vec)
70+
vec_copy_to_u8(&vec)
7371
}
7472

7573
#[allow(dead_code)]
7674
// When no image formats that use it are enabled
77-
pub(crate) fn vec_u16_copy_u8(vec: &[u16]) -> Vec<u8> {
78-
let mut new = vec![0; vec.len() * mem::size_of::<u16>()];
79-
NativeEndian::write_u16_into(&vec[..], &mut new[..]);
80-
new
75+
pub(crate) fn vec_u32_into_u8(vec: Vec<u32>) -> Vec<u8> {
76+
// Do this way until we find a way to not alloc/dealloc but get llvm to realloc instead.
77+
vec_copy_to_u8(&vec)
78+
}
79+
80+
#[allow(dead_code)]
81+
// When no image formats that use it are enabled
82+
pub(crate) fn vec_u64_into_u8(vec: Vec<u64>) -> Vec<u8> {
83+
// Do this way until we find a way to not alloc/dealloc but get llvm to realloc instead.
84+
vec_copy_to_u8(&vec)
85+
}
86+
87+
#[allow(dead_code)]
88+
// When no image formats that use it are enabled
89+
pub(crate) fn vec_copy_to_u8<T>(vec: &[T]) -> Vec<u8>
90+
where
91+
T: bytemuck::Pod,
92+
{
93+
bytemuck::cast_slice(vec).to_owned()
8194
}
8295

8396

0 commit comments

Comments
 (0)