From a99161a2d20ae7a56c097cbd39dd1926f81d1f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Capello?= Date: Wed, 4 Dec 2024 14:13:58 -0300 Subject: [PATCH] Add MaskByColor command lua tests --- tests/scripts/app_command.lua | 99 +++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/tests/scripts/app_command.lua b/tests/scripts/app_command.lua index 4f70e5d1e..646b838ee 100644 --- a/tests/scripts/app_command.lua +++ b/tests/scripts/app_command.lua @@ -664,3 +664,102 @@ do expect_img(i, { 1, 1, 1, 1, 1, 0, 0, 1 }) end + +-- MaskByColor +do + local s = Sprite(5, 5, ColorMode.INDEXED) + local c = s.cels[1] + local i = c.image + array_to_pixels({ + 1, 1, 0, 0, 1, + 1, 1, 0, 0, 1, + 1, 0, 0, 0, 1, + 1, 0, 0, 1, 1, + 1, 0, 0, 1, 1, + }, i) + + app.command.MaskByColor { + color = Color{ index=1 }, + tolerance = 0, + } + app.fgColor = Color{ index=2 } + app.command.Fill() + + expect_img(i, { + 2, 2, 0, 0, 2, + 2, 2, 0, 0, 2, + 2, 0, 0, 0, 2, + 2, 0, 0, 2, 2, + 2, 0, 0, 2, 2, + }) + + -- Subtract from current selection by color + app.command.MaskAll {} + app.command.MaskByColor { + color = Color{ index=2 }, + tolerance = 0, + mode = SelectionMode.SUBTRACT, + } + + app.fgColor = Color{ index=3 } + app.command.Fill() + + expect_img(i, { + 2, 2, 3, 3, 2, + 2, 2, 3, 3, 2, + 2, 3, 3, 3, 2, + 2, 3, 3, 2, 2, + 2, 3, 3, 2, 2, + }) + + -- Add to current selection by color + app.command.MaskByColor { + color = Color{ index=2 }, + tolerance = 0, + mode = SelectionMode.ADD, + } + app.fgColor = Color{ index=4 } + app.command.Fill() + + expect_img(i, { + 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, + }) + + -- Reset image for new test + array_to_pixels({ + 1, 1, 0, 0, 1, + 1, 1, 0, 0, 1, + 1, 0, 0, 0, 1, + 1, 0, 0, 1, 1, + 1, 0, 0, 1, 1, + }, i) + + -- Select a centered 3x3 square + app.command.MaskAll {} + app.command.ModifySelection { + modifier = 'contract', + quantity = 1, + brush = 'square' + } + -- Intersect with current selection by color + app.command.MaskByColor { + color = Color{ index=1 }, + tolerance = 0, + mode = SelectionMode.INTERSECT, + } + + app.fgColor = Color{ index=2 } + app.command.Fill() + + expect_img(i, { + 1, 1, 0, 0, 1, + 1, 2, 0, 0, 1, + 1, 0, 0, 0, 1, + 1, 0, 0, 2, 1, + 1, 0, 0, 1, 1, + }) +end