Greatly improved performance for 16 bit images
This commit is contained in:
1 parent
724e5e8c80
commit
345aff0629
2 files changed
+12
-6
No files matched your search
+4
-6
@@ -427,15 +427,13 @@ impl<R: Read + Seek> Decoder<R> {
|
||||
}
|
||||
(ColorType::RGBA(16), DecodingBuffer::U16(ref mut buffer)) |
|
||||
(ColorType:: RGB(16), DecodingBuffer::U16(ref mut buffer)) => {
|
||||
for datum in buffer[..bytes/2].iter_mut() {
|
||||
*datum = try!(reader.read_u16())
|
||||
}
|
||||
try!(reader.read_u16_into(&mut buffer[..bytes/2]));
|
||||
bytes/2
|
||||
}
|
||||
(ColorType::Gray(16), DecodingBuffer::U16(ref mut buffer)) => {
|
||||
for datum in buffer[..bytes/2].iter_mut() {
|
||||
*datum = try!(reader.read_u16());
|
||||
if self.photometric_interpretation == PhotometricInterpretation::WhiteIsZero {
|
||||
try!(reader.read_u16_into(&mut buffer[..bytes/2]));
|
||||
if self.photometric_interpretation == PhotometricInterpretation::WhiteIsZero {
|
||||
for datum in buffer[..bytes/2].iter_mut() {
|
||||
*datum = 0xffff - *datum
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,14 @@ pub trait EndianReader: Read {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn read_u16_into(&mut self, buffer: &mut [u16]) -> Result<(), io::Error> {
|
||||
match self.byte_order() {
|
||||
ByteOrder::LittleEndian => <Self as ReadBytesExt>::read_u16_into::<LittleEndian>(self, buffer),
|
||||
ByteOrder::BigEndian => <Self as ReadBytesExt>::read_u16_into::<BigEndian>(self, buffer)
|
||||
}
|
||||
}
|
||||
|
||||
/// Reads an u32
|
||||
#[inline(always)]
|
||||
fn read_u32(&mut self) -> Result<u32, io::Error> {
|
||||
|
||||
Reference in new issue
Block a user