Glyph baking: comparator-free edge sort (atlas pixels unchanged)
This commit is contained in:
1 parent
3a4fc158fa
commit
48ee9270f6
5 files changed
+113
-5
No files matched your search
Generated
+1
-1
@@ -1 +1 @@
|
||||
[[46, "imgui.lua"], [22664, "imgui_demo.lua"], [34521, "imgui_draw.lua"], [42861, "imgui_h.lua"], [45864, "roblox/raster.lua"], [46340, "roblox/textures.lua"], [46511, "roblox/layers.lua"], [46848, "roblox/overlays.lua"], [46929, "roblox/render.lua"], [47774, "roblox/parallel.lua"], [48173, "imgui_impl_roblox.lua"], [48674, "imgui_impl_roblox_fonts.lua"], [55077, "imgui_internal.lua"], [59045, "imgui_tables.lua"], [64137, "imgui_widgets.lua"], [76378, "imstb_rectpack.lua"], [77055, "imstb_textedit.lua"], [78597, "imstb_truetype.lua"], [81504, "imstd_minstdio.lua"]]
|
||||
[[46, "imgui.lua"], [22664, "imgui_demo.lua"], [34521, "imgui_draw.lua"], [42861, "imgui_h.lua"], [45864, "roblox/raster.lua"], [46340, "roblox/textures.lua"], [46511, "roblox/layers.lua"], [46848, "roblox/overlays.lua"], [46929, "roblox/render.lua"], [47774, "roblox/parallel.lua"], [48173, "imgui_impl_roblox.lua"], [48674, "imgui_impl_roblox_fonts.lua"], [55077, "imgui_internal.lua"], [59045, "imgui_tables.lua"], [64137, "imgui_widgets.lua"], [76378, "imstb_rectpack.lua"], [77055, "imstb_textedit.lua"], [78597, "imstb_truetype.lua"], [81540, "imstd_minstdio.lua"]]
|
||||
Generated
+37
-1
@@ -80975,6 +80975,42 @@ local function stbtt__sort_edges(p)
|
||||
STBTT_sort(p, STBTT__COMPARE)
|
||||
end
|
||||
|
||||
-- [Luau] sorts p[lo..hi] by y0 without a comparator callback (like upstream's stbtt__sort_edges_quicksort + ins_sort)
|
||||
@native
|
||||
local function stbtt__sort_edges_range(p, lo, hi)
|
||||
while hi - lo > 12 do
|
||||
-- median of three -> p[lo]
|
||||
local m = math.floor((lo + hi) / 2)
|
||||
local a, b, c = p[lo], p[m], p[hi]
|
||||
if b.y0 < a.y0 then a, b = b, a end
|
||||
if c.y0 < b.y0 then b, c = c, b; if b.y0 < a.y0 then a, b = b, a end end
|
||||
p[lo], p[m], p[hi] = b, a, c
|
||||
local pivot = p[lo].y0
|
||||
local i, j = lo + 1, hi
|
||||
while true do
|
||||
while p[i].y0 < pivot do i = i + 1 end
|
||||
while pivot < p[j].y0 do j = j - 1 end
|
||||
if i >= j then break end
|
||||
p[i], p[j] = p[j], p[i]
|
||||
i = i + 1; j = j - 1
|
||||
end
|
||||
p[lo], p[j] = p[j], p[lo]
|
||||
-- recurse into the smaller side, loop on the larger
|
||||
if j - lo < hi - j then
|
||||
stbtt__sort_edges_range(p, lo, j - 1); lo = j + 1
|
||||
else
|
||||
stbtt__sort_edges_range(p, j + 1, hi); hi = j - 1
|
||||
end
|
||||
end
|
||||
for i = lo + 1, hi do
|
||||
local t = p[i]
|
||||
local y = t.y0
|
||||
local j = i - 1
|
||||
while j >= lo and p[j].y0 > y do p[j + 1] = p[j]; j = j - 1 end
|
||||
p[j + 1] = t
|
||||
end
|
||||
end
|
||||
|
||||
--- @param result stbtt__bitmap
|
||||
--- @param pts stbtt__point[]
|
||||
--- @param wcount int[]
|
||||
@@ -81049,7 +81085,7 @@ local function stbtt__rasterize(result, pts, wcount, windings, scale_x, scale_y,
|
||||
end
|
||||
|
||||
-- now sort the edges by their highest point (should snap to integer, and then by x)
|
||||
stbtt__sort_edges(e)
|
||||
stbtt__sort_edges_range(e, 1, n) -- [Luau] e[n + 1..] are y0 == nil sentinels, already last
|
||||
|
||||
-- now, traverse the scanlines and find the intersections on each scanline, use xor winding rule
|
||||
stbtt__rasterize_sorted_edges(result, e, n, vsubsample, off_x, off_y)
|
||||
|
||||
Generated
+1
-1
@@ -1 +1 @@
|
||||
[[183, "imgui.lua"], [22801, "imgui_demo.lua"], [34658, "imgui_draw.lua"], [42998, "imgui_h.lua"], [45999, "imgui_impl_love.lua"], [46543, "imgui_internal.lua"], [50511, "imgui_tables.lua"], [55603, "imgui_widgets.lua"], [67844, "imstb_rectpack.lua"], [68521, "imstb_textedit.lua"], [70063, "imstb_truetype.lua"], [72970, "imstd_minstdio.lua"]]
|
||||
[[183, "imgui.lua"], [22801, "imgui_demo.lua"], [34658, "imgui_draw.lua"], [42998, "imgui_h.lua"], [45999, "imgui_impl_love.lua"], [46543, "imgui_internal.lua"], [50511, "imgui_tables.lua"], [55603, "imgui_widgets.lua"], [67844, "imstb_rectpack.lua"], [68521, "imstb_textedit.lua"], [70063, "imstb_truetype.lua"], [73006, "imstd_minstdio.lua"]]
|
||||
Generated
+37
-1
@@ -72441,6 +72441,42 @@ local function stbtt__sort_edges(p)
|
||||
STBTT_sort(p, STBTT__COMPARE)
|
||||
end
|
||||
|
||||
-- [Luau] sorts p[lo..hi] by y0 without a comparator callback (like upstream's stbtt__sort_edges_quicksort + ins_sort)
|
||||
|
||||
local function stbtt__sort_edges_range(p, lo, hi)
|
||||
while hi - lo > 12 do
|
||||
-- median of three -> p[lo]
|
||||
local m = math.floor((lo + hi) / 2)
|
||||
local a, b, c = p[lo], p[m], p[hi]
|
||||
if b.y0 < a.y0 then a, b = b, a end
|
||||
if c.y0 < b.y0 then b, c = c, b; if b.y0 < a.y0 then a, b = b, a end end
|
||||
p[lo], p[m], p[hi] = b, a, c
|
||||
local pivot = p[lo].y0
|
||||
local i, j = lo + 1, hi
|
||||
while true do
|
||||
while p[i].y0 < pivot do i = i + 1 end
|
||||
while pivot < p[j].y0 do j = j - 1 end
|
||||
if i >= j then break end
|
||||
p[i], p[j] = p[j], p[i]
|
||||
i = i + 1; j = j - 1
|
||||
end
|
||||
p[lo], p[j] = p[j], p[lo]
|
||||
-- recurse into the smaller side, loop on the larger
|
||||
if j - lo < hi - j then
|
||||
stbtt__sort_edges_range(p, lo, j - 1); lo = j + 1
|
||||
else
|
||||
stbtt__sort_edges_range(p, j + 1, hi); hi = j - 1
|
||||
end
|
||||
end
|
||||
for i = lo + 1, hi do
|
||||
local t = p[i]
|
||||
local y = t.y0
|
||||
local j = i - 1
|
||||
while j >= lo and p[j].y0 > y do p[j + 1] = p[j]; j = j - 1 end
|
||||
p[j + 1] = t
|
||||
end
|
||||
end
|
||||
|
||||
--- @param result stbtt__bitmap
|
||||
--- @param pts stbtt__point[]
|
||||
--- @param wcount int[]
|
||||
@@ -72515,7 +72551,7 @@ local function stbtt__rasterize(result, pts, wcount, windings, scale_x, scale_y,
|
||||
end
|
||||
|
||||
-- now sort the edges by their highest point (should snap to integer, and then by x)
|
||||
stbtt__sort_edges(e)
|
||||
stbtt__sort_edges_range(e, 1, n) -- [Luau] e[n + 1..] are y0 == nil sentinels, already last
|
||||
|
||||
-- now, traverse the scanlines and find the intersections on each scanline, use xor winding rule
|
||||
stbtt__rasterize_sorted_edges(result, e, n, vsubsample, off_x, off_y)
|
||||
|
||||
+37
-1
@@ -2379,6 +2379,42 @@ local function stbtt__sort_edges(p)
|
||||
STBTT_sort(p, STBTT__COMPARE)
|
||||
end
|
||||
|
||||
-- [Luau] sorts p[lo..hi] by y0 without a comparator callback (like upstream's stbtt__sort_edges_quicksort + ins_sort)
|
||||
@native
|
||||
local function stbtt__sort_edges_range(p, lo, hi)
|
||||
while hi - lo > 12 do
|
||||
-- median of three -> p[lo]
|
||||
local m = math.floor((lo + hi) / 2)
|
||||
local a, b, c = p[lo], p[m], p[hi]
|
||||
if b.y0 < a.y0 then a, b = b, a end
|
||||
if c.y0 < b.y0 then b, c = c, b; if b.y0 < a.y0 then a, b = b, a end end
|
||||
p[lo], p[m], p[hi] = b, a, c
|
||||
local pivot = p[lo].y0
|
||||
local i, j = lo + 1, hi
|
||||
while true do
|
||||
while p[i].y0 < pivot do i = i + 1 end
|
||||
while pivot < p[j].y0 do j = j - 1 end
|
||||
if i >= j then break end
|
||||
p[i], p[j] = p[j], p[i]
|
||||
i = i + 1; j = j - 1
|
||||
end
|
||||
p[lo], p[j] = p[j], p[lo]
|
||||
-- recurse into the smaller side, loop on the larger
|
||||
if j - lo < hi - j then
|
||||
stbtt__sort_edges_range(p, lo, j - 1); lo = j + 1
|
||||
else
|
||||
stbtt__sort_edges_range(p, j + 1, hi); hi = j - 1
|
||||
end
|
||||
end
|
||||
for i = lo + 1, hi do
|
||||
local t = p[i]
|
||||
local y = t.y0
|
||||
local j = i - 1
|
||||
while j >= lo and p[j].y0 > y do p[j + 1] = p[j]; j = j - 1 end
|
||||
p[j + 1] = t
|
||||
end
|
||||
end
|
||||
|
||||
--- @param result stbtt__bitmap
|
||||
--- @param pts stbtt__point[]
|
||||
--- @param wcount int[]
|
||||
@@ -2453,7 +2489,7 @@ local function stbtt__rasterize(result, pts, wcount, windings, scale_x, scale_y,
|
||||
end
|
||||
|
||||
-- now sort the edges by their highest point (should snap to integer, and then by x)
|
||||
stbtt__sort_edges(e)
|
||||
stbtt__sort_edges_range(e, 1, n) -- [Luau] e[n + 1..] are y0 == nil sentinels, already last
|
||||
|
||||
-- now, traverse the scanlines and find the intersections on each scanline, use xor winding rule
|
||||
stbtt__rasterize_sorted_edges(result, e, n, vsubsample, off_x, off_y)
|
||||
|
||||
Reference in new issue
Block a user