Browse Source

Merge branch 'master' into PNGOptimisation

pull/1574/head
James Jackson-South 6 years ago
committed by GitHub
parent
commit
6865e7238a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs
  2. 4
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
  3. 16
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeHelper.cs
  4. 16
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs

8
src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the GNU Affero General Public License, Version 3. // Licensed under the GNU Affero General Public License, Version 3.
using System; using System;
@ -28,12 +28,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
/// <summary> /// <summary>
/// Gets or sets the number of scanlines within the frame. /// Gets or sets the number of scanlines within the frame.
/// </summary> /// </summary>
public short Scanlines { get; set; } public int Scanlines { get; set; }
/// <summary> /// <summary>
/// Gets or sets the number of samples per scanline. /// Gets or sets the number of samples per scanline.
/// </summary> /// </summary>
public short SamplesPerLine { get; set; } public int SamplesPerLine { get; set; }
/// <summary> /// <summary>
/// Gets or sets the number of components within a frame. In progressive frames this value can range from only 1 to 4. /// Gets or sets the number of components within a frame. In progressive frames this value can range from only 1 to 4.
@ -105,4 +105,4 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
} }
} }
} }
} }

4
src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

@ -841,8 +841,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
Extended = frameMarker.Marker == JpegConstants.Markers.SOF1, Extended = frameMarker.Marker == JpegConstants.Markers.SOF1,
Progressive = frameMarker.Marker == JpegConstants.Markers.SOF2, Progressive = frameMarker.Marker == JpegConstants.Markers.SOF2,
Precision = this.temp[0], Precision = this.temp[0],
Scanlines = (short)((this.temp[1] << 8) | this.temp[2]), Scanlines = (this.temp[1] << 8) | this.temp[2],
SamplesPerLine = (short)((this.temp[3] << 8) | this.temp[4]), SamplesPerLine = (this.temp[3] << 8) | this.temp[4],
ComponentCount = this.temp[5] ComponentCount = this.temp[5]
}; };

16
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeHelper.cs

@ -72,7 +72,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
// case ResizeMode.Stretch: // case ResizeMode.Stretch:
default: default:
return (new Size(width, height), new Rectangle(0, 0, width, height)); return (new Size(Sanitize(width), Sanitize(height)), new Rectangle(0, 0, Sanitize(width), Sanitize(height)));
} }
} }
@ -143,7 +143,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
} }
// Target image width and height can be different to the rectangle width and height. // Target image width and height can be different to the rectangle width and height.
return (new Size(width, height), new Rectangle(targetX, targetY, targetWidth, targetHeight)); return (new Size(Sanitize(width), Sanitize(height)), new Rectangle(targetX, targetY, Sanitize(targetWidth), Sanitize(targetHeight)));
} }
// Switch to pad mode to downscale and calculate from there. // Switch to pad mode to downscale and calculate from there.
@ -253,7 +253,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
} }
// Target image width and height can be different to the rectangle width and height. // Target image width and height can be different to the rectangle width and height.
return (new Size(width, height), new Rectangle(targetX, targetY, targetWidth, targetHeight)); return (new Size(Sanitize(width), Sanitize(height)), new Rectangle(targetX, targetY, Sanitize(targetWidth), Sanitize(targetHeight)));
} }
private static (Size, Rectangle) CalculateMaxRectangle( private static (Size, Rectangle) CalculateMaxRectangle(
@ -282,7 +282,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
} }
// Replace the size to match the rectangle. // Replace the size to match the rectangle.
return (new Size(targetWidth, targetHeight), new Rectangle(0, 0, targetWidth, targetHeight)); return (new Size(Sanitize(targetWidth), Sanitize(targetHeight)), new Rectangle(0, 0, Sanitize(targetWidth), Sanitize(targetHeight)));
} }
private static (Size, Rectangle) CalculateMinRectangle( private static (Size, Rectangle) CalculateMinRectangle(
@ -330,7 +330,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
} }
// Replace the size to match the rectangle. // Replace the size to match the rectangle.
return (new Size(targetWidth, targetHeight), new Rectangle(0, 0, targetWidth, targetHeight)); return (new Size(Sanitize(targetWidth), Sanitize(targetHeight)), new Rectangle(0, 0, Sanitize(targetWidth), Sanitize(targetHeight)));
} }
private static (Size, Rectangle) CalculatePadRectangle( private static (Size, Rectangle) CalculatePadRectangle(
@ -398,7 +398,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
} }
// Target image width and height can be different to the rectangle width and height. // Target image width and height can be different to the rectangle width and height.
return (new Size(width, height), new Rectangle(targetX, targetY, targetWidth, targetHeight)); return (new Size(Sanitize(width), Sanitize(height)), new Rectangle(targetX, targetY, Sanitize(targetWidth), Sanitize(targetHeight)));
} }
private static (Size, Rectangle) CalculateManualRectangle( private static (Size, Rectangle) CalculateManualRectangle(
@ -419,9 +419,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
int targetHeight = targetRectangle.Height > 0 ? targetRectangle.Height : height; int targetHeight = targetRectangle.Height > 0 ? targetRectangle.Height : height;
// Target image width and height can be different to the rectangle width and height. // Target image width and height can be different to the rectangle width and height.
return (new Size(width, height), new Rectangle(targetX, targetY, targetWidth, targetHeight)); return (new Size(Sanitize(width), Sanitize(height)), new Rectangle(targetX, targetY, Sanitize(targetWidth), Sanitize(targetHeight)));
} }
private static void ThrowInvalid(string message) => throw new InvalidOperationException(message); private static void ThrowInvalid(string message) => throw new InvalidOperationException(message);
private static int Sanitize(int input) => Math.Max(1, input);
} }
} }

16
tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs

@ -605,5 +605,21 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2)); image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2));
} }
} }
[Fact]
public void Issue1195()
{
using (var image = new Image<Rgba32>(2, 300))
{
var size = new Size(50, 50);
image.Mutate(x => x
.Resize(
new ResizeOptions
{
Size = size,
Mode = ResizeMode.Max
}));
}
}
} }
} }

Loading…
Cancel
Save