get("#388") -- rect functions get("#348") -- rgb functions get("#356") -- num2hex get("#430") -- makeIcon get("#428") -- findContents get("#431") -- LXTerminal character reference get("#433") -- iconDiff function getIconSize(icon) local i = 1 while string.sub(icon, i, i) ~= '.' do i = i+1 end local w = i-1 -- #icon+1 = (w+1)*h -- => h = (#icon+1)/(w+1) local h = (#icon+1)/(w+1) return w, h end fw_, fh_ = getIconSize(characterReference[1][2]) print("fw/fh", fw_, fh_) function recognizeChar(icon) local best, min for _, ic in ipairs(characterReference) do local c, reficon = unpack(ic) local diff if min ~= nil then diff = iconDiffWithLimit(icon, reficon, min, fw_, fh_) else diff = iconDiff(icon, reficon) end --print("c", c, "diff", diff, "reficon", reficon) if diff ~= nil and (min == nil or diff < min) then best, min = c, diff end end return best, min end return function() local problem = findContents() if problem then return --[[problem]] end local fw, fh = 8, 17 -- font width/height local tw = math.floor((contents_x2-contents_x1)/fw+0.5) local th = math.floor((contents_y2-contents_y1)/fh+0.5) print("Terminal size: "..tw.."*"..th) local tbl = {} local maxdiff, maxc for y = 0, th-1 do line = {} for x = 0, tw-1 do local xx, yy = contents_x1+x*fw+1, contents_y1+y*fh local cropped = {width=fw-1, height=fh-1, getInt = function(x, y) return img.getInt(xx+x, yy+y) end} local icon = makeIcon(cropped) local c, diff = recognizeChar(icon) if maxdiff == nil or diff > maxdiff then maxdiff, maxc = diff, c end --print("c: "..tostring(c)..", diff: "..tostring(diff)..", icon: "..icon) table.insert(line, c or "?") end table.insert(tbl, table.concat(line)) end print("maxdiff", maxdiff, "c", maxc) return "Screen text:\n"..table.concat(tbl, "\n") end