Advertisement
Guest User

Untitled

a guest
Nov 21st, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Title: ColorMine for POV-Ray
  2. // Authors: Michael Horvath
  3. // Version: 0.1.0
  4. // Created: 2016-11-19
  5. // Updated: 2016-11-19
  6. // Description: This include file is an incomplete adaption of ColorMine
  7. // located online at http://colormine.org/. Unfortunately, POV-Ray does not yet
  8. // support the creation of objects in the object-oriented programming sense, so
  9. // I had to make a lot of changes to make everything work in POV-Ray.
  10. // License: See below.
  11. //
  12. // The MIT License (MIT)
  13. //
  14. // Copyright (c) 2013 ColorMine.org
  15. //
  16. // Permission is hereby granted, free of charge, to any person obtaining a copy
  17. // of this software and associated documentation files (the "Software"), to deal
  18. // in the Software without restriction, including without limitation the rights
  19. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  20. // copies of the Software, and to permit persons to whom the Software is
  21. // furnished to do so, subject to the following conditions:
  22. //
  23. // The above copyright notice and this permission notice shall be included in
  24. // all copies or substantial portions of the Software.
  25. //
  26. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  27. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  28. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  29. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  30. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  31. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  32. // THE SOFTWARE.
  33.  
  34.  
  35. #version 3.70
  36.  
  37. #declare XYZWhiteReference = color <95.047,100.000,108.883>;
  38. #declare XYZEpsilon = 0.008856;
  39. #declare XYZKappa = 903.3;
  40.  
  41.  
  42. // input L = between 0 and 100
  43. // input C = between 0 and 100
  44. // input H = between 0 and 360
  45. // output L = between 0 and 100
  46. // output A = between -128 and +128
  47. // output B = between -128 and +128
  48. #macro CLCH2LAB(Color)
  49.     #local LCHFT = color Color;
  50.     #local L = LCHFT.red;
  51.     #local C = LCHFT.green;
  52.     #local H = LCHFT.blue;
  53.     #local hRadians = radians(H);
  54.     #local A = cos(hRadians) * C;
  55.     #local B = sin(hRadians) * C;
  56.     <L,A,B>
  57. #end
  58.  
  59.  
  60. // input L = between 0 and 100
  61. // input A = between -128 and +128
  62. // input B = between -128 and +128
  63. // output X: between 0 and 100
  64. // output Y: between 0 and 100
  65. // output Z: between 0 and 100
  66. #macro CLAB2XYZ(Color)
  67.     #local LABFT = color Color;
  68.     #local L = LABFT.red;
  69.     #local A = LABFT.green;
  70.     #local B = LABFT.blue;
  71.     #local Y = (L + 16) / 116;
  72.     #local X = Y + A / 500;
  73.     #local Z = Y - B / 200;
  74.     #local X3 = X * X * X;
  75.     #local Z3 = Z * Z * Z;
  76.     #local X = XYZWhiteReference.red    * (X3 > XYZEpsilon ? X3 : (X - 16.0 / 116.0) / 7.787);
  77.     #local Y = XYZWhiteReference.green  * (L > (XYZKappa * XYZEpsilon) ? pow(((L + 16) / 116), 3) : L / XYZKappa);
  78.     #local Z = XYZWhiteReference.blue   * (Z3 > XYZEpsilon ? Z3 : (Z - 16.0 / 116.0) / 7.787);
  79.     <X,Y,Z>
  80. #end
  81.  
  82.  
  83. // input X: between 0 and 100
  84. // input Y: between 0 and 100
  85. // input Z: between 0 and 100
  86. // output R: between 0 and 1 (should maybe change this to betwen 0 and 255 per ColorMine)
  87. // output G: between 0 and 1 (should maybe change this to betwen 0 and 255 per ColorMine)
  88. // output B: between 0 and 1 (should maybe change this to betwen 0 and 255 per ColorMine)
  89. // Note that out-of-range colors are *NOT* corrected. You will have to do this yourself.
  90. #macro CXYZ2RGB(Color)
  91.     #local XYZFT = color Color;
  92.     #local X = (XYZFT.red)/100;
  93.     #local Y = (XYZFT.green)/100;
  94.     #local Z = (XYZFT.blue)/100;
  95.     #local R = X *  3.2406 + Y * -1.5372 + Z * -0.4986;
  96.     #local G = X * -0.9689 + Y *  1.8758 + Z *  0.0415;
  97.     #local B = X *  0.0557 + Y * -0.2040 + Z *  1.0570;
  98.     #local R = (R > 0.0031308 ? 1.055 * pow(R, 1 / 2.4) - 0.055 : 12.92 * R);
  99.     #local G = (G > 0.0031308 ? 1.055 * pow(G, 1 / 2.4) - 0.055 : 12.92 * G);
  100.     #local B = (B > 0.0031308 ? 1.055 * pow(B, 1 / 2.4) - 0.055 : 12.92 * B);
  101.     <R,G,B>
  102. #end
  103.  
  104. #macro CORRECTRGB(Color)
  105.     #local RGBFT = color Color;
  106.     #local R = RGBFT.red;
  107.     #local G = RGBFT.green;
  108.     #local B = RGBFT.blue;
  109.     #local R = min(max(R,0),1);
  110.     #local G = min(max(G,0),1);
  111.     #local B = min(max(B,0),1);
  112.     <R,G,B>
  113. #end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement