aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/skcms/src/GaussNewton.h
blob: 2d5174d32836905933f52a8e3986d62c626a48f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
 * Copyright 2018 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#pragma once

#include <stdbool.h>

// One Gauss-Newton step, tuning up to 3 parameters P to minimize [ r(x,ctx) ]^2.
//
//   rg:       residual function r(x,P) to minimize, and gradient at x in dfdP
//   ctx:      arbitrary context argument passed to rg
//   P:        in-out, both your initial guess for parameters of r(), and our updated values
//   x0,x1,N:  N x-values to test in [x0,x1] (both inclusive) with even spacing
//
// If you have fewer than 3 parameters, set the unused P to zero, don't touch their dfdP.
//
// Returns true and updates P on success, or returns false on failure.
bool skcms_gauss_newton_step(float (*rg)(float x, const void*, const float P[3], float dfdP[3]),
                             const void* ctx,
                             float P[3],
                             float x0, float x1, int N);

// Evaluate an skcms_Curve at x.
float skcms_eval_curve(float x, const skcms_Curve*);