Beispiel #1
0
        public Image RenderImage(ILUT lut)
        {
            bool render = false;

            if (_bitmap == null)
            {
                System.Drawing.Imaging.PixelFormat format = Components == 4
                                        ? System.Drawing.Imaging.PixelFormat.Format32bppArgb
                                        : System.Drawing.Imaging.PixelFormat.Format32bppRgb;
                _pixels = new PinnedIntArray(ScaledData.Width * ScaledData.Height);
                _bitmap = new Bitmap(ScaledData.Width, ScaledData.Height, ScaledData.Width * 4, format, _pixels.Pointer);
                render  = true;
            }
            if (_applyLut && lut != null && !lut.IsValid)
            {
                lut.Recalculate();
                render = true;
            }
            _bitmap.RotateFlip(RotateFlipType.RotateNoneFlipNone);
            if (render)
            {
                ScaledData.Render((_applyLut ? lut : null), _pixels.Data);
            }
            _bitmap.RotateFlip(GetRotateFlipType());
            return(_bitmap);
        }
Beispiel #2
0
        public BitmapSource RenderImageSource(ILUT lut)
        {
            bool render = false;

            if (_bitmap == null)
            {
                _pixels = new PinnedIntArray(ScaledData.Width * ScaledData.Height);
                _bitmap = new WriteableBitmap(ScaledData.Width, ScaledData.Height);
                render  = true;
            }
            if (_applyLut && lut != null && !lut.IsValid)
            {
                lut.Recalculate();
                render = true;
            }
            if (render)
            {
                ScaledData.Render((_applyLut ? lut : null), _pixels.Data);
            }

            MultiThread.For(0, _pixels.Count, delegate(int i) { _bitmap.Pixels[i] = _pixels.Data[i]; });
            _bitmap.Rotate(_rotation);
            if (_flipX)
            {
                _bitmap.Flip(WriteableBitmapExtensions.FlipMode.Horizontal);
            }
            if (_flipY)
            {
                _bitmap.Flip(WriteableBitmapExtensions.FlipMode.Vertical);
            }

            _bitmap.Invalidate();

            return(_bitmap);
        }
Beispiel #3
0
        public BitmapSource RenderImageSource(ILUT lut)
        {
            bool render = false;

            if (_applyLut && lut != null && !lut.IsValid)
            {
                lut.Recalculate();
                render = true;
            }

            if (_bitmapSource == null || render)
            {
                _pixels = new PinnedIntArray(ScaledData.Width * ScaledData.Height);
                ScaledData.Render((_applyLut ? lut : null), _pixels.Data);
                _bitmapSource = RenderBitmapSource(ScaledData.Width, ScaledData.Height, _pixels.Data);
            }

            if (_rotation != 0 || _flipX || _flipY)
            {
                TransformGroup rotFlipTransform = new TransformGroup();
                rotFlipTransform.Children.Add(new RotateTransform(_rotation));
                rotFlipTransform.Children.Add(new ScaleTransform(_flipX ? -1 : 1, _flipY ? -1 : 1));
                _bitmapSource = new TransformedBitmap(_bitmapSource, rotFlipTransform);
            }

            return(_bitmapSource);
        }
Beispiel #4
0
        public bool RenderImage(ILUT lut, System.IO.MemoryStream ms, out int w, out int h, bool bRotate90 = false)
        {
            if (this._applyLut && lut != null && !lut.IsValid)
            {
                lut.Recalculate();
            }
            IImage image = null;

            try
            {
                image = ImageManager.CreateImage(this.ScaledWidth, this.ScaledHeight);

                var pixels = image.Pixels.Data;
                this.ScaledData.Render(this._applyLut ? lut : null, pixels);

                foreach (var overlay in this._overlays)
                {
                    overlay.Render(pixels, this.ScaledWidth, this.ScaledHeight);
                }
                return(image.Render(this.Components, ms, out w, out h, bRotate90));
            }
            finally
            {
                if (image != null)
                {
                    image.Dispose();
                    image = null;
                }
            }
        }
Beispiel #5
0
        public bool RenderImage(ILUT lut, bool bRotate90, string saveToBmp)
        {
            if (this._applyLut && lut != null && !lut.IsValid)
            {
                lut.Recalculate();
            }
            IImage image = null;

            try
            {
                image = ImageManager.CreateImage(this.ScaledWidth, this.ScaledHeight);

                var pixels = image.Pixels.Data;
                this.ScaledData.Render(this._applyLut ? lut : null, pixels);

                foreach (var overlay in this._overlays)
                {
                    overlay.Render(pixels, this.ScaledWidth, this.ScaledHeight);
                }

                return(image.Render(this.Components, bRotate90, saveToBmp));
            }
            finally
            {
                if (image != null)
                {
                    image.Dispose();
                    image = null;
                }
            }
        }
Beispiel #6
0
        public void Recalculate()
        {
            if (IsValid)
            {
                return;
            }

            _lut.Recalculate();

            for (int i = _minValue; i <= _maxValue; i++)
            {
                _table[i + _offset] = _lut[i];
            }
        }
