Browse Source

Cleanup

pull/23/head
James Jackson-South 10 years ago
parent
commit
be5b01bd75
  1. 1
      Settings.StyleCop
  2. 20
      src/ImageSharp/Common/Extensions/StreamExtensions.cs
  3. 3
      src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs
  4. 1
      src/ImageSharp/Formats/Png/Filters/AverageFilter.cs
  5. 1
      src/ImageSharp/Formats/Png/Filters/NoneFilter.cs
  6. 1
      src/ImageSharp/Formats/Png/Filters/PaethFilter.cs
  7. 1
      src/ImageSharp/Formats/Png/Filters/SubFilter.cs
  8. 3
      src/ImageSharp/Formats/Png/Filters/UpFilter.cs
  9. 3
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  10. 3
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  11. 26
      src/ImageSharp/IO/EndianBinaryWriter.cs
  12. 2
      src/ImageSharp/Image/Image.cs
  13. 15
      src/ImageSharp/Numerics/Ellipse.cs
  14. 8
      src/ImageSharp/Profiles/Exif/ExifReader.cs
  15. 3
      src/ImageSharp/Profiles/Exif/ExifTag.cs
  16. 38
      src/ImageSharp/Samplers/Options/Orientation.cs
  17. 2
      src/ImageSharp/Samplers/Processors/RotateProcessor.cs
  18. 22
      src/ImageSharp/Samplers/Processors/SkewProcessor.cs

1
Settings.StyleCop

@ -33,6 +33,7 @@
<Value>pp</Value>
<Value>cmyk</Value>
<Value>Paeth</Value>
<Value>th</Value>
</CollectionProperty>
</GlobalSettings>
<Analyzers>

20
src/ImageSharp/Common/Extensions/StreamExtensions.cs

@ -5,10 +5,19 @@
namespace ImageSharp
{
using System.Buffers;
using System.IO;
/// <summary>
/// Extension methods for the <see cref="Stream"/> type.
/// </summary>
internal static class StreamExtensions
{
/// <summary>
/// Skips the number of bytes in the given stream.
/// </summary>
/// <param name="stream">The stream.</param>
/// <param name="count">The count.</param>
public static void Skip(this Stream stream, int count)
{
if (count < 1)
@ -22,8 +31,15 @@ namespace ImageSharp
}
else
{
byte[] foo = new byte[count];
stream.Read(foo, 0, count);
byte[] foo = ArrayPool<byte>.Shared.Rent(count);
try
{
stream.Read(foo, 0, count);
}
finally
{
ArrayPool<byte>.Shared.Return(foo);
}
}
}
}

3
src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs

@ -246,7 +246,6 @@ namespace ImageSharp.Formats
/// <summary>
/// The AC luminance huffman table index
/// </summary>
LuminanceAC = 1,
// ReSharper restore UnusedMember.Local
@ -851,6 +850,7 @@ namespace ImageSharp.Formats
Block b = new Block();
Block cb = new Block();
Block cr = new Block();
// ReSharper disable once InconsistentNaming
int prevDCY = 0, prevDCCb = 0, prevDCCr = 0;
@ -880,6 +880,7 @@ namespace ImageSharp.Formats
Block b = new Block();
Block[] cb = new Block[4];
Block[] cr = new Block[4];
// ReSharper disable once InconsistentNaming
int prevDCY = 0, prevDCCb = 0, prevDCCr = 0;

1
src/ImageSharp/Formats/Png/Filters/AverageFilter.cs

@ -49,6 +49,7 @@ namespace ImageSharp.Formats
/// </summary>
/// <param name="scanline">The scanline to encode</param>
/// <param name="previousScanline">The previous scanline.</param>
/// <param name="result">The encoded scanline.</param>
/// <param name="bytesPerPixel">The bytes per pixel.</param>
/// <param name="bytesPerScanline">The number of bytes per scanline</param>
/// <returns>The <see cref="T:byte[]"/></returns>

1
src/ImageSharp/Formats/Png/Filters/NoneFilter.cs

