public static Bitmap RenderLayer(ImageGraphic layer, int dstWidth, int dstHeight)
		{
			Bitmap bitmap = new Bitmap(dstWidth, dstHeight);
			Rectangle clientArea = new Rectangle(0, 0, dstWidth, dstHeight);

			BitmapData bitmapData = LockBitmap(bitmap);
			int bytesPerPixel = 4;
			ImageRenderer.Render(layer, bitmapData.Scan0, bitmapData.Width, bytesPerPixel, clientArea);
			bitmap.UnlockBits(bitmapData);
			return bitmap;
		}
Example #2
0
		public static void Render(
			ImageGraphic imageGraphic,
			IntPtr pDstPixelData,
			int dstWidth,
			int dstBytesPerPixel,
			Rectangle clientRectangle)
		{
			if (clientRectangle.Width <= 0 || clientRectangle.Height <= 0)
				return;

			if (imageGraphic.SizeInBytes != imageGraphic.PixelData.Raw.Length)
				throw new InvalidOperationException(String.Format(SR.ExceptionIncorrectPixelDataSize, imageGraphic.SizeInBytes, imageGraphic.PixelData.Raw.Length));

#if DEBUG
			CodeClock clock = new CodeClock();
			clock.Start();
#endif
			RectangleF srcViewableRectangle;
			Rectangle dstViewableRectangle;

			CalculateVisibleRectangles(imageGraphic, clientRectangle, out dstViewableRectangle, out srcViewableRectangle);

		    var grayGraphic = imageGraphic as GrayscaleImageGraphic;
		    ColorImageGraphic colorGraphic;
            if (grayGraphic != null)
			{
				RenderGrayscale(
                    grayGraphic,
					srcViewableRectangle,
					dstViewableRectangle,
					pDstPixelData,
					dstWidth,
					dstBytesPerPixel);
			}
            else if (null != (colorGraphic = imageGraphic as ColorImageGraphic))
			{
				RenderColor(
                    colorGraphic,
					srcViewableRectangle,
					dstViewableRectangle,
					pDstPixelData,
					dstWidth,
					dstBytesPerPixel);
			}
			else
			{
				throw new Exception("Unknown ImageGraphic.");
			}
#if DEBUG
			clock.Stop();
			PerformanceReportBroker.PublishReport("ImageRenderer", "Render", clock.Seconds);
#endif
		}
Example #3
0
		public override bool Start(IMouseInformation mouseInformation)
		{
			if (this.SelectedImageGraphicProvider == null)
				return false;

			_selectedTile = mouseInformation.Tile as Tile;
			_selectedTile.InformationBox = new InformationBox();
			_selectedImageGraphic = this.SelectedImageGraphicProvider.ImageGraphic;
			_selectedImageSop = (this.SelectedPresentationImage as IImageSopProvider).ImageSop;

			Probe(mouseInformation.Location);

			return true;
		}
Example #4
0
 public override IVoiLut CreateVoiLut(ImageGraphic imageGraphic)
 {
     return(_createVoiLutDelegate(imageGraphic));
 }
Example #5
0
 /// <summary>
 /// Creates a Voi LUT suitable for the given <paramref name="imageGraphic"/>.
 /// </summary>
 /// <returns>The VOI LUT as an <see cref="IVoiLut"/>.</returns>
 public abstract IVoiLut CreateVoiLut(ImageGraphic imageGraphic);
			public override IVoiLut CreateVoiLut(ImageGraphic imageGraphic)
			{
				return _createVoiLutDelegate(imageGraphic);
			}
		/// <summary>
		/// Creates a Voi LUT suitable for the given <paramref name="imageGraphic"/>.
		/// </summary>
		/// <returns>The VOI LUT as an <see cref="IVoiLut"/>.</returns>
		public abstract IVoiLut CreateVoiLut(ImageGraphic imageGraphic);
