File: PrintResponses.cpp

package info (click to toggle)
luminance-hdr 2.6.1.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 34,788 kB
  • sloc: cpp: 43,954; ansic: 4,122; xml: 116; makefile: 20; sh: 7
file content (85 lines) | stat: -rw-r--r-- 2,335 bytes parent folder | download | duplicates (5)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <vector>
#include <iostream>
#include <fstream>
#include <cmath>

#include <HdrCreation/responses.h>

using namespace std;
using namespace libhdr::fusion;

static const size_t SAMPLES = 1024;

static float getSample(int sample)
{
    return static_cast<float>(sample)/(SAMPLES - 1);
}

void printResponseCurve(const ResponseCurve& responseFunction1,
                        void (*responseFunction2)(float*, int) ,
                        const std::string& fileNameGnuplot,
                        const std::string& fileNameMatlab)
{
    vector<float> data(SAMPLES);

    ofstream outputFile(fileNameGnuplot.c_str());
    responseFunction2(data.data(), SAMPLES);
    for (size_t idx = 0; idx < SAMPLES; ++idx)
    {
        float sample = getSample(idx);
        float w = responseFunction1.getResponse(sample);

        outputFile << idx << " "
                   << sample << " "
                   << data[idx] << " "
                   << w << " "
                   << abs(data[idx] - w)
                   << "\n";
    }
    outputFile.close();

    responseFunction1.writeToFile(fileNameMatlab);
}

void responseLinear( float* I, int M )
{
    for (int m=0 ; m<M ; m++)
    {
        I[m] = m / float(M-1); // range is not important, values are normalized later
    }
}

void responseLog10( float* I, int M )
{
    const float mid = 0.5f * M;
    const float norm = 0.0625f * M;
    const float maxValue = powf(10.0f, float(M-1 - mid) / norm);

    for (int m=0 ; m < M; ++m)
    {
        I[m] = powf(10.0f, float(m - mid) / norm) / maxValue;
    }
}

void responseGamma( float* I, int M )
{
    float norm = M / 4.0f;

    // response curve decided empirically
    for( int m=0 ; m<M ; m++ )
        I[m] = powf( m/norm, 1.7f ) + 1e-4;
}

int main()
{
    printResponseCurve(ResponseCurve(RESPONSE_LINEAR), &responseLinear,
                       "response_linear.dat", "response_linear.m");
    printResponseCurve(ResponseCurve(RESPONSE_LOG10), &responseLog10,
                       "response_log10.dat", "response_log10.m");
    printResponseCurve(ResponseCurve(RESPONSE_GAMMA), &responseGamma,
                       "response_gamma.dat", "response_gamma.m");
    printResponseCurve(ResponseCurve(RESPONSE_SRGB), &responseLinear,
                       "response_srgb.dat", "response_srgb.m");

    return 0;
}