Author Topic: CoronaColor - Formula to convert 32-bit Linear RGB to sRGB 8-bit?  (Read 4869 times)

2017-07-10, 00:41:21

Nate101

  • Active Users
  • **
  • Posts: 33
    • View Profile
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.





2017-07-10, 01:38:17
Reply #2

Nate101

  • Active Users
  • **
  • Posts: 33
    • View Profile
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.

2017-07-10, 10:49:07
Reply #3

Ondra

  • Administrator
  • Active Users
  • *****
  • Posts: 9048
  • Turning coffee to features since 2009
    • View Profile

inputFloat = input8Bit/255.f
outputFloat = pow(inputFloat, 1/2.2f) or pow(inputFloat, 2.2f) (depends on direction)
output8Bit = uint8(outputFloat * 255.f)
Rendering is magic.How to get minidumps for crashed/frozen 3ds Max | Sorry for short replies, brief responses = more time to develop Corona ;)

2017-07-11, 03:28:48
Reply #4

Nate101

  • Active Users
  • **
  • Posts: 33
    • View Profile

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!