mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
* fix: update linear_blend to respect alpha channel * fix: update masked_blend to respect alpha channel Unclear if this is the right implementation. * misc: remove unnecessary fixed declaration * misc: update mask_blend * update changes.md * misc: fix typo in changes.md
This commit is contained in:
+5
-3
@@ -2,21 +2,23 @@ Magic Set Editor changelog, for the details see `git log`
|
||||
==============================================================================
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
version 2.5.0 (Unofficial), 2024-04-28
|
||||
version 2.5.0 (Unofficial), 2024-08-23
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
Features:
|
||||
* Add Russian and Korean translations. Update locale files from Full-Magic-Pack (haganbmj#69)
|
||||
* Increase stats column width by 50% (haganbmj#72)
|
||||
|
||||
Bug fixes:
|
||||
* Fixed scrolled widgets not scrolling fully (or at all) on Linux (@llemoi, haganbmj#54)
|
||||
* Fixed crash when 0 keywords match filter string in keyword panel (@llemoi, haganbmj#57)
|
||||
* Correct "all images" filter when selecting files. (haganbmj#70)
|
||||
* Correct "all images" filter when selecting files. (@BaconCatBug, haganbmj#70)
|
||||
* Correct localization of strings on Print window.
|
||||
* Fixed issue where "All Images" filter on the art picker was not showing .jpeg files (BaconCatBug)
|
||||
* Correct how blend functions handle alpha channels. (haganbmj#83)
|
||||
|
||||
Internal:
|
||||
* Add Mac OS build resources (@halian, haganbmj#67, haganbmj#68)
|
||||
* CMakeLists updates for static compilation. (@BackCatBug, haganbmj#74)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
version 2.4.0 (Unofficial), 2022-11-19
|
||||
|
||||
+36
-6
@@ -55,23 +55,53 @@ void linear_blend(Image& img1, const Image& img2, double x1,double y1, double x2
|
||||
data1 += 3;
|
||||
data2 += 3;
|
||||
}
|
||||
}
|
||||
|
||||
// Blend Alpha for the two images.
|
||||
if (img1.HasAlpha() && img2.HasAlpha()) {
|
||||
Byte *alpha1 = img1.GetAlpha(), *alpha2 = img2.GetAlpha();
|
||||
for (int y = 0; y < height; ++y) {
|
||||
for (int x = 0; x < width; ++x) {
|
||||
int mult = x * xm + y * ym + d;
|
||||
if (mult < 0) mult = 0;
|
||||
if (mult > fixed) mult = fixed;
|
||||
alpha1[0] = alpha1[0] + mult * (alpha2[0] - alpha1[0]) / fixed;
|
||||
alpha1 += 1;
|
||||
alpha2 += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Mask Blend
|
||||
|
||||
void mask_blend(Image& img1, const Image& img2, const Image& mask) {
|
||||
if (img2.GetWidth() != img1.GetWidth() || img2.GetHeight() != img1.GetHeight()
|
||||
|| mask.GetWidth() != img1.GetWidth() || mask.GetHeight() != img1.GetHeight()) {
|
||||
throw Error(_("Images used for blending must have the same size"));
|
||||
int width = img1.GetWidth(), height = img1.GetHeight();
|
||||
if (img2.GetWidth() != width || img2.GetHeight() != height) {
|
||||
throw Error(_("Images used for blending in masked_blend function must have the same size"));
|
||||
}
|
||||
|
||||
UInt size = img1.GetWidth() * img1.GetHeight() * 3;
|
||||
if (mask.GetWidth() != width || mask.GetHeight() != height) {
|
||||
throw Error(_("Mask used for blending in masked_blend function must have the same size as the images"));
|
||||
}
|
||||
|
||||
UInt size = width * height;
|
||||
// these have the following structure:
|
||||
// [pixel1red, pixel1green, pixel1blue, pixel2red, pixel2green, pixel2blue, pixel3red, etc...]
|
||||
Byte *data1 = img1.GetData(), *data2 = img2.GetData(), *dataM = mask.GetData();
|
||||
// for each subpixel...
|
||||
for (UInt i = 0 ; i < size ; ++i) {
|
||||
for (UInt i = 0; i < (size * 3); ++i) {
|
||||
data1[i] = (data1[i] * dataM[i] + data2[i] * (255 - dataM[i])) / 255;
|
||||
}
|
||||
|
||||
if (img1.HasAlpha() && img2.HasAlpha()) {
|
||||
// these have the following structure:
|
||||
// [pixel1alpha, pixel2alpha, pixel3alpha, etc...]
|
||||
Byte *alpha1 = img1.GetAlpha(), *alpha2 = img2.GetAlpha();
|
||||
for (UInt i = 0; i < size; ++i) {
|
||||
// use mask's red channel to blend alpha (all mask channels should be identical since it's grey scale)
|
||||
alpha1[i] = (alpha1[i] * dataM[i * 3] + alpha2[i] * (255 - dataM[i * 3])) / 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Alpha
|
||||
|
||||
Reference in New Issue
Block a user