// Title: ColorMine for POV-Ray // Authors: Michael Horvath // Version: 0.1.4 // Created: 2016-11-19 // Updated: 2016-12-15 // 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. #version 3.7; #declare XYZWhiteReference = color <95.047,100.000,108.883>; #declare XYZEpsilon = 0.008856; #declare XYZKappa = 903.3; #macro GetDenominator(Vector) #local Color = color Vector; Color.red + 15 * Color.green + 3 * Color.blue; #end #macro round(X, Q) ceil(X * pow(10, Q) - 0.5) * pow(0.1, Q) #end // input L = between 0 and 100 // input C = between 0 and 128 // 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 // untested // input L = between 0 and 100 // input U = between -128 and +128 // input V = between -128 and +128 // output X: between 0 and 100 // output Y: between 0 and 100 // output Z: between 0 and 100 #macro CLUV2XYZ(Color) #local LUVFT = color Color; #local L = LUVFT.red; #local U = LUVFT.green; #local V = LUVFT.blue; #local c = -1/3; #local uPrime = 4 * XYZWhiteReference.red/GetDenominator(XYZWhiteReference); #local vPrime = 9 * XYZWhiteReference.green/GetDenominator(XYZWhiteReference); #local a = 1/3 * (52 * L/(U + 13 * L * uPrime) - 1); #local itemL_16_116 = (L + 16)/116; #local Y = (L > XYZKappa * XYZEpsilon ? pow(itemL_16_116,3) : L/XYZKappa); #local b = -5 * Y; #local d = Y * (39 * L/(V + 13 * L * vPrime) - 5); #local X = (d - b)/(a - c); #local Z = X * a + b; #local X = X * 100; #local Y = Y * 100; #local Z = Z * 100; #end // untested // input H = between 0 and 360 // input C = between 0 and 128 // input L = between 0 and 100 // output L = between 0 and 100 // output U = between -128 and +128 // output V = between -128 and +128 #macro CHCL2LUV(Color) #local HCLFT = color Color; #local H = HCLFT.red; #local C = HCLFT.green; #local L = HCLFT.blue; #local hRadians = radians(H); #local U = cos(hRadians) * C; #local V = sin(hRadians) * C; #end // input R: between 0 and 1 // input G: between 0 and 1 // input B: between 0 and 1 // output R: between 00 and FF // output G: between 00 and FF // output B: between 00 and FF #macro CRGB2HEX(Color) #local RGBFT = color Color; #local R = RGBFT.red; #local G = RGBFT.green; #local B = RGBFT.blue; concat(CDEC2HEX(R), CDEC2HEX(G), CDEC2HEX(B)) #end // input number: between 0 and 1 // output number: between 00 and FF #macro CDEC2HEX(n) #local HexArray = array[16] {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"} #local n = max(0, min(255, round(n * 255, 0))); #local Num1 = (n - mod(n, 16))/16; #local Num2 = mod(n, 16); concat(HexArray[Num1], HexArray[Num2]) #end // output X: between 0 and 100 // output Y: between 0 and 100 // output Z: between 0 and 100 // output x: between 0 and 1 // output y: between 0 and 1 // output Y: between 0 and 100 #macro XYZ2xyY(Color) #local Y1 = Color.y; #local xDividend = Color.x + Color.y + Color.z; #local X = Color.x / xDividend; #local y2Dividend = Color.x + Color.y + Color.z; #local Y2 = Color.y / y2Dividend; #end #declare xyz_table = array[90] { <0.001368000000,0.000039000000,0.006450001000>,//380 <0.002236000000,0.000064000000,0.010549990000>,//385 <0.004243000000,0.000120000000,0.020050010000>,//390 <0.007650000000,0.000217000000,0.036210000000>,//395 <0.014310000000,0.000396000000,0.067850010000>,//400 <0.023190000000,0.000640000000,0.110200000000>,//405 <0.043510000000,0.001210000000,0.207400000000>,//410 <0.077630000000,0.002180000000,0.371300000000>,//415 <0.134380000000,0.004000000000,0.645600000000>,//420 <0.214770000000,0.007300000000,1.039050100000>,//425 <0.283900000000,0.011600000000,1.385600000000>,//430 <0.328500000000,0.016840000000,1.622960000000>,//435 <0.348280000000,0.023000000000,1.747060000000>,//440 <0.348060000000,0.029800000000,1.782600000000>,//445 <0.336200000000,0.038000000000,1.772110000000>,//450 <0.318700000000,0.048000000000,1.744100000000>,//455 <0.290800000000,0.060000000000,1.669200000000>,//460 <0.251100000000,0.073900000000,1.528100000000>,//465 <0.195360000000,0.090980000000,1.287640000000>,//470 <0.142100000000,0.112600000000,1.041900000000>,//475 <0.095640000000,0.139020000000,0.812950100000>,//480 <0.057950010000,0.169300000000,0.616200000000>,//485 <0.032010000000,0.208020000000,0.465180000000>,//490 <0.014700000000,0.258600000000,0.353300000000>,//495 <0.004900000000,0.323000000000,0.272000000000>,//500 <0.002400000000,0.407300000000,0.212300000000>,//505 <0.009300000000,0.503000000000,0.158200000000>,//510 <0.029100000000,0.608200000000,0.111700000000>,//515 <0.063270000000,0.710000000000,0.078249990000>,//520 <0.109600000000,0.793200000000,0.057250010000>,//525 <0.165500000000,0.862000000000,0.042160000000>,//530 <0.225749900000,0.914850100000,0.029840000000>,//535 <0.290400000000,0.954000000000,0.020300000000>,//540 <0.359700000000,0.980300000000,0.013400000000>,//545 <0.433449900000,0.994950100000,0.008749999000>,//550 <0.512050100000,1.000000000000,0.005749999000>,//555 <0.594500000000,0.995000000000,0.003900000000>,//560 <0.678400000000,0.978600000000,0.002749999000>,//565 <0.762100000000,0.952000000000,0.002100000000>,//570 <0.842500000000,0.915400000000,0.001800000000>,//575 <0.916300000000,0.870000000000,0.001650001000>,//580 <0.978600000000,0.816300000000,0.001400000000>,//585 <1.026300000000,0.757000000000,0.001100000000>,//590 <1.056700000000,0.694900000000,0.001000000000>,//595 <1.062200000000,0.631000000000,0.000800000000>,//600 <1.045600000000,0.566800000000,0.000600000000>,//605 <1.002600000000,0.503000000000,0.000340000000>,//610 <0.938400000000,0.441200000000,0.000240000000>,//615 <0.854449900000,0.381000000000,0.000190000000>,//620 <0.751400000000,0.321000000000,0.000100000000>,//625 <0.642400000000,0.265000000000,0.000049999990>,//630 <0.541900000000,0.217000000000,0.000030000000>,//635 <0.447900000000,0.175000000000,0.000020000000>,//640 <0.360800000000,0.138200000000,0.000010000000>,//645 <0.283500000000,0.107000000000,0.000000000000>,//650 <0.218700000000,0.081600000000,0.000000000000>,//655 <0.164900000000,0.061000000000,0.000000000000>,//660 <0.121200000000,0.044580000000,0.000000000000>,//665 <0.087400000000,0.032000000000,0.000000000000>,//670 <0.063600000000,0.023200000000,0.000000000000>,//675 <0.046770000000,0.017000000000,0.000000000000>,//680 <0.032900000000,0.011920000000,0.000000000000>,//685 <0.022700000000,0.008210000000,0.000000000000>,//690 <0.015840000000,0.005723000000,0.000000000000>,//695 <0.011359160000,0.004102000000,0.000000000000>,//700 <0.008110916000,0.002929000000,0.000000000000>,//705 <0.005790346000,0.002091000000,0.000000000000>,//710 <0.004106457000,0.001484000000,0.000000000000>,//715 <0.002899327000,0.001047000000,0.000000000000>,//720 <0.002049190000,0.000740000000,0.000000000000>,//725 <0.001439971000,0.000520000000,0.000000000000>,//730 <0.000999949300,0.000361100000,0.000000000000>,//735 <0.000690078600,0.000249200000,0.000000000000>,//740 <0.000476021300,0.000171900000,0.000000000000>,//745 <0.000332301100,0.000120000000,0.000000000000>,//750 <0.000234826100,0.000084800000,0.000000000000>,//755 <0.000166150500,0.000060000000,0.000000000000>,//760 <0.000117413000,0.000042400000,0.000000000000>,//765 <0.000083075270,0.000030000000,0.000000000000>,//770 <0.000058706520,0.000021200000,0.000000000000>,//775 <0.000041509940,0.000014990000,0.000000000000>,//780 <0.000029353260,0.000010600000,0.000000000000>,//785 <0.000020673830,0.000007465700,0.000000000000>,//790 <0.000014559770,0.000005257800,0.000000000000>,//795 <0.000010253980,0.000003702900,0.000000000000>,//800 <0.000007221456,0.000002607800,0.000000000000>,//805 <0.000005085868,0.000001836600,0.000000000000>,//810 <0.000003581652,0.000001293400,0.000000000000>,//815 <0.000002522525,0.000000910930,0.000000000000>,//820 <0.000001776509,0.000000641530,0.000000000000> //825 } #declare D65_table = array[90] { 49.9755,//380 52.3118,//385 54.6482,//390 68.7015,//395 82.7549,//400 87.1204,//405 91.486,//410 92.4589,//415 93.4318,//420 90.057,//425 86.6823,//430 95.7736,//435 104.865,//440 110.936,//445 117.008,//450 117.41,//455 117.812,//460 116.336,//465 114.861,//470 115.392,//475 115.923,//480 112.367,//485 108.811,//490 109.082,//495 109.354,//500 108.578,//505 107.802,//510 106.296,//515 104.79,//520 106.239,//525 107.689,//530 106.047,//535 104.405,//540 104.225,//545 104.046,//550 102.023,//555 100,//560 98.1671,//565 96.3342,//570 96.0611,//575 95.788,//580 92.2368,//585 88.6856,//590 89.3459,//595 90.0062,//600 89.8026,//605 89.5991,//610 88.6489,//615 87.6987,//620 85.4936,//625 83.2886,//630 83.4939,//635 83.6992,//640 81.863,//645 80.0268,//650 80.1207,//655 80.2146,//660 81.2462,//665 82.2778,//670 80.281,//675 78.2842,//680 74.0027,//685 69.7213,//690 70.6652,//695 71.6091,//700 72.979,//705 74.349,//710 67.9765,//715 61.604,//720 65.7448,//725 69.8856,//730 72.4863,//735 75.087,//740 69.3398,//745 63.5927,//750 55.0054,//755 46.4182,//760 56.6118,//765 66.8054,//770 65.0941,//775 63.3828,//780 63.8434,//785 64.304,//790 61.8779,//795 59.4519,//800 55.7054,//805 51.959,//810 54.6998,//815 57.4406,//820 58.8765//825 }