Skip to content

Commit

Permalink
[ME] Fixing a mistake in the implementation of image blending (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
takahiro0327 authored Jul 10, 2024
1 parent fd11989 commit 771789b
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/MaterialEditor.Core/Core.MaterialEditor.Animation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,16 @@ private static MEAnimationDefine LoadAnimationDefFromApngBytes( int texID, byte[

Color32[] previous = null;

if(fctl.DisposeOp == LibAPNG.DisposeOps.APNGDisposeOpPrevious)
{
previous = new Color32[pixels.Length];
System.Array.Copy(pixels, previous, previous.Length);
}

uint frameWidth = fctl.Width;
uint frameHeight = fctl.Height;
uint offsetX = fctl.XOffset;
uint offsetY = (uint)height - (fctl.YOffset + frameHeight);

if (fctl.DisposeOp == LibAPNG.DisposeOps.APNGDisposeOpPrevious)
{
previous = new Color32[frameWidth * frameHeight];
}

switch (fctl.BlendOp)
{
case LibAPNG.BlendOps.APNGBlendOpSource:
Expand All @@ -312,6 +311,8 @@ private static MEAnimationDefine LoadAnimationDefFromApngBytes( int texID, byte[
{
for (uint x = 0; x < frameWidth; ++x)
{
if (previous != null)
previous[offset] = pixels[(y + offsetY) * width + x + offsetX];
pixels[(y + offsetY) * width + x + offsetX] = addPixels[offset++];
}
}
Expand All @@ -325,6 +326,8 @@ private static MEAnimationDefine LoadAnimationDefFromApngBytes( int texID, byte[
for (uint x = 0; x < frameWidth; ++x)
{
long offset0 = (y + offsetY) * width + x + offsetX;
if(previous != null)
previous[offset] = pixels[offset0];
Color32 p = pixels[offset0];
Color32 q = addPixels[offset++];

Expand Down Expand Up @@ -358,12 +361,27 @@ private static MEAnimationDefine LoadAnimationDefFromApngBytes( int texID, byte[

case LibAPNG.DisposeOps.APNGDisposeOpBackground:
//Clear black
System.Array.Clear(pixels, 0, pixels.Length);
Color32 clear = new Color32(0, 0, 0, 0);
for (uint y = 0; y < frameHeight; ++y)
{
for (uint x = 0; x < frameWidth; ++x)
{
long offset0 = (y + offsetY) * width + x + offsetX;
pixels[offset0] = clear;
}
}
break;

case LibAPNG.DisposeOps.APNGDisposeOpPrevious:
//Prev frame
System.Array.Copy(previous, pixels, previous.Length);
for (uint y = 0, offset = 0; y < frameHeight; ++y)
{
for (uint x = 0; x < frameWidth; ++x)
{
long offset0 = (y + offsetY) * width + x + offsetX;
pixels[offset0] = previous[offset++];
}
}
break;
}
}
Expand Down

0 comments on commit 771789b

Please sign in to comment.