image formats: comments are specs only
This commit is contained in:
1 parent
0bd7b87d2b
commit
b5546e208e
40 files changed
+246
-626
No files matched your search
@@ -1,15 +1,12 @@
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- image/gif/Decode: the per-frame pixel work (native; never throws): palette indexes (plain or interlaced rows) to
|
||||
-- rgba8, and drawing a frame onto the canvas (transparent pixels leave the canvas as it is). The caller sizes every
|
||||
-- buffer: indexes fw * fh bytes, the palette 256 u32 entries, the frame fw * fh * 4, the canvas cw * ch * 4.
|
||||
-- image/gif/Decode: GIF frame pixels: palette indexes (plain or interlaced) to rgba8, drawn onto the canvas.
|
||||
local readu8, readu32, writeu32 = buffer.readu8, buffer.readu32, buffer.writeu32
|
||||
|
||||
local Decode = {}
|
||||
|
||||
-- the source row of output row y in an interlaced frame (passes: every 8th from 0, every 8th from 4, every 4th from
|
||||
-- 2, every 2nd from 1)
|
||||
-- interlace passes: every 8th row from 0, every 8th from 4, every 4th from 2, every 2nd from 1
|
||||
local function interlacedRow(fh: number): { number }
|
||||
local map = table.create(fh, 0)
|
||||
local r = 0
|
||||
@@ -24,8 +21,6 @@ local function interlacedRow(fh: number): { number }
|
||||
return map
|
||||
end
|
||||
|
||||
-- toRgba(indexes, fw, fh, interlaced, palette, out): out = the frame in rgba8 (palette: 256 u32 entries, the
|
||||
-- transparent one already alpha 0)
|
||||
function Decode.toRgba(indexes: buffer, fw: number, fh: number, interlaced: boolean, palette: buffer, out: buffer)
|
||||
local rows = if interlaced then interlacedRow(fh) else nil
|
||||
for y = 0, fh - 1 do
|
||||
@@ -37,7 +32,6 @@ function Decode.toRgba(indexes: buffer, fw: number, fh: number, interlaced: bool
|
||||
end
|
||||
end
|
||||
|
||||
-- draw(canvas, cw, ch, frame, fx, fy, fw, fh): frame pixels with alpha > 0 replace the canvas (clipped)
|
||||
function Decode.draw(canvas: buffer, cw: number, ch: number, frame: buffer, fx: number, fy: number, fw: number, fh: number)
|
||||
local x0, y0 = math.max(0, fx), math.max(0, fy)
|
||||
local x1, y1 = math.min(cw, fx + fw), math.min(ch, fy + fh)
|
||||
@@ -53,7 +47,6 @@ function Decode.draw(canvas: buffer, cw: number, ch: number, frame: buffer, fx:
|
||||
end
|
||||
end
|
||||
|
||||
-- clear(canvas, cw, ch, fx, fy, fw, fh): the frame's rectangle to transparent black (dispose to background)
|
||||
function Decode.clear(canvas: buffer, cw: number, ch: number, fx: number, fy: number, fw: number, fh: number)
|
||||
local x0, y0 = math.max(0, fx), math.max(0, fy)
|
||||
local x1, y1 = math.min(cw, fx + fw), math.min(ch, fy + fh)
|
||||
|
||||
Reference in new issue
Block a user