ACES 0.7.1
[OpenColorIO-Configs.git] / aces_0.1.1 / luts / sony / slogf65_to_aces_3200.ctl
1 ////////////////////////////////////////////////////////////////////////////////////// 
2 // License Terms for Academy Color Encoding System Components                       //
3 //                                                                                  //
4 // Academy Color Encoding System (ACES) software and tools are provided by the      //
5 // Academy under the following terms and conditions: A worldwide, royalty-free,     //
6 // non-exclusive right to copy, modify, create derivatives, and use, in source and  //
7 // binary forms, is hereby granted, subject to acceptance of this license.          //
8 // Performance of any of the aforementioned acts indicates acceptance to be bound   //
9 // by the following terms and conditions:                                           //
10 //                                                                                  //
11 // Copies of source code, in whole or in part, must retain the above copyright      //
12 // notice, this list of conditions and the Disclaimer of Warranty.                  //
13 //                                                                                  //
14 // Use in binary form must retain the copyright notice (below), this list of        //
15 // conditions and the Disclaimer of Warranty in the documentation and/or other      //
16 // materials provided with the distribution.                                        //
17 //                                                                                  //
18 // * Nothing in this license shall be deemed to grant any rights to trademarks,     //
19 // copyrights, patents, trade secrets or any other intellectual property of         //
20 // A.M.P.A.S. or any contributors, except as expressly stated herein.               //
21 //                                                                                  //
22 // * Neither the name "A.M.P.A.S." nor the name of any other contributors to this   //
23 // software may be used to endorse or promote products derivative of or based on    //
24 // this software without express prior written permission of A.M.P.A.S. or the      //
25 // contributors, as appropriate.                                                    //
26 //                                                                                  //
27 // * This license shall be construed pursuant to the laws of the State of           //
28 // California, and any disputes related thereto shall be subject to the             //
29 // jurisdiction of the courts therein.                                              //
30 //                                                                                  //
31 // Copyright © 2012 Academy of Motion Picture Arts and Sciences (A.M.P.A.S.).       //
32 // Portions contributed by others as indicated. All rights reserved.                //
33 //                                                                                  //
34 // Disclaimer of Warranty: THIS SOFTWARE IS PROVIDED BY A.M.P.A.S. AND CONTRIBUTORS //
35 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,    //
36 // THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND //
37 // NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL A.M.P.A.S., OR ANY            //
38 // CONTRIBUTORS OR DISTRIBUTORS, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    //
39 // SPECIAL, EXEMPLARY, RESITUTIONARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT  //
40 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR   //
41 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF           //
42 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE  //
43 // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF        //
44 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                                       //
45 //                                                                                  //
46 // WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE ACADEMY SPECIFICALLY       //
47 // DISCLAIMS ANY REPRESENTATIONS OR WARRANTIES WHATSOEVER RELATED TO PATENT OR      //
48 // OTHER INTELLECTUAL PROPERTY RIGHTS IN THE ACADEMY COLOR ENCODING SYSTEM, OR      //
49 // APPLICATIONS THEREOF, HELD BY PARTIES OTHER THAN A.M.P.A.S.,WHETHER DISCLOSED OR //
50 // UNDISCLOSED.                                                                     //
51 ////////////////////////////////////////////////////////////////////////////////////// 
52
53 //
54 // IDT for S-Log/S-Gamut F65 cameras
55 // Prototype: Jeremy Selan
56 //
57
58
59
60 /* ============ SUBFUNCTIONS ============ */
61 float SLog2_to_lin (
62     float SLog
63 )
64 {
65     // fit from [64,940] -> [0,1023] (of 1023)
66     // Map slog2->ire
67     float x = (SLog-64.0/1023.0) / ((940.0-64.0)/1023.0);
68     if (x < 0.030001222851889303)
69     {
70         x = ((x-0.030001222851889303 ) * 0.28258064516129);
71     }
72     else
73     {
74         x = (219.0*(pow(10.0, ((x-0.616596-0.03)/0.432699)) - 0.037584) /155.0);
75     }
76     
77     // 1.0 IRE => 0.9 scene-linear
78     return x*0.9;
79 }
80
81
82
83
84
85 /* ============ Main Algorithm ============ */
86 void
87 main
88 (   input varying float rIn,
89     input varying float gIn,
90     input varying float bIn,
91     input varying float aIn,
92     output varying float rOut,
93     output varying float gOut,
94     output varying float bOut,
95     output varying float aOut
96 )
97 {
98     // Prepare input values based on application bit depth handling
99     float SLog[3];
100     SLog[0] = rIn;
101     SLog[1] = gIn;
102     SLog[2] = bIn;
103
104     // 10-bit Sony S-log to linear S-gamut
105     float lin[3];
106     lin[0] = SLog2_to_lin( SLog[0]);
107     lin[1] = SLog2_to_lin( SLog[1]);
108     lin[2] = SLog2_to_lin( SLog[2]);
109
110     // S-Gamut to ACES matrix
111     rOut = lin[0] * 1.0110238740 + lin[1] * -0.1362526051 + lin[2] * 0.1252287310;
112     gOut = lin[0] * 0.1011994504 + lin[1] * 0.9562196265 + lin[2] * -0.0574190769;
113     bOut = lin[0] * 0.0600766530 + lin[1] * -0.1010185315 + lin[2] * 1.0409418785;
114     aOut = aIn;
115 }