Hello everyone,
I would like to introduce StbSharp: https://github.com/rds1983/StbSharp
Which is open-source(MIT licensed) C# port of famous framework Stb: https://github.com/nothings/stb
Right now, though, it is quite young. Only stb_image.h is ported and not completely; it can load only .png and .jpg files.
As you can see the StbSharp is somewhat slower. But on the other hand it gives consistent result of the run-time image loading through different platforms.
It is important to note, that StbSharp is not manual port. It has been ported using another open-source(MIT also) project called Sichem: https://github.com/rds1983/Sichem
Sichem is C to C# code converter. It uses libclang to build the syntax tree from C and generates the C# code from it. Right now, Sichem works only with stb_image.h. However if required it could be tuned to port other C projects.
Now, let’s return to StbSharp. My first priority is to add other images types supported by stb_image.h (gif, pic, psd, etc). Then I’ll consider taking another stb library (i.e. stb_truetype.h).
Interesting to see. Looking at the code, you may be able to get a small improvement at Image.cs(303) by using fixed on the data array as it will be doing bounds checking on every access. You may also get a benefit from Marshal.Copy from an IntPtr to managed array.
You may be interested to see there is already a port of stb_truetype in the form of TrueTypeSharp.
So the loading time is 151 ms for Texture2D.FromStream and 227 for StbSharp. Overally StbSharp is about 1.6 times slower than Texture2D.FromStream. And there was same proportion on WindowsDX.
Great there is TrueTypeSharp already. Probably I’ll port something else then.
Hi everyone,
I would like to post update on this project. As there was significant progress during the last year.
Now following stb libraries had been ported: stb_image.h, stb_image_write.h, stb_image_resize.h, stb_dxt.h, stb_vorbis.c and stb_truetype.h
As there was some confusion, I would like to clarify, that StbSharp is port. It’s not wrapper. I took original C code and converted it to C#. So StbSharp doesnt require any native binaries.
I’ve made a small MG sample(requires MG to be installed). It demonstrates StbSharp in action: it draws image loaded with StbImage, plays music loaded with StbVorbis and draws text from font loaded with StbTrueType.
Link to the sample: https://github.com/rds1983/StbSharp/releases/download/0.6.5.31/MonoGameWithStb.zip
Unfortunately, no.
Sichem ports code from C to C#, while IMGUI is C++.
There’s another pure C GUI lib called nuklear, which I’ve ported already: https://github.com/rds1983/NuklearSharp
I would like to post update for the project.
Latest StbSharp is no longer monolithic, but had been split into separate projects: https://github.com/StbSharp
Each project is avaiable at the nuget with the version corresponding to the one it had been ported from(i.e. StbImageSharp version 2.22 means it was ported from stb_image.h’s version 2.22).
Also I’ve kept only projects that are at least somewhat useful to the developers. Which are StbImageSharp, StbImageWriteSharp, StbTrueTypeSharp and StbVorbisSharp. Other stb libs seems to have almost zero interest in them.
Though if anyone would like any other stb lib to be ported, then, please, let me know.
Made performance testing framework that runs over ~800 images and tries to load 10 times each with StbImageSharp, then with native stb_image.h called through C++/CLI(Stb.Native), then with SixLabors ImageSharp.
Here are results(total loading times):