Browse Source

Fix pad memory access error

pull/2052/head
James Jackson-South 4 years ago
parent
commit
baa8c7b8e7
  1. 6
      src/ImageSharp/Processing/Extensions/Transforms/PadExtensions.cs
  2. 5
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs
  3. 4
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs

6
src/ImageSharp/Processing/Extensions/Transforms/PadExtensions.cs

@ -1,6 +1,8 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using System;
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
@ -29,9 +31,11 @@ namespace SixLabors.ImageSharp.Processing
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Pad(this IImageProcessingContext source, int width, int height, Color color)
{
Size size = source.GetCurrentSize();
var options = new ResizeOptions
{
Size = new Size(width, height),
// Prevent downsizing.
Size = new Size(Math.Max(width, size.Width), Math.Max(height, size.Height)),
Mode = ResizeMode.BoxPad,
Sampler = KnownResamplers.NearestNeighbor,
PadColor = color

5
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs

@ -61,12 +61,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
Rectangle destinationRectangle = this.destinationRectangle;
bool compand = this.options.Compand;
bool premultiplyAlpha = this.options.PremultiplyAlpha;
this.options.PadColor = Color.GreenYellow;
TPixel fillColor = this.options.PadColor.ToPixel<TPixel>();
bool shouldFill = (this.options.Mode == ResizeMode.BoxPad || this.options.Mode == ResizeMode.Pad)
&& this.options.PadColor != default;
TPixel fillColor = this.options.PadColor.ToPixel<TPixel>();
// Handle resize dimensions identical to the original
if (source.Width == destination.Width

4
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs

@ -80,14 +80,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
int numberOfWindowBands = ResizeHelper.CalculateResizeWorkerHeightInWindowBands(
this.windowBandHeight,
targetWorkingRect.Width,
destWidth,
workingBufferLimitHintInBytes);
this.workerHeight = Math.Min(this.sourceRectangle.Height, numberOfWindowBands * this.windowBandHeight);
this.transposedFirstPassBuffer = configuration.MemoryAllocator.Allocate2D<Vector4>(
this.workerHeight,
targetWorkingRect.Width,
destWidth,
preferContiguosImageBuffers: true,
options: AllocationOptions.Clean);

Loading…
Cancel
Save