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.
// 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
{
/// <summary>
@ -18,4 +13,4 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// </summary>
bool IgnoreMetadata { get; }
}
}
}

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

@ -1,11 +1,6 @@
// Copyright (c) Six Labors and contributors.
// 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
{
/// <summary>
@ -31,4 +26,4 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// <value>The subsample ratio of the jpg image.</value>
JpegSubsample? Subsample { get; }
}
}
}

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

@ -1,10 +1,8 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.IO;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Jpeg;
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());
}
}
}
}

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

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

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
{
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)
{

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]
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return ref this.tables[index];
}
get => 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.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder;
using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components;
@ -367,14 +366,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
if (this.ComponentCount == 4)
{
if (this.adobe.ColorTransform == PdfJsJpegConstants.Markers.Adobe.ColorTransformYcck)
{
return JpegColorSpace.Ycck;
}
else
{
return JpegColorSpace.Cmyk;
}
return this.adobe.ColorTransform == PdfJsJpegConstants.Markers.Adobe.ColorTransformYcck
? JpegColorSpace.Ycck
: JpegColorSpace.Cmyk;
}
throw new ImageFormatException($"Unsupported color mode. Max components 4; found {this.ComponentCount}");

Loading…
Cancel
Save