|
|
@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Benchmarks.LoadResizeSave |
|
|
private const string SkiaSharpBitmap = nameof(SkiaSharpBitmap); |
|
|
private const string SkiaSharpBitmap = nameof(SkiaSharpBitmap); |
|
|
|
|
|
|
|
|
// Set the quality for ImagSharp
|
|
|
// Set the quality for ImagSharp
|
|
|
private readonly JpegEncoder imageSharpJpegEncoder = new () { Quality = Quality }; |
|
|
private readonly JpegEncoder imageSharpJpegEncoder = new() { Quality = Quality }; |
|
|
private readonly ImageCodecInfo systemDrawingJpegCodec = |
|
|
private readonly ImageCodecInfo systemDrawingJpegCodec = |
|
|
ImageCodecInfo.GetImageEncoders().First(codec => codec.FormatID == ImageFormat.Jpeg.Guid); |
|
|
ImageCodecInfo.GetImageEncoders().First(codec => codec.FormatID == ImageFormat.Jpeg.Guid); |
|
|
|
|
|
|
|
|
@ -138,7 +138,7 @@ namespace SixLabors.ImageSharp.Benchmarks.LoadResizeSave |
|
|
this.outputDirectory, |
|
|
this.outputDirectory, |
|
|
Path.GetFileNameWithoutExtension(inputPath) + "-" + postfix + Path.GetExtension(inputPath)); |
|
|
Path.GetFileNameWithoutExtension(inputPath) + "-" + postfix + Path.GetExtension(inputPath)); |
|
|
|
|
|
|
|
|
private (int width, int height) ScaledSize(int inWidth, int inHeight, int outSize) |
|
|
private (int Width, int Height) ScaledSize(int inWidth, int inHeight, int outSize) |
|
|
{ |
|
|
{ |
|
|
int width, height; |
|
|
int width, height; |
|
|
if (inWidth > inHeight) |
|
|
if (inWidth > inHeight) |
|
|
@ -160,8 +160,8 @@ namespace SixLabors.ImageSharp.Benchmarks.LoadResizeSave |
|
|
using var image = SystemDrawingImage.FromFile(input, true); |
|
|
using var image = SystemDrawingImage.FromFile(input, true); |
|
|
this.IncreaseTotalMegapixels(image.Width, image.Height); |
|
|
this.IncreaseTotalMegapixels(image.Width, image.Height); |
|
|
|
|
|
|
|
|
(int width, int height) scaled = this.ScaledSize(image.Width, image.Height, ThumbnailSize); |
|
|
(int Width, int Height) scaled = this.ScaledSize(image.Width, image.Height, this.ThumbnailSize); |
|
|
var resized = new Bitmap(scaled.width, scaled.height); |
|
|
var resized = new Bitmap(scaled.Width, scaled.Height); |
|
|
using var graphics = Graphics.FromImage(resized); |
|
|
using var graphics = Graphics.FromImage(resized); |
|
|
using var attributes = new ImageAttributes(); |
|
|
using var attributes = new ImageAttributes(); |
|
|
attributes.SetWrapMode(WrapMode.TileFlipXY); |
|
|
attributes.SetWrapMode(WrapMode.TileFlipXY); |
|
|
@ -188,7 +188,7 @@ namespace SixLabors.ImageSharp.Benchmarks.LoadResizeSave |
|
|
|
|
|
|
|
|
image.Mutate(i => i.Resize(new ResizeOptions |
|
|
image.Mutate(i => i.Resize(new ResizeOptions |
|
|
{ |
|
|
{ |
|
|
Size = new ImageSharpSize(ThumbnailSize, ThumbnailSize), |
|
|
Size = new ImageSharpSize(this.ThumbnailSize, this.ThumbnailSize), |
|
|
Mode = ResizeMode.Max |
|
|
Mode = ResizeMode.Max |
|
|
})); |
|
|
})); |
|
|
|
|
|
|
|
|
@ -205,7 +205,7 @@ namespace SixLabors.ImageSharp.Benchmarks.LoadResizeSave |
|
|
this.IncreaseTotalMegapixels(image.Width, image.Height); |
|
|
this.IncreaseTotalMegapixels(image.Width, image.Height); |
|
|
|
|
|
|
|
|
// Resize it to fit a 150x150 square
|
|
|
// Resize it to fit a 150x150 square
|
|
|
image.Resize(ThumbnailSize, ThumbnailSize); |
|
|
image.Resize(this.ThumbnailSize, this.ThumbnailSize); |
|
|
|
|
|
|
|
|
// Reduce the size of the file
|
|
|
// Reduce the size of the file
|
|
|
image.Strip(); |
|
|
image.Strip(); |
|
|
@ -221,8 +221,8 @@ namespace SixLabors.ImageSharp.Benchmarks.LoadResizeSave |
|
|
{ |
|
|
{ |
|
|
var settings = new ProcessImageSettings() |
|
|
var settings = new ProcessImageSettings() |
|
|
{ |
|
|
{ |
|
|
Width = ThumbnailSize, |
|
|
Width = this.ThumbnailSize, |
|
|
Height = ThumbnailSize, |
|
|
Height = this.ThumbnailSize, |
|
|
ResizeMode = CropScaleMode.Max, |
|
|
ResizeMode = CropScaleMode.Max, |
|
|
SaveFormat = FileFormat.Jpeg, |
|
|
SaveFormat = FileFormat.Jpeg, |
|
|
JpegQuality = Quality, |
|
|
JpegQuality = Quality, |
|
|
@ -238,11 +238,11 @@ namespace SixLabors.ImageSharp.Benchmarks.LoadResizeSave |
|
|
{ |
|
|
{ |
|
|
using var original = SKBitmap.Decode(input); |
|
|
using var original = SKBitmap.Decode(input); |
|
|
this.IncreaseTotalMegapixels(original.Width, original.Height); |
|
|
this.IncreaseTotalMegapixels(original.Width, original.Height); |
|
|
(int width, int height) scaled = this.ScaledSize(original.Width, original.Height, ThumbnailSize); |
|
|
(int Width, int Height) scaled = this.ScaledSize(original.Width, original.Height, this.ThumbnailSize); |
|
|
using var surface = SKSurface.Create(new SKImageInfo(scaled.width, scaled.height, original.ColorType, original.AlphaType)); |
|
|
using var surface = SKSurface.Create(new SKImageInfo(scaled.Width, scaled.Height, original.ColorType, original.AlphaType)); |
|
|
using var paint = new SKPaint() { FilterQuality = SKFilterQuality.High }; |
|
|
using var paint = new SKPaint() { FilterQuality = SKFilterQuality.High }; |
|
|
SKCanvas canvas = surface.Canvas; |
|
|
SKCanvas canvas = surface.Canvas; |
|
|
canvas.Scale((float)scaled.width / original.Width); |
|
|
canvas.Scale((float)scaled.Width / original.Width); |
|
|
canvas.DrawBitmap(original, 0, 0, paint); |
|
|
canvas.DrawBitmap(original, 0, 0, paint); |
|
|
canvas.Flush(); |
|
|
canvas.Flush(); |
|
|
|
|
|
|
|
|
@ -256,8 +256,8 @@ namespace SixLabors.ImageSharp.Benchmarks.LoadResizeSave |
|
|
{ |
|
|
{ |
|
|
using var original = SKBitmap.Decode(input); |
|
|
using var original = SKBitmap.Decode(input); |
|
|
this.IncreaseTotalMegapixels(original.Width, original.Height); |
|
|
this.IncreaseTotalMegapixels(original.Width, original.Height); |
|
|
(int width, int height) scaled = this.ScaledSize(original.Width, original.Height, ThumbnailSize); |
|
|
(int Width, int Height) scaled = this.ScaledSize(original.Width, original.Height, this.ThumbnailSize); |
|
|
using var resized = original.Resize(new SKImageInfo(scaled.width, scaled.height), SKFilterQuality.High); |
|
|
using var resized = original.Resize(new SKImageInfo(scaled.Width, scaled.Height), SKFilterQuality.High); |
|
|
if (resized == null) |
|
|
if (resized == null) |
|
|
{ |
|
|
{ |
|
|
return; |
|
|
return; |
|
|
@ -272,7 +272,7 @@ namespace SixLabors.ImageSharp.Benchmarks.LoadResizeSave |
|
|
public void NetVipsResize(string input) |
|
|
public void NetVipsResize(string input) |
|
|
{ |
|
|
{ |
|
|
// Thumbnail to fit a 150x150 square
|
|
|
// Thumbnail to fit a 150x150 square
|
|
|
using var thumb = NetVipsImage.Thumbnail(input, ThumbnailSize, ThumbnailSize); |
|
|
using var thumb = NetVipsImage.Thumbnail(input, this.ThumbnailSize, this.ThumbnailSize); |
|
|
|
|
|
|
|
|
// Save the results
|
|
|
// Save the results
|
|
|
thumb.Jpegsave(this.OutputPath(input, NetVips), q: Quality, strip: true); |
|
|
thumb.Jpegsave(this.OutputPath(input, NetVips), q: Quality, strip: true); |
|
|
|