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 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 TestBasicGrayscaleImage16()
		{
			const int rows = 8;
			const int cols = 8;

			var pixelData = new byte[rows*cols*2];
			using (var imageGraphic = new GrayscaleImageGraphic(rows, cols, 16, 16, 15, false, false, 1, 0, () => pixelData))
			using (var presentationImage = new TestPresentationImage(imageGraphic))
			{
				presentationImage.DrawToBitmap(100, 100);
			}
		}
示例#4
0
        public void TestBasicGrayscaleImage16()
        {
            const int rows = 8;
            const int cols = 8;

            var pixelData = new byte[rows * cols * 2];

            using (var imageGraphic = new GrayscaleImageGraphic(rows, cols, 16, 16, 15, false, false, 1, 0, () => pixelData))
                using (var presentationImage = new TestPresentationImage(imageGraphic))
                {
                    presentationImage.DrawToBitmap(100, 100);
                }
        }
示例#5
0
        public void TestBasicColorImage()
        {
            const int rows = 8;
            const int cols = 8;

            var pixelData = new byte[rows * cols * 4];

            using (var imageGraphic = new ColorImageGraphic(rows, cols, () => pixelData))
                using (var presentationImage = new TestPresentationImage(imageGraphic))
                {
                    presentationImage.DrawToBitmap(100, 100);
                }
        }
示例#6
0
        public void TestInvalidPixelDataGrayscaleImage16()
        {
            const int rows = 8;
            const int cols = 8;

            try
            {
                var badPixelData = new byte[rows * cols * 2 - 10];
                using (var imageGraphic = new GrayscaleImageGraphic(rows, cols, 16, 16, 15, false, false, 1, 0, () => badPixelData))
                    using (var presentationImage = new TestPresentationImage(imageGraphic))
                    {
                        presentationImage.DrawToBitmap(100, 100);
                    }
                Assert.Fail("Expected RenderingException was not thrown");
            }
            catch (RenderingException ex)
            {
                Trace.WriteLine(string.Format("Rendering exception thrown: {0}", ex.UserMessage));
            }
        }
		public void TestInvalidPixelDataGrayscaleImage8()
		{
			const int rows = 8;
			const int cols = 8;

			try
			{
				var badPixelData = new byte[rows*cols - 10];
				using (var imageGraphic = new GrayscaleImageGraphic(rows, cols, 8, 8, 7, false, false, 1, 0, () => badPixelData))
				using (var presentationImage = new TestPresentationImage(imageGraphic))
				{
					presentationImage.DrawToBitmap(100, 100);
				}
				Assert.Fail("Expected RenderingException was not thrown");
			}
			catch (RenderingException ex)
			{
				Trace.WriteLine(string.Format("Rendering exception thrown: {0}", ex.UserMessage));
			}
		}
示例#8
0
        public void TestMaximumPracticalColorImage()
        {
            if (Assert64Bit())
            {
                return;
            }

            // due to the 2GB limit for a single buffer and the current ImageViewer rendering infrastructure,
            // it is not possible to render the largest possible valid-DICOM color image.
            // these values test the maximum renderable image under the current infrastructure assuming a 64-bit machine
            const int rows = (1 << 15) - 1;
            const int cols = (1 << 14);

            var pixelData = new byte[rows * cols * 4];

            using (var imageGraphic = new ColorImageGraphic(rows, cols, () => pixelData))
                using (var presentationImage = new TestPresentationImage(imageGraphic))
                {
                    presentationImage.DrawToBitmap(100, 100);
                }
        }
		public void TestMaximumPracticalColorImage()
		{
			if (Assert64Bit()) return;

			// due to the 2GB limit for a single buffer and the current ImageViewer rendering infrastructure,
			// it is not possible to render the largest possible valid-DICOM color image.
			// these values test the maximum renderable image under the current infrastructure assuming a 64-bit machine
			const int rows = (1 << 15) - 1;
			const int cols = (1 << 14);

			var pixelData = new byte[rows*cols*4];
			using (var imageGraphic = new ColorImageGraphic(rows, cols, () => pixelData))
			using (var presentationImage = new TestPresentationImage(imageGraphic))
			{
				presentationImage.DrawToBitmap(100, 100);
			}
		}
示例#10
0
		public void TestBasicColorImage()
		{
			const int rows = 8;
			const int cols = 8;

			var pixelData = new byte[rows*cols*4];
			using (var imageGraphic = new ColorImageGraphic(rows, cols, () => pixelData))
			using (var presentationImage = new TestPresentationImage(imageGraphic))
			{
				presentationImage.DrawToBitmap(100, 100);
			}
		}