// Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. // Modified file, original is found at: // https://github.com/SixLabors/ImageSharp/blob/master/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor.cs using SixLabors.ImageSharp; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Processors.Transforms; namespace Hast.Samples.SampleAssembly.ImageSharpModifications.Resize; public class ResizeProcessor : CloningImageProcessor { /// /// Initializes a new instance of the class. /// /// The resize options. /// The source image size. public ResizeProcessor(ResizeOptions options, Size sourceSize, int maxDegreeOfParallelism) { Guard.NotNull(options, nameof(options)); Guard.NotNull(options.Sampler, nameof(options.Sampler)); Guard.MustBeValueType(options.Sampler, nameof(options.Sampler)); (var size, var rectangle) = ResizeHelper.CalculateTargetLocationAndBounds(sourceSize, options); Sampler = options.Sampler; DestinationWidth = size.Width; DestinationHeight = size.Height; DestinationRectangle = rectangle; Compand = options.Compand; MaxDegreeOfParallelism = maxDegreeOfParallelism; } /// /// Gets the sampler to perform the resize operation. /// public IResampler Sampler { get; } /// /// Gets the destination width. /// public int DestinationWidth { get; } /// /// Gets the destination height. /// public int DestinationHeight { get; } /// /// Gets the resize rectangle. /// public Rectangle DestinationRectangle { get; } /// /// Gets a value indicating whether to compress or expand individual pixel color values on processing. /// public bool Compand { get; } /// /// Gets a value indicating whether to premultiply the alpha (if it exists) during the resize operation. /// public bool PremultiplyAlpha { get; } /// /// Gets a value indicating the max degree of parallelism. /// public int MaxDegreeOfParallelism { get; } /// public override ICloningImageProcessor CreatePixelSpecificCloningProcessor( Configuration configuration, Image source, Rectangle sourceRectangle) { configuration.MaxDegreeOfParallelism = MaxDegreeOfParallelism; return new ResizeProcessor(configuration, this, source, sourceRectangle); } }