Skip to content
Browse files

Mono.Simd version of InvertColorsEffect.

  • Loading branch information...
1 parent bfe807d commit c9e4b04ffdbb9649be94c5c0a61593811804bd73 @jpobst jpobst committed
Showing with 21 additions and 3 deletions.
  1. +19 −2 Pinta.Core/Effects/InvertColorsEffect.cs
  2. +2 −1 Pinta.Core/Pinta.Core.csproj
View
21 Pinta.Core/Effects/InvertColorsEffect.cs
@@ -26,6 +26,7 @@
using System;
using Cairo;
+using Mono.Simd;
namespace Pinta.Core
{
@@ -41,9 +42,25 @@ public class InvertColorsEffect : BaseEffect
get { return Mono.Unix.Catalog.GetString ("Invert Colors"); }
}
- public override void RenderEffect (ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois)
+ public unsafe override void RenderEffect (ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois)
{
- op.Apply (dest, src, rois);
+ if (!SimdRuntime.IsMethodAccelerated (typeof (Vector16b), "op_Subtraction")) {
+ op.Apply (dest, src, rois);
+ } else {
+ Vector16b invert = new Vector16b (255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0);
+ Vector16b alpha_mask = new Vector16b (0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255);
+
+ Vector16b* srcPtr = (Vector16b*)src.DataPtr;
+ Vector16b* dstPtr = (Vector16b*)dest.DataPtr;
+
+ for (int row = 0; row < (src.Width * src.Height) / 4; row++) {
+ Vector16b srcVal = *srcPtr;
+ *dstPtr = ((invert - srcVal) & invert) | (srcVal & alpha_mask);
+
+ srcPtr++;
+ dstPtr++;
+ }
+ }
}
}
}
View
3 Pinta.Core/Pinta.Core.csproj
@@ -32,6 +32,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="Mono.Simd, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
<Reference Include="gdk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
@@ -148,4 +149,4 @@
<Name>Pinta.Resources</Name>
</ProjectReference>
</ItemGroup>
-</Project>
+</Project>

0 comments on commit c9e4b04

Please sign in to comment.
Something went wrong with that request. Please try again.