1
0
Fork 0
forked from len0rd/rockbox

Clean up rocklib_img

optimize both size and speed
fix invert for color screens

Change-Id: I7edecae32dcb3daf5b3ed984a0e5b3d463269e60
This commit is contained in:
William Wilgus 2018-09-23 18:25:31 +02:00
parent e4b843335b
commit c0682e0944
7 changed files with 520 additions and 609 deletions

View file

@ -36,7 +36,7 @@ if not rb.lcd_framebuffer then rb.splash(rb.HZ, "No Support!") return nil end
local _blit ={} do local _blit ={} do
_blit.CUSTOM = 0xFF --user defined blit function func(dst_val, x, y, src_val, x, y) _blit.CUSTOM = nil --user defined blit function func(dst_val, x, y, src_val, x, y)
_blit.BCOPY = 0x0 --copy (use :copy() instead it is slightly faster _blit.BCOPY = 0x0 --copy (use :copy() instead it is slightly faster
_blit.BOR = 0x1 --OR source and dest pixels _blit.BOR = 0x1 --OR source and dest pixels
_blit.BXOR = 0x2 --XOR source and dest pixels _blit.BXOR = 0x2 --XOR source and dest pixels

View file

@ -49,17 +49,9 @@ local _clr = {} do
maxstate = (bit.lshift(1, 24) - 1) maxstate = (bit.lshift(1, 24) - 1)
end end
local function init(v)
return v or 0
end
-- clamps value to >= min and <= max rolls over to opposite -- clamps value to >= min and <= max rolls over to opposite
local function clamp_roll(val, min, max) local function clamp_roll(val, min, max)
if min > max then -- Warning doesn't check if min < max
local swap = min
min, max = max, swap
end
if val < min then if val < min then
val = max val = max
elseif val > max then elseif val > max then
@ -72,12 +64,12 @@ local _clr = {} do
-- sets color -- monochrome / greyscale use 'set' -- color targets 'r,b,g' -- sets color -- monochrome / greyscale use 'set' -- color targets 'r,b,g'
-- on monochrome/ greyscale targets: -- on monochrome/ greyscale targets:
-- '-1' sets the highest 'color' state & 0 is the minimum 'color' state -- '-1' sets the highest 'color' state & 0 is the minimum 'color' state
local function clrset(set, r, g, b) _clr.set = function(set, r, g, b)
local color = set or 0 local color = set or 0
if IS_COLOR_TARGET then if IS_COLOR_TARGET then
if (r ~= _NIL or g ~= _NIL or b ~= _NIL) then if (r or g or b) then
r, g, b = init(r), init(g), init(b) r, g, b = (r or 0), (g or 0), (b or 0)
color = rb.lcd_rgbpack(r, g, b) color = rb.lcd_rgbpack(r, g, b)
end end
end end
@ -86,21 +78,21 @@ local _clr = {} do
end -- clrset end -- clrset
-- de/increments current color by 'inc' -- optionally color targets by 'r,g,b' -- de/increments current color by 'inc' -- optionally color targets by 'r,g,b'
local function clrinc(current, inc, r, g, b) _clr.inc = function(current, inc, r, g, b)
local color = 0 local color = 0
current = current or color current = current or color
inc = inc or 1 inc = inc or 1
if IS_COLOR_TARGET then if IS_COLOR_TARGET then
local ru, gu, bu = rb.lcd_rgbunpack(current); local ru, gu, bu = rb.lcd_rgbunpack(current);
if (r ~= _NIL or g ~= _NIL or b ~= _NIL) then if (r or g or b) then
r, g, b = init(r), init(g), init(b) r, g, b = (r or 0), (g or 0), (b or 0)
ru = ru + r; gu = gu + g; bu = bu + b ru = ru + r; gu = gu + g; bu = bu + b
color = rb.lcd_rgbpack(ru, gu, bu)
else else
ru = ru + inc; gu = gu + inc; bu = bu + inc ru = ru + inc; gu = gu + inc; bu = bu + inc
color = rb.lcd_rgbpack(ru, gu, bu)
end end
color = rb.lcd_rgbpack(ru, gu, bu)
else else
color = current + inc color = current + inc
end end
@ -108,9 +100,6 @@ local _clr = {} do
return clamp_roll(color, 0, maxstate) return clamp_roll(color, 0, maxstate)
end -- clrinc end -- clrinc
-- expose functions to the outside through _clr table
_clr.set = clrset
_clr.inc = clrinc
end -- color functions end -- color functions
return _clr return _clr

View file

@ -52,35 +52,39 @@ if not rb.lcd_framebuffer then rb.splash(rb.HZ, "No Support!") return nil end
local _draw = {} do local _draw = {} do
local rocklib_image = getmetatable(rb.lcd_framebuffer())
setmetatable(_draw, rocklib_image)
-- Internal Constants -- Internal Constants
local _LCD = rb.lcd_framebuffer() local _LCD = rb.lcd_framebuffer()
local LCD_W, LCD_H = rb.LCD_WIDTH, rb.LCD_HEIGHT local LCD_W, LCD_H = rb.LCD_WIDTH, rb.LCD_HEIGHT
local BSAND = 8 -- blits color to dst if src <> 0 local BSAND = 8 -- blits color to dst if src <> 0
local _NIL = nil -- nil placeholder local _NIL = nil -- nil placeholder
local function set_viewport(vp) local _abs = math.abs
if not vp then rb.set_viewport() return end local _clear = rocklib_image.clear
if rb.LCD_DEPTH == 2 then -- invert 2-bit screens local _copy = rocklib_image.copy
--vp.drawmode = bit.bxor(vp.drawmode, 4) local _ellipse = rocklib_image.ellipse
vp.fg_pattern = 3 - vp.fg_pattern local _get = rocklib_image.get
vp.bg_pattern = 3 - vp.bg_pattern local _line = rocklib_image.line
end local _marshal = rocklib_image.marshal
rb.set_viewport(vp) local _min = math.min
end local _newimg = rb.new_image
local _points = rocklib_image.points
-- line -- line
local function line(img, x1, y1, x2, y2, color, bClip) _draw.line = function(img, x1, y1, x2, y2, color, bClip)
img:line(x1, y1, x2, y2, color, bClip) _line(img, x1, y1, x2, y2, color, bClip)
end end
-- horizontal line; x, y define start point; length in horizontal direction -- horizontal line; x, y define start point; length in horizontal direction
local function hline(img, x, y , length, color, bClip) local function hline(img, x, y , length, color, bClip)
img:line(x, y, x + length, _NIL, color, bClip) _line(img, x, y, x + length, _NIL, color, bClip)
end end
-- vertical line; x, y define start point; length in vertical direction -- vertical line; x, y define start point; length in vertical direction
local function vline(img, x, y , length, color, bClip) local function vline(img, x, y , length, color, bClip)
img:line(x, y, _NIL, y + length, color, bClip) _line(img, x, y, _NIL, y + length, color, bClip)
end end
-- draws a non-filled figure based on points in t-points -- draws a non-filled figure based on points in t-points
@ -100,7 +104,7 @@ local _draw = {} do
local pt2 = t_points[i + 1] or pt_first_last-- first and last point local pt2 = t_points[i + 1] or pt_first_last-- first and last point
img:line(pt1[1] + x, pt1[2] + y, pt2[1]+x, pt2[2]+y, color, bClip) _line(img, pt1[1] + x, pt1[2] + y, pt2[1] + x, pt2[2] + y, color, bClip)
end end
end end
@ -109,90 +113,80 @@ local _draw = {} do
local function rect(img, x, y, width, height, color, bClip) local function rect(img, x, y, width, height, color, bClip)
if width == 0 or height == 0 then return end if width == 0 or height == 0 then return end
local ppt = {{0, 0}, {width, 0}, {width, height}, {0, height}} polyline(img, x, y, {{0, 0}, {width, 0}, {width, height}, {0, height}}, color, true, bClip)
polyline(img, x, y, ppt, color, true, bClip)
--[[
vline(img, x, y, height, color, bClip);
vline(img, x + width, y, height, color, bClip);
hline(img, x, y, width, color, bClip);
hline(img, x, y + height, width, color, bClip);]]
end end
-- filled rect, fillcolor is color if left empty -- filled rect, fillcolor is color if left empty
local function rect_filled(img, x, y, width, height, color, fillcolor, bClip) _draw.rect_filled = function(img, x, y, width, height, color, fillcolor, bClip)
if width == 0 or height == 0 then return end if width == 0 or height == 0 then return end
if not fillcolor then if not fillcolor then
img:clear(color, x, y, x + width, y + height, bClip) _clear(img, color, x, y, x + width, y + height, bClip)
else else
img:clear(fillcolor, x, y, x + width, y + height, bClip) _clear(img, fillcolor, x, y, x + width, y + height, bClip)
rect(img, x, y, width, height, color, bClip) rect(img, x, y, width, height, color, bClip)
end end
end end
-- circle cx,cy define center point -- circle cx,cy define center point
local function circle(img, cx, cy, radius, color, bClip) _draw.circle = function(img, cx, cy, radius, color, bClip)
local r = radius local r = radius
img:ellipse(cx - r, cy - r, cx + r, cy + r, color, _NIL, bClip) _ellipse(img, cx - r, cy - r, cx + r, cy + r, color, _NIL, bClip)
end end
-- filled circle cx,cy define center, fillcolor is color if left empty -- filled circle cx,cy define center, fillcolor is color if left empty
local function circle_filled(img, cx, cy, radius, color, fillcolor, bClip) _draw.circle_filled = function(img, cx, cy, radius, color, fillcolor, bClip)
fillcolor = fillcolor or color fillcolor = fillcolor or color
local r = radius local r = radius
img:ellipse(cx - r, cy - r, cx + r, cy + r, color, fillcolor, bClip) _ellipse(img, cx - r, cy - r, cx + r, cy + r, color, fillcolor, bClip)
end end
-- ellipse that fits into defined rect -- ellipse that fits into defined rect
local function ellipse_rect(img, x1, y1, x2, y2, color, bClip) _draw.ellipse_rect = function(img, x1, y1, x2, y2, color, bClip)
img:ellipse(x1, y1, x2, y2, color, _NIL, bClip) _ellipse(img, x1, y1, x2, y2, color, _NIL, bClip)
end end
--ellipse that fits into defined rect, fillcolor is color if left empty --ellipse that fits into defined rect, fillcolor is color if left empty
local function ellipse_rect_filled(img, x1, y1, x2, y2, color, fillcolor, bClip) _draw.ellipse_rect_filled = function(img, x1, y1, x2, y2, color, fillcolor, bClip)
if not fillcolor then fillcolor = color end if not fillcolor then fillcolor = color end
img:ellipse(x1, y1, x2, y2, color, fillcolor, bClip) _ellipse(img, x1, y1, x2, y2, color, fillcolor, bClip)
end end
-- ellipse cx, cy define center point; a, b the major/minor axis -- ellipse cx, cy define center point; a, b the major/minor axis
local function ellipse(img, cx, cy, a, b, color, bClip) _draw.ellipse = function(img, cx, cy, a, b, color, bClip)
img:ellipse(cx - a, cy - b, cx + a, cy + b, color, _NIL, bClip) _ellipse(img, cx - a, cy - b, cx + a, cy + b, color, _NIL, bClip)
end end
-- filled ellipse cx, cy define center point; a, b the major/minor axis -- filled ellipse cx, cy define center point; a, b the major/minor axis
-- fillcolor is color if left empty -- fillcolor is color if left empty
local function ellipse_filled(img, cx, cy, a, b, color, fillcolor, bClip) _draw.ellipse_filled = function(img, cx, cy, a, b, color, fillcolor, bClip)
if not fillcolor then fillcolor = color end if not fillcolor then fillcolor = color end
img:ellipse(cx - a, cy - b, cx + a, cy + b, color, fillcolor, bClip) _ellipse(img, cx - a, cy - b, cx + a, cy + b, color, fillcolor, bClip)
end end
-- rounded rectangle -- rounded rectangle
local function rounded_rect(img, x, y, w, h, radius, color, bClip) local function rounded_rect(img, x, y, w, h, radius, color, bClip)
local c_img local c_img
local function blit(dx, dy, sx, sy, ox, oy)
img:copy(c_img, dx, dy, sx, sy, ox, oy, bClip, BSAND, color)
end
if w == 0 or h == 0 then return end if w == 0 or h == 0 then return end
-- limit the radius of the circle otherwise it will overtake the rect -- limit the radius of the circle otherwise it will overtake the rect
radius = math.min(w / 2, radius) radius = _min(w / 2, radius)
radius = math.min(h / 2, radius) radius = _min(h / 2, radius)
local r = radius local r = radius
c_img = rb.new_image(r * 2 + 1, r * 2 + 1) c_img = _newimg(r * 2 + 1, r * 2 + 1)
c_img:clear(0) _clear(c_img, 0)
circle(c_img, r + 1, r + 1, r, 0xFFFFFF) _ellipse(c_img, 1, 1, 1 + r + r, 1 + r + r, 0x1, _NIL, bClip)
-- copy 4 pieces of circle to their respective corners -- copy 4 pieces of circle to their respective corners
blit(x, y, _NIL, _NIL, r + 1, r + 1) --TL _copy(img, c_img, x, y, _NIL, _NIL, r + 1, r + 1, bClip, BSAND, color) --TL
blit(x + w - r - 2, y, r, _NIL, r + 1, r + 1) --TR _copy(img, c_img, x + w - r - 2, y, r, _NIL, r + 1, r + 1, bClip, BSAND, color) --TR
blit(x , y + h - r - 2, _NIL, r, r + 1, _NIL) --BL _copy(img, c_img, x , y + h - r - 2, _NIL, r, r + 1, _NIL, bClip, BSAND, color) --BL
blit(x + w - r - 2, y + h - r - 2, r, r, r + 1, r + 1)--BR _copy(img, c_img, x + w - r - 2, y + h - r - 2, r, r, r + 1, r + 1, bClip, BSAND, color)--BR
c_img = _NIL c_img = _NIL
vline(img, x, y + r, h - r * 2, color, bClip); vline(img, x, y + r, h - r * 2, color, bClip);
@ -202,38 +196,34 @@ local _draw = {} do
end end
-- rounded rectangle fillcolor is color if left empty -- rounded rectangle fillcolor is color if left empty
local function rounded_rect_filled(img, x, y, w, h, radius, color, fillcolor, bClip) _draw.rounded_rect_filled = function(img, x, y, w, h, radius, color, fillcolor, bClip)
local c_img local c_img
local function blit(dx, dy, sx, sy, ox, oy)
img:copy(c_img, dx, dy, sx, sy, ox, oy, bClip, BSAND, fillcolor)
end
if w == 0 or h == 0 then return end if w == 0 or h == 0 then return end
if not fillcolor then fillcolor = color end if not fillcolor then fillcolor = color end
-- limit the radius of the circle otherwise it will overtake the rect -- limit the radius of the circle otherwise it will overtake the rect
radius = math.min(w / 2, radius) radius = _min(w / 2, radius)
radius = math.min(h / 2, radius) radius = _min(h / 2, radius)
local r = radius local r = radius
c_img = rb.new_image(r * 2 + 1, r * 2 + 1) c_img = _newimg(r * 2 + 1, r * 2 + 1)
c_img:clear(0) _clear(c_img, 0)
circle_filled(c_img, r + 1, r + 1, r, fillcolor) _ellipse(c_img, 1, 1, 1 + r + r, 1 + r + r, 0x1, 0x1, bClip)
-- copy 4 pieces of circle to their respective corners -- copy 4 pieces of circle to their respective corners
blit(x, y, _NIL, _NIL, r + 1, r + 1) --TL _copy(img, c_img, x, y, _NIL, _NIL, r + 1, r + 1, bClip, BSAND, fillcolor) --TL
blit(x + w - r - 2, y, r, _NIL, r + 1, r + 1) --TR _copy(img, c_img, x + w - r - 2, y, r, _NIL, r + 1, r + 1, bClip, BSAND, fillcolor) --TR
blit(x, y + h - r - 2, _NIL, r, r + 1, _NIL) --BL _copy(img, c_img, x, y + h - r - 2, _NIL, r, r + 1, _NIL, bClip, BSAND, fillcolor) --BL
blit(x + w - r - 2, y + h - r - 2, r, r, r + 1, r + 1) --BR _copy(img, c_img, x + w - r - 2, y + h - r - 2, r, r, r + 1, r + 1, bClip, BSAND, fillcolor) --BR
c_img = _NIL c_img = _NIL
-- finish filling areas circles didn't cover -- finish filling areas circles didn't cover
img:clear(fillcolor, x + r, y, x + w - r, y + h - 1, bClip) _clear(img, fillcolor, x + r, y, x + w - r, y + h - 1, bClip)
img:clear(fillcolor, x, y + r, x + r, y + h - r, bClip) _clear(img, fillcolor, x, y + r, x + r, y + h - r, bClip)
img:clear(fillcolor, x + w - r, y + r, x + w - 1, y + h - r - 1, bClip) _clear(img, fillcolor, x + w - r, y + r, x + w - 1, y + h - r - 1, bClip)
if fillcolor ~= color then if fillcolor ~= color then
rounded_rect(img, x, y, w, h, r, color, bClip) rounded_rect(img, x, y, w, h, r, color, bClip)
@ -241,23 +231,23 @@ local _draw = {} do
end end
-- draws an image at xy coord in dest image -- draws an image at xy coord in dest image
local function image(dst, src, x, y, bClip) _draw.image = function(dst, src, x, y, bClip)
if not src then --make sure an image was passed, otherwise bail if not src then --make sure an image was passed, otherwise bail
rb.splash(rb.HZ, "No Image!") rb.splash(rb.HZ, "No Image!")
return _NIL return _NIL
end end
dst:copy(src, x, y, 1, 1, _NIL, _NIL, bClip) _copy(dst, src, x, y, 1, 1, _NIL, _NIL, bClip)
end end
-- floods an area of targetclr with fillclr x, y specifies the start seed -- floods an area of targetclr with fillclr x, y specifies the start seed
function flood_fill(img, x, y, targetclr, fillclr) _draw.flood_fill = function(img, x, y, targetclr, fillclr)
-- scanline 4-way flood algorithm -- scanline 4-way flood algorithm
-- ^ -- ^
-- <--------x---> -- <--------x--->
-- v -- v
-- check that target color doesn't = fill and the first point is target color -- check that target color doesn't = fill and the first point is target color
if targetclr == fillclr or targetclr ~= img:get(x,y, true) then return end if targetclr == fillclr or targetclr ~= _get(img, x, y, true) then return end
local max_w = img:width() local max_w = img:width()
local max_h = img:height() local max_h = img:height()
@ -271,21 +261,20 @@ local _draw = {} do
-- y coordinates are in even indices -- y coordinates are in even indices
local qtail = 0 local qtail = 0
local iter_n; -- North iteration
local iter_s; -- South iteration
local function check_ns(val, x, y) local function check_ns(val, x, y)
if targetclr == val then if targetclr == val then
if targetclr == iter_n() then y = y - 1
if targetclr == _get(img, x, y, true) then -- north
qtail = qtail + 2 qtail = qtail + 2
qpt[qtail - 1] = x qpt[qtail - 1] = x
qpt[qtail] = (y - 1) qpt[qtail] = y
end end
y = y + 2
if targetclr == iter_s() then if targetclr == _get(img, x, y, true) then -- south
qtail = qtail + 2 qtail = qtail + 2
qpt[qtail - 1] = x qpt[qtail - 1] = x
qpt[qtail] = (y + 1) qpt[qtail] = y
end end
return fillclr return fillclr
end end
@ -293,17 +282,12 @@ local _draw = {} do
end end
local function seed_pt(x, y) local function seed_pt(x, y)
-- will never hit max_w * max_h^2 but make sure not to end early -- should never hit max but make sure not to end early
for qhead = 2, max_w * max_h * max_w * max_h, 2 do for qhead = 2, 0x40000000, 2 do
if targetclr == img:get(x, y, true) then if targetclr == _get(img, x, y, true) then
iter_n = img:points(x, y - 1, 1, y - 1) _marshal(img, x, y, 1, y, _NIL, _NIL, true, check_ns) -- west
iter_s = img:points(x, y + 1, 1, y + 1) _marshal(img, x + 1, y, max_w, y, _NIL, _NIL, true, check_ns) -- east
img:marshal(x, y, 1, y, _NIL, _NIL, true, check_ns)
iter_n = img:points(x + 1, y - 1, max_w, y - 1)
iter_s = img:points(x + 1, y + 1, max_w, y + 1)
img:marshal(x + 1, y, max_w, y, _NIL, _NIL, true, check_ns)
end end
x = qpt[qhead - 1] x = qpt[qhead - 1]
@ -320,7 +304,7 @@ local _draw = {} do
end -- flood_fill end -- flood_fill
-- draws a closed figure based on points in t_points -- draws a closed figure based on points in t_points
local function polygon(img, x, y, t_points, color, fillcolor, bClip) _draw.polygon = function(img, x, y, t_points, color, fillcolor, bClip)
if #t_points < 2 then error("not enough points", 3) end if #t_points < 2 then error("not enough points", 3) end
if fillcolor then if fillcolor then
@ -335,35 +319,41 @@ local _draw = {} do
if pt[2] < y_min then y_min = pt[2] end if pt[2] < y_min then y_min = pt[2] end
if pt[2] > y_max then y_max = pt[2] end if pt[2] > y_max then y_max = pt[2] end
end end
w = math.abs(x_max) + math.abs(x_min) w = _abs(x_max) + _abs(x_min)
h = math.abs(y_max) + math.abs(y_min) h = _abs(y_max) + _abs(y_min)
x_min = x_min - 2 -- leave a border to use flood_fill x_min = x_min - 2 -- leave a border to use flood_fill
y_min = y_min - 2 y_min = y_min - 2
local fill_img = rb.new_image(w + 3, h + 3) local fill_img = _newimg(w + 3, h + 3)
fill_img:clear(0xFFFFFF) _clear(fill_img, 0x1)
for i = 1, #t_points, 1 do for i = 1, #t_points, 1 do
local pt1 = t_points[i] local pt1 = t_points[i]
local pt2 = t_points[i + 1] or t_points[1]-- first and last point local pt2 = t_points[i + 1] or t_points[1]-- first and last point
fill_img:line(pt1[1] - x_min, pt1[2] - y_min, _line(fill_img, pt1[1] - x_min, pt1[2] - y_min,
pt2[1]- x_min, pt2[2] - y_min, 0) pt2[1]- x_min, pt2[2] - y_min, 0)
end end
flood_fill(fill_img, fill_img:width(), fill_img:height() , 1, 0) _draw.flood_fill(fill_img, fill_img:width(), fill_img:height() , 0x1, 0x0)
img:copy(fill_img, x - 1, y - 1, _NIL, _NIL, _NIL, _NIL, bClip, BSAND, fillcolor) _copy(img, fill_img, x - 1, y - 1, _NIL, _NIL, _NIL, _NIL, bClip, BSAND, fillcolor)
end end
polyline(img, x, y, t_points, color, true, bClip) polyline(img, x, y, t_points, color, true, bClip)
end end
-- draw text onto image if width/height are supplied text is centered -- draw text onto image if width/height are supplied text is centered
local function text(img, x, y, width, height, font, color, text) _draw.text = function(img, x, y, width, height, font, color, text)
font = font or rb.FONT_UI font = font or rb.FONT_UI
local opts = {x = 0, y = 0, width = LCD_W - 1, height = LCD_H - 1, local opts = {x = 0, y = 0, width = LCD_W - 1, height = LCD_H - 1,
font = font, drawmode = 3, fg_pattern = 0xFFFFFF, bg_pattern = 0} font = font, drawmode = 3, fg_pattern = 0x1, bg_pattern = 0}
set_viewport(opts)
if rb.LCD_DEPTH == 2 then -- invert 2-bit screens
--vp.drawmode = bit.bxor(vp.drawmode, 4)
vp.fg_pattern = 3 - vp.fg_pattern
vp.bg_pattern = 3 - vp.bg_pattern
end
rb.set_viewport(opts)
local res, w, h = rb.font_getstringsize(text, font) local res, w, h = rb.font_getstringsize(text, font)
@ -380,8 +370,8 @@ local _draw = {} do
end end
-- make a copy of the current screen for later -- make a copy of the current screen for later
local screen_img = rb.new_image(LCD_W, LCD_H) local screen_img = _newimg(LCD_W, LCD_H)
screen_img:copy(_LCD) _copy(screen_img, _LCD)
-- check if the screen buffer is supplied image if so set img to the copy -- check if the screen buffer is supplied image if so set img to the copy
if img == _LCD then if img == _LCD then
@ -391,10 +381,6 @@ local _draw = {} do
-- we will be printing the text to the screen then blitting into img -- we will be printing the text to the screen then blitting into img
rb.lcd_clear_display() rb.lcd_clear_display()
local function blit(dx, dy)
img:copy(_LCD, dx, dy, _NIL, _NIL, _NIL, _NIL, false, BSAND, color)
end
if w > LCD_W then -- text is too long for the screen do it in chunks if w > LCD_W then -- text is too long for the screen do it in chunks
local l = 1 local l = 1
local resp, wp, hp local resp, wp, hp
@ -417,7 +403,7 @@ local _draw = {} do
end end
-- using the mask we made blit color into img -- using the mask we made blit color into img
blit(x + width, y + height) _copy(img, _LCD, x + width, y + height, _NIL, _NIL, _NIL, _NIL, false, BSAND, color)
x = x + wp x = x + wp
rb.lcd_clear_display() rb.lcd_clear_display()
lenr = text:len() lenr = text:len()
@ -426,43 +412,20 @@ local _draw = {} do
rb.lcd_putsxy(0, 0, text) rb.lcd_putsxy(0, 0, text)
-- using the mask we made blit color into img -- using the mask we made blit color into img
blit(x + width, y + height) _copy(img, _LCD, x + width, y + height, _NIL, _NIL, _NIL, _NIL, false, BSAND, color)
end end
_LCD:copy(screen_img) -- restore screen _copy(_LCD, screen_img) -- restore screen
set_viewport() -- set viewport default rb.set_viewport() -- set viewport default
return res, w, h return res, w, h
end end
-- expose functions to the outside through _draw table -- expose internal functions to the outside through _draw table
_draw.image = image
_draw.text = text
_draw.line = line
_draw.hline = hline _draw.hline = hline
_draw.vline = vline _draw.vline = vline
_draw.polygon = polygon
_draw.polyline = polyline _draw.polyline = polyline
_draw.rect = rect _draw.rect = rect
_draw.circle = circle
_draw.ellipse = ellipse
_draw.flood_fill = flood_fill
_draw.ellipse_rect = ellipse_rect
_draw.rounded_rect = rounded_rect _draw.rounded_rect = rounded_rect
-- filled functions use color as fillcolor if fillcolor is left empty...
_draw.rect_filled = rect_filled
_draw.circle_filled = circle_filled
_draw.ellipse_filled = ellipse_filled
_draw.ellipse_rect_filled = ellipse_rect_filled
_draw.rounded_rect_filled = rounded_rect_filled
-- adds the above _draw functions into the metatable for RLI_IMAGE
local ex = getmetatable(rb.lcd_framebuffer())
for k, v in pairs(_draw) do
if ex[k] == _NIL then
ex[k] = v
end
end
end -- _draw functions end -- _draw functions
return _draw return _draw

View file

@ -65,35 +65,43 @@ if not rb.lcd_framebuffer then rb.splash(rb.HZ, "No Support!") return nil end
local _img = {} do local _img = {} do
local rocklib_image = getmetatable(rb.lcd_framebuffer())
setmetatable(_img, rocklib_image)
-- internal constants -- internal constants
local _NIL = nil -- _NIL placeholder local _NIL = nil -- _NIL placeholder
local _math = require("math_ex") -- math functions needed local _math = require("math_ex") -- math functions needed
local LCD_W, LCD_H = rb.LCD_WIDTH, rb.LCD_HEIGHT local LCD_W, LCD_H = rb.LCD_WIDTH, rb.LCD_HEIGHT
local _copy = rocklib_image.copy
local _get = rocklib_image.get
local _marshal = rocklib_image.marshal
local _points = rocklib_image.points
-- returns new image -of- img sized to fit w/h tiling to fit if needed -- returns new image -of- img sized to fit w/h tiling to fit if needed
local function tile(img, w, h) _img.tile = function(img, w, h)
local hs , ws = img:height(), img:width() local hs , ws = img:height(), img:width()
local t_img = rb.new_image(w, h) local t_img = rb.new_image(w, h)
for x = 1, w, ws do t_img:copy(img, x, 1, 1, 1) end for x = 1, w, ws do _copy(t_img, img, x, 1, 1, 1) end
for y = hs, h, hs do t_img:copy(t_img, 1, y, 1, 1, w, hs) end for y = hs, h, hs do _copy(t_img, t_img, 1, y, 1, 1, w, hs) end
return t_img return t_img
end end
-- resizes src to size of dst -- resizes src to size of dst
local function resize(dst, src) _img.resize = function(dst, src)
-- simple nearest neighbor resize derived from rockbox - pluginlib_bmp.c -- simple nearest neighbor resize derived from rockbox - pluginlib_bmp.c
-- pretty rough results highly recommend building one more suited.. -- pretty rough results highly recommend building one more suited..
local dw, dh = dst:width(), dst:height() local dw, dh = dst:width(), dst:height()
local xstep = (bit.lshift(src:width(),8) / (dw)) + 1 local xstep = (bit.lshift(src:width(), 8) / (dw)) + 1
local ystep = (bit.lshift(src:height(),8) / (dh)) local ystep = (bit.lshift(src:height(), 8) / (dh))
local xpos, ypos = 0, 0 local xpos, ypos = 0, 0
local src_x, src_y local src_x, src_y
-- walk the dest get src pixel -- walk the dest get src pixel
function rsz_trans(val, x, y) local function rsz_trans(val, x, y)
if x == 1 then if x == 1 then
src_y = bit.rshift(ypos,8) + 1 src_y = bit.rshift(ypos,8) + 1
xpos = xstep - bit.rshift(xstep,4) + 1 xpos = xstep - bit.rshift(xstep,4) + 1
@ -101,14 +109,14 @@ local _img = {} do
end end
src_x = bit.rshift(xpos,8) + 1 src_x = bit.rshift(xpos,8) + 1
xpos = xpos + xstep xpos = xpos + xstep
return (src:get(src_x, src_y, true) or 0) return (_get(src, src_x, src_y, true) or 0)
end end
--/* (dst*, [x1, y1, x2, y2, dx, dy, clip, function]) */ --/* (dst*, [x1, y1, x2, y2, dx, dy, clip, function]) */
dst:marshal(1, 1, dw, dh, _NIL, _NIL, false, rsz_trans) _marshal(dst, 1, 1, dw, dh, _NIL, _NIL, false, rsz_trans)
end end
-- returns new image -of- img rotated in whole degrees 0 - 360 -- returns new image -of- img rotated in whole degrees 0 - 360
local function rotate(img, degrees) _img.rotate = function(img, degrees)
-- we do this backwards as if dest was the unrotated object -- we do this backwards as if dest was the unrotated object
degrees = 360 - degrees degrees = 360 - degrees
local c, s = _math.d_cos(degrees), _math.d_sin(degrees) local c, s = _math.d_cos(degrees), _math.d_sin(degrees)
@ -133,7 +141,7 @@ local _img = {} do
|_____| |_______| |_______| ]] |_____| |_______| |_______| ]]
-- walk the dest get translated src pixel, oversamples src to fill gaps -- walk the dest get translated src pixel, oversamples src to fill gaps
function rot_trans(val, x, y) local function rot_trans(val, x, y)
-- move center x/y to the origin -- move center x/y to the origin
local xtran = x - d_xctr; local xtran = x - d_xctr;
local ytran = y - d_yctr; local ytran = y - d_yctr;
@ -142,68 +150,56 @@ local _img = {} do
local yrot = ((xtran * s) + (ytran * c)) / 10000 + s_yctr local yrot = ((xtran * s) + (ytran * c)) / 10000 + s_yctr
local xrot = ((xtran * c) - (ytran * s)) / 10000 + s_xctr local xrot = ((xtran * c) - (ytran * s)) / 10000 + s_xctr
-- upper left of src image back to origin, copy src pixel -- upper left of src image back to origin, copy src pixel
return img:get(xrot, yrot, true) or 0 return _get(img, xrot, yrot, true) or 0
end end
r_img:marshal(1, 1, dw, dh, _NIL, _NIL, false, rot_trans) _marshal(r_img, 1, 1, dw, dh, _NIL, _NIL, false, rot_trans)
return r_img return r_img
end end
-- saves img to file: name -- saves img to file: name
local function save(img, name) _img.save = function(img, name)
-- bmp saving derived from rockbox - screendump.c -- bmp saving derived from rockbox - screendump.c
-- bitdepth is limited by the device -- bitdepth is limited by the device
-- eg. device displays greyscale, rgb images are saved greyscale -- eg. device displays greyscale, rgb images are saved greyscale
local file local file
local bbuffer = {} -- concat buffer for s_bytes
local fbuffer = {} -- concat buffer for file writes, reused local fbuffer = {} -- concat buffer for file writes, reused
local function dump_fbuffer(thresh)
if #fbuffer >= thresh then
file:write(table.concat(fbuffer))
for i=1, #fbuffer do fbuffer[i] = _NIL end -- reuse table
end
end
local function s_bytesLE(bits, value) local function s_bytesLE(bits, value)
-- bits must be multiples of 8 (sizeof byte) -- bits must be multiples of 8 (sizeof byte)
local byte local byte
local result = "" local nbytes = bit.rshift(bits, 3)
for b = 1, bit.rshift(bits, 3) do for b = 1, nbytes do
if value > 0 then if value > 0 then
byte = value % 256 byte = value % 256
value = (value - byte) / 256 value = (value - byte) / 256
result = result .. string.char(byte)
else else
result = result .. string.char(0) byte = 0
end end
bbuffer[b] = string.char(byte)
end end
return result return table.concat(bbuffer, _NIL, 1, nbytes)
end end
local function s_bytesBE(bits, value) local function s_bytesBE(bits, value)
-- bits must be multiples of 8 (sizeof byte) -- bits must be multiples of 8 (sizeof byte)
local byte local byte
local result = "" local nbytes = bit.rshift(bits, 3)
for b = 1, bit.rshift(bits, 3) do for b = nbytes, 1, -1 do
if value > 0 then if value > 0 then
byte = value % 256 byte = value % 256
value = (value - byte) / 256 value = (value - byte) / 256
result = string.char(byte) .. result
else else
result = string.char(0) .. result byte = 0
end end
bbuffer[b] = string.char(byte)
end end
return result return table.concat(bbuffer, _NIL, 1, nbytes)
end end
local function c_cmp(color, shift) local cmp = {["r"] = function(c) return bit.band(bit.rshift(c, 16), 0xFF) end,
-- [RR][GG][BB] ["g"] = function(c) return bit.band(bit.rshift(c, 08), 0xFF) end,
return bit.band(bit.rshift(color, shift), 0xFF) ["b"] = function(c) return bit.band(c, 0xFF) end}
end
local cmp = {["r"] = function(c) return c_cmp(c, 16) end,
["g"] = function(c) return c_cmp(c, 08) end,
["b"] = function(c) return c_cmp(c, 00) end}
local function bmp_color(color) local function bmp_color(color)
return s_bytesLE(8, cmp.b(color)).. return s_bytesLE(8, cmp.b(color))..
@ -314,7 +310,8 @@ local _img = {} do
end end
end end
dump_fbuffer(0) -- write the header to the file now file:write(table.concat(fbuffer))-- write the header to the file now
for i=1, #fbuffer do fbuffer[i] = _NIL end -- reuse table
local imgdata = fbuffer local imgdata = fbuffer
-- pad rows to a multiple of 4 bytes -- pad rows to a multiple of 4 bytes
@ -327,18 +324,23 @@ local _img = {} do
end end
-- Bitmap lines start at bottom unless biHeight is negative -- Bitmap lines start at bottom unless biHeight is negative
for point in img:points(1, h, w + bytesleft, 1) do for point in _points(img, 1, h, w + bytesleft, 1) do
imgdata[#imgdata + 1] = fs_bytes_E(bpp, point or 0) imgdata[#imgdata + 1] = fs_bytes_E(bpp, point or 0)
dump_fbuffer(31) -- buffered write, increase # for performance
if #fbuffer >= 31 then -- buffered write, increase # for performance
file:write(table.concat(fbuffer))
for i=1, #fbuffer do fbuffer[i] = _NIL end -- reuse table
end end
dump_fbuffer(0) --write leftovers to file end
file:write(table.concat(fbuffer)) --write leftovers to file
fbuffer = _NIL
file:close() file:close()
end -- save(img, name) end -- save(img, name)
--searches an image for target color --searches an image for target color
local function search(img, x1, y1, x2, y2, targetclr, variation, stepx, stepy) _img.search = function(img, x1, y1, x2, y2, targetclr, variation, stepx, stepy)
if variation > 128 then variation = 128 end if variation > 128 then variation = 128 end
if variation < -128 then variation = -128 end if variation < -128 then variation = -128 end
@ -352,7 +354,7 @@ local _img = {} do
targetl = swap targetl = swap
end end
for point, x, y in img:points(x1, y1, x2, y2, stepx, stepy) do for point, x, y in _points(img, x1, y1, x2, y2, stepx, stepy) do
if point >= targetl and point <= targeth then if point >= targetl and point <= targeth then
return point, x, y return point, x, y
end end
@ -362,12 +364,12 @@ local _img = {} do
--[[ we won't be extending these into RLI_IMAGE]] --[[ we won't be extending these into RLI_IMAGE]]
-- creates a new rbimage size w x h -- creates a new rbimage size w x h
local function new(w, h) _img.new = function(w, h)
return rb.new_image(w, h) return rb.new_image(w, h)
end end
-- returns new image -of- file: name (_NIL if error) -- returns new image -of- file: name (_NIL if error)
local function load(name) _img.load = function(name)
return rb.read_bmp_file("/" .. name) return rb.read_bmp_file("/" .. name)
end end
@ -381,23 +383,6 @@ local _img = {} do
_img.RLI_INFO_DEPTH = 0x6 _img.RLI_INFO_DEPTH = 0x6
_img.RLI_INFO_FORMAT = 0x7 _img.RLI_INFO_FORMAT = 0x7
_img.RLI_INFO_ADDRESS = 0x8 _img.RLI_INFO_ADDRESS = 0x8
-- expose functions to the outside through _img table
_img.save = save
_img.search = search
_img.rotate = rotate
_img.resize = resize
_img.tile = tile
-- adds the above _img functions into the metatable for RLI_IMAGE
local ex = getmetatable(rb.lcd_framebuffer())
for k, v in pairs(_img) do
if ex[k] == _NIL then ex[k] = v end
end
-- not exposed through RLI_IMAGE
_img.new = new
_img.load = load
end -- _img functions end -- _img functions
return _img return _img

View file

@ -51,7 +51,6 @@ local _lcd = {} do
--internal constants --internal constants
local _NIL = nil -- _NIL placeholder local _NIL = nil -- _NIL placeholder
local LCD_W, LCD_H = rb.LCD_WIDTH, rb.LCD_HEIGHT
-- clamps value to >= min and <= max -- clamps value to >= min and <= max
local function clamp(val, min, max) local function clamp(val, min, max)
@ -65,21 +64,21 @@ local _lcd = {} do
end end
-- return a copy of lcd screen -- return a copy of lcd screen
local function duplicate(t, screen_img) _lcd.duplicate = function(t, screen_img)
screen_img = screen_img or rb.new_image() screen_img = screen_img or rb.new_image()
screen_img:copy(rb.lcd_framebuffer()) screen_img:copy(rb.lcd_framebuffer())
return screen_img return screen_img
end end
-- updates screen in specified rectangle -- updates screen in specified rectangle
local function update_rect(t, x, y, w, h) _lcd.update_rect = function(t, x, y, w, h)
rb.lcd_update_rect(x - 1, y - 1, rb.lcd_update_rect(x - 1, y - 1,
clamp(x + w, 1, LCD_W) - 1, clamp(x + w, 1, rb.LCD_WIDTH) - 1,
clamp(y + h, 1, LCD_H) - 1) clamp(y + h, 1, rb.LCD_HEIGHT) - 1)
end end
-- clears lcd, optional.. ([color, x1, y1, x2, y2, clip]) -- clears lcd, optional.. ([color, x1, y1, x2, y2, clip])
local function clear(t, clr, ...) _lcd.clear = function(t, clr, ...)
rb.lcd_scroll_stop() --rb really doesn't like bg change while scroll rb.lcd_scroll_stop() --rb really doesn't like bg change while scroll
if clr == _NIL and ... == _NIL then if clr == _NIL and ... == _NIL then
rb.lcd_clear_display() rb.lcd_clear_display()
@ -89,7 +88,7 @@ local _lcd = {} do
end end
-- loads an image to the screen -- loads an image to the screen
local function image(t, src, x, y) _lcd.image = function(t, src, x, y)
if not src then --make sure an image was passed, otherwise bail if not src then --make sure an image was passed, otherwise bail
rb.splash(rb.HZ, "No Image!") rb.splash(rb.HZ, "No Image!")
return _NIL return _NIL
@ -98,19 +97,19 @@ local _lcd = {} do
end end
-- Formattable version of splash -- Formattable version of splash
local function splashf(t, timeout, ...) _lcd.splashf = function(t, timeout, ...)
rb.splash(timeout, string.format(...)) rb.splash(timeout, string.format(...))
end end
-- Gets size of text -- Gets size of text
local function text_extent(t, msg, font) _lcd.text_extent = function(t, msg, font)
font = font or rb.FONT_UI font = font or rb.FONT_UI
return rb.font_getstringsize(msg, font) return rb.font_getstringsize(msg, font)
end end
-- Sets viewport size -- Sets viewport size
local function set_viewport(t, vp) _lcd.set_viewport = function(t, vp)
if not vp then rb.set_viewport() return end if not vp then rb.set_viewport() return end
if rb.LCD_DEPTH == 2 then -- invert 2-bit screens if rb.LCD_DEPTH == 2 then -- invert 2-bit screens
--vp.drawmode = bit.bxor(vp.drawmode, 4) --vp.drawmode = bit.bxor(vp.drawmode, 4)
@ -133,14 +132,17 @@ local _lcd = {} do
end end
--expose functions to the outside through _lcd table --expose functions to the outside through _lcd table
--[[
_lcd.text_extent = text_extent _lcd.text_extent = text_extent
_lcd.set_viewport = set_viewport _lcd.set_viewport = set_viewport
_lcd.duplicate = duplicate _lcd.duplicate = duplicate
_lcd.update = rb.lcd_update _lcd.update = _update
_lcd.update_rect = update_rect _lcd.update_rect = update_rect
_lcd.clear = clear _lcd.clear = clear
_lcd.splashf = splashf _lcd.splashf = splashf
_lcd.image = image _lcd.image = image
]]
_lcd.update = rb.lcd_update
_lcd.DEPTH = rb.LCD_DEPTH _lcd.DEPTH = rb.LCD_DEPTH
_lcd.W = rb.LCD_WIDTH _lcd.W = rb.LCD_WIDTH
_lcd.H = rb.LCD_HEIGHT _lcd.H = rb.LCD_HEIGHT

View file

@ -49,13 +49,12 @@ local _print = {} do
local _NIL = nil -- _NIL placeholder local _NIL = nil -- _NIL placeholder
local _LCD = rb.lcd_framebuffer() local _LCD = rb.lcd_framebuffer()
local LCD_W, LCD_H = rb.LCD_WIDTH, rb.LCD_HEIGHT
local WHITE = _clr.set(-1, 255, 255, 255) local WHITE = _clr.set(-1, 255, 255, 255)
local BLACK = _clr.set(0, 0, 0, 0) local BLACK = _clr.set(0, 0, 0, 0)
local DRMODE_SOLID = 3 local DRMODE_SOLID = 3
local col_buf, s_lines = {}, {} local col_buf, s_lines = {}, {}
local _p_opts = _NIL local _p_opts = _NIL
local tabstring = string.rep(" ", 2)
-- print internal helper functions -- print internal helper functions
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- clamps value to >= min and <= max -- clamps value to >= min and <= max
@ -69,46 +68,20 @@ local _print = {} do
return max return max
end end
-- updates screen in specified rectangle
local function update_rect(x, y, w, h)
rb.lcd_update_rect(x - 1, y - 1,
clamp(x + w, 1, LCD_W) - 1,
clamp(y + h, 1, LCD_H) - 1)
end
-- Gets size of text -- Gets size of text
local function text_extent(msg, font) local function text_extent(msg, font)
font = font or rb.FONT_UI
-- res, w, h -- res, w, h
return rb.font_getstringsize(msg, font) return rb.font_getstringsize(msg, font or rb.FONT_UI)
end
-- Sets viewport size
local function set_viewport(vp)
if not vp then rb.set_viewport() return end
if rb.LCD_DEPTH == 2 then -- invert 2-bit screens
--vp.drawmode = bit.bxor(vp.drawmode, 4)
vp.fg_pattern = 3 - vp.fg_pattern
vp.bg_pattern = 3 - vp.bg_pattern
end
rb.set_viewport(vp)
end
-- shallow copy of table
function table_clone(t)
local copy = {}
for k, v in pairs(t) do
copy[k] = v
end
return copy
end end
-- Updates a single line on the screen -- Updates a single line on the screen
local function update_line(enabled, opts, line, h) local function update_line(enabled, opts, line, h)
if enabled ~= true then return end if enabled ~= true then return end
local o = opts or _p_opts local o = opts or _p_opts
update_rect(o.x, o.y + line * h + 1, o.width, h) -- updates screen in specified rectangle
rb.lcd_update_rect(o.x - 1, o.y + line * h,
clamp(o.x + o.width, 1, rb.LCD_WIDTH) - 1,
clamp(o.y + line * h + 1 + h, 1, rb.LCD_HEIGHT) - 1)
end end
-- Clears a single line on the screen -- Clears a single line on the screen
@ -129,22 +102,23 @@ local _print = {} do
local function col_buf_insert(msg, line, _p_opts) local function col_buf_insert(msg, line, _p_opts)
--if _p_opts.line <= 1 then col_buf = {} end --if _p_opts.line <= 1 then col_buf = {} end
if not col_buf[line] then if not col_buf[line] then
table.insert(col_buf, line, msg) end table.insert(col_buf, line, msg)
end
end end
--replaces / strips escape characters --replaces / strips tab characters
local function check_escapes(o, msg) local function check_escapes(o, msg)
--[[ --for replacing a variety of escapes
local tabsz = 2 local tabsz = 2
local tabstr = string.rep(" ", tabsz) local tabstr = string.rep(" ", tabsz)
local function repl(esc) local function repl(esc)
local ret = "" local ret = ""
if esc:sub(1,1) == "\t" then ret = string.rep(tabstr, esc:len()) end if esc:sub(1,1) == "\t" then ret = string.rep(tabstr, esc:len()) end
return ret return ret
end end
msg = msg:gsub("(%c+)", repl) msg = msg:gsub("(%c+)", repl)
]]
msg = msg:gsub("\t", tabstring)
local res, w, h = text_extent(msg, o.font) local res, w, h = text_extent(msg, o.font)
return w, h, msg return w, h, msg
end end
@ -154,8 +128,8 @@ local _print = {} do
local function set_defaults() local function set_defaults()
_p_opts = { x = 1, _p_opts = { x = 1,
y = 1, y = 1,
width = LCD_W - 1, width = rb.LCD_WIDTH - 1,
height = LCD_H - 1, height = rb.LCD_HEIGHT - 1,
font = rb.FONT_UI, font = rb.FONT_UI,
drawmode = DRMODE_SOLID, drawmode = DRMODE_SOLID,
fg_pattern = WHITE, fg_pattern = WHITE,
@ -178,7 +152,15 @@ local _print = {} do
-- if bByRef is _NIL or false then a copy is returned -- if bByRef is _NIL or false then a copy is returned
local function get_settings(bByRef) local function get_settings(bByRef)
_p_opts = _p_opts or set_defaults() _p_opts = _p_opts or set_defaults()
if not bByRef then return table_clone(_p_opts) end if not bByRef then
-- shallow copy of table
local copy = {}
for k, v in pairs(_p_opts) do
copy[k] = v
end
return copy
end
return _p_opts return _p_opts
end end
@ -216,7 +198,16 @@ local _print = {} do
-- alternative selection method -- alternative selection method
--msg = "> " .. msg --msg = "> " .. msg
end end
set_viewport(o)
if not o then rb.set_viewport() return end
if rb.LCD_DEPTH == 2 then -- invert 2-bit screens
o.fg_pattern = 3 - o.fg_pattern
o.bg_pattern = 3 - o.bg_pattern
end
rb.set_viewport(o)
o = _NIL o = _NIL
end end
@ -251,8 +242,8 @@ local _print = {} do
-- sets print area -- sets print area
local function set_area(x, y, w, h) local function set_area(x, y, w, h)
local o = get_settings(true) local o = get_settings(true)
o.x, o.y = clamp(x, 1, LCD_W), clamp(y, 1, LCD_H) o.x, o.y = clamp(x, 1, rb.LCD_WIDTH), clamp(y, 1, rb.LCD_HEIGHT)
o.width, o.height = clamp(w, 1, LCD_W - o.x), clamp(h, 1, LCD_H - o.y) o.width, o.height = clamp(w, 1, rb.LCD_WIDTH - o.x), clamp(h, 1, rb.LCD_HEIGHT - o.y)
o.max_line = max_lines(_p_opts) o.max_line = max_lines(_p_opts)
clear() clear()
@ -312,6 +303,7 @@ local _print = {} do
local o = get_settings(true) local o = get_settings(true)
local w, h, msg local w, h, msg
local line = o.line - 1 -- rb is 0-based lua is 1-based local line = o.line - 1 -- rb is 0-based lua is 1-based
if not (...) or (...) == "\n" then -- handles blank line / single '\n' if not (...) or (...) == "\n" then -- handles blank line / single '\n'
local res, w, h = text_extent(" ", o.font) local res, w, h = text_extent(" ", o.font)

File diff suppressed because it is too large Load diff