Browse Source

Some minor cleanup

af/merge-core
James Jackson-South 9 years ago
parent
commit
fa221f144d
  1. 17
      src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs
  2. 6
      src/ImageSharp/Formats/Jpg/Utils/JpegUtils.cs
  3. 16
      src/ImageSharp/Image/PixelAccessor{TColor}.cs
  4. 27
      src/ImageSharp/Image/PixelArea{TColor}.cs
  5. 14
      src/ImageSharp/PixelAccessor.cs

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

@ -2,6 +2,7 @@
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats
{
using System;
@ -230,18 +231,24 @@ namespace ImageSharp.Formats
/// Writes data to "Define Quantization Tables" block for QuantIndex
/// </summary>
/// <param name="dqt">The "Define Quantization Tables" block</param>
/// <param name="offset">Offset in dqt</param>
/// <param name="offset">Offset in "Define Quantization Tables" block</param>
/// <param name="i">The quantization index</param>
/// <param name="q">The quantazation table to copy data from</param>
private static void WriteDataToDqt(byte[] dqt, ref int offset, QuantIndex i, ref Block8x8F q)
/// <param name="quant">The quantization table to copy data from</param>
private static void WriteDataToDqt(byte[] dqt, ref int offset, QuantIndex i, ref Block8x8F quant)
{
dqt[offset++] = (byte)i;
for (int j = 0; j < Block8x8F.ScalarCount; j++)
{
dqt[offset++] = (byte)q[j];
dqt[offset++] = (byte)quant[j];
}
}
/// <summary>
/// Initializes quantization table.
/// </summary>
/// <param name="i">The quantization index.</param>
/// <param name="scale">The scaling factor.</param>
/// <param name="quant">The quantization table.</param>
private static void InitQuantizationTable(int i, int scale, ref Block8x8F quant)
{
for (int j = 0; j < Block8x8F.ScalarCount; j++)
@ -517,7 +524,7 @@ namespace ImageSharp.Formats
/// <param name="tempDest">Temporal block to be used as FDCT Destination</param>
/// <param name="temp2">Temporal block 2</param>
/// <param name="quant">Quantization table</param>
/// <param name="unzigPtr">The 8x8 Unzig block ptr</param>
/// <param name="unzigPtr">The 8x8 Unzig block pointer</param>
/// <returns>
/// The <see cref="int"/>
/// </returns>

6
src/ImageSharp/Formats/Jpg/Utils/JpegUtils.cs

@ -93,7 +93,7 @@ namespace ImageSharp.Formats.Jpg
for (int y = 0; y < fromY; y++)
{
byte* ptrBase = (byte*)area.DataPointer + (y * area.RowByteCount);
byte* ptrBase = (byte*)area.DataPointer + (y * area.RowStride);
for (int x = fromX; x < area.Width; x++)
{
@ -106,8 +106,8 @@ namespace ImageSharp.Formats.Jpg
for (int y = fromY; y < area.Height; y++)
{
byte* currBase = (byte*)area.DataPointer + (y * area.RowByteCount);
byte* prevBase = (byte*)area.DataPointer + ((y - 1) * area.RowByteCount);
byte* currBase = (byte*)area.DataPointer + (y * area.RowStride);
byte* prevBase = (byte*)area.DataPointer + ((y - 1) * area.RowStride);
for (int x = 0; x < area.Width; x++)
{

16
src/ImageSharp/Image/PixelAccessor{TColor}.cs

@ -292,7 +292,7 @@ namespace ImageSharp
for (int y = 0; y < height; y++)
{
byte* source = area.PixelBase + (y * area.RowByteCount);
byte* source = area.PixelBase + (y * area.RowStride);
byte* destination = this.GetRowPointer(targetX, targetY + y);
for (int x = 0; x < width; x++)
@ -321,7 +321,7 @@ namespace ImageSharp
for (int y = 0; y < height; y++)
{
byte* source = area.PixelBase + (y * area.RowByteCount);
byte* source = area.PixelBase + (y * area.RowStride);
byte* destination = this.GetRowPointer(targetX, targetY + y);
for (int x = 0; x < width; x++)
@ -350,7 +350,7 @@ namespace ImageSharp
for (int y = 0; y < height; y++)
{
byte* source = area.PixelBase + (y * area.RowByteCount);
byte* source = area.PixelBase + (y * area.RowStride);
byte* destination = this.GetRowPointer(targetX, targetY + y);
for (int x = 0; x < width; x++)
@ -379,7 +379,7 @@ namespace ImageSharp
for (int y = 0; y < height; y++)
{
byte* source = area.PixelBase + (y * area.RowByteCount);
byte* source = area.PixelBase + (y * area.RowStride);
byte* destination = this.GetRowPointer(targetX, targetY + y);
for (int x = 0; x < width; x++)
@ -405,7 +405,7 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
int offset = y * area.RowByteCount;
int offset = y * area.RowStride;
for (int x = 0; x < width; x++)
{
this[sourceX + x, sourceY + y].ToBytes(area.Bytes, offset, ComponentOrder.ZYX);
@ -426,7 +426,7 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
int offset = y * area.RowByteCount;
int offset = y * area.RowStride;
for (int x = 0; x < width; x++)
{
this[sourceX + x, sourceY + y].ToBytes(area.Bytes, offset, ComponentOrder.ZYXW);
@ -447,7 +447,7 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
int offset = y * area.RowByteCount;
int offset = y * area.RowStride;
for (int x = 0; x < width; x++)
{
this[sourceX + x, sourceY + y].ToBytes(area.Bytes, offset, ComponentOrder.XYZ);
@ -468,7 +468,7 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
int offset = y * area.RowByteCount;
int offset = y * area.RowStride;
for (int x = 0; x < width; x++)
{
this[sourceX + x, sourceY + y].ToBytes(area.Bytes, offset, ComponentOrder.XYZW);

27
src/ImageSharp/Image/PixelArea{TColor}.cs

@ -75,7 +75,7 @@ namespace ImageSharp
this.Width = width;
this.Height = height;
this.ComponentOrder = componentOrder;
this.RowByteCount = width * GetComponentCount(componentOrder);
this.RowStride = width * GetComponentCount(componentOrder);
this.Bytes = bytes;
this.pixelsHandle = GCHandle.Alloc(this.Bytes, GCHandleType.Pinned);
@ -132,9 +132,9 @@ namespace ImageSharp
this.Width = width;
this.Height = height;
this.ComponentOrder = componentOrder;
this.RowByteCount = (width * GetComponentCount(componentOrder)) + padding;
this.RowStride = (width * GetComponentCount(componentOrder)) + padding;
int bufferSize = this.RowByteCount * height;
int bufferSize = this.RowStride * height;
if (usePool)
{
@ -188,9 +188,9 @@ namespace ImageSharp
public byte* PixelBase { get; private set; }
/// <summary>
/// Gets number of bytes in a row.
/// Gets the width of one row in the number of bytes.
/// </summary>
public int RowByteCount { get; }
public int RowStride { get; }
/// <summary>
/// Gets the width.
@ -201,6 +201,7 @@ namespace ImageSharp
/// Gets the pool used to rent <see cref="Bytes"/>, when it's not coming from an external source
/// </summary>
// ReSharper disable once StaticMemberInGenericType
// TODO: Use own pool?
private static ArrayPool<byte> BytesPool => ArrayPool<byte>.Shared;
/// <summary>
@ -234,7 +235,7 @@ namespace ImageSharp
/// </summary>
internal void Reset()
{
Unsafe.InitBlock(this.PixelBase, 0, (uint)(this.RowByteCount * this.Height));
Unsafe.InitBlock(this.PixelBase, 0, (uint)(this.RowStride * this.Height));
}
/// <summary>
@ -262,6 +263,16 @@ namespace ImageSharp
throw new NotSupportedException();
}
/// <summary>
/// Checks that the length of the byte array to ensure that it matches the given width and height.
/// </summary>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <param name="bytes">The byte array.</param>
/// <param name="componentOrder">The component order.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown if the byte array is th incorrect length.
/// </exception>
[Conditional("DEBUG")]
private void CheckBytesLength(int width, int height, byte[] bytes, ComponentOrder componentOrder)
{
@ -274,6 +285,10 @@ namespace ImageSharp
}
}
/// <summary>
/// Disposes the object and frees resources for the Garbage Collector.
/// </summary>
/// <param name="disposing">If true, the object gets disposed.</param>
private void Dispose(bool disposing)
{
if (this.isDisposed)

14
src/ImageSharp/PixelAccessor.cs

@ -28,7 +28,7 @@ namespace ImageSharp
for (int y = 0; y < height; y++)
{
byte* source = area.PixelBase + (y * area.RowByteCount);
byte* source = area.PixelBase + (y * area.RowStride);
byte* destination = this.GetRowPointer(targetX, targetY + y);
Unsafe.CopyBlock(destination, source, byteCount);
@ -40,7 +40,7 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
byte* source = area.PixelBase + (y * area.RowByteCount);
byte* source = area.PixelBase + (y * area.RowStride);
byte* destination = this.GetRowPointer(targetX, targetY + y);
for (int x = 0; x < width; x++)
@ -58,7 +58,7 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
byte* source = area.PixelBase + (y * area.RowByteCount);
byte* source = area.PixelBase + (y * area.RowStride);
byte* destination = this.GetRowPointer(targetX, targetY + y);
for (int x = 0; x < width; x++)
@ -76,7 +76,7 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
byte* source = area.PixelBase + (y * area.RowByteCount);
byte* source = area.PixelBase + (y * area.RowStride);
byte* destination = this.GetRowPointer(targetX, targetY + y);
for (int x = 0; x < width; x++)
@ -95,7 +95,7 @@ namespace ImageSharp
for (int y = 0; y < height; y++)
{
byte* source = this.GetRowPointer(sourceX, sourceY + y);
byte* destination = area.PixelBase + (y * area.RowByteCount);
byte* destination = area.PixelBase + (y * area.RowStride);
for (int x = 0; x < width; x++)
{
@ -115,7 +115,7 @@ namespace ImageSharp
for (int y = 0; y < height; y++)
{
byte* source = this.GetRowPointer(sourceX, sourceY + y);
byte* destination = area.PixelBase + (y * area.RowByteCount);
byte* destination = area.PixelBase + (y * area.RowStride);
for (int x = 0; x < width; x++)
{
@ -135,7 +135,7 @@ namespace ImageSharp
for (int y = 0; y < height; y++)
{
byte* source = this.GetRowPointer(sourceX, sourceY + y);
byte* destination = area.PixelBase + (y * area.RowByteCount);
byte* destination = area.PixelBase + (y * area.RowStride);
for (int x = 0; x < width; x++)
{

Loading…
Cancel
Save