// Title: ColorMine for POV-Ray // Authors: Michael Horvath // Version: 0.1.0 // Created: 2016-11-19 // Updated: 2016-11-19 // Description: This include file is an incomplete adaption of ColorMine // located online at http://colormine.org/. Unfortunately, POV-Ray does not yet // support the creation of objects in the object-oriented programming sense, so // I had to make a lot of changes to make everything work in POV-Ray. // License: See below. // // The MIT License (MIT) // // Copyright (c) 2013 ColorMine.org // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. #declare XYZWhiteReference = color <95.047,100.000,108.883>; #declare XYZEpsilon = 0.008856; #declare XYZKappa = 903.3; // input L = between 0 and 100 // input C = between 0 and 100 // input H = between 0 and 360 // output L = between 0 and 100 // output A = between -128 and +128 // output B = between -128 and +128 #macro CLCH2LAB(Color) #local LCHFT = color Color; #local L = LCHFT.red; #local C = LCHFT.green; #local H = LCHFT.blue; #local hRadians = radians(H); #local A = cos(hRadians) * C; #local B = sin(hRadians) * C; #end // input L = between 0 and 100 // input A = between -128 and +128 // input B = between -128 and +128 // output X: between 0 and 100 // output Y: between 0 and 100 // output Z: between 0 and 100 #macro CLAB2XYZ(Color) #local LABFT = color Color; #local L = LABFT.red; #local A = LABFT.green; #local B = LABFT.blue; #local Y = (L + 16) / 116; #local X = Y + A / 500; #local Z = Y - B / 200; #local X3 = X * X * X; #local Z3 = Z * Z * Z; #local X = XYZWhiteReference.red * (X3 > XYZEpsilon ? X3 : (X - 16.0 / 116.0) / 7.787); #local Y = XYZWhiteReference.green * (L > (XYZKappa * XYZEpsilon) ? pow(((L + 16) / 116), 3) : L / XYZKappa); #local Z = XYZWhiteReference.blue * (Z3 > XYZEpsilon ? Z3 : (Z - 16.0 / 116.0) / 7.787); #end // input X: between 0 and 100 // input Y: between 0 and 100 // input Z: between 0 and 100 // output R: between 0 and 1 (should maybe change this to betwen 0 and 255 per ColorMine) // output G: between 0 and 1 (should maybe change this to betwen 0 and 255 per ColorMine) // output B: between 0 and 1 (should maybe change this to betwen 0 and 255 per ColorMine) // Note that out-of-range colors are *NOT* corrected. You will have to do this yourself. #macro CXYZ2RGB(Color) #local XYZFT = color Color; #local X = (XYZFT.red)/100; #local Y = (XYZFT.green)/100; #local Z = (XYZFT.blue)/100; #local R = X * 3.2406 + Y * -1.5372 + Z * -0.4986; #local G = X * -0.9689 + Y * 1.8758 + Z * 0.0415; #local B = X * 0.0557 + Y * -0.2040 + Z * 1.0570; #local R = (R > 0.0031308 ? 1.055 * pow(R, 1 / 2.4) - 0.055 : 12.92 * R); #local G = (G > 0.0031308 ? 1.055 * pow(G, 1 / 2.4) - 0.055 : 12.92 * G); #local B = (B > 0.0031308 ? 1.055 * pow(B, 1 / 2.4) - 0.055 : 12.92 * B); #end #macro CORRECTRGB(Color) #local RGBFT = color Color; #local R = RGBFT.red; #local G = RGBFT.green; #local B = RGBFT.blue; #local R = min(max(R,0),1); #local G = min(max(G,0),1); #local B = min(max(B,0),1); #end