Skip to content

added predictors #86

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

Merged
merged 23 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d49342c
added predictors
feefladder Apr 2, 2025
df407ba
improved tests, fixed some bugs
feefladder Apr 2, 2025
c37e067
added docs+doctests
feefladder Apr 2, 2025
9f704d8
fixed clippy, doctest improvements
feefladder Apr 2, 2025
6c9a8cf
added padding test, fixed corresponding bugs, removed printlns
feefladder Apr 2, 2025
a3291b0
Remove registry
kylebarron Apr 2, 2025
b3640c0
Rename to Unpredict
kylebarron Apr 2, 2025
67eca9c
Change to pub(crate) fields
kylebarron Apr 2, 2025
a50fb81
Change to pub(crate)
kylebarron Apr 2, 2025
2b3fe03
Remove lifetime and store a single element for bits_per_pixel
kylebarron Apr 2, 2025
d754e14
Remove unused planar configuration
kylebarron Apr 2, 2025
cda2bcc
chunk_width and chunk_height without unwrap
kylebarron Apr 2, 2025
4787983
Move PredictorInfo into predictor.rs
kylebarron Apr 2, 2025
931f58d
Remove unnecessary doctests and unused code
kylebarron Apr 2, 2025
2ac868a
Only call chunks_* once
kylebarron Apr 2, 2025
be74506
Ensure no copies when endianness matches system endianness
kylebarron Apr 2, 2025
a0ff033
added planar_configuration back, updated bits_per_pixel and added tests
feefladder Apr 2, 2025
26176f9
silly clippy things
feefladder Apr 3, 2025
111630b
removed UnPredict trait in favour of separate functions; small change…
feefladder Apr 3, 2025
73d4894
added doc comment clarifying that strips are also tiles
feefladder Apr 3, 2025
5286e17
Update src/tiff/error.rs
feefladder Jun 10, 2025
dc46f8a
Apply suggestions from @weji14
feefladder Jun 10, 2025
9b3afc8
made floating point predictor(s) use
feefladder Jun 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/cog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ mod test {
use std::io::BufReader;
use std::sync::Arc;

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

Expand Down Expand Up @@ -51,9 +50,8 @@ mod test {
let tiff = TIFF::new(ifds);

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

Expand Down
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ pub enum AsyncTiffError {
#[error("General error: {0}")]
General(String),

/// Tile index error
#[error("Tile index out of bounds: {0}, {1}")]
TileIndexError(u32, u32),

/// IO Error.
#[error(transparent)]
IOError(#[from] std::io::Error),
Expand Down
17 changes: 15 additions & 2 deletions src/ifd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use num_enum::TryFromPrimitive;

use crate::error::{AsyncTiffError, AsyncTiffResult};
use crate::geo::{GeoKeyDirectory, GeoKeyTag};
use crate::reader::AsyncFileReader;
use crate::predictor::PredictorInfo;
use crate::reader::{AsyncFileReader, Endianness};
use crate::tiff::tags::{
CompressionMethod, PhotometricInterpretation, PlanarConfiguration, Predictor, ResolutionUnit,
SampleFormat, Tag,
Expand All @@ -21,6 +22,8 @@ const DOCUMENT_NAME: u16 = 269;
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct ImageFileDirectory {
pub(crate) endianness: Endianness,

pub(crate) new_subfile_type: Option<u32>,

/// The number of columns in the image, i.e., the number of pixels per row.
Expand Down Expand Up @@ -143,7 +146,10 @@ pub struct ImageFileDirectory {

impl ImageFileDirectory {
/// Create a new ImageFileDirectory from tag data
pub fn from_tags(tag_data: HashMap<Tag, Value>) -> AsyncTiffResult<Self> {
pub fn from_tags(
tag_data: HashMap<Tag, Value>,
endianness: Endianness,
) -> AsyncTiffResult<Self> {
let mut new_subfile_type = None;
let mut image_width = None;
let mut image_height = None;
Expand Down Expand Up @@ -349,6 +355,7 @@ impl ImageFileDirectory {
PlanarConfiguration::Chunky
};
Ok(Self {
endianness,
new_subfile_type,
image_width: image_width.expect("image_width not found"),
image_height: image_height.expect("image_height not found"),
Expand Down Expand Up @@ -689,6 +696,8 @@ impl ImageFileDirectory {
Ok(Tile {
x,
y,
predictor: self.predictor.unwrap_or(Predictor::None),
predictor_info: PredictorInfo::from_ifd(self),
compressed_bytes,
compression_method: self.compression,
photometric_interpretation: self.photometric_interpretation,
Expand All @@ -705,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 @@ -724,6 +735,8 @@ impl ImageFileDirectory {
let tile = Tile {
x,
y,
predictor: self.predictor.unwrap_or(Predictor::None),
predictor_info,
compressed_bytes,
compression_method: self.compression,
photometric_interpretation: self.photometric_interpretation,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod error;
pub mod geo;
mod ifd;
pub mod metadata;
pub mod predictor;
pub mod tiff;
mod tile;

Expand Down
9 changes: 6 additions & 3 deletions src/metadata/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl ImageFileDirectoryReader {
let (tag, value) = self.read_tag(fetch, tag_idx).await?;
tags.insert(tag, value);
}
ImageFileDirectory::from_tags(tags)
ImageFileDirectory::from_tags(tags, self.endianness)
}

/// Finish this reader, reading the byte offset of the next IFD
Expand Down Expand Up @@ -623,11 +623,14 @@ async fn read_tag_value<F: MetadataFetch>(

#[cfg(test)]
mod test {
use crate::{
metadata::{reader::read_tag, MetadataFetch},
reader::Endianness,
tiff::{tags::Tag, Value},
};
use bytes::Bytes;
use futures::FutureExt;

use super::*;

impl MetadataFetch for Bytes {
fn fetch(
&self,
Expand Down
Loading