Beispiel #7
0
        public BitmapSource RenderImageSource(ILUT lut)
        {
            var render = false;

            if (_bitmap == null)
            {
                _pixels = new PinnedIntArray(ScaledData.Width * ScaledData.Height);
                _bitmap = BitmapFactory.New(ScaledData.Width, ScaledData.Height);
                render  = true;
            }

            if (_applyLut && lut != null && !lut.IsValid)
            {
                lut.Recalculate();
                render = true;
            }

            if (render)
            {
                ScaledData.Render((_applyLut ? lut : null), _pixels.Data);

                foreach (var overlay in _overlays)
                {
                    overlay.Render(_pixels.Data, ScaledData.Width, ScaledData.Height);
                }
            }

            using (var context = _bitmap.GetBitmapContext())
            {
                Array.Copy(_pixels.Data, context.Pixels, _pixels.Count);

                _bitmap.Rotate(_rotation);
                if (_flipX)
                {
                    _bitmap.Flip(WriteableBitmapExtensions.FlipMode.Horizontal);
                }
                if (_flipY)
                {
                    _bitmap.Flip(WriteableBitmapExtensions.FlipMode.Vertical);
                }
            }

            return(_bitmap);
        }
Beispiel #8
0
        public BitmapSource RenderImageSource(ILUT lut)
        {
            var render = false;

            if (_bitmap == null)
            {
                _pixels = new PinnedIntArray(ScaledData.Width * ScaledData.Height);
                render  = true;
            }

            if (_applyLut && lut != null && !lut.IsValid)
            {
                lut.Recalculate();
                render = true;
            }

            if (render)
            {
                ScaledData.Render((_applyLut ? lut : null), _pixels.Data);

                foreach (var overlay in _overlays)
                {
                    overlay.Render(_pixels.Data, ScaledData.Width, ScaledData.Height);
                }
            }

            using (
                var context = new CGBitmapContext(_pixels, ScaledWidth, ScaledHeight, 8, 4 * ScaledWidth,
                                                  CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedLast))
            {
                var transform = CGAffineTransform.MakeRotation((float)(_rotation * Math.PI / 180.0));
                transform.Scale(_flipX ? -1.0f : 1.0f, _flipY ? -1.0f : 1.0f);
                transform.Translate(_flipX ? ScaledWidth : 0.0f, _flipY ? ScaledHeight : 0.0f);
                context.ConcatCTM(transform);

                _bitmap = context.ToImage();
            }

            return(_bitmap);
        }
Beispiel #9
0
        public IImage RenderImage(ILUT lut)
        {
            if (this._applyLut && lut != null && !lut.IsValid)
            {
                lut.Recalculate();
            }

            var image = ImageManager.CreateImage(this.ScaledWidth, this.ScaledHeight);

            var pixels = image.Pixels.Data;

            this.ScaledData.Render(this._applyLut ? lut : null, pixels);

            foreach (var overlay in this._overlays)
            {
                overlay.Render(pixels, this.ScaledWidth, this.ScaledHeight);
            }

            image.Render(this.Components, this._flipX, this._flipY, this._rotation);

            return(image);
        }
Beispiel #10
0
        public bool RenderFileImage(ILUT lut, string saveToBmp)
        {
            if (this._applyLut && lut != null && !lut.IsValid)
            {
                lut.Recalculate();
            }
            IFileImage image = null;

            try
            {
                image = FileImageManager.CreateImage(this.ScaledWidth, this.ScaledHeight, saveToBmp);

                var pixels = image.Pixels;
                this.ScaledData.RenderToStream(this._applyLut ? lut : null, pixels);

                foreach (var overlay in this._overlays)
                {
                    //overlay.Render(pixels, this.ScaledWidth, this.ScaledHeight);
                    //overlay未实现RenderToStream,目前测试的dcm均不含overlay
                    throw new NotSupportedException();
                }

                image.Flush();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
                if (image != null)
                {
                    image.Dispose();
                    image = null;
                }
            }
        }
Beispiel #11
0
 public Image RenderImage(ILUT lut)
 {
     bool render = false;
     if (_bitmap == null) {
         PixelFormat format = Components == 4 ? PixelFormat.Format32bppArgb : PixelFormat.Format32bppRgb;
         _pixels = new PinnedIntArray(ScaledData.Width * ScaledData.Height);
         _bitmap = new Bitmap(ScaledData.Width, ScaledData.Height, ScaledData.Width * 4, format, _pixels.Pointer);
         render = true;
     }
     if (_applyLut && lut != null && !lut.IsValid) {
         lut.Recalculate();
         render = true;
     }
     _bitmap.RotateFlip(RotateFlipType.RotateNoneFlipNone);
     if (render) {
         ScaledData.Render((_applyLut ? lut : null), _pixels.Data);
     }
     _bitmap.RotateFlip(GetRotateFlipType());
     return _bitmap;
 }
Beispiel #12
0
        public IImage RenderImage(ILUT lut)
        {
            if (this._applyLut && lut != null && !lut.IsValid)
            {
                lut.Recalculate();
            }

            var image = ImageManager.CreateImage(this.ScaledWidth, this.ScaledHeight);

            var pixels = image.Pixels.Data;
            this.ScaledData.Render(this._applyLut ? lut : null, pixels);

            foreach (var overlay in this._overlays)
            {
                overlay.Render(pixels, this.ScaledWidth, this.ScaledHeight);
            }

            image.Render(this.Components, this._flipX, this._flipY, this._rotation);

            return image;
        }