All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
48 lines
1.1 KiB
Lua
48 lines
1.1 KiB
Lua
--- @section RLE
|
|
RLE = {
|
|
data = {}
|
|
}
|
|
|
|
--- Registers an RLE-encoded image.
|
|
--- @param rle_data table Table containing 'id', 'values' and 'runs' arrays.
|
|
function RLE.register(rle_data)
|
|
table.insert(RLE.data, rle_data)
|
|
end
|
|
|
|
--- Gets the RLE data for a given ID.
|
|
--- @param id string The identifier of the image.
|
|
--- @return table|nil The RLE data or nil if not found.
|
|
function RLE.get(id)
|
|
for _, rle_data in ipairs(RLE.data) do
|
|
if rle_data.id == id then
|
|
return rle_data
|
|
end
|
|
end
|
|
return nil
|
|
end
|
|
|
|
--- Draws an RLE-encoded image by its ID.
|
|
--- @param id string The identifier of the image to draw.
|
|
function RLE.draw(id)
|
|
local rle_data = RLE.get(id)
|
|
if not rle_data then return end
|
|
|
|
local img_values = rle_data.values
|
|
local img_runs = rle_data.runs
|
|
|
|
local SCREEN_WIDTH=240
|
|
local SCREEN_HEIGHT=136
|
|
local val_i=0
|
|
local run=0
|
|
for y=0,SCREEN_HEIGHT-1 do
|
|
for x=0,SCREEN_WIDTH-1 do
|
|
if run==0 then
|
|
val_i=val_i+1
|
|
run=img_runs[val_i]
|
|
end
|
|
run=run-1
|
|
pix(x,y,img_values[val_i])
|
|
end
|
|
end
|
|
end
|