forked from hkc/cc-stuff
1
0
Fork 0

Some more checks in ccpi

This commit is contained in:
Casey 2024-01-18 15:12:24 +03:00
parent c917da78cb
commit ba07886a4f
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 19 additions and 4 deletions

View File

@ -18,15 +18,22 @@ local function load(path)
image.palette[i] = bit.bor(image.palette[i], string.byte(fp:read(1))) image.palette[i] = bit.bor(image.palette[i], string.byte(fp:read(1)))
end end
print(image.w, image.h)
for y = 1, image.h do for y = 1, image.h do
local line = { s = "", bg = "", fg = "" } local line = { s = "", bg = "", fg = "" }
for x = 1, image.w do for x = 1, image.w do
line.s = line.s .. fp:read(1) local data = fp:read(2)
local char = fp:read(1) if #data == 0 then
if char == nil 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) return nil, string.format("Failed to read color data for x=%d y=%d", x, y)
end end
local color = string.byte(char)
line.bg = line.bg .. string.format("%x", bit.band(0xF, color)) 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))) line.fg = line.fg .. string.format("%x", bit.band(0xF, bit.brshift(color, 4)))
end end
@ -44,6 +51,14 @@ local function draw(img, ox, oy, monitor)
ox = ox or 1 ox = ox or 1
oy = oy 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 for i = 1, 16 do
t.setPaletteColor(bit.blshift(1, i - 1), img.palette[i]) t.setPaletteColor(bit.blshift(1, i - 1), img.palette[i])
end end