praeclarum / NGraphics

NGraphics is a cross platform library for rendering vector graphics on .NET. It provides a unified API for both immediate and retained mode graphics using high quality native renderers.
MIT License
710 stars 133 forks source link

Store color as HSV instead of RGB #70

Open Orillion360 opened 7 years ago

Orillion360 commented 7 years ago

Why: NGraphics.Color stores data in 3 bytes called R, G, B. This method of data storage is destructive.

Explanation: If you convert the HSV value black, X, Y, 0 (where X and Y are variables), it will get converted to 0, 0, 0 in RGB. When you attempt to convert back the color to HSV, it does not have sufficient data to reconstruct the original HSV value and will default to 0, 0, 0 in HSV, thereby losing the origin X and Y values. However if the data was stored as HSV, it can easily reconstruct the original RGB value.

This method of storing also results in a lot of rounding errors for all the Hue, Saturation, and Value values.