Skip to content

Commit

Permalink
fix: Fixed the bug that Transformations such as blur and rotate on th…
Browse files Browse the repository at this point in the history
…e Android platform did not keep the ColorSpace unchanged. (#213)
  • Loading branch information
panpf committed Oct 14, 2024
1 parent 8b40e9a commit f53903b
Show file tree
Hide file tree
Showing 9 changed files with 752 additions and 311 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Translations: [简体中文](CHANGELOG_zh.md)
expected. [#210](https://github.com/panpf/sketch/issues/210)
* fix: Fix the bug that the filterQuality parameter of AsyncImage is
invalid. [#211](https://github.com/panpf/sketch/issues/211)
* fix: Fixed the bug that Transformations such as blur and rotate on the Android platform did not
keep the ColorSpace unchanged. [#213](https://github.com/panpf/sketch/issues/211)
* remove: Remove ComposeBitmapImage
* remove: Remove Image.getPixels()
* change: SkiaBitmapImage is now cached in the memory cache on non-Android platforms, not
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
的 equals 方法未按预期执行的 bug。 [#210](https://github.com/panpf/sketch/issues/210)
* fix: 修复 AsyncImage 的 filterQuality 参数无效的
bug。 [#211](https://github.com/panpf/sketch/issues/211)
* fix: 修复 Android 平台上 blur、rotate 等 Transformation 没有保持 ColorSpace 不变的
bug。 [#213](https://github.com/panpf/sketch/issues/211)
* remove: 移除 ComposeBitmapImage
* remove: 删除 Image.getPixels()
* change: 现在非安卓平台上内存缓存中缓存的是 SkiaBitmapImage,不再是 ComposeBitmapImage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.github.panpf.sketch.core.android.test

import android.graphics.Bitmap
import android.graphics.Bitmap.Config.ARGB_8888
import android.graphics.Bitmap.Config.RGB_565
import android.graphics.ColorSpace
import android.os.Build
import com.github.panpf.sketch.ColorType
import com.github.panpf.sketch.colorType
import com.github.panpf.sketch.createBitmap
import com.github.panpf.sketch.createEmptyBitmapWith
import com.github.panpf.sketch.images.ResourceImages
import com.github.panpf.sketch.isImmutable
import com.github.panpf.sketch.size
Expand Down Expand Up @@ -119,4 +122,115 @@ class BitmapAndroidTest {
)
}
}

@Test
fun testCreateEmptyBitmapWith() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Bitmap.createBitmap(
/* width = */ 101,
/* height = */ 202,
/* config = */ Bitmap.Config.ARGB_8888,
/* hasAlpha = */ true,
/* colorSpace = */ ColorSpace.get(ColorSpace.Named.SRGB)
).apply {
assertEquals(expected = 101, actual = width)
assertEquals(expected = 202, actual = height)
assertEquals(expected = ColorType.ARGB_8888, actual = config)
assertEquals(expected = true, actual = hasAlpha())
assertEquals(expected = ColorSpace.get(ColorSpace.Named.SRGB), actual = colorSpace)
}.createEmptyBitmapWith(
width = 202,
height = 101,
colorType = RGB_565,
hasAlpha = false
).apply {
assertEquals(expected = 202, actual = width)
assertEquals(expected = 101, actual = height)
assertEquals(expected = ColorType.RGB_565, actual = config)
assertEquals(expected = false, actual = hasAlpha())
assertEquals(expected = ColorSpace.get(ColorSpace.Named.SRGB), actual = colorSpace)
}.createEmptyBitmapWith(
size = Size(100, 100),
colorType = RGB_565,
hasAlpha = false
).apply {
assertEquals(expected = 100, actual = width)
assertEquals(expected = 100, actual = height)
assertEquals(expected = ColorType.RGB_565, actual = config)
assertEquals(expected = false, actual = hasAlpha())
assertEquals(expected = ColorSpace.get(ColorSpace.Named.SRGB), actual = colorSpace)
}

Bitmap.createBitmap(
/* width = */ 101,
/* height = */ 202,
/* config = */ Bitmap.Config.ARGB_8888,
/* hasAlpha = */ true,
/* colorSpace = */ ColorSpace.get(ColorSpace.Named.DISPLAY_P3)
).apply {
assertEquals(expected = 101, actual = width)
assertEquals(expected = 202, actual = height)
assertEquals(expected = ColorType.ARGB_8888, actual = config)
assertEquals(expected = true, actual = hasAlpha())
assertEquals(
expected = ColorSpace.get(ColorSpace.Named.DISPLAY_P3),
actual = colorSpace
)
}.createEmptyBitmapWith(
width = 202,
height = 101,
colorType = RGB_565,
hasAlpha = false
).apply {
assertEquals(expected = 202, actual = width)
assertEquals(expected = 101, actual = height)
assertEquals(expected = ColorType.RGB_565, actual = config)
assertEquals(expected = false, actual = hasAlpha())
assertEquals(
expected = ColorSpace.get(ColorSpace.Named.DISPLAY_P3),
actual = colorSpace
)
}.createEmptyBitmapWith(
size = Size(100, 100),
colorType = RGB_565,
hasAlpha = false
).apply {
assertEquals(expected = 100, actual = width)
assertEquals(expected = 100, actual = height)
assertEquals(expected = ColorType.RGB_565, actual = config)
assertEquals(expected = false, actual = hasAlpha())
assertEquals(
expected = ColorSpace.get(ColorSpace.Named.DISPLAY_P3),
actual = colorSpace
)
}
} else {
Bitmap.createBitmap(
/* width = */ 101,
/* height = */ 202,
/* config = */ Bitmap.Config.ARGB_8888,
).apply {
assertEquals(expected = 101, actual = width)
assertEquals(expected = 202, actual = height)
assertEquals(expected = ColorType.ARGB_8888, actual = config)
}.createEmptyBitmapWith(
width = 202,
height = 101,
colorType = RGB_565,
hasAlpha = false
).apply {
assertEquals(expected = 202, actual = width)
assertEquals(expected = 101, actual = height)
assertEquals(expected = ColorType.RGB_565, actual = config)
}.createEmptyBitmapWith(
size = Size(100, 100),
colorType = RGB_565,
hasAlpha = false
).apply {
assertEquals(expected = 100, actual = width)
assertEquals(expected = 100, actual = height)
assertEquals(expected = ColorType.RGB_565, actual = config)
}
}
}
}
Loading

0 comments on commit f53903b

Please sign in to comment.