Removed unused functions and make InvalidChunkIndex a UsageError
This commit is contained in:
1 parent
8c0c13f022
commit
e1f4161e0b
5 files changed
+21
-95
No files matched your search
@@ -7,7 +7,7 @@ use super::tag_reader::TagReader;
|
||||
use super::{fp_predict_f32, fp_predict_f64, DecodingBuffer, Limits};
|
||||
use super::{stream::SmartReader, ChunkType};
|
||||
use crate::tags::{CompressionMethod, PhotometricInterpretation, Predictor, SampleFormat, Tag};
|
||||
use crate::{ColorType, TiffError, TiffFormatError, TiffResult, TiffUnsupportedError};
|
||||
use crate::{ColorType, TiffError, TiffFormatError, TiffResult, TiffUnsupportedError, UsageError};
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::io::{self, Cursor, Read, Seek};
|
||||
use std::sync::Arc;
|
||||
@@ -419,7 +419,7 @@ impl Image {
|
||||
pub(crate) fn chunk_info(&self, chunk_index: usize) -> Option<ChunkInfo> {
|
||||
match &self.chunk_type {
|
||||
ChunkType::Strip => {
|
||||
let rows_per_strip = self.strip_decoder.as_ref()?.rows_per_strip as usize;
|
||||
let rows_per_strip = self.strip_decoder.as_ref().unwrap().rows_per_strip as usize;
|
||||
|
||||
let sized_width = self.width as usize;
|
||||
let sized_height = self.height as usize;
|
||||
@@ -440,7 +440,7 @@ impl Image {
|
||||
})
|
||||
}
|
||||
ChunkType::Tile => {
|
||||
let tile_attrs = self.tile_attributes.as_ref()?;
|
||||
let tile_attrs = self.tile_attributes.as_ref().unwrap();
|
||||
let (padding_right, padding_down) = tile_attrs.get_padding(chunk_index);
|
||||
|
||||
let tile_width = tile_attrs.tile_width - padding_right;
|
||||
@@ -525,8 +525,8 @@ impl Image {
|
||||
let predictor = self.predictor;
|
||||
let samples = self.bits_per_sample.len();
|
||||
|
||||
let chunk_info = self.chunk_info(chunk_index).ok_or(TiffError::FormatError(
|
||||
TiffFormatError::InvalidChunkIndex(chunk_index),
|
||||
let chunk_info = self.chunk_info(chunk_index).ok_or(TiffError::UsageError(
|
||||
UsageError::InvalidChunkIndex(chunk_index),
|
||||
))?;
|
||||
|
||||
let jpeg_tables = self.jpeg_tables.clone();
|
||||
|
||||
+4
-84
@@ -1064,31 +1064,6 @@ impl<R: Read + Seek> Decoder<R> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[deprecated = "Use read_chunk_to_buffer instead"]
|
||||
fn read_tile_to_buffer(
|
||||
&mut self,
|
||||
mut buffer: DecodingBuffer,
|
||||
tile_index: usize,
|
||||
output_width: usize,
|
||||
) -> TiffResult<()> {
|
||||
self.check_chunk_type(ChunkType::Tile)?;
|
||||
|
||||
let offset = self.image.chunk_file_range(tile_index)?.0;
|
||||
self.goto_offset_u64(offset)?;
|
||||
|
||||
let byte_order = self.reader.byte_order;
|
||||
|
||||
self.image.expand_chunk(
|
||||
&mut self.reader,
|
||||
buffer.copy(),
|
||||
output_width,
|
||||
byte_order,
|
||||
tile_index,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn read_chunk_to_buffer(
|
||||
&mut self,
|
||||
mut buffer: DecodingBuffer,
|
||||
@@ -1168,74 +1143,19 @@ impl<R: Read + Seek> Decoder<R> {
|
||||
/// information on the size of the strip read and so the caller must take care of the final
|
||||
/// strip in the image as the data read may be less than the expected strip size. This interface
|
||||
/// may change at a future date to reflect this.
|
||||
///
|
||||
/// `read_strip_at` can be used to get both the strip data and the strip size.
|
||||
///
|
||||
#[deprecated = "Use read_chunk instead"]
|
||||
#[deprecated = "Use read_chunk_at instead"]
|
||||
pub fn read_strip(&mut self) -> TiffResult<DecodingResult> {
|
||||
let result = self.read_strip_at(self.current_chunk)?;
|
||||
let result = self.read_chunk_at(self.current_chunk)?;
|
||||
|
||||
Ok(result.0)
|
||||
}
|
||||
|
||||
/// Read the specified strip (at index `strip_index`) and return the binary data as a Vector and
|
||||
/// `ChunkInfo` describing the size of the strip.
|
||||
///
|
||||
#[deprecated = "Use read_chunk instead"]
|
||||
pub fn read_strip_at(&mut self, strip_index: usize) -> TiffResult<(DecodingResult, ChunkInfo)> {
|
||||
self.check_chunk_type(ChunkType::Strip)?;
|
||||
|
||||
let chunk_info = self
|
||||
.image()
|
||||
.chunk_info(strip_index)
|
||||
.ok_or(TiffFormatError::InvalidChunkIndex(strip_index))?;
|
||||
|
||||
let mut result = self.result_buffer(chunk_info.data_width, chunk_info.data_height)?;
|
||||
self.read_strip_to_buffer(result.as_buffer(0))?;
|
||||
|
||||
Ok((result, chunk_info))
|
||||
}
|
||||
|
||||
/// Read a single tile from the image and return it as a Vector. This method does not return
|
||||
/// information on the size of the tile read and so the caller must take care of tiles on the
|
||||
/// rightmost column and the bottommost row in the image as the data read may be less than the
|
||||
/// expected tile size. This interface may change at a future date to reflect this.
|
||||
///
|
||||
/// `read_tile_at` can be used to get both the tile data and the tile size.
|
||||
#[deprecated = "Use read_chunk instead"]
|
||||
pub fn read_tile(&mut self) -> TiffResult<DecodingResult> {
|
||||
let result = self.read_tile_at(self.current_chunk)?;
|
||||
|
||||
self.current_chunk += 1;
|
||||
|
||||
Ok(result.0)
|
||||
}
|
||||
|
||||
/// Read the specified tile (at index `tile_index`) and return the binary data as a Vector and
|
||||
/// `ChunkInfo` describing the size of the tile.
|
||||
#[deprecated = "Use read_chunk_at instead"]
|
||||
pub fn read_tile_at(&mut self, tile_index: usize) -> TiffResult<(DecodingResult, ChunkInfo)> {
|
||||
self.check_chunk_type(ChunkType::Tile)?;
|
||||
|
||||
let chunk_info = self
|
||||
.image()
|
||||
.chunk_info(tile_index)
|
||||
.ok_or(TiffFormatError::InvalidChunkIndex(tile_index))?;
|
||||
|
||||
let mut result = self.result_buffer(chunk_info.data_width, chunk_info.data_height)?;
|
||||
|
||||
self.read_tile_to_buffer(result.as_buffer(0), tile_index, chunk_info.data_width)?;
|
||||
|
||||
Ok((result, chunk_info))
|
||||
}
|
||||
|
||||
/// Read a single chunk from the image and return it as a Vector. This method does not return
|
||||
/// information on the size of the chunk read and so the caller must take care of chunks on the
|
||||
/// rightmost column and the bottommost row in the image as the data read may be less than the
|
||||
/// expected chunk size. This interface may change at a future date to reflect this.
|
||||
///
|
||||
/// `read_chunk_at` can be used to get both the chunk data and the tile size.
|
||||
pub fn read_chunk(&mut self) -> TiffResult<DecodingResult> {
|
||||
pub fn read_tile(&mut self) -> TiffResult<DecodingResult> {
|
||||
let result = self.read_chunk_at(self.current_chunk)?;
|
||||
|
||||
self.current_chunk += 1;
|
||||
@@ -1249,7 +1169,7 @@ impl<R: Read + Seek> Decoder<R> {
|
||||
let chunk_info = self
|
||||
.image()
|
||||
.chunk_info(chunk_index)
|
||||
.ok_or(TiffFormatError::InvalidChunkIndex(chunk_index))?;
|
||||
.ok_or(UsageError::InvalidChunkIndex(chunk_index))?;
|
||||
|
||||
let mut result = self.result_buffer(chunk_info.data_width, chunk_info.data_height)?;
|
||||
|
||||
|
||||
Reference in new issue
Block a user