Add some tests for Simple and Alpha Compositing inks

This commit is contained in:
David Capello 2020-05-20 18:17:17 -03:00
parent f358262ad5
commit 6497147845
2 changed files with 91 additions and 4 deletions

87
scripts/inks.lua Normal file
View File

@ -0,0 +1,87 @@
-- Copyright (C) 2020 Igara Studio S.A.
--
-- This file is released under the terms of the MIT license.
-- Read LICENSE.txt for more information.
dofile('./test_utils.lua')
local pencil = "pencil"
function test_inks(colorMode)
-- Test ink over a transparent sprite
local s = Sprite(3, 3, colorMode)
local p, a, b, c, d
if colorMode == ColorMode.GRAY then
local function gray(g)
return app.pixelColor.graya(g, 255)
end
p = s.palettes[1]
a, b, c, d = gray(0), gray(64), gray(128), gray(255)
else
p = Palette()
p:resize(4)
p:setColor(0, Color(0, 0, 0))
p:setColor(1, Color(64, 64, 64))
p:setColor(2, Color(128, 128, 128))
p:setColor(3, Color(255, 255, 255))
s:setPalette(p)
a, b, c, d = 0, 1, 2, 3
if colorMode == ColorMode.RGB then
a = p:getColor(a).rgbaPixel
b = p:getColor(b).rgbaPixel
c = p:getColor(c).rgbaPixel
d = p:getColor(d).rgbaPixel
end
end
-- With simple ink opacity doesn't have affect (always the color)
local opacities = { 0, 128, 255 }
for i = 1,#opacities do
print(opacities[i])
expect_img(app.activeImage,
{ 0, 0, 0,
0, 0, 0,
0, 0, 0 })
app.useTool{ tool=pencil, color=d, points={ Point(0, 0), Point(2, 2) },
ink=Ink.SIMPLE, opacity=opacities[i] }
expect_img(app.activeImage,
{ d, 0, 0,
0, d, 0,
0, 0, d })
if i < #opacities then app.undo() end
end
-- Check that painting with transparent index (color) on a
-- transparent layer (using any value of opacity) with alpha
-- compositing doesn't modify pixels
for i = 1,#opacities do
app.useTool{ tool=pencil, color=0, points={ Point(1, 1) },
ink=Ink.ALPHA_COMPOSITING, opacity=opacities[i] }
expect_img(app.activeImage,
{ d, 0, 0,
0, d, 0,
0, 0, d })
end
-- Convert to background layer
app.command.BackgroundFromLayer()
app.useTool{ tool=pencil, color=d, points={ Point(0, 1), Point(2, 1) },
ink=Ink.ALPHA_COMPOSITING, opacity=64 }
expect_img(app.activeImage,
{ d, a, a,
b, d, b,
a, a, d })
app.useTool{ tool=pencil, color=d, points={ Point(0, 1) },
ink=Ink.ALPHA_COMPOSITING, opacity=86 }
expect_img(app.activeImage,
{ d, a, a,
c, d, b,
a, a, d })
end
test_inks(ColorMode.RGB)
test_inks(ColorMode.GRAY)
test_inks(ColorMode.INDEXED)

View File

@ -60,11 +60,11 @@ function expect_img(image, expectedPixels)
app.pixelColor.rgbaA(b)))
elseif image.colorMode == ColorMode.GRAY then
print(string.format(' - Value A = gray(%d,%d)',
app.pixelColor.grayG(a),
app.pixelColor.grayA(a)))
app.pixelColor.grayaV(a),
app.pixelColor.grayaA(a)))
print(string.format(' - Value B = gray(%d,%d)',
app.pixelColor.grayV(b),
app.pixelColor.grayA(b)))
app.pixelColor.grayaV(b),
app.pixelColor.grayaA(b)))
else
print(' - Value A = ' .. tostring(a))
print(' - Value B = ' .. tostring(b))