Browse Source

Format code

pull/537/head
Jason Nelson 8 years ago
parent
commit
6102faf9c7
  1. 7
      src/ImageSharp/Formats/Jpeg/IJpegDecoderOptions.cs
  2. 7
      src/ImageSharp/Formats/Jpeg/IJpegEncoderOptions.cs
  3. 2
      src/ImageSharp/Formats/Jpeg/ImageExtensions.cs
  4. 2
      src/ImageSharp/Formats/Jpeg/JpegConfigurationModule.cs
  5. 55
      src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs
  6. 1
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs
  7. 5
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTables.cs
  8. 12
      src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs

7
src/ImageSharp/Formats/Jpeg/IJpegDecoderOptions.cs

@ -1,11 +1,6 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Generic;
using System.IO;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Jpeg namespace SixLabors.ImageSharp.Formats.Jpeg
{ {
/// <summary> /// <summary>
@ -18,4 +13,4 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// </summary> /// </summary>
bool IgnoreMetadata { get; } bool IgnoreMetadata { get; }
} }
} }

7
src/ImageSharp/Formats/Jpeg/IJpegEncoderOptions.cs

@ -1,11 +1,6 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Generic;
using System.IO;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Jpeg namespace SixLabors.ImageSharp.Formats.Jpeg
{ {
/// <summary> /// <summary>
@ -31,4 +26,4 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// <value>The subsample ratio of the jpg image.</value> /// <value>The subsample ratio of the jpg image.</value>
JpegSubsample? Subsample { get; } JpegSubsample? Subsample { get; }
} }
} }

2
src/ImageSharp/Formats/Jpeg/ImageExtensions.cs

@ -1,10 +1,8 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using System.IO; using System.IO;
using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;

2
src/ImageSharp/Formats/Jpeg/JpegConfigurationModule.cs

@ -17,4 +17,4 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
config.ImageFormatsManager.AddImageFormatDetector(new JpegImageFormatDetector()); config.ImageFormatsManager.AddImageFormatDetector(new JpegImageFormatDetector());
} }
} }
} }

55
src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs

@ -16,12 +16,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// <inheritdoc/> /// <inheritdoc/>
public IImageFormat DetectFormat(ReadOnlySpan<byte> header) public IImageFormat DetectFormat(ReadOnlySpan<byte> header)
{ {
if (this.IsSupportedFileFormat(header)) return this.IsSupportedFileFormat(header) ? ImageFormats.Jpeg : null;
{
return ImageFormats.Jpeg;
}
return null;
} }
private bool IsSupportedFileFormat(ReadOnlySpan<byte> header) private bool IsSupportedFileFormat(ReadOnlySpan<byte> header)
@ -35,36 +30,24 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// </summary> /// </summary>
/// <param name="header">The bytes representing the file header.</param> /// <param name="header">The bytes representing the file header.</param>
/// <returns>The <see cref="bool"/></returns> /// <returns>The <see cref="bool"/></returns>
private bool IsJfif(ReadOnlySpan<byte> header) private bool IsJfif(ReadOnlySpan<byte> header) =>
{ header[6] == 0x4A && // J
// TODO: This should be in constants header[7] == 0x46 && // F
bool isJfif = header[8] == 0x49 && // I
header[6] == 0x4A && // J header[9] == 0x46 && // F
header[7] == 0x46 && // F header[10] == 0x00;
header[8] == 0x49 && // I
header[9] == 0x46 && // F
header[10] == 0x00;
return isJfif;
}
/// <summary> /// <summary>
/// Returns a value indicating whether the given bytes identify EXIF data. /// Returns a value indicating whether the given bytes identify EXIF data.
/// </summary> /// </summary>
/// <param name="header">The bytes representing the file header.</param> /// <param name="header">The bytes representing the file header.</param>
/// <returns>The <see cref="bool"/></returns> /// <returns>The <see cref="bool"/></returns>
private bool IsExif(ReadOnlySpan<byte> header) private bool IsExif(ReadOnlySpan<byte> header) =>
{ header[6] == 0x45 && // E
// TODO: This should be in constants header[7] == 0x78 && // X
bool isExif = header[8] == 0x69 && // I
header[6] == 0x45 && // E header[9] == 0x66 && // F
header[7] == 0x78 && // X header[10] == 0x00;
header[8] == 0x69 && // I
header[9] == 0x66 && // F
header[10] == 0x00;
return isExif;
}
/// <summary> /// <summary>
/// Returns a value indicating whether the given bytes identify Jpeg data. /// Returns a value indicating whether the given bytes identify Jpeg data.
@ -72,14 +55,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// </summary> /// </summary>
/// <param name="header">The bytes representing the file header.</param> /// <param name="header">The bytes representing the file header.</param>
/// <returns>The <see cref="bool"/></returns> /// <returns>The <see cref="bool"/></returns>
private bool IsJpeg(ReadOnlySpan<byte> header) private bool IsJpeg(ReadOnlySpan<byte> header) =>
{ header[0] == 0xFF && // 255
// TODO: This should be in constants header[1] == 0xD8; // 216
bool isJpg =
header[0] == 0xFF && // 255
header[1] == 0xD8; // 216
return isJpg;
}
} }
} }

1
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs

@ -17,7 +17,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
internal class PdfJsFrameComponent : IDisposable, IJpegComponent internal class PdfJsFrameComponent : IDisposable, IJpegComponent
{ {
private readonly MemoryManager memoryManager; private readonly MemoryManager memoryManager;
#pragma warning disable SA1401 // Fields should be private
public PdfJsFrameComponent(MemoryManager memoryManager, PdfJsFrame frame, byte id, int horizontalFactor, int verticalFactor, byte quantizationTableIndex, int index) public PdfJsFrameComponent(MemoryManager memoryManager, PdfJsFrame frame, byte id, int horizontalFactor, int verticalFactor, byte quantizationTableIndex, int index)
{ {

5
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTables.cs

@ -21,10 +21,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
public ref PdfJsHuffmanTable this[int index] public ref PdfJsHuffmanTable this[int index]
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get get => ref this.tables[index];
{
return ref this.tables[index];
}
} }
} }
} }

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

@ -7,7 +7,6 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats.Jpeg.Common; using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder;
using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components; using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components;
@ -367,14 +366,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
if (this.ComponentCount == 4) if (this.ComponentCount == 4)
{ {
if (this.adobe.ColorTransform == PdfJsJpegConstants.Markers.Adobe.ColorTransformYcck) return this.adobe.ColorTransform == PdfJsJpegConstants.Markers.Adobe.ColorTransformYcck
{ ? JpegColorSpace.Ycck
return JpegColorSpace.Ycck; : JpegColorSpace.Cmyk;
}
else
{
return JpegColorSpace.Cmyk;
}
} }
throw new ImageFormatException($"Unsupported color mode. Max components 4; found {this.ComponentCount}"); throw new ImageFormatException($"Unsupported color mode. Max components 4; found {this.ComponentCount}");

Loading…
Cancel
Save