Browse Source

Add xml docs for new functionality

pull/20/head
James Jackson-South 9 years ago
parent
commit
91c3835a3b
  1. 2
      Settings.StyleCop
  2. 13
      src/ImageSharp/Colors/ColorPixelAccessor.cs
  3. 23
      src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
  4. 21
      src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs
  5. 77
      src/ImageSharp/Image/PixelAccessor.cs

2
Settings.StyleCop

@ -24,6 +24,8 @@
<Value>codeword</Value>
<Value>unscaled</Value>
<Value>zig-zag</Value>
<Value>crc</Value>
<Value>zlib</Value>
</CollectionProperty>
</GlobalSettings>
<Analyzers>

13
src/ImageSharp/Colors/ColorPixelAccessor.cs

@ -8,13 +8,21 @@ namespace ImageSharp
using System;
using System.Runtime.CompilerServices;
public unsafe sealed class ColorPixelAccessor : PixelAccessor<Color, uint>
/// <summary>
/// An optimized pixel accessor for the <see cref="Image"/> class.
/// </summary>
public sealed unsafe class ColorPixelAccessor : PixelAccessor<Color, uint>
{
/// <summary>
/// Initializes a new instance of the <see cref="ColorPixelAccessor"/> class.
/// </summary>
/// <param name="image">The image to provide pixel access for.</param>
public ColorPixelAccessor(ImageBase<Color, uint> image)
: base(image)
{
}
/// <inheritdoc />
protected override void CopyFromBGR(PixelRow<Color, uint> row, int targetY, int width)
{
byte* source = row.DataPointer;
@ -29,6 +37,7 @@ namespace ImageSharp
}
}
/// <inheritdoc />
protected override void CopyFromBGRA(PixelRow<Color, uint> row, int targetY, int width)
{
byte* source = row.DataPointer;
@ -43,6 +52,7 @@ namespace ImageSharp
}
}
/// <inheritdoc />
protected override void CopyToBGR(PixelRow<Color, uint> row, int sourceY, int width)
{
byte* source = this.GetRowPointer(sourceY);
@ -68,6 +78,7 @@ namespace ImageSharp
}
}
/// <inheritdoc />
protected override void CopyToBGRA(PixelRow<Color, uint> row, int sourceY, int width)
{
byte* source = this.GetRowPointer(sourceY);

23
src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs

@ -2,7 +2,6 @@
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats
{
using System;
@ -134,19 +133,19 @@ namespace ImageSharp.Formats
if (this.infoHeader.BitsPerPixel == 32)
{
this.ReadRgb32<TColor, TPacked>(pixels, this.infoHeader.Width, this.infoHeader.Height, inverted);
this.ReadRgb32(pixels, this.infoHeader.Width, this.infoHeader.Height, inverted);
}
else if (this.infoHeader.BitsPerPixel == 24)
{
this.ReadRgb24<TColor, TPacked>(pixels, this.infoHeader.Width, this.infoHeader.Height, inverted);
this.ReadRgb24(pixels, this.infoHeader.Width, this.infoHeader.Height, inverted);
}
else if (this.infoHeader.BitsPerPixel == 16)
{
this.ReadRgb16<TColor, TPacked>(pixels, this.infoHeader.Width, this.infoHeader.Height, inverted);
this.ReadRgb16(pixels, this.infoHeader.Width, this.infoHeader.Height, inverted);
}
else if (this.infoHeader.BitsPerPixel <= 8)
{
this.ReadRgbPalette<TColor, TPacked>(pixels, palette, this.infoHeader.Width, this.infoHeader.Height, this.infoHeader.BitsPerPixel, inverted);
this.ReadRgbPalette(pixels, palette, this.infoHeader.Width, this.infoHeader.Height, this.infoHeader.BitsPerPixel, inverted);
}
break;
@ -184,7 +183,15 @@ namespace ImageSharp.Formats
return row;
}
private static int CalculatPadding(int width, int componentCount)
/// <summary>
/// Calculates the amount of bytes to pad a row.
/// </summary>
/// <param name="width">The image width.</param>
/// <param name="componentCount">The pixel component count.</param>
/// <returns>
/// The <see cref="int"/>.
/// </returns>
private static int CalculatePadding(int width, int componentCount)
{
int padding = (width * componentCount) % 4;
@ -312,7 +319,7 @@ namespace ImageSharp.Formats
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct
{
int padding = CalculatPadding(width, 3);
int padding = CalculatePadding(width, 3);
using (PixelRow<TColor, TPacked> row = new PixelRow<TColor, TPacked>(width, ComponentOrder.BGR, padding))
{
for (int y = 0; y < height; y++)
@ -338,7 +345,7 @@ namespace ImageSharp.Formats
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct
{
int padding = CalculatPadding(width, 4);
int padding = CalculatePadding(width, 4);
using (PixelRow<TColor, TPacked> row = new PixelRow<TColor, TPacked>(width, ComponentOrder.BGRA, padding))
{
for (int y = 0; y < height; y++)

21
src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs

@ -14,6 +14,11 @@ namespace ImageSharp.Formats
/// </summary>
internal sealed class ZlibInflateStream : Stream
{
/// <summary>
/// The raw stream containing the uncompressed image data.
/// </summary>
private readonly Stream rawStream;
/// <summary>
/// A value indicating whether this instance of the given entity has been disposed.
/// </summary>
@ -27,19 +32,23 @@ namespace ImageSharp.Formats
/// </remarks>
private bool isDisposed;
/// <summary>
/// The raw stream containing the uncompressed image data.
/// </summary>
private readonly Stream rawStream;
/// <summary>
/// The read crc data.
/// </summary>
private byte[] crcread;
// The stream responsible for decompressing the input stream.
/// <summary>
/// The stream responsible for decompressing the input stream.
/// </summary>
private DeflateStream deflateStream;
/// <summary>
/// Initializes a new instance of the <see cref="ZlibInflateStream"/> class.
/// </summary>
/// <param name="stream">The stream.</param>
/// <exception cref="Exception">
/// Thrown if the compression method is incorrect.
/// </exception>
public ZlibInflateStream(Stream stream)
{
// The DICT dictionary identifier identifying the used dictionary.

77
src/ImageSharp/Image/PixelAccessor.cs

@ -101,7 +101,7 @@ namespace ImageSharp
/// </summary>
/// <param name="x">The x-coordinate of the pixel. Must be greater than zero and smaller than the width of the pixel.</param>
/// <param name="y">The y-coordinate of the pixel. Must be greater than zero and smaller than the width of the pixel.</param>
/// <returns>The <see cref="TColor"/> at the specified position.</returns>
/// <returns>The <see typeparam="TColor"/> at the specified position.</returns>
public TColor this[int x, int y]
{
get { return Unsafe.Read<TColor>(this.pixelsBase + (((y * this.Width) + x) * Unsafe.SizeOf<TColor>())); }
@ -136,6 +136,14 @@ namespace ImageSharp
this.CopyBlock(0, 0, target, 0, 0, target.Width * target.Height);
}
/// <summary>
/// Copied a row of pixels from the image.
/// </summary>
/// <param name="row">The row.</param>
/// <param name="targetY">The target row index.</param>
/// <exception cref="NotSupportedException">
/// Thrown when an unsupported component order value is passed.
/// </exception>
public void CopyFrom(PixelRow<TColor, TPacked> row, int targetY)
{
switch (row.ComponentOrder)
@ -153,10 +161,18 @@ namespace ImageSharp
this.CopyFromRGBA(row, targetY, Math.Min(row.Width, this.Width));
break;
default:
throw new NotSupportedException();
throw new NotSupportedException();
}
}
/// <summary>
/// Copied a row of pixels to the image.
/// </summary>
/// <param name="row">The row.</param>
/// <param name="sourceY">The source row index.</param>
/// <exception cref="NotSupportedException">
/// Thrown when an unsupported component order value is passed.
/// </exception>
public void CopyTo(PixelRow<TColor, TPacked> row, int sourceY)
{
switch (row.ComponentOrder)
@ -174,7 +190,7 @@ namespace ImageSharp
this.CopyToRGBA(row, sourceY, Math.Min(row.Width, this.Width));
break;
default:
throw new NotSupportedException();
throw new NotSupportedException();
}
}
@ -207,6 +223,12 @@ namespace ImageSharp
GC.SuppressFinalize(this);
}
/// <summary>
/// Copies from a row in <see cref="ComponentOrder.BGR"/> format.
/// </summary>
/// <param name="row">The row.</param>
/// <param name="targetY">The target row index.</param>
/// <param name="width">The width.</param>
protected virtual void CopyFromBGR(PixelRow<TColor, TPacked> row, int targetY, int width)
{
byte* source = row.DataPointer;
@ -225,6 +247,12 @@ namespace ImageSharp
}
}
/// <summary>
/// Copies from a row in <see cref="ComponentOrder.BGRA"/> format.
/// </summary>
/// <param name="row">The row.</param>
/// <param name="targetY">The target row index.</param>
/// <param name="width">The width.</param>
protected virtual void CopyFromBGRA(PixelRow<TColor, TPacked> row, int targetY, int width)
{
byte* source = row.DataPointer;
@ -243,6 +271,12 @@ namespace ImageSharp
}
}
/// <summary>
/// Copies from a row in <see cref="ComponentOrder.RGB"/> format.
/// </summary>
/// <param name="row">The row.</param>
/// <param name="targetY">The target row index.</param>
/// <param name="width">The width.</param>
protected virtual void CopyFromRGB(PixelRow<TColor, TPacked> row, int targetY, int width)
{
byte* source = row.DataPointer;
@ -261,6 +295,12 @@ namespace ImageSharp
}
}
/// <summary>
/// Copies from a row in <see cref="ComponentOrder.RGBA"/> format.
/// </summary>
/// <param name="row">The row.</param>
/// <param name="targetY">The target row index.</param>
/// <param name="width">The width.</param>
protected virtual void CopyFromRGBA(PixelRow<TColor, TPacked> row, int targetY, int width)
{
byte* source = row.DataPointer;
@ -279,6 +319,12 @@ namespace ImageSharp
}
}
/// <summary>
/// Copies to a row in <see cref="ComponentOrder.RGBA"/> format.
/// </summary>
/// <param name="row">The row.</param>
/// <param name="sourceY">The target row index.</param>
/// <param name="width">The width.</param>
protected virtual void CopyToBGR(PixelRow<TColor, TPacked> row, int sourceY, int width)
{
int offset = 0;
@ -289,6 +335,12 @@ namespace ImageSharp
}
}
/// <summary>
/// Copies to a row in <see cref="ComponentOrder.BGRA"/> format.
/// </summary>
/// <param name="row">The row.</param>
/// <param name="sourceY">The target row index.</param>
/// <param name="width">The width.</param>
protected virtual void CopyToBGRA(PixelRow<TColor, TPacked> row, int sourceY, int width)
{
int offset = 0;
@ -299,6 +351,12 @@ namespace ImageSharp
}
}
/// <summary>
/// Copies to a row in <see cref="ComponentOrder.RGB"/> format.
/// </summary>
/// <param name="row">The row.</param>
/// <param name="sourceY">The target row index.</param>
/// <param name="width">The width.</param>
protected virtual void CopyToRGB(PixelRow<TColor, TPacked> row, int sourceY, int width)
{
int offset = 0;
@ -309,6 +367,12 @@ namespace ImageSharp
}
}
/// <summary>
/// Copies to a row in <see cref="ComponentOrder.RGBA"/> format.
/// </summary>
/// <param name="row">The row.</param>
/// <param name="sourceY">The target row index.</param>
/// <param name="width">The width.</param>
protected virtual void CopyToRGBA(PixelRow<TColor, TPacked> row, int sourceY, int width)
{
int offset = 0;
@ -319,6 +383,13 @@ namespace ImageSharp
}
}
/// <summary>
/// Gets the pointer at the specified row.
/// </summary>
/// <param name="targetY">The target row index.</param>
/// <returns>
/// The <see cref="T:byte*"/>.
/// </returns>
protected byte* GetRowPointer(int targetY)
{
return this.pixelsBase + ((targetY * this.Width) * Unsafe.SizeOf<TColor>());

Loading…
Cancel
Save