Testing access through alternate tag reads
This commit is contained in:
1 parent
24b008a7c3
commit
d3b777c961
2 files changed
+72
-1
No files matched your search
@@ -1865,3 +1865,70 @@ impl<'l> IfdDecoder<'l> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::Decoder;
|
||||||
|
use crate::{
|
||||||
|
bytecast,
|
||||||
|
tags::{ByteOrder, Tag, ValueBuffer},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn equivalence_of_tag_readers() {
|
||||||
|
let file = std::fs::File::open(concat!(
|
||||||
|
env!("CARGO_MANIFEST_DIR"),
|
||||||
|
"/tests/images/int8_rgb.tif"
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mut decoder = Decoder::new(file).unwrap();
|
||||||
|
let file_bo = decoder.byte_order();
|
||||||
|
let mut ifd = decoder.image_ifd();
|
||||||
|
|
||||||
|
{
|
||||||
|
let value = ifd
|
||||||
|
.find_tag(Tag::BitsPerSample)
|
||||||
|
.unwrap()
|
||||||
|
.expect("must have BitsPerSample");
|
||||||
|
|
||||||
|
let samples = value.into_u16_vec().unwrap();
|
||||||
|
assert_eq!(samples.as_slice(), [8, 8, 8]);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut value = ValueBuffer::from_value(&[0u16; 4]);
|
||||||
|
let _entry = ifd
|
||||||
|
.find_tag_buf(Tag::BitsPerSample, &mut value)
|
||||||
|
.unwrap()
|
||||||
|
.expect("must have BitsPerSample");
|
||||||
|
|
||||||
|
value.set_byte_order(ByteOrder::native());
|
||||||
|
assert_eq!(value.as_bytes(), bytecast::u16_as_ne_bytes(&[8, 8, 8]));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut by_bytes = [0u16; 4];
|
||||||
|
let entry = ifd
|
||||||
|
.find_entry(Tag::BitsPerSample)
|
||||||
|
.expect("must have BitsPerSample");
|
||||||
|
|
||||||
|
let byte_len = ifd
|
||||||
|
.find_tag_bytes(
|
||||||
|
Tag::BitsPerSample,
|
||||||
|
bytecast::u16_as_ne_mut_bytes(&mut by_bytes),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
.expect("must have BitsPerSample");
|
||||||
|
assert_eq!(byte_len, 3 * std::mem::size_of::<u16>());
|
||||||
|
|
||||||
|
file_bo.convert(
|
||||||
|
entry.field_type(),
|
||||||
|
bytecast::u16_as_ne_mut_bytes(&mut by_bytes[..3]),
|
||||||
|
ByteOrder::native(),
|
||||||
|
);
|
||||||
|
assert_eq!(&by_bytes[..3], &[8, 8, 8]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-1
@@ -432,9 +432,13 @@ impl ValueBuffer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Internal method to change the type and count while re-interpreting the byte buffer.
|
||||||
|
///
|
||||||
|
/// Should only be called after writing bytes to the internal buffer prepared with
|
||||||
|
/// `Self::prepare_length`.
|
||||||
pub(crate) fn assume_type(&mut self, ty: Type, count: u64, bo: ByteOrder) {
|
pub(crate) fn assume_type(&mut self, ty: Type, count: u64, bo: ByteOrder) {
|
||||||
debug_assert!({
|
debug_assert!({
|
||||||
ty.value_bytes(self.count)
|
ty.value_bytes(count)
|
||||||
.is_ok_and(|n| n < self.bytes.len() as u64)
|
.is_ok_and(|n| n < self.bytes.len() as u64)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user