feat(text): composite shared text rasters in output
Raster static text on UI-thread changes and reuse the same transparent BGRA frame in preview and all compositor paths. Cache text frame identity in the frame-pump signature and invalidate static bakes on edits. Follow OBS text-source conventions: https://obsproject.com/kb/text-sources
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Xunit;
|
||||
using ytLive.Models;
|
||||
using ytLive.Services;
|
||||
|
||||
namespace ytLive.Tests;
|
||||
|
||||
[Collection("RealApp")]
|
||||
public sealed class TextOverlayRendererTests
|
||||
{
|
||||
private readonly RealAppHost _app;
|
||||
|
||||
public TextOverlayRendererTests(RealAppHost app) => _app = app;
|
||||
|
||||
[Fact]
|
||||
public void Raster_IsCached_And_PreviewBitmap_Uses_The_Same_Transparent_Pixels()
|
||||
{
|
||||
_app.Run(() =>
|
||||
{
|
||||
var source = new Source
|
||||
{
|
||||
Type = SourceType.TextOverlay,
|
||||
TextContent = "Cached text",
|
||||
Width = 220,
|
||||
Height = 70,
|
||||
TextFontSize = 36,
|
||||
TextColor = "#80FFFFFF",
|
||||
TextBold = true,
|
||||
TextUnderline = true,
|
||||
};
|
||||
var renderer = new TextOverlayRenderer();
|
||||
renderer.UpdatePreview(source);
|
||||
|
||||
var first = Assert.IsType<VideoFrame>(renderer.RenderFrame(source));
|
||||
var preview = Assert.IsType<WriteableBitmap>(source.VideoImageSource);
|
||||
var pixels = new byte[first.BgraPixels.Length];
|
||||
preview.CopyPixels(pixels, first.Stride, 0);
|
||||
Assert.Equal(first.BgraPixels, pixels);
|
||||
Assert.Contains(first.BgraPixels.Where((_, index) => index % 4 == 3), alpha => alpha > 0);
|
||||
Assert.Contains(first.BgraPixels.Where((_, index) => index % 4 == 3), alpha => alpha == 0);
|
||||
|
||||
renderer.UpdatePreview(source);
|
||||
Assert.Same(first, renderer.RenderFrame(source));
|
||||
Assert.Same(preview, source.VideoImageSource);
|
||||
|
||||
source.TextContent = "Changed";
|
||||
renderer.UpdatePreview(source);
|
||||
Assert.NotSame(first, renderer.RenderFrame(source));
|
||||
Assert.NotSame(preview, source.VideoImageSource);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user