-
-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
193 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using NAPS2.Pdf; | ||
using Xunit; | ||
|
||
namespace NAPS2.Sdk.Tests.Pdf; | ||
|
||
public class JpegFormatHelperTests | ||
{ | ||
[Fact] | ||
public void Jfif() | ||
{ | ||
var header = JpegFormatHelper.ReadHeader(new MemoryStream(ImageResources.dog)); | ||
Assert.NotNull(header); | ||
Assert.Equal(788, header.Width); | ||
Assert.Equal(525, header.Height); | ||
Assert.Equal(3, header.NumComponents); | ||
Assert.Equal(72, header.HorizontalDpi); | ||
Assert.Equal(72, header.VerticalDpi); | ||
Assert.True(header.HasJfifHeader); | ||
} | ||
|
||
[Fact] | ||
public void JfifGrey() | ||
{ | ||
var header = JpegFormatHelper.ReadHeader(new MemoryStream(ImageResources.dog_gray)); | ||
Assert.NotNull(header); | ||
Assert.Equal(788, header.Width); | ||
Assert.Equal(525, header.Height); | ||
Assert.Equal(1, header.NumComponents); | ||
Assert.Equal(72, header.HorizontalDpi); | ||
Assert.Equal(72, header.VerticalDpi); | ||
Assert.True(header.HasJfifHeader); | ||
} | ||
|
||
[Fact] | ||
public void Exif() | ||
{ | ||
var header = JpegFormatHelper.ReadHeader(new MemoryStream(ImageResources.dog_exif)); | ||
Assert.NotNull(header); | ||
Assert.Equal(788, header.Width); | ||
Assert.Equal(525, header.Height); | ||
Assert.Equal(3, header.NumComponents); | ||
Assert.Equal(72, header.HorizontalDpi); | ||
Assert.Equal(72, header.VerticalDpi); | ||
Assert.False(header.HasJfifHeader); | ||
Assert.True(header.HasExifHeader); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Buffers.Binary; | ||
|
||
namespace NAPS2.Util; | ||
|
||
public class EndianReader | ||
{ | ||
private readonly bool _reverseEndianness; | ||
|
||
public EndianReader(bool reverseEndianness) | ||
{ | ||
_reverseEndianness = reverseEndianness; | ||
} | ||
|
||
public int ReadInt16(byte[] buf, int offset) | ||
{ | ||
var value = BitConverter.ToInt16(buf, offset); | ||
if (_reverseEndianness) value = BinaryPrimitives.ReverseEndianness(value); | ||
return value; | ||
} | ||
|
||
public int ReadInt32(byte[] buf, int offset) | ||
{ | ||
var value = BitConverter.ToInt32(buf, offset); | ||
if (_reverseEndianness) value = BinaryPrimitives.ReverseEndianness(value); | ||
return value; | ||
} | ||
} |