From ba07886a4fd35962c045617f038c75e5b1cb4bed Mon Sep 17 00:00:00 2001 From: hkc Date: Thu, 18 Jan 2024 15:12:24 +0300 Subject: [PATCH] Some more checks in ccpi --- ccpi.lua | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/ccpi.lua b/ccpi.lua index af1c31c..b230169 100644 --- a/ccpi.lua +++ b/ccpi.lua @@ -18,15 +18,22 @@ local function load(path) image.palette[i] = bit.bor(image.palette[i], string.byte(fp:read(1))) end + print(image.w, image.h) + for y = 1, image.h do local line = { s = "", bg = "", fg = "" } for x = 1, image.w do - line.s = line.s .. fp:read(1) - local char = fp:read(1) - if char == nil then + local data = fp:read(2) + if #data == 0 then + return nil, string.format("Failed to read character at x=%d y=%d", x, y) + end + + line.s = line.s .. data:sub(1, 1) + local color = string.byte(data, 2, 2) + + if color == nil then return nil, string.format("Failed to read color data for x=%d y=%d", x, y) end - local color = string.byte(char) line.bg = line.bg .. string.format("%x", bit.band(0xF, color)) line.fg = line.fg .. string.format("%x", bit.band(0xF, bit.brshift(color, 4))) end @@ -44,6 +51,14 @@ local function draw(img, ox, oy, monitor) ox = ox or 1 oy = oy or 1 + if not t.setPaletteColor then + return nil, "setPaletteColor is not supported on this term" + end + + if not t.setTextScale then + return nil, "setTextScale is not supported on this term" + end + for i = 1, 16 do t.setPaletteColor(bit.blshift(1, i - 1), img.palette[i]) end