Exemplo n.º 1
0
 /// <summary>
 /// Creates and initializes a new lens tilt depth-of-field effect.
 /// </summary>
 /// <param name="source">The source image to be blurred.</param>
 /// <param name="focusBand">The band that represents the focus area in the image. Pixels within this band won't be blurred.
 /// Areas outside of the area will be progressively more blurred as the distance from the focus band increases..</param>
 /// <param name="blurStrengthAtEdge1">Strength of the blur on the Edge1 side of the focus band.</param>
 /// <param name="blurStrengthAtEdge2">Strength of the blur on the Edge2 side of the focus band.</param>
 public LensTiltDepthOfFieldEffect(IImageProvider source, FocusBand focusBand, double strengthAtEdge1, double strengthAtEdge2, DepthOfFieldQuality quality)
     : base(source, quality)
 {
     FocusBand       = focusBand;
     StrengthAtEdge1 = strengthAtEdge1;
     StrengthAtEdge2 = strengthAtEdge2;
 }
		/// <summary>
		/// Creates and initializes a new lens tilt depth-of-field effect.
		/// </summary>
		/// <param name="source">The source image to be blurred.</param>
		/// <param name="focusBand">The band that represents the focus area in the image. Pixels within this band won't be blurred. 
		/// Areas outside of the area will be progressively more blurred as the distance from the focus band increases..</param>
		/// <param name="blurStrengthAtEdge1">Strength of the blur on the Edge1 side of the focus band.</param>
		/// <param name="blurStrengthAtEdge2">Strength of the blur on the Edge2 side of the focus band.</param>
		public LensTiltDepthOfFieldEffect(IImageProvider source, FocusBand focusBand, double strengthAtEdge1, double strengthAtEdge2, DepthOfFieldQuality quality)
			: base(source, quality)
		{
			FocusBand = focusBand;
			StrengthAtEdge1 = strengthAtEdge1;
			StrengthAtEdge2 = strengthAtEdge2;
		}
        private FocusBand GetBandFromHorizonLine(Point p1, Point p2)
        {
            double xDiff = p1.X - p2.X;
            double yDiff = p1.Y - p2.Y;

            Point midpoint = new Point((p2.X + p1.X) / 2, (p2.Y + p1.Y) / 2);

            Func <double, Point> lineNormalFunction;

            if (Math.Abs(xDiff) < 1e-3)
            {
                //special case to avoid divide by zero
                lineNormalFunction = (x) => new Point(midpoint.X + x, midpoint.Y);
            }
            else if (Math.Abs(yDiff) < 1e-3)
            {
                //special case to avoid divide by zero
                lineNormalFunction = (y) => new Point(midpoint.X, midpoint.Y + y);
            }
            else
            {
                double slope     = (p2.Y - p1.Y) / (p2.X - p1.X);
                double perpSlope = -1 / slope;

                double intercept = midpoint.Y - (perpSlope * midpoint.X);

                lineNormalFunction = (x) => new Point(midpoint.X + x, (perpSlope * (midpoint.X + x)) + intercept);
            }

            FocusBand band = new FocusBand(lineNormalFunction(0), lineNormalFunction(1e-5));

            return(band);
        }
Exemplo n.º 4
0
        protected override MaybeTask<IImageProvider> GetEffectInternalAsync(IImageProvider source, Windows.Foundation.Size sourceSize, Windows.Foundation.Size renderSize)
        {
            if (m_effectEffect == null)
            {
                m_focus = new FocusBand(new Point(0.5, 0.3), new Point(0.5, 0.4));

                m_effectEffect = new LensTiltDepthOfFieldEffect(source, m_focus, 1.0, 1.0, DepthOfFieldQuality.Preview);

            }
            else if (m_effectEffect.Source != source)
            {
                m_effectEffect.Source = source;
            }

            return new MaybeTask<IImageProvider>(m_effectEffect);
        }
        private static async Task RenderEffect(FocusBand focusBand, DepthOfFieldQuality quality, [CallerMemberName] string testName = "")
        {
			using (var source = KnownImages.Nurse.ImageSource)
            using (var effect = new LensTiltDepthOfFieldEffect(source, focusBand, 1.0, 1.0, quality))
            using (var renderer = new JpegRenderer(effect))
            {
                var buffer = await renderer.RenderAsync();

				ImageResults.Instance.SaveToPicturesLibrary(buffer, "LensTiltDepthOfFieldEffectTest_" + testName + ".jpg");
            }
        }
        public async Task RenderWithZeroWidthFocusAreaSuccedes()
        {
            var verticalZeroBand = new FocusBand(new Point(0.3, 0.5), new Point(0.3, 0.5));
            await RenderEffect(verticalZeroBand, DepthOfFieldQuality.Full);

            var horizontalZeroBand = new FocusBand(new Point(0.5, 0.7), new Point(0.5, 0.7));
            await RenderEffect(horizontalZeroBand, DepthOfFieldQuality.Full);
        }
        public async Task RenderWithFullFocusAreaSuccedes()
        {
            var verticalFullBand = new FocusBand(new Point(0.0, 0.5), new Point(1.0, 0.5));
            await RenderEffect(verticalFullBand, DepthOfFieldQuality.Full);

            var horizontalFullBand = new FocusBand(new Point(0.5, 0.0), new Point(0.5, 1.0));
            await RenderEffect(horizontalFullBand, DepthOfFieldQuality.Full);
        }
		private FocusBand GetBandFromHorizonLine(Point p1, Point p2)
		{
			double xDiff = p1.X - p2.X;
			double yDiff = p1.Y - p2.Y;

			Point midpoint = new Point((p2.X + p1.X) / 2, (p2.Y + p1.Y) / 2);

			Func<double, Point> lineNormalFunction;

			if (Math.Abs(xDiff) < 1e-3)
			{
				//special case to avoid divide by zero
				lineNormalFunction = (x) => new Point(midpoint.X + x, midpoint.Y);
			}
			else if (Math.Abs(yDiff) < 1e-3)
			{
				//special case to avoid divide by zero
				lineNormalFunction = (y) => new Point(midpoint.X, midpoint.Y + y);
			}
			else
			{
				double slope = (p2.Y - p1.Y) / (p2.X - p1.X);
				double perpSlope = -1 / slope;

				double intercept = midpoint.Y - (perpSlope * midpoint.X);

				lineNormalFunction = (x) => new Point(midpoint.X + x, (perpSlope * (midpoint.X + x)) + intercept);
			}

			FocusBand band = new FocusBand(lineNormalFunction(0), lineNormalFunction(1e-5));

			return band;
		}