Compare commits

..
7 Commits
Author SHA1 Message Date
Jonathan Behrens 0da9770916 Merge pull request #190 from kurtkuehnert/YCbCr_support
Added support for the YCbCr PhotometricInterpretation
2023-01-06 23:54:16 -08:00
Kurt Kühnert c30ea911a2 fixed ci 2023-01-05 10:00:10 +01:00
Kurt Kühnert da07c0f4f5 added round trip test
fixed ci
added colortype
2023-01-05 09:34:54 +01:00
Jonathan Behrens 289fab2fcd Merge pull request #197 from pka/fix-padding
Fix padding when image size is multiple of chunk size
2022-12-16 15:49:58 -08:00
Pirmin Kalberer 21252d9d89 Fix padding when image size is multiple of chunk size 2022-12-16 23:37:38 +01:00
Andreas Molzer ffaccf2b52 Merge pull request #196 from image-rs/release-0.8.1
Changelog and metadata for 0.8.1
2022-12-10 16:57:28 +01:00
Kurt Kühnert a08604b015 added support for the YCbCr PhotometricInterpretation 2022-11-16 17:33:39 +01:00
5 changed files with 28 additions and 3 deletions

No files matched your search

+12 -3
View File
@@ -32,12 +32,11 @@ impl TileAttributes {
(self.image_height + self.tile_length - 1) / self.tile_length (self.image_height + self.tile_length - 1) / self.tile_length
} }
fn padding_right(&self) -> usize { fn padding_right(&self) -> usize {
self.tile_width - self.image_width % self.tile_width (self.tile_width - self.image_width % self.tile_width) % self.tile_width
} }
fn padding_down(&self) -> usize { fn padding_down(&self) -> usize {
self.tile_length - self.image_height % self.tile_length (self.tile_length - self.image_height % self.tile_length) % self.tile_length
} }
pub fn get_padding(&self, tile: usize) -> (usize, usize) { pub fn get_padding(&self, tile: usize) -> (usize, usize) {
let row = tile / self.tiles_across(); let row = tile / self.tiles_across();
let column = tile % self.tiles_across(); let column = tile % self.tiles_across();
@@ -306,6 +305,15 @@ impl Image {
), ),
)), )),
}, },
PhotometricInterpretation::YCbCr => match self.bits_per_sample[..] {
[y, cb, cr] if [y, y] == [cb, cr] => Ok(ColorType::YCbCr(y)),
_ => Err(TiffError::UnsupportedError(
TiffUnsupportedError::InterpretationWithBits(
self.photometric_interpretation,
self.bits_per_sample.clone(),
),
)),
},
PhotometricInterpretation::BlackIsZero | PhotometricInterpretation::WhiteIsZero PhotometricInterpretation::BlackIsZero | PhotometricInterpretation::WhiteIsZero
if self.bits_per_sample.len() == 1 => if self.bits_per_sample.len() == 1 =>
{ {
@@ -465,6 +473,7 @@ impl Image {
(ColorType::RGB(n), _) (ColorType::RGB(n), _)
| (ColorType::RGBA(n), _) | (ColorType::RGBA(n), _)
| (ColorType::CMYK(n), _) | (ColorType::CMYK(n), _)
| (ColorType::YCbCr(n), _)
| (ColorType::Gray(n), _) | (ColorType::Gray(n), _)
if usize::from(n) == buffer.byte_len() * 8 => {} if usize::from(n) == buffer.byte_len() * 8 => {}
(ColorType::Gray(n), DecodingBuffer::U8(_)) if n < 8 => match self.predictor { (ColorType::Gray(n), DecodingBuffer::U8(_)) if n < 8 => match self.predictor {
+8
View File
@@ -235,3 +235,11 @@ impl ColorType for CMYK64Float {
const BITS_PER_SAMPLE: &'static [u16] = &[64, 64, 64, 64]; const BITS_PER_SAMPLE: &'static [u16] = &[64, 64, 64, 64];
const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::IEEEFP; 4]; const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::IEEEFP; 4];
} }
pub struct YCbCr8;
impl ColorType for YCbCr8 {
type Inner = u8;
const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::YCbCr;
const BITS_PER_SAMPLE: &'static [u16] = &[8, 8, 8];
const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::Uint; 3];
}
+3
View File
@@ -37,4 +37,7 @@ pub enum ColorType {
/// Pixel is CMYK /// Pixel is CMYK
CMYK(u8), CMYK(u8),
/// Pixel is YCbCr
YCbCr(u8),
} }
+5
View File
@@ -264,6 +264,11 @@ fn test_gray_f64_roundtrip() {
test_f64_roundtrip::<colortype::Gray64Float>("gradient-1c-64b-float.tiff", ColorType::Gray(64)); test_f64_roundtrip::<colortype::Gray64Float>("gradient-1c-64b-float.tiff", ColorType::Gray(64));
} }
#[test]
fn test_ycbcr_u8_roundtrip() {
test_u8_roundtrip::<colortype::YCbCr8>("tiled-jpeg-ycbcr.tif", ColorType::YCbCr(8));
}
trait AssertDecode { trait AssertDecode {
fn assert_tag_u32(&mut self, tag: u16) -> u32; fn assert_tag_u32(&mut self, tag: u16) -> u32;
fn assert_tag_u32_vec(&mut self, tag: u16) -> Vec<u32>; fn assert_tag_u32_vec(&mut self, tag: u16) -> Vec<u32>;
Binary file not shown.