Skip to content

Commit 9848ede

Browse files
Merge pull request #1 from Walter-Rabbit/feat/tests
Feat/tests
2 parents 627a9ff + f92d66e commit 9848ede

15 files changed

Lines changed: 141 additions & 7 deletions

Source/RedPixel.Core/ImageFormat.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ namespace RedPixel.Core;
55

66
public class ImageFormat
77
{
8+
public static readonly ImageFormat Png = new(
9+
"png",
10+
HeaderMatchFuncFactory.Create(new byte[] { 137, 80, 78, 71, 13, 10, 26, 10 }));
11+
812
public static readonly ImageFormat Pnm = new(
913
"pnm",
1014
HeaderMatchFuncFactory.Create(new byte[] { 80, 53 }, new byte[] { 80, 54 }),
1115
"pgm", "ppm");
1216

13-
public static readonly ImageFormat Png = new(
14-
"png",
15-
HeaderMatchFuncFactory.Create(new byte[] { 137, 80, 78, 71, 13, 10, 26, 10 }));
16-
1717
private readonly Func<Stream, bool> _matchFunc;
1818

1919
private ImageFormat(string format, Func<Stream, bool> matchFunc, params string[] alternatives)

Source/RedPixel.Core/Models/Bitmap.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Buffers;
2-
using RedPixel.Core.Colors;
1+
using RedPixel.Core.Colors;
32
using RedPixel.Core.Colors.ValueObjects;
43
using RedPixel.Core.Tools;
54

@@ -61,7 +60,7 @@ public double[][] GetHistogram(int fromX, int toX, int fromY, int toY)
6160

6261
for (int i = 0; i < 3; i++)
6362
{
64-
histogramValues[i] = new double[BytesForColor*256];
63+
histogramValues[i] = new double[BytesForColor * 256];
6564
histogramValues[i].AsSpan().Fill(0);
6665
}
6766

@@ -126,4 +125,28 @@ public void ApplyContrastAdjustment(float ignorePart)
126125
}
127126
}
128127
}
128+
129+
public override bool Equals(object obj)
130+
{
131+
if (obj is not Bitmap bitmap)
132+
{
133+
return false;
134+
}
135+
136+
const double eps = 1;
137+
for (int y = 0; y < Height; y++)
138+
{
139+
for (int x = 0; x < Width; x++)
140+
{
141+
if (Math.Abs(Matrix[y, x].FirstComponent - bitmap.Matrix[y, x].FirstComponent) > eps ||
142+
Math.Abs(Matrix[y, x].SecondComponent - bitmap.Matrix[y, x].SecondComponent) > eps ||
143+
Math.Abs(Matrix[y, x].ThirdComponent - bitmap.Matrix[y, x].ThirdComponent) > eps)
144+
{
145+
return false;
146+
}
147+
}
148+
}
149+
150+
return true;
151+
}
129152
}
701 KB
Loading
276 Bytes
Loading
546 Bytes
Loading
123 Bytes
Loading
1.23 MB
Loading
210 Bytes
Loading
774 Bytes
Loading
127 Bytes
Loading

0 commit comments

Comments
 (0)