Skip to content

Commit

Permalink
MediaView: Move HDR gain map reading to IO.
Browse files Browse the repository at this point in the history
It should help with media view scrolling lag (#578, #518)

Signed-off-by: IacobIonut01 <[email protected]>
  • Loading branch information
IacobIonut01 committed Feb 4, 2025
1 parent 4df3d45 commit 8afe53e
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ fun <T : Media> MediaViewScreen(
// set HDR Gain map
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
LaunchedEffect(mediaState.value) {
withContext(Dispatchers.IO) {
snapshotFlow { pagerState.currentPage }.collectLatest {
printWarning("Trying to set HDR mode for page $it")
if (currentMedia?.isImage == true) {
Expand All @@ -338,17 +339,20 @@ fun <T : Media> MediaViewScreen(
value = currentMedia?.mimeType,
)
}
val result = withContext(Dispatchers.IO) {
context.sketch.execute(request)
}
val result = context.sketch.execute(request)
(result.image as? BitmapImage)?.bitmap?.let { bitmap ->
val hasGainmap = bitmap.hasGainmap()
withContext(Dispatchers.Main.immediate) {
context.setHdrMode(hasGainmap)
}
printWarning("Setting HDR Mode to $hasGainmap")
} ?: printWarning("Resulting image null")
} else {
withContext(Dispatchers.Main.immediate) {
context.setHdrMode(false)
}
printWarning("Not an image, skipping")
}
}
}
}
Expand Down

0 comments on commit 8afe53e

Please sign in to comment.