Skip to content

Cleanup #965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle source
}

float yPlusOne = y + 1;
for (float subPixel = (float)y; subPixel < yPlusOne; subPixel += subpixelFraction)
for (float subPixel = y; subPixel < yPlusOne; subPixel += subpixelFraction)
{
int pointsFound = region.Scan(subPixel + offset, buffer, configuration);
if (pointsFound == 0)
Expand Down Expand Up @@ -192,4 +192,4 @@ private bool IsSolidBrushWithoutBlending(out SolidBrush solidBrush)
return this.definition.Options.IsOpaqueColorWithoutBlending(solidBrush.Color);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,22 @@ private class CachingGlyphRenderer : IGlyphRenderer, IDisposable

private readonly PathBuilder builder;

private Point currentRenderPosition = default;
private (GlyphRendererParameters glyph, PointF subPixelOffset) currentGlyphRenderParams = default;
private readonly int offset = 0;
private PointF currentPoint = default(PointF);
private Point currentRenderPosition;
private (GlyphRendererParameters glyph, PointF subPixelOffset) currentGlyphRenderParams;
private readonly int offset;
private PointF currentPoint;

private readonly Dictionary<(GlyphRendererParameters glyph, PointF subPixelOffset), GlyphRenderData>
glyphData = new Dictionary<(GlyphRendererParameters glyph, PointF subPixelOffset), GlyphRenderData>();

private readonly bool renderOutline = false;
private readonly bool renderFill = false;
private bool rasterizationRequired = false;
private readonly bool renderOutline;
private readonly bool renderFill;
private bool rasterizationRequired;

public CachingGlyphRenderer(MemoryAllocator memoryAllocator, int size, IPen pen, bool renderFill)
{
this.MemoryAllocator = memoryAllocator;
this.currentRenderPosition = default;
this.Pen = pen;
this.renderFill = renderFill;
this.renderOutline = pen != null;
Expand Down Expand Up @@ -326,7 +327,7 @@ private Buffer2D<float> Render(IPath path)
bool scanlineDirty = false;
float yPlusOne = y + 1;

for (float subPixel = (float)y; subPixel < yPlusOne; subPixel += subpixelFraction)
for (float subPixel = y; subPixel < yPlusOne; subPixel += subpixelFraction)
{
var start = new PointF(path.Bounds.Left - 1, subPixel);
var end = new PointF(path.Bounds.Right + 1, subPixel);
Expand Down
6 changes: 3 additions & 3 deletions src/ImageSharp/Common/Extensions/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System.Threading.Tasks;
Expand All @@ -16,7 +16,7 @@ internal static class ConfigurationExtensions
/// </summary>
public static ParallelOptions GetParallelOptions(this Configuration configuration)
{
return new ParallelOptions() { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism };
return new ParallelOptions { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism };
}
}
}
}
4 changes: 2 additions & 2 deletions src/ImageSharp/Common/Helpers/Guard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public static void DestinationShouldNotBeTooShort<TSource, TDest>(
{
if (destination.Length < source.Length)
{
ThrowArgumentException($"Destination span is too short!", destinationParamName);
ThrowArgumentException("Destination span is too short!", destinationParamName);
}
}

Expand All @@ -251,7 +251,7 @@ public static void DestinationShouldNotBeTooShort<TSource, TDest>(
{
if (destination.Length < source.Length)
{
ThrowArgumentException($"Destination span is too short!", destinationParamName);
ThrowArgumentException("Destination span is too short!", destinationParamName);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/ImageSharp/Common/ParallelUtils/ParallelHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System;
Expand Down Expand Up @@ -61,7 +61,7 @@ public static void IterateRows(

int verticalStep = DivideCeil(rectangle.Height, numOfSteps);

var parallelOptions = new ParallelOptions() { MaxDegreeOfParallelism = numOfSteps };
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };

Parallel.For(
0,
Expand Down Expand Up @@ -109,7 +109,7 @@ public static void IterateRowsWithTempBuffer<T>(

int verticalStep = DivideCeil(rectangle.Height, numOfSteps);

var parallelOptions = new ParallelOptions() { MaxDegreeOfParallelism = numOfSteps };
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };

Parallel.For(
0,
Expand Down Expand Up @@ -158,4 +158,4 @@ private static void ValidateRectangle(Rectangle rectangle)
$"{nameof(rectangle)}.{nameof(rectangle.Height)}");
}
}
}
}
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Bmp/BmpFileHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static BmpFileHeader Parse(Span<byte> data)
return MemoryMarshal.Cast<byte, BmpFileHeader>(data)[0];
}

