Skip to content

Commit

Permalink
Improve lossy artifacting and expose thresholds
Browse files Browse the repository at this point in the history
  • Loading branch information
boatbomber committed Apr 11, 2022
1 parent 7fa900a commit 87a4637
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
7 changes: 1 addition & 6 deletions src/Util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ function Util.DeltaRGB(a: Color3, b: Color3)
local l1, a1, b1 = Util.RGBtoLAB(a)
local l2, a2, b2 = Util.RGBtoLAB(b)

local delta = (l2 - l1) ^ 2 + (a2 - a1) ^ 2 + (b2 - b1) ^ 2
if delta < 900 then
return 0.02
else
return delta / 40000
end
return (l2 - l1) ^ 2 + (a2 - a1) ^ 2 + (b2 - b1) ^ 2
end

return Util
17 changes: 9 additions & 8 deletions src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ local Util = require(script.Util)

function module.new(ResX: number, ResY: number)
local Canvas = {
_ActiveFrames = 0,
_Active = 0,
_ColumnFrames = {},
_UpdatedColumns = {},

Threshold = 2,
LossyThreshold = 4,
}

local invX, invY = 1 / ResX, 1 / ResY
local dist = ResY * 0.03
local diff = 0.015
local lossy = diff + math.clamp(0.5 * (ResY / 250)^2, 0, 0.6)

-- Generate initial grid of color data
local Grid = table.create(ResX)
Expand Down Expand Up @@ -73,7 +74,7 @@ function module.new(ResX: number, ResY: number)
table.insert(Canvas._ColumnFrames[x], Frame)
end

Canvas._ActiveFrames += 1
Canvas._Active += 1
end

function Canvas:Destroy()
Expand Down Expand Up @@ -102,14 +103,14 @@ function module.new(ResX: number, ResY: number)

for _, object in ipairs(column) do
self._Pool:Return(object)
self._ActiveFrames -= 1
self._Active -= 1
end
table.clear(column)
else
for _, object in ipairs(Container:GetChildren()) do
self._Pool:Return(object)
end
self._ActiveFrames = 0
self._Active = 0
table.clear(self._ColumnFrames)
end
end
Expand All @@ -135,10 +136,10 @@ function module.new(ResX: number, ResY: number)
end

local delta = Util.DeltaRGB(lastColor, color)
if delta > diff then
if delta > self.Threshold then
local offset = y - pixelStart - 1

if (delta > lossy) or (y-lastPixel > dist) then
if (delta > self.LossyThreshold) or (y-lastPixel > dist) then
table.insert(colorData, { p = offset - 0.08, c = lastColor })
colorCount += 1
end
Expand Down

0 comments on commit 87a4637

Please sign in to comment.