Example #8
0
 private unsafe static void CopyToUnsigned8(ImageGraphic image, itkImageBase itkImage)
 {
     fixed (byte* pSrcByte = image.PixelData.Raw)
     {
         itkImageRegionIterator_IUC2 inputIt = new itkImageRegionIterator_IUC2(itkImage, itkImage.LargestPossibleRegion);
         byte* pSrc = (byte*)pSrcByte;
         int height = image.Rows;
         int width = image.Columns;
         byte pixelValue;
         for (int y = 0; y < height; y++)
         {
             for (int x = 0; x < width; x++)
             {
                 pixelValue = pSrc[0];
                 inputIt.Set(pixelValue);
                 pSrc++;
                 inputIt++;
             }
         }
     }
 }
Example #9
0
		/// <summary>
		/// Draws an <see cref="ImageGraphic"/>.
		/// </summary>
		protected override void DrawImageGraphic(ImageGraphic imageGraphic)
		{
			CodeClock clock = new CodeClock();
			clock.Start();

			const int bytesPerPixel = 4;

			Surface.ImageBuffer.Graphics.Clear(Color.FromArgb(0x0, 0xFF, 0xFF, 0xFF));

			BitmapData bitmapData = Surface.ImageBuffer.Bitmap.LockBits(
				new Rectangle(0, 0, Surface.ImageBuffer.Bitmap.Width, Surface.ImageBuffer.Bitmap.Height),
				ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

			try
			{
				ImageRenderer.Render(imageGraphic, bitmapData.Scan0, bitmapData.Width, bytesPerPixel, Surface.ClientRectangle);
			}
			finally
			{
				Surface.ImageBuffer.Bitmap.UnlockBits(bitmapData);
			}

			Surface.FinalBuffer.RenderImage(Surface.ImageBuffer);

			clock.Stop();
			PerformanceReportBroker.PublishReport("GDIRenderer", "DrawImageGraphic", clock.Seconds);
		}
Example #10
0
		/// <summary>
		/// Cloning constructor.
		/// </summary>
		protected ImageGraphic(ImageGraphic source, ICloningContext context)
		{
			context.CloneFields(source, this);
			SetValidationPolicy();
		}
		private void CreateImageLayer(ImageTypes imageType)
		{
			if (imageType == ImageTypes.Mono16)
				_image = new GrayscaleImageGraphic(_srcHeight, _srcWidth, 16, 16, 15, false, false, 1.9, 3, new byte[2 * _srcWidth * _srcHeight]);
			else if (imageType == ImageTypes.Mono8)
				_image = new GrayscaleImageGraphic(_srcHeight, _srcWidth, 8, 8, 7, false, false, 1.0, 0, new byte[_srcWidth * _srcHeight]);
			if (imageType == ImageTypes.Mono16Signed)
				_image = new GrayscaleImageGraphic(_srcHeight, _srcWidth, 16, 16, 15, true, false, 2.0, -630, new byte[2 * _srcWidth * _srcHeight]);
			else if (imageType == ImageTypes.Mono8Signed)
				_image = new GrayscaleImageGraphic(_srcHeight, _srcWidth, 8, 8, 7, true, false, 0.5, 4, new byte[_srcWidth * _srcHeight]);
			else
				_image = new ColorImageGraphic(_srcHeight, _srcWidth, new byte[4 * _srcWidth * _srcHeight]);

			if (_image is GrayscaleImageGraphic)
			{
				(_image as IColorMapInstaller).InstallColorMap(new GrayscaleColorMap());
			}

			_containerGraphic = new CompositeImageGraphic(_image.Rows, _image.Columns);
			_containerGraphic.Graphics.Add(_image);

			ImageSpatialTransform transform = (ImageSpatialTransform)_containerGraphic.SpatialTransform;
			transform.Initialize();
			transform.ClientRectangle = new Rectangle(0, 0, _dstWidth, _dstHeight);
			transform.ScaleToFit = _scaleToFit;
			transform.Scale = _scale;
			transform.FlipX = _flipHorizontal;
			transform.FlipY = _flipVertical;
			transform.RotationXY = _rotation;
			transform.TranslationX = _translationX;
			transform.TranslationY = _translationY;
		}
Example #12
0
 /// <summary>
 /// Cloning constructor.
 /// </summary>
 protected ImageGraphic(ImageGraphic source, ICloningContext context)
 {
     context.CloneFields(source, this);
     SetValidationPolicy();
 }
Example #13
0
		public override void Cancel()
		{
			if (_selectedTile == null || _selectedImageGraphic == null)
				return;

			_selectedImageGraphic = null;

			_selectedTile.InformationBox.Visible = false;
			_selectedTile.InformationBox = null;
			_selectedTile = null;
		}
Example #14
0
 private unsafe static void CopyFromUnsigned8(ImageGraphic image, itkImageBase itkImage)
 {
     fixed (byte* pDstByte = image.PixelData.Raw)
     {
         itkImageRegionConstIterator_IUC2 itkIt = new itkImageRegionConstIterator_IUC2(itkImage, itkImage.LargestPossibleRegion);
         byte* pDst = (byte*)pDstByte;
         int height = image.Rows;
         int width = image.Columns;
         for (int y = 0; y < height; y++)
         {
             for (int x = 0; x < width; x++)
             {
                 pDst[0] = itkIt.Get().ValueAsUC;
                 pDst++;
                 itkIt++;
             }
         }
     }
 }
Example #15
0
		/// <summary>
		/// Draws an <see cref="ImageGraphic"/>.
		/// </summary>
		protected override void DrawImageGraphic(ImageGraphic imageGraphic)
		{
			CodeClock clock = new CodeClock();
			clock.Start();

			Surface.ImageBuffer.Graphics.Clear(Color.FromArgb(0x0, 0xFF, 0xFF, 0xFF));

			DrawImageGraphic(Surface.ImageBuffer, imageGraphic);

			Surface.FinalBuffer.RenderImage(Surface.ImageBuffer);

			clock.Stop();
			PerformanceReportBroker.PublishReport("GDIRenderer", "DrawImageGraphic", clock.Seconds);
		}
Example #16
0
		/// <summary>
		/// Draws an image graphic to the specified destination buffer.
		/// </summary>
		/// <param name="buffer">The destination buffer.</param>
		/// <param name="imageGraphic">The image graphic to be drawn.</param>
		public static void DrawImageGraphic(BitmapBuffer buffer, ImageGraphic imageGraphic)
		{
			const int bytesPerPixel = 4;

			var bounds = ((IGdiBuffer) buffer).Bounds;
			var bitmapData = buffer.Bitmap.LockBits(bounds, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
			try
			{
				ImageRenderer.Render(imageGraphic, bitmapData.Scan0, bitmapData.Width, bytesPerPixel, bounds);
			}
			finally
			{
				buffer.Bitmap.UnlockBits(bitmapData);
			}
		}
Example #17
0
		private static bool IsRotated(ImageGraphic imageGraphic)
		{
			float m12 = imageGraphic.SpatialTransform.CumulativeTransform.Elements[2];
			return !FloatComparer.AreEqual(m12, 0.0f, 0.001f);
		}
Example #18
0
		/// <summary>
		/// Draws an <see cref="ImageGraphic"/>.  Must be overridden and implemented.
		/// </summary>
		protected abstract void DrawImageGraphic(ImageGraphic imageGraphic);
Example #19
0
		//internal for unit testing only.
		internal static void CalculateVisibleRectangles(
			ImageGraphic imageGraphic,
			Rectangle clientRectangle,
			out Rectangle dstVisibleRectangle,
			out RectangleF srcVisibleRectangle)
		{
			Rectangle srcRectangle = new Rectangle(0, 0, imageGraphic.Columns, imageGraphic.Rows);
			RectangleF dstRectangle = imageGraphic.SpatialTransform.ConvertToDestination(srcRectangle);

			// Find the intersection between the drawable client rectangle and
			// the transformed destination rectangle
			dstRectangle = RectangleUtilities.RoundInflate(dstRectangle);
			dstRectangle = RectangleUtilities.Intersect(clientRectangle, dstRectangle);

			if (dstRectangle.IsEmpty)
			{
				dstVisibleRectangle = Rectangle.Empty;
				srcVisibleRectangle = RectangleF.Empty;
				return;
			}

			// Figure out what portion of the image is visible in source coordinates
			srcVisibleRectangle = imageGraphic.SpatialTransform.ConvertToSource(dstRectangle);
			//dstRectangle is already rounded, this is just a conversion to Rectangle.
			dstVisibleRectangle = Rectangle.Round(dstRectangle);
		}