Skip to content

Suggested changes for predictors #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6 changes: 1 addition & 5 deletions src/cog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ mod test {
use std::io::BufReader;
use std::sync::Arc;

use crate::decoder::DecoderRegistry;
use crate::metadata::{PrefetchBuffer, TiffMetadataReader};
use crate::predictor::RevPredictorRegistry;
use crate::reader::{AsyncFileReader, ObjectReader};

use super::*;
Expand All @@ -52,10 +50,8 @@ mod test {
let tiff = TIFF::new(ifds);

let ifd = &tiff.ifds[1];
let decoder_registry = DecoderRegistry::default();
let predictor_registry = RevPredictorRegistry::default();
let tile = ifd.fetch_tile(0, 0, reader.as_ref()).await.unwrap();
let tile = tile.decode(&decoder_registry, &predictor_registry).unwrap();
let tile = tile.decode(&Default::default()).unwrap();
std::fs::write("img.buf", tile).unwrap();
}

Expand Down
33 changes: 6 additions & 27 deletions src/ifd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ use num_enum::TryFromPrimitive;

use crate::error::{AsyncTiffError, AsyncTiffResult};
use crate::geo::{GeoKeyDirectory, GeoKeyTag};
use crate::predictor::PredictorInfo;
use crate::reader::{AsyncFileReader, Endianness};
use crate::tiff::tags::{
CompressionMethod, PhotometricInterpretation, PlanarConfiguration, Predictor, ResolutionUnit,
SampleFormat, Tag,
};
use crate::tiff::{TiffError, Value};
use crate::tile::{PredictorInfo, Tile};
use crate::tile::Tile;

const DOCUMENT_NAME: u16 = 269;

Expand Down Expand Up @@ -681,30 +682,6 @@ impl ImageFileDirectory {
Some(offset as _..(offset + byte_count) as _)
}

fn get_predictor_info(&self) -> PredictorInfo {
PredictorInfo {
endianness: self.endianness,
image_width: self.image_width,
image_height: self.image_height,
chunk_width: if self.tile_width.is_none() {
// we are stripped => image_width
self.image_width
} else {
self.tile_width.unwrap()
},
chunk_height: if self.tile_height.is_none() {
self.rows_per_strip
.expect("no tile height and no rows_per_strip")
} else {
self.tile_height.unwrap()
},
bits_per_sample: &self.bits_per_sample,
samples_per_pixel: self.samples_per_pixel,
sample_format: &self.sample_format,
planar_configuration: self.planar_configuration,
}
}

/// Fetch the tile located at `x` column and `y` row using the provided reader.
pub async fn fetch_tile(
&self,
Expand All @@ -720,7 +697,7 @@ impl ImageFileDirectory {
x,
y,
predictor: self.predictor.unwrap_or(Predictor::None),
predictor_info: self.get_predictor_info(),
predictor_info: PredictorInfo::from_ifd(self),
compressed_bytes,
compression_method: self.compression,
photometric_interpretation: self.photometric_interpretation,
Expand All @@ -737,6 +714,8 @@ impl ImageFileDirectory {
) -> AsyncTiffResult<Vec<Tile>> {
assert_eq!(x.len(), y.len(), "x and y should have same len");

let predictor_info = PredictorInfo::from_ifd(self);

// 1: Get all the byte ranges for all tiles
let byte_ranges = x
.iter()
Expand All @@ -757,7 +736,7 @@ impl ImageFileDirectory {
x,
y,
predictor: self.predictor.unwrap_or(Predictor::None),
predictor_info: self.get_predictor_info(),
predictor_info,
compressed_bytes,
compression_method: self.compression,
photometric_interpretation: self.photometric_interpretation,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ mod tile;

pub use cog::TIFF;
pub use ifd::ImageFileDirectory;
pub use tile::{PredictorInfo, Tile};
pub use tile::Tile;
Loading