Files
LlamaCasty/ytLive.Tests/ZoomFrameBuilderTests.cs
T
gramps 4b3d82ff0f Zoom: compose the box as a real 2x layer above the background (Unit: zoom layer + magnification proof)
Right-click now creates a transient ZoomSceneElement at z-index 1 whose pixels are a
genuine 2x magnified sample of the backdrop (live capture under art), composited into
stream/recording like any layer while the output crop stays the tier. All shapes are
centered on the click and clamped to frame; healed on load/scene-create, never persisted,
hidden from the layers list + element template (IsZoomLayer). BuildCompositorOptions is
now internal = always tier crop (test seam). ZoomFrameBuilder is a pure static sampler
(box/2 window centered on the box center, single-slot cache) proven by a banded-backdrop
test; LayerReorderPersistenceTests drag resolves rows by item since the collapsed zoom
row shifts container indices. Also books TASK 51 (webcam background Remove + Blur) and
syncs memory docs (HANDOFF, MyMistakes, indexes). Full suite: 405 passed, 0 warnings.
2026-10-07 23:39:54 -07:00

83 lines
2.9 KiB
C#

using System;
using Xunit;
using ytLive.Services;
using ytLive.ViewModels;
namespace ytLive.Tests;
/// <summary>
/// Proves the zoom layer's pixels are the GENUINE 2x magnification of the
/// backdrop: the source window is the box/2 interior centred on the box centre
/// (the same region as the preview's VisualBrush), with the static art composited
/// over the live capture exactly as the SceneCompositor draws the backdrop. This
/// is the "don't ship a magnifier you only think exists" proof — a 1x box, a
/// mis-positioned window, or a wrong backdrop layer all fail hard below.
/// </summary>
public sealed class ZoomFrameBuilderTests
{
private static VideoFrame BandedBackdrop(int bandW, int bandCount)
{
var w = bandW * bandCount;
const int h = 1080;
var buf = new byte[w * h * 4];
var bandColors = new (byte B, byte G, byte R)[]
{
(10, 20, 30), // band 0
(0, 0, 255), // band 1 red
(0, 255, 0), // band 2 green — the box window lands here
(255, 0, 0), // band 3 blue
};
for (var y = 0; y < h; y++)
{
for (var x = 0; x < w; x++)
{
var (b, g, r) = bandColors[Math.Min(bandCount - 1, x / bandW)];
var i = (y * w + x) * 4;
buf[i] = b;
buf[i + 1] = g;
buf[i + 2] = r;
buf[i + 3] = 255;
}
}
return new VideoFrame(w, h, buf);
}
private static VideoFrame SolidFrame(int w, int h, byte b, byte g, byte r)
{
var buf = new byte[w * h * 4];
for (var i = 0; i < w * h; i++)
{
buf[i * 4] = b;
buf[i * 4 + 1] = g;
buf[i * 4 + 2] = r;
buf[i * 4 + 3] = 255;
}
return new VideoFrame(w, h, buf);
}
[Fact]
public void Build_Produces_2x_Centered_ArtOverLive_Magnification()
{
var art = BandedBackdrop(480, 4); // [0,480) 1/4 dim, [480,960) red, [960,1440) green, [1440,1920) blue
var live = SolidFrame(1920, 1080, 200, 60, 60); // magenta-ish — must never show through
// Box [840,1320)x[100,580). 2x window = [960,1200)x[160,520) = band 2, all green.
// A 1x (broken) magnifier samples [840,1320) → red+green+blue mixed.
var zoom = ZoomFrameBuilder.Build(live, art, 840, 100, 480, 480, 1920, 1080);
Assert.NotNull(zoom);
Assert.Equal(480, zoom.Width);
Assert.Equal(480, zoom.Height);
for (var y = 0; y < zoom.Height; y++)
{
for (var x = 0; x < zoom.Width; x++)
{
var i = (y * zoom.Width + x) * 4;
Assert.Equal(0, zoom.BgraPixels[i]); // B
Assert.Equal(255, zoom.BgraPixels[i + 1]); // G
Assert.Equal(0, zoom.BgraPixels[i + 2]); // R
Assert.Equal(255, zoom.BgraPixels[i + 3]); // A
}
}
}
}