Skip to content

Commit

Permalink
Commonize some of SubSamplingImage's files
Browse files Browse the repository at this point in the history
  • Loading branch information
saket committed Jan 4, 2025
1 parent dbd3218 commit 99b24b9
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 7 deletions.
3 changes: 3 additions & 0 deletions zoomable-image/sub-sampling-image/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ kotlin {
implementation(compose.uiUtil)
implementation(libs.kotlinx.immutableCollections)
}
commonTest.dependencies {
implementation(kotlin("test"))
}
androidMain {
dependencies {
implementation(libs.androidx.ktx.core)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package me.saket.telephoto.subsamplingimage.internal

import androidx.compose.ui.semantics.SemanticsPropertyKey
import androidx.compose.ui.semantics.SemanticsPropertyReceiver
import androidx.compose.ui.unit.IntSize
import kotlinx.collections.immutable.ImmutableList

internal val ImageSemanticStateKey = SemanticsPropertyKey<SubSamplingImageSemanticState>("ImageSemanticState")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

package me.saket.telephoto.subsamplingimage.internal

import android.graphics.BitmapFactory
import androidx.compose.runtime.Immutable
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.unit.IntRect
import kotlin.jvm.JvmInline

/** A region in the source image that will be drawn in a [ViewportTile]. */
@Immutable
Expand Down Expand Up @@ -57,7 +57,16 @@ internal data class ViewportImageTile(
val isBase get() = tile.isBase
}

/** See [BitmapFactory.Options.inSampleSize]. */
/**
* Documentation copied from `android.graphics.BitmapFactory.Options.inSampleSize`:
*
* If set to a value > 1, requests the decoder to sub-sample the original image, returning
* a smaller image to save memory. The sample size is the number of pixels in either dimension
* that correspond to a single pixel in the decoded bitmap. For example, inSampleSize == 4
* returns an image that is 1/4 the width/height of the original, and 1/16 the number of
* pixels. Any value <= 1 is treated the same as 1. Note: the decoder uses a final value
* based on powers of 2, any other value will be rounded down to the nearest power of 2.
*/
@JvmInline
internal value class ImageSampleSize(val size: Int) {
companion object; // For extensions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import assertk.assertions.isEqualTo
import assertk.assertions.isLessThan
import assertk.assertions.isNotEmpty
import assertk.assertions.isNull
import org.junit.Ignore
import org.junit.Test
import kotlin.random.Random
import kotlin.random.nextInt
import kotlin.test.Ignore
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.measureTime
import kotlin.test.Test

class ImageRegionTileGridGeneratorTest {

Expand Down Expand Up @@ -111,7 +111,7 @@ class ImageRegionTileGridGeneratorTest {
}
}

@Ignore("The output of this test is different when it's run individually vs with the whole class")
@Ignore // "The output of this test is different when it's run individually vs with the whole class"
@Test fun `generation of tiles should be fast enough to be run on the main thread`() {
val time = measureTime {
repeat(1_000) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import androidx.compose.ui.unit.toRect
import androidx.core.graphics.toRect
import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isIn
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
Expand Down

0 comments on commit 99b24b9

Please sign in to comment.