diff --git a/docs/ReFuel.StbImage.md b/docs/ReFuel.StbImage.md new file mode 100644 index 0000000..44da264 --- /dev/null +++ b/docs/ReFuel.StbImage.md @@ -0,0 +1,48 @@ +# ReFuel.StbImage +StbImage is a very common library that has been developed mainly by Sean Barett. +It is one of the easiest to use image loading libraries on the planet +especially for C and C++ users. It is relatively simple to load up and use in +C#, however the C# build system makes it a bit difficult to manage native +dependencies. Therefore this package makes it easy for you and everyone else +who needs a cross platform way to load images. + +Intended OS targets are: +* Windows (x86 and x64) +* Linux (arm32, arm64, x86 and x64) +* MacOS (arm64, x64) + +## Usage +```cs +using ReFuel.Stb; + +// Simply load an image from a Stream or Span (T: unmanaged) source. +using StbImage image = StbImage.Load(source); + +Console.WriteLine("{0}x{1}", image.Width, image.Height); +// StbImage.ImagePointer is a pointer to the image data. +// Pass the image to an unsafe library as is (e.g. OpenGL), or cast it to a span. Currently there is no "safe" way to do this. + +// OpenGL example +GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, image.Width, image.Height, 0, StbiFormatToGLFormat(image.Format, image.IsFloat ? PixelFormat.Float : PixelFormat.UnsignedByte), image.ImagePointer); + +// C# example +struct Pixel +{ + int R, G, B, A; +} + +Span pixels; +unsafe +{ + pixels = new Span(image.ImagePointer, image.Width * image.Height); +} +``` + +### Global Options +| Option | Description | +|--------|-------------| +| `bool StbImage.FlipVerticallyOnLoad` | Flips the image vertically after loading. Practical for uses where a right handed coordinate system is used (e.g. OpenGL) | +| `bool UnpremultiplyOnLoad` | Applies to Apple iPhone PNG images, where the image is sometimes encoded with premultiplied alpha. Reverses this premultiplication. | + +## Calling Stbi directly. +If you wish to call the native Stbi library, call functions in the static class `Stbi`. See `stb_image.h` documentation [online](https://github.com/nothings/stb/blob/master/stb_image.h). diff --git a/docs/getting-started.md b/docs/getting-started.md deleted file mode 100644 index 8b3a794..0000000 --- a/docs/getting-started.md +++ /dev/null @@ -1 +0,0 @@ -# Getting Started \ No newline at end of file diff --git a/docs/introduction.md b/docs/introduction.md deleted file mode 100644 index f6ecaa6..0000000 --- a/docs/introduction.md +++ /dev/null @@ -1 +0,0 @@ -# Introduction \ No newline at end of file diff --git a/docs/toc.yml b/docs/toc.yml index d7e9ea8..a250fb3 100644 --- a/docs/toc.yml +++ b/docs/toc.yml @@ -1,4 +1,2 @@ -- name: Introduction - href: introduction.md -- name: Getting Started - href: getting-started.md \ No newline at end of file +- name: ReFuel.StbImage Guide + href: ReFuel.StbImage.md \ No newline at end of file