Debian Codegraph @

core/libs/dngwriter/extra/dng_sdk/dng_spline.h

raw
1 /*****************************************************************************/
2 // Copyright 2006-2019 Adobe Systems Incorporated
3 // All Rights Reserved.
4 //
5 // NOTICE: Adobe permits you to use, modify, and distribute this file in
6 // accordance with the terms of the Adobe license agreement accompanying it.
7 /*****************************************************************************/
8
9 #ifndef __dng_spline__
10 #define __dng_spline__
11
12 /*****************************************************************************/
13
14 #include "dng_1d_function.h"
15 #include "dng_memory.h"
16
17 #include <vector>
18
19 /*****************************************************************************/
20
21 inline real64 EvaluateSplineSegment (real64 x,
22 real64 x0,
23 real64 y0,
24 real64 s0,
25 real64 x1,
26 real64 y1,
27 real64 s1)
28 {
29
30 real64 A = x1 - x0;
31
32 real64 B = (x - x0) / A;
33
34 real64 C = (x1 - x) / A;
35
36 real64 D = ((y0 * (2.0 - C + B) + (s0 * A * B)) * (C * C)) +
37 ((y1 * (2.0 - B + C) - (s1 * A * C)) * (B * B));
38
39 return D;
40
41 }
42
43 /*****************************************************************************/
44
45 inline real64 EvaluateSlopeSplineSegment (real64 x,
46 real64 x0,
47 real64 y0,
48 real64 s0,
49 real64 x1,
50 real64 y1,
51 real64 s1)
52 {
53
54 real64 A = x1 - x0;
55
56 real64 A2 = A * A;
57
58 real64 A3 = A2 * A;
59
60 real64 c0 = ((s1 * x0 * x0) + (2.0 * s0 * x0 * x1) + (2.0 * s1 * x0 * x1) + (s0 * x1 * x1) - (4.0 * x1 * y0) - (4.0 * x0 * y1)) / A2;
61
62 real64 c1 = ((2.0 * x0 * x1 * y0) + (4.0 * x1 * x1 * y0) - (4.0 * x0 * x0 * y1) - (2.0 * x0 * x1 * y1)) / A3;
63
64 real64 quad_term = 3.0 * x * x * (((s0 + s1) / A2) + (2.0 * (y0 - y1) / A3));
65
66 real64 linear_term = 2.0 * x * (((-((s0 * x0)) - (2.0 * s1 * x0) - (2.0 * s0 * x1) - (s1 * x1) + (2.0 * y0) + (2.0 * y1)) / A2) +
67 ((-(x0 * y0) - (5.0 * x1 * y0) + (5.0 * x0 * y1) + (x1 * y1)) / A3));
68
69 return linear_term + quad_term + c0 + c1;
70
71 }
72
73 /*****************************************************************************/
74
75 class dng_spline_solver: public dng_1d_function
76 {
77
78 public:
79
80 dng_std_vector<real64> X;
81 dng_std_vector<real64> Y;
82
83 dng_std_vector<real64> S;
84
85 // If true, then use linear slope extension before the first curve endpoint.
86
87 bool fUseSlopeExtensionLo = false;
88
89 // If true, then use linear slope extension after the last curve endpoint.
90
91 bool fUseSlopeExtensionHi = false;
92
93 public:
94
95 dng_spline_solver ();
96
97 virtual ~dng_spline_solver ();
98
99 void Reset ();
100
101 void Add (real64 x, real64 y);
102
103 virtual void Solve ();
104
105 virtual bool IsIdentity () const;
106
107 virtual real64 Evaluate (real64 x) const;
108
109 virtual real64 EvaluateSlope (real64 x) const;
110
111 real64 UseSlopeExtensionLo () const
112 {
113 return fUseSlopeExtensionLo;
114 }
115
116 real64 UseSlopeExtensionHi () const
117 {
118 return fUseSlopeExtensionHi;
119 }
120
121 void SetUseSlopeExtension (bool flag)
122 {
123 fUseSlopeExtensionLo = flag;
124 fUseSlopeExtensionHi = flag;
125 }
126
127 void SetUseSlopeExtensionLo (bool flag)
128 {
129 fUseSlopeExtensionLo = flag;
130 }
131
132 void SetUseSlopeExtensionHi (bool flag)
133 {
134 fUseSlopeExtensionHi = flag;
135 }
136
137 };
138
139 /*****************************************************************************/
140
141 #endif // __dng_spline__
142
143 /*****************************************************************************/