~cytrogen/vbhelper

5d996edc1eb4d04e145c6fe283d6a8f6b1c2a9f5 — nacabaro 1 year, 3 months ago 5a1d52a + 074ced1
Merge branch 'main' into ui/home_screen
M app/src/main/java/com/github/nacabaro/vbhelper/components/CharacterEntry.kt => app/src/main/java/com/github/nacabaro/vbhelper/components/CharacterEntry.kt +4 -1
@@ 31,17 31,20 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
import com.github.nacabaro.vbhelper.utils.getObscuredBitmap
import java.nio.ByteBuffer

@Composable
fun CharacterEntry(
    icon: BitmapData,
    obscure: Boolean = false,
    modifier: Modifier = Modifier,
    shape: Shape = MaterialTheme.shapes.medium,
    multiplier: Int = 3,
    onClick: () -> Unit = {  }
) {
    val bitmap = remember (icon.bitmap) {
        icon.getBitmap()
        if(obscure) icon.getObscuredBitmap() else icon.getBitmap()
    }
    val imageBitmap = remember(bitmap) { bitmap.asImageBitmap() }
    val density: Float = LocalContext.current.resources.displayMetrics.density

M app/src/main/java/com/github/nacabaro/vbhelper/screens/DimScreen.kt => app/src/main/java/com/github/nacabaro/vbhelper/screens/DimScreen.kt +2 -0
@@ 1,5 1,6 @@
package com.github.nacabaro.vbhelper.screens

import android.util.Log
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items


@@ 54,6 55,7 @@ fun DiMScreen(
            items(characterList.value) { character ->
                CharacterEntry(
                    onClick = {  },
                    obscure = true,
                    icon = BitmapData(
                        bitmap = character.sprite1,
                        width = character.spritesWidth,

M app/src/main/java/com/github/nacabaro/vbhelper/utils/BitmapData.kt => app/src/main/java/com/github/nacabaro/vbhelper/utils/BitmapData.kt +24 -0
@@ 14,6 14,30 @@ fun BitmapData.getBitmap(): Bitmap {
    return Bitmap.createBitmap(createARGBIntArray(), this.width, this.height, Bitmap.Config.HARDWARE)
}

object ARGBMasks {
    const val ALPHA = (0xFF shl 24)
    const val RED = (0xFF shl 16)
    const val GREEN = (0xFF shl 8)
    const val BLUE = 0xFF

}

const val BLACK = ARGBMasks.ALPHA

fun BitmapData.getObscuredBitmap(): Bitmap {
    val argbPixels = createARGBIntArray()
    for(i in argbPixels.indices) {
        val currentPixel = argbPixels[i]
        if( currentPixel and ARGBMasks.ALPHA != 0) {
            // non transparent pixel
            argbPixels[i] = BLACK
        }
    }
    return Bitmap.createBitmap(argbPixels, 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()