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

Share AssetFileDescriptor with ImageDecoder #1990

Merged
merged 4 commits into from
Jan 3, 2024
Merged

Share AssetFileDescriptor with ImageDecoder #1990

merged 4 commits into from
Jan 3, 2024

Conversation

revonateB0T
Copy link
Contributor

@revonateB0T revonateB0T commented Jan 2, 2024

Close #1970

@@ -30,30 +30,28 @@ internal class ContentUriFetcher(
override suspend fun fetch(): FetchResult {
val androidUri = data.toAndroidUri()
val contentResolver = options.context.contentResolver
val inputStream = if (isContactPhotoUri(data)) {
val afd = if (isContactPhotoUri(data)) {
Copy link
Member

Choose a reason for hiding this comment

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

Separate to this PR, but will ImageDecoder.createSource(options.context.contentResolver, metadata.uri.toAndroidUri()) correctly handle this special case for a contacts image URI?

One of the issues with passing this data to StaticImageDecoderDecoder is we're coupling the source with the decoder.

Copy link
Contributor Author

@revonateB0T revonateB0T Jan 3, 2024

Choose a reason for hiding this comment

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

Separate to this PR, but will ImageDecoder.createSource(options.context.contentResolver, metadata.uri.toAndroidUri()) correctly handle this special case for a contacts image URI?

One of the issues with passing this data to StaticImageDecoderDecoder is we're coupling the source with the decoder.

Haven't test it, but now ImageDecoder use a afd that InputStream use for this case so it doesn't matter
And ImageDecoder should work as it use openAssetFileDescriptor internally as well

And about coupling, I think we have to couple it as both BitmapFactory and ImageDecoder doesn't have a appropriate API to pass a "native" stream(SkStream like), and okio is ByteArray based.
Ideally we could abstract all source to a "ByteBufferStream" which could use DirectByteBuffer as internal storage(on other platform just a native allocated buffer), but things is neither okio nor decoder support it
But kotlinx-io is doing such thing

The best we can do is, if the source is file backed and can be used directly(i.e. uri, File), just let decoder use it directly

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.

[Coil 3] Lazy allocated BufferedSource for ImageSource
2 participants