POV-Ray : Newsgroups : povray.text.scene-files : RGB-sRGB interconversion : RGB-sRGB interconversion Server Time
26 Apr 2024 18:19:59 EDT (-0400)
  RGB-sRGB interconversion  
From: Bald Eagle
Date: 17 Mar 2017 12:35:01
Message: <web.58cc101945a951b1c437ac910@news.povray.org>
I hope I got this correct.

Some brief experiments indicate that it ought to have a dramatic impact on
"washed-out" scenes resulting from using image color values reported by 3rd
party sampling software.

Please test and give me some feedback for problems, suggestions, or
improvements.

Plain text follows, "include" file attached.


#macro RGB2SRGB (C_linear)
 // POV-Ray SDL macro - March 2017 - Bill Walker "Bald Eagle"
 // Version 1.0
 // Converts a color in RGB color space to a color in sRGB color space
 // https://en.wikipedia.org/wiki/SRGB
 // Input: C_linear is a standard rgb color vector <R, G, B, [F], [T]>
 // Output: < Red, Green, Blue, Filter, Transmit >
 #local _Color = color C_linear;
 #local RGB = array[3] {C_linear.red, C_linear.green, C_linear.blue};
 #local SRGB = array[3];
 #local _a = 0.055;
 #local _Threshold = 0.0031308;
 #local _Gamma = 2.4;
 #for (Component, 0, 2)
  #if (RGB[Component] <= _Threshold)
   #local SRGB[Component] = RGB[Component] * 12.92;
  #else
   #local SRGB[Component] = ((1 + _a) * pow (RGB[Component], 1/_Gamma)) - _a;
  #end // end if
 #end // end for Component
 #local C_srgb = <SRGB[0], SRGB[1], SRGB[2], _Color.filter, _Color.transmit>;

 C_srgb

#end // end macro RGB2SRGB

#macro SRGB2RGB (C_exponential)
 // POV-Ray SDL macro - March 2017 - Bill Walker "Bald Eagle"
 // Version 1.0
 // Converts a color in sRGB color space to a color in RGB color space
 // https://en.wikipedia.org/wiki/SRGB
 // Input: C_exponential is a standard rgb color vector <R, G, B, [F], [T]>
 // Output: < Red, Green, Blue, Filter, Transmit >
 // Usage: rgb SRGB2RGB(<Red, Green, Blue>)
 // Usage (e.g. for sampled colors): rgb SRGB2RGB(<Red, Green, Blue>/255) *
[Modifier]
 #local _Color = color C_exponential;
 #local SRGB = array[3] {C_exponential.red, C_exponential.green,
C_exponential.blue};
 #local RGB = array[3];
 #local _a = 0.055;
 #local _Threshold = 0.04045;
 #local _Gamma = 2.4;
 #for (Component, 0, 2)
  #if (SRGB[Component] <= _Threshold)
   #local RGB[Component] = SRGB[Component] / 12.92;
  #else
   #local RGB[Component] = pow ((SRGB[Component] + _a)/(1 + _a), _Gamma);
  #end // end if
 #end // end for Component
 #local C_rgb = <RGB[0], RGB[1], RGB[2], _Color.filter, _Color.transmit>;

 C_rgb

#end // end macro SRGB2RGB


Post a reply to this message


Attachments:
Download 'rgb_srgb_1.inc.txt' (2 KB)

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.