Skip to content

Commit 6c637af

Browse files
Implement IEquatable<Block8x8F> and check when summing. (#848)
1 parent 617c77c commit 6c637af

5 files changed

Lines changed: 32 additions & 5 deletions

File tree

src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
1414
/// <summary>
1515
/// Represents a Jpeg block with <see cref="float"/> coefficients.
1616
/// </summary>
17-
internal partial struct Block8x8F
17+
internal partial struct Block8x8F : IEquatable<Block8x8F>
1818
{
1919
/// <summary>
2020
/// A number of scalar coefficients in a <see cref="Block8x8F"/>
@@ -538,6 +538,27 @@ public void LoadFromInt16ExtendedAvx2(ref Block8x8 source)
538538
Unsafe.Add(ref dRef, 7) = bottom;
539539
}
540540

541+
/// <inheritdoc />
542+
public bool Equals(Block8x8F other)
543+
{
544+
return this.V0L == other.V0L
545+
&& this.V0R == other.V0R
546+
&& this.V1L == other.V1L
547+
&& this.V1R == other.V1R
548+
&& this.V2L == other.V2L
549+
&& this.V2R == other.V2R
550+
&& this.V3L == other.V3L
551+
&& this.V3R == other.V3R
552+
&& this.V4L == other.V4L
553+
&& this.V4R == other.V4R
554+
&& this.V5L == other.V5L
555+
&& this.V5R == other.V5R
556+
&& this.V6L == other.V6L
557+
&& this.V6R == other.V6R
558+
&& this.V7L == other.V7L
559+
&& this.V7R == other.V7R;
560+
}
561+
541562
/// <inheritdoc />
542563
public override string ToString()
543564
{

src/ImageSharp/Formats/Jpeg/Components/Decoder/QualityEvaluator.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,13 @@ public static int EstimateQuality(Block8x8F[] quantizationTables)
8484
for (int i = 0; i < quantizationTables.Length; i++)
8585
{
8686
ref Block8x8F qTable = ref quantizationTables[i];
87-
for (int j = 0; j < Block8x8F.Size; j++)
87+
88+
if (!qTable.Equals(default))
8889
{
89-
sum += qTable[j];
90+
for (int j = 0; j < Block8x8F.Size; j++)
91+
{
92+
sum += qTable[j];
93+
}
9094
}
9195
}
9296

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ public partial class JpegDecoderTests
5252
public static readonly TheoryData<string, int> QualityFiles =
5353
new TheoryData<string, int>
5454
{
55-
{ TestImages.Jpeg.Baseline.Calliphora, 80},
56-
{ TestImages.Jpeg.Progressive.Fb, 75 }
55+
{ TestImages.Jpeg.Baseline.Calliphora, 80 },
56+
{ TestImages.Jpeg.Progressive.Fb, 75 },
57+
{ TestImages.Jpeg.Issues.IncorrectQuality845, 99 }
5758
};
5859

5960
[Theory]

tests/ImageSharp.Tests/TestImages.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ public static class Issues
172172
public const string OrderedInterleavedProgressive723C = "Jpg/issues/Issue723-Ordered-Interleaved-Progressive-C.jpg";
173173
public const string ExifGetString750Transform = "Jpg/issues/issue750-exif-tranform.jpg";
174174
public const string ExifGetString750Load = "Jpg/issues/issue750-exif-load.jpg";
175+
public const string IncorrectQuality845 = "Jpg/issues/Issue845-Incorrect-Quality99.jpg";
175176

176177
public static class Fuzz
177178
{
2.17 MB
Loading

0 commit comments

Comments
 (0)