public unsafe void WriteTo(Span<byte> buffer)
public void WriteTo(Span<byte> buffer)
{
ref BmpFileHeader dest = ref Unsafe.As<byte, BmpFileHeader>(ref MemoryMarshal.GetReference(buffer));

Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ public void WriteV3Header(Span<byte> buffer)
/// Writes a complete Bitmap V4 header to a buffer.
/// </summary>
/// <param name="buffer">The buffer to write to.</param>
public unsafe void WriteV4Header(Span<byte> buffer)
public void WriteV4Header(Span<byte> buffer)
{
ref BmpInfoHeader dest = ref Unsafe.As<byte, BmpInfoHeader>(ref MemoryMarshal.GetReference(buffer));

Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Gif/GifEncoderCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream)
bool useGlobalTable = this.colorTableMode == GifColorTableMode.Global;

// Quantize the image returning a palette.
IQuantizedFrame<TPixel> quantized = null;
IQuantizedFrame<TPixel> quantized;
using (IFrameQuantizer<TPixel> frameQuantizer = this.quantizer.CreateFrameQuantizer<TPixel>(image.GetConfiguration()))
{
quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private void ParseBaselineData()
}
}

private unsafe void ParseBaselineDataInterleaved()
private void ParseBaselineDataInterleaved()
{
// Interleaved
int mcu = 0;
Expand Down Expand Up @@ -196,7 +196,7 @@ ref Unsafe.Add(ref blockRef, blockCol),
}
}

private unsafe void ParseBaselineDataNonInterleaved()
private void ParseBaselineDataNonInterleaved()
{
JpegComponent component = this.components[this.frame.ComponentOrder[0]];
ref HuffmanScanBuffer buffer = ref this.scanBuffer;
Expand Down Expand Up @@ -366,7 +366,7 @@ ref Unsafe.Add(ref blockRef, blockCol),
}
}

private unsafe void ParseProgressiveDataNonInterleaved()
private void ParseProgressiveDataNonInterleaved()
{
JpegComponent component = this.components[this.frame.ComponentOrder[0]];
ref HuffmanScanBuffer buffer = ref this.scanBuffer;
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Png/PngConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal static class PngConstants
/// <summary>
/// The dictionary of available color types.
/// </summary>
public static readonly Dictionary<PngColorType, byte[]> ColorTypes = new Dictionary<PngColorType, byte[]>()
public static readonly Dictionary<PngColorType, byte[]> ColorTypes = new Dictionary<PngColorType, byte[]>
{
[PngColorType.Grayscale] = new byte[] { 1, 2, 4, 8, 16 },
[PngColorType.Rgb] = new byte[] { 8, 16 },
Expand Down
8 changes: 4 additions & 4 deletions src/ImageSharp/Image.FromBytes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System;
Expand Down Expand Up @@ -147,7 +147,7 @@ public static IImageFormat DetectFormat(ReadOnlySpan<byte> data)
/// <param name="config">The configuration.</param>
/// <param name="data">The byte array containing encoded image data to read the header from.</param>
/// <returns>The mime type or null if none found.</returns>
public static unsafe IImageFormat DetectFormat(Configuration config, ReadOnlySpan<byte> data)
public static IImageFormat DetectFormat(Configuration config, ReadOnlySpan<byte> data)
{
int maxHeaderSize = config.MaxHeaderSize;
if (maxHeaderSize <= 0)
Expand Down Expand Up @@ -351,7 +351,7 @@ public static Image Load(ReadOnlySpan<byte> data, out IImageFormat format) =>
/// <param name="config">The configuration options.</param>
/// <param name="data">The byte span containing image data.</param>
/// <returns>A new <see cref="Image"/>.</returns>
public static unsafe Image Load(Configuration config, ReadOnlySpan<byte> data) => Load(config, data, out _);
public static Image Load(Configuration config, ReadOnlySpan<byte> data) => Load(config, data, out _);

/// <summary>
/// Load a new instance of <see cref="Image"/> from the given encoded byte span.
Expand Down Expand Up @@ -395,4 +395,4 @@ public static unsafe Image Load(
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/ImageSharp/ImageFrame{TPixel}.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System;
Expand Down Expand Up @@ -267,7 +267,7 @@ internal ImageFrame<TPixel2> CloneAs<TPixel2>(Configuration configuration)
ParallelHelper.IterateRows(
this.Bounds(),
configuration,
(rows) =>
rows =>
{
for (int y = rows.Min; y < rows.Max; y++)
{
Expand Down
4 changes: 2 additions & 2 deletions src/ImageSharp/Memory/Buffer2DExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static unsafe void CopyColumns<T>(

fixed (byte* ptr = span)
{
byte* basePtr = (byte*)ptr;
byte* basePtr = ptr;
for (int y = 0; y < buffer.Height; y++)
{
byte* sPtr = basePtr + sOffset;
Expand Down Expand Up @@ -184,4 +184,4 @@ private static void CheckColumnRegionsDoNotOverlap<T>(
}
}
}
}
}
10 changes: 5 additions & 5 deletions src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System;
Expand Down Expand Up @@ -53,12 +53,12 @@ public byte[] GetData()

if (this.exifIndexes.Count > 0)
{
exifIndex = (int)this.GetIndex(this.ifdIndexes, ExifTag.SubIFDOffset);
exifIndex = this.GetIndex(this.ifdIndexes, ExifTag.SubIFDOffset);
}

if (this.gpsIndexes.Count > 0)
{
gpsIndex = (int)this.GetIndex(this.ifdIndexes, ExifTag.GPSIFDOffset);
gpsIndex = this.GetIndex(this.ifdIndexes, ExifTag.GPSIFDOffset);
}

uint ifdLength = 2 + this.GetLength(this.ifdIndexes) + 4;
Expand Down Expand Up @@ -125,7 +125,7 @@ public byte[] GetData()
i = this.WriteData(startIndex, this.gpsIndexes, result, i);
}

WriteUInt16((ushort)0, result, i);
WriteUInt16(0, result, i);

return result;
}
Expand Down Expand Up @@ -373,4 +373,4 @@ private int WriteValue(ExifValue value, Span<byte> destination, int offset)
return this.WriteValue(value.DataType, value.Value, destination, offset);
}
}
}
}
6 changes: 3 additions & 3 deletions src/ImageSharp/Primitives/ColorMatrix.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

