Browse Source

Meh

pull/643/head
James Jackson-South 8 years ago
parent
commit
6d928f6640
  1. 24
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedByteBuffer257.cs
  2. 120
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs
  3. 9
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs
  4. 2
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/ScanDecoder.cs

24
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedByteBuffer257.cs

@ -0,0 +1,24 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct FixedByteBuffer257
{
public fixed byte Data[257];
public byte this[int idx]
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
ref byte self = ref Unsafe.As<FixedByteBuffer257, byte>(ref this);
return Unsafe.Add(ref self, idx);
}
}
}
}

120
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs

@ -50,69 +50,69 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
const int Length = 257; const int Length = 257;
using (IBuffer<short> huffcode = memoryManager.Allocate<short>(Length)) using (IBuffer<short> huffcode = memoryManager.Allocate<short>(Length))
{ {
// Span<short> codes = huffcode.Span; Span<short> codes = huffcode.Span;
ref short huffcodeRef = ref MemoryMarshal.GetReference(huffcode.Span); ref short huffcodeRef = ref MemoryMarshal.GetReference(huffcode.Span);
this.GenerateSizeTable(count); this.GenerateSizeTable(count);
//int k = 0; int k = 0;
//fixed (short* sizesRef = this.Sizes.Data) fixed (short* size = this.Sizes.Data)
//fixed (short* deltaRef = this.ValOffset.Data) fixed (short* delta = this.ValOffset.Data)
//fixed (long* maxcodeRef = this.MaxCode.Data) fixed (long* maxcode = this.MaxCode.Data)
//{ {
// uint code = 0; uint code = 0;
// int j; int j;
// for (j = 1; j <= 16; j++) for (j = 1; j <= 16; j++)
// { {
// // Compute delta to add to code to compute symbol id. // Compute delta to add to code to compute symbol id.
// deltaRef[j] = (short)(k - code); delta[j] = (short)(k - code);
// if (sizesRef[k] == j) if (size[k] == j)
// { {
// while (sizesRef[k] == j) while (size[k] == j)
// { {
// codes[k++] = (short)code++; codes[k++] = (short)code++;
// // Unsafe.Add(ref huffcodeRef, k++) = (short)code++; // Unsafe.Add(ref huffcodeRef, k++) = (short)code++;
// // TODO: Throw if invalid? // TODO: Throw if invalid?
// } }
// } }
// // Compute largest code + 1 for this size. preshifted as neeed later. // Compute largest code + 1 for this size. preshifted as neeed later.
// maxcodeRef[j] = code << (16 - j); maxcode[j] = code << (16 - j);
// code <<= 1; code <<= 1;
// } }
// maxcodeRef[j] = 0xFFFFFFFF; maxcode[j] = 0xFFFFFFFF;
//} }
//fixed (short* lookaheadRef = this.Lookahead.Data) fixed (byte* lookaheadRef = this.Lookahead.Data)
//{ {
// const int FastBits = ScanDecoder.FastBits; const int FastBits = ScanDecoder.FastBits;
// var fast = new Span<short>(lookaheadRef, 1 << FastBits); var fast = new Span<short>(lookaheadRef, 1 << FastBits);
// fast.Fill(255); // Flag for non-accelerated fast.Fill(255); // Flag for non-accelerated
// fixed (short* sizesRef = this.Sizes.Data) fixed (short* sizesRef = this.Sizes.Data)
// { {
// for (int i = 0; i < k; i++) for (int i = 0; i < k; i++)
// { {
// int s = sizesRef[i]; int s = sizesRef[i];
// if (s <= ScanDecoder.FastBits) if (s <= ScanDecoder.FastBits)
// { {
// int c = codes[i] << (FastBits - s); int c = codes[i] << (FastBits - s);
// int m = 1 << (FastBits - s); int m = 1 << (FastBits - s);
// for (int j = 0; j < m; j++) for (int j = 0; j < m; j++)
// { {
// fast[c + j] = (byte)i; fast[c + j] = (byte)i;
// } }
// } }
// } }
// } }
//} }
this.GenerateCodeTable(ref huffcodeRef, Length, out int k); // this.GenerateCodeTable(ref huffcodeRef, Length, out int k);
this.GenerateDecoderTables(count, ref huffcodeRef); // this.GenerateDecoderTables(count, ref huffcodeRef);
this.GenerateLookaheadTables(count, values, ref huffcodeRef, k); // this.GenerateLookaheadTables(count, values, ref huffcodeRef, k);
} }
fixed (byte* huffValRef = this.Values.Data) fixed (byte* huffValRef = this.Values.Data)
@ -224,7 +224,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
const int FastBits = ScanDecoder.FastBits; const int FastBits = ScanDecoder.FastBits;
var lookaheadSpan = new Span<short>(lookaheadRef, 1 << ScanDecoder.FastBits); var lookaheadSpan = new Span<short>(lookaheadRef, 1 << ScanDecoder.FastBits);
lookaheadSpan.Fill(255); // Flag for non-accelerated lookaheadSpan.Fill(byte.MaxValue); // Flag for non-accelerated
fixed (short* sizesRef = this.Sizes.Data) fixed (short* sizesRef = this.Sizes.Data)
{ {
for (int i = 0; i < k; ++i) for (int i = 0; i < k; ++i)

9
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs

@ -860,14 +860,5 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
} }
} }
} }
private void Reset()
{
// Reset
// TODO: I do not understand why these values are reset? We should surely be tracking the bits across mcu's?
this.bitsCount = 0;
this.bitsData = 0;
this.unexpectedMarkerReached = false;
}
} }
} }

2
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/ScanDecoder.cs

@ -607,7 +607,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
// wants to be compared against something shifted to have 16; // wants to be compared against something shifted to have 16;
// that way we don't need to shift inside the loop. // that way we don't need to shift inside the loop.
uint temp = this.codeBuffer >> 16; uint temp = this.codeBuffer >> 16;
for (k = FastBits + 1; ; ++k) for (k = FastBits + 1; ; k++)
{ {
if (temp < table.MaxCode[k]) if (temp < table.MaxCode[k])
{ {

Loading…
Cancel
Save