상속: IDisposable
        /// <summary>
        /// Applies the filter to the specified <paramref name="bitmap"/>. This method
        /// first calls <see cref="ImageReplacementFilter.GetDestinationDimensions(FastBitmap, out Int32, out Int32)" />
        /// to calculate the size of the destination image. Then it calls
        /// <see cref="ImageReplacementFilter.ApplyFilter(FastBitmap, DrawingContext, int, int)" /> 
        /// which is where the overridden class implements its filter algorithm.
        /// </summary>
        /// <param name="bitmap">
        /// Image to apply the <see cref="ImageReplacementFilter" /> to.
        /// </param>
        public override sealed void ApplyFilter(FastBitmap bitmap)
        {
            OnBeginApplyFilter(bitmap);

            // get destination dimensions
            int width, height;
            bool shouldContinue = GetDestinationDimensions(bitmap, out width, out height);
            if (!shouldContinue)
                return;

            DrawingVisual dv = new DrawingVisual();
            ConfigureDrawingVisual(bitmap, dv);

            DrawingContext dc = dv.RenderOpen();

            ApplyFilter(bitmap, dc, width, height);
            dc.Close();

            RenderTargetBitmap rtb = RenderTargetBitmapUtility.CreateRenderTargetBitmap(width, height);
            rtb.Render(dv);
            FastBitmap destination = new FastBitmap(rtb);

            // copy metadata
            // TODO
            /*foreach (PropertyItem propertyItem in bitmap.InnerBitmap.PropertyItems)
                destination.InnerBitmap.SetPropertyItem(propertyItem);*/

            // set new image
            bitmap.InnerBitmap = destination.InnerBitmap;

            OnEndApplyFilter();
        }
 protected override Effect GetEffect(FastBitmap source)
 {
     return new ContrastAdjustmentEffect
     {
         Level = (Level + 100) / 40.0
     };
 }
예제 #3
0
        protected override sealed void CreateImage()
        {
            base.CreateImage();

            Rect bounds = new Rect(StrokeWidth / 2, StrokeWidth / 2,
                CalculatedWidth - StrokeWidth,
                CalculatedHeight - StrokeWidth);
            Brush brush = Fill.GetBrush();

            PointCollection points = GetPoints(bounds);
            PathGeometry geometry = CanonicalSplineHelper.CreateSpline(points, Roundness / 100.0, null, true, true, 0.25);

            Pen pen = GetPen();

            DrawingVisual dv = new DrawingVisual();
            DrawingContext dc = dv.RenderOpen();

            // Draw polygon.
            dc.DrawGeometry(brush, pen, geometry);

            dc.Close();

            RenderTargetBitmap rtb = RenderTargetBitmapUtility.CreateRenderTargetBitmap(CalculatedWidth, CalculatedHeight);
            rtb.Render(dv);
            Bitmap = new FastBitmap(rtb);
        }
예제 #4
0
 protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
 {
     Vector offsetSize = GetOffsetSize() + new Vector(Size, Size);
     dc.PushTransform(new TranslateTransform(offsetSize.X, offsetSize.Y));
     base.ApplyFilter(source, dc, width, height);
     dc.Pop();
 }
예제 #5
0
        protected override Effect GetEffect(FastBitmap source)
        {
            // Fill temporary graphics buffer with mask (currently always a rectangle).
            DrawingVisual dv = new DrawingVisual
            {
                Effect = new BlurEffect
                {
                    Radius = Radius,
                    KernelType = KernelType.Gaussian
                }
            };

            DrawingContext dc = dv.RenderOpen();
            dc.DrawImage(source.InnerBitmap, new Rect(0, 0, source.Width, source.Height));
            dc.Close();

            RenderTargetBitmap rtb = RenderTargetBitmapUtility.CreateRenderTargetBitmap(source.Width, source.Height);
            rtb.Render(dv);

            Brush blurredImage = new ImageBrush(rtb);

            return new UnsharpMaskEffect
            {
                BlurMask = blurredImage,
                Amount = Amount / 100.0,
                Threshold = Threshold
            };
        }
예제 #6
0
 /// <summary>
 /// Returns the dimensions of the output image.
 /// </summary>
 /// <param name="source">The source image.</param>
 /// <param name="width">The desired width of the output image.</param>
 /// <param name="height">The desired height of the output image.</param>
 /// <returns><c>true</c> if the destination image should be created; otherwise <c>false</c>.
 /// The <see cref="DropShadowFilter" /> always returns <c>true</c>.</returns>
 protected override bool GetDestinationDimensions(FastBitmap source, out int width, out int height)
 {
     Vector padding = GetPadding();
     width = source.Width + (int) Math.Ceiling(Math.Abs(padding.X));
     height = source.Height + (int) Math.Ceiling(Math.Abs(padding.Y));
     return true;
 }
        public override void ApplyFilter(ImageGenerationContext context, FastBitmap bitmap)
        {
            if (Width == Unit.Empty && Height == Unit.Empty)
                throw new DynamicImageException("At least one of Width or Height must be set.");

            string sourceFileName = Path.GetTempFileName();
            try
            {
                bitmap.Save(sourceFileName);

                string outputFileName = Path.GetTempFileName();

                try
                {
                    int width = (Width == Unit.Empty) ? bitmap.Width : Unit.GetCalculatedValue(Width, bitmap.Width);
                    int height = (Height == Unit.Empty) ? bitmap.Height : Unit.GetCalculatedValue(Height, bitmap.Height);
                    new CairWrapper(context).ProcessImage(sourceFileName, outputFileName, int.MaxValue,
                        width, height, ConvolutionType);
                    FastBitmap output = new FastBitmap(File.ReadAllBytes(outputFileName));
                    if (output.InnerBitmap != null)
                        bitmap.InnerBitmap = output.InnerBitmap;
                }
                finally
                {
                    File.Delete(outputFileName);
                }
            }
            finally
            {
                File.Delete(sourceFileName);
            }
        }
 protected override Effect GetEffect(FastBitmap source)
 {
     return new BrightnessAdjustmentEffect
     {
         Level = this.Level/100.0
     };
 }
예제 #9
0
        protected override Effect GetEffect(FastBitmap source)
        {
            // Get curves either from Curves collection or ACV file.
            CurveCollection curves = GetCurves();

            // Check that there are at least 4 curves.
            if (curves.Count < 4)
                throw new DynamicImageException(
                    "At least 4 curves (corresponding to Composite, Red, Green, Blue) must be specified.");

            // Convert mathematical curve definitions into 4x256 lookup texture (Composite, Red, Green, Blue are the 4 "columns").
            FastBitmap curvesLookup = new FastBitmap(4, 256);
            curvesLookup.Lock();
            for (int x = 0; x < 4; ++x)
            {
                IEnumerable<CurvePoint> points = curves[x].Points.Cast<CurvePoint>();
                float[] xValues = points.Select(p => (float) p.Input).ToArray();
                float[] yValues = points.Select(p => (float) p.Output).ToArray();
                float[] derivatives = CubicSplineUtility.CalculateSpline(xValues, yValues);
                for (int y = 0; y < 256; ++y)
                    curvesLookup[x, y] = Color.FromRgb((byte) CubicSplineUtility.InterpolateSpline(xValues, yValues, derivatives, y), 0, 0);
            }
            curvesLookup.Unlock();

            return new CurvesEffect
            {
                CurvesLookup = new ImageBrush(curvesLookup.InnerBitmap)
            };
        }
