file-format keenengine-font
{
	unsigned16 height
	unsigned16[256] offsets
	unsigned8[256] widths

	current-letter: 0

	image-layout-width: 256
	image-layout
	{
		loop(256): i
		{
			if (offsets[i] != 0)
			{
				at offsets[i]:

				image
				{
					format: "I1"
					width: widths[i]
					bit-stride: width
				}
			}
		}
	}
}

alpha-mask: 1

file-format keenengine-unmasked8x8
{
	image
	{
		format:  "I4"
		data-size: file.size
		width: 8
		height: 8
		tiles-across: 10
		bit-stride: width * height
	}
}

file-format keenengine-masked8x8
{
	image 
	{
		format: "A1I4"
		data-size: file.size
		width: 8
		height: 8
		tiles-across: 3
		bit-stride: width * height
		alpha-mask: 1
	}
}

function keen-huffman
{
	file.bit-reading-shift-out-right = true
    	file.bit-reading-shift-in-right = false

	bytes-written: 0
	current-node: 254
	next-node: 0
	total-bits: file.size * 8

	loop while((bytes-written < decompressed-size) and (total-bits > 0))
	{
		bits(1) c
		total-bits = total-bits - 1

		next-node = huff-table[current-node * 2 + c]

		if (next-node < 256)
		{
			write unsigned8 next-node
			bytes-written = bytes-written + 1
			current-node = 254
		}
		else
		{
			current-node = next-node & 0xFF
		}
	}
}

/*file-format shl-file
{
	fixed-string(4) cID == "CMP1"
	unsigned16 compression-method
	unsigned32 decompressed-size
	unsigned32 original-size

	file[1]
	{
		offset: file.position
		size: original-size
		if (compression-method == 1)
		{
			compressed "slib-lzw"
		}
		else if (compression-method == 2)
		{
			compressed "slib-lzh"
		}

		name: "Decompressed data"
	}
}*/
