* Speed up scanline order inversion
This commit is contained in:
parent
b9c3da3ca6
commit
d1c5af790a
40
hexfont.lua
40
hexfont.lua
|
@ -55,7 +55,15 @@ hexfont.constructor = function(self, properties)
|
||||||
-- Defaults
|
-- Defaults
|
||||||
self.background_color = properties.background_color or { 0x00 }
|
self.background_color = properties.background_color or { 0x00 }
|
||||||
self.foreground_color = properties.foreground_color or { 0xFF }
|
self.foreground_color = properties.foreground_color or { 0xFF }
|
||||||
|
|
||||||
|
-- scanline order “bottom-top” was chosen as the default to match
|
||||||
|
-- the default scanline order of tga_encoder and to require users
|
||||||
|
-- using another file format encoder to care about scanline order
|
||||||
|
-- (users who “do not care about scanline order” might find their
|
||||||
|
-- glyphs upside down … the fault, naturally, lies with the user)
|
||||||
self.scanline_order = properties.scanline_order or "bottom-top"
|
self.scanline_order = properties.scanline_order or "bottom-top"
|
||||||
|
|
||||||
|
-- tab size = 8 half-width spaces when using GNU Unifont
|
||||||
self.tabulator_size = properties.tabulator_size or 8 * 8
|
self.tabulator_size = properties.tabulator_size or 8 * 8
|
||||||
self.kerning = properties.kerning or false
|
self.kerning = properties.kerning or false
|
||||||
|
|
||||||
|
@ -133,16 +141,6 @@ hexfont.bitmap_to_pixels = function(self, bitmap_hex)
|
||||||
"boolean" == type(self.kerning)
|
"boolean" == type(self.kerning)
|
||||||
)
|
)
|
||||||
|
|
||||||
-- scanline order “bottom-top” was chosen as the default to match
|
|
||||||
-- the default scanline order of tga_encoder and to require users
|
|
||||||
-- using another file format encoder to care about scanline order
|
|
||||||
-- (users who “do not care about scanline order” might find their
|
|
||||||
-- glyphs upside down … the fault, naturally, lies with the user)
|
|
||||||
assert(
|
|
||||||
"bottom-top" == self.scanline_order or
|
|
||||||
"top-bottom" == self.scanline_order
|
|
||||||
)
|
|
||||||
|
|
||||||
local height = 16
|
local height = 16
|
||||||
local width = bitmap_hex:len() * 4 / height
|
local width = bitmap_hex:len() * 4 / height
|
||||||
assert(
|
assert(
|
||||||
|
@ -171,12 +169,6 @@ hexfont.bitmap_to_pixels = function(self, bitmap_hex)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- flip image upside down for ”bottom-top” scanline order
|
|
||||||
-- (i.e. the first encoded pixel is the bottom left pixel)
|
|
||||||
if "bottom-top" == self.scanline_order then
|
|
||||||
pixels = pixelops.flip_vertically(pixels)
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.kerning then
|
if self.kerning then
|
||||||
-- remove rightmost column if it is empty
|
-- remove rightmost column if it is empty
|
||||||
local remove_rightmost_column = true
|
local remove_rightmost_column = true
|
||||||
|
@ -301,15 +293,8 @@ hexfont.render_text = function(self, text)
|
||||||
if nil == result then
|
if nil == result then
|
||||||
result = pixels
|
result = pixels
|
||||||
else
|
else
|
||||||
if "bottom-top" == self.scanline_order then
|
for i = 1, #pixels do
|
||||||
for i = #pixels, 1, -1 do
|
result[#result+1] = pixels[i]
|
||||||
table.insert(result, 1, pixels[i])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if "top-bottom" == self.scanline_order then
|
|
||||||
for i = 1, #pixels do
|
|
||||||
result[#result+1] = pixels[i]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local pixels_width = #pixels[1]
|
local pixels_width = #pixels[1]
|
||||||
|
@ -328,5 +313,10 @@ hexfont.render_text = function(self, text)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
-- flip image upside down for ”bottom-top” scanline order
|
||||||
|
-- (i.e. the first encoded pixel is the bottom left pixel)
|
||||||
|
if "bottom-top" == self.scanline_order then
|
||||||
|
result = pixelops.flip_vertically(result)
|
||||||
|
end
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue