-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoutline.lua
84 lines (66 loc) · 2.09 KB
/
outline.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
--[[
==Pixel Outline v1.00 (LUA)==
Outlines current layer with 1px of fg colour
By Rik Nicol / @hot_pengu / https://github.com/rikfuzz/aseprite-scripts
Requirements
Aseprite (Currently requires Aseprite v1.2.10-beta2)
Click "Open Scripts Folder" in File > Scripts and drag the script into the folder.
]]--
local newImage = Image(app.activeImage.width+2,app.activeImage.height+2)
newImage:putImage(app.activeImage,1,1)
local function clrpx(color)
return app.pixelColor.rgba(color.red, color.green, color.blue, color.alpha)
end
local outlineColor = app.fgColor;
outlineColor = clrpx(outlineColor);
local function isTransparent(a)
return app.pixelColor.rgbaA(a) == 0
end
local function getPixel(x,y)
if(x>=newImage.width) then
return app.pixelColor.rgba(0, 0, 0, 0)
end
if(y>=newImage.height) then
return app.pixelColor.rgba(0, 0, 0, 0)
end
if(x<0) then
return app.pixelColor.rgba(0, 0, 0, 0)
end
if(y<0) then
return app.pixelColor.rgba(0, 0, 0, 0)
end
return newImage:getPixel(x, y)
end
local function putPixel(color,x,y)
return newImage:putPixel(x, y, color)
end
local outlinePlacesX = {};
local outlinePlacesY = {};
local function pushOutline(x,y)
table.insert(outlinePlacesX,x)
table.insert(outlinePlacesY,y)
end
local function ol()
local testGrid = {};
local imageGrid = {};
for y=0,newImage.height do
for x=0,newImage.width do
if isTransparent(getPixel(x,y)) and
(not isTransparent(getPixel(x-1,y)) or
not isTransparent(getPixel(x+1,y)) or
not isTransparent(getPixel(x,y+1)) or
not isTransparent(getPixel(x,y-1))) then
pushOutline(x,y)
end
end
end
for i=1,#outlinePlacesX do
putPixel(outlineColor,outlinePlacesX[i],outlinePlacesY[i])
end
end
ol()
app.transaction(
function()
app.activeCel.position = {x=app.activeCel.position.x-1,y=app.activeCel.position.y-1}
app.activeCel.image = newImage;
end)