just make a little part of saturation correction
This commit is contained in:
@@ -33,9 +33,10 @@ struct color_gain {
|
||||
double red;
|
||||
double green;
|
||||
double blue;
|
||||
} color_gain{1.3, 0.8, 1.3};
|
||||
} color_gain{1.1, 0.7, 1.3};
|
||||
|
||||
static const double gamma_value = 2.2;
|
||||
static const double saturation_inc = -0.5;
|
||||
|
||||
using namespace sc_core;
|
||||
using namespace sc_dt;
|
||||
@@ -253,6 +254,7 @@ int sc_main(int argc, char* argv[]) {
|
||||
gamma_enable = true;
|
||||
gamma_inverse = (uint32_t)((1.0 / gamma_value) * std::pow(2, 8));
|
||||
for (int i = 0; i < 256; i++) {
|
||||
// calculate gamma table
|
||||
isp->gamma_table[i](gamma_table[i]);
|
||||
gamma_table[i] = (uint32_t)(255 * pow(i / 255.0, 1.0 / gamma_value));
|
||||
}
|
||||
@@ -338,10 +340,44 @@ int sc_main(int argc, char* argv[]) {
|
||||
uint8_t green = (tb_isp.out[y * OUT_WIDTH + x] & 0x0000ff00) >> 8;
|
||||
uint8_t blue = (tb_isp.out[y * OUT_WIDTH + x] & 0x000000ff);
|
||||
|
||||
// Adjust gamma line
|
||||
// red = 255 * std::pow(red / 255.0, 1 / gamma_value);
|
||||
// green = 255 * std::pow(green / 255.0, 1 / gamma_value);
|
||||
// blue = 255 * std::pow(blue / 255.0, 1 / gamma_value);
|
||||
|
||||
// Adjust white balance
|
||||
|
||||
// Adjust vibrance
|
||||
uint8_t max = std::max({red, green, blue});
|
||||
uint8_t min = std::min({red, green, blue});
|
||||
double delta = (max - min) / 255.0;
|
||||
double value = (max + min) / 255.0;
|
||||
if (delta != 0) {
|
||||
double L = value / 2.0;
|
||||
// double S = (L <= 0.5) ? delta / value : delta / (2 - value);
|
||||
double S = delta / max;
|
||||
double alpha = 0.0;
|
||||
if (saturation_inc >= 0) {
|
||||
if ((saturation_inc + S) >= 1)
|
||||
alpha = S;
|
||||
else
|
||||
alpha = 1 - saturation_inc;
|
||||
alpha = 1 / alpha - 1;
|
||||
red = static_cast<uchar>(red + (red - L * 255) * alpha);
|
||||
green =
|
||||
static_cast<uchar>(green + (green - L * 255) * alpha);
|
||||
blue = static_cast<uchar>(blue + (blue - L * 255) * alpha);
|
||||
} else {
|
||||
alpha = saturation_inc;
|
||||
red = static_cast<uchar>(L * 255 +
|
||||
(red - L * 255) * (1 + alpha));
|
||||
green = static_cast<uchar>(L * 255 +
|
||||
(green - L * 255) * (1 + alpha));
|
||||
blue = static_cast<uchar>(L * 255 +
|
||||
(blue - L * 255) * (1 + alpha));
|
||||
}
|
||||
}
|
||||
|
||||
out_image.write((const char*)&red, sizeof(red));
|
||||
out_image.write((const char*)&green, sizeof(green));
|
||||
out_image.write((const char*)&blue, sizeof(blue));
|
||||
|
||||
Reference in New Issue
Block a user