Ejemplo n.º 1
0
 /// <summary>
 /// Resizes an image to the given width and height with the given sampler.
 /// </summary>
 /// <typeparam name="TPixel">The pixel format.</typeparam>
 /// <param name="source">The image to resize.</param>
 /// <param name="width">The target image width.</param>
 /// <param name="height">The target image height.</param>
 /// <param name="sampler">The <see cref="IResampler"/> to perform the resampling.</param>
 /// <returns>The <see cref="Image{TPixel}"/></returns>
 /// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks>
 public static Image <TPixel> Resize <TPixel>(this Image <TPixel> source, int width, int height, IResampler sampler)
     where TPixel : struct, IPixel <TPixel>
 {
     return(Resize(source, width, height, sampler, false));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Resampler"/> class.
        /// </summary>
        /// <param name="sampler">
        /// The sampler to perform the resize operation.
        /// </param>
        protected Resampler(IResampler sampler)
        {
            Guard.NotNull(sampler, nameof(sampler));

            this.Sampler = sampler;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="InterpolatedTransformProcessorBase{TPixel}"/> class.
 /// </summary>
 /// <param name="sampler">The sampler to perform the transform operation.</param>
 protected InterpolatedTransformProcessorBase(IResampler sampler)
 {
     this.Sampler = sampler;
 }
 protected static void CalculateWeightsDown(int min, int max, int sourceMin, int sourceMax, float point, IResampler sampler, float scale, Span <float> weights)
 {
     float     sum            = 0;
     ref float weightsBaseRef = ref weights[0];
Ejemplo n.º 5
0
        public void ImageShouldResizeWithMinMode <TPixel>(TestImageProvider <TPixel> provider, string name, IResampler sampler)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> image = provider.GetImage())
            {
                var options = new ResizeOptions
                {
                    Sampler = sampler,
                    Size    = new Size((int)MathF.Round(image.Width * .75F), (int)MathF.Round(image.Height * .95F)),
                    Mode    = ResizeMode.Min
                };

                image.Resize(options)
                .DebugSave(provider, name, Extensions.Bmp);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CenteredAffineTransformProcessor{TPixel}"/> class.
 /// </summary>
 /// <param name="matrix">The transform matrix</param>
 /// <param name="sampler">The sampler to perform the transform operation.</param>
 /// <param name="sourceSize">The source image size</param>
 protected CenteredAffineTransformProcessor(Matrix3x2 matrix, IResampler sampler, Size sourceSize)
     : base(matrix, sampler, GetTransformedDimensions(sourceSize, matrix))
 {
 }
Ejemplo n.º 7
0
        public void Resize_WorksWithAllResamplers <TPixel>(TestImageProvider <TPixel> provider, string name, IResampler sampler, float ratio)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> image = provider.GetImage())
            {
                SizeF newSize = image.Size() * ratio;
                image.Mutate(x => x.Resize((Size)newSize, sampler, false));
                FormattableString details = $"{name}-{ratio.ToString(System.Globalization.CultureInfo.InvariantCulture)}";

                image.DebugSave(provider, details);
                image.CompareToReferenceOutput(ImageComparer.TolerantPercentage(0.005f), provider, details);
            }
        }
        /// <summary>
        /// Resizes an image to the given width and height with the given sampler and
        /// source rectangle.
        /// </summary>
        /// <param name="source">The image to resize.</param>
        /// <param name="width">The target image width.</param>
        /// <param name="height">The target image height.</param>
        /// <param name="sampler">The <see cref="IResampler"/> to perform the resampling.</param>
        /// <param name="sourceRectangle">
        /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
        /// </param>
        /// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
        /// <returns>The <see cref="Image"/></returns>
        /// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks>
        public static Image Resize(this Image source, int width, int height, IResampler sampler, Rectangle sourceRectangle, ProgressEventHandler progressHandler = null)
        {
            if (width == 0 && height > 0)
            {
                width = source.Width * height / source.Height;
            }

            if (height == 0 && width > 0)
            {
                height = source.Height * width / source.Width;
            }

            Resize processor = new Resize(sampler);
            processor.OnProgress += progressHandler;

            try
            {
                return source.Process(width, height, sourceRectangle, new Rectangle(0, 0, width, height), processor);
            }
            finally
            {
                processor.OnProgress -= progressHandler;
            }
        }
Ejemplo n.º 9
0
        public void ImageShouldResizeWithCropWidthMode <TPixel>(TestImageProvider <TPixel> provider, string name, IResampler sampler)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> image = provider.GetImage())
            {
                var options = new ResizeOptions
                {
                    Sampler = sampler,
                    Size    = new Size(image.Width / 2, image.Height)
                };

                image.Resize(options)
                .DebugSave(provider, name, Extensions.Bmp);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CenteredProjectiveTransformProcessor{TPixel}"/> class.
 /// </summary>
 /// <param name="matrix">The transform matrix</param>
 /// <param name="sampler">The sampler to perform the transform operation.</param>
 protected CenteredProjectiveTransformProcessor(Matrix4x4 matrix, IResampler sampler)
     : base(matrix, sampler)
 {
 }
Ejemplo n.º 11
0
 public void ImageShouldResizeHeightAndKeepAspect <TPixel>(TestImageProvider <TPixel> provider, string name, IResampler sampler)
     where TPixel : struct, IPixel <TPixel>
 {
     using (Image <TPixel> image = provider.GetImage())
     {
         image.Resize(0, image.Height / 3, sampler, false)
         .DebugSave(provider, name, Extensions.Bmp);
     }
 }
Ejemplo n.º 12
0
        public void ImageShouldResizeFromSourceRectangle <TPixel>(TestImageProvider <TPixel> provider, string name, IResampler sampler)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> image = provider.GetImage())
            {
                var sourceRectangle = new Rectangle(image.Width / 8, image.Height / 8, image.Width / 4, image.Height / 4);
                var destRectangle   = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);

                image.Resize(image.Width, image.Height, sampler, sourceRectangle, destRectangle, false)
                .DebugSave(provider, name, Extensions.Bmp);
            }
        }
