public Statistics Diff(TestPresentationImage other) { if (other == null) { throw new ArgumentNullException(); } List <int> diffs = new List <int>(); using (Bitmap thatBitmap = other.DrawToBitmap(_width, _height)) { using (Bitmap thisBitmap = this.DrawToBitmap(_width, _height)) { for (int x = 0; x < _width; x++) { for (int y = 0; y < _height; y++) { Color thatColor = thatBitmap.GetPixel(x, y); Color thisColor = thisBitmap.GetPixel(x, y); diffs.Add(Math.Abs(thatColor.R - thisColor.R)); diffs.Add(Math.Abs(thatColor.G - thisColor.G)); diffs.Add(Math.Abs(thatColor.B - thisColor.B)); diffs.Add(Math.Abs(thatColor.A - thisColor.A)); } } } } return(new Statistics(diffs)); }
public void TestImageRoundtripSpatialTransform() { TestPresentationState ps = new TestPresentationState(); foreach (string file in Directory.GetFiles(Directory.GetCurrentDirectory(), "*.test.bmp")) { File.Delete(file); } for (int rotation = 0; rotation < 360; rotation += 90) { for (int flipX = 0; flipX < 2; flipX++) { for (int flipY = 0; flipY < 2; flipY++) { Trace.WriteLine(string.Format("Testing Roundtrip IMG->IOD->IMG with params Rot={0}, fX={1}, fY={2}", rotation, flipX, flipY)); TestPresentationImage original = new TestPresentationImage(); original.SpatialTransform.FlipX = (flipX % 2 == 1); original.SpatialTransform.FlipY = (flipY % 2 == 1); original.SpatialTransform.RotationXY = rotation; original.SaveBitmap(string.Format("{0:d2}-{1}-{2}-original.test.bmp", rotation / 10, flipX, flipY)); TestPresentationImage actual = ps.DeserializeSpatialTransform(ps.SerializeSpatialTransform(original)); actual.SaveBitmap(string.Format("{0:d2}-{1}-{2}-actual.test.bmp", rotation / 10, flipX, flipY)); Statistics stats = original.Diff(actual); Trace.WriteLine(string.Format("DIFF STATS {0}", stats)); Assert.IsTrue(stats.IsEqualTo(0, 5), string.Format("Roundtrip IMG->IOD->IMG FAILED: Rot={0}, fX={1}, fY={2}", rotation, flipX, flipY)); actual.Dispose(); original.Dispose(); } } } }
public void TestIodRoundtripSpatialTransform() { TestPresentationState ps = new TestPresentationState(); for (int rotation = 0; rotation < 360; rotation += 90) { for (int flipH = 0; flipH < 2; flipH++) { Trace.WriteLine(string.Format("Testing Roundtrip IOD->IMG->IOD with params Rot={0}, fH={1}", rotation, flipH)); SpatialTransformModuleIod original = new SpatialTransformModuleIod(); original.ImageHorizontalFlip = (flipH == 1) ? ImageHorizontalFlip.Y : ImageHorizontalFlip.N; original.ImageRotation = rotation; TestPresentationImage image = ps.DeserializeSpatialTransform(original); using (image) { SpatialTransformModuleIod actual = ps.SerializeSpatialTransform(image); Assert.AreEqual(original.ImageHorizontalFlip, actual.ImageHorizontalFlip, string.Format("Roundtrip IOD->IMG->IOD FAILED: Rot={0}, fH={1}", rotation, flipH)); Assert.AreEqual(original.ImageRotation, actual.ImageRotation, string.Format("Roundtrip IOD->IMG->IOD FAILED: Rot={0}, fH={1}", rotation, flipH)); } } } }