Browse Source

more cleanup

af/merge-core
Anton Firszov 9 years ago
parent
commit
d5efd64550
  1. 4
      src/ImageSharp/Formats/Jpg/Components/Decoder/Bits.cs
  2. 23
      src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs
  3. 48
      src/ImageSharp/Formats/Jpg/Utils/JpegUtils.cs

4
src/ImageSharp/Formats/Jpg/Components/Decoder/Bits.cs

@ -47,7 +47,7 @@ namespace ImageSharp.Formats.Jpg
// Grab the decode bytes, use them and then set them
// back on the decoder.
var decoderBytes = decoder.Bytes;
Bytes decoderBytes = decoder.Bytes;
byte c = decoderBytes.ReadByteStuffedByte(decoder.InputStream, out errorCode);
decoder.Bytes = decoderBytes;
@ -84,7 +84,7 @@ namespace ImageSharp.Formats.Jpg
{
if (this.UnreadBits < t)
{
var errorCode = this.EnsureNBits(t, decoder);
JpegDecoderCore.ErrorCodes errorCode = this.EnsureNBits(t, decoder);
if (errorCode != JpegDecoderCore.ErrorCodes.NoError)
{
throw new JpegDecoderCore.MissingFF00Exception();

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

@ -226,6 +226,22 @@ namespace ImageSharp.Formats
stream.Flush();
}
/// <summary>
/// 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="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)
{
dqt[offset++] = (byte)i;
for (int j = 0; j < Block8x8F.ScalarCount; j++)
{
dqt[offset++] = (byte)q[j];
}
}
private static void InitQuantizationTable(int i, int scale, ref Block8x8F quant)
{
for (int j = 0; j < Block8x8F.ScalarCount; j++)
@ -622,8 +638,8 @@ namespace ImageSharp.Formats
byte[] dqt = ArrayPool<byte>.Shared.Rent(dqtCount);
int offset = 0;
JpegUtils.WriteDataToDqt(dqt, ref offset, QuantIndex.Luminance, ref this.luminanceQuantTable);
JpegUtils.WriteDataToDqt(dqt, ref offset, QuantIndex.Chrominance, ref this.chrominanceQuantTable);
WriteDataToDqt(dqt, ref offset, QuantIndex.Luminance, ref this.luminanceQuantTable);
WriteDataToDqt(dqt, ref offset, QuantIndex.Chrominance, ref this.chrominanceQuantTable);
this.outputStream.Write(dqt, 0, dqtCount);
ArrayPool<byte>.Shared.Return(dqt);
@ -782,7 +798,7 @@ namespace ImageSharp.Formats
// ReSharper disable once InconsistentNaming
float prevDCY = 0, prevDCCb = 0, prevDCCr = 0;
using (var rgbBytes = new PixelArea<TColor>(8, 8, ComponentOrder.XYZ, true))
using (PixelArea<TColor> rgbBytes = new PixelArea<TColor>(8, 8, ComponentOrder.XYZ, true))
{
for (int y = 0; y < pixels.Height; y += 16)
{
@ -814,6 +830,7 @@ namespace ImageSharp.Formats
&temp2,
&onStackChrominanceQuantTable,
unzig.Data);
Block8x8F.Scale16X16To8X8(&b, crPtr);
prevDCCr = this.WriteBlock(
QuantIndex.Chrominance,

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

@ -19,18 +19,10 @@ namespace ImageSharp.Formats.Jpg
/// <typeparam name="TColor">
/// The pixel type
/// </typeparam>
/// <param name="pixels">
/// The input pixel acessor
/// </param>
/// <param name="dest">
/// The destination <see cref="PixelArea{TColor}"/>
/// </param>
/// <param name="sourceY">
/// Starting Y coord
/// </param>
/// <param name="sourceX">
/// Starting X coord
/// </param>
/// <param name="pixels">The input pixel acessor</param>
/// <param name="dest">The destination <see cref="PixelArea{TColor}"/></param>
/// <param name="sourceY">Starting Y coord</param>
/// <param name="sourceX">Starting X coord</param>
public static void CopyRGBBytesStretchedTo<TColor>(
this PixelAccessor<TColor> pixels,
PixelArea<TColor> dest,
@ -47,12 +39,8 @@ namespace ImageSharp.Formats.Jpg
/// <summary>
/// Copy an RGB value
/// </summary>
/// <param name="source">
/// Source pointer
/// </param>
/// <param name="dest">
/// Destination pointer
/// </param>
/// <param name="source">Source pointer</param>
/// <param name="dest">Destination pointer</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void CopyRgb(byte* source, byte* dest)
{
@ -61,30 +49,6 @@ namespace ImageSharp.Formats.Jpg
*dest = *source; // B
}
/// <summary>
/// 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="i">
/// The quantization index
/// </param>
/// <param name="q">
/// The quantazation table to copy data from
/// </param>
internal static void WriteDataToDqt(byte[] dqt, ref int offset, QuantIndex i, ref Block8x8F q)
{
dqt[offset++] = (byte)i;
for (int j = 0; j < Block8x8F.ScalarCount; j++)
{
dqt[offset++] = (byte)q[j];
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsInvalidStretchArea<TColor>(PixelArea<TColor> area, int fromX, int fromY)
where TColor : struct, IPackedPixel, IEquatable<TColor>

Loading…
Cancel
Save