Ejemplo n.º 13
0
 public void ImageShouldResize <TPixel>(TestImageProvider <TPixel> provider, string name, IResampler sampler)
     where TPixel : struct, IPixel <TPixel>
 {
     using (Image <TPixel> image = provider.GetImage())
     {
         image.Resize(image.Width / 2, image.Height / 2, sampler, true)
         .DebugSave(provider, name, Extensions.Bmp);
     }
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Rotate"/> class.
 /// </summary>
 /// <param name="sampler">
 /// The sampler to perform the resize operation.
 /// </param>
 public Rotate(IResampler sampler)
     : base(sampler)
 {
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ResizeProcessor"/> class.
 /// </summary>
 /// <param name="sampler">The sampler to perform the resize operation.</param>
 /// <param name="width">The target width.</param>
 /// <param name="height">The target height.</param>
 /// <param name="sourceSize">The source image size</param>
 public ResizeProcessor(IResampler sampler, int width, int height, Size sourceSize)
     : this(sampler, width, height, sourceSize, new Rectangle(0, 0, width, height), false)
 {
 }
 /// <summary>
 /// Resizes an image to the given width and height with the given sampler.
 /// </summary>
 /// <param name="source">The image to resize.</param>
 /// <param name="width">The target image width.</param>
 /// <param name="height">The target image height.</param>
 /// <param name="sampler">The <see cref="IResampler"/> to perform the resampling.</param>
 /// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
 /// <returns>The <see cref="Image"/></returns>
 /// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks>
 public static Image Resize(this Image source, int width, int height, IResampler sampler, ProgressEventHandler progressHandler = null)
 {
     return Resize(source, width, height, sampler, source.Bounds, progressHandler);
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Skews an image by the given angles in degrees using the specified sampling algorithm.
 /// </summary>
 /// <typeparam name="TPixel">The pixel format.</typeparam>
 /// <param name="source">The image to skew.</param>
 /// <param name="degreesX">The angle in degrees to perform the skew along the x-axis.</param>
 /// <param name="degreesY">The angle in degrees to perform the skew along the y-axis.</param>
 /// <param name="sampler">The <see cref="IResampler"/> to perform the resampling.</param>
 /// <returns>The <see cref="Image{TPixel}"/></returns>
 public static IImageProcessingContext <TPixel> Skew <TPixel>(this IImageProcessingContext <TPixel> source, float degreesX, float degreesY, IResampler sampler)
     where TPixel : struct, IPixel <TPixel>
 => source.ApplyProcessor(new SkewProcessor <TPixel>(degreesX, degreesY, sampler, source.GetCurrentSize()));
        /// <summary>
        /// Rotates an image by the given angle in degrees.
        /// </summary>
        /// <param name="source">The image to resize.</param>
        /// <param name="degrees">The angle in degrees to perform the rotation.</param>
        /// <param name="sampler">The <see cref="IResampler"/> to perform the resampling.</param>
        /// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
        /// <returns>The <see cref="Image"/></returns>
        public static Image Rotate(this Image source, float degrees, IResampler sampler, ProgressEventHandler progressHandler = null)
        {
            Rotate processor = new Rotate(sampler) { Angle = degrees };
            processor.OnProgress += progressHandler;

            try
            {
                return source.Process(source.Width, source.Height, source.Bounds, source.Bounds, processor);
            }
            finally
            {
                processor.OnProgress -= progressHandler;
            }
        }
Ejemplo n.º 19
0
        public void ImageShouldResizeWithMaxMode <TPixel>(TestImageProvider <TPixel> provider, string name, IResampler sampler)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> image = provider.GetImage())
            {
                var options = new ResizeOptions
                {
                    Sampler = sampler,
                    Size    = new Size(300, 300),
                    Mode    = ResizeMode.Max
                };

                image.Resize(options)
                .DebugSave(provider, name, Extensions.Bmp);
            }
        }