Skip to content

Commit

Permalink
change: Removed AndroidBitmap, SkiBitmap, SkiaImageInfo, SkiaImage, S…
Browse files Browse the repository at this point in the history
…kiaRect, and renamed ComposeImagePainter to ImageBitmapPainter, SkiaAnimatedImage renamed to AnimatedImage, SkiaAnimatedImagePainter renamed to AnimatedImagePainter
  • Loading branch information
panpf committed Oct 13, 2024
1 parent a76eb27 commit 8b40e9a
Show file tree
Hide file tree
Showing 78 changed files with 686 additions and 796 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ Translations: [简体中文](CHANGELOG_zh.md)
* change: ErrorImageState is refactored into ConditionStateImage, and ConditionStateImage can be
used in placeholder and fallback
* change: Remove PainterState.Empty
* change: Removed AndroidBitmap, SkiBitmap, SkiaImageInfo, SkiaImage, SkiaRect, and renamed
ComposeImagePainter to ImageBitmapPainter, SkiaAnimatedImage renamed to AnimatedImage,
SkiaAnimatedImagePainter renamed to AnimatedImagePainter
* improve: Improve IconDrawable, support fixed-size background and restrict icons to have fixed
sizes or specify iconSize
* improve: Improve IconPainter, support fixed-size background and restrict icons to have fixed
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
* change: ErrorImageState 重构为 ConditionStateImage,并且 ConditionStateImage 可以用在 placeholder 和
fallback
* change: 移除 PainterState.Empty
* change: 移除 AndroidBitmap、SkiBitmap、SkiaImageInfo、SkiaImage、SkiaRect,ComposeImagePainter 重命名为
ImageBitmapPainter、SkiaAnimatedImage 重命名为 AnimatedImage、SkiaAnimatedImagePainter 重命名为
AnimatedImagePainter
* improve: 改进 IconDrawable,支持有固定大小的 background 并且限制 icon 必须有固定尺寸或指定 iconSize
* improve: 改进 IconPainter,支持有固定大小的 background 并且限制 icon 必须有固定尺寸或指定 iconSize
* new: 非安卓平台现在也支持 ColorType 了
Expand Down
2 changes: 1 addition & 1 deletion docs/wiki/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ when (image) {
is PainterImage -> {
val painter: Painter = image.painter
}
is SkiaAnimatedImage -> {
is AnimatedImage -> {
val codec: Codec = image.codec
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/wiki/getting_started_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ when (image) {
is PainterImage -> {
val painter: Painter = image.painter
}
is SkiaAnimatedImage -> {
is AnimatedImage -> {
val codec: Codec = image.codec
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.panpf.sketch.test.utils

import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap
import com.github.panpf.sketch.Bitmap
import com.github.panpf.sketch.ComposeBitmap

actual fun Bitmap.toComposeBitmap(): ComposeBitmap = this.asImageBitmap()
actual fun Bitmap.toComposeBitmap(): ImageBitmap = this.asImageBitmap()
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package com.github.panpf.sketch.test.utils

import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.github.panpf.sketch.Bitmap
import com.github.panpf.sketch.ComposeBitmap
import com.github.panpf.sketch.request.GlobalLifecycle

@Composable
Expand All @@ -30,8 +30,6 @@ fun PreviewContainer(content: @Composable () -> Unit) =
fun LifecycleContainer(content: @Composable () -> Unit) =
CompositionLocalProvider(LocalLifecycleOwner provides GlobalLifecycle.owner, content = content)

expect fun Bitmap.toComposeBitmap(): ComposeBitmap

typealias ComposeSize = androidx.compose.ui.geometry.Size
expect fun Bitmap.toComposeBitmap(): ImageBitmap

fun ComposeSize(width: Float, height: Float) = androidx.compose.ui.geometry.Size(width, height)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.panpf.sketch.test.utils

import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asComposeImageBitmap
import com.github.panpf.sketch.Bitmap
import com.github.panpf.sketch.ComposeBitmap

actual fun Bitmap.toComposeBitmap(): ComposeBitmap = this.asComposeImageBitmap()
actual fun Bitmap.toComposeBitmap(): ImageBitmap = this.asComposeImageBitmap()
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.github.panpf.sketch.test.utils

import com.github.panpf.sketch.Bitmap
import com.github.panpf.sketch.SkiaBitmap
import com.github.panpf.sketch.createBitmap
import com.github.panpf.sketch.images.ResourceImages
import org.jetbrains.skia.ColorType.RGBA_8888
import org.jetbrains.skia.ColorType.RGB_565

actual fun createBitmap(width: Int, height: Int): Bitmap {
return SkiaBitmap(width, height)
return createBitmap(width, height)
}

actual fun createARGBBitmap(width: Int, height: Int): Bitmap {
return SkiaBitmap(width, height, RGBA_8888)
return createBitmap(width, height, RGBA_8888)
}

actual fun create565Bitmap(width: Int, height: Int): Bitmap {
return SkiaBitmap(width, height, RGB_565)
return createBitmap(width, height, RGB_565)
}

actual fun getMutableBitmap(): Bitmap {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.github.panpf.sketch.test.utils

import com.github.panpf.sketch.BitmapImage
import com.github.panpf.sketch.SkiaBitmap
import com.github.panpf.sketch.SkiaImage
import com.github.panpf.sketch.asImage
import com.github.panpf.sketch.createBitmap
import com.github.panpf.sketch.source.DataSource
import okio.buffer
import okio.use
import org.jetbrains.skia.Image

actual fun createBitmapImage(width: Int, height: Int): BitmapImage =
SkiaBitmap(width, height).asImage()
createBitmap(width, height).asImage()

fun DataSource.toSkiaImage(): SkiaImage {
fun DataSource.toSkiaImage(): Image {
val exifBytes = openSource().buffer().use { it.readByteArray() }
return SkiaImage.makeFromEncoded(exifBytes)
return Image.makeFromEncoded(exifBytes)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ToFormatStringTest {
AndroidDrawableImage(
drawable=ResizeDrawable(
drawable=BitmapDrawable(
AndroidBitmap@a3a8b76(
Bitmap@a3a8b76(
233x350,
ARGB_8888,
SRGB
Expand All @@ -49,7 +49,7 @@ class ToFormatStringTest {
shareable=true
)
""".trimIndent(),
actual = "AndroidDrawableImage(drawable=ResizeDrawable(drawable=BitmapDrawable(AndroidBitmap@a3a8b76(233x350,ARGB_8888,SRGB)), size=690x690, scale=CENTER_CROP), shareable=true)"
actual = "AndroidDrawableImage(drawable=ResizeDrawable(drawable=BitmapDrawable(Bitmap@a3a8b76(233x350,ARGB_8888,SRGB)), size=690x690, scale=CENTER_CROP), shareable=true)"
.toFormattedString()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.github.panpf.sketch.AnimatedImage
import com.github.panpf.sketch.LocalPlatformContext
import com.github.panpf.sketch.SingletonSketch
import com.github.panpf.sketch.SkiaAnimatedImage
import com.github.panpf.sketch.images.ResourceImages
import com.github.panpf.sketch.painter.SkiaAnimatedImagePainter
import com.github.panpf.sketch.painter.AnimatedImagePainter
import com.github.panpf.sketch.request.ImageRequest
import com.github.panpf.sketch.request.RequestContext
import com.github.panpf.sketch.request.animationEndCallback
Expand Down Expand Up @@ -71,7 +71,7 @@ class DesktopTempTestScreen : BaseScreen() {
// modifier = Modifier.size(200.dp).background(Color.Cyan)
// )

var animatedPainter by remember { mutableStateOf<SkiaAnimatedImagePainter?>(null) }
var animatedPainter by remember { mutableStateOf<AnimatedImagePainter?>(null) }
val context = LocalPlatformContext.current
LaunchedEffect(Unit) {
withContext(ioCoroutineDispatcher()) {
Expand All @@ -84,14 +84,14 @@ class DesktopTempTestScreen : BaseScreen() {
.use { it.readByteArray() }

val data = Data.makeFromBytes(bytes)
val image = SkiaAnimatedImage(
val image = AnimatedImage(
codec = Codec.makeFromData(data),
repeatCount = null,
cacheDecodeTimeoutFrame = true,
animationStartCallback = request.animationStartCallback,
animationEndCallback = request.animationEndCallback
)
animatedPainter = SkiaAnimatedImagePainter(
animatedPainter = AnimatedImagePainter(
animatedImage = image,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.github.panpf.sketch.BitmapImage
import com.github.panpf.sketch.Image
import com.github.panpf.sketch.SkiaBitmap
import com.github.panpf.sketch.cache.CachePolicy.DISABLED
import com.github.panpf.sketch.createBitmap
import com.github.panpf.sketch.decode.BitmapColorType
import com.github.panpf.sketch.images.ResourceImages
import com.github.panpf.sketch.request.ComposableImageRequest
Expand Down Expand Up @@ -108,7 +108,7 @@ class SkiaColorTypeTestScreen : BaseScreen() {
override fun transform(requestContext: RequestContext, input: Image): TransformResult {
val inputBitmap = (input as BitmapImage).bitmap
val intPixels = inputBitmap.readIntPixels()
val newSkiaBitmap = SkiaBitmap(inputBitmap.imageInfo)
val newSkiaBitmap = createBitmap(inputBitmap.imageInfo)
newSkiaBitmap.installIntPixels(intPixels)
return TransformResult(
image = input.copy(bitmap = newSkiaBitmap),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

package com.github.panpf.sketch.decode.internal

import com.github.panpf.sketch.SkiaAnimatedImage
import com.github.panpf.sketch.SkiaImageInfo
import com.github.panpf.sketch.AnimatedImage
import com.github.panpf.sketch.decode.DecodeConfig
import com.github.panpf.sketch.decode.DecodeResult
import com.github.panpf.sketch.decode.Decoder
Expand Down Expand Up @@ -95,15 +94,15 @@ open class SkiaAnimatedDecoder(
val decodeConfig = DecodeConfig(request, imageInfo.mimeType, codec.isOpaque)
val newColorType = decodeConfig.colorType ?: codec.imageInfo.colorType
val newColorSpace = decodeConfig.colorSpace ?: codec.imageInfo.colorSpace
val skiaImageInfo = SkiaImageInfo(
val skiaImageInfo = org.jetbrains.skia.ImageInfo(
width = codec.imageInfo.width,
height = codec.imageInfo.height,
colorType = newColorType,
alphaType = codec.imageInfo.colorAlphaType,
colorSpace = newColorSpace
)
// TODO Support animatedTransformation
val animatedImage = SkiaAnimatedImage(
val animatedImage = AnimatedImage(
codec = codec,
imageInfo = skiaImageInfo,
repeatCount = repeatCount,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.panpf.sketch.animated.nonandroid.test.decode

import com.github.panpf.sketch.AnimatedImage
import com.github.panpf.sketch.ComponentRegistry
import com.github.panpf.sketch.SkiaAnimatedImage
import com.github.panpf.sketch.decode.GifSkiaAnimatedDecoder
import com.github.panpf.sketch.decode.ImageInfo
import com.github.panpf.sketch.decode.supportSkiaGif
Expand Down Expand Up @@ -116,7 +116,7 @@ class GifSkiaAnimatedDecoderTest {
assertEquals(expected = Size(480, 480), actual = image.size)
assertEquals(expected = LOCAL, actual = this.dataFrom)
assertEquals(expected = null, actual = this.transformeds)
assertEquals(expected = null, actual = image.asOrThrow<SkiaAnimatedImage>().repeatCount)
assertEquals(expected = null, actual = image.asOrThrow<AnimatedImage>().repeatCount)
}

ImageRequest(context, ResourceImages.animGif.uri) {
Expand All @@ -127,7 +127,7 @@ class GifSkiaAnimatedDecoderTest {
assertEquals(expected = Size(480, 480), actual = image.size)
assertEquals(expected = LOCAL, actual = this.dataFrom)
assertEquals(expected = null, actual = this.transformeds)
assertEquals(expected = 3, actual = image.asOrThrow<SkiaAnimatedImage>().repeatCount)
assertEquals(expected = 3, actual = image.asOrThrow<AnimatedImage>().repeatCount)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.panpf.sketch.animated.nonandroid.test.decode

import com.github.panpf.sketch.AnimatedImage
import com.github.panpf.sketch.ComponentRegistry
import com.github.panpf.sketch.SkiaAnimatedImage
import com.github.panpf.sketch.decode.ImageInfo
import com.github.panpf.sketch.decode.WebpSkiaAnimatedDecoder
import com.github.panpf.sketch.decode.supportSkiaAnimatedWebp
Expand Down Expand Up @@ -116,7 +116,7 @@ class WebpSkiaAnimatedDecoderTest {
assertEquals(expected = Size(width = 480, height = 270), actual = image.size)
assertEquals(expected = LOCAL, actual = this.dataFrom)
assertEquals(expected = null, actual = this.transformeds)
assertEquals(expected = null, actual = image.asOrThrow<SkiaAnimatedImage>().repeatCount)
assertEquals(expected = null, actual = image.asOrThrow<AnimatedImage>().repeatCount)
}

ImageRequest(context, ResourceImages.animWebp.uri) {
Expand All @@ -127,7 +127,7 @@ class WebpSkiaAnimatedDecoderTest {
assertEquals(expected = Size(width = 480, height = 270), actual = image.size)
assertEquals(expected = LOCAL, actual = this.dataFrom)
assertEquals(expected = null, actual = this.transformeds)
assertEquals(expected = 3, actual = image.asOrThrow<SkiaAnimatedImage>().repeatCount)
assertEquals(expected = 3, actual = image.asOrThrow<AnimatedImage>().repeatCount)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.FilterQuality
import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.graphics.painter.ColorPainter
import com.github.panpf.sketch.AndroidBitmap
import com.github.panpf.sketch.asImage
import com.github.panpf.sketch.asPainter
import com.github.panpf.sketch.painter.ComposeBitmapPainter
import com.github.panpf.sketch.createBitmap
import com.github.panpf.sketch.painter.DrawableAnimatablePainter
import com.github.panpf.sketch.painter.DrawablePainter
import com.github.panpf.sketch.painter.ImageBitmapPainter
import com.github.panpf.sketch.test.utils.FakeImage
import com.github.panpf.sketch.test.utils.TestAnimatableDrawable
import com.github.panpf.sketch.test.utils.TestColor
Expand All @@ -35,15 +35,15 @@ class PainterImageAndroidTest {
actual = colorPainter.asImage().asPainter()
)

val bitmap = AndroidBitmap(100, 100)
val bitmap = createBitmap(100, 100)
assertEquals(
expected = FilterQuality.Low,
actual = bitmap.asImage().asPainter().asOrThrow<ComposeBitmapPainter>().filterQuality
actual = bitmap.asImage().asPainter().asOrThrow<ImageBitmapPainter>().filterQuality
)
assertEquals(
expected = FilterQuality.High,
actual = bitmap.asImage().asPainter(FilterQuality.High)
.asOrThrow<ComposeBitmapPainter>().filterQuality
.asOrThrow<ImageBitmapPainter>().filterQuality
)

val animatableDrawable = TestAnimatableDrawable(ColorDrawable(TestColor.RED))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.graphics.painter.ColorPainter
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.runComposeUiTest
import com.github.panpf.sketch.AndroidBitmap
import com.github.panpf.sketch.createBitmap
import com.github.panpf.sketch.drawable.asEquitable
import com.github.panpf.sketch.painter.DrawableAnimatablePainter
import com.github.panpf.sketch.painter.DrawablePainter
Expand Down Expand Up @@ -54,7 +54,7 @@ class DrawablePainterTest {
)
}

val bitmap = remember { AndroidBitmap(100, 100) }
val bitmap = remember { createBitmap(100, 100) }
rememberDrawablePainter(BitmapDrawable(null, bitmap).asEquitable(bitmap)).apply {
assertEquals(
expected = DrawablePainter(
Expand Down Expand Up @@ -111,7 +111,7 @@ class DrawablePainterTest {
)
}

BitmapDrawable(null, AndroidBitmap(100, 100)).asPainter().apply {
BitmapDrawable(null, createBitmap(100, 100)).asPainter().apply {
assertTrue(
actual = this is BitmapPainter,
message = "Expected: BitmapPainter, actual: $this"
Expand Down

This file was deleted.

Loading

0 comments on commit 8b40e9a

Please sign in to comment.