Skip to content

Commit

Permalink
Add test suite for effects.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpobst committed Dec 30, 2012
1 parent 0146ab3 commit 474683b
Show file tree
Hide file tree
Showing 101 changed files with 2,321 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<Reference Include="System.Drawing" />
</ItemGroup>
<ItemGroup>
<Compile Include="BitmapExtensions.cs" />
<Compile Include="BitmapWrapper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
77 changes: 77 additions & 0 deletions Pinta.ImageManipulation.UnitTests/BaseTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// BaseTest.cs
//
// Author:
// Jonathan Pobst <monkey@jpobst.com>
//
// Copyright (c) 2012 Jonathan Pobst
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Drawing;
using System.IO;

namespace Pinta.ImageManipulation.UnitTests
{
public abstract class BaseTest
{
protected Bitmap GetSourceImage (string name)
{
var bitmap = new Bitmap (Path.Combine ("SourceBitmaps", name));

return bitmap;
}

protected Bitmap GetExpectedImage (string name)
{
var bitmap = new Bitmap (Path.Combine ("ExpectedBitmaps", name));

return bitmap;
}

protected unsafe void Compare (Bitmap actual, string expected)
{
if (!File.Exists (Path.Combine ("ExpectedBitmaps", expected))) {
actual.Save (Path.Combine (@"C:\Users\Jonathan\Desktop\Bitmaps", expected));
return;
}

var exp_img = GetExpectedImage (expected);

var act_data = actual.LockBits (new System.Drawing.Rectangle (0, 0, actual.Width, actual.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
var exp_data = exp_img.LockBits (new System.Drawing.Rectangle (0, 0, actual.Width, actual.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

var act_ptr = (ColorBgra*)act_data.Scan0;
var exp_ptr = (ColorBgra*)exp_data.Scan0;

var diff = 0;

for (var i = 0; i < actual.Width * actual.Height; i++)
if (*(act_ptr++) != *(exp_ptr++))
diff++;

actual.UnlockBits (act_data);
exp_img.UnlockBits (exp_data);

Assert.AreEqual (0, diff);
}
}
}
47 changes: 47 additions & 0 deletions Pinta.ImageManipulation.UnitTests/Effects/AutoLevelEffectTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// AutoLevelEffectTest.cs
//
// Author:
// Jonathan Pobst <monkey@jpobst.com>
//
// Copyright (c) 2012 Jonathan Pobst
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Pinta.ImageManipulation.Effects;

namespace Pinta.ImageManipulation.UnitTests.Effects
{
[TestClass]
public class AutoLevelEffectTest : BaseTest
{
[TestMethod]
public void AutoLevelEffect1 ()
{
var src = GetSourceImage ("input.png");

var effect = new AutoLevelEffect ();
effect.Render (src);

Compare (src, "autolevel1.png");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// BlackAndWhiteEffectTest.cs
//
// Author:
// Jonathan Pobst <monkey@jpobst.com>
//
// Copyright (c) 2012 Jonathan Pobst
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Pinta.ImageManipulation.Effects;

namespace Pinta.ImageManipulation.UnitTests.Effects
{
[TestClass]
public class BlackAndWhiteEffectTest : BaseTest
{
[TestMethod]
public void BlackAndWhiteEffect1 ()
{
var src = GetSourceImage ("input.png");

var effect = new BlackAndWhiteEffect ();
effect.Render (src);

Compare (src, "blackandwhite1.png");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// BrightnessContrastEffectTest.cs
//
// Author:
// Jonathan Pobst <monkey@jpobst.com>
//
// Copyright (c) 2012 Jonathan Pobst
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Pinta.ImageManipulation.Effects;

namespace Pinta.ImageManipulation.UnitTests.Effects
{
[TestClass]
public class BrightnessContrastEffectTest : BaseTest
{
[TestMethod]
public void BrightnessContrastEffect1 ()
{
var src = GetSourceImage ("input.png");

var effect = new BrightnessContrastEffect ();
effect.Render (src);

Compare (src, "brightnesscontrast1.png");
}

[TestMethod]
public void BrightnessContrastEffect2 ()
{
var src = GetSourceImage ("input.png");

var effect = new BrightnessContrastEffect (80, 20);
effect.Render (src);

Compare (src, "brightnesscontrast2.png");
}
}
}
58 changes: 58 additions & 0 deletions Pinta.ImageManipulation.UnitTests/Effects/BulgeEffectTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// BulgeEffectTest.cs
//
// Author:
// Jonathan Pobst <monkey@jpobst.com>
//
// Copyright (c) 2012 Jonathan Pobst
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Pinta.ImageManipulation.Effects;

namespace Pinta.ImageManipulation.UnitTests.Effects
{
[TestClass]
public class BulgeEffectTest : BaseTest
{
[TestMethod]
public void BulgeEffect1 ()
{
var src = GetSourceImage ("input.png");

var effect = new BulgeEffect ();
effect.Render (src);

Compare (src, "bulge1.png");
}

[TestMethod]
public void BulgeEffect2 ()
{
var src = GetSourceImage ("input.png");

var effect = new BulgeEffect (12, new PointD (20, -20));
effect.Render (src);

Compare (src, "bulge2.png");
}
}
}
58 changes: 58 additions & 0 deletions Pinta.ImageManipulation.UnitTests/Effects/EdgeDetectEffectTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// EdgeDetectEffectTest.cs
//
// Author:
// Jonathan Pobst <monkey@jpobst.com>
//
// Copyright (c) 2012 Jonathan Pobst
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Pinta.ImageManipulation.Effects;

namespace Pinta.ImageManipulation.UnitTests.Effects
{
[TestClass]
public class EdgeDetectEffectTest : BaseTest
{
[TestMethod]
public void EdgeDetectEffect1 ()
{
var src = GetSourceImage ("input.png");

var effect = new EdgeDetectEffect ();
effect.Render (src);

Compare (src, "edgedetect1.png");
}

[TestMethod]
public void EdgeDetectEffect2 ()
{
var src = GetSourceImage ("input.png");

var effect = new EdgeDetectEffect (90);
effect.Render (src);

Compare (src, "edgedetect2.png");
}
}
}
Loading

0 comments on commit 474683b

Please sign in to comment.