+ Add and modify rendering tests
This commit is contained in:
parent
d1c5af790a
commit
4f70014e12
71
test.lua
71
test.lua
|
@ -4,21 +4,34 @@
|
||||||
dofile("init.lua")
|
dofile("init.lua")
|
||||||
dofile("tga_encoder.lua")
|
dofile("tga_encoder.lua")
|
||||||
|
|
||||||
font_1 = unicode_text.hexfont()
|
font_1 = unicode_text.hexfont(
|
||||||
|
{
|
||||||
|
kerning = true,
|
||||||
|
}
|
||||||
|
)
|
||||||
font_1:load_glyphs(
|
font_1:load_glyphs(
|
||||||
io.lines("/usr/share/unifont/unifont.hex")
|
io.lines("/usr/share/unifont/unifont.hex")
|
||||||
)
|
)
|
||||||
local text = "ABC 123 😀\
|
font_1:load_glyphs(
|
||||||
|
io.lines("U+FFFD.hex")
|
||||||
|
)
|
||||||
|
|
||||||
|
-- The following text purposely contains glyphs not in unifont.hex, to
|
||||||
|
-- show that these are rendered like U+FFFD REPLACEMENT CHARACTER (<28>).
|
||||||
|
local text = "ABC... 123!!! 😀\
|
||||||
\
|
\
|
||||||
wð♥𐍈"
|
U+0077 w LATIN SMALL LETTER W\
|
||||||
|
U+00F0 ð LATIN SMALL LETTER ETH\
|
||||||
|
U+2665 ♥ BLACK HEART SUIT\
|
||||||
|
U+10348 𐍈 GOTHIC LETTER HWAIR"
|
||||||
local pixels = font_1:render_text(text)
|
local pixels = font_1:render_text(text)
|
||||||
local image = tga_encoder.image(pixels)
|
local image = tga_encoder.image(pixels)
|
||||||
image:save("test.tga")
|
image:save("test.tga")
|
||||||
|
|
||||||
font_2 = unicode_text.hexfont(
|
font_2 = unicode_text.hexfont(
|
||||||
{
|
{
|
||||||
background_color = { 0x33, 0x66, 0x99 },
|
background_color = { 1 },
|
||||||
foreground_color = { 0xDD, 0x00, 0x00 },
|
foreground_color = { 0 },
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
font_2:load_glyphs(
|
font_2:load_glyphs(
|
||||||
|
@ -28,9 +41,55 @@ font_2:load_glyphs(
|
||||||
io.lines("unifont_upper.hex")
|
io.lines("unifont_upper.hex")
|
||||||
)
|
)
|
||||||
local file = io.open("UTF-8-demo.txt")
|
local file = io.open("UTF-8-demo.txt")
|
||||||
|
|
||||||
|
-- encode image with colormap (palette)
|
||||||
tga_encoder.image(
|
tga_encoder.image(
|
||||||
font_2:render_text(
|
font_2:render_text(
|
||||||
file:read("*all")
|
file:read("*all")
|
||||||
)
|
)
|
||||||
):save("UTF-8-demo.tga")
|
):save(
|
||||||
|
"UTF-8-demo.tga",
|
||||||
|
{
|
||||||
|
colormap = {
|
||||||
|
{ 0xFF, 0xFF, 0xFF },
|
||||||
|
{ 0x00, 0x00, 0xFF },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
file:close()
|
file:close()
|
||||||
|
|
||||||
|
font_2.background_color = { 0, 0, 0 }
|
||||||
|
font_2.foreground_color = { 255, 255, 255 }
|
||||||
|
font_2.tabulator_size = 4 * 8
|
||||||
|
local file = io.open("example.txt")
|
||||||
|
local text = file:read("*all")
|
||||||
|
file:close()
|
||||||
|
local pixels = font_2:render_text(text)
|
||||||
|
|
||||||
|
-- colorize text pixels
|
||||||
|
for h = 1, #pixels do
|
||||||
|
for w = 1, #pixels[h] do
|
||||||
|
local pixel = pixels[h][w]
|
||||||
|
if (
|
||||||
|
255 == pixel[1] and
|
||||||
|
255 == pixel[2] and
|
||||||
|
255 == pixel[3]
|
||||||
|
) then
|
||||||
|
pixel = {
|
||||||
|
( h + w ) % 128 + 128,
|
||||||
|
( h % w ) % 128 + 128,
|
||||||
|
( h - w ) % 128 + 128,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
pixels[h][w] = pixel
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- encode image with 15-bit colors
|
||||||
|
tga_encoder.image(pixels):save(
|
||||||
|
"example.tga",
|
||||||
|
{
|
||||||
|
color_format="A1R5G5B5",
|
||||||
|
compression = "RAW",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue