Browse Source

A little sanitation

af/merge-core
James Jackson-South 9 years ago
parent
commit
8b8ea351a2
  1. 18
      src/ImageSharp.Formats.Bmp/BmpEncoderCore.cs
  2. 8
      src/ImageSharp.Formats.Jpeg/JpegDecoderCore.cs
  3. 1
      src/ImageSharp.Formats.Jpeg/JpegEncoderCore.cs
  4. 1
      src/ImageSharp/Image/ImageBase{TColor}.cs

18
src/ImageSharp.Formats.Bmp/BmpEncoderCore.cs

@ -34,7 +34,7 @@ namespace ImageSharp.Formats
/// <param name="bitsPerPixel">The <see cref="BmpBitsPerPixel"/></param> /// <param name="bitsPerPixel">The <see cref="BmpBitsPerPixel"/></param>
public void Encode<TColor>(ImageBase<TColor> image, Stream stream, BmpBitsPerPixel bitsPerPixel) public void Encode<TColor>(ImageBase<TColor> image, Stream stream, BmpBitsPerPixel bitsPerPixel)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
Guard.NotNull(image, nameof(image)); Guard.NotNull(image, nameof(image));
Guard.NotNull(stream, nameof(stream)); Guard.NotNull(stream, nameof(stream));
@ -119,23 +119,23 @@ namespace ImageSharp.Formats
/// Writes the pixel data to the binary stream. /// Writes the pixel data to the binary stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param> /// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param>
/// <param name="image"> /// <param name="image">
/// The <see cref="ImageBase{TColor}"/> containing pixel data. /// The <see cref="ImageBase{TColor}"/> containing pixel data.
/// </param> /// </param>
private void WriteImage<TColor>(EndianBinaryWriter writer, ImageBase<TColor> image) private void WriteImage<TColor>(EndianBinaryWriter writer, ImageBase<TColor> image)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
using (PixelAccessor<TColor> pixels = image.Lock()) using (PixelAccessor<TColor> pixels = image.Lock())
{ {
switch (this.bmpBitsPerPixel) switch (this.bmpBitsPerPixel)
{ {
case BmpBitsPerPixel.Pixel32: case BmpBitsPerPixel.Pixel32:
this.Write32Bit<TColor>(writer, pixels); this.Write32Bit(writer, pixels);
break; break;
case BmpBitsPerPixel.Pixel24: case BmpBitsPerPixel.Pixel24:
this.Write24Bit<TColor>(writer, pixels); this.Write24Bit(writer, pixels);
break; break;
} }
} }
@ -145,11 +145,11 @@ namespace ImageSharp.Formats
/// Writes the 32bit color palette to the stream. /// Writes the 32bit color palette to the stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param> /// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param>
/// <param name="pixels">The <see cref="PixelAccessor{TColor}"/> containing pixel data.</param> /// <param name="pixels">The <see cref="PixelAccessor{TColor}"/> containing pixel data.</param>
private void Write32Bit<TColor>(EndianBinaryWriter writer, PixelAccessor<TColor> pixels) private void Write32Bit<TColor>(EndianBinaryWriter writer, PixelAccessor<TColor> pixels)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
using (PixelArea<TColor> row = new PixelArea<TColor>(pixels.Width, ComponentOrder.Zyxw, this.padding)) using (PixelArea<TColor> row = new PixelArea<TColor>(pixels.Width, ComponentOrder.Zyxw, this.padding))
{ {
for (int y = pixels.Height - 1; y >= 0; y--) for (int y = pixels.Height - 1; y >= 0; y--)
@ -164,11 +164,11 @@ namespace ImageSharp.Formats
/// Writes the 24bit color palette to the stream. /// Writes the 24bit color palette to the stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param> /// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param>
/// <param name="pixels">The <see cref="PixelAccessor{TColor}"/> containing pixel data.</param> /// <param name="pixels">The <see cref="PixelAccessor{TColor}"/> containing pixel data.</param>
private void Write24Bit<TColor>(EndianBinaryWriter writer, PixelAccessor<TColor> pixels) private void Write24Bit<TColor>(EndianBinaryWriter writer, PixelAccessor<TColor> pixels)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
using (PixelArea<TColor> row = new PixelArea<TColor>(pixels.Width, ComponentOrder.Zyx, this.padding)) using (PixelArea<TColor> row = new PixelArea<TColor>(pixels.Width, ComponentOrder.Zyx, this.padding))
{ {
for (int y = pixels.Height - 1; y >= 0; y--) for (int y = pixels.Height - 1; y >= 0; y--)

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

@ -5,10 +5,8 @@
namespace ImageSharp.Formats namespace ImageSharp.Formats
{ {
using System; using System;
using System.Buffers;
using System.IO; using System.IO;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using ImageSharp.Formats.Jpg; using ImageSharp.Formats.Jpg;
@ -586,7 +584,7 @@ namespace ImageSharp.Formats
byte yellow = this.ycbcrImage.CrChannel.Pixels[co + (x / scale)]; byte yellow = this.ycbcrImage.CrChannel.Pixels[co + (x / scale)];
TColor packed = default(TColor); TColor packed = default(TColor);
this.PackCmyk<TColor>(ref packed, cyan, magenta, yellow, x, y); this.PackCmyk(ref packed, cyan, magenta, yellow, x, y);
pixels[x, y] = packed; pixels[x, y] = packed;
} }
}); });
@ -744,7 +742,7 @@ namespace ImageSharp.Formats
byte cr = this.ycbcrImage.CrChannel.Pixels[co + (x / scale)]; byte cr = this.ycbcrImage.CrChannel.Pixels[co + (x / scale)];
TColor packed = default(TColor); TColor packed = default(TColor);
this.PackYcck<TColor>(ref packed, yy, cb, cr, x, y); this.PackYcck(ref packed, yy, cb, cr, x, y);
pixels[x, y] = packed; pixels[x, y] = packed;
} }
}); });
@ -1037,7 +1035,7 @@ namespace ImageSharp.Formats
} }
this.InputProcessor.ReadFull(this.Temp, 0, remaining); this.InputProcessor.ReadFull(this.Temp, 0, remaining);
this.RestartInterval = ((int)this.Temp[0] << 8) + (int)this.Temp[1]; this.RestartInterval = (this.Temp[0] << 8) + this.Temp[1];
} }
/// <summary> /// <summary>

1
src/ImageSharp.Formats.Jpeg/JpegEncoderCore.cs

@ -8,7 +8,6 @@ namespace ImageSharp.Formats
using System; using System;
using System.Buffers; using System.Buffers;
using System.IO; using System.IO;
using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using ImageSharp.Formats.Jpg; using ImageSharp.Formats.Jpg;

1
src/ImageSharp/Image/ImageBase{TColor}.cs

@ -6,7 +6,6 @@
namespace ImageSharp namespace ImageSharp
{ {
using System; using System;
using System.Buffers;
using System.Diagnostics; using System.Diagnostics;
/// <summary> /// <summary>

Loading…
Cancel
Save