help please: is there a fast way to convert srgb values to linear ?

I use RGB-Linear2.blend, that should be version 2.
Yes, if you can make a script that changes the colors directly on the selected object I guess it is more easy to test.

Setting the display device (none, srgb, rec709) is needed to correctly use the CM. If you don’t need the CM then you can leave display device to none.

2.4x uses the srgb space, while 2.7x can use srgb or rec709 depending on the display device you use.


ok let me till this night
will make a new version
sorry never really look at this bug for color
have a lot of old 2.49 files but I always add my own cycles mat !
so no color problems !

happy bl

here is new version which changes all material diffuse color on selected objects

test it and let me know if OK!

RGB-Linear4.blend (120 KB)

2 buttons version

RGB-Linear5.blend (120 KB)

happy bl

AWESOME !! :slight_smile:

srgb to linear works just fine, I can import any srgb model and convert it to linear values !
unfortunately linear to srgb seems to have some problems, it doesn’t convert well

test it yourself with the dark red value

dark red srgb = 0.5,0,0
dark red linear = 0.214,0,0

so if you convert 0.5,0,0 from srgb to linear you get 0.214,0,0 that is right
while if you convert 0.214,0,0 from linear to srgb you get 0.95,0,0 that is wrong since you should get 0.5,0,0

may be you didn’t code correctly the math in python …

/* LINEAR TO SRGB
/* this assumes red,green,blue values from 0 to 1
/* and convert linear red to srgb red
/* you need to do the same for green and blue
L = red
if L <= 0.0031308 then S = L12.92 else S = 1.055(L^(1/2.4))-0.055
red = S

the order of evaluation is important:
you first need to do 1/2.4 that is about 0.4166
then power 0.214 (L) by 0.4166 that is about 0.5260
then multiply 0.5260 by 1.055 that is about 0.5549
then subtract 0.055 from 0.5549 that is about 0.5

I gave a look at your python code and I found the bug, you should rewrite the lin2s1 function as follows:

def lin2s1(x):

     a = 0.055
     if x &lt;=0.0031308:
           y = x * 12.92
     elif 0.0031308 &lt; x &lt;= 1 :
           y = 1.055*(x**(1.0/2.4)) - 0.055

     return y

this way it works fine :slight_smile:

1 Like

nice catch
did u correct it

I already replace the version 3 with a new one anyway

so does seems to work as expected
show us some test so people can see the difference !

thanks
happy bl

WELL DONE !! It works perfect ! :slight_smile:

One minor bug is that it converts the whole scene instead of the selected object only. But this is easy to work around just loading a single object at a time to convert it.

Also, if you would accept a suggestion, to me the script interface seems over complicated. Just having two buttons “srgb to linear” and “linear to srgb” would do the job.

Anyway, now your script works perfect and it is usable for production !!

The attached image shows the difference between linear and srgb colors. Linear colors are much darker than srgb.

So if you import a srgb model in the scene (blend 2.4x,dae,fbx,obj,3ds etc), Blender reads it as linear and the colors appear much brighter than in the original model.

Now using your script the user can convert between srgb and linear so to fix the Blender behaviour when needed.

To import from srgb format (blend 2.4x,dae,fbx,obj,3ds etc)

  • turn off CM by setting display device to none
  • import the srgb model
  • run the srgb_to_linear script
  • turn on CM by setting display device to srgb

To export to srgb format (blend 2.4x,dae,fbx,obj,3ds etc)

  • turn off CM
  • run the linear_to_srgb script
  • export the model

Beware, this applies to Blender 2.5x-2.73 (current version at this time). The Blender team said that they will add CM capabilities to i/o scripts in a future release (see https://developer.blender.org/T43025). So this issue may not apply to future versions of Blender.

Also, some external i/o scripts could already handle the srgb-linear conversion so you have to check out before exporting. Anyway, you have the script if you need it.

bye, Alessandro :slight_smile:


another thing like that I saw yesterday
doing some model I use the color picker in the viewport on background image
and it gets the right color I think!
but I have to manually increase the color intensity
is it same problem and possible to correct mat be ?

I will look at that problem for all mat
not certain I thought it did only on the selected ob !

thanks
happy bl

corrected and made new version #4
I made certain that mat change now is only for the selected ob !

check it out let me know if all OK!

also made a 2 buttons version
try it and let me know what you think?
see post #22

happy bl

Yes, the color picker assumes everything it reads is linear so it fails reading srgb colors. The same as i/o scripts fail reading srgb materials.

The only way to use the color picker with textures is to turn off CM by setting display device to none.

But this is not a bug in the CM or in the texture (meta tag color space). The texture is correctly defined as srgb and the CM does its job fine by displaying it correctly. It is a bug in the color picker so you can’t fix it. There is no way.

Anyway, your new two button script works just fine ! It only converts selected objects and it is very easy to use. I tested it and I didn’t find any bug at all. GREAT JOB :slight_smile:


I tested the color picker with textures and as far as I can see there isn’t any issue with it. It correctly converts srgb texture values to linear values.

To see the real colors (no lights and shadows) you have to set the shading to shadeless. I used a shadeless sphere as object to test the picker.

Also, to see the srgb value, you need to access the HSV or HEX tabs of the color panel. This is because the RGB tab shows linear values, while the HSV and HEX tabs show the dispay space values (srgb when display device is set to srgb).

This behaviour may be confusing for the user and indeed it is. I already pointed out this issue in my post to the blender team (see https://developer.blender.org/T43025) and they say they will update the color picker to allow the user choose the color space for all tabs. This will happen in a future release though, together with i/o scripts CM.

Anyway, your new two button script works just fine ! It only converts selected objects and it is very easy to use. I tested it and I didn’t find any bug at all.

GREAT JOB :slight_smile:


color picker

do you mean it will pick right color if I use HSV then RBG ?


HSV at least looks brighter!

thanks

If you don’t mind I need the blend file to check it so I can give you a correct answer.

From what I see in the picture may be you simply didn’t pick the two colors from the same texture pixel. Since the texture is a photo of course there are slight variations of colors depending on the pixel you pick up. Also, the two cubes you use to compare the colors must be shadeless to correctly evaluate the picker. Anyway this is only a guess, if you can post the scene I can look at it better.

bye, Alessandro :slight_smile:

p.s. I attached my scene I used above for picker testing. It uses a shadeless sphere (to avoid lighting variations) and a bmp image (to avoid jpg color variations). You can use it to test the picker the correct way. When loading the scene be sure to check the “scene interface” option so to have everything at its place as intended.

picker.blend (110 KB)

yesterday I got 2.73a
and looks like the color test I did does not work anymore!
anyway this is a small detail and don’t use it often!

as long as script works well
that was the main goal !

happy bl

2.73a is amazing :slight_smile:

If it may help, you can use my scene above picker.bend for testing. I’m quite sure the color picker works fine though.

I would add that your script could be very useful even for paint artists used to Painter or Photoshop. Because it allows to assign plain srgb colors to the 3d model out of the CM, then convert the colors to linear for rendering.

The color space used by Painter, Photoshop and any paint application around is srgb. So paint artists are used to the srgb color space. Linear colors don’t make sense for them because it is a color space they don’t know.

Unfortunately at this time (Blender 2.73a) there is no way for a paint artist to input RGB values in srgb space inside the CM. This is because the RGB tab of the color panel only accepts linear values. So in Blender it doesn’t exist a RGB input for red,green,blu values in srgb space.

So finally your script is essential for two very important tasks:

  • import/export 3d formats that use srgb colors (blend 2.4x,dae,fbx,obj,3ds etc)
  • allow paint artists to assign RGB values in the traditional srgb color space they are used to

p.s. marked as [SOLVED]
p.p.s. I reported your script to the Blender team https://developer.blender.org/T43025

Except there are a number of issues.

I would encourage anyone scripting to leverage the OCIO calls to perform the transfer curve forward / reverse transfos for sRGB, not roll their own via a formula.

Second, it should be made clear that sRGB is more than just a transfer curve, but also a set of primaries.

Needless to say, isolating any color transform outside of a color management system will end up causing more problems than it seeks to solve.

@troy_s
I totally agree with you 100% on everything you said.

Indeed, this script was fast coded by RickyBlender to be used as a workaround until the Blender team “fixes” the CM.

I say “fixes” in quotes because it is not an issue in the CM code itself, but it is rather an issue in the i/o scripts that are not CM aware (unfortunately including blend 2.4x i/o and dae/fbx i/o).

@everyone
Anyway, the Blender team is aware of this and seems it is going to fix it in a next release. See https://developer.blender.org/T43025

from Antony Riakiotakis (Color Picker coder):
“The problem is to allow users to specify if material color values in assets are to be converted into linear. As @brecht said and @sergey explained this will not fix lighting, but at least some artists should be able to get something close to the original color.”

“I will also try to improve the color pickers so users can choose the space where things are displayed.”

from Sergey Sharybin (Color Management coder):
“The plan here i think would be to add some utility function in bpy so importers/exporters might do color conversion if they want. But such conversion on io shouldn’t be something what belongs to core (meaning individual io scripts will deal with this).”

@forum moderators
If it is agreed by the forum moderators, it would be useful to make this thread sticky. Both to make the beginner artist aware of the issue, and to make the workaround more visible and available to the community. As actually this script is the only way to “fix” things up.

@ Padone
to have this as a sticky you should contact the moderator team
and mat be add sticky to material and texture forum!

also it looks like there many more color scheme that exist
look at wiki for RBG
don’t know if there are equations for the other color scheme
would be possible to add these to the script !

any idea when they are going to correct this ?
I mean very soon or in 6 months ?

there is this site here
different color palette formulas
http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html

I could make a new algo for these if it is worth it !

happy bl

I will restate again, as apparently I wasn’t clear.

This is the wrong approach. Not just slightly wrong, but completely.

To perform a correct color conversion, a script must be absolutely certain of the correct input space and output space. OCIO tracks these assumptions, and controls the reference space.

The only method to correctly achieve a color transform is within the context of the color management system.

So, in order to correctly perform these actions withing Blender, for example, you must use the OCIO calls, as opposed to formulas for transfer.

Even if one is outside of Blender, it is still vastly wiser to use OCIO.

don’t know if it can be done with script !

cannot find much on this OCIO thing
any good link on this ?

i know there is always the question of the Color Temperature of the screen
to be taken into account which depends on the Screen monitor you have too!

hopefully this will be taken care soon by Dev’s

happy bl