ACES 0.7.1
[OpenColorIO-Configs.git] / aces / luts / sony / slogf35_to_aces.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 10-bit S-Log/S-Gamut Sony cameras
55 // Provided by Sony Electronics Corp.
56 //
57
58
59
60
61
62 /* ============ CONSTANTS ============ */
63 const float SGAMUT_TO_ACES_MTX[3][3] = {
64         { 0.754338638,  0.021198141, -0.009756991 },
65         { 0.133697046,  1.005410934,  0.004508563 },
66         { 0.111968437, -0.026610548,  1.005253201 }
67 };
68
69
70
71
72
73 /* ============ SUBFUNCTIONS ============ */
74 float SLog10_to_lin (
75         float SLog
76 )
77 {
78         return (pow(10,((((SLog/4-16)/219)-0.616596-0.03)/0.432699))-0.037584)*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 * 1023.0;
101         SLog[1] = gIn * 1023.0;
102         SLog[2] = bIn * 1023.0;
103
104         // 10-bit Sony S-log to linear S-gamut
105         float lin[3];
106         lin[0] = SLog10_to_lin( SLog[0]);
107         lin[1] = SLog10_to_lin( SLog[1]);
108         lin[2] = SLog10_to_lin( SLog[2]);
109         
110         // S-Gamut to ACES matrix
111         float aces[3] = mult_f3_f33( lin, SGAMUT_TO_ACES_MTX);
112
113         rOut = aces[0];
114         gOut = aces[1];
115         bOut = aces[2];
116         aOut = aIn;
117 }