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

make progress callback mutable #1694

Conversation

johannesvollmer
Copy link
Contributor

@johannesvollmer johannesvollmer commented Apr 2, 2022

see #1488

note: this will break any downstream implementations of ImageDecoder::read_image_with_progress and ImageDecoderRect::read_rect_with_progress. However, it most cases, it should be easy to fix, just by making the callback parameter mutable. Only where the progress callback is captured or sent in multiple places, more changes might be required.

which branch should it go?

@HeroicKatora
Copy link
Member

The only case where this is less general is when F is recursive, right? We never required Send or Sync so it's not possible to call the callback from a parallel decoder in the current state anyways.

src/image.rs Outdated Show resolved Hide resolved
@johannesvollmer
Copy link
Contributor Author

johannesvollmer commented Apr 7, 2022

Fixing the formatting...

@HeroicKatora HeroicKatora marked this pull request as ready for review April 7, 2022 18:17
@HeroicKatora
Copy link
Member

Well, not sure if that was the right button. My brain assumed it was the Approve for Run for reasons of placement… It seems like it wasn't completely wrong though 😂

@@ -152,10 +152,10 @@ impl<'a, R: 'a + Read + Seek> ImageDecoder<'a> for OpenExrDecoder<R> {
}

// reads with or without alpha, depending on `self.alpha_preference` and `self.alpha_present_in_file`
fn read_image_with_progress<F: Fn(Progress)>(
fn read_image_with_progress<F: FnMut(Progress)>(
Copy link
Contributor Author

@johannesvollmer johannesvollmer Apr 7, 2022

Choose a reason for hiding this comment

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

So, @HeroicKatora will there be any problem with recursion of the progress callback? If yes, is it even relevant, would it happen in the real world?

Copy link
Member

Choose a reason for hiding this comment

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

No, I don't believe so. Only a really small fraction will be recursive, if any, and our default implementation handles this gracefully.

@fintelia
Copy link
Contributor

fintelia commented Apr 7, 2022

Is there a particular rush to expose this feature? It feels like a lot of churn to add read_image_with_progress_mut in 0.24.x, deprecate it in 0.25.x, and remove in 0.26.x. So if it is possible to work around this for now (which I think it might be using Rc<RefCell> ?), I'd prefer to do that and just change the type signature of read_image_with_progress for 0.25.x.

@johannesvollmer
Copy link
Contributor Author

No, we could also note this down for the next major release

@HeroicKatora HeroicKatora changed the base branch from master to next-version-0.25 May 18, 2022 18:03
@HeroicKatora
Copy link
Member

I've create a new branch next-version-0.25 for all breaking changes. Feel free to amend everything into the breaking change then.

@fintelia fintelia mentioned this pull request Jun 10, 2023
19 tasks
@johannesvollmer
Copy link
Contributor Author

todo:

  • just change the type signature of read_image_with_progress for 0.25.x instead of adding a backwards-compatible variant

@johannesvollmer
Copy link
Contributor Author

@fintelia is the current stance to remove progress completely?

@fintelia
Copy link
Contributor

That's the plan at the moment, yes.

It turns out that having a method taking a callback function prevents the ImageDecoder trait from being object safe, which is a goal for the 0.25.x release. This however leaves open the possibility of adding an additional non-object safe trait for incremental decoding (like how we also have ImageDecoderRect), which we'd be able to do in a backwards compatible way

@johannesvollmer
Copy link
Contributor Author

johannesvollmer commented Feb 13, 2024

Maybe removing it now allows someone in the future to add it back in without breaking object safety. Let's remove it for now.

Or perhaps the byte-level adapter for the input stream would be a good way to do it in the future, maybe completely separate from this crate.

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