Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ResizeProcessor{TPixel}"/> class.
        /// </summary>
        /// <param name="options">The resize options</param>
        /// <param name="sourceSize">The source image size</param>
        public ResizeProcessor(ResizeOptions options, Size sourceSize)
        {
            Guard.NotNull(options, nameof(options));
            Guard.NotNull(options.Sampler, nameof(options.Sampler));

            int tempWidth  = options.Size.Width;
            int tempHeight = options.Size.Height;

            // Ensure size is populated across both dimensions.
            // These dimensions are used to calculate the final dimensions determined by the mode algorithm.
            if (tempWidth == 0 && tempHeight > 0)
            {
                tempWidth = (int)MathF.Round(sourceSize.Width * tempHeight / (float)sourceSize.Height);
            }

            if (tempHeight == 0 && tempWidth > 0)
            {
                tempHeight = (int)MathF.Round(sourceSize.Height * tempWidth / (float)sourceSize.Width);
            }

            Guard.MustBeGreaterThan(tempWidth, 0, nameof(tempWidth));
            Guard.MustBeGreaterThan(tempHeight, 0, nameof(tempHeight));

            (Size size, Rectangle rectangle) = ResizeHelper.CalculateTargetLocationAndBounds(sourceSize, options, tempWidth, tempHeight);

            this.Sampler         = options.Sampler;
            this.Width           = size.Width;
            this.Height          = size.Height;
            this.ResizeRectangle = rectangle;
            this.Compand         = options.Compand;
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ResizeProcessor{TPixel}"/> class.
        /// </summary>
        /// <param name="options">The resize options</param>
        /// <param name="sourceSize">The source image size</param>
        public ResizeProcessor(ResizeOptions options, Size sourceSize)
        {
            Guard.NotNull(options, nameof(options));
            Guard.NotNull(options.Sampler, nameof(options.Sampler));

            int targetWidth  = options.Size.Width;
            int targetHeight = options.Size.Height;

            // Ensure size is populated across both dimensions.
            // These dimensions are used to calculate the final dimensions determined by the mode algorithm.
            // If only one of the incoming dimensions is 0, it will be modified here to maintain aspect ratio.
            // If it is not possible to keep aspect ratio, make sure at least the minimum is is kept.
            const int min = 1;

            if (targetWidth == 0 && targetHeight > 0)
            {
                targetWidth = (int)MathF.Max(min, MathF.Round(sourceSize.Width * targetHeight / (float)sourceSize.Height));
            }

            if (targetHeight == 0 && targetWidth > 0)
            {
                targetHeight = (int)MathF.Max(min, MathF.Round(sourceSize.Height * targetWidth / (float)sourceSize.Width));
            }

            Guard.MustBeGreaterThan(targetWidth, 0, nameof(targetWidth));
            Guard.MustBeGreaterThan(targetHeight, 0, nameof(targetHeight));

            (Size size, Rectangle rectangle) = ResizeHelper.CalculateTargetLocationAndBounds(sourceSize, options, targetWidth, targetHeight);

            this.Sampler         = options.Sampler;
            this.Width           = size.Width;
            this.Height          = size.Height;
            this.ResizeRectangle = rectangle;
            this.Compand         = options.Compand;
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ResizeProcessor"/> class.
        /// </summary>
        /// <param name="options">The resize options.</param>
        /// <param name="sourceSize">The source image size.</param>
        public ResizeProcessor(ResizeOptions options, Size sourceSize)
        {
            Guard.NotNull(options, nameof(options));
            Guard.NotNull(options.Sampler, nameof(options.Sampler));

            (Size size, Rectangle rectangle) = ResizeHelper.CalculateTargetLocationAndBounds(sourceSize, options);

            this.Sampler         = options.Sampler;
            this.TargetWidth     = size.Width;
            this.TargetHeight    = size.Height;
            this.TargetRectangle = rectangle;
            this.Compand         = options.Compand;
        }
Пример #4
0
        public ResizeWorker(
            Configuration configuration,
            Buffer2DRegion <TPixel> source,
            PixelConversionModifiers conversionModifiers,
            ResizeKernelMap horizontalKernelMap,
            ResizeKernelMap verticalKernelMap,
            int destWidth,
            Rectangle targetWorkingRect,
            Point targetOrigin)
        {
            this.configuration       = configuration;
            this.source              = source;
            this.sourceRectangle     = source.Rectangle;
            this.conversionModifiers = conversionModifiers;
            this.horizontalKernelMap = horizontalKernelMap;
            this.verticalKernelMap   = verticalKernelMap;
            this.destWidth           = destWidth;
            this.targetWorkingRect   = targetWorkingRect;
            this.targetOrigin        = targetOrigin;

            this.windowBandHeight = verticalKernelMap.MaxDiameter;

            // We need to make sure the working buffer is contiguous:
            int workingBufferLimitHintInBytes = Math.Min(
                configuration.WorkingBufferSizeHintInBytes,
                configuration.MemoryAllocator.GetBufferCapacityInBytes());

            int numberOfWindowBands = ResizeHelper.CalculateResizeWorkerHeightInWindowBands(
                this.windowBandHeight,
                destWidth,
                workingBufferLimitHintInBytes);

            this.workerHeight = Math.Min(this.sourceRectangle.Height, numberOfWindowBands * this.windowBandHeight);

            this.transposedFirstPassBuffer = configuration.MemoryAllocator.Allocate2D <Vector4>(
                this.workerHeight,
                destWidth,
                preferContiguosImageBuffers: true,
                options: AllocationOptions.Clean);

            this.tempRowBuffer    = configuration.MemoryAllocator.Allocate <Vector4>(this.sourceRectangle.Width);
            this.tempColumnBuffer = configuration.MemoryAllocator.Allocate <Vector4>(destWidth);

            this.currentWindow = new RowInterval(0, this.workerHeight);
        }
Пример #5
0
        public ResizeWorker(
            Configuration configuration,
            BufferArea <TPixel> source,
            PixelConversionModifiers conversionModifiers,
            ResizeKernelMap horizontalKernelMap,
            ResizeKernelMap verticalKernelMap,
            int destWidth,
            Rectangle targetWorkingRect,
            Point targetOrigin)
        {
            this.configuration       = configuration;
            this.source              = source;
            this.sourceRectangle     = source.Rectangle;
            this.conversionModifiers = conversionModifiers;
            this.horizontalKernelMap = horizontalKernelMap;
            this.verticalKernelMap   = verticalKernelMap;
            this.destWidth           = destWidth;
            this.targetWorkingRect   = targetWorkingRect;
            this.targetOrigin        = targetOrigin;

            this.windowBandHeight = verticalKernelMap.MaxDiameter;

            int numberOfWindowBands = ResizeHelper.CalculateResizeWorkerHeightInWindowBands(
                this.windowBandHeight,
                destWidth,
                configuration.WorkingBufferSizeHintInBytes);

            this.workerHeight = Math.Min(this.sourceRectangle.Height, numberOfWindowBands * this.windowBandHeight);

            this.transposedFirstPassBuffer = configuration.MemoryAllocator.Allocate2D <Vector4>(
                this.workerHeight,
                destWidth,
                AllocationOptions.Clean);

            this.tempRowBuffer    = configuration.MemoryAllocator.Allocate <Vector4>(this.sourceRectangle.Width);
            this.tempColumnBuffer = configuration.MemoryAllocator.Allocate <Vector4>(destWidth);

            this.currentWindow = new RowInterval(0, this.workerHeight);
        }