Skip to content

Commit

Permalink
MonsterCard: fix additive-blend bug, fix gif save
Browse files Browse the repository at this point in the history
  • Loading branch information
Kagamia committed Feb 20, 2016
1 parent d9e4463 commit 0ee3717
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
Binary file modified References/spine-xna.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions WzComparerR2.MonsterCard/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.5.0")]
[assembly: AssemblyFileVersion("1.1.5.60102")]
[assembly: AssemblyVersion("1.1.6.0")]
[assembly: AssemblyFileVersion("1.1.6.60220")]
41 changes: 26 additions & 15 deletions WzComparerR2.MonsterCard/UI/SpineControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ public System.Drawing.Bitmap SaveAsGif(int frameDelay)

int length = (int)Math.Round(ani.Duration * 1000);
int time = 0;

var gifBgColor = Setting.GifBackGroundColor;
var clearColor = gifBgColor.A == 255 ? new Color(gifBgColor.R, gifBgColor.G, gifBgColor.B, 255) :
Color.TransparentBlack;
bool isTransparent = gifBgColor.A < 255;

do
{
aniItem.aniState.Apply(aniItem.skeleton);
Expand All @@ -315,7 +321,7 @@ public System.Drawing.Bitmap SaveAsGif(int frameDelay)
//渲染
GraphicsDevice.SetRenderTarget(0, rt);
GraphicsDevice.DepthStencilBuffer = stencil;
GraphicsDevice.Clear(Color.TransparentBlack);
GraphicsDevice.Clear(clearColor);
renderer.Effect.World = Matrix.CreateTranslation(-rect.Left, -rect.Top, 0);
renderer.PremultipliedAlpha = aniItem.dataEx.preMultiAlpha;
renderer.Begin();
Expand All @@ -327,25 +333,31 @@ public System.Drawing.Bitmap SaveAsGif(int frameDelay)
renderer.End();

//处理透明度
RenderTarget2D rt2 = new RenderTarget2D(this.GraphicsDevice, rect.Width, rect.Height, 1, SurfaceFormat.Color, RenderTargetUsage.PreserveContents);
GraphicsDevice.SetRenderTarget(0, rt2);
GraphicsDevice.Clear(Color.TransparentBlack);

shader.Begin(SaveStateMode.None);
shader.Techniques[0].Passes[0].Begin();
sb.Begin(SpriteBlendMode.None);
sb.Draw(rt.GetTexture(), new Rectangle(0, 0, rect.Width, rect.Height), Color.White);
sb.End();
shader.Techniques[0].Passes[0].End();
shader.End();
if (isTransparent)
{
RenderTarget2D rt2 = new RenderTarget2D(this.GraphicsDevice, rect.Width, rect.Height, 1, SurfaceFormat.Color, RenderTargetUsage.PreserveContents);
GraphicsDevice.SetRenderTarget(0, rt2);
GraphicsDevice.Clear(Color.TransparentBlack);

shader.Begin(SaveStateMode.None);
shader.Techniques[0].Passes[0].Begin();
sb.Begin(SpriteBlendMode.None);
sb.Draw(rt.GetTexture(), new Rectangle(0, 0, rect.Width, rect.Height), Color.White);
sb.End();
shader.Techniques[0].Passes[0].End();
shader.End();

rt.Dispose();
rt = rt2;
}

//结束
GraphicsDevice.SetRenderTarget(0, null);
GraphicsDevice.DepthStencilBuffer = null;

//保存
byte[] bmpData = new byte[rt.Width * rt.Height * 4];
rt2.GetTexture().GetData(bmpData);
rt.GetTexture().GetData(bmpData);
bmpCache.Add(bmpData);
unsafe
{
Expand All @@ -362,7 +374,6 @@ public System.Drawing.Bitmap SaveAsGif(int frameDelay)
//清理
stencil.Dispose();
rt.Dispose();
rt2.Dispose();
}

//更新时间轴
Expand All @@ -377,7 +388,7 @@ public System.Drawing.Bitmap SaveAsGif(int frameDelay)

shader.Dispose();

var gifBmp = gif.EncodeGif2(Setting.GifBackGroundColor, Setting.GifMinAlphaMixed);
var gifBmp = gif.EncodeGif2(gifBgColor, Setting.GifMinAlphaMixed);
bmpCache = null;
return gifBmp;
//this.effItems.Clear();
Expand Down

0 comments on commit 0ee3717

Please sign in to comment.