Skip to content
Draft
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
18 changes: 18 additions & 0 deletions src/codecs/tiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ where
(tiff::ColorType::Gray(1), Uint) => ColorType::L8,
(tiff::ColorType::Gray(8), Uint) => ColorType::L8,
(tiff::ColorType::Gray(16), Uint) => ColorType::L16,
(tiff::ColorType::Gray(16), IEEEFP) => ColorType::L32F,
(tiff::ColorType::Gray(32), IEEEFP) => ColorType::L32F,
(tiff::ColorType::GrayA(8), Uint) => ColorType::La8,
(tiff::ColorType::GrayA(16), Uint) => ColorType::La16,
Expand All @@ -135,6 +136,8 @@ where
(tiff::ColorType::RGBA(16), Uint) => ColorType::Rgba16,
(tiff::ColorType::CMYK(8), Uint) => ColorType::Rgb8,
(tiff::ColorType::CMYK(16), Uint) => ColorType::Rgb16,
(tiff::ColorType::CMYK(16), IEEEFP) => ColorType::Rgb32F,
(tiff::ColorType::RGBA(16), IEEEFP) => ColorType::Rgba32F,
(tiff::ColorType::RGB(32), IEEEFP) => ColorType::Rgb32F,
(tiff::ColorType::RGBA(32), IEEEFP) => ColorType::Rgba32F,
(tiff::ColorType::YCbCr(8), Uint) => ColorType::Rgb8,
Expand All @@ -152,6 +155,9 @@ where
(tiff::ColorType::CMYK(8), Uint) => ExtendedColorType::Cmyk8,
(tiff::ColorType::CMYK(16), Uint) => ExtendedColorType::Cmyk16,
(tiff::ColorType::YCbCr(8), Uint) => ExtendedColorType::YCbCr8,
(tiff::ColorType::Gray(16), IEEEFP) => ExtendedColorType::L16F,
(tiff::ColorType::CMYK(16), IEEEFP) => ExtendedColorType::Rgb16F,
(tiff::ColorType::RGBA(16), IEEEFP) => ExtendedColorType::Rgba16F,
_ => color_type.into(),
};

Expand Down Expand Up @@ -534,6 +540,18 @@ impl<R: BufRead + Seek> ImageDecoder for TiffDecoder<R> {

ycbcr_to_rgb8(ycbcr, lr, lg, lb, out);
}
DecodingResult::F16(v)
if matches!(
info.original_color_type,
ExtendedColorType::L16F
| ExtendedColorType::Rgb16F
| ExtendedColorType::Rgba16F
) =>
{
for (half, out) in v.iter().zip(buf.as_chunks_mut::<4>().0.iter_mut()) {
*out = half.to_f32().to_ne_bytes();
}
}
DecodingResult::U8(v) => {
buf.copy_from_slice(v);
}
Expand Down
19 changes: 18 additions & 1 deletion src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,16 @@ pub enum ExtendedColorType {
/// Pixel is 8-bit BGR with an alpha channel
Bgra8,

// TODO f16 types?
// TODO: Should the new f16 types come after Ycbcr8 for serde backwards compatibility?
/// Pixel is 16-bit float luminance
L16F,
/// Pixel is 16-bit float luminance with an alpha channel
La16F,
/// Pixel is 16-bit float RGB
Rgb16F,
/// Pixel is 16-bit float RGBA
Rgba16F,

/// Pixel is 32-bit float luminance
L32F,
/// Pixel is 32-bit float luminance with an alpha channel
Expand Down Expand Up @@ -191,20 +200,23 @@ impl ExtendedColorType {
| ExtendedColorType::L4
| ExtendedColorType::L8
| ExtendedColorType::L16
| ExtendedColorType::L16F
| ExtendedColorType::L32F
| ExtendedColorType::Unknown(_) => 1,
ExtendedColorType::La1
| ExtendedColorType::La2
| ExtendedColorType::La4
| ExtendedColorType::La8
| ExtendedColorType::La16
| ExtendedColorType::La16F
| ExtendedColorType::La32F => 2,
ExtendedColorType::Rgb1
| ExtendedColorType::Rgb2
| ExtendedColorType::Rgb4
| ExtendedColorType::Rgb5x1
| ExtendedColorType::Rgb8
| ExtendedColorType::Rgb16
| ExtendedColorType::Rgb16F
| ExtendedColorType::Rgb32F
| ExtendedColorType::YCbCr8
| ExtendedColorType::Bgr8 => 3,
Expand All @@ -213,6 +225,7 @@ impl ExtendedColorType {
| ExtendedColorType::Rgba4
| ExtendedColorType::Rgba8
| ExtendedColorType::Rgba16
| ExtendedColorType::Rgba16F
| ExtendedColorType::Rgba32F
| ExtendedColorType::Bgra8
| ExtendedColorType::Cmyk8
Expand Down Expand Up @@ -246,6 +259,10 @@ impl ExtendedColorType {
ExtendedColorType::La16 => 32,
ExtendedColorType::Rgb16 => 48,
ExtendedColorType::Rgba16 => 64,
ExtendedColorType::L16F => 16,
ExtendedColorType::La16F => 32,
ExtendedColorType::Rgb16F => 48,
ExtendedColorType::Rgba16F => 64,
ExtendedColorType::L32F => 32,
ExtendedColorType::La32F => 64,
ExtendedColorType::Rgb32F => 96,
Expand Down
Binary file added tests/images/tiff/testsuite/random-fp16.tiff
Binary file not shown.
Binary file added tests/reference/tiff/testsuite/random-fp16.tiff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions tests/reference_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ fn main() -> std::process::ExitCode {

if reference_format == ImageFormat::Png && image_format == Some(ImageFormat::Tiff) {
match test_img {
DynamicImage::ImageLuma32F(_) => {
test_img = test_img.to_luma16().into();
}
DynamicImage::ImageLumaA32F(_) => {
test_img = test_img.to_luma_alpha16().into();
}
DynamicImage::ImageRgb32F(_) => {
test_img = test_img.to_rgb16().into();
}
Expand Down
Loading