f624800b84
I was forced to manually do update the following files, because otherwise they would be ignored according .gitignore settings. Probably they should be deleted from repo. Interop/.idea/compiler.xml Interop/.idea/gradle.xml Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_3.xml Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_3.xml Interop/.idea/modules.xml Interop/.idea/modules/Indexer/Indexer.iml Interop/.idea/modules/Runtime/Runtime.iml Interop/.idea/modules/StubGenerator/StubGenerator.iml backend.native/backend.native.iml backend.native/bc.frontend/bc.frontend.iml backend.native/cli.bc/cli.bc.iml backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt backend.native/tests/link/lib/foo.kt backend.native/tests/link/lib/foo2.kt backend.native/tests/teamcity-test.property
26 lines
905 B
Kotlin
26 lines
905 B
Kotlin
package codegen.arithmetic.github1856
|
|
|
|
import kotlin.test.*
|
|
|
|
object RGBA {
|
|
fun packFast(r: Int, g: Int, b: Int, a: Int) = (r shl 0) or (g shl 8) or (b shl 16) or (a shl 24)
|
|
|
|
fun getFastR(v: Int): Int = (v ushr 0) and 0xFF
|
|
fun getFastG(v: Int): Int = (v ushr 8) and 0xFF
|
|
fun getFastB(v: Int): Int = (v ushr 16) and 0xFF
|
|
fun getFastA(v: Int): Int = (v ushr 24) and 0xFF
|
|
|
|
fun premultiplyFastInt(v: Int): Int {
|
|
val A = getFastA(v) + 1
|
|
val RB = (((v and 0x00FF00FF) * A) ushr 8) and 0x00FF00FF
|
|
val G = (((v and 0x0000FF00) * A) ushr 8) and 0x0000FF00
|
|
return (v and 0x00FFFFFF.inv()) or RB or G
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun main() {
|
|
val source = listOf(0xFFFFFFFF.toInt(), 0xFFFFFF77.toInt(), 0x777777FF.toInt(), 0x77777777.toInt())
|
|
val expect = listOf(-1, -137, 2000107383, 2000107319)
|
|
assertEquals(expect, source.map { RGBA.premultiplyFastInt(it) })
|
|
} |