MCPcopy Create free account
hub / github.com/LibRaw/LibRaw / gamma_curve

Function gamma_curve

samples/unprocessed_raw.cpp:202–251  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200#define SQR(x) ((x) * (x))
201
202void gamma_curve(unsigned short *curve)
203{
204
205 double pwr = 1.0 / 2.2;
206 double ts = 0.0;
207 int imax = 0xffff;
208 int mode = 2;
209 int i;
210 double g[6], bnd[2] = {0, 0}, r;
211
212 g[0] = pwr;
213 g[1] = ts;
214 g[2] = g[3] = g[4] = 0;
215 bnd[g[1] >= 1] = 1;
216 if (g[1] && (g[1] - 1) * (g[0] - 1) <= 0)
217 {
218 for (i = 0; i < 48; i++)
219 {
220 g[2] = (bnd[0] + bnd[1]) / 2;
221 if (g[0])
222 bnd[(pow(g[2] / g[1], -g[0]) - 1) / g[0] - 1 / g[2] > -1] = g[2];
223 else
224 bnd[g[2] / exp(1 - 1 / g[2]) < g[1]] = g[2];
225 }
226 g[3] = g[2] / g[1];
227 if (g[0])
228 g[4] = g[2] * (1 / g[0] - 1);
229 }
230 if (g[0])
231 g[5] = 1 / (g[1] * SQR(g[3]) / 2 - g[4] * (1 - g[3]) +
232 (1 - pow(g[3], 1 + g[0])) * (1 + g[4]) / (1 + g[0])) -
233 1;
234 else
235 g[5] = 1 / (g[1] * SQR(g[3]) / 2 + 1 - g[2] - g[3] -
236 g[2] * g[3] * (log(g[3]) - 1)) -
237 1;
238 for (i = 0; i < 0x10000; i++)
239 {
240 curve[i] = 0xffff;
241 if ((r = (double)i / imax) < 1)
242 curve[i] =
243 0x10000 *
244 (mode ? (r < g[3] ? r * g[1]
245 : (g[0] ? pow(r, g[0]) * (1 + g[4]) - g[4]
246 : log(r) * g[2] + 1))
247 : (r < g[2] ? r / g[1]
248 : (g[0] ? pow((r + g[4]) / (1 + g[4]), 1 / g[0])
249 : exp((r - 1) / g[2]))));
250 }
251}
252
253void tiff_set(ushort *ntag, ushort tag, ushort type, int count, int val)
254{

Callers 9

mainFunction · 0.85
kodak_thumb_loaderMethod · 0.85
convert_to_rgbMethod · 0.85
copy_mem_imageMethod · 0.85
write_ppm_tiffMethod · 0.85
identify_finetune_dcrMethod · 0.85
tiff.cppFile · 0.85
lossy_dng_load_rawMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected