Exemplo n.º 1
0
        /// <summary>
        /// Determines the size of the source image.
        /// This method is only used when re-projection applies.
        /// </summary>
        /// <param name="sourceBoundingBox">The source bounding box.</param>
        /// <param name="targetSize">Requested target size.</param>
        /// <returns>The computed source size.</returns>
        protected virtual Size DetermineSourceSize(IBoundingBox sourceBoundingBox, Size targetSize)
        {
            if (!ReprojectionServiceOptions.SourceSizeFactor.HasValue)
            {
                return(DetermineSourceSizeByAmountOfPixels(sourceBoundingBox, targetSize.Area()));
            }

            if (ReprojectionServiceOptions.SourceSizeFactor.Value < 0)
            {
                return(DetermineSourceSizeByAmountOfPixels(sourceBoundingBox, -ReprojectionServiceOptions.SourceSizeFactor.Value * targetSize.Area()));
            }

            var aspect = sourceBoundingBox.AspectRatio();

            var sizes = new [] {
                new SizeD(targetSize.Height * aspect, targetSize.Height),
                new SizeD(targetSize.Width * aspect, targetSize.Width),
                new SizeD(targetSize.Width, targetSize.Width / aspect),
                new SizeD(targetSize.Height, targetSize.Height / aspect)
            };

            var min = sizes.Select(s => s.Area()).Min();
            var max = sizes.Select(s => s.Area()).Max();

            return(DetermineSourceSizeByAmountOfPixels(sourceBoundingBox, min + (max - min) * ReprojectionServiceOptions.SourceSizeFactor.Value));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Knowing the source bounding box and its aspect ratio, this helper determines
        /// an image size given the an amount of pixels that the image should contain.
        /// </summary>
        /// <param name="sourceBoundingBox">The source bounding box</param>
        /// <param name="nPixels">The number of pixels that the image should contain</param>
        /// <returns>The size determined out of bounding box and number of pixels, rounded to the nearest integer.</returns>
        protected virtual Size DetermineSourceSizeByAmountOfPixels(IBoundingBox sourceBoundingBox, double nPixels)
        {
            var aspectRatio = sourceBoundingBox.AspectRatio();
            var h           = Math.Sqrt(nPixels / aspectRatio);
            var w           = h * aspectRatio;

            return(new Size((int)Math.Round(w), (int)Math.Round(h)));
        }
Exemplo n.º 3
0
 /// <summary> Determines if two bounding boxes have the same aspect ratio. </summary>
 /// <param name="this">First bounding box.</param>
 /// <param name="other">Second bounding box.</param>
 /// <returns>True, if the aspect ratio is equal. False otherwise.</returns>
 public static bool EqualsAspect(this IBoundingBox @this, IBoundingBox other)
 {
     return(Math.Abs(@this.AspectRatio() - other.AspectRatio()) < 1e-4);
 }