Skip to content

Commit

Permalink
Add a test for enabling hdr color mode
Browse files Browse the repository at this point in the history
  • Loading branch information
saket committed Dec 7, 2024
1 parent 5043a65 commit 0575f7f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package me.saket.telephoto.subsampling

import android.content.Context
import android.content.pm.ActivityInfo
import android.graphics.BitmapFactory
import android.net.Uri
import androidx.compose.foundation.border
Expand Down Expand Up @@ -817,6 +818,43 @@ class SubSamplingImageTest {
}
}

@Test fun enable_hdr_color_mode_for_images_that_contain_ultra_hdr_content() {
assertThat(rule.activity.window.colorMode).isEqualTo(ActivityInfo.COLOR_MODE_DEFAULT)

var imageAssetName by mutableStateOf("fox_1000.jpg")
rule.setContent {
val zoomableState = rememberZoomableState()
SubSamplingImage(
modifier = Modifier
.fillMaxSize()
.zoomable(zoomableState)
.testTag("image"),
state = rememberSubSamplingImageState(
zoomableState = zoomableState,
imageSource = SubSamplingImageSource.asset(imageAssetName),
),
contentDescription = null,
)
}

rule.waitUntil {
rule.onNodeWithTag("image").isImageDisplayed()
}
assertThat(rule.activity.window.colorMode).isEqualTo(ActivityInfo.COLOR_MODE_DEFAULT)

imageAssetName = "vadapav_ultra_hdr.jpg"
rule.waitUntil {
rule.onNodeWithTag("image").isImageDisplayedInFullQuality()
}
assertThat(rule.activity.window.colorMode).isEqualTo(ActivityInfo.COLOR_MODE_HDR)

imageAssetName = "path.jpg"
rule.waitUntil {
rule.onNodeWithTag("image").isImageDisplayedInFullQuality()
}
assertThat(rule.activity.window.colorMode).isEqualTo(ActivityInfo.COLOR_MODE_DEFAULT)
}

@Suppress("unused")
enum class LayoutSizeParam(val modifier: Modifier) {
FillMaxSize(Modifier.fillMaxSize()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal class AndroidImageRegionDecoder private constructor(
val options = BitmapFactory.Options().apply {
inSampleSize = region.sampleSize.size
inPreferredConfig = imageOptions.config.toAndroidConfig()
if (Build.VERSION.SDK_INT >= 26) {
if (SDK_INT >= 26) {
inPreferredColorSpace = imageOptions.androidColorSpace
}
}
Expand Down

0 comments on commit 0575f7f

Please sign in to comment.