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

Support progressive JPEGs / incremental WebP decoding #940

Open
andob opened this issue Oct 10, 2021 · 7 comments
Open

Support progressive JPEGs / incremental WebP decoding #940

andob opened this issue Oct 10, 2021 · 7 comments
Labels
enhancement New feature or request

Comments

@andob
Copy link

andob commented Oct 10, 2021

Most image loading libraries load the image (from network / disk cache / memory cache) then the image gets displayed into imageview.

Yet browsers can progressively display images as they are downloaded, that is - start the download, display a low quality version of the image, then increase the quality as more parts of the file gets downloaded.

Right now the only android library that can progressively load images is Fresco, as you can see on this page. However, in any other aspect, Fresco seem to be inferior.

This feature can be very useful when loading big images on low bandwidth networks.

Could Coil library implement such feature?

@andob
Copy link
Author

andob commented Oct 10, 2021

could be useful - progressive JPEG files are encoded in such way that the browser (or any other software) could load them progressively. I don't think / don't know if android's native bitmap decoder (BitmapFactory.decode) can do this.

@andob
Copy link
Author

andob commented Oct 10, 2021

another similar issue on Picasso repo

@colinrtwhite colinrtwhite added enhancement New feature or request help wanted Issues that are up for grabs + are good candidates for community PRs labels Oct 10, 2021
@colinrtwhite colinrtwhite changed the title support progressive image loading / progressive JPEGs Oct 10, 2021
@colinrtwhite
Copy link
Member

colinrtwhite commented Oct 10, 2021

It's not possible to support this for generic file types - only JPEGs that have been specially encoded for progressive decoding can do this. Android doesn't support progressive JPEGs so you'd need to write a custom Decoder to support this.

@andob
Copy link
Author

andob commented Oct 11, 2021

I think we have to rely on a C library to decode. Before the time iOS had native support of progressive jpegs, there was Concorde - that was based on libjpeg-turbo. Tubo has java bindings, but the roundtrip time of JNI method invocation is slow on android, would be best to minimise the number of JNI calls.

I can try to contribute on this with a pull request.

I can write C code but I'm not sure I can write C code well. I'm currently learning rust. Rust guarantees memory safety at compile time, without giving the programmer the reposability to release memory - but at the same time it doesn't have a GC. I can try to write the native part of the decoder in rust (+ libjpeg-turbo or mozjpeg or whatever), and then call rust code from kotlin via JNI. Would that be ok with you?

@colinrtwhite
Copy link
Member

Hmm I'd like to keep Coil and any extension libraries 100% Kotlin code (and no native code) since it can greatly increase APK size. If it's only possible with native code then I think this is a good candidate for an external extension library (happy to link to it).

@andob
Copy link
Author

andob commented Oct 11, 2021

I'm no expert, but as far as I researched, there is no standard Android SDK way to decode progressive JPEG. Standard Java has ImageIO API that supports it, however those classes also depend on native code, assuming the code could be ported to android. Another option would be libjpeg-turbo or other native decoder library. Fresco also relies on native code.

Ideally Google developers should implement some new API on the Android SDK itself for this, starting with Android 13, and another Jetpack support library to backport the feature. This could open possibility to implement this feature on any image loading library, Glide, Picasso, Coil.

Submitted an issue on Google Issue tracker to ask for such API. Let's wait to see what is their take on the matter..

@colinrtwhite colinrtwhite changed the title Support progressive image loading / progressive JPEGs Oct 11, 2021
@colinrtwhite
Copy link
Member

I'd be surprised if Google implements this in AndroidX since it seems out of scope (androidx also disallows using native libraries), but it's worth submitting a ticket. It's also not clear how much use progressive JPEG sees today; if it's small it might not be worth the large effort to implement.

Also, it looks like BitmapFactory already supports progressive JPEG (which means Coil already supports it too), however it only outputs the final image - not the intermediate frames.

Also it looks like WebP supports something similar to progressive JPEG so I added it to this ticket.

@colinrtwhite colinrtwhite removed the help wanted Issues that are up for grabs + are good candidates for community PRs label Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
2 participants