* Speed up scanline order inversion

This commit is contained in:
Nils Dagsson Moskopp 2023-03-18 23:45:23 +01:00
parent b9c3da3ca6
commit d1c5af790a
1 changed files with 15 additions and 25 deletions

View File

@ -55,7 +55,15 @@ hexfont.constructor = function(self, properties)
-- Defaults
self.background_color = properties.background_color or { 0x00 }
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"
-- tab size = 8 half-width spaces when using GNU Unifont
self.tabulator_size = properties.tabulator_size or 8 * 8
self.kerning = properties.kerning or false
@ -133,16 +141,6 @@ hexfont.bitmap_to_pixels = function(self, bitmap_hex)
"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 width = bitmap_hex:len() * 4 / height
assert(
@ -171,12 +169,6 @@ hexfont.bitmap_to_pixels = function(self, bitmap_hex)
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
-- remove rightmost column if it is empty
local remove_rightmost_column = true
@ -301,17 +293,10 @@ hexfont.render_text = function(self, text)
if nil == result then
result = pixels
else
if "bottom-top" == self.scanline_order then
for i = #pixels, 1, -1 do
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
local pixels_width = #pixels[1]
if pixels_width > max_width then
max_width = pixels_width
@ -328,5 +313,10 @@ hexfont.render_text = function(self, text)
)
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
end