Skip to content
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

Added basic tile decoding #125

Merged
merged 7 commits into from
Apr 18, 2021
Merged

Added basic tile decoding #125

merged 7 commits into from
Apr 18, 2021

Conversation

to-mas-kral
Copy link
Contributor

Hi there ! This is my first PR to an open-source Rust repo after quite some time so bear with me please :-)

Tile-based decoding isn't much different from strip-based, it's just a matter of trying to fit it nicely into the existing codebase, which I tried really hard to do, but I didn't really come up with elegant code... I basically had to duplicate the whole expand_strip method.

I didn't add incremental decoding, because I wasn't sure about the API, but that can be easily done later.

I left a few TODOs in the code. Firstly, I need a good way of skipping some bytes from the Reader to skip padded tiles, but there doesn't seem to be a good way of doing it, so I just allocated one Vec, that I reuse for the whole image.

The other TODO is about errors. I'm not sure how pedantic the decoder should be. For example, the spec says "do not use both strip-oriented fields and tile-oriented fields in the same image", but I noticed that some libtiff test images contain both.

I also tried to add tile support for the JPEG decoder, but the JPEG implementation doesn't work for my test images #124 (comment), so I'll wait until that gets fixed.

Copy link
Member

@HeroicKatora HeroicKatora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think most of this looks very solid. Where are the images from, so as not to run into any copyright issues on work committed to git? (Their size is okay).

Firstly, I need a good way of skipping some bytes from the Reader to skip padded tiles, but there doesn't seem to be a good way of doing it, so I just allocated one Vec, that I reuse for the whole image.

This is fine by me. I'd suppose we could add something to the EndianReader here at some point. You could open an issue about this inefficiency.

I'm not sure how pedantic the decoder should be.

A good baseline is to try and accept anything that other libraries deal with, if there is no ambiguity. There's a larger question of how to report such warnings or violations to the user. In any case, one justification in the code and a FIXME comment is good enough, we can always relax this later if it appears to be an issue in practice.

src/decoder/mod.rs Outdated Show resolved Hide resolved
src/decoder/mod.rs Outdated Show resolved Hide resolved
@to-mas-kral
Copy link
Contributor Author

I don't like that I duplicated some code in the expand_strip/tile methods, so I'll try to refactor that.

The new test photos are mine, so there shouldn't be any problem about that.

How do you think the incremental API should work ?
The strip incremental API lets you read a few strips on their own and then read the rest of the image at once (at least I think that's how it works). The problem with this API for Tiles is that if the user doesn't read all of the tiles in a row, then they would get like an L-shaped result, which probably doesn't make sense. So I'd let the user read one tile at the time, but make it so the next call to read_image() returns the whole image.

@HeroicKatora
Copy link
Member

How do you think the incremental API should work ?

What do you think about actually returning an error when calling read_strip on a tiled image? The method is about the ability to efficiently access the underlying encoding and I'd argue it is the resposibility of the caller to ensure that this is the correct encoding. For tiles you could add a similar read_tile method.

@to-mas-kral
Copy link
Contributor Author

Sure, I added new error types for that.

Btw, I'm happy to see that @fintelia is working on simplifying the expand_strip function. I'll probably wait until that gets merged and try to mirror that for expand_tile.

@HeroicKatora
Copy link
Member

@TomasKralCZ Both of these have been merged, so you can reuse the refactored methods :)

@to-mas-kral
Copy link
Contributor Author

I think the code looks pretty good now.
One thing I'm not sure about is why @fintelia removed color inversion for signed formats. Is that non-standard behaviour ? I remember there was a comment about how libtiff interprets that in a certain way but it got removed.

Copy link
Contributor

@fintelia fintelia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some duplicated code that could probably be factored out, but that can happen in a followup.

@HeroicKatora HeroicKatora merged commit a874b9c into image-rs:master Apr 18, 2021
@to-mas-kral to-mas-kral deleted the tiles branch April 18, 2021 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants