Browse Source

Delete unused code

af/merge-core
James Jackson-South 8 years ago
parent
commit
814211b942
  1. 6
      src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegBlockPostProcessor.cs
  2. 19
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FourByte.cs
  3. 142
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsJpegPixelArea.cs
  4. 131
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsYCbCrToRgbTables.cs
  5. 17
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/ThreeByte.cs
  6. 138
      src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegConstants.cs
  7. 156
      src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs

6
src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegBlockPostProcessor.cs

@ -47,9 +47,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder
this.DequantiazationTable = ZigZag.CreateDequantizationTable(ref decoder.QuantizationTables[qtIndex]);
this.subSamplingDivisors = component.SubSamplingDivisors;
this.SourceBlock = default(Block8x8F);
this.WorkspaceBlock1 = default(Block8x8F);
this.WorkspaceBlock2 = default(Block8x8F);
this.SourceBlock = default;
this.WorkspaceBlock1 = default;
this.WorkspaceBlock2 = default;
}
/// <summary>

19
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FourByte.cs

@ -1,19 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
[StructLayout(LayoutKind.Sequential)]
internal readonly struct FourByte
{
public readonly byte X;
public readonly byte Y;
public readonly byte Z;
public readonly byte W;
}
}

142
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsJpegPixelArea.cs

@ -1,142 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Diagnostics;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
/// <summary>
/// Represents a section of the jpeg component data laid out in pixel order.
/// </summary>
internal struct PdfJsJpegPixelArea : IDisposable
{
private readonly MemoryManager memoryManager;
private IBuffer<byte> componentData;
private int rowStride;
/// <summary>
/// Gets the number of components
/// </summary>
public int NumberOfComponents;
/// <summary>
/// Gets the width
/// </summary>
public int Width;
/// <summary>
/// Gets the height
/// </summary>
public int Height;
/// <summary>
/// Initializes a new instance of the <see cref="PdfJsJpegPixelArea"/> struct.
/// </summary>
/// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
/// <param name="imageWidth">The image width</param>
/// <param name="imageHeight">The image height</param>
/// <param name="numberOfComponents">The number of components</param>
public PdfJsJpegPixelArea(MemoryManager memoryManager, int imageWidth, int imageHeight, int numberOfComponents)
{
this.memoryManager = memoryManager;
this.Width = imageWidth;
this.Height = imageHeight;
this.NumberOfComponents = numberOfComponents;
this.componentData = null;
this.rowStride = this.Width * this.NumberOfComponents;
this.componentData = this.memoryManager.Allocate<byte>(this.Width * this.Height * this.NumberOfComponents);
}
//// <summary>
//// Organsizes the decoded jpeg components into a linear array ordered by component.
//// This must be called before attempting to retrieve the data.
//// </summary>
//// <param name="components">The jpeg component blocks</param>
// public void LinearizeBlockData(PdfJsComponentBlocks components)
// {
// ref byte componentDataRef = ref MemoryMarshal.GetReference(this.componentData.Span);
// const uint Mask3Lsb = 0xFFFFFFF8; // Used to clear the 3 LSBs
// using (IBuffer<int> xScaleBlockOffset = this.memoryManager.Allocate<int>(this.Width))
// {
// ref int xScaleBlockOffsetRef = ref MemoryMarshal.GetReference(xScaleBlockOffset.Span);
// int numberOfComponents = this.NumberOfComponents;
// int width = this.Width;
// int height = this.Height;
//
// for (int i = 0; i < numberOfComponents; i++)
// {
// ref PdfJsComponent component = ref components.Components[i];
// ref short outputRef = ref MemoryMarshal.GetReference(component.Output.Span);
// Vector2 componentScale = component.Scale;
// float cX = componentScale.X;
// float cY = componentScale.Y;
// int blocksPerScanline = (component.BlocksPerLine + 1) << 3;
//
// // Precalculate the xScaleBlockOffset
// int j;
// for (int x = 0; x < width; x++)
// {
// j = (int)(x * cX);
// Unsafe.Add(ref xScaleBlockOffsetRef, x) = (int)((j & Mask3Lsb) << 3) | (j & 7);
// }
//
// // Linearize the blocks of the component
// int offset = i;
// for (int y = 0; y < height; y++)
// {
// j = (int)(y * cY);
// int index = blocksPerScanline * (int)(j & Mask3Lsb) | ((j & 7) << 3);
// for (int x = 0; x < width; x++)
// {
// Unsafe.Add(ref componentDataRef, offset) = (byte)Unsafe.Add(ref outputRef, index + Unsafe.Add(ref xScaleBlockOffsetRef, x));
// offset += numberOfComponents;
// }
// }
// }
// }
// }
/// <summary>
/// Gets a <see cref="Span{Byte}"/> representing the row 'y' beginning from the the first byte on that row.
/// </summary>
/// <param name="y">The y-coordinate of the pixel row. Must be greater than or equal to zero and less than the height of the pixel area.</param>
/// <returns>The <see cref="Span{TPixel}"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<byte> GetRowSpan(int y)
{
this.CheckCoordinates(y);
return this.componentData.Slice(y * this.rowStride, this.rowStride);
}
/// <inheritdoc/>
public void Dispose()
{
this.componentData?.Dispose();
this.componentData = null;
}
/// <summary>
/// Checks the coordinates to ensure they are within bounds.
/// </summary>
/// <param name="y">The y-coordinate of the row. Must be greater than zero and less than the height of the area.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown if the coordinates are not within the bounds of the image.
/// </exception>
[Conditional("DEBUG")]
private void CheckCoordinates(int y)
{
if (y < 0 || y >= this.Height)
{
throw new ArgumentOutOfRangeException(nameof(y), y, $"{y} is outwith the area bounds.");
}
}
}
}

131
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsYCbCrToRgbTables.cs

@ -1,131 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
/// <summary>
/// Provides 8-bit lookup tables for converting from YCbCr to Rgb colorspace.
/// Methods to build the tables are based on libjpeg implementation.
/// </summary>
internal readonly struct PdfJsYCbCrToRgbTables
{
/// <summary>
/// The red red-chrominance table
/// </summary>
public static int[] CrRTable = new int[256];
/// <summary>
/// The blue blue-chrominance table
/// </summary>
public static int[] CbBTable = new int[256];
/// <summary>
/// The green red-chrominance table
/// </summary>
public static int[] CrGTable = new int[256];
/// <summary>
/// The green blue-chrominance table
/// </summary>
public static int[] CbGTable = new int[256];
// Speediest right-shift on some machines and gives us enough accuracy at 4 decimal places.
private const int ScaleBits = 16;
private const int Half = 1 << (ScaleBits - 1);
private const int MinSample = 0;
private const int HalfSample = 128;
private const int MaxSample = 255;
/// <summary>
/// Initializes the YCbCr tables
/// </summary>
public static void Create()
{
for (int i = 0, x = -128; i <= 255; i++, x++)
{
// i is the actual input pixel value, in the range 0..255
// The Cb or Cr value we are thinking of is x = i - 128
// Cr=>R value is nearest int to 1.402 * x
CrRTable[i] = RightShift((Fix(1.402F) * x) + Half);
// Cb=>B value is nearest int to 1.772 * x
CbBTable[i] = RightShift((Fix(1.772F) * x) + Half);
// Cr=>G value is scaled-up -0.714136286
CrGTable[i] = (-Fix(0.714136286F)) * x;
// Cb => G value is scaled - up - 0.344136286 * x
// We also add in Half so that need not do it in inner loop
CbGTable[i] = ((-Fix(0.344136286F)) * x) + Half;
}
}
/// <summary>
/// Optimized method to pack bytes to the image from the YCbCr color space.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="packed">The packed pixel.</param>
/// <param name="y">The y luminance component.</param>
/// <param name="cb">The cb chroma component.</param>
/// <param name="cr">The cr chroma component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void PackYCbCr<TPixel>(ref TPixel packed, byte y, byte cb, byte cr)
where TPixel : struct, IPixel<TPixel>
{
byte r = (byte)(y + CrRTable[cr]).Clamp(0, 255);
// The values for the G calculation are left scaled up, since we must add them together before rounding.
byte g = (byte)(y + RightShift(CbGTable[cb] + CrGTable[cr])).Clamp(0, 255);
byte b = (byte)(y + CbBTable[cb]).Clamp(0, 255);
packed.PackFromRgba32(new Rgba32(r, g, b, 255));
}
/// <summary>
/// Optimized method to pack bytes to the image from the YccK color space.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="packed">The packed pixel.</param>
/// <param name="y">The y luminance component.</param>
/// <param name="cb">The cb chroma component.</param>
/// <param name="cr">The cr chroma component.</param>
/// <param name="k">The keyline component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void PackYccK<TPixel>(ref TPixel packed, byte y, byte cb, byte cr, byte k)
where TPixel : struct, IPixel<TPixel>
{
int c = (MaxSample - (y + CrRTable[cr])).Clamp(0, 255);
// The values for the G calculation are left scaled up, since we must add them together before rounding.
int m = (MaxSample - (y + RightShift(CbGTable[cb] + CrGTable[cr]))).Clamp(0, 255);
int cy = (MaxSample - (y + CbBTable[cb])).Clamp(0, 255);
byte r = (byte)((c * k) / MaxSample);
byte g = (byte)((m * k) / MaxSample);
byte b = (byte)((cy * k) / MaxSample);
packed.PackFromRgba32(new Rgba32(r, g, b, MaxSample));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int Fix(float x)
{
return (int)((x * (1L << ScaleBits)) + 0.5F);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int RightShift(int x)
{
return x >> ScaleBits;
}
}
}

17
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/ThreeByte.cs

@ -1,17 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
[StructLayout(LayoutKind.Sequential)]
internal readonly struct ThreeByte
{
public readonly byte X;
public readonly byte Y;
public readonly byte Z;
}
}

138
src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegConstants.cs

@ -194,62 +194,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
/// </summary>
public const ushort RST7 = 0xFFD7;
/// <summary>
/// Contains JFIF specific markers
/// </summary>
public static class JFif
{
/// <summary>
/// Represents J in ASCII
/// </summary>
public const byte J = 0x4A;
/// <summary>
/// Represents F in ASCII
/// </summary>
public const byte F = 0x46;
/// <summary>
/// Represents I in ASCII
/// </summary>
public const byte I = 0x49;
/// <summary>
/// Represents the null "0" marker
/// </summary>
public const byte Null = 0x0;
}
/// <summary>
/// Contains Adobe specific markers
/// </summary>
public static class Adobe
{
/// <summary>
/// Represents A in ASCII
/// </summary>
public const byte A = 0x41;
/// <summary>
/// Represents d in ASCII
/// </summary>
public const byte D = 0x64;
/// <summary>
/// Represents b in ASCII
/// </summary>
public const byte O = 0x6F;
/// <summary>
/// Represents b in ASCII
/// </summary>
public const byte B = 0x62;
/// <summary>
/// Represents e in ASCII
/// </summary>
public const byte E = 0x65;
/// <summary>
/// The color transform is unknown.(RGB or CMYK)
/// </summary>
@ -265,93 +214,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
/// </summary>
public const byte ColorTransformYcck = 2;
}
/// <summary>
/// Contains EXIF specific markers
/// </summary>
public static class Exif
{
/// <summary>
/// Represents E in ASCII
/// </summary>
public const byte E = 0x45;
/// <summary>
/// Represents x in ASCII
/// </summary>
public const byte X = 0x78;
/// <summary>
/// Represents i in ASCII
/// </summary>
public const byte I = 0x69;
/// <summary>
/// Represents f in ASCII
/// </summary>
public const byte F = 0x66;
/// <summary>
/// Represents the null "0" marker
/// </summary>
public const byte Null = 0x0;
}
/// <summary>
/// Contains ICC specific markers
/// </summary>
public static class ICC
{
/// <summary>
/// Represents I in ASCII
/// </summary>
public const byte I = 0x49;
/// <summary>
/// Represents C in ASCII
/// </summary>
public const byte C = 0x43;
/// <summary>
/// Represents _ in ASCII
/// </summary>
public const byte UnderScore = 0x5F;
/// <summary>
/// Represents P in ASCII
/// </summary>
public const byte P = 0x50;
/// <summary>
/// Represents R in ASCII
/// </summary>
public const byte R = 0x52;
/// <summary>
/// Represents O in ASCII
/// </summary>
public const byte O = 0x4F;
/// <summary>
/// Represents F in ASCII
/// </summary>
public const byte F = 0x46;
/// <summary>
/// Represents L in ASCII
/// </summary>
public const byte L = 0x4C;
/// <summary>
/// Represents E in ASCII
/// </summary>
public const byte E = 0x45;
/// <summary>
/// Represents the null "0" marker
/// </summary>
public const byte Null = 0x0;
}
}
}
}

156
src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs

@ -58,8 +58,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
/// </summary>
private PdfJsHuffmanTables acHuffmanTables;
private PdfJsJpegPixelArea pixelArea;
/// <summary>
/// The reset interval determined by RST markers
/// </summary>
private ushort resetInterval;
/// <summary>
@ -77,14 +78,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
/// </summary>
private AdobeMarker adobe;
/// <summary>
/// Initializes static members of the <see cref="PdfJsJpegDecoderCore"/> class.
/// </summary>
static PdfJsJpegDecoderCore()
{
PdfJsYCbCrToRgbTables.Create();
}
/// <summary>
/// Initializes a new instance of the <see cref="PdfJsJpegDecoderCore" /> class.
/// </summary>
@ -143,6 +136,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
/// <inheritdoc/>
public IEnumerable<IJpegComponent> Components => this.Frame.Components;
/// <inheritdoc/>
public Block8x8F[] QuantizationTables { get; private set; }
/// <summary>
@ -341,7 +335,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
public void Dispose()
{
this.Frame?.Dispose();
this.pixelArea.Dispose();
// Set large fields to null.
this.Frame = null;
@ -349,53 +342,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
this.acHuffmanTables = null;
}
/// <summary>
/// Fills the given image with the color data. TODO: Delete ME!!
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The image</param>
private void FillPixelData<TPixel>(ImageFrame<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
if (this.ComponentCount > 4)
{
throw new ImageFormatException($"Unsupported color mode. Max components 4; found {this.ComponentCount}");
}
this.pixelArea = new PdfJsJpegPixelArea(this.configuration.MemoryManager, image.Width, image.Height, this.ComponentCount);
// this.pixelArea.LinearizeBlockData(this.components);
if (this.ComponentCount == 1)
{
this.FillGrayScaleImage(image);
return;
}
if (this.ComponentCount == 3)
{
if (this.adobe.Equals(default) || this.adobe.ColorTransform == PdfJsJpegConstants.Markers.Adobe.ColorTransformYCbCr)
{
this.FillYCbCrImage(image);
}
else if (this.adobe.ColorTransform == PdfJsJpegConstants.Markers.Adobe.ColorTransformUnknown)
{
this.FillRgbImage(image);
}
}
if (this.ComponentCount == 4)
{
if (this.adobe.ColorTransform == PdfJsJpegConstants.Markers.Adobe.ColorTransformYcck)
{
this.FillYcckImage(image);
}
else
{
this.FillCmykImage(image);
}
}
}
/// <summary>
/// Returns the correct colorspace based on the image component count
/// </summary>
@ -844,100 +790,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
tables[index] = new PdfJsHuffmanTable(this.configuration.MemoryManager, codeLengths, values);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void FillGrayScaleImage<TPixel>(ImageFrame<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
for (int y = 0; y < image.Height; y++)
{
ref TPixel imageRowRef = ref MemoryMarshal.GetReference(image.GetPixelRowSpan(y));
ref byte areaRowRef = ref MemoryMarshal.GetReference(this.pixelArea.GetRowSpan(y));
for (int x = 0; x < image.Width; x++)
{
ref byte luminance = ref Unsafe.Add(ref areaRowRef, x);
ref TPixel pixel = ref Unsafe.Add(ref imageRowRef, x);
var rgba = new Rgba32(luminance, luminance, luminance);
pixel.PackFromRgba32(rgba);
}
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void FillYCbCrImage<TPixel>(ImageFrame<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
for (int y = 0; y < image.Height; y++)
{
ref TPixel imageRowRef = ref MemoryMarshal.GetReference(image.GetPixelRowSpan(y));
ref ThreeByte areaRowRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast<byte, ThreeByte>(this.pixelArea.GetRowSpan(y)));
for (int x = 0; x < image.Width; x++)
{
ref ThreeByte ycbcr = ref Unsafe.Add(ref areaRowRef, x);
ref TPixel pixel = ref Unsafe.Add(ref imageRowRef, x);
PdfJsYCbCrToRgbTables.PackYCbCr(ref pixel, ycbcr.X, ycbcr.Y, ycbcr.Z);
}
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void FillYcckImage<TPixel>(ImageFrame<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
for (int y = 0; y < image.Height; y++)
{
ref TPixel imageRowRef = ref MemoryMarshal.GetReference(image.GetPixelRowSpan(y));
ref FourByte areaRowRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast<byte, FourByte>(this.pixelArea.GetRowSpan(y)));
for (int x = 0; x < image.Width; x++)
{
ref FourByte ycbcrk = ref Unsafe.Add(ref areaRowRef, x);
ref TPixel pixel = ref Unsafe.Add(ref imageRowRef, x);
PdfJsYCbCrToRgbTables.PackYccK(ref pixel, ycbcrk.X, ycbcrk.Y, ycbcrk.Z, ycbcrk.W);
}
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void FillCmykImage<TPixel>(ImageFrame<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
for (int y = 0; y < image.Height; y++)
{
ref TPixel imageRowRef = ref MemoryMarshal.GetReference(image.GetPixelRowSpan(y));
ref FourByte areaRowRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast<byte, FourByte>(this.pixelArea.GetRowSpan(y)));
for (int x = 0; x < image.Width; x++)
{
ref FourByte cmyk = ref Unsafe.Add(ref areaRowRef, x);
byte k = cmyk.W;
// TODO: We should see if Vector3 breaks this.
byte r = (byte)((cmyk.X * k) / 255);
byte g = (byte)((cmyk.Y * k) / 255);
byte b = (byte)((cmyk.Z * k) / 255);
ref TPixel pixel = ref Unsafe.Add(ref imageRowRef, x);
var rgba = new Rgba32(r, g, b);
pixel.PackFromRgba32(rgba);
}
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void FillRgbImage<TPixel>(ImageFrame<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
for (int y = 0; y < image.Height; y++)
{
Span<TPixel> imageRowSpan = image.GetPixelRowSpan(y);
Span<byte> areaRowSpan = this.pixelArea.GetRowSpan(y);
PixelOperations<TPixel>.Instance.PackFromRgb24Bytes(areaRowSpan, imageRowSpan, image.Width);
}
}
/// <summary>
/// Reads a <see cref="ushort"/> from the stream advancing it by two bytes
/// </summary>

Loading…
Cancel
Save