@ -29,6 +29,7 @@ namespace ImageSharp.Formats
/// Encodes the scanline
/// </summary>
/// <param name="scanline">The scanline to encode</param>
/// <param name="result">The encoded scanline.</param>
/// <param name="bytesPerScanline">The number of bytes per scanline</param>
public static void Encode(byte[] scanline, byte[] result, int bytesPerScanline)
{

1
src/ImageSharp/Formats/Png/Filters/PaethFilter.cs

@ -49,6 +49,7 @@ namespace ImageSharp.Formats
/// </summary>
/// <param name="scanline">The scanline to encode</param>
/// <param name="previousScanline">The previous scanline.</param>
/// <param name="result">The encoded scanline.</param>
/// <param name="bytesPerPixel">The bytes per pixel.</param>
/// <param name="bytesPerScanline">The number of bytes per scanline</param>
/// <returns>The <see cref="T:byte[]"/></returns>

1
src/ImageSharp/Formats/Png/Filters/SubFilter.cs

@ -41,6 +41,7 @@ namespace ImageSharp.Formats
/// Encodes the scanline
/// </summary>
/// <param name="scanline">The scanline to encode</param>
/// <param name="result">The encoded scanline.</param>
/// <param name="bytesPerPixel">The bytes per pixel.</param>
/// <param name="bytesPerScanline">The number of bytes per scanline</param>
/// <returns>The <see cref="T:byte[]"/></returns>

3
src/ImageSharp/Formats/Png/Filters/UpFilter.cs

@ -42,8 +42,9 @@ namespace ImageSharp.Formats
/// Encodes the scanline
/// </summary>
/// <param name="scanline">The scanline to encode</param>
/// <param name="bytesPerScanline">The number of bytes per scanline</param>
/// <param name="previousScanline">The previous scanline.</param>
/// <param name="result">The encoded scanline.</param>
/// <param name="bytesPerScanline">The number of bytes per scanline</param>
/// <returns>The <see cref="T:byte[]"/></returns>
public static byte[] Encode(byte[] scanline, byte[] previousScanline, byte[] result, int bytesPerScanline)
{

3
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -284,7 +284,7 @@ namespace ImageSharp.Formats
byte[] defilteredScanline;
// TODO: It would be good if we can reduce the memory usage here - Each filter is creating a new row.
// Every time I try to use the same approach as I have in the encoder though I keep messing up.
// Every time I try to use the same approach as I have in the encoder though I keep messing up.
// Fingers crossed someone with a big brain and a kind heart will come along and finish optimizing this for me.
switch (filterType)
{
@ -592,6 +592,7 @@ namespace ImageSharp.Formats
/// <param name="chunk">The chunk.</param>
private void ReadChunkData(PngChunk chunk)
{
// TODO: It might be possible to rent this but that could also lead to issues assigning the data to various properties
chunk.Data = new byte[chunk.Length];
this.currentStream.Read(chunk.Data, 0, chunk.Length);
}

3
src/ImageSharp/Formats/Png/PngEncoderCore.cs

@ -34,7 +34,6 @@ namespace ImageSharp.Formats
/// </summary>
private readonly byte[] chunkDataBuffer = new byte[16];
/// <summary>
/// Contains the raw pixel data from an indexed image.
/// </summary>
@ -626,7 +625,7 @@ namespace ImageSharp.Formats
memoryStream?.Dispose();
}
// Store the chunks in repeated 64k blocks.
// Store the chunks in repeated 64k blocks.
// This reduces the memory load for decoding the image for many decoders.
int numChunks = bufferLength / MaxBlockSize;

26
src/ImageSharp/IO/EndianBinaryWriter.cs

@ -346,6 +346,19 @@ namespace ImageSharp.IO
this.BaseStream.Write(this.buffer, 0, index);
}
/// <summary>
/// Disposes of the underlying stream.
/// </summary>
public void Dispose()
{
if (!this.disposed)
{
this.Flush();
this.disposed = true;
((IDisposable)this.BaseStream).Dispose();
}
}
/// <summary>
/// Checks whether or not the writer has been disposed, throwing an exception if so.
/// </summary>
@ -368,18 +381,5 @@ namespace ImageSharp.IO
this.CheckDisposed();
this.BaseStream.Write(bytes, 0, length);
}
/// <summary>
/// Disposes of the underlying stream.
/// </summary>
public void Dispose()
{
if (!this.disposed)
{
this.Flush();
this.disposed = true;
((IDisposable)this.BaseStream).Dispose();
}
}
}
}

2
src/ImageSharp/Image/Image.cs

@ -191,6 +191,7 @@ namespace ImageSharp
/// </summary>
/// <param name="stream">The stream to save the image to.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>The <see cref="Image{TColor,TPacked}"/></returns>
public Image<TColor, TPacked> Save(Stream stream)
{
Guard.NotNull(stream, nameof(stream));
@ -204,6 +205,7 @@ namespace ImageSharp
/// <param name="stream">The stream to save the image to.</param>
/// <param name="format">The format to save the image as.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>The <see cref="Image{TColor,TPacked}"/></returns>
public Image<TColor, TPacked> Save(Stream stream, IImageFormat format)
{
Guard.NotNull(stream, nameof(stream));

15
src/ImageSharp/Numerics/Ellipse.cs

@ -9,18 +9,27 @@ namespace ImageSharp
using System.ComponentModel;
using System.Numerics;
/// <summary>
/// Represents an ellipse.
/// </summary>
public struct Ellipse : IEquatable<Ellipse>
{
/// <summary>
/// Represents a <see cref="Ellipse"/> that has X and Y values set to zero.
/// </summary>
public static readonly Ellipse Empty = default(Ellipse);
/// <summary>
/// The center point.
/// </summary>
private Point center;
/// <summary>
/// Represents a <see cref="Ellipse"/> that has X and Y values set to zero.
/// Initializes a new instance of the <see cref="Ellipse"/> struct.
/// </summary>
public static readonly Ellipse Empty = default(Ellipse);
/// <param name="center">The center point.</param>
/// <param name="radiusX">The x-radius.</param>
/// <param name="radiusY">The y-radius.</param>
public Ellipse(Point center, float radiusX, float radiusY)
{
this.center = center;

8
src/ImageSharp/Profiles/Exif/ExifReader.cs

@ -112,8 +112,16 @@ namespace ImageSharp
return result;
}
/// <summary>
/// Gets the invalid tags.
/// </summary>
public IEnumerable<ExifTag> InvalidTags => this.invalidTags;
/// <summary>
/// Adds the collection of EXIF values to the reader.
/// </summary>
/// <param name="values">The values.</param>
/// <param name="index">The index.</param>
private void AddValues(Collection<ExifValue> values, uint index)
{
this.currentIndex = this.startIndex + index;

3
src/ImageSharp/Profiles/Exif/ExifTag.cs

@ -3,12 +3,11 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
// Descriptions from: http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html
namespace ImageSharp
{
/// <summary>
/// All exif tags from the Exif standard 2.2
/// Descriptions from: <see href="http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html"/>
/// </summary>
public enum ExifTag
{

38
src/ImageSharp/Samplers/Options/Orientation.cs

@ -5,16 +5,54 @@
namespace ImageSharp
{
/// <summary>
/// Enumerates the available orientation values supplied by EXIF metadata.
/// </summary>
internal enum Orientation : ushort
{
/// <summary>
/// Unknown rotation.
/// </summary>
Unknown = 0,
/// <summary>
/// The 0th row at the top, the 0th column on the left.
/// </summary>
TopLeft = 1,
/// <summary>
/// The 0th row at the top, the 0th column on the right.
/// </summary>
TopRight = 2,
/// <summary>
/// The 0th row at the bottom, the 0th column on the right.
/// </summary>
BottomRight = 3,
/// <summary>
/// The 0th row at the bottom, the 0th column on the left.
/// </summary>
BottomLeft = 4,
/// <summary>
/// The 0th row on the left, the 0th column at the top.
/// </summary>
LeftTop = 5,
/// <summary>
/// The 0th row at the right, the 0th column at the top.
/// </summary>
RightTop = 6,
/// <summary>
/// The 0th row on the right, the 0th column at the bottom.
/// </summary>
RightBottom = 7,
/// <summary>
/// The 0th row on the left, the 0th column at the bottom.
/// </summary>
LeftBottom = 8
}
}

2
src/ImageSharp/Samplers/Processors/RotateProcessor.cs

@ -88,7 +88,7 @@ namespace ImageSharp.Processors
/// </summary>
/// <param name="target">The target image.</param>
/// <param name="source">The source image.</param>
/// <returns></returns>
/// <returns>The <see cref="bool"/></returns>
private bool OptimizedApply(ImageBase<TColor, TPacked> target, ImageBase<TColor, TPacked> source)
{
const float Epsilon = .0001F;

22
src/ImageSharp/Samplers/Processors/SkewProcessor.cs

@ -19,7 +19,7 @@ namespace ImageSharp.Processors
where TPacked : struct
{
/// <summary>
/// The tranform matrix to apply.
/// The transform matrix to apply.
/// </summary>
private Matrix3x2 processMatrix;
@ -38,16 +38,6 @@ namespace ImageSharp.Processors
/// </summary>
public bool Expand { get; set; } = true;
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> target, ImageBase<TColor, TPacked> source, Rectangle targetRectangle, Rectangle sourceRectangle)
{
this.processMatrix = Point.CreateSkew(new Point(0, 0), -this.AngleX, -this.AngleY);
if (this.Expand)
{
CreateNewTarget(target, sourceRectangle, this.processMatrix);
}
}
/// <inheritdoc/>
public override void Apply(ImageBase<TColor, TPacked> target, ImageBase<TColor, TPacked> source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
@ -75,5 +65,15 @@ namespace ImageSharp.Processors
});
}
}
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> target, ImageBase<TColor, TPacked> source, Rectangle targetRectangle, Rectangle sourceRectangle)
{
this.processMatrix = Point.CreateSkew(new Point(0, 0), -this.AngleX, -this.AngleY);
if (this.Expand)
{
CreateNewTarget(target, sourceRectangle, this.processMatrix);
}
}
}
}
Loading…
Cancel
Save