https://github.com/crozone/blursharp
Blurhash implementation for C#
https://github.com/crozone/blursharp
Last synced: about 1 year ago
JSON representation
Blurhash implementation for C#
- Host: GitHub
- URL: https://github.com/crozone/blursharp
- Owner: crozone
- License: mit
- Created: 2020-02-21T00:28:56.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-16T07:24:23.000Z (over 6 years ago)
- Last Synced: 2025-03-27T19:39:39.925Z (over 1 year ago)
- Language: C#
- Homepage:
- Size: 1.26 MB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BlurSharp
Blurhash implementation for C#
## Progress report
What is done:
* BlurHash core encoder
* Encoder wrapper for `System.Drawing`
* Encoder tests for a set of testing images, using all possible component values.
What is TODO:
* Decoder
* Decoder wrapper for `System.Drawing`
* Decoder tests
## Performance
### Results
Currently, this implementation is ~25x faster than the reference C implementation.
On my reference machine, BlurSharp (Release) can encode all six reference images in 1,1 to 8,8 component forms (64 combinations per image) in under 5 seconds. The C implementation (compiled with -O2) does the same in 125 seconds.
### How
The library has been written with the `System.Numerics` vector instructions, specifically `Vector3` is used heavily to speed up operations. A precalculated lookup table is used to do SRGB to Linear float conversions.
`Span` is also used extensively in order to reduce object allocations and unnecessary copying of buffers.
For example, `Span` allows for the encoding of `System.Drawing` bitmaps without copying the image buffer. Further work needs to be done to allow core support for different pixel formats, so that `Bitmap.LockBits` doesn't have to do work internally to present the image as `PixelFormat.Format24bppRgb`.
The library also leverages the new `Span` based safe `stackalloc` keyword to avoid heap allocations. Depending on how much stack you allow the encoder to use, an image can be encoded without a single object allocation. This can reduce GC pressure under heavy workloads.
Performance TODO:
* Potentially use parallel processing (questionable benefit for web scenarios)