Blurhash support, contribution request
I'll consider it, please submit your merge request.
All the changes I needed to make have been made in the dev-blurhash branch.
There are several important changes that you need to be aware of:
- Removed dependency on compose and related remember functions, because this module also needs to consider Android view scenarios
- The newBlurHashUri function adds url encoding to prevent the blurhash string from destroying the uri structure.
- The cache key in BlurHashStateImage is spliced with the bitmap size, and asynchronous decoding is removed. Asynchronous decoding cannot be used here. For specific reasons, please see the comments in the source code.
I still have a few questions about BlurHashUtil :
- The source code has been significantly modified compared to cbeyls. You may not be able to upgrade from cbeyls in the future. I hope it remains completely consistent. If you must modify it, you can keep most of the code consistent and only modify the necessary parts.
- The outputheight parameter in BlurHashUtil:163 is not used. You need to check whether there is a problem here.
2 - outputwidth, outputheight and output (to decode smaller blurhash into bigger canvas) aren't needed since you suggested not to use sharing bitmaps, so could be removed. https://github.com/panpf/sketch/pull/265
1 - Beside the point above, I'd leave the code as it is now. Both have same extracted helping functions. In case new version of an algo is introduced, and modifying current algo won't be obvious, they could be easily compared in performance since have same set of input arguments (except original algo immediately sets pixels from array into bitmap).
The dev branch has been updated and the relevant documentation is ready.
https://github.com/panpf/sketch/blob/dev/docs/blurhash.md
Please check if there are any problems.
I see you switched to use ? as blurhash and size separator in blurhash uri, it seems there is an issue with parsing blurhash string uri in this case since question mark could be a part of blurhash string.
For instance UHF5?xYk^6#M@-5b,1J5@[or[k6.};FxngOZ.
Yes, this is the rule of the URI protocol, the path and query must be separated by a question mark.
So I uri-encoded blurhash in the newBlurHashUri function.
https://github.com/panpf/sketch/blob/d7a0f4dff2556b08207580403de3e621e95a4f43/sketch-blurhash/src/commonMain/kotlin/com/github/panpf/sketch/fetch/BlurHashUriFetcher.kt#L47
Added in 4.4.0-alpha01.
@0sten Version 4.4.0-alpha01 with blurhash has been out for a while now, and I wanted to know if you’ve been using or testing it. I’d love to hear your feedback.
It works fine for my app, thanks! that's how I use it in grid's code:
AsyncImage(
uri = uploadPresentable.imageThumbUri.uri,
contentDescription = "uploadId= ${uploadPresentable.upload.uploadId}",
modifier = Modifier.matchParentSize(),
contentScale = ContentScale.Crop,
state = rememberAsyncImageState(ComposableImageOptions {
if (uploadPresentable.upload.meta.blurhash?.isNotEmpty() == true) {
val blurhashSize = BLURHASH_IN_GRID_SIZE
val blurHashStateImage = BlurHashStateImage(
uploadPresentable.upload.meta.blurhash,
blurhashSize
)
placeholder(blurHashStateImage)
error(blurHashStateImage)
fallback(blurHashStateImage)
}
})
)
https://github.com/user-attachments/assets/6e2424ee-9952-404f-a099-1b0e86d73a16