#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 // 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 = ; 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 // 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.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 = ; C_rgb #end // end macro SRGB2RGB