#pragma warning disable SA1117 // Parameters should be on same line or separate lines
Expand Down Expand Up @@ -269,7 +269,7 @@ public bool IsIdentity
/// </summary>
/// <param name="value">The source matrix.</param>
/// <returns>The negated matrix.</returns>
public static unsafe ColorMatrix operator -(ColorMatrix value)
public static ColorMatrix operator -(ColorMatrix value)
{
ColorMatrix m;

Expand Down Expand Up @@ -456,4 +456,4 @@ public override string ToString()
this.M51.ToString(ci), this.M52.ToString(ci), this.M53.ToString(ci), this.M54.ToString(ci));
}
}
}
}
4 changes: 2 additions & 2 deletions src/ImageSharp/Processing/KnownFilterMatrices.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System;
Expand Down Expand Up @@ -141,7 +141,7 @@ public static class KnownFilterMatrices
/// <summary>
/// Gets an approximated black and white filter
/// </summary>
public static ColorMatrix BlackWhiteFilter { get; } = new ColorMatrix()
public static ColorMatrix BlackWhiteFilter { get; } = new ColorMatrix
{
M11 = 1.5F,
M12 = 1.5F,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle source
Parallel.For(
0,
tileYStartPositions.Count,
new ParallelOptions() { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism },
new ParallelOptions { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism },
index =>
{
int cdfX = 0;
Expand Down Expand Up @@ -470,7 +470,7 @@ public void CalculateLookupTables(ImageFrame<TPixel> source, HistogramEqualizati
Parallel.For(
0,
this.tileYStartPositions.Count,
new ParallelOptions() { MaxDegreeOfParallelism = this.configuration.MaxDegreeOfParallelism },
new ParallelOptions { MaxDegreeOfParallelism = this.configuration.MaxDegreeOfParallelism },
index =>
{
int cdfX = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle source
{
MemoryAllocator memoryAllocator = configuration.MemoryAllocator;

var parallelOptions = new ParallelOptions() { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism };
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism };
int tileWidth = source.Width / this.Tiles;
int tileHeight = tileWidth;
int pixelInTile = tileWidth * tileHeight;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

// ReSharper disable InconsistentNaming
Expand All @@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg.BlockOperations
{
public class Block8x8F_Round
{
private Block8x8F block = default(Block8x8F);
private Block8x8F block;

[GlobalSetup]
public void Setup()
Expand Down Expand Up @@ -66,4 +66,4 @@ public void SimdRound()
row7 = SimdUtils.FastRound(row7);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using BenchmarkDotNet.Attributes;
Expand Down Expand Up @@ -42,7 +42,7 @@ public void ParseStreamPdfJs()
{
using (var memoryStream = new MemoryStream(this.jpegBytes))
{
var decoder = new JpegDecoderCore(Configuration.Default, new Formats.Jpeg.JpegDecoder() { IgnoreMetadata = true });
var decoder = new JpegDecoderCore(Configuration.Default, new Formats.Jpeg.JpegDecoder { IgnoreMetadata = true });
decoder.ParseStream(memoryStream);
decoder.Dispose();
}
Expand All @@ -65,4 +65,4 @@ public void ParseStreamPdfJs()
// | 'System.Drawing FULL' | Core | Core | Jpg/b(...)f.jpg [28] | 17.68 ms | 2.711 ms | 0.1486 ms | 1.00 | 0.00 | 343.7500 | - | - | 757.04 KB |
// | JpegDecoderCore.ParseStream | Core | Core | Jpg/b(...)f.jpg [28] | 14.27 ms | 3.671 ms | 0.2012 ms | 0.81 | 0.00 | - | - | - | 11.76 KB |
}
}
}
Loading