Skip to content

Commit

Permalink
Fix when using a background layer, switching to Indexed Color Mode
Browse files Browse the repository at this point in the history
fills all layer bounding rectangles with Color 0 (fix aseprite#4438)

Conditions to reproduce the original issue:
- Opaque RGBA sprite, i.e. the bottom layer is 'Background'.
- There is a second layer with an ellipse (for example).
- There is a mask color #000000 alpha=0 is in the palette.
- The mask color index is greater and not equal than 0.
- Go to Sprite > Color Mode > Indexed.
Result: the transparent color of the second layer will change to
index color = 0 (usually black).

Also added a test.
  • Loading branch information
Gasparoken committed Jun 12, 2024
1 parent 8f7bf09 commit ceb93b3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
12 changes: 4 additions & 8 deletions src/doc/sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,14 +456,10 @@ RgbMap* Sprite::rgbMap(const frame_t frame,
return nullptr;
}
}
int maskIndex;
if (forLayer == RgbMapFor::OpaqueLayer)
maskIndex = -1;
else {
maskIndex = palette(frame)->findMaskColor();
if (maskIndex == -1)
maskIndex = 0;
}
int maskIndex = palette(frame)->findMaskColor();
maskIndex = (maskIndex == -1 ?
(forLayer == RgbMapFor::OpaqueLayer ? -1 : 0)
: maskIndex);
m_rgbMap->regenerateMap(palette(frame), maskIndex);
return m_rgbMap.get();
}
Expand Down
40 changes: 39 additions & 1 deletion tests/scripts/color_convert.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Copyright (C) 2019-2022 Igara Studio S.A.
-- Copyright (C) 2019-2024 Igara Studio S.A.
--
-- This file is released under the terms of the MIT license.
-- Read LICENSE.txt for more information.
Expand Down Expand Up @@ -49,3 +49,41 @@ do
end
end
end

-- Test of mask color conversion in a opaque sprite with
-- extra non-opaque layers.
-- Conditions:
-- + There is a background layer
-- + There is an extra layer drawn
-- + The mask color is in the palette and whose index is greater than 0
-- + RGBA->INDEXED conversion
do
local sprite = Sprite(3, 3, ColorMode.RGB)
app.command.BackgroundFromLayer()
local pal = sprite.palettes[1]
local backgroundLayer = sprite.layers[1]

assert(sprite.layers[1].isBackground)
assert(sprite.colorMode == ColorMode.RGB)
assert(sprite.layers[1]:cel(1).image:getPixel(0, 0) == app.pixelColor.rgba(0,0,0,255))
assert(#pal == 256)

pal:setColor(0, Color{ r=255, g=0 , b=0 , a=255 })
pal:setColor(1, Color{ r=0 , g=0 , b=0 , a=0 })
pal:setColor(2, Color{ r=0 , g=255, b=0 , a=255 })
pal:setColor(3, Color{ r=0 , g=0 , b=255, a=255 })
local layer = sprite:newLayer()
app.useTool {
tool='pencil',
color=pal:getColor(2),
points={ Point(0, 1), Point(1, 0) },
layer=Layer
}

app.command.ChangePixelFormat {
format="indexed"
}

assert(pal:getColor(1) == Color{r=0 , g=0 , b=0 , a=0})
assert(layer:cel(1).image:getPixel(0, 0) == 1)
end

0 comments on commit ceb93b3

Please sign in to comment.