mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-28 16:11:35 +00:00
Fix image:drawImage+BlendMode.SRC doesn't draw mask pixels (fix #5001)
Also added tests for Image:drawImage + BlendMode::SRC + ColorMode.RGBA
This commit is contained in:
parent
919f4f3321
commit
f2b870a17f
@ -1,5 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (c) 2024 Igara Studio S.A.
|
||||
// Copyright (c) 2024-2025 Igara Studio S.A.
|
||||
// Copyright (c) 2001-2015 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -26,6 +26,7 @@ namespace doc {
|
||||
|
||||
template<class DstTraits, class SrcTraits>
|
||||
class BlenderHelper {
|
||||
BlendMode m_blendMode;
|
||||
BlendFunc m_blendFunc;
|
||||
color_t m_maskColor;
|
||||
|
||||
@ -36,6 +37,7 @@ public:
|
||||
const BlendMode blendMode,
|
||||
const bool newBlend)
|
||||
{
|
||||
m_blendMode = blendMode;
|
||||
m_blendFunc = SrcTraits::get_blender(blendMode, newBlend);
|
||||
m_maskColor = src->maskColor();
|
||||
}
|
||||
@ -44,6 +46,8 @@ public:
|
||||
typename SrcTraits::pixel_t src,
|
||||
int opacity)
|
||||
{
|
||||
if (m_blendMode == BlendMode::SRC)
|
||||
return src;
|
||||
if (src != m_maskColor)
|
||||
return (*m_blendFunc)(dst, src, opacity);
|
||||
else
|
||||
@ -56,6 +60,7 @@ public:
|
||||
|
||||
template<>
|
||||
class BlenderHelper<RgbTraits, GrayscaleTraits> {
|
||||
BlendMode m_blendMode;
|
||||
BlendFunc m_blendFunc;
|
||||
color_t m_maskColor;
|
||||
|
||||
@ -66,6 +71,7 @@ public:
|
||||
const BlendMode blendMode,
|
||||
const bool newBlend)
|
||||
{
|
||||
m_blendMode = blendMode;
|
||||
m_blendFunc = RgbTraits::get_blender(blendMode, newBlend);
|
||||
m_maskColor = src->maskColor();
|
||||
}
|
||||
@ -74,6 +80,8 @@ public:
|
||||
GrayscaleTraits::pixel_t src,
|
||||
int opacity)
|
||||
{
|
||||
if (m_blendMode == BlendMode::SRC)
|
||||
return src;
|
||||
if (src != m_maskColor) {
|
||||
int v = graya_getv(src);
|
||||
return (*m_blendFunc)(dst, rgba(v, v, v, graya_geta(src)), opacity);
|
||||
|
@ -1,4 +1,4 @@
|
||||
-- Copyright (C) 2019-2024 Igara Studio S.A.
|
||||
-- Copyright (C) 2019-2025 Igara Studio S.A.
|
||||
-- Copyright (C) 2018 David Capello
|
||||
--
|
||||
-- This file is released under the terms of the MIT license.
|
||||
@ -352,6 +352,33 @@ do
|
||||
|
||||
end
|
||||
|
||||
-- Tests using Image:drawImage() with BlendMode::SRC + ColorMode.RGBA
|
||||
do
|
||||
local __ = Color(0, 0, 0, 0).rgbaPixel
|
||||
local oo = Color(255, 255, 255, 0).rgbaPixel
|
||||
local xx = Color(127, 127, 127, 127).rgbaPixel
|
||||
local rr = Color(255, 0, 0).rgbaPixel
|
||||
local BG = Color(127, 127, 127).rgbaPixel
|
||||
|
||||
local a_rgb = Image(3, 2, ColorMode.RGBA)
|
||||
array_to_pixels({ __, rr, xx,
|
||||
oo, rr, __ }, a_rgb)
|
||||
local b_rgb = Image(4, 4, ColorMode.RGBA)
|
||||
b_rgb:clear(BG)
|
||||
b_rgb:drawImage(a_rgb, Point(0, 1), 255, BlendMode.SRC)
|
||||
expect_img(b_rgb, { BG, BG, BG, BG,
|
||||
__, rr, xx, BG,
|
||||
oo, rr, __, BG,
|
||||
BG, BG, BG, BG })
|
||||
|
||||
b_rgb:clear(BG)
|
||||
b_rgb:drawImage(a_rgb, Point(-1, 2), 255, BlendMode.SRC)
|
||||
expect_img(b_rgb, { BG, BG, BG, BG,
|
||||
BG, BG, BG, BG,
|
||||
rr, xx, BG, BG,
|
||||
rr, __, BG, BG })
|
||||
end
|
||||
|
||||
-- Tests using Image:drawImage() with opacity and blend modes
|
||||
do
|
||||
local spr = Sprite(3, 3, ColorMode.RGB)
|
||||
|
Loading…
x
Reference in New Issue
Block a user