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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// Copyright (c) 2012-2017 VideoStitch SAS
// Copyright (c) 2018 stitchEm
#ifndef PHOTO_TRANSFORM_HPP_
#define PHOTO_TRANSFORM_HPP_
#include "backend/common/core/transformPhotoParam.hpp"
#include "coordinates.hpp"
#include <stdint.h>
namespace VideoStitch {
namespace Core {
class InputDefinition;
class PanoDefinition;
/**
* A class that represents the photometric transformations applied between an input and the pano output.
*/
class PhotoTransform {
public:
/**
* A class that holds an input's color correction parameters.
*/
class ColorCorrectionParams {
public:
/**
* Create from explicit values.
*/
ColorCorrectionParams(double ev, double redCB, double greenCB, double blueCB)
: ev(ev), redCB(redCB), greenCB(greenCB), blueCB(blueCB) {}
/**
* Create from a color multiplier so that greenCB == 1.0 if possible.
* Note that it's not always possible (e.g. if the green component if colorMult is 0.0 while the red or blue is >
* 0.0).
* @param colorMult multiplier
* @param panoEv Exposure value of the panorama
* @param panoRedCB red compensation value of the panorama
* @param panoGreenCB red compensation value of the panorama
* @param panoBlueCB red compensation value of the panorama
*/
static ColorCorrectionParams canonicalFromMultiplier(float3 colorMult, double panoEv, double panoRedCB,
double panoGreenCB, double panoBlueCB);
/**
* Computes the actual color multiplier (transfer function in linear space) for this correction.
* @param panoEv Exposure value of the panorama
*/
float3 computeColorMultiplier(double panoEv, double panoRedCB, double panoGreenCB, double panoBlueCB) const;
/**
* Exposure value.
*/
const double ev;
/**
* Red correction.
*/
const double redCB;
/**
* Green correction.
*/
const double greenCB;
/**
* Blue correction.
*/
const double blueCB;
};
virtual ~PhotoTransform() {}
protected:
explicit PhotoTransform(double idds);
PhotoTransform() {}
/**
* Compute vignetting multiplier.
* @param im Input definition. Must be the same as the one that was used to create the Transform.
* @param uv coordinates in input space, relative to the center of the input.
*/
double computeVignettingMult(const InputDefinition& im, const CenterCoords2& uv) const;
double computeVignettingMult(const InputDefinition& im, const TopLeftCoords2& uv) const;
/**
* Frame radius for vignetting.
*/
double inverseDemiDiagonalSquared;
friend class PhotoCorrPreProcessor;
};
class HostPhotoTransform : public PhotoTransform {
public:
HostPhotoTransform(double inverseDemiDiagonalSquared, TransformPhotoParam hostPhotoParam);
/**
* Creates a PhotoTransform that maps the given input into the given panorama.
* @param pano The PanoDefinition
* @param im The InputDefinition
*/
static HostPhotoTransform* create(const InputDefinition& im);
/**
* Transforms a single point on the CPU from input to panorama colorspace.
* Equivalent to (mapPhotoInputToLinear o mapPhotoCorrectLinear o mapPhotoLinearToPano)
* @param time Current time value.
* @param pano Panorama definition. Must be the same as the one that was used to create the Transform.
* @param im Input definition. Must be the same as the one that was used to create the Transform.
* @param uv coordinates in input space, relative to the top-left of the input. They take part in the photo transform
* through vignetting.
* @param rgb color in input space. In [0;255].
* @returns color in pano space
*/
float3 mapPhotoInputToPano(int time, const PanoDefinition& pano, const InputDefinition& im, TopLeftCoords2 uv,
float3 rgb) const;
/**
* Color-corrects a sample in linear space.
* @param colorMult color multiplier
* @param rgb Color In [0;255].
*/
float3 mapPhotoCorrectLinear(float3 colorMult, float3 rgb) const;
/**
* Same as above, but stops just before color correction is applied.
* @param im Input definition. Must be the same as the one that was used to create the Transform.
* @param uv coordinates in input space, relative to the top-left of the input. They take part in the photo transform
* through vignetting.
* @param rgb color in input space. In [0;255].
* @returns color in pano space
*/
virtual float3 mapPhotoInputToLinear(const InputDefinition& im, TopLeftCoords2 uv, float3 rgb) const = 0;
/**
* Takes a color-corrected sample in linear photo space and transform it to pano space.
* @param rgb Color In [0;255].
*/
virtual float3 mapPhotoLinearToPano(float3 rgb) const = 0;
/**
* Takes a pano space sample and transforms it to color-corrected linear photo space.
* @param rgb Color In [0;255].
*/
virtual float3 mapPhotoPanoToLinear(float3 rgb) const = 0;
const TransformPhotoParam& getHostPhotoParam() const { return hostPhotoParam; }
protected:
TransformPhotoParam hostPhotoParam;
};
class DevicePhotoTransform : public PhotoTransform {
public:
DevicePhotoTransform(double inverseDemiDiagonalSquared, TransformPhotoParam devicePhotoParam);
static DevicePhotoTransform* create(const InputDefinition& im);
const TransformPhotoParam& getDevicePhotoParam() const { return devicePhotoParam; }
protected:
TransformPhotoParam devicePhotoParam;
};
} // namespace Core
} // namespace VideoStitch
#endif