aseprite/scripts/image.lua

66 lines
1.5 KiB
Lua
Raw Normal View History

2018-08-31 02:23:31 +00:00
-- Copyright (C) 2018 David Capello
--
-- This file is released under the terms of the MIT license.
-- Read LICENSE.txt for more information.
2018-09-03 17:28:31 +00:00
local pc = app.pixelColor
2018-08-31 02:23:31 +00:00
local a = Image(32, 64)
assert(a.width == 32)
assert(a.height == 64)
assert(a.colorMode == ColorMode.RGB) -- RGB by default
assert(a:isEmpty())
assert(a:isPlain(pc.rgba(0, 0, 0, 0)))
assert(a:isPlain(0))
2018-08-31 02:23:31 +00:00
2018-09-03 17:28:31 +00:00
do
local b = Image(32, 64, ColorMode.INDEXED)
assert(b.width == 32)
assert(b.height == 64)
assert(b.colorMode == ColorMode.INDEXED)
end
2018-08-31 02:23:31 +00:00
-- Get/put RGBA pixels
2018-09-03 17:28:31 +00:00
do
for y=0,a.height-1 do
for x=0,a.width-1 do
a:putPixel(x, y, pc.rgba(x, y, x+y, x-y))
end
2018-08-31 02:23:31 +00:00
end
assert(not a:isEmpty())
2018-08-31 02:23:31 +00:00
end
-- Clone
2018-09-03 17:28:31 +00:00
do
local c = a:clone()
assert(c.width == 32)
assert(c.height == 64)
assert(c.colorMode == ColorMode.RGB)
2018-08-31 02:23:31 +00:00
2018-09-03 17:28:31 +00:00
-- Get RGB pixels
for y=0,c.height-1 do
for x=0,c.width-1 do
assert(c:getPixel(x, y) == pc.rgba(x, y, x+y, x-y))
end
2018-08-31 02:23:31 +00:00
end
end
-- Patch
2018-09-03 17:28:31 +00:00
do
local spr = Sprite(256, 256)
local image = app.site.image
local copy = image:clone()
assert(image:getPixel(0, 0) == 0)
for y=0,copy.height-1 do
for x=0,copy.width-1 do
copy:putPixel(x, y, pc.rgba(255-x, 255-y, 0, 255))
end
2018-08-31 02:23:31 +00:00
end
2018-09-03 17:28:31 +00:00
image:putImage(copy)
assert(image:getPixel(0, 0) == pc.rgba(255, 255, 0, 255))
assert(image:getPixel(255, 255) == pc.rgba(0, 0, 0, 255))
app.undo()
assert(image:getPixel(0, 0) == pc.rgba(0, 0, 0, 0))
assert(image:getPixel(255, 255) == pc.rgba(0, 0, 0, 0))
2018-08-31 02:23:31 +00:00
end