commonMain.graphics.Overlay.kt Maven / Gradle / Ivy
package ch.softappeal.konapi.graphics
import ch.softappeal.konapi.readFile
private fun ByteArray.isSet(bit: Int) = (this[bit / 8].toInt() and (1 shl (bit % 8))) != 0
private fun ByteArray.set(bit: Int) {
this[bit / 8] = (this[bit / 8].toInt() or (1 shl (bit % 8))).toByte()
}
public open class Overlay internal constructor(
public val size: Int, dimension: Dimension, internal val bitmap: ByteArray,
) : Dimension(dimension) {
init {
require(size >= 0) { "size=$size must >= 0" }
}
private val bits = width * height
public fun draw(graphics: Graphics, xTopLeft: Int, yTopLeft: Int, index: Int) {
require(index in 0.. {}
DUMP_PIXEL_ON -> bitmap.set(bit)
else -> throw IllegalArgumentException("unexpected pixel '$p' at index $index")
}
bit++
}
}
}
require(!lines.hasNext()) { "unexpected lines at end" }
return Overlay(size, dimension, bitmap)
}