Skip to content

Commit

Permalink
Merge pull request #88 from PixiEditor/master
Browse files Browse the repository at this point in the history
Fixed CombineLayers (Export) bug
  • Loading branch information
flabbet committed Oct 26, 2020
2 parents 2d92bce + b31fe20 commit a3f2f41
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 10 additions & 7 deletions PixiEditor/Models/ImageManipulation/BitmapUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ public static WriteableBitmap CombineLayers(Layer[] layers, int width, int heigh
for (int x = 0; x < finalBitmap.Width; x++)
{
Color color = layers[i].GetPixelWithOffset(x, y);
if (i > 0 && color.A < 255)
float layerOpacity = layers[i].Opacity;
if (i > 0 && ((color.A < 255 && color.A > 0) || (layerOpacity < 1f && layerOpacity > 0)))
{
var lastLayerPixel = layers[i - 1].GetPixelWithOffset(x, y);
byte r = (byte)((color.R * color.A / 255) + (lastLayerPixel.R * lastLayerPixel.A * (255 - color.A) / (255 * 255)));
byte g = (byte)((color.G * color.A / 255) + (lastLayerPixel.G * lastLayerPixel.A * (255 - color.A) / (255 * 255)));
byte b = (byte)((color.B * color.A / 255) + (lastLayerPixel.B * lastLayerPixel.A * (255 - color.A) / (255 * 255)));
byte a = (byte)(color.A + (lastLayerPixel.A * (255 - color.A) / 255));
color = Color.FromArgb((byte)(a * layers[i].Opacity), r, g, b);
var lastLayerPixel = finalBitmap.GetPixel(x, y);
byte lastPixelA = (byte)(lastLayerPixel.A * layers[i - 1].Opacity);
byte pixelA = (byte)(color.A * layerOpacity);
byte r = (byte)((color.R * pixelA / 255) + (lastLayerPixel.R * lastPixelA * (255 - pixelA) / (255 * 255)));
byte g = (byte)((color.G * pixelA / 255) + (lastLayerPixel.G * lastPixelA * (255 - pixelA) / (255 * 255)));
byte b = (byte)((color.B * pixelA / 255) + (lastLayerPixel.B * lastPixelA * (255 - pixelA) / (255 * 255)));
byte a = (byte)(pixelA + (lastPixelA * (255 - pixelA) / 255));
color = Color.FromArgb(a, r, g, b);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions PixiEditor/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.3.4")]
[assembly: AssemblyFileVersion("0.1.3.4")]
[assembly: AssemblyVersion("0.1.3.5")]
[assembly: AssemblyFileVersion("0.1.3.5")]

0 comments on commit a3f2f41

Please sign in to comment.