Chaos Corona Forum

Chaos Corona for 3ds Max => [Max] I need help! => Topic started by: Nate101 on 2017-07-10, 00:41:21

Title: CoronaColor - Formula to convert 32-bit Linear RGB to sRGB 8-bit?
Post by: Nate101 on 2017-07-10, 00:41:21
Hi all,

Wanted to see if someone could help me, I'm trying to write a mathematical formula which converts an RGB value from 32-bit linear to sRGB 8-bit (and vice versa).  In essence, I just want to mimic what the CoronaColor picker does with its color preview.  Using the color below as an example, I'd like to know how Corona converts the linear (56,244,6) into the 8-bit preview (128,250,46).  Is there a formula I can use to do this conversion?  I wasn't able to find anything in the help files on this subject.

(http://nateprototype-com.stackstaging.com/CoronaForum/ColorPicker.jpg)

Title: Re: CoronaColor - Formula to convert 32-bit Linear RGB to sRGB 8-bit?
Post by: cecofuli on 2017-07-10, 01:11:49
You need to use Corona Color Picker =)
Title: Re: CoronaColor - Formula to convert 32-bit Linear RGB to sRGB 8-bit?
Post by: Nate101 on 2017-07-10, 01:38:17
You need to use Corona Color Picker =)

You're right I should, but not sure it would get me any closer to answering my original question?  I'm doing the color conversion outside 3ds Max, and trying to mimic what Corona is doing in the example I provided.
Title: Re: CoronaColor - Formula to convert 32-bit Linear RGB to sRGB 8-bit?
Post by: Ondra on 2017-07-10, 10:49:07

inputFloat = input8Bit/255.f
outputFloat = pow(inputFloat, 1/2.2f) or pow(inputFloat, 2.2f) (depends on direction)
output8Bit = uint8(outputFloat * 255.f)
Title: Re: CoronaColor - Formula to convert 32-bit Linear RGB to sRGB 8-bit?
Post by: Nate101 on 2017-07-11, 03:28:48

inputFloat = input8Bit/255.f
outputFloat = pow(inputFloat, 1/2.2f) or pow(inputFloat, 2.2f) (depends on direction)
output8Bit = uint8(outputFloat * 255.f)

Thanks Ondra!