renamed aces -> aces_0.1.1 to reflect versioning
[OpenColorIO-Configs.git] / aces_0.1.1 / luts / unbuild / adx_adx16_to_aces.ctl
1 ////////////////////////////////////////////////////////////////////////////////////// \r
2 // License Terms for Academy Color Encoding System Components                       //\r
3 //                                                                                  //\r
4 // Academy Color Encoding System (ACES) software and tools are provided by the      //\r
5 // Academy under the following terms and conditions: A worldwide, royalty-free,     //\r
6 // non-exclusive right to copy, modify, create derivatives, and use, in source and  //\r
7 // binary forms, is hereby granted, subject to acceptance of this license.          //\r
8 // Performance of any of the aforementioned acts indicates acceptance to be bound   //\r
9 // by the following terms and conditions:                                           //\r
10 //                                                                                  //\r
11 // Copies of source code, in whole or in part, must retain the above copyright      //\r
12 // notice, this list of conditions and the Disclaimer of Warranty.                  //\r
13 //                                                                                  //\r
14 // Use in binary form must retain the copyright notice (below), this list of        //\r
15 // conditions and the Disclaimer of Warranty in the documentation and/or other      //\r
16 // materials provided with the distribution.                                        //\r
17 //                                                                                  //\r
18 // * Nothing in this license shall be deemed to grant any rights to trademarks,     //\r
19 // copyrights, patents, trade secrets or any other intellectual property of         //\r
20 // A.M.P.A.S. or any contributors, except as expressly stated herein.               //\r
21 //                                                                                  //\r
22 // * Neither the name "A.M.P.A.S." nor the name of any other contributors to this   //\r
23 // software may be used to endorse or promote products derivative of or based on    //\r
24 // this software without express prior written permission of A.M.P.A.S. or the      //\r
25 // contributors, as appropriate.                                                    //\r
26 //                                                                                  //\r
27 // * This license shall be construed pursuant to the laws of the State of           //\r
28 // California, and any disputes related thereto shall be subject to the             //\r
29 // jurisdiction of the courts therein.                                              //\r
30 //                                                                                  //\r
31 // Copyright © 2012 Academy of Motion Picture Arts and Sciences (A.M.P.A.S.).       //\r
32 // Portions contributed by others as indicated. All rights reserved.                //\r
33 //                                                                                  //\r
34 // Disclaimer of Warranty: THIS SOFTWARE IS PROVIDED BY A.M.P.A.S. AND CONTRIBUTORS //\r
35 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,    //\r
36 // THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND //\r
37 // NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL A.M.P.A.S., OR ANY            //\r
38 // CONTRIBUTORS OR DISTRIBUTORS, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    //\r
39 // SPECIAL, EXEMPLARY, RESITUTIONARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT  //\r
40 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR   //\r
41 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF           //\r
42 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE  //\r
43 // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF        //\r
44 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                                       //\r
45 //                                                                                  //\r
46 // WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE ACADEMY SPECIFICALLY       //\r
47 // DISCLAIMS ANY REPRESENTATIONS OR WARRANTIES WHATSOEVER RELATED TO PATENT OR      //\r
48 // OTHER INTELLECTUAL PROPERTY RIGHTS IN THE ACADEMY COLOR ENCODING SYSTEM, OR      //\r
49 // APPLICATIONS THEREOF, HELD BY PARTIES OTHER THAN A.M.P.A.S.,WHETHER DISCLOSED OR //\r
50 // UNDISCLOSED.                                                                     //\r
51 ////////////////////////////////////////////////////////////////////////////////////// \r
52 \r
53 // \r
54 // Universal ADX16 to ACES Transform\r
55 // \r
56 \r
57 \r
58 \r
59 \r
60 \r
61 /* ============ CONSTANTS ============ */\r
62 const float CDD_TO_CID[3][3] = {\r
63         {0.75573, 0.05901, 0.16134},\r
64         {0.22197, 0.96928, 0.07406},\r
65         {0.02230, -0.02829, 0.76460}\r
66 };\r
67 \r
68 const float EXP_TO_ACES[3][3] = {\r
69         {0.72286, 0.11923, 0.01427},\r
70         {0.12630, 0.76418, 0.08213},\r
71         {0.15084, 0.11659, 0.90359}\r
72 };\r
73 \r
74 const float LUT_1D[11][2] = {\r
75         {-0.190000000000000, -6.000000000000000},\r
76         { 0.010000000000000, -2.721718645000000},\r
77         { 0.028000000000000, -2.521718645000000},\r
78         { 0.054000000000000, -2.321718645000000},\r
79         { 0.095000000000000, -2.121718645000000},\r
80         { 0.145000000000000, -1.921718645000000},\r
81         { 0.220000000000000, -1.721718645000000},\r
82         { 0.300000000000000, -1.521718645000000},\r
83         { 0.400000000000000, -1.321718645000000},\r
84         { 0.500000000000000, -1.121718645000000},\r
85         { 0.600000000000000, -0.926545676714876}\r
86 };\r
87 \r
88 const float REF_PT = (7120.0 - 1520.0) / 8000.0 * (100.0 / 55.0) - log10(0.18);\r
89 \r
90 \r
91 \r
92 \r
93 \r
94 /* ============ Main Algorithm ============ */\r
95 void main\r
96 (   input varying float rIn,\r
97     input varying float gIn,\r
98     input varying float bIn,\r
99     input varying float aIn,\r
100     output varying float rOut,\r
101     output varying float gOut,\r
102     output varying float bOut,\r
103     output varying float aOut\r
104 )\r
105 {\r
106         // Prepare input values based on application bit depth handling\r
107         float adx[3];\r
108     adx[0] = rIn * 65535.0;\r
109         adx[1] = gIn * 65535.0;\r
110         adx[2] = bIn * 65535.0;\r
111 \r
112         // Convert ADX16 values to Channel Dependent Density values\r
113         float cdd[3];\r
114         cdd[0] = ( adx[0] - 1520.0) / 8000.0;\r
115         cdd[1] = ( adx[1] - 1520.0) / 8000.0;\r
116         cdd[2] = ( adx[2] - 1520.0) / 8000.0;\r
117 \r
118         // Convert Channel Dependent Density values into Channel Independent Density values\r
119         float cid[3] = mult_f3_f33( cdd, CDD_TO_CID);\r
120         \r
121         // Convert Channel Independent Density values to Relative Log Exposure values\r
122         float logE[3];\r
123         if ( cid[0] <= 0.6) logE[0] = interpolate1D( LUT_1D, cid[0]);\r
124         if ( cid[1] <= 0.6) logE[1] = interpolate1D( LUT_1D, cid[1]);\r
125         if ( cid[2] <= 0.6) logE[2] = interpolate1D( LUT_1D, cid[2]);\r
126         \r
127         if ( cid[0] > 0.6) logE[0] = ( 100.0 / 55.0) * cid[0] - REF_PT;\r
128         if ( cid[1] > 0.6) logE[1] = ( 100.0 / 55.0) * cid[1] - REF_PT;\r
129         if ( cid[2] > 0.6) logE[2] = ( 100.0 / 55.0) * cid[2] - REF_PT;\r
130 \r
131         // Convert Relative Log Exposure values to Relative Exposure values\r
132         float exp[3];\r
133         exp[0] = pow( 10, logE[0]);\r
134         exp[1] = pow( 10, logE[1]);\r
135         exp[2] = pow( 10, logE[2]);\r
136 \r
137         // Convert Relative Exposure values to ACES values\r
138         float aces[3] = mult_f3_f33( exp, EXP_TO_ACES);\r
139 \r
140         rOut = aces[0];\r
141         gOut = aces[1];\r
142         bOut = aces[2];\r
143         aOut = aIn;     \r
144 }