Coverage Report

Created: 2025-08-26 06:51

/src/dng_sdk/source/dng_1d_table.cpp
Line
Count
Source (jump to first uncovered line)
1
/*****************************************************************************/
2
// Copyright 2006-2008 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
/* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_1d_table.cpp#1 $ */ 
10
/* $DateTime: 2012/05/30 13:28:51 $ */
11
/* $Change: 832332 $ */
12
/* $Author: tknoll $ */
13
14
/*****************************************************************************/
15
16
#include "dng_1d_table.h"
17
18
#include "dng_1d_function.h"
19
#include "dng_memory.h"
20
#include "dng_utils.h"
21
22
/*****************************************************************************/
23
24
dng_1d_table::dng_1d_table ()
25
26
36.9k
  : fBuffer ()
27
  , fTable  (NULL)
28
  
29
36.9k
  {
30
  
31
36.9k
  }
32
33
/*****************************************************************************/
34
35
dng_1d_table::~dng_1d_table ()
36
36.9k
  {
37
  
38
36.9k
  }
39
  
40
/*****************************************************************************/
41
42
void dng_1d_table::SubDivide (const dng_1d_function &function,
43
                uint32 lower,
44
                uint32 upper,
45
                real32 maxDelta)
46
0
  {
47
  
48
0
  uint32 range = upper - lower;
49
    
50
0
  bool subDivide = (range > (kTableSize >> 8));
51
  
52
0
  if (!subDivide)
53
0
    {
54
    
55
0
    real32 delta = Abs_real32 (fTable [upper] - 
56
0
                   fTable [lower]);
57
                   
58
0
    if (delta > maxDelta)
59
0
      {
60
      
61
0
      subDivide = true;
62
      
63
0
      }
64
    
65
0
    }
66
    
67
0
  if (subDivide)
68
0
    {
69
    
70
0
    uint32 middle = (lower + upper) >> 1;
71
    
72
0
    fTable [middle] = (real32) function.Evaluate (middle * (1.0 / (real64) kTableSize));
73
    
74
0
    if (range > 2)
75
0
      {
76
      
77
0
      SubDivide (function, lower, middle, maxDelta);
78
      
79
0
      SubDivide (function, middle, upper, maxDelta);
80
      
81
0
      }
82
  
83
0
    }
84
    
85
0
  else
86
0
    {
87
    
88
0
    real64 y0 = fTable [lower];
89
0
    real64 y1 = fTable [upper];
90
    
91
0
    real64 delta = (y1 - y0) / (real64) range;
92
    
93
0
    for (uint32 j = lower + 1; j < upper; j++)
94
0
      {
95
      
96
0
      y0 += delta;
97
        
98
0
      fTable [j] = (real32) y0;
99
            
100
0
      }
101
    
102
0
    }
103
    
104
0
  }
105
  
106
/*****************************************************************************/
107
108
void dng_1d_table::Initialize (dng_memory_allocator &allocator,
109
                 const dng_1d_function &function,
110
                 bool subSample)
111
36.8k
  {
112
  
113
36.8k
  fBuffer.Reset (allocator.Allocate ((kTableSize + 2) * sizeof (real32)));
114
  
115
36.8k
  fTable = fBuffer->Buffer_real32 ();
116
  
117
36.8k
  if (subSample)
118
0
    {
119
    
120
0
    fTable [0         ] = (real32) function.Evaluate (0.0);
121
0
    fTable [kTableSize] = (real32) function.Evaluate (1.0);
122
    
123
0
    real32 maxDelta = Max_real32 (Abs_real32 (fTable [kTableSize] -
124
0
                          fTable [0         ]), 1.0f) *
125
0
              (1.0f / 256.0f);
126
                 
127
0
    SubDivide (function,
128
0
           0,
129
0
           kTableSize,
130
0
           maxDelta);
131
    
132
0
    }
133
    
134
36.8k
  else
135
36.8k
    {
136
      
137
150M
    for (uint32 j = 0; j <= kTableSize; j++)
138
150M
      {
139
      
140
150M
      real64 x = j * (1.0 / (real64) kTableSize);
141
      
142
150M
      real64 y = function.Evaluate (x);
143
      
144
150M
      fTable [j] = (real32) y;
145
      
146
150M
      }
147
      
148
36.8k
    }
149
    
150
36.8k
  fTable [kTableSize + 1] = fTable [kTableSize];
151
  
152
36.8k
  }
153
154
/*****************************************************************************/
155
156
void dng_1d_table::Expand16 (uint16 *table16) const
157
6.99k
  {
158
  
159
6.99k
  real64 step = (real64) kTableSize / 65535.0;
160
  
161
6.99k
  real64 y0 = fTable [0];
162
6.99k
  real64 y1 = fTable [1];
163
  
164
6.99k
  real64 base  = y0 * 65535.0 + 0.5;
165
6.99k
  real64 slope = (y1 - y0) * 65535.0;
166
  
167
6.99k
  uint32 index = 1;
168
6.99k
  real64 fract = 0.0;
169
  
170
458M
  for (uint32 j = 0; j < 0x10000; j++)
171
458M
    {
172
    
173
458M
    table16 [j] = (uint16) (base + slope * fract);
174
    
175
458M
    fract += step;
176
    
177
458M
    if (fract > 1.0)
178
28.6M
      {
179
      
180
28.6M
      index += 1;
181
28.6M
      fract -= 1.0;
182
      
183
28.6M
      y0 = y1;
184
28.6M
      y1 = fTable [index];
185
      
186
28.6M
      base  = y0 * 65535.0 + 0.5;
187
28.6M
      slope = (y1 - y0) * 65535.0;
188
      
189
28.6M
      }
190
    
191
458M
    }
192
  
193
6.99k
  }
194
195
/*****************************************************************************/