//-----Bald Eagle's RGB to SRGB color conversion macro----- #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_exponential is a standard srgb // color vector // Output: < Red, Green, Blue, Filter, Transmit > // Usage: srgb SRGB2RGB() // Usage (e.g. for sampled colors): // srgb RGB2SRGB(/255) * [Modifier] #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.04045; #local _Gamma = 2.4; #for (Component, 0, 2) #if (_RGB[Component] <= _Threshold) #local _SRGB[Component] = _RGB[Component] / 12.92; #else #local _SRGB[Component] = pow ((_RGB[Component] + _a)/(1 + _a), _Gamma); #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 //----- and Bald Eagle's SRGB to RGB color conversion macro----- #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 srgb // color vector // Output: < Red, Green, Blue, Filter, Transmit > // Usage: rgb SRGB2RGB() // Usage (e.g. for sampled colors): // rgb SRGB2RGB(/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.0031308; #local _Gamma = 2.4; #for (Component, 0, 2) #if (_SRGB[Component] <= _Threshold) #local _RGB[Component] = _SRGB[Component] * 12.92; #else #local _RGB[Component] = ((1 + _a) * pow (_SRGB[Component], 1/_Gamma)) - _a; #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