Browse Source

more cleanup

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

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

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

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

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

Loading…
Cancel
Save