mirror of
https://github.com/nacabaro/vbhelper.git
synced 2026-01-27 16:05:32 +00:00
Merge pull request #13 from cfogrady/TransparentBackground
Make background on characters and icons transparent.
This commit is contained in:
commit
7f22650601
@ -13,7 +13,9 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.FilterQuality
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.github.nacabaro.vbhelper.domain.Sprites
|
||||
import com.github.nacabaro.vbhelper.utils.BitmapData
|
||||
import com.github.nacabaro.vbhelper.utils.getBitmap
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
@Composable
|
||||
@ -23,9 +25,7 @@ fun CharacterEntry(
|
||||
onClick: () -> Unit = { }
|
||||
) {
|
||||
val bitmap = remember (icon.bitmap) {
|
||||
Bitmap.createBitmap(icon.width, icon.height, Bitmap.Config.RGB_565).apply {
|
||||
copyPixelsFromBuffer(ByteBuffer.wrap(icon.bitmap))
|
||||
}
|
||||
icon.getBitmap()
|
||||
}
|
||||
val imageBitmap = remember(bitmap) { bitmap.asImageBitmap() }
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@ import androidx.compose.ui.graphics.FilterQuality
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.github.nacabaro.vbhelper.utils.BitmapData
|
||||
import com.github.nacabaro.vbhelper.utils.getBitmap
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
@Composable
|
||||
@ -27,9 +28,7 @@ fun DexDiMEntry(
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val bitmap = remember (logo.bitmap) {
|
||||
Bitmap.createBitmap(logo.width, logo.height, Bitmap.Config.RGB_565).apply {
|
||||
copyPixelsFromBuffer(ByteBuffer.wrap(logo.bitmap))
|
||||
}
|
||||
logo.getBitmap()
|
||||
}
|
||||
val imageBitmap = remember(bitmap) { bitmap.asImageBitmap() }
|
||||
|
||||
|
||||
@ -1,8 +1,35 @@
|
||||
package com.github.nacabaro.vbhelper.utils
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import com.github.cfogrady.vb.dim.sprite.SpriteData
|
||||
|
||||
// simple, but smooth
|
||||
data class BitmapData (
|
||||
val bitmap: ByteArray,
|
||||
val width: Int,
|
||||
val height: Int
|
||||
)
|
||||
)
|
||||
|
||||
fun BitmapData.getBitmap(): Bitmap {
|
||||
return Bitmap.createBitmap(createARGBIntArray(), this.width, this.height, Bitmap.Config.HARDWARE)
|
||||
}
|
||||
|
||||
fun BitmapData.createARGBIntArray(): IntArray {
|
||||
// hack to get it into correct format by relying on the DIM Sprites methods since we haven't changed the raw pixel data at this point.
|
||||
val bytes = SpriteData.Sprite.builder().width(this.width).height(this.height).pixelData(this.bitmap).build()
|
||||
.get24BitRGB()
|
||||
val result = IntArray(this.width*this.height)
|
||||
for(i in result.indices) {
|
||||
val originalIndex = i*3
|
||||
val red = bytes[originalIndex].toUInt() and 0xFFu
|
||||
val green = bytes[originalIndex+1].toUInt() and 0xFFu
|
||||
val blue = bytes[originalIndex+2].toUInt() and 0xFFu
|
||||
val alpha = if(red == 0u && blue == 0u && green == 0xFFu) 0 else 0xFF
|
||||
result[i] = (alpha shl 24) or (red shl 16).toInt() or (green shl 8).toInt() or blue.toInt()
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun List<BitmapData>.getBitmaps(): List<Bitmap> {
|
||||
return this.map{it.getBitmap()}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user