# Convert RGB-256 to RGB-float

I am trying to convert colors from RGB (256) to RGB (float) for use in blender. Apparently you just have to divide each value of RGB 256 by 255 (counting the 0 would be 256 values).

For example in Illustrator I have a value R = 229, it would be

229/255 = 0.89

And so with the three RGB values. However, I find that the two colors are different on screen. Why is that happening? If I am doing the calculation wrong, how is the conversion done?

I attach an example of the same color in Illustrator transformed to float in blender. As can be seen, the resulting color is different.

You need input in Hex

Blender uses a linear color space but Illustrator is not.
Blender color value can greater than 1.

## How to convert?

From blender color:
$$\left\{x<0.0031308:12.92\cdot x,1.055\cdot\operatorname{abs}\left(x\right)^{\frac{1}{2.4}}-0.055\right\}\left\{0\le x\le1\right\}$$

To blender color:
$$\left\{x<0.04045:\frac{x}{12.92},\left(\frac{x+0.055}{1.055}\right)^{2.4}\right\}\left\{0\le x\le1\right\}$$

## python verson:

import bpy, math

def to_blender_color(c):
c = min(max(0, c), 255) / 255
return c / 12.92 if c < 0.04045 else math.pow((c + 0.055) / 1.055, 2.4)

def from_blender_color(c):
color = max(0.0, c * 12.92) if c < 0.0031308 else 1.055 * math.pow(c, 1.0 / 2.4) - 0.055
return hex(max(min(int(color * 255 + 0.5), 255), 0))


## Example:

$$x=\frac{229}{255}=0.89803921568627$$

$$(\frac{x+0.055}{1.055})^{2.4}=0.7835377915261935$$

• Thank you very much for the reply. Although the correction on how to do the conversion is right, I discovered that the main problem was in the management of color profiles. The deviation of my calculation (which was done wrong) is very small it does not explain the huge color divergence. Apr 19, 2022 at 7:51
• Please, tell me what do you think, to choose the right answer. Apr 19, 2022 at 7:53

Although the other answer is correct, it does not completely solve the color divergence problem since it is mainly due to the color management settings. Color profiles must be used correctly to achieve consistency between applications.

In this case, just use NONE in display device did the work.

• You can choose to None, but it can't choose Filmic. You will lost the benefits of Filmic transform. And the image result are different.
– X Y
Apr 19, 2022 at 8:12