-
Notifications
You must be signed in to change notification settings - Fork 8
/
grader.h
101 lines (83 loc) · 2.36 KB
/
grader.h
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
#ifndef GRADER_HDR
#define GRADER_HDR
#include <stddef.h>
struct ColorGrader {
ColorGrader();
void setBrightness(double brightness);
void setContrast(double contrast);
double brightness() const;
double contrast() const;
enum {
kBalanceShadows,
kBalanceMidtones,
kBalanceHighlights,
kBalanceMax
};
enum {
kHuesAll,
kHuesRed,
kHuesYellow,
kHuesGreen,
kHuesCyan,
kHuesBlue,
kHuesMagenta,
kHuesMax
};
void setLuma(bool keep);
void setCR(double value, int what);
void setMG(double value, int what);
void setYB(double value, int what);
void setH(double hue, int what);
void setS(double saturation, int what);
void setL(double lightness, int what);
void setHueOverlap(double value);
bool luma() const;
double CR(int what) const;
double MG(int what) const;
double YB(int what) const;
double H(int what) const;
double S(int what) const;
double L(int what) const;
double hueOverlap() const;
const unsigned char *data() const;
bool updated() const;
void reset();
void update();
void grade();
protected:
void applyBrightnessContrast();
void applyColorBalance();
void applyHueSaturation();
void generateColorBalanceTables();
void generateHueSaturationTables();
void generateTexture();
// Color space conversion functions
static void RGB2HSL(int &red, int &green, int &blue);
static int HSLINT(double n1, double n2, double hue);
static void HSL2RGB(int &hue, int &saturation, int &lightness);
static int RGB2L(int red, int green, int blue);
private:
// Brightness & contrast
double m_brightness;
double m_contrast;
// Hue & saturation
double m_hue[kHuesMax];
double m_lightness[kHuesMax];
double m_saturation[kHuesMax];
double m_hueOverlap;
int m_hLookup[6][256];
int m_sLookup[6][256];
int m_lLookup[6][256];
// color balance
bool m_preserveLuma;
double m_balance[3][kBalanceMax];
double m_balanceAdd[kBalanceMax][256];
double m_balanceSub[kBalanceMax][256];
unsigned char m_balanceLookup[3][256];
// 3D LUT
static constexpr size_t kWidth = 256u; //16*16
static constexpr size_t kHeight = 16u;
unsigned char m_data[kWidth * kHeight * 3];
bool m_updated;
};
#endif