mirror of
https://github.com/curioustorvald/Terrarum-sans-bitmap.git
synced 2026-03-07 11:51:50 +09:00
we have a render (but not colour)
This commit is contained in:
@@ -53,32 +53,41 @@ class PixmapRegionPack(
|
||||
val regions: Array<Pixmap>
|
||||
|
||||
init {
|
||||
// test print the whole sheet
|
||||
/*pixmap.pixels.rewind()
|
||||
for (y in 0 until pixmap.height) {
|
||||
for (x in 0 until pixmap.width) {
|
||||
pixmap.pixels.get() // discard r
|
||||
pixmap.pixels.get() // discard g
|
||||
pixmap.pixels.get() // discard b
|
||||
val a = pixmap.pixels.get()
|
||||
|
||||
if (a == 255.toByte()) print("█") else print("·")
|
||||
}
|
||||
println()
|
||||
}
|
||||
println()*/
|
||||
|
||||
|
||||
|
||||
pixmap.pixels.rewind()
|
||||
|
||||
if (!xySwapped) {
|
||||
regions = Array<Pixmap>(horizontalCount * verticalCount, {
|
||||
val rx = (it % horizontalCount * (tileW + hGap)) + hFrame // pixel, not index
|
||||
val ry = (it / horizontalCount * (tileH + vGap)) + vFrame // pixel, not index
|
||||
|
||||
val region = Pixmap(tileW, tileH, Pixmap.Format.RGBA8888)
|
||||
|
||||
/*region.setColor(Color.WHITE)
|
||||
region.drawPixmap(pixmap, 0, 0,
|
||||
rx * (tileW + hGap),
|
||||
ry * (tileH + vGap),
|
||||
tileW,
|
||||
tileH
|
||||
)*/
|
||||
|
||||
region.pixels.rewind()
|
||||
|
||||
//println(region.pixels.capacity())
|
||||
|
||||
// for every "scanline"
|
||||
for (y in 0 until tileH) {
|
||||
//println("${pixmap.width * pixmap.height * 4} ==? ${pixmap.pixels.capacity()}")
|
||||
|
||||
val offsetY = ry * (pixmap.width * 4) + (vFrame * pixmap.width * 4)
|
||||
val offsetY = (ry + y) * (pixmap.width * 4) + (vFrame * pixmap.width * 4)
|
||||
val offsetX = rx * 4 + hFrame * 4
|
||||
|
||||
//println("($rx, $ry): ${offsetY + offsetX} / ${pixmap.pixels.capacity()}; $offsetY, $offsetX")
|
||||
//println("offset: ${offsetX + offsetY}")
|
||||
|
||||
val bytesBuffer = ByteArray(4 * tileW)
|
||||
|
||||
@@ -86,22 +95,19 @@ class PixmapRegionPack(
|
||||
pixmap.pixels.get(bytesBuffer, 0, bytesBuffer.size)
|
||||
|
||||
// test print bytesbuffer
|
||||
bytesBuffer.forEachIndexed { index, it ->
|
||||
/*bytesBuffer.forEachIndexed { index, it ->
|
||||
if (index % 4 == 3) {
|
||||
if (it == 255.toByte()) print("█") else print("·")
|
||||
}
|
||||
}
|
||||
println()
|
||||
println()*/
|
||||
|
||||
region.pixels.put(bytesBuffer)
|
||||
}
|
||||
|
||||
//println()
|
||||
|
||||
println()
|
||||
|
||||
//val region = Pixmap(5, 20, Pixmap.Format.RGBA8888)
|
||||
//region.pixels.rewind()
|
||||
//region.pixels.put(byteArrayOf(-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0))
|
||||
|
||||
// todo globalFlipY ?
|
||||
|
||||
@@ -110,15 +116,40 @@ class PixmapRegionPack(
|
||||
}
|
||||
else {
|
||||
regions = Array<Pixmap>(horizontalCount * verticalCount, {
|
||||
val region = Pixmap(tileW, tileH, Pixmap.Format.RGBA8888)
|
||||
val rx = (it / verticalCount * (tileW + hGap)) + hFrame
|
||||
val ry = (it % verticalCount * (tileH + vGap)) + vFrame
|
||||
|
||||
region.drawPixmap(pixmap, 0, 0,
|
||||
rx * (tileW + hGap),
|
||||
ry * (tileH + vGap),
|
||||
tileW, tileH
|
||||
)
|
||||
val region = Pixmap(tileW, tileH, Pixmap.Format.RGBA8888)
|
||||
region.pixels.rewind()
|
||||
|
||||
|
||||
// for every "scanline"
|
||||
for (y in 0 until tileH) {
|
||||
|
||||
val offsetY = (ry + y) * (pixmap.width * 4) + (vFrame * pixmap.width * 4)
|
||||
val offsetX = rx * 4 + hFrame * 4
|
||||
|
||||
//println("offset: ${offsetX + offsetY}")
|
||||
|
||||
val bytesBuffer = ByteArray(4 * tileW)
|
||||
|
||||
pixmap.pixels.position(offsetY + offsetX)
|
||||
pixmap.pixels.get(bytesBuffer, 0, bytesBuffer.size)
|
||||
|
||||
// test print bytesbuffer
|
||||
/*bytesBuffer.forEachIndexed { index, it ->
|
||||
if (index % 4 == 3) {
|
||||
if (it == 255.toByte()) print("█") else print("·")
|
||||
}
|
||||
}
|
||||
println()*/
|
||||
|
||||
region.pixels.put(bytesBuffer)
|
||||
}
|
||||
|
||||
//println()
|
||||
|
||||
|
||||
|
||||
// todo globalFlipY ?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user