From 8517bf5f50b884bb957757e1beaddc95667c0625 Mon Sep 17 00:00:00 2001 From: routersys Date: Sat, 4 Jul 2026 11:40:40 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=8F=E3=83=BC=E3=83=89=E3=82=A6=E3=82=A7?= =?UTF-8?q?=E3=82=A2=E5=90=88=E6=88=90=E3=81=B8=E5=90=88=E6=88=90=E3=83=A2?= =?UTF-8?q?=E3=83=BC=E3=83=89=E9=81=A9=E7=94=A8=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaScript/Drawing/HardwareCompositor.cs | 39 ++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/LuaScript/Drawing/HardwareCompositor.cs b/LuaScript/Drawing/HardwareCompositor.cs index da6f65d..170d9a2 100644 --- a/LuaScript/Drawing/HardwareCompositor.cs +++ b/LuaScript/Drawing/HardwareCompositor.cs @@ -1,11 +1,15 @@ using System; using System.Numerics; using System.Runtime.InteropServices; +using LuaScript.Compat; using Vortice.DCommon; using Vortice.Direct2D1; +using Vortice.Direct2D1.Effects; using Vortice.DXGI; using Vortice.Mathematics; using YukkuriMovieMaker.Commons; +using YukkuriMovieMaker.Player; +using Blend = YukkuriMovieMaker.Project.Blend; namespace LuaScript { @@ -17,6 +21,8 @@ namespace LuaScript private ID2D1Bitmap1? _source; private ID2D1Bitmap1? _target; private ID2D1Bitmap1? _staging; + private Opacity? _opacityEffect; + private ID2D1Image? _opacityOutput; private int _sourceWidth; private int _sourceHeight; private int _targetWidth; @@ -53,6 +59,7 @@ namespace LuaScript var interpolation = command.Antialias != 0d ? BitmapInterpolationMode.Linear : BitmapInterpolationMode.NearestNeighbor; + var blend = BlendModeMap.Resolve(command.Blend); var dc = _ctx.DeviceContext; var rt = (ID2D1RenderTarget)dc; @@ -62,7 +69,7 @@ namespace LuaScript { dc.BeginDraw(); rt.Transform = transform; - rt.DrawBitmap(_source!, opacity, interpolation); + DrawSource(rt, opacity, interpolation, blend); rt.Transform = Matrix3x2.Identity; dc.EndDraw(); } @@ -92,6 +99,25 @@ namespace LuaScript return true; } + private void DrawSource(ID2D1RenderTarget rt, float opacity, BitmapInterpolationMode interpolation, Blend blend) + { + if (blend == Blend.Normal) + { + rt.DrawBitmap(_source!, opacity, interpolation); + return; + } + + var interp = ToImageInterpolation(interpolation); + _opacityEffect!.Value = opacity; + if (blend.IsCompositionEffect()) + _ctx.DeviceContext.DrawImage(_opacityOutput!, interpolationMode: interp, compositeMode: blend.ToD2DCompositionMode()); + else + _ctx.DeviceContext.BlendImage(_opacityOutput!, blend.ToD2DBlendMode(), null, null, interp); + } + + private static InterpolationMode ToImageInterpolation(BitmapInterpolationMode mode) => + mode == BitmapInterpolationMode.Linear ? InterpolationMode.Linear : InterpolationMode.NearestNeighbor; + private void EnsureSource(int width, int height) { if (_source is not null && _sourceWidth == width && _sourceHeight == height) @@ -101,6 +127,13 @@ namespace LuaScript _source = _ctx.DeviceContext.CreateEmptyBitmap(width, height, BitmapOptions.Target); _sourceWidth = width; _sourceHeight = height; + + if (_opacityEffect is null) + { + _opacityEffect = new Opacity(_ctx.DeviceContext); + _opacityOutput = _opacityEffect.Output; + } + _opacityEffect.SetInput(0, _source, true); } private void EnsureTarget(int width, int height) @@ -128,9 +161,13 @@ namespace LuaScript public void Dispose() { + _opacityOutput?.Dispose(); + _opacityEffect?.Dispose(); _source?.Dispose(); _target?.Dispose(); _staging?.Dispose(); + _opacityOutput = null; + _opacityEffect = null; _source = null; _target = null; _staging = null;