using System; using Xunit; using ytLive.Services; using ytLive.ViewModels; namespace ytLive.Tests; /// /// 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. /// 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 } } } }