Now with transparency flood-fill, and the dithered sky that makes possible.

This commit is contained in:
Martin Haye 2013-11-10 13:07:59 -08:00
parent e48146085e
commit ea7140524b
3 changed files with 60 additions and 6 deletions

View File

@ -15,6 +15,8 @@ import java.nio.channels.Channels
*/
class PackMap
{
def TRANSPARENT_COLOR = 15
def parseMap(tiles, map)
{
// Parse each row of the map
@ -87,6 +89,53 @@ class PackMap
return result
}
/**
* Flood fill from the upper left and upper right corners to determine
* all transparent areas.
*/
def calcTransparency(img)
{
def height = img.size
def width = img[0].size
// Keep track of which pixels we have traversed
def marks = img.collect { new boolean[it.size] }
// Initial positions to check
def queue = [] as Queue
queue.add([0, 0, img[0][0]])
queue.add([width-1, 0, img[0][width-1]])
// While we have anything left to check...
while (!queue.isEmpty())
{
// Get a coordinate and color to compare to
def (x, y, c) = queue.poll()
// If outside the image, skip it
if (x < 0 || x >= width || y < 0 || y >= height)
continue
// Process each pixel only once
if (marks[y][x])
continue
marks[y][x] = true
// Stop at color changes
if (img[y][x] != c)
continue
// Found a pixel to change to transparent. Mark it, and check in every
// direction for more of the same color.
//
img[y][x] = TRANSPARENT_COLOR
queue.add([x-1, y, c])
queue.add([x, y-1, c])
queue.add([x, y+1, c])
queue.add([x+1, y, c])
}
}
class MultiPix
{
def colorValues = [:]
@ -140,7 +189,7 @@ class PackMap
def (color, value) = pix.getHighColor()
outRow.add(color)
// Distribute the error: 50% to the right, 25% down, 25% down-right
/*
/* Note: This makes things really look weird, so not doing it any more.
if (dx+1 < outWidth)
pixBuf[dy][dx+1].addError(pix, color, 0.5)
if (dy+1 < outHeight)
@ -188,13 +237,15 @@ class PackMap
}
// The renderer wants bits of the two pixels interleaved in a special way.
// Given input pix1=00000xyz and pix2=00000qrs, the output will be 00xqyrzs.
// So the renderer uses mask 00101010 to extract pix1, and 00010101 for pix2.
// Given input pix1=0000QRST and pix2=0000wxyz, the output will be QwRxSyTz.
// So the renderer uses mask 10101010 to extract pix1, then shifts left one
// bit and uses the same mask to get pix2.
//
def combine(pix1, pix2) {
return ((pix2 & 1) << 0) | ((pix1 & 1) << 1) |
((pix2 & 2) << 1) | ((pix1 & 2) << 2) |
((pix2 & 4) << 2) | ((pix1 & 4) << 3);
((pix2 & 4) << 2) | ((pix1 & 4) << 3) |
((pix2 & 8) << 3) | ((pix1 & 8) << 4);
}
def writeImage(stream, image)
@ -251,6 +302,9 @@ class PackMap
parseImage(dataIn.image.find { it.@name == name })
}
println "Flood-filling transparency from upper corners."
images.each { calcTransparency(it) }
// Ready to start writing the output file.
new File(binPath).withOutputStream { stream ->
println "Writing map."

View File

@ -4,7 +4,7 @@
TOP_LINE = $2180 ; 24 lines down from top
NLINES = 128
SKY_COLOR_E = $22 ; blue
SKY_COLOR_O = $22 ; blue
SKY_COLOR_O = $20 ; hi-bit black
GROUND_COLOR_E = $28 ; orange
GROUND_COLOR_O = $20 ; hi-bit black
TEX_SIZE = $555 ; 32x32 + 16x16 + 8x8 + 4x4 + 2x2 + 1x1

View File

@ -1455,7 +1455,7 @@ main:
jmp @nextFrame
: cmp #$1B ; ESC to exit
beq @done
jmp @pauseLup ; unrecognize key -- go back and get another one.
jmp @pauseLup ; unrecognized key: go back and get another one.
@done:
; back to text mode
bit setText