mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-28 16:20:50 +00:00
New tests to load/save Sprite/Image/Palette
This commit is contained in:
parent
ea4f6ce957
commit
585ffc91a4
@ -1,65 +1,94 @@
|
|||||||
|
-- Copyright (C) 2019 Igara Studio S.A.
|
||||||
-- Copyright (C) 2018 David Capello
|
-- Copyright (C) 2018 David Capello
|
||||||
--
|
--
|
||||||
-- This file is released under the terms of the MIT license.
|
-- This file is released under the terms of the MIT license.
|
||||||
-- Read LICENSE.txt for more information.
|
-- Read LICENSE.txt for more information.
|
||||||
|
|
||||||
local pc = app.pixelColor
|
local rgba = app.pixelColor.rgba
|
||||||
|
|
||||||
local a = Image(32, 64)
|
local a = Image(32, 64)
|
||||||
assert(a.width == 32)
|
assert(a.width == 32)
|
||||||
assert(a.height == 64)
|
assert(a.height == 64)
|
||||||
assert(a.colorMode == ColorMode.RGB) -- RGB by default
|
assert(a.colorMode == ColorMode.RGB) -- RGB by default
|
||||||
assert(a:isEmpty())
|
assert(a:isEmpty())
|
||||||
assert(a:isPlain(pc.rgba(0, 0, 0, 0)))
|
assert(a:isPlain(rgba(0, 0, 0, 0)))
|
||||||
assert(a:isPlain(0))
|
assert(a:isPlain(0))
|
||||||
|
|
||||||
do
|
do
|
||||||
local b = Image(32, 64, ColorMode.INDEXED)
|
local b = Image(32, 64, ColorMode.INDEXED)
|
||||||
assert(b.width == 32)
|
assert(b.width == 32)
|
||||||
assert(b.height == 64)
|
assert(b.height == 64)
|
||||||
assert(b.colorMode == ColorMode.INDEXED)
|
assert(b.colorMode == ColorMode.INDEXED)
|
||||||
|
|
||||||
|
local c = Image{ width=32, height=64, colorMode=ColorMode.INDEXED }
|
||||||
|
assert(c.width == 32)
|
||||||
|
assert(c.height == 64)
|
||||||
|
assert(c.colorMode == ColorMode.INDEXED)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get/put RGBA pixels
|
-- Get/put RGBA pixels
|
||||||
do
|
do
|
||||||
for y=0,a.height-1 do
|
for y=0,a.height-1 do
|
||||||
for x=0,a.width-1 do
|
for x=0,a.width-1 do
|
||||||
a:putPixel(x, y, pc.rgba(x, y, x+y, x-y))
|
a:putPixel(x, y, rgba(x, y, x+y, x-y))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
assert(not a:isEmpty())
|
assert(not a:isEmpty())
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Clone
|
-- Clone
|
||||||
do
|
do
|
||||||
local c = a:clone()
|
local c = Image(a)
|
||||||
assert(c.width == 32)
|
local d = a:clone()
|
||||||
assert(c.height == 64)
|
assert(c.width == 32)
|
||||||
assert(c.colorMode == ColorMode.RGB)
|
assert(c.height == 64)
|
||||||
|
assert(c.colorMode == ColorMode.RGB)
|
||||||
|
assert(c.width == d.width)
|
||||||
|
assert(c.height == d.height)
|
||||||
|
assert(c.colorMode == d.colorMode)
|
||||||
|
|
||||||
-- Get RGB pixels
|
-- Get RGB pixels
|
||||||
for y=0,c.height-1 do
|
for y=0,c.height-1 do
|
||||||
for x=0,c.width-1 do
|
for x=0,c.width-1 do
|
||||||
assert(c:getPixel(x, y) == pc.rgba(x, y, x+y, x-y))
|
local expectedColor = rgba(x, y, x+y, x-y)
|
||||||
end
|
assert(c:getPixel(x, y) == expectedColor)
|
||||||
end
|
assert(d:getPixel(x, y) == expectedColor)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Patch
|
-- Patch
|
||||||
do
|
do
|
||||||
local spr = Sprite(256, 256)
|
local spr = Sprite(256, 256)
|
||||||
local image = app.site.image
|
local image = app.site.image
|
||||||
local copy = image:clone()
|
local copy = image:clone()
|
||||||
assert(image:getPixel(0, 0) == 0)
|
assert(image:getPixel(0, 0) == 0)
|
||||||
for y=0,copy.height-1 do
|
for y=0,copy.height-1 do
|
||||||
for x=0,copy.width-1 do
|
for x=0,copy.width-1 do
|
||||||
copy:putPixel(x, y, pc.rgba(255-x, 255-y, 0, 255))
|
copy:putPixel(x, y, rgba(255-x, 255-y, 0, 255))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
image:putImage(copy)
|
image:putImage(copy)
|
||||||
assert(image:getPixel(0, 0) == pc.rgba(255, 255, 0, 255))
|
assert(image:getPixel(0, 0) == rgba(255, 255, 0, 255))
|
||||||
assert(image:getPixel(255, 255) == pc.rgba(0, 0, 0, 255))
|
assert(image:getPixel(255, 255) == rgba(0, 0, 0, 255))
|
||||||
app.undo()
|
app.undo()
|
||||||
assert(image:getPixel(0, 0) == pc.rgba(0, 0, 0, 0))
|
assert(image:getPixel(0, 0) == rgba(0, 0, 0, 0))
|
||||||
assert(image:getPixel(255, 255) == pc.rgba(0, 0, 0, 0))
|
assert(image:getPixel(255, 255) == rgba(0, 0, 0, 0))
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Load/Save
|
||||||
|
do
|
||||||
|
local a = Image{ fromFile="sprites/1empty3.aseprite" }
|
||||||
|
assert(a.width == 32)
|
||||||
|
assert(a.height == 32)
|
||||||
|
a:saveAs("_test_oneframe.png")
|
||||||
|
|
||||||
|
local b = Image{ fromFile="_test_oneframe.png" }
|
||||||
|
assert(b.width == 32)
|
||||||
|
assert(b.height == 32)
|
||||||
|
for y=0,a.height-1 do
|
||||||
|
for x=0,a.width-1 do
|
||||||
|
assert(a:getPixel(x, y) == b:getPixel(x, y))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,27 +1,51 @@
|
|||||||
|
-- Copyright (C) 2019 Igara Studio S.A.
|
||||||
-- Copyright (C) 2018 David Capello
|
-- Copyright (C) 2018 David Capello
|
||||||
--
|
--
|
||||||
-- This file is released under the terms of the MIT license.
|
-- This file is released under the terms of the MIT license.
|
||||||
-- Read LICENSE.txt for more information.
|
-- Read LICENSE.txt for more information.
|
||||||
|
|
||||||
local p = Palette()
|
do
|
||||||
assert(#p == 256)
|
local p = Palette()
|
||||||
for i = 0,#p-1 do
|
assert(#p == 256)
|
||||||
assert(p:getColor(i) == Color(0, 0, 0))
|
for i = 0,#p-1 do
|
||||||
|
assert(p:getColor(i) == Color(0, 0, 0))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
p = Palette(32)
|
do
|
||||||
assert(#p == 32)
|
local p = Palette(32)
|
||||||
for i = 0,#p-1 do
|
assert(#p == 32)
|
||||||
assert(p:getColor(i) == Color(0, 0, 0))
|
for i = 0,#p-1 do
|
||||||
|
assert(p:getColor(i) == Color(0, 0, 0))
|
||||||
|
end
|
||||||
|
|
||||||
|
p:resize(4)
|
||||||
|
assert(#p == 4)
|
||||||
|
p:setColor(0, Color(255, 8, 32))
|
||||||
|
p:setColor(1, Color(250, 4, 30))
|
||||||
|
p:setColor(2, Color(240, 3, 20))
|
||||||
|
p:setColor(3, Color(210, 2, 10))
|
||||||
|
assert(p:getColor(0) == Color(255, 8, 32))
|
||||||
|
assert(p:getColor(1) == Color(250, 4, 30))
|
||||||
|
assert(p:getColor(2) == Color(240, 3, 20))
|
||||||
|
assert(p:getColor(3) == Color(210, 2, 10))
|
||||||
end
|
end
|
||||||
|
|
||||||
p:resize(4)
|
-- Load/save
|
||||||
assert(#p == 4)
|
do
|
||||||
p:setColor(0, Color(255, 8, 32))
|
local p = Palette{ fromFile="sprites/abcd.aseprite" }
|
||||||
p:setColor(1, Color(250, 4, 30))
|
assert(#p == 5)
|
||||||
p:setColor(2, Color(240, 3, 20))
|
assert(p:getColor(0) == Color(0, 0, 0))
|
||||||
p:setColor(3, Color(210, 2, 10))
|
assert(p:getColor(1) == Color(25, 0, 255))
|
||||||
assert(p:getColor(0) == Color(255, 8, 32))
|
assert(p:getColor(2) == Color(255, 0, 0))
|
||||||
assert(p:getColor(1) == Color(250, 4, 30))
|
assert(p:getColor(3) == Color(255, 255, 0))
|
||||||
assert(p:getColor(2) == Color(240, 3, 20))
|
assert(p:getColor(4) == Color(0, 128, 0))
|
||||||
assert(p:getColor(3) == Color(210, 2, 10))
|
|
||||||
|
p:saveAs("_test_.gpl")
|
||||||
|
|
||||||
|
local q = Palette{ fromFile="_test_.gpl" }
|
||||||
|
assert(#p == #q)
|
||||||
|
for i=0,#q-1 do
|
||||||
|
assert(p:getColor(i) == q:getColor(i))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
-- Copyright (C) 2019 Igara Studio S.A.
|
||||||
-- Copyright (C) 2018 David Capello
|
-- Copyright (C) 2018 David Capello
|
||||||
--
|
--
|
||||||
-- This file is released under the terms of the MIT license.
|
-- This file is released under the terms of the MIT license.
|
||||||
@ -28,10 +29,22 @@ do
|
|||||||
assert(a.width == 8)
|
assert(a.width == 8)
|
||||||
assert(a.height == 10)
|
assert(a.height == 10)
|
||||||
|
|
||||||
local b = Sprite(4, 4, ColorMode.INDEXED)
|
-- Test other Sprite() constructors
|
||||||
|
local b = Sprite(4, 8, ColorMode.INDEXED)
|
||||||
assert(b.width == 4)
|
assert(b.width == 4)
|
||||||
assert(b.height == 4)
|
assert(b.height == 8)
|
||||||
assert(b.colorMode == ColorMode.INDEXED)
|
assert(b.colorMode == ColorMode.INDEXED)
|
||||||
|
|
||||||
|
local c = Sprite{ colorMode=ColorMode.INDEXED, width=10, height=20 }
|
||||||
|
assert(c.width == 10)
|
||||||
|
assert(c.height == 20)
|
||||||
|
assert(c.colorMode == ColorMode.INDEXED)
|
||||||
|
|
||||||
|
local d = Sprite{ fromFile="sprites/abcd.aseprite" }
|
||||||
|
assert(#d.layers == 4)
|
||||||
|
assert(d.width == 32)
|
||||||
|
assert(d.height == 32)
|
||||||
|
assert(d.colorMode == ColorMode.INDEXED)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Transparent color
|
-- Transparent color
|
||||||
@ -63,7 +76,7 @@ do
|
|||||||
assert(a.palettes[1]:getColor(2) == Color(0, 0, 255))
|
assert(a.palettes[1]:getColor(2) == Color(0, 0, 255))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Flatten
|
-- Duplicate & Flatten
|
||||||
|
|
||||||
do
|
do
|
||||||
local a = Sprite(32, 32)
|
local a = Sprite(32, 32)
|
||||||
@ -71,6 +84,8 @@ do
|
|||||||
a:newLayer()
|
a:newLayer()
|
||||||
assert(#a.layers == 3)
|
assert(#a.layers == 3)
|
||||||
|
|
||||||
a:flatten()
|
local b = Sprite(a) -- Clone a
|
||||||
|
a:flatten() -- Flatten a
|
||||||
assert(#a.layers == 1)
|
assert(#a.layers == 1)
|
||||||
|
assert(#b.layers == 3)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user