
PixelMap: Sleeker, Faster Bitmap Editing for .NET - ruarai
http://www.ruarai.com/pixelmap.html
======
kevingadd
Nice to see a straightforward stripped down image manipulation library.

It's important not to do too much HSV/HSL color manipulation with an API like
this, though - unlike RGBA, which can be altered independently, the Hue/etc
properties on the Color type in this library are lossy, because you can't
cleanly roundtrip between integer RGBA and HSV (of any precision, really). If
you use high precision floats you can roundtrip somewhat more reliably, but
it's still a bad bet. So if you first change the Hue and then change the
Saturation, you'll get some really nasty artifacts at some points in the color
space. (For example, if you try to set the Hue of solid black, it won't do
anything.)

A better approach for HSV is to just have a value that represents a point in
the HSV color space, and convert it once to/from RGBA when you need to. Do as
much in a given color space as you can. (Also, when dealing with HSV you
simply need more precision than 24bpp rgb. I typically used 16 bits per
channel to reduce the amount of error.)

For cases where you want to do HSV and you care about performance, you could
probably use the new .NET SIMD types like System.Numerics.Vector4. Then you'd
be getting a perf boost from native SIMD operations and you could carry your
channels around as float32.

~~~
ChrisLomont
For 8 bit RGBA, using around 10 bit HSV, you can round trip if you're very
careful in your code.

------
mdip
Love it.

I ran into the awful performance of the Get/SetPixel methods doing some work
with font rendering a while back. The solution I chose ended up similar to the
StackOverflow post on linked on the page but it made the code unmaintainable
enough that I just abandoned it entirely[1]. I might revisit that next month.

[1] It was a weekend/side project so I was revisiting it after several days
and I remember thinking "WTF was I trying to accomplish here again?"

------
jpobst
Nice! If you're interested in pixel manipulation in .NET, there's also
Pinta.ImageManipulation built out of the source code for Paint.NET and Pinta.

[https://github.com/PintaProject/Pinta.ImageManipulation](https://github.com/PintaProject/Pinta.ImageManipulation)

