It is very clear question, but I’ve done a lot of research and didn’t find answer. StackOverflow question as this or this are about jpeg converting. This is about python build-in library.
So, how to convert sRGB to AdobeRGB and vice versa??? I mean a mathematical function, that convert 3 bytes to 3 bytes. No jpges, and so on. Just mathematical function to convert colors using pen and paper.
Yes, photoshop does it in fact and there are some strange online calculators, that show another result.
Why can’t I find a simple formula in google?
I got to thinking, that I don’t know something and there is no straight answer to my question.
I will be very grateful if someone can describe, what’s going on or give formula.
UPDATE
Large array of results for integer rgbs will be also correct answer.
2
Answers
It’s a little complicated ones, so please read spec sheets if you need formulas.
sRGB (PDF)
https://www.w3.org/Graphics/Color/srgb
Adobe RGB (Oct.12,2004 draft) (PDF)
http://www.color.org/adobergb.pdf
Adobe RGB (1998) (PDF)
https://www.adobe.com/digitalimag/pdfs/AdobeRGB1998.pdf
Wiki is also good.
sRGB
https://en.wikipedia.org/wiki/SRGB_color_space
Adobe RGB
https://en.wikipedia.org/wiki/Adobe_RGB_color_space
For testing, check color conversion settings.
Software specific conversion may occur.
(mainly if out of range, but in some settings, not out of range values also be affected)
ex.
Photoshop color settings
http://help.adobe.com/en_US/creativesuite/cs/using/WS6A727430-9717-42df-B578-C0AC705C54F0.html#WS6078C298-CB20-4dc8-ACD4-D344110AA026
Related readings
http://www.color-management-guide.com/conversion-mode-perceptual-relative-colorimetric-rendering-intent.html
Using XYZ is more flexible concerning about converting to other color spaces than direct (between sRGB and Adobe RGB) conversion.
RGB color space
https://en.wikipedia.org/wiki/RGB_color_space
Conversion between sRGB and XYZ contains non-linear operation.
So, direct conversion between sRGB and Adobe RGB is difficult.
See Specification of the transformation section in wiki of sRGB.
(The reverse transformation part.)
from spec sheet
RL for linear(XYZ(D65)), R for sRGB in this formula.
Green and blue also have same formulas.
Not preventing direct conversion between other color spaces but,
conversion between Adobe RGB and XYZ also contains non-linear operation.
(Rounding to int.)
More precisely, it is Adobe RGB(in float values) to Adobe RGB(in int values) conversion.
NB: Intended white points for them are different.
(as there purpose are different. sRGB for display, Adobe RGB for photos.)
And conversion matrix in spec sheets are for D65(sRGB) and D50 or D65(Adobe RGB).
We should think about 3 things.
RGB value itself, value range (and correctness of color) of display, and viewing environment.
Ex.
1.Conversion matrix (and other formulas): RGB value
2.Display white and black point: value range of display
3.Ambient illumination chromaticity: viewing environment
Only 1(matrix and formulas) has effects in converting values,
but 2 and 3 also important because they decide how we can see RGB values.
NB: with ICC profile, if 2(display settings) is stored, it counts on.
If display range is narrow than RGB value can represent, they will be clipped (while displaying).
If range is not proper, white or black maybe seen as gray, etc.
If ambient illumination chromaticity is different from the one conversion matrix and formulas are intended for, we will see different colors.
Conversion matrix
(This is important, as having effects on RGB converted values.)
from sRGB (Showing conversion matrix is for D65.)
In Adobe RGB(1998) spec sheet, two types of conversion matrices (and formulas) exist.
4.3.1~ (without ICC): D65
4.3.6~ (with ICC): D50
from Adobe RGB(1998)
(for images with ICC profile etc.)
NB: caution white is not (1.0, 1.0, 1.0).
from Adobe RGB(1998)
(for images without ICC profile etc.)
This maybe good for calc (and white point for sRGB is pre-known(and it is D65)).
NB:White (x=0.3127, y=0.3290) corresponds to D65.
(See section 4.2.1 Reference Display White Point.)
Ambient illumination chromaticity
(Do not confuse with display white point. This has effects on color correctness we can see.)
from Adobe RGB (draft)
from Adobe RGB (1998)
Display white point
(Do not confuse with ambient illumination chromaticity. This is about range which display can show up.)
from sRGB
from Adobe RGB (1998)
from Adobe RGB (1998) (for information.)
from sRGB
(NB: sRGB is defined in IEC 61966-2-1)
This means it is not per-defined which white(D65 etc) is used for displaying sRGB, so store it in ICC profile.
Standard illuminant (wiki) (Just for info. Not part of this conversion.)
https://en.wikipedia.org/wiki/Standard_illuminant
Here is Python code to implement the formulas. As noted in the comments, you convert from one color space to XYZ (normalized) then from XYZ to the new color space. I’m not 100% happy with the accuracy of these functions, but it should get you in the ballpark. As I come up with refinements I’ll edit them into the answer.