Skip to content

Commit

Permalink
some optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
rds1983 committed Apr 18, 2024
1 parent c8d3e7a commit 6e5b491
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 51 deletions.
29 changes: 1 addition & 28 deletions src/Hebron.Runtime/CRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ public static void free(void* a)

public static void memcpy(void* a, void* b, long size)
{
var ap = (byte*)a;
var bp = (byte*)b;
for (long i = 0; i < size; ++i)
*ap++ = *bp++;
Buffer.MemoryCopy(b, a, size, size);
}

public static void memcpy(void* a, void* b, ulong size)
Expand All @@ -62,11 +59,6 @@ public static void memmove(void* a, void* b, long size)
}
}

public static void memmove(void* a, void* b, ulong size)
{
memmove(a, b, (long)size);
}

public static int memcmp(void* a, void* b, long size)
{
var result = 0;
Expand All @@ -84,19 +76,6 @@ public static int memcmp(void* a, void* b, long size)
return result;
}

public static int memcmp(void* a, void* b, ulong size)
{
return memcmp(a, b, (long)size);
}

public static int memcmp(byte* a, byte[] b, ulong size)
{
fixed (void* bptr = b)
{
return memcmp(a, bptr, (long)size);
}
}

public static void memset(void* ptr, int value, long size)
{
var bptr = (byte*)ptr;
Expand Down Expand Up @@ -141,12 +120,6 @@ public static double pow(double a, double b)
return Math.Pow(a, b);
}

public static void SetArray<T>(T[] data, T value)
{
for (var i = 0; i < data.Length; ++i)
data[i] = value;
}

public static double ldexp(double number, int exponent)
{
return number * Math.Pow(2, exponent);
Expand Down
2 changes: 1 addition & 1 deletion src/StbImageSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Description>C# port of the stb_image.h</Description>
<PackageLicenseUrl>Public Domain</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/StbSharp/StbImageSharp</PackageProjectUrl>
<Version>2.27.13</Version>
<Version>2.27.14</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion tests/StbImageSharp.Testing/StbImageSharp.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\StbImageSharp.csproj" />
Expand Down
Binary file added tests/StbImageSharp.Tests/Resources/IDockable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 21 additions & 21 deletions tests/StbImageSharp.Tests/Tests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Hebron.Runtime;
using NUnit.Framework;
using NUnit.Framework;
using StbImageSharp.Tests.Utility;
using System;
using System.IO;
Expand All @@ -26,6 +25,7 @@ public void LoadUnknownFormat(string filename)
});
}

[TestCase("IDockable.png", 715, 426, ColorComponents.RedGreenBlueAlpha)]
[TestCase("sample_1280×853.hdr", 1280, 853, ColorComponents.RedGreenBlue)]
[TestCase("DockPanes.jpg", 609, 406, ColorComponents.RedGreenBlue)]
public void Load(string filename, int width, int height, ColorComponents colorComponents)
Expand All @@ -37,12 +37,12 @@ public void Load(string filename, int width, int height, ColorComponents colorCo
}

Assert.IsNotNull(result);
Assert.AreEqual(result.Width, width);
Assert.AreEqual(result.Height, height);
Assert.AreEqual(result.Comp, ColorComponents.RedGreenBlueAlpha);
Assert.AreEqual(result.SourceComp, colorComponents);
Assert.AreEqual(width, result.Width);
Assert.AreEqual(height, result.Height);
Assert.AreEqual(ColorComponents.RedGreenBlueAlpha, result.Comp);
Assert.AreEqual(colorComponents, result.SourceComp);
Assert.IsNotNull(result.Data);
Assert.AreEqual(result.Data.Length, result.Width * result.Height * 4);
Assert.AreEqual(result.Width * result.Height * 4, result.Data.Length);
}

[TestCase("sample_1280×853.hdr", 1280, 853, ColorComponents.RedGreenBlue)]
Expand All @@ -55,12 +55,12 @@ public void LoadHdr(string filename, int width, int height, ColorComponents colo
}

Assert.IsNotNull(result);
Assert.AreEqual(result.Width, width);
Assert.AreEqual(result.Height, height);
Assert.AreEqual(result.Comp, ColorComponents.RedGreenBlueAlpha);
Assert.AreEqual(result.SourceComp, colorComponents);
Assert.AreEqual(width, result.Width);
Assert.AreEqual(height, result.Height);
Assert.AreEqual(ColorComponents.RedGreenBlueAlpha, result.Comp);
Assert.AreEqual(colorComponents, result.SourceComp);
Assert.IsNotNull(result.Data);
Assert.AreEqual(result.Data.Length, result.Width * result.Height * 4);
Assert.AreEqual(result.Width * result.Height * 4, result.Data.Length);
}

[TestCase("sample_1280×853.hdr", 2000, 1280, 853, ColorComponents.RedGreenBlue, false)]
Expand All @@ -83,10 +83,10 @@ public void Info(string filename, int headerSize, int width, int height, ColorCo
Assert.IsNotNull(result);

var info = result.Value;
Assert.AreEqual(info.Width, width);
Assert.AreEqual(info.Height, height);
Assert.AreEqual(info.ColorComponents, colorComponents);
Assert.AreEqual(info.BitsPerChannel, is16bit ? 16 : 8);
Assert.AreEqual(width, info.Width);
Assert.AreEqual(height, info.Height);
Assert.AreEqual(colorComponents, info.ColorComponents);
Assert.AreEqual(is16bit ? 16 : 8, info.BitsPerChannel);
}

[TestCase("somersault.gif", 384, 480, ColorComponents.RedGreenBlueAlpha, 43)]
Expand All @@ -97,11 +97,11 @@ public void AnimatedGifFrames(string fileName, int width, int height, ColorCompo
var frameCount = 0;
foreach(var frame in ImageResult.AnimatedGifFramesFromStream(stream))
{
Assert.AreEqual(frame.Width, width);
Assert.AreEqual(frame.Height, height);
Assert.AreEqual(frame.Comp, colorComponents);
Assert.AreEqual(width, frame.Width);
Assert.AreEqual(height, frame.Height);
Assert.AreEqual(colorComponents, frame.Comp);
Assert.IsNotNull(frame.Data);
Assert.AreEqual(frame.Data.Length, frame.Width * frame.Height * (int)frame.Comp);
Assert.AreEqual(frame.Width * frame.Height * (int)frame.Comp, frame.Data.Length);

++frameCount;
}
Expand All @@ -111,7 +111,7 @@ public void AnimatedGifFrames(string fileName, int width, int height, ColorCompo
stream.Seek(0, SeekOrigin.Begin);
}

Assert.AreEqual(StbImage.NativeAllocations, 0);
Assert.AreEqual(0, StbImage.NativeAllocations);
}
}
}

0 comments on commit 6e5b491

Please sign in to comment.