예제 #10
0
        /// <summary>
        /// Applies the <see cref="ShinyFloorFilter" /> to the specified <paramref name="source"/>.
        /// </summary>
        /// <param name="source">The source image.</param>
        /// <param name="dc"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
        {
            // First, draw reflected image with an opacity mask.
            int reflectionHeight = (int)(source.Height * (ReflectionPercentage / 100.0f));
            dc.PushTransform(new TransformGroup
            {
                Children = new TransformCollection
                {
                    new ScaleTransform {ScaleY = -1},
                    new TranslateTransform {Y = GetReflectionOffsetY(source) + reflectionHeight}
                }
            });
            dc.PushOpacityMask(new LinearGradientBrush(
                SWMColors.Transparent,
                SWMColor.FromArgb((byte)(255.0f * (ReflectionOpacity / 100.0f)), 0, 0, 0),
                new Point(0, 0),
                new Point(0, 1)));

            dc.DrawImage(new CroppedBitmap(source.InnerBitmap, new Int32Rect(0, source.Height - reflectionHeight, source.Width, reflectionHeight)),
                new Rect(0, 0, source.Width, reflectionHeight));

            dc.Pop();
            dc.Pop();

            // Draw original image.
            dc.DrawImage(source.InnerBitmap, new Rect(0, 0, source.Width, source.Height));
        }
예제 #11
0
        protected override sealed void CreateImage(ImageGenerationContext context)
        {
            base.CreateImage(context);

            Rect bounds = new Rect(StrokeWidth / 2, StrokeWidth / 2,
                CalculatedWidth - StrokeWidth,
                CalculatedHeight - StrokeWidth);
            Brush brush = Fill.GetBrush();

            Pen pen = GetPen();

            DrawingVisual dv = new DrawingVisual();
            DrawingContext dc = dv.RenderOpen();

            if (Roundness == 0)
                dc.DrawRectangle(brush, pen, bounds);
            else
                dc.DrawRoundedRectangle(brush, pen, bounds, Roundness, Roundness);

            dc.Close();

            RenderTargetBitmap rtb = RenderTargetBitmapUtility.CreateRenderTargetBitmap(CalculatedWidth, CalculatedHeight);
            rtb.Render(dv);
            Bitmap = new FastBitmap(rtb);
        }
예제 #12
0
 protected override Effect GetEffect(ImageGenerationContext context, FastBitmap source)
 {
     return new ColorTintEffect
     {
         Amount = Amount/100.0,
         RequiredColor = Color.ToWpfColor()
     };
 }
예제 #13
0
 protected override Effect GetEffect(FastBitmap source)
 {
     return new EmbossEffect
     {
         Amount = Amount,
         Width = Width/(double) source.Width
     };
 }
예제 #14
0
 protected override Effect GetEffect(ImageGenerationContext context, FastBitmap source)
 {
     return new BlurEffect
     {
         KernelType = KernelType.Gaussian,
         Radius = Radius,
         RenderingBias = RenderingBias.Quality
     };
 }
예제 #15
0
 protected override Effect GetEffect(FastBitmap source)
 {
     return new BlurEffect
     {
         KernelType = KernelType.Gaussian,
         Radius = Radius,
         RenderingBias = RenderingBias.Quality
     };
 }
예제 #16
0
        protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
        {
            // Draw border.
            dc.DrawRectangle(Fill.GetBrush(), null, new Rect(0, 0, width, height));

            // Draw image.
            dc.PushTransform(new TranslateTransform(Width, Width));
            dc.DrawImage(source.InnerBitmap, new Rect(0, 0, source.Width, source.Height));
            dc.Pop();
        }
예제 #17
0
 protected override Effect GetEffect(ImageGenerationContext context, FastBitmap source)
 {
     return new DropShadowEffect
     {
         Direction = 0,
         Color = Color.ToWpfColor(),
         BlurRadius = Size,
         ShadowDepth = 0,
         Opacity = Opacity
     };
 }
예제 #18
0
 protected override Effect GetEffect(FastBitmap source)
 {
     return new DropShadowEffect
     {
         Direction = 0,
         Color = Color,
         BlurRadius = Size,
         ShadowDepth = 0,
         Opacity = Opacity
     };
 }
