Browse Source

Fixed some warnings

pull/1702/head
Dmitry Pentin 5 years ago
parent
commit
a92161f73a
  1. 22
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
  2. 7
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

22
src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

@ -513,7 +513,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
JpegThrowHelper.ThrowInvalidImageContentException("Bad App1 Marker length."); JpegThrowHelper.ThrowInvalidImageContentException("Bad App1 Marker length.");
} }
var profile = new byte[remaining]; byte[] profile = new byte[remaining];
stream.Read(profile, 0, remaining); stream.Read(profile, 0, remaining);
if (ProfileResolver.IsProfile(profile, ProfileResolver.ExifMarker)) if (ProfileResolver.IsProfile(profile, ProfileResolver.ExifMarker))
@ -547,14 +547,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
return; return;
} }
var identifier = new byte[Icclength]; byte[] identifier = new byte[Icclength];
stream.Read(identifier, 0, Icclength); stream.Read(identifier, 0, Icclength);
remaining -= Icclength; // We have read it by this point remaining -= Icclength; // We have read it by this point
if (ProfileResolver.IsProfile(identifier, ProfileResolver.IccMarker)) if (ProfileResolver.IsProfile(identifier, ProfileResolver.IccMarker))
{ {
this.isIcc = true; this.isIcc = true;
var profile = new byte[remaining]; byte[] profile = new byte[remaining];
stream.Read(profile, 0, remaining); stream.Read(profile, 0, remaining);
if (this.iccData is null) if (this.iccData is null)
@ -592,7 +592,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
remaining -= ProfileResolver.AdobePhotoshopApp13Marker.Length; remaining -= ProfileResolver.AdobePhotoshopApp13Marker.Length;
if (ProfileResolver.IsProfile(this.temp, ProfileResolver.AdobePhotoshopApp13Marker)) if (ProfileResolver.IsProfile(this.temp, ProfileResolver.AdobePhotoshopApp13Marker))
{ {
var resourceBlockData = new byte[remaining]; byte[] resourceBlockData = new byte[remaining];
stream.Read(resourceBlockData, 0, remaining); stream.Read(resourceBlockData, 0, remaining);
Span<byte> blockDataSpan = resourceBlockData.AsSpan(); Span<byte> blockDataSpan = resourceBlockData.AsSpan();
@ -607,8 +607,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
Span<byte> imageResourceBlockId = blockDataSpan.Slice(0, 2); Span<byte> imageResourceBlockId = blockDataSpan.Slice(0, 2);
if (ProfileResolver.IsProfile(imageResourceBlockId, ProfileResolver.AdobeIptcMarker)) if (ProfileResolver.IsProfile(imageResourceBlockId, ProfileResolver.AdobeIptcMarker))
{ {
var resourceBlockNameLength = ReadImageResourceNameLength(blockDataSpan); int resourceBlockNameLength = ReadImageResourceNameLength(blockDataSpan);
var resourceDataSize = ReadResourceDataLength(blockDataSpan, resourceBlockNameLength); int resourceDataSize = ReadResourceDataLength(blockDataSpan, resourceBlockNameLength);
int dataStartIdx = 2 + resourceBlockNameLength + 4; int dataStartIdx = 2 + resourceBlockNameLength + 4;
if (resourceDataSize > 0 && blockDataSpan.Length >= dataStartIdx + resourceDataSize) if (resourceDataSize > 0 && blockDataSpan.Length >= dataStartIdx + resourceDataSize)
{ {
@ -619,8 +619,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
} }
else else
{ {
var resourceBlockNameLength = ReadImageResourceNameLength(blockDataSpan); int resourceBlockNameLength = ReadImageResourceNameLength(blockDataSpan);
var resourceDataSize = ReadResourceDataLength(blockDataSpan, resourceBlockNameLength); int resourceDataSize = ReadResourceDataLength(blockDataSpan, resourceBlockNameLength);
int dataStartIdx = 2 + resourceBlockNameLength + 4; int dataStartIdx = 2 + resourceBlockNameLength + 4;
if (blockDataSpan.Length < dataStartIdx + resourceDataSize) if (blockDataSpan.Length < dataStartIdx + resourceDataSize)
{ {
@ -643,7 +643,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
private static int ReadImageResourceNameLength(Span<byte> blockDataSpan) private static int ReadImageResourceNameLength(Span<byte> blockDataSpan)
{ {
byte nameLength = blockDataSpan[2]; byte nameLength = blockDataSpan[2];
var nameDataSize = nameLength == 0 ? 2 : nameLength; int nameDataSize = nameLength == 0 ? 2 : nameLength;
if (nameDataSize % 2 != 0) if (nameDataSize % 2 != 0)
{ {
nameDataSize++; nameDataSize++;
@ -660,9 +660,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// <returns>The block length.</returns> /// <returns>The block length.</returns>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
private static int ReadResourceDataLength(Span<byte> blockDataSpan, int resourceBlockNameLength) private static int ReadResourceDataLength(Span<byte> blockDataSpan, int resourceBlockNameLength)
{ => BinaryPrimitives.ReadInt32BigEndian(blockDataSpan.Slice(2 + resourceBlockNameLength, 4));
return BinaryPrimitives.ReadInt32BigEndian(blockDataSpan.Slice(2 + resourceBlockNameLength, 4));
}
/// <summary> /// <summary>
/// Processes the application header containing the Adobe identifier /// Processes the application header containing the Adobe identifier

7
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

@ -62,10 +62,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
return !TestEnvironment.Is64BitProcess && largeImagesToSkipOn32Bit.Contains(provider.SourceFileOrDescription); return !TestEnvironment.Is64BitProcess && largeImagesToSkipOn32Bit.Contains(provider.SourceFileOrDescription);
} }
public JpegDecoderTests(ITestOutputHelper output) public JpegDecoderTests(ITestOutputHelper output) => this.Output = output;
{
this.Output = output;
}
private ITestOutputHelper Output { get; } private ITestOutputHelper Output { get; }
@ -163,7 +160,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{ {
var cts = new CancellationTokenSource(); var cts = new CancellationTokenSource();
var file = Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, TestImages.Jpeg.Baseline.Jpeg420Small); string file = Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, TestImages.Jpeg.Baseline.Jpeg420Small);
using var pausedStream = new PausedStream(file); using var pausedStream = new PausedStream(file);
pausedStream.OnWaiting(s => pausedStream.OnWaiting(s =>
{ {

Loading…
Cancel
Save