Color conversion between color spaces
I'm creating a library that allows conversion between the following color spaces:
HSV, HLS, RGB, CMYK, HEX
Up until now, I have the following conversions implemented:
HSV -> HLS
HSV -> RGB
HSV -> CMYK (HSV -> RGB -> CMYK :: see NB)
RGB -> HSV
RGB -> HLS
RGB -> CMYK
RGB -> HEX
HLS -> RGB
HLS -> HSV
HLS -> CMYK (HLS -> RGB -> CMYK :: see NB)
CMYK -> RGB
CMYK -> HSV (CMYK -> RGB -> HSV :: see NB)
CMYK -> HLS (CMYK -> RGB -> HLS :: see NB)
NB: HSV and HSL can't be directly converted to CMYK because they're not absolute color spaces. They need elements of the RGB space so that the conversion to CMYK is meaningful. (CMYK color to HSV color directly)
Right now, I have to implement all the HEX conversions:
HEX <-> R开发者_开发技巧GB
HEX <-> HSV
HEX <-> HLS
HEX <-> CMYK
Converting between HEX and RGB is simple and I have it implemented. What bothers me are the HEX <-> HSV and HEX <-> HLS conversions. Is there a direct way to convert HEX to HSV and HSL or do I have to use HEX -> RGB -> HSV/HLS? What about HEX <-> CMYK?
Any help would be greatly appreciated.
Typically the HEX values are just HEX representations of each individual channel's values concatenated together. If all of your colors are represented by 8 bits and you are looking for a HEX representation that can be used in HTML it would be like this:
Color 8 bit HEX value --------------------------------- RGB 255,128,0 FF8000 CMYK 255,128,255,128 FF80FF80
精彩评论