using Age.Engine.Model; using Xunit; public class SoftwareAffineRasterizerTests { [Theory] [InlineData(-1, 2, false)] [InlineData(4, -1, false)] [InlineData(1, 1, true)] public void BlitRgba_IntegerTranslationFastPath_MatchesGeneralAffine(int tx, int ty, bool multiplyTint) { byte[] src = new byte[5 * 4 * 4]; for (int i = 0; i < src.Length; i += 4) { src[i] = (byte)(20 + i % 211); src[i + 1] = (byte)(70 + i % 173); src[i + 2] = (byte)(130 + i % 107); src[i + 3] = (byte)(40 + i % 216); } byte[] expected = new byte[6 * 5 * 4]; for (int i = 0; i < expected.Length; i++) expected[i] = (byte)(i * 17 + 3); byte[] actual = (byte[])expected.Clone(); var translation = new Affine2D(1, 0, 0, 1, tx, ty); ReferenceBlit(expected, 6, 5, src, 5, 1, 1, 3, 2, translation, 0x4080c0, 0.35f, 0.6f, multiplyTint); SoftwareAffineRasterizer.BlitRgba(actual, 6, 5, src, 5, 4, 1, 1, 3, 2, translation, 0x4080c0, 0.35f, 0.6f, multiplyTint); Assert.Equal(expected, actual); } [Theory] [InlineData(-2, 1)] [InlineData(4, -1)] [InlineData(1, 2)] public void FillRgba_IntegerTranslationFastPath_MatchesGeneralAffine(int tx, int ty) { byte[] expected = new byte[6 * 5 * 4]; for (int i = 0; i < expected.Length; i++) expected[i] = (byte)(i * 11 + 5); byte[] actual = (byte[])expected.Clone(); var translation = new Affine2D(1, 0, 0, 1, tx, ty); ReferenceFill(expected, 6, 5, 4, 3, translation, 0x9a4f21, 0.42f); SoftwareAffineRasterizer.FillRgba(actual, 6, 5, 4, 3, translation, 0x9a4f21, 0.42f); Assert.Equal(expected, actual); } [Fact] public void BlitRgba_RotatesTwoPixelsClockwiseWithNearestSampling() { byte[] src = { 255,0,0,255, 0,255,0,255 }; byte[] dst = new byte[4*4*4]; var world = Transform2DMath.Build( new TransformState(1,1,1,0,0,0,1,1,0, 0,0,1,90)); SoftwareAffineRasterizer.BlitRgba(dst,4,4,src,2,1,0,0,2,1, world.FromLocalOrigin(1,1),0xffffff,0,1); Assert.Equal(new byte[] {255,0,0,255}, dst[16..20]); Assert.Equal(new byte[] {0,255,0,255}, dst[32..36]); } [Fact] public void FillRgba_UsesAffineShapeRatherThanBoundingBox() { byte[] dst = new byte[5*5*4]; var m = new Affine2D(1,0.5,-0.5,1,2,1); SoftwareAffineRasterizer.FillRgba(dst,5,5,2,2,m,0xff0000,1); int colored = 0; for(int i=3;i