예제 #19
0
        protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
        {
            // Draw image.
            dc.PushTransform(new TranslateTransform(BorderWidth, BorderWidth));
            dc.DrawImage(source.InnerBitmap, new Rect(0, 0, source.Width, source.Height));
            dc.Pop();

            // Draw border.
            dc.DrawRoundedRectangle(null, new Pen(new SolidColorBrush(BorderColor), BorderWidth),
                new Rect(BorderWidth / 2.0, BorderWidth / 2.0, width - BorderWidth, height - BorderWidth),
                Roundness, Roundness);
        }
예제 #20
0
 protected override Effect GetEffect(ImageGenerationContext context, FastBitmap source)
 {
     FastBitmap maskBitmap = MaskImage.GetBitmap(context);
     _maskImageWidth = maskBitmap.Width;
     _maskImageHeight = maskBitmap.Height;
     return new ClippingMaskEffect
     {
         Mask = new ImageBrush(maskBitmap.InnerBitmap),
         InputCoordsOffset = new Vector(MaskPositionX / (double) source.Width, MaskPositionY / (double) source.Height),
         InputCoordsScale = new Vector(_maskImageWidth / (double) source.Width, _maskImageHeight / (double) source.Height)
     };
 }
예제 #21
0
        public void ResizeFilter_UseHeightResizeMode_CalculatedCorrectly()
        {
            FastBitmap bitmap = new FastBitmap("Filters\\Images\\Tulips.png", UriKind.Relative);

            ResizeFilter resizeFilter = new ResizeFilter();
            resizeFilter.Mode = ResizeMode.UseHeight;
            resizeFilter.Height = Unit.Pixel(200);

            resizeFilter.ApplyFilter(bitmap);

            Assert.AreEqual(300, bitmap.Width);
            Assert.AreEqual(200, bitmap.Height);
        }
예제 #22
0
 /// <summary>
 /// Applies the <see cref="RotationFilter" /> to the specified <paramref name="source"/>.
 /// </summary>
 protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
 {
     dc.PushTransform(new TransformGroup
     {
         Children = new TransformCollection
         {
             _rotateTransform,
             new TranslateTransform((width - source.Width) / 2.0, (height - source.Height) / 2.0)
         }
     });
     dc.DrawImage(source.InnerBitmap, new Rect(0, 0, source.Width, source.Height));
     dc.Pop();
 }
예제 #23
0
        public void ResizeFilter_UniformResizeModeWithDominantHeight_CalculatedCorrectly()
        {
            FastBitmap bitmap = new FastBitmap("Filters\\Images\\Tulips.png", UriKind.Relative);

            ResizeFilter resizeFilter = new ResizeFilter();
            resizeFilter.Mode = ResizeMode.Uniform;
            resizeFilter.Width = Unit.Pixel(200);
            resizeFilter.Height = Unit.Pixel(100);

            resizeFilter.ApplyFilter(bitmap);

            Assert.AreEqual(150, bitmap.Width);
            Assert.AreEqual(100, bitmap.Height);
        }
        protected override void CreateImage(ImageGenerationContext context)
        {
            string outputFileName = Path.GetTempFileName();

            try
            {
                if (!new CutyCaptWrapper(context).SaveScreenShot(WebsiteUrl, outputFileName, Timeout, BrowserWidth))
                    return;
                Bitmap = new FastBitmap(File.ReadAllBytes(outputFileName));
            }
            finally
            {
                File.Delete(outputFileName);
            }
        }
예제 #25
0
        protected override void CreateImage(ImageGenerationContext context)
        {
            Bitmap = new FastBitmap(Width, Height);
            Bitmap.Lock();

            for (int y = 0; y < Height; y++)
                for (int x = 0; x < Width; x++)
                {
                    ColorHsv colorHsv = CalculateFractalColor(x, y);
                    var color = (Color) colorHsv;
                    Bitmap[x, y] = color.ToWpfColor();
                }

            Bitmap.Unlock();
        }
