Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "gd"
- local base = gd.createFromJpeg("frm/frm1.jpg")
- local black = base:colorAllocate(0, 0, 0)
- local sizex, sizey = base:sizeXY()
- local frame = gd.create(sizex, sizey)
- function lum(c)
- local r = base:red(c)
- local g = base:green(c)
- local b = base:blue(c)
- return (r+g+b)/3
- end
- function sortfrmv(base, sizex, sizey, p2p, threshold, ord)
- local out = gd.createTrueColor(sizex, sizey)
- for x = 1, sizex do
- local startsort = 1
- local sortc = base:getPixel(x, 1)
- local sortw = lum(sortc)
- local sortlist = {{c = sortc, w = sortw}}
- for y = 2, sizey do
- local color = base:getPixel(x, y)
- local w = lum(color)
- if (p2p and math.abs(w-sortlist[#sortlist].w) > threshold)
- or (not p2p and math.abs(w-sortw) > threshold) or y == sizey then
- if ord == 'inc' then
- table.sort(sortlist, function(a, b) return a.w < b.w end)
- elseif ord == 'dec' then
- table.sort(sortlist, function(a, b) return a.w > b.w end)
- else
- if sortlistside(sortlist) < 0 then
- table.sort(sortlist, function(a, b) return a.w < b.w end)
- else
- table.sort(sortlist, function(a, b) return a.w > b.w end)
- end
- end
- for ly = 1, #sortlist do
- out:setPixel(x, startsort+ly-1, sortlist[ly].c)
- end
- startsort = y
- sortw = w
- sortlist = {{c = color, w = w}}
- else
- table.insert(sortlist, {c = color, w = w})
- end
- end
- end
- return out
- end
- function sortfrmh(base, sizex, sizey, p2p, threshold, ord)
- local out = gd.createTrueColor(sizex, sizey)
- for y = 1, sizey do
- local startsort = 1
- local sortc = base:getPixel(1, y)
- local sortw = lum(sortc)
- local sortlist = {{c = sortc, w = sortw}}
- for x = 2, sizex do
- local color = base:getPixel(x, y)
- local w = lum(color)
- if (p2p and math.abs(w-sortlist[#sortlist].w) > threshold)
- or (not p2p and math.abs(w-sortw) > threshold) or x == sizex then
- if ord == "inc" then
- table.sort(sortlist, function(a, b) return a.w < b.w end)
- elseif ord == "dec" then
- table.sort(sortlist, function(a, b) return a.w > b.w end)
- else
- if sortlistside(sortlist) < 0 then
- table.sort(sortlist, function(a, b) return a.w < b.w end)
- else
- table.sort(sortlist, function(a, b) return a.w > b.w end)
- end
- end
- for lx = 1, #sortlist do
- out:setPixel(startsort+lx-1, y, sortlist[lx].c)
- end
- startsort = x
- sortw = w
- sortlist = {{c = color, w = w}}
- else
- table.insert(sortlist, {c = color, w = w})
- end
- end
- end
- return out
- end
- frame:gifAnimBegin("out.gif", false, 0)
- for frm = 1, 50 do
- base = gd.createFromJpeg("frm/frm"..frm..".jpg")
- local th = frm-1
- local sorted = sortfrmv(base, sizex, sizey, true, th, 'dec')
- frame = sorted:createPaletteFromTrueColor(true, 40)
- frame:gifAnimAdd("out.gif", true, 0, 0, 8, gd.DISPOSAL_NONE)
- print("frame:", frm, "threshold:", th)
- end
- gd.gifAnimEnd("out.gif")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement