Browse Source

shut up StyleStalin, I'm working! :P

pull/298/head
Anton Firszov 9 years ago
parent
commit
0a80231bd3
  1. 2
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsComponentBlocks.cs
  2. 2
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsJpegPixelArea.cs
  3. 21
      src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoder.cs
  4. 170
      src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs
  5. 8
      src/Shared/stylecop.json

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

@ -10,7 +10,7 @@ namespace ImageSharp.Formats.Jpeg.PdfJsPort.Components
/// <summary> /// <summary>
/// Contains all the decoded component blocks /// Contains all the decoded component blocks
/// </summary> /// </summary>
internal sealed class ComponentBlocks : IDisposable internal sealed class PdfJsComponentBlocks : IDisposable
{ {
/// <summary> /// <summary>
/// Gets or sets the component blocks /// Gets or sets the component blocks

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

@ -63,7 +63,7 @@ namespace ImageSharp.Formats.Jpeg.PdfJsPort.Components
/// <param name="components">The jpeg component blocks</param> /// <param name="components">The jpeg component blocks</param>
/// <param name="width">The pixel area width</param> /// <param name="width">The pixel area width</param>
/// <param name="height">The pixel area height</param> /// <param name="height">The pixel area height</param>
public void LinearizeBlockData(ComponentBlocks components, int width, int height) public void LinearizeBlockData(PdfJsComponentBlocks components, int width, int height)
{ {
this.Width = width; this.Width = width;
this.Height = height; this.Height = height;

21
src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoder.cs

@ -0,0 +1,21 @@
namespace ImageSharp.Formats.Jpeg.PdfJsPort
{
using System;
using System.IO;
using ImageSharp.PixelFormats;
internal sealed class PdfJsJpegDecoder : IImageDecoder, IJpegDecoderOptions
{
public bool IgnoreMetadata { get; set; }
public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream)
where TPixel : struct, IPixel<TPixel>
{
using (var decoder = new PdfJsJpegDecoderCore(configuration, this))
{
return decoder.Decode<TPixel>(stream);
}
}
}
}

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

@ -6,8 +6,6 @@
namespace ImageSharp.Formats.Jpeg.PdfJsPort namespace ImageSharp.Formats.Jpeg.PdfJsPort
{ {
using System; using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@ -41,7 +39,7 @@ namespace ImageSharp.Formats.Jpeg.PdfJsPort
private PdfJsFrame frame; private PdfJsFrame frame;
private ComponentBlocks components; private PdfJsComponentBlocks components;
private PdfJsJpegPixelArea pixelArea; private PdfJsJpegPixelArea pixelArea;
@ -269,19 +267,19 @@ namespace ImageSharp.Formats.Jpeg.PdfJsPort
this.imageWidth = this.frame.SamplesPerLine; this.imageWidth = this.frame.SamplesPerLine;
this.imageHeight = this.frame.Scanlines; this.imageHeight = this.frame.Scanlines;
this.components = new ComponentBlocks { Components = new PdfJsComponent[this.frame.ComponentCount] }; this.components = new PdfJsComponentBlocks { Components = new PdfJsComponent[this.frame.ComponentCount] };
for (int i = 0; i < this.components.Components.Length; i++) for (int i = 0; i < this.components.Components.Length; i++)
{ {
ref var frameComponent = ref this.frame.Components[i]; ref var frameComponent = ref this.frame.Components[i];
var component = new PdfJsComponent var component = new PdfJsComponent
{ {
Scale = new System.Numerics.Vector2( Scale = new System.Numerics.Vector2(
frameComponent.HorizontalFactor / (float)this.frame.MaxHorizontalFactor, frameComponent.HorizontalFactor / (float)this.frame.MaxHorizontalFactor,
frameComponent.VerticalFactor / (float)this.frame.MaxVerticalFactor), frameComponent.VerticalFactor / (float)this.frame.MaxVerticalFactor),
BlocksPerLine = frameComponent.BlocksPerLine, BlocksPerLine = frameComponent.BlocksPerLine,
BlocksPerColumn = frameComponent.BlocksPerColumn BlocksPerColumn = frameComponent.BlocksPerColumn
}; };
this.BuildComponentData(ref component, ref frameComponent); this.BuildComponentData(ref component, ref frameComponent);
this.components.Components[i] = component; this.components.Components[i] = component;
@ -300,7 +298,8 @@ namespace ImageSharp.Formats.Jpeg.PdfJsPort
{ {
if (this.numberOfComponents > 4) if (this.numberOfComponents > 4)
{ {
throw new ImageFormatException($"Unsupported color mode. Max components 4; found {this.numberOfComponents}"); throw new ImageFormatException(
$"Unsupported color mode. Max components 4; found {this.numberOfComponents}");
} }
this.pixelArea = new PdfJsJpegPixelArea(image.Width, image.Height, this.numberOfComponents); this.pixelArea = new PdfJsJpegPixelArea(image.Width, image.Height, this.numberOfComponents);
@ -314,7 +313,8 @@ namespace ImageSharp.Formats.Jpeg.PdfJsPort
if (this.numberOfComponents == 3) if (this.numberOfComponents == 3)
{ {
if (this.adobe.Equals(default(PdfJsAdobe)) || this.adobe.ColorTransform == PdfJsJpegConstants.Markers.Adobe.ColorTransformYCbCr) if (this.adobe.Equals(default(PdfJsAdobe))
|| this.adobe.ColorTransform == PdfJsJpegConstants.Markers.Adobe.ColorTransformYCbCr)
{ {
this.FillYCbCrImage(image); this.FillYCbCrImage(image);
} }
@ -381,22 +381,22 @@ namespace ImageSharp.Formats.Jpeg.PdfJsPort
this.InputStream.Read(this.temp, 0, 13); this.InputStream.Read(this.temp, 0, 13);
remaining -= 13; remaining -= 13;
bool isJfif = this.temp[0] == PdfJsJpegConstants.Markers.JFif.J && bool isJfif = this.temp[0] == PdfJsJpegConstants.Markers.JFif.J
this.temp[1] == PdfJsJpegConstants.Markers.JFif.F && && this.temp[1] == PdfJsJpegConstants.Markers.JFif.F
this.temp[2] == PdfJsJpegConstants.Markers.JFif.I && && this.temp[2] == PdfJsJpegConstants.Markers.JFif.I
this.temp[3] == PdfJsJpegConstants.Markers.JFif.F && && this.temp[3] == PdfJsJpegConstants.Markers.JFif.F
this.temp[4] == PdfJsJpegConstants.Markers.JFif.Null; && this.temp[4] == PdfJsJpegConstants.Markers.JFif.Null;
if (isJfif) if (isJfif)
{ {
this.jFif = new PdfJsJFif this.jFif = new PdfJsJFif
{ {
MajorVersion = this.temp[5], MajorVersion = this.temp[5],
MinorVersion = this.temp[6], MinorVersion = this.temp[6],
DensityUnits = this.temp[7], DensityUnits = this.temp[7],
XDensity = (short)((this.temp[8] << 8) | this.temp[9]), XDensity = (short)((this.temp[8] << 8) | this.temp[9]),
YDensity = (short)((this.temp[10] << 8) | this.temp[11]) YDensity = (short)((this.temp[10] << 8) | this.temp[11])
}; };
} }
// TODO: thumbnail // TODO: thumbnail
@ -423,12 +423,10 @@ namespace ImageSharp.Formats.Jpeg.PdfJsPort
byte[] profile = new byte[remaining]; byte[] profile = new byte[remaining];
this.InputStream.Read(profile, 0, remaining); this.InputStream.Read(profile, 0, remaining);
if (profile[0] == PdfJsJpegConstants.Markers.Exif.E && if (profile[0] == PdfJsJpegConstants.Markers.Exif.E && profile[1] == PdfJsJpegConstants.Markers.Exif.X
profile[1] == PdfJsJpegConstants.Markers.Exif.X && && profile[2] == PdfJsJpegConstants.Markers.Exif.I && profile[3] == PdfJsJpegConstants.Markers.Exif.F
profile[2] == PdfJsJpegConstants.Markers.Exif.I && && profile[4] == PdfJsJpegConstants.Markers.Exif.Null
profile[3] == PdfJsJpegConstants.Markers.Exif.F && && profile[5] == PdfJsJpegConstants.Markers.Exif.Null)
profile[4] == PdfJsJpegConstants.Markers.Exif.Null &&
profile[5] == PdfJsJpegConstants.Markers.Exif.Null)
{ {
this.isExif = true; this.isExif = true;
metadata.ExifProfile = new ExifProfile(profile); metadata.ExifProfile = new ExifProfile(profile);
@ -454,18 +452,17 @@ namespace ImageSharp.Formats.Jpeg.PdfJsPort
this.InputStream.Read(identifier, 0, Icclength); this.InputStream.Read(identifier, 0, Icclength);
remaining -= Icclength; // We have read it by this point remaining -= Icclength; // We have read it by this point
if (identifier[0] == PdfJsJpegConstants.Markers.ICC.I && if (identifier[0] == PdfJsJpegConstants.Markers.ICC.I && identifier[1] == PdfJsJpegConstants.Markers.ICC.C
identifier[1] == PdfJsJpegConstants.Markers.ICC.C && && identifier[2] == PdfJsJpegConstants.Markers.ICC.C
identifier[2] == PdfJsJpegConstants.Markers.ICC.C && && identifier[3] == PdfJsJpegConstants.Markers.ICC.UnderScore
identifier[3] == PdfJsJpegConstants.Markers.ICC.UnderScore && && identifier[4] == PdfJsJpegConstants.Markers.ICC.P
identifier[4] == PdfJsJpegConstants.Markers.ICC.P && && identifier[5] == PdfJsJpegConstants.Markers.ICC.R
identifier[5] == PdfJsJpegConstants.Markers.ICC.R && && identifier[6] == PdfJsJpegConstants.Markers.ICC.O
identifier[6] == PdfJsJpegConstants.Markers.ICC.O && && identifier[7] == PdfJsJpegConstants.Markers.ICC.F
identifier[7] == PdfJsJpegConstants.Markers.ICC.F && && identifier[8] == PdfJsJpegConstants.Markers.ICC.I
identifier[8] == PdfJsJpegConstants.Markers.ICC.I && && identifier[9] == PdfJsJpegConstants.Markers.ICC.L
identifier[9] == PdfJsJpegConstants.Markers.ICC.L && && identifier[10] == PdfJsJpegConstants.Markers.ICC.E
identifier[10] == PdfJsJpegConstants.Markers.ICC.E && && identifier[11] == PdfJsJpegConstants.Markers.ICC.Null)
identifier[11] == PdfJsJpegConstants.Markers.ICC.Null)
{ {
byte[] profile = new byte[remaining]; byte[] profile = new byte[remaining];
this.InputStream.Read(profile, 0, remaining); this.InputStream.Read(profile, 0, remaining);
@ -503,21 +500,21 @@ namespace ImageSharp.Formats.Jpeg.PdfJsPort
this.InputStream.Read(this.temp, 0, 12); this.InputStream.Read(this.temp, 0, 12);
remaining -= 12; remaining -= 12;
bool isAdobe = this.temp[0] == PdfJsJpegConstants.Markers.Adobe.A && bool isAdobe = this.temp[0] == PdfJsJpegConstants.Markers.Adobe.A
this.temp[1] == PdfJsJpegConstants.Markers.Adobe.D && && this.temp[1] == PdfJsJpegConstants.Markers.Adobe.D
this.temp[2] == PdfJsJpegConstants.Markers.Adobe.O && && this.temp[2] == PdfJsJpegConstants.Markers.Adobe.O
this.temp[3] == PdfJsJpegConstants.Markers.Adobe.B && && this.temp[3] == PdfJsJpegConstants.Markers.Adobe.B
this.temp[4] == PdfJsJpegConstants.Markers.Adobe.E; && this.temp[4] == PdfJsJpegConstants.Markers.Adobe.E;
if (isAdobe) if (isAdobe)
{ {
this.adobe = new PdfJsAdobe this.adobe = new PdfJsAdobe
{ {
DCTEncodeVersion = (short)((this.temp[5] << 8) | this.temp[6]), DCTEncodeVersion = (short)((this.temp[5] << 8) | this.temp[6]),
APP14Flags0 = (short)((this.temp[7] << 8) | this.temp[8]), APP14Flags0 = (short)((this.temp[7] << 8) | this.temp[8]),
APP14Flags1 = (short)((this.temp[9] << 8) | this.temp[10]), APP14Flags1 = (short)((this.temp[9] << 8) | this.temp[10]),
ColorTransform = this.temp[11] ColorTransform = this.temp[11]
}; };
} }
if (remaining > 0) if (remaining > 0)
@ -555,7 +552,8 @@ namespace ImageSharp.Formats.Jpeg.PdfJsPort
this.InputStream.Read(this.temp, 0, 64); this.InputStream.Read(this.temp, 0, 64);
remaining -= 64; remaining -= 64;
Span<short> tableSpan = this.quantizationTables.Tables.GetRowSpan(quantizationTableSpec & 15); Span<short> tableSpan =
this.quantizationTables.Tables.GetRowSpan(quantizationTableSpec & 15);
for (int j = 0; j < 64; j++) for (int j = 0; j < 64; j++)
{ {
tableSpan[PdfJsQuantizationTables.DctZigZag[j]] = this.temp[j]; tableSpan[PdfJsQuantizationTables.DctZigZag[j]] = this.temp[j];
@ -575,10 +573,12 @@ namespace ImageSharp.Formats.Jpeg.PdfJsPort
this.InputStream.Read(this.temp, 0, 128); this.InputStream.Read(this.temp, 0, 128);
remaining -= 128; remaining -= 128;
Span<short> tableSpan = this.quantizationTables.Tables.GetRowSpan(quantizationTableSpec & 15); Span<short> tableSpan =
this.quantizationTables.Tables.GetRowSpan(quantizationTableSpec & 15);
for (int j = 0; j < 64; j++) for (int j = 0; j < 64; j++)
{ {
tableSpan[PdfJsQuantizationTables.DctZigZag[j]] = (short)((this.temp[2 * j] << 8) | this.temp[(2 * j) + 1]); tableSpan[PdfJsQuantizationTables.DctZigZag[j]] =
(short)((this.temp[2 * j] << 8) | this.temp[(2 * j) + 1]);
} }
} }
@ -614,14 +614,14 @@ namespace ImageSharp.Formats.Jpeg.PdfJsPort
this.InputStream.Read(this.temp, 0, remaining); this.InputStream.Read(this.temp, 0, remaining);
this.frame = new PdfJsFrame this.frame = new PdfJsFrame
{ {
Extended = frameMarker.Marker == PdfJsJpegConstants.Markers.SOF1, Extended = frameMarker.Marker == PdfJsJpegConstants.Markers.SOF1,
Progressive = frameMarker.Marker == PdfJsJpegConstants.Markers.SOF2, Progressive = frameMarker.Marker == PdfJsJpegConstants.Markers.SOF2,
Precision = this.temp[0], Precision = this.temp[0],
Scanlines = (short)((this.temp[1] << 8) | this.temp[2]), Scanlines = (short)((this.temp[1] << 8) | this.temp[2]),
SamplesPerLine = (short)((this.temp[3] << 8) | this.temp[4]), SamplesPerLine = (short)((this.temp[3] << 8) | this.temp[4]),
ComponentCount = this.temp[5] ComponentCount = this.temp[5]
}; };
int maxH = 0; int maxH = 0;
int maxV = 0; int maxV = 0;
@ -762,18 +762,18 @@ namespace ImageSharp.Formats.Jpeg.PdfJsPort
var scanDecoder = default(PdfJsScanDecoder); var scanDecoder = default(PdfJsScanDecoder);
scanDecoder.DecodeScan( scanDecoder.DecodeScan(
this.frame, this.frame,
this.InputStream, this.InputStream,
this.dcHuffmanTables, this.dcHuffmanTables,
this.acHuffmanTables, this.acHuffmanTables,
this.frame.Components, this.frame.Components,
componentIndex, componentIndex,
selectorsCount, selectorsCount,
this.resetInterval, this.resetInterval,
spectralStart, spectralStart,
spectralEnd, spectralEnd,
successiveApproximation >> 4, successiveApproximation >> 4,
successiveApproximation & 15); successiveApproximation & 15);
} }
/// <summary> /// <summary>
@ -788,7 +788,8 @@ namespace ImageSharp.Formats.Jpeg.PdfJsPort
using (var computationBuffer = Buffer<short>.CreateClean(64)) using (var computationBuffer = Buffer<short>.CreateClean(64))
using (var multiplicationBuffer = Buffer<short>.CreateClean(64)) using (var multiplicationBuffer = Buffer<short>.CreateClean(64))
{ {
Span<short> quantizationTable = this.quantizationTables.Tables.GetRowSpan(frameComponent.QuantizationIdentifier); Span<short> quantizationTable =
this.quantizationTables.Tables.GetRowSpan(frameComponent.QuantizationIdentifier);
Span<short> computationBufferSpan = computationBuffer; Span<short> computationBufferSpan = computationBuffer;
// For AA&N IDCT method, multiplier are equal to quantization // For AA&N IDCT method, multiplier are equal to quantization
@ -807,7 +808,11 @@ namespace ImageSharp.Formats.Jpeg.PdfJsPort
for (int blockCol = 0; blockCol < blocksPerLine; blockCol++) for (int blockCol = 0; blockCol < blocksPerLine; blockCol++)
{ {
int offset = GetBlockBufferOffset(ref component, blockRow, blockCol); int offset = GetBlockBufferOffset(ref component, blockRow, blockCol);
PdfJsIDCT.QuantizeAndInverseFast(ref frameComponent, offset, ref computationBufferSpan, ref multiplierSpan); PdfJsIDCT.QuantizeAndInverseFast(
ref frameComponent,
offset,
ref computationBufferSpan,
ref multiplierSpan);
} }
} }
} }
@ -838,8 +843,11 @@ namespace ImageSharp.Formats.Jpeg.PdfJsPort
for (int i = 0; i < this.frame.ComponentCount; i++) for (int i = 0; i < this.frame.ComponentCount; i++)
{ {
ref var component = ref this.frame.Components[i]; ref var component = ref this.frame.Components[i];
int blocksPerLine = (int)MathF.Ceiling(MathF.Ceiling(this.frame.SamplesPerLine / 8F) * component.HorizontalFactor / this.frame.MaxHorizontalFactor); int blocksPerLine = (int)MathF.Ceiling(
int blocksPerColumn = (int)MathF.Ceiling(MathF.Ceiling(this.frame.Scanlines / 8F) * component.VerticalFactor / this.frame.MaxVerticalFactor); MathF.Ceiling(this.frame.SamplesPerLine / 8F) * component.HorizontalFactor
/ this.frame.MaxHorizontalFactor);
int blocksPerColumn = (int)MathF.Ceiling(
MathF.Ceiling(this.frame.Scanlines / 8F) * component.VerticalFactor / this.frame.MaxVerticalFactor);
int blocksPerLineForMcu = mcusPerLine * component.HorizontalFactor; int blocksPerLineForMcu = mcusPerLine * component.HorizontalFactor;
int blocksPerColumnForMcu = mcusPerColumn * component.VerticalFactor; int blocksPerColumnForMcu = mcusPerColumn * component.VerticalFactor;

8
src/Shared/stylecop.json

@ -3,7 +3,13 @@
"settings": { "settings": {
"documentationRules": { "documentationRules": {
"companyName": "James Jackson-South", "companyName": "James Jackson-South",
"copyrightText": "Copyright (c) James Jackson-South and contributors.\nLicensed under the Apache License, Version 2.0." "copyrightText": "Copyright (c) James Jackson-South and contributors.\nLicensed under the Apache License, Version 2.0.",
"documentInterfaces": false,
"documentInternalElements": false,
"documentExposedElements": false,
"documentPrivateElements": false,
"documentPrivateFields": false
} }
} }
} }
Loading…
Cancel
Save