예제 #26
0
        protected override void CreateImage()
        {
            Bitmap = new FastBitmap(Width, Height);
            Bitmap.Lock();

            for (int y = 0; y < Height; y++)
                for (int x = 0; x < Width; x++)
                {
                    ColorHsv colourHsv = CalculateFractalColour(x, y);
                    Color colour = (Color) colourHsv;
                    Bitmap[x, y] = colour;
                }

            Bitmap.Unlock();
        }
예제 #27
0
        protected override Effect GetEffect(FastBitmap source)
        {
            FastBitmap transferLookup = new FastBitmap(1, 256);
            transferLookup.Lock();
            for (int y = 0; y < 256; ++y)
            {
                byte colorComponent = (byte) (255 * GetTransferFunctionValue(y / 255.0f));
                transferLookup[0, y] = Color.FromRgb(colorComponent, colorComponent, colorComponent);
            }
            transferLookup.Unlock();

            return new TransferEffect
            {
                TransferLookup = new ImageBrush(transferLookup.InnerBitmap)
            };
        }
        protected override void CreateImage()
        {
            string outputFileName = Path.GetTempFileName();

            try
            {
                string filename = FileSourceHelper.ResolveFileName(SourceFileName, Site, DesignMode);
                GhostscriptSharp.GhostscriptWrapper.GeneratePageThumb(filename, outputFileName, PageNumber, 96, 96);

                Bitmap = new Util.FastBitmap(File.ReadAllBytes(outputFileName));
            }
            finally
            {
                File.Delete(outputFileName);
            }
        }
예제 #29
0
        public static FastBitmap BlendLayers(FastBitmap output, IEnumerable<Layer> layers)
        {
            DrawingVisual dv = new DrawingVisual();
            RenderTargetBitmap rtb = RenderTargetBitmapUtility.CreateRenderTargetBitmap(output.Width, output.Height);

            // Draw background.
            var dc2 = dv.RenderOpen();
            dc2.DrawImage(output.InnerBitmap, new System.Windows.Rect(0, 0, output.Width, output.Height));
            dc2.Close();
            rtb.Render(dv);

            var layersList = layers.ToList();

            // As an optimisation, if BlendMode=Normal for all layers, don't use LayerBlenderEffect.
            // Just draw images directly using DrawImage.
            if (layersList.All(x => x.BlendMode == BlendMode.Normal))
            {
                foreach (var layer in layersList)
                    DrawImage(dv, layer, rtb);
            }
            else
            {
                ImageSource imageSource = output.InnerBitmap;

                foreach (var layer in layersList)
                {
                    using (var effect = new LayerBlenderEffect(layer.BlendMode, output.Width, output.Height)
                    {
                        Background = new ImageBrush(imageSource)
                        {
                            TileMode = TileMode.None,
                            Stretch = Stretch.None,
                            ViewportUnits = BrushMappingMode.RelativeToBoundingBox,
                            Viewport = new System.Windows.Rect(0, 0, 1, 1)
                        }
                    })
                    {
                        dv.Effect = effect;
                        DrawImage(dv, layer, rtb);
                    }

                    imageSource = rtb;
                }
            }

            return new FastBitmap(rtb);
        }
예제 #30
0
        public void ResizeFilterInUseHeightModeCalculatesDimensionsCorrectly()
        {
            // Arrange.
            var bitmap = new FastBitmap(@"Resources\Tulips.png", UriKind.Relative);
            var resizeFilter = new ResizeFilter
            {
                Mode = ResizeMode.UseHeight,
                Height = Unit.Pixel(200)
            };

            // Act.
            resizeFilter.ApplyFilter(bitmap);

            // Assert.
            Assert.AreEqual(300, bitmap.Width);
            Assert.AreEqual(200, bitmap.Height);
        }