|
@@ -47,9 +47,9 @@ ImageHDR::ImageHDR(float* d, unsigned int w, unsigned int h)
|
|
|
height = h;
|
|
|
this->min_intensity = d[0];
|
|
|
this->max_intensity = d[0];
|
|
|
- data = new float[width*height*3];
|
|
|
- for (unsigned int i = 0; i < width*height*3; i++) {
|
|
|
- data[i]=d[i];
|
|
|
+ data = new float[width * height * 3];
|
|
|
+ for (unsigned int i = 0; i < width * height * 3; i++) {
|
|
|
+ data[i] = d[i];
|
|
|
if (this->min_intensity > data[i])
|
|
|
this->min_intensity = data[i];
|
|
|
if (this->max_intensity < data[i])
|
|
@@ -122,10 +122,10 @@ void ImageHDR::exposure(const float ev)
|
|
|
float coeff = powf(2, ev);
|
|
|
|
|
|
if (!linear)
|
|
|
- {
|
|
|
- non_linear_to_linear();
|
|
|
- linear = true;
|
|
|
- }
|
|
|
+ {
|
|
|
+ non_linear_to_linear();
|
|
|
+ linear = true;
|
|
|
+ }
|
|
|
|
|
|
std::thread tab_t[_MT_];
|
|
|
MT_exposure tab_a[_MT_];
|
|
@@ -137,7 +137,7 @@ void ImageHDR::exposure(const float ev)
|
|
|
tab_a[id].data = data + (id * block_size);
|
|
|
tab_a[id].length = block_size;
|
|
|
tab_a[id].coeff = coeff;
|
|
|
-
|
|
|
+
|
|
|
if (id == (_MT_ - 1))
|
|
|
tab_a[id].length = tab_length - ((_MT_ - 1) * block_size);
|
|
|
|
|
@@ -157,10 +157,10 @@ void ImageHDR::exposure(const float ev)
|
|
|
float coef = powf(2, ev);
|
|
|
|
|
|
if (!linear)
|
|
|
- {
|
|
|
- non_linear_to_linear();
|
|
|
- linear = true;
|
|
|
- }
|
|
|
+ {
|
|
|
+ non_linear_to_linear();
|
|
|
+ linear = true;
|
|
|
+ }
|
|
|
|
|
|
for (unsigned int i = 0; i < width * height * 3; i++)
|
|
|
data[i] *= coef;
|
|
@@ -192,26 +192,26 @@ void ImageHDR::contrast(const float c)
|
|
|
{
|
|
|
float max_contrast_factor = 2.0f, scaling_factor = 1.0f, contrast_value = c;
|
|
|
|
|
|
- if (linear)
|
|
|
+ if (contrast_value != 0.0f)
|
|
|
+ {
|
|
|
+ if (linear)
|
|
|
{
|
|
|
linear_to_non_linear();
|
|
|
linear = false;
|
|
|
}
|
|
|
|
|
|
- if (contrast_value != 0.0f)
|
|
|
+ contrast_value = contrast_value / 100.0f;
|
|
|
+ if (contrast_value > 0.0f)
|
|
|
+ {
|
|
|
+ scaling_factor = 1 * (1 - contrast_value) + max_contrast_factor * contrast_value;
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- contrast_value = contrast_value / 100.0f;
|
|
|
- if (contrast_value > 0.0f)
|
|
|
- {
|
|
|
- scaling_factor = 1 * (1 - contrast_value) + max_contrast_factor * contrast_value;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- contrast_value = -contrast_value;
|
|
|
- scaling_factor = 1 * (1 - contrast_value) + max_contrast_factor * contrast_value;
|
|
|
- scaling_factor = 1 / scaling_factor;
|
|
|
- }
|
|
|
+ contrast_value = -contrast_value;
|
|
|
+ scaling_factor = 1 * (1 - contrast_value) + max_contrast_factor * contrast_value;
|
|
|
+ scaling_factor = 1 / scaling_factor;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
std::thread tab_t[_MT_];
|
|
|
MT_contrast tab_a[_MT_];
|
|
@@ -220,16 +220,16 @@ void ImageHDR::contrast(const float c)
|
|
|
unsigned int tab_length = width * height * 3;
|
|
|
unsigned int block_size = tab_length / _MT_;
|
|
|
for (id = 0; id < _MT_; id++)
|
|
|
- {
|
|
|
- tab_a[id].data = data + (id * block_size);
|
|
|
- tab_a[id].length = block_size;
|
|
|
- tab_a[id].coeff = scaling_factor;
|
|
|
+ {
|
|
|
+ tab_a[id].data = data + (id * block_size);
|
|
|
+ tab_a[id].length = block_size;
|
|
|
+ tab_a[id].coeff = scaling_factor;
|
|
|
|
|
|
- if (id == (_MT_ - 1))
|
|
|
- tab_a[id].length = tab_length - ((_MT_ - 1) * block_size);
|
|
|
+ if (id == (_MT_ - 1))
|
|
|
+ tab_a[id].length = tab_length - ((_MT_ - 1) * block_size);
|
|
|
|
|
|
- tab_t[id] = std::thread(contrast_MT, (void*)(tab_a + id));
|
|
|
- }
|
|
|
+ tab_t[id] = std::thread(contrast_MT, (void*)(tab_a + id));
|
|
|
+ }
|
|
|
|
|
|
for (id = 0; id < _MT_; id++) {
|
|
|
tab_t[id].join();
|
|
@@ -243,25 +243,25 @@ void ImageHDR::contrast(const float c)
|
|
|
float max_contrast_factor = 2.0f, scaling_factor = 1.0f, contrast_value = c;
|
|
|
|
|
|
if (linear)
|
|
|
- {
|
|
|
- linear_to_non_linear();
|
|
|
- linear = false;
|
|
|
- }
|
|
|
+ {
|
|
|
+ linear_to_non_linear();
|
|
|
+ linear = false;
|
|
|
+ }
|
|
|
|
|
|
if (contrast_value != 0.0f)
|
|
|
+ {
|
|
|
+ contrast_value = contrast_value / 100.0f;
|
|
|
+ if (contrast_value > 0.0f)
|
|
|
+ {
|
|
|
+ scaling_factor = 1 * (1 - contrast_value) + max_contrast_factor * contrast_value;
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- contrast_value = contrast_value / 100.0f;
|
|
|
- if (contrast_value > 0.0f)
|
|
|
- {
|
|
|
- scaling_factor = 1 * (1 - contrast_value) + max_contrast_factor * contrast_value;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- contrast_value = -contrast_value;
|
|
|
- scaling_factor = 1 * (1 - contrast_value) + max_contrast_factor * contrast_value;
|
|
|
- scaling_factor = 1 / scaling_factor;
|
|
|
- }
|
|
|
+ contrast_value = -contrast_value;
|
|
|
+ scaling_factor = 1 * (1 - contrast_value) + max_contrast_factor * contrast_value;
|
|
|
+ scaling_factor = 1 / scaling_factor;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
for (unsigned int i = 0; i < width * height * 3; i++)
|
|
|
data[i] = scaling_factor * (data[i] - 0.5f) + 0.5f;
|
|
@@ -287,11 +287,11 @@ void* histogram_regularization_MT(void* arg)
|
|
|
float* colorDataFY = a->colorDataFY;
|
|
|
|
|
|
for (unsigned int i = 0; i < a->length; i++)
|
|
|
- {
|
|
|
- data[i * 3] = data[i * 3] * colorDataFY[i] / colorDataY[i];
|
|
|
- data[i * 3 + 1] = data[i * 3 + 1] * colorDataFY[i] / colorDataY[i];
|
|
|
- data[i * 3 + 2] = data[i * 3 + 2] * colorDataFY[i] / colorDataY[i];
|
|
|
- }
|
|
|
+ {
|
|
|
+ data[i * 3] = data[i * 3] * colorDataFY[i] / colorDataY[i];
|
|
|
+ data[i * 3 + 1] = data[i * 3 + 1] * colorDataFY[i] / colorDataY[i];
|
|
|
+ data[i * 3 + 2] = data[i * 3 + 2] * colorDataFY[i] / colorDataY[i];
|
|
|
+ }
|
|
|
|
|
|
return arg;
|
|
|
}
|
|
@@ -339,28 +339,23 @@ void ImageHDR::ycurve_histogram_regularization(float* colorDataY, float* colorDa
|
|
|
|
|
|
void ImageHDR::yCurve(float s, float b, float m, float w, float h)
|
|
|
{
|
|
|
+
|
|
|
if (linear)
|
|
|
- {
|
|
|
- linear_to_non_linear();
|
|
|
- linear = false;
|
|
|
- }
|
|
|
+ {
|
|
|
+ linear_to_non_linear();
|
|
|
+ linear = false;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
float* colorDataY = Conversion::sRGB_to_Y_of_XYZ(data, width * height);
|
|
|
|
|
|
+ YCurve yc(s, b, m, w, h, 200);
|
|
|
|
|
|
- float yMax = colorDataY[0];
|
|
|
- for (unsigned int i = 0; i < width * height; i++)
|
|
|
- if (yMax < colorDataY[i])
|
|
|
- yMax = colorDataY[i];
|
|
|
-
|
|
|
- yMax = yMax * 100;
|
|
|
|
|
|
+ Eigen::MatrixXf* points = yc.evalpts(100);
|
|
|
|
|
|
- YCurve yc(s, b, m, w, h, yMax);
|
|
|
-
|
|
|
+ std::cout << *points << std::endl;
|
|
|
|
|
|
- Eigen::MatrixXf* points = yc.evalpts(100);
|
|
|
Eigen::RowVectorXf y = (*points).col(0) / 100;
|
|
|
Eigen::RowVectorXf fy = (*points).col(1) / 100;
|
|
|
delete(points);
|
|
@@ -370,9 +365,8 @@ void ImageHDR::yCurve(float s, float b, float m, float w, float h)
|
|
|
// The index of the search method in utils.cpp could be calculated or determined ?
|
|
|
float* colorDataFY = Utils::interp(colorDataY, width * height, y, fy);
|
|
|
|
|
|
-
|
|
|
ycurve_histogram_regularization(colorDataY, colorDataFY);
|
|
|
-
|
|
|
+
|
|
|
delete[](colorDataY);
|
|
|
delete[](colorDataFY);
|
|
|
}
|
|
@@ -395,33 +389,26 @@ void ImageHDR::ycurve_histogram_regularization(float* colorDataY, float* colorDa
|
|
|
colorDataY[i] = yMin;
|
|
|
|
|
|
for (unsigned int i = 0; i < width * height; i++)
|
|
|
- {
|
|
|
- data[i * 3] = data[i * 3] * colorDataFY[i] / colorDataY[i];
|
|
|
- data[i * 3 + 1] = data[i * 3 + 1] * colorDataFY[i] / colorDataY[i];
|
|
|
- data[i * 3 + 2] = data[i * 3 + 2] * colorDataFY[i] / colorDataY[i];
|
|
|
- }
|
|
|
+ {
|
|
|
+ data[i * 3] = data[i * 3] * colorDataFY[i] / colorDataY[i];
|
|
|
+ data[i * 3 + 1] = data[i * 3 + 1] * colorDataFY[i] / colorDataY[i];
|
|
|
+ data[i * 3 + 2] = data[i * 3 + 2] * colorDataFY[i] / colorDataY[i];
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
void ImageHDR::yCurve(float s, float b, float m, float w, float h)
|
|
|
{
|
|
|
if (linear)
|
|
|
- {
|
|
|
- linear_to_non_linear();
|
|
|
- linear = false;
|
|
|
- }
|
|
|
+ {
|
|
|
+ linear_to_non_linear();
|
|
|
+ linear = false;
|
|
|
+ }
|
|
|
|
|
|
float* colorDataY = Conversion::sRGB_to_Y_of_XYZ(data, width * height);
|
|
|
|
|
|
|
|
|
- float yMax = colorDataY[0];
|
|
|
- for (unsigned int i = 0; i < width * height; i++)
|
|
|
- if (yMax < colorDataY[i])
|
|
|
- yMax = colorDataY[i];
|
|
|
-
|
|
|
- yMax = yMax * 100;
|
|
|
-
|
|
|
- YCurve yc(s, b, m, w, h, yMax);
|
|
|
+ YCurve yc(s, b, m, w, h, 200);
|
|
|
|
|
|
|
|
|
Eigen::MatrixXf* points = yc.evalpts(100);
|
|
@@ -458,34 +445,34 @@ void* lightness_MT(void* arg)
|
|
|
bool* mask = a->mask;
|
|
|
|
|
|
float rangeMask[5][2] =
|
|
|
- {
|
|
|
- {0.0f, 0.2f},
|
|
|
- {0.2f, 0.4f},
|
|
|
- {0.4f, 0.6f},
|
|
|
- {0.6f, 0.8f},
|
|
|
- {0.8f, 1.0f}
|
|
|
- };
|
|
|
+ {
|
|
|
+ {0.0f, 0.2f},
|
|
|
+ {0.2f, 0.4f},
|
|
|
+ {0.4f, 0.6f},
|
|
|
+ {0.6f, 0.8f},
|
|
|
+ {0.8f, 1.0f}
|
|
|
+ };
|
|
|
|
|
|
unsigned int maskColor[5][3] =
|
|
|
- {
|
|
|
- {0, 0, 1},
|
|
|
- {0, 1, 1},
|
|
|
- {0, 1, 0},
|
|
|
- {1, 1, 0},
|
|
|
- {1, 0, 0}
|
|
|
- };
|
|
|
+ {
|
|
|
+ {0, 0, 1},
|
|
|
+ {0, 1, 1},
|
|
|
+ {0, 1, 0},
|
|
|
+ {1, 1, 0},
|
|
|
+ {1, 0, 0}
|
|
|
+ };
|
|
|
|
|
|
for (unsigned int i = 0; i < a->length; i++)
|
|
|
- {
|
|
|
- for (unsigned int j = 0; j < 5; j++)
|
|
|
- if (mask[j])
|
|
|
- if (colorDataY[i] >= rangeMask[j][0] && colorDataY[i] <= rangeMask[j][1])
|
|
|
- {
|
|
|
- data[i * 3] = (float)(maskColor[j][0]);
|
|
|
- data[i * 3 + 1] = (float)(maskColor[j][1]);
|
|
|
- data[i * 3 + 2] = (float)(maskColor[j][2]);
|
|
|
- }
|
|
|
- }
|
|
|
+ {
|
|
|
+ for (unsigned int j = 0; j < 5; j++)
|
|
|
+ if (mask[j])
|
|
|
+ if (colorDataY[i] >= rangeMask[j][0] && colorDataY[i] <= rangeMask[j][1])
|
|
|
+ {
|
|
|
+ data[i * 3] = (float)(maskColor[j][0]);
|
|
|
+ data[i * 3 + 1] = (float)(maskColor[j][1]);
|
|
|
+ data[i * 3 + 2] = (float)(maskColor[j][2]);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
return arg;
|
|
|
}
|
|
@@ -495,10 +482,10 @@ void ImageHDR::lightnessMask(bool s, bool b, bool m, bool w, bool h)
|
|
|
bool mask[5] = { s, b, m, w, h };
|
|
|
|
|
|
if (linear)
|
|
|
- {
|
|
|
- linear_to_non_linear();
|
|
|
- linear = false;
|
|
|
- }
|
|
|
+ {
|
|
|
+ linear_to_non_linear();
|
|
|
+ linear = false;
|
|
|
+ }
|
|
|
|
|
|
float* colorDataY = Conversion::sRGB_to_Y_of_XYZ(data, width * height);
|
|
|
|
|
@@ -535,42 +522,42 @@ void ImageHDR::lightnessMask(bool s, bool b, bool m, bool w, bool h)
|
|
|
bool mask[5] = { s, b, m, w, h };
|
|
|
|
|
|
float rangeMask[5][2] =
|
|
|
- {
|
|
|
- {0.0f, 0.2f},
|
|
|
- {0.2f, 0.4f},
|
|
|
- {0.4f, 0.6f},
|
|
|
- {0.6f, 0.8f},
|
|
|
- {0.8f, 1.0f}
|
|
|
- };
|
|
|
+ {
|
|
|
+ {0.0f, 0.2f},
|
|
|
+ {0.2f, 0.4f},
|
|
|
+ {0.4f, 0.6f},
|
|
|
+ {0.6f, 0.8f},
|
|
|
+ {0.8f, 1.0f}
|
|
|
+ };
|
|
|
|
|
|
unsigned int maskColor[5][3] =
|
|
|
- {
|
|
|
- {0, 0, 1},
|
|
|
- {0, 1, 1},
|
|
|
- {0, 1, 0},
|
|
|
- {1, 1, 0},
|
|
|
- {1, 0, 0}
|
|
|
- };
|
|
|
+ {
|
|
|
+ {0, 0, 1},
|
|
|
+ {0, 1, 1},
|
|
|
+ {0, 1, 0},
|
|
|
+ {1, 1, 0},
|
|
|
+ {1, 0, 0}
|
|
|
+ };
|
|
|
|
|
|
if (linear)
|
|
|
- {
|
|
|
- linear_to_non_linear();
|
|
|
- linear = false;
|
|
|
- }
|
|
|
+ {
|
|
|
+ linear_to_non_linear();
|
|
|
+ linear = false;
|
|
|
+ }
|
|
|
|
|
|
float* colorDataY = Conversion::sRGB_to_Y_of_XYZ(data, width * height);
|
|
|
|
|
|
for (unsigned int i = 0; i < width * height; i++)
|
|
|
- {
|
|
|
- for (unsigned int j = 0; j < 5; j++)
|
|
|
- if (mask[j])
|
|
|
- if (colorDataY[i] >= rangeMask[j][0] && colorDataY[i] <= rangeMask[j][1])
|
|
|
- {
|
|
|
- data[i * 3] = (float)(maskColor[j][0]);
|
|
|
- data[i * 3 + 1] = (float)(maskColor[j][1]);
|
|
|
- data[i * 3 + 2] = (float)(maskColor[j][2]);
|
|
|
- }
|
|
|
- }
|
|
|
+ {
|
|
|
+ for (unsigned int j = 0; j < 5; j++)
|
|
|
+ if (mask[j])
|
|
|
+ if (colorDataY[i] >= rangeMask[j][0] && colorDataY[i] <= rangeMask[j][1])
|
|
|
+ {
|
|
|
+ data[i * 3] = (float)(maskColor[j][0]);
|
|
|
+ data[i * 3 + 1] = (float)(maskColor[j][1]);
|
|
|
+ data[i * 3 + 2] = (float)(maskColor[j][2]);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
delete[](colorDataY);
|
|
|
}
|
|
@@ -592,14 +579,14 @@ void* saturation_MT(void* arg)
|
|
|
float* dataLab = a->dataLab;
|
|
|
|
|
|
for (unsigned int i = 0; i < a->length; i++)
|
|
|
- {
|
|
|
- float a_of_Lab = dataLab[i * 3 + 1];
|
|
|
- float b_of_Lab = dataLab[i * 3 + 2];
|
|
|
- dataLab[i * 3 + 1] = Conversion::Lab_to_C_of_LCH(a_of_Lab, b_of_Lab);
|
|
|
- // Application de la saturation
|
|
|
- dataLab[i * 3 + 1] = powf(dataLab[i * 3 + 1] / 100.0f, a->gamma) * 100.0f;
|
|
|
- dataLab[i * 3 + 2] = Conversion::Lab_to_H_of_LCH(a_of_Lab, b_of_Lab);
|
|
|
- }
|
|
|
+ {
|
|
|
+ float a_of_Lab = dataLab[i * 3 + 1];
|
|
|
+ float b_of_Lab = dataLab[i * 3 + 2];
|
|
|
+ dataLab[i * 3 + 1] = Conversion::Lab_to_C_of_LCH(a_of_Lab, b_of_Lab);
|
|
|
+ // Application de la saturation
|
|
|
+ dataLab[i * 3 + 1] = powf(dataLab[i * 3 + 1] / 100.0f, a->gamma) * 100.0f;
|
|
|
+ dataLab[i * 3 + 2] = Conversion::Lab_to_H_of_LCH(a_of_Lab, b_of_Lab);
|
|
|
+ }
|
|
|
|
|
|
return arg;
|
|
|
}
|
|
@@ -611,10 +598,10 @@ void ImageHDR::saturation(float s)
|
|
|
gamma = (-s / 25.0f) + 1.0f;
|
|
|
|
|
|
if (!linear)
|
|
|
- {
|
|
|
- non_linear_to_linear();
|
|
|
- linear = false;
|
|
|
- }
|
|
|
+ {
|
|
|
+ non_linear_to_linear();
|
|
|
+ linear = false;
|
|
|
+ }
|
|
|
|
|
|
float* dataLab = Conversion::sRGB_to_Lab(data, width * height);
|
|
|
|
|
@@ -656,22 +643,22 @@ void ImageHDR::saturation(float s)
|
|
|
gamma = (-s / 25.0f) + 1.0f;
|
|
|
|
|
|
if (!linear)
|
|
|
- {
|
|
|
- non_linear_to_linear();
|
|
|
- linear = false;
|
|
|
- }
|
|
|
+ {
|
|
|
+ non_linear_to_linear();
|
|
|
+ linear = false;
|
|
|
+ }
|
|
|
|
|
|
float* dataLab = Conversion::sRGB_to_Lab(data, width * height);
|
|
|
|
|
|
for (unsigned int i = 0; i < width * height; i++)
|
|
|
- {
|
|
|
- float a = dataLab[i * 3 + 1];
|
|
|
- float b = dataLab[i * 3 + 2];
|
|
|
- dataLab[i * 3 + 1] = Conversion::Lab_to_C_of_LCH(a, b);
|
|
|
- // Application de la saturation
|
|
|
- dataLab[i * 3 + 1] = powf(dataLab[i * 3 + 1] / 100.0f, gamma) * 100.0f;
|
|
|
- dataLab[i * 3 + 2] = Conversion::Lab_to_H_of_LCH(a, b);
|
|
|
- }
|
|
|
+ {
|
|
|
+ float a = dataLab[i * 3 + 1];
|
|
|
+ float b = dataLab[i * 3 + 2];
|
|
|
+ dataLab[i * 3 + 1] = Conversion::Lab_to_C_of_LCH(a, b);
|
|
|
+ // Application de la saturation
|
|
|
+ dataLab[i * 3 + 1] = powf(dataLab[i * 3 + 1] / 100.0f, gamma) * 100.0f;
|
|
|
+ dataLab[i * 3 + 2] = Conversion::Lab_to_H_of_LCH(a, b);
|
|
|
+ }
|
|
|
|
|
|
delete[](data);
|
|
|
data = dataLab;
|
|
@@ -722,243 +709,243 @@ void* colorEditor_MT(void* arg)
|
|
|
|
|
|
// not the default parameter
|
|
|
if (!(lMin == 0.0f && lMax == 100.0f
|
|
|
- && cMin == 0.0f && cMax == 100.0f
|
|
|
- && hMin == 0.0f && hMax == 360.0f
|
|
|
- && tolerance == 0.1f
|
|
|
- && edit_hue == 0.0f
|
|
|
- && edit_exposure == 0.0f
|
|
|
- && edit_contrast == 0.0f
|
|
|
- && edit_saturation == 0.0f
|
|
|
- && mask == false))
|
|
|
+ && cMin == 0.0f && cMax == 100.0f
|
|
|
+ && hMin == 0.0f && hMax == 360.0f
|
|
|
+ && tolerance == 0.1f
|
|
|
+ && edit_hue == 0.0f
|
|
|
+ && edit_exposure == 0.0f
|
|
|
+ && edit_contrast == 0.0f
|
|
|
+ && edit_saturation == 0.0f
|
|
|
+ && mask == false))
|
|
|
+ {
|
|
|
+ if (colorspace == Colorspace::RGB)
|
|
|
{
|
|
|
- if (colorspace == Colorspace::RGB)
|
|
|
- {
|
|
|
- if (!linear)
|
|
|
- {
|
|
|
- data = Conversion::non_linear_to_linear(data, length * 3);
|
|
|
- linear = true;
|
|
|
- }
|
|
|
-
|
|
|
- dataLCH = Conversion::sRGB_to_Lab(data, length);
|
|
|
-
|
|
|
- for (unsigned int i = 0; i < length; i++)
|
|
|
- {
|
|
|
- float a = dataLCH[i * 3 + 1];
|
|
|
- float b = dataLCH[i * 3 + 2];
|
|
|
- dataLCH[i * 3 + 1] = Conversion::Lab_to_C_of_LCH(a, b);
|
|
|
- dataLCH[i * 3 + 2] = Conversion::Lab_to_H_of_LCH(a, b);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- dataLCH = data;
|
|
|
-
|
|
|
- float* lChannel = new float[length];
|
|
|
- float* cChannel = new float[length];
|
|
|
- float* hChannel = new float[length];
|
|
|
+ if (!linear)
|
|
|
+ {
|
|
|
+ data = Conversion::non_linear_to_linear(data, length * 3);
|
|
|
+ linear = true;
|
|
|
+ }
|
|
|
|
|
|
- for (unsigned int i = 0; i < length; i++)
|
|
|
- {
|
|
|
- lChannel[i] = dataLCH[i * 3];
|
|
|
- cChannel[i] = dataLCH[i * 3 + 1];
|
|
|
- hChannel[i] = dataLCH[i * 3 + 2];
|
|
|
- }
|
|
|
+ dataLCH = Conversion::sRGB_to_Lab(data, length);
|
|
|
|
|
|
- // Récupération du max du canal L et C
|
|
|
- float lMaxChannel = dataLCH[0];
|
|
|
- float cMaxChannel = dataLCH[1];
|
|
|
- for (unsigned int i = 1; i < length; i++)
|
|
|
- {
|
|
|
- if (dataLCH[i * 3] > lMaxChannel)
|
|
|
- lMaxChannel = dataLCH[i * 3];
|
|
|
- if (dataLCH[i * 3 + 1] > cMaxChannel)
|
|
|
- cMaxChannel = dataLCH[i * 3 + 1];
|
|
|
- }
|
|
|
+ for (unsigned int i = 0; i < length; i++)
|
|
|
+ {
|
|
|
+ float a = dataLCH[i * 3 + 1];
|
|
|
+ float b = dataLCH[i * 3 + 2];
|
|
|
+ dataLCH[i * 3 + 1] = Conversion::Lab_to_C_of_LCH(a, b);
|
|
|
+ dataLCH[i * 3 + 2] = Conversion::Lab_to_H_of_LCH(a, b);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ dataLCH = data;
|
|
|
|
|
|
- if (lMaxChannel < 100.0f)
|
|
|
- lMaxChannel = 100.0f;
|
|
|
- if (cMaxChannel < 100.0f)
|
|
|
- cMaxChannel = 100.0f;
|
|
|
+ float* lChannel = new float[length];
|
|
|
+ float* cChannel = new float[length];
|
|
|
+ float* hChannel = new float[length];
|
|
|
|
|
|
- lMax = lMax * lMaxChannel / 100.0f;
|
|
|
- cMax = cMax * cMaxChannel / 100.0f;
|
|
|
+ for (unsigned int i = 0; i < length; i++)
|
|
|
+ {
|
|
|
+ lChannel[i] = dataLCH[i * 3];
|
|
|
+ cChannel[i] = dataLCH[i * 3 + 1];
|
|
|
+ hChannel[i] = dataLCH[i * 3 + 2];
|
|
|
+ }
|
|
|
|
|
|
- float* lightnessMask = Utils::NPlinearWeightMask(lChannel, length, lMin, lMax, lightTolerance);
|
|
|
+ // Récupération du max du canal L et C
|
|
|
+ float lMaxChannel = dataLCH[0];
|
|
|
+ float cMaxChannel = dataLCH[1];
|
|
|
+ for (unsigned int i = 1; i < length; i++)
|
|
|
+ {
|
|
|
+ if (dataLCH[i * 3] > lMaxChannel)
|
|
|
+ lMaxChannel = dataLCH[i * 3];
|
|
|
+ if (dataLCH[i * 3 + 1] > cMaxChannel)
|
|
|
+ cMaxChannel = dataLCH[i * 3 + 1];
|
|
|
+ }
|
|
|
|
|
|
- float* chromaMask = Utils::NPlinearWeightMask(cChannel, length, cMin, cMax, chromaTolerance);
|
|
|
+ if (lMaxChannel < 100.0f)
|
|
|
+ lMaxChannel = 100.0f;
|
|
|
+ if (cMaxChannel < 100.0f)
|
|
|
+ cMaxChannel = 100.0f;
|
|
|
|
|
|
+ lMax = lMax * lMaxChannel / 100.0f;
|
|
|
+ cMax = cMax * cMaxChannel / 100.0f;
|
|
|
|
|
|
- float* hueMask = Utils::NPlinearWeightMask(hChannel, length, hMin, hMax, hueTolerance);
|
|
|
+ float* lightnessMask = Utils::NPlinearWeightMask(lChannel, length, lMin, lMax, lightTolerance);
|
|
|
|
|
|
+ float* chromaMask = Utils::NPlinearWeightMask(cChannel, length, cMin, cMax, chromaTolerance);
|
|
|
|
|
|
- minMask = new float[length];
|
|
|
- compMask = new float[length];
|
|
|
|
|
|
+ float* hueMask = Utils::NPlinearWeightMask(hChannel, length, hMin, hMax, hueTolerance);
|
|
|
|
|
|
- for (unsigned int i = 0; i < length; i++)
|
|
|
- {
|
|
|
- minMask[i] = lightnessMask[i];
|
|
|
- if (chromaMask[i] < minMask[i])
|
|
|
- minMask[i] = chromaMask[i];
|
|
|
- if (hueMask[i] < minMask[i])
|
|
|
- minMask[i] = hueMask[i];
|
|
|
- compMask[i] = 1.0f - minMask[i];
|
|
|
- }
|
|
|
-
|
|
|
- delete[](lightnessMask);
|
|
|
- delete[](chromaMask);
|
|
|
- delete[](hueMask);
|
|
|
-
|
|
|
- float hueShift = edit_hue;
|
|
|
-
|
|
|
- for (unsigned int i = 0; i < length; i++) {
|
|
|
- float oldValue = hChannel[i];
|
|
|
- hChannel[i] = oldValue + hueShift;
|
|
|
- while (hChannel[i] < 0.0f)
|
|
|
- hChannel[i] += 360.0f;
|
|
|
- while (hChannel[i] >= 360.0f)
|
|
|
- hChannel[i] -= 360.0f;
|
|
|
- hChannel[i] = hChannel[i] * minMask[i] + oldValue * compMask[i];
|
|
|
- }
|
|
|
|
|
|
+ minMask = new float[length];
|
|
|
+ compMask = new float[length];
|
|
|
|
|
|
- float saturation = edit_saturation;
|
|
|
- float gamma = 1.0f / ((saturation / 25.0f) + 1.0f);
|
|
|
- if (saturation < 0)
|
|
|
- gamma = (-saturation / 25.0f) + 1.0f;
|
|
|
|
|
|
+ for (unsigned int i = 0; i < length; i++)
|
|
|
+ {
|
|
|
+ minMask[i] = lightnessMask[i];
|
|
|
+ if (chromaMask[i] < minMask[i])
|
|
|
+ minMask[i] = chromaMask[i];
|
|
|
+ if (hueMask[i] < minMask[i])
|
|
|
+ minMask[i] = hueMask[i];
|
|
|
+ compMask[i] = 1.0f - minMask[i];
|
|
|
+ }
|
|
|
|
|
|
- for (unsigned int i = 0; i < length; i++) {
|
|
|
- cChannel[i] = powf(cChannel[i] / 100.0f, gamma) * 100 * minMask[i] + cChannel[i] * compMask[i];
|
|
|
- }
|
|
|
+ delete[](lightnessMask);
|
|
|
+ delete[](chromaMask);
|
|
|
+ delete[](hueMask);
|
|
|
|
|
|
+ float hueShift = edit_hue;
|
|
|
|
|
|
+ for (unsigned int i = 0; i < length; i++) {
|
|
|
+ float oldValue = hChannel[i];
|
|
|
+ hChannel[i] = oldValue + hueShift;
|
|
|
+ while (hChannel[i] < 0.0f)
|
|
|
+ hChannel[i] += 360.0f;
|
|
|
+ while (hChannel[i] >= 360.0f)
|
|
|
+ hChannel[i] -= 360.0f;
|
|
|
+ hChannel[i] = hChannel[i] * minMask[i] + oldValue * compMask[i];
|
|
|
+ }
|
|
|
|
|
|
- float* colorLCH = new float[length * 3];
|
|
|
|
|
|
- for (unsigned int i = 0; i < length; i++)
|
|
|
- {
|
|
|
- colorLCH[i * 3] = lChannel[i];
|
|
|
- colorLCH[i * 3 + 1] = cChannel[i];
|
|
|
- colorLCH[i * 3 + 2] = hChannel[i];
|
|
|
- }
|
|
|
+ float saturation = edit_saturation;
|
|
|
+ float gamma = 1.0f / ((saturation / 25.0f) + 1.0f);
|
|
|
+ if (saturation < 0)
|
|
|
+ gamma = (-saturation / 25.0f) + 1.0f;
|
|
|
|
|
|
- delete[](lChannel);
|
|
|
- delete[](cChannel);
|
|
|
- delete[](hChannel);
|
|
|
|
|
|
- float ev = edit_exposure;
|
|
|
- float* colorRGB = NULL;
|
|
|
+ for (unsigned int i = 0; i < length; i++) {
|
|
|
+ cChannel[i] = powf(cChannel[i] / 100.0f, gamma) * 100 * minMask[i] + cChannel[i] * compMask[i];
|
|
|
+ }
|
|
|
|
|
|
- if (ev != 0)
|
|
|
- {
|
|
|
- colorRGB = Conversion::LCH_to_sRGB(colorLCH, length);
|
|
|
|
|
|
- float* colorRGBev = new float[length * 3];
|
|
|
- float coeff = powf(2, ev);
|
|
|
|
|
|
- for (unsigned int i = 0; i < length; i++)
|
|
|
- {
|
|
|
- colorRGBev[i * 3] = colorRGB[i * 3] * coeff * minMask[i];
|
|
|
- colorRGBev[i * 3 + 1] = colorRGB[i * 3 + 1] * coeff * minMask[i];
|
|
|
- colorRGBev[i * 3 + 2] = colorRGB[i * 3 + 2] * coeff * minMask[i];
|
|
|
+ float* colorLCH = new float[length * 3];
|
|
|
|
|
|
- colorRGB[i * 3] = colorRGB[i * 3] * compMask[i] + colorRGBev[i * 3];
|
|
|
- colorRGB[i * 3 + 1] = colorRGB[i * 3 + 1] * compMask[i] + colorRGBev[i * 3 + 1];
|
|
|
- colorRGB[i * 3 + 2] = colorRGB[i * 3 + 2] * compMask[i] + colorRGBev[i * 3 + 2];
|
|
|
+ for (unsigned int i = 0; i < length; i++)
|
|
|
+ {
|
|
|
+ colorLCH[i * 3] = lChannel[i];
|
|
|
+ colorLCH[i * 3 + 1] = cChannel[i];
|
|
|
+ colorLCH[i * 3 + 2] = hChannel[i];
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ delete[](lChannel);
|
|
|
+ delete[](cChannel);
|
|
|
+ delete[](hChannel);
|
|
|
|
|
|
- delete[](colorRGBev);
|
|
|
+ float ev = edit_exposure;
|
|
|
+ float* colorRGB = NULL;
|
|
|
|
|
|
- }
|
|
|
+ if (ev != 0)
|
|
|
+ {
|
|
|
+ colorRGB = Conversion::LCH_to_sRGB(colorLCH, length);
|
|
|
|
|
|
- if (edit_contrast != 0)
|
|
|
- {
|
|
|
- float contrast = edit_contrast / 100.0f;
|
|
|
- float maxContrastFactor = 2.0f;
|
|
|
- float scalingFactor = (1.0f - contrast) + maxContrastFactor * contrast;
|
|
|
- if (contrast < 0.0f)
|
|
|
- {
|
|
|
- contrast = -contrast;
|
|
|
- scalingFactor = 1.0f / scalingFactor;
|
|
|
- }
|
|
|
+ float* colorRGBev = new float[length * 3];
|
|
|
+ float coeff = powf(2, ev);
|
|
|
|
|
|
- float pivot = powf(2, ev) * (lMin + lMax) / 2.0f / 100.0f;
|
|
|
+ for (unsigned int i = 0; i < length; i++)
|
|
|
+ {
|
|
|
+ colorRGBev[i * 3] = colorRGB[i * 3] * coeff * minMask[i];
|
|
|
+ colorRGBev[i * 3 + 1] = colorRGB[i * 3 + 1] * coeff * minMask[i];
|
|
|
+ colorRGBev[i * 3 + 2] = colorRGB[i * 3 + 2] * coeff * minMask[i];
|
|
|
|
|
|
+ colorRGB[i * 3] = colorRGB[i * 3] * compMask[i] + colorRGBev[i * 3];
|
|
|
+ colorRGB[i * 3 + 1] = colorRGB[i * 3 + 1] * compMask[i] + colorRGBev[i * 3 + 1];
|
|
|
+ colorRGB[i * 3 + 2] = colorRGB[i * 3 + 2] * compMask[i] + colorRGBev[i * 3 + 2];
|
|
|
|
|
|
- if (colorRGB == NULL)
|
|
|
- colorRGB = Conversion::LCH_to_sRGB(colorLCH, length);
|
|
|
-
|
|
|
- float* colorRGB2 = Conversion::linear_to_non_linear(colorRGB, length * 3);
|
|
|
- delete[](colorRGB);
|
|
|
- colorRGB=colorRGB2;
|
|
|
+ }
|
|
|
|
|
|
+ delete[](colorRGBev);
|
|
|
|
|
|
- float* colorRGBcon = new float[length * 3];
|
|
|
-
|
|
|
- for (unsigned int i = 0; i < length; i++)
|
|
|
- {
|
|
|
- colorRGBcon[i * 3] = (colorRGB[i * 3] - pivot) * scalingFactor + pivot;
|
|
|
- colorRGBcon[i * 3 + 1] = (colorRGB[i * 3 + 1] - pivot) * scalingFactor + pivot;
|
|
|
- colorRGBcon[i * 3 + 2] = (colorRGB[i * 3 + 2] - pivot) * scalingFactor + pivot;
|
|
|
- colorRGB[i * 3] = colorRGBcon[i * 3] * minMask[i] + colorRGB[i * 3] * compMask[i];
|
|
|
- colorRGB[i * 3 + 1] = colorRGBcon[i * 3 + 1] * minMask[i] + colorRGB[i * 3 + 1] * compMask[i];
|
|
|
- colorRGB[i * 3 + 2] = colorRGBcon[i * 3 + 2] * minMask[i] + colorRGB[i * 3 + 2] * compMask[i];
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- delete[](colorRGBcon);
|
|
|
+ if (edit_contrast != 0)
|
|
|
+ {
|
|
|
+ float contrast = edit_contrast / 100.0f;
|
|
|
+ float maxContrastFactor = 2.0f;
|
|
|
+ float scalingFactor = (1.0f - contrast) + maxContrastFactor * contrast;
|
|
|
+ if (contrast < 0.0f)
|
|
|
+ {
|
|
|
+ contrast = -contrast;
|
|
|
+ scalingFactor = 1.0f / scalingFactor;
|
|
|
+ }
|
|
|
|
|
|
- colorRGB2 = Conversion::non_linear_to_linear(colorRGB, length * 3);
|
|
|
- delete[](colorRGB);
|
|
|
- colorRGB=colorRGB2;
|
|
|
+ float pivot = powf(2, ev) * (lMin + lMax) / 2.0f / 100.0f;
|
|
|
|
|
|
- }
|
|
|
|
|
|
if (colorRGB == NULL)
|
|
|
- colorRGB = Conversion::LCH_to_sRGB(colorLCH, length);
|
|
|
+ colorRGB = Conversion::LCH_to_sRGB(colorLCH, length);
|
|
|
|
|
|
- for (unsigned int i = 0; i < length * 3; i++)
|
|
|
- {
|
|
|
- data[i] = colorRGB[i];
|
|
|
- }
|
|
|
+ float* colorRGB2 = Conversion::linear_to_non_linear(colorRGB, length * 3);
|
|
|
+ delete[](colorRGB);
|
|
|
+ colorRGB = colorRGB2;
|
|
|
+
|
|
|
+
|
|
|
+ float* colorRGBcon = new float[length * 3];
|
|
|
+
|
|
|
+ for (unsigned int i = 0; i < length; i++)
|
|
|
+ {
|
|
|
+ colorRGBcon[i * 3] = (colorRGB[i * 3] - pivot) * scalingFactor + pivot;
|
|
|
+ colorRGBcon[i * 3 + 1] = (colorRGB[i * 3 + 1] - pivot) * scalingFactor + pivot;
|
|
|
+ colorRGBcon[i * 3 + 2] = (colorRGB[i * 3 + 2] - pivot) * scalingFactor + pivot;
|
|
|
+ colorRGB[i * 3] = colorRGBcon[i * 3] * minMask[i] + colorRGB[i * 3] * compMask[i];
|
|
|
+ colorRGB[i * 3 + 1] = colorRGBcon[i * 3 + 1] * minMask[i] + colorRGB[i * 3 + 1] * compMask[i];
|
|
|
+ colorRGB[i * 3 + 2] = colorRGBcon[i * 3 + 2] * minMask[i] + colorRGB[i * 3 + 2] * compMask[i];
|
|
|
+ }
|
|
|
|
|
|
+ delete[](colorRGBcon);
|
|
|
+
|
|
|
+ colorRGB2 = Conversion::non_linear_to_linear(colorRGB, length * 3);
|
|
|
delete[](colorRGB);
|
|
|
- delete[](colorLCH);
|
|
|
- colorspace = Colorspace::RGB;
|
|
|
- linear = true;
|
|
|
+ colorRGB = colorRGB2;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (colorRGB == NULL)
|
|
|
+ colorRGB = Conversion::LCH_to_sRGB(colorLCH, length);
|
|
|
|
|
|
+ for (unsigned int i = 0; i < length * 3; i++)
|
|
|
+ {
|
|
|
+ data[i] = colorRGB[i];
|
|
|
}
|
|
|
+
|
|
|
+ delete[](colorRGB);
|
|
|
+ delete[](colorLCH);
|
|
|
+ colorspace = Colorspace::RGB;
|
|
|
+ linear = true;
|
|
|
+
|
|
|
+ }
|
|
|
else
|
|
|
+ {
|
|
|
+ //TODO - To test for memory leak ?
|
|
|
+ if (colorspace == Colorspace::LCH)
|
|
|
{
|
|
|
- //TODO - To test for memory leak ?
|
|
|
- if (colorspace == Colorspace::LCH)
|
|
|
- {
|
|
|
- float* colorRGB = Conversion::LCH_to_sRGB(data, length);
|
|
|
+ float* colorRGB = Conversion::LCH_to_sRGB(data, length);
|
|
|
|
|
|
- for (unsigned int i = 0; i < length * 3; i++)
|
|
|
- {
|
|
|
- data[i] = colorRGB[i];
|
|
|
- }
|
|
|
+ for (unsigned int i = 0; i < length * 3; i++)
|
|
|
+ {
|
|
|
+ data[i] = colorRGB[i];
|
|
|
+ }
|
|
|
|
|
|
- delete[](colorRGB);
|
|
|
+ delete[](colorRGB);
|
|
|
|
|
|
- colorspace = Colorspace::RGB;
|
|
|
- linear = true;
|
|
|
- }
|
|
|
+ colorspace = Colorspace::RGB;
|
|
|
+ linear = true;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
if (mask)
|
|
|
- {
|
|
|
+ {
|
|
|
|
|
|
- for (unsigned int i = 0; i < length; i++)
|
|
|
- {
|
|
|
- data[i * 3] = minMask[i];
|
|
|
- data[i * 3 + 1] = minMask[i];
|
|
|
- data[i * 3 + 2] = minMask[i];
|
|
|
- }
|
|
|
- colorspace = Colorspace::RGB;
|
|
|
- linear = false;
|
|
|
+ for (unsigned int i = 0; i < length; i++)
|
|
|
+ {
|
|
|
+ data[i * 3] = minMask[i];
|
|
|
+ data[i * 3 + 1] = minMask[i];
|
|
|
+ data[i * 3 + 2] = minMask[i];
|
|
|
}
|
|
|
+ colorspace = Colorspace::RGB;
|
|
|
+ linear = false;
|
|
|
+ }
|
|
|
|
|
|
delete[](minMask);
|
|
|
delete[](compMask);
|
|
@@ -1030,234 +1017,234 @@ void ImageHDR::colorEditor(float* selection_lightness, float* selection_chroma,
|
|
|
|
|
|
// not the default parameter
|
|
|
if (!(selection_lightness[0] == 0.0f && selection_lightness[1] == 100.0f
|
|
|
- && selection_chroma[0] == 0.0f && selection_chroma[1] == 100.0f
|
|
|
- && selection_hue[0] == 0.0f && selection_hue[1] == 360.0f
|
|
|
- && tolerance == 0.1f
|
|
|
- && edit_hue == 0.0f
|
|
|
- && edit_exposure == 0.0f
|
|
|
- && edit_contrast == 0.0f
|
|
|
- && edit_saturation == 0.0f
|
|
|
- && mask == false))
|
|
|
+ && selection_chroma[0] == 0.0f && selection_chroma[1] == 100.0f
|
|
|
+ && selection_hue[0] == 0.0f && selection_hue[1] == 360.0f
|
|
|
+ && tolerance == 0.1f
|
|
|
+ && edit_hue == 0.0f
|
|
|
+ && edit_exposure == 0.0f
|
|
|
+ && edit_contrast == 0.0f
|
|
|
+ && edit_saturation == 0.0f
|
|
|
+ && mask == false))
|
|
|
+ {
|
|
|
+ if (colorspace == Colorspace::RGB)
|
|
|
{
|
|
|
- if (colorspace == Colorspace::RGB)
|
|
|
- {
|
|
|
- if (!linear)
|
|
|
- {
|
|
|
- non_linear_to_linear();
|
|
|
- linear = true;
|
|
|
- }
|
|
|
-
|
|
|
- dataLCH = Conversion::sRGB_to_Lab(data, width * height);
|
|
|
-
|
|
|
- for (unsigned int i = 0; i < width * height; i++)
|
|
|
- {
|
|
|
- float a = dataLCH[i * 3 + 1];
|
|
|
- float b = dataLCH[i * 3 + 2];
|
|
|
- dataLCH[i * 3 + 1] = Conversion::Lab_to_C_of_LCH(a, b);
|
|
|
- dataLCH[i * 3 + 2] = Conversion::Lab_to_H_of_LCH(a, b);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- dataLCH = data;
|
|
|
-
|
|
|
- float* lChannel = new float[width * height];
|
|
|
- float* cChannel = new float[width * height];
|
|
|
- float* hChannel = new float[width * height];
|
|
|
+ if (!linear)
|
|
|
+ {
|
|
|
+ non_linear_to_linear();
|
|
|
+ linear = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ dataLCH = Conversion::sRGB_to_Lab(data, width * height);
|
|
|
+
|
|
|
for (unsigned int i = 0; i < width * height; i++)
|
|
|
- {
|
|
|
- lChannel[i] = dataLCH[i * 3];
|
|
|
- cChannel[i] = dataLCH[i * 3 + 1];
|
|
|
- hChannel[i] = dataLCH[i * 3 + 2];
|
|
|
- }
|
|
|
+ {
|
|
|
+ float a = dataLCH[i * 3 + 1];
|
|
|
+ float b = dataLCH[i * 3 + 2];
|
|
|
+ dataLCH[i * 3 + 1] = Conversion::Lab_to_C_of_LCH(a, b);
|
|
|
+ dataLCH[i * 3 + 2] = Conversion::Lab_to_H_of_LCH(a, b);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ dataLCH = data;
|
|
|
+
|
|
|
+ float* lChannel = new float[width * height];
|
|
|
+ float* cChannel = new float[width * height];
|
|
|
+ float* hChannel = new float[width * height];
|
|
|
+ for (unsigned int i = 0; i < width * height; i++)
|
|
|
+ {
|
|
|
+ lChannel[i] = dataLCH[i * 3];
|
|
|
+ cChannel[i] = dataLCH[i * 3 + 1];
|
|
|
+ hChannel[i] = dataLCH[i * 3 + 2];
|
|
|
+ }
|
|
|
|
|
|
- // Récupération du max du canal L et C
|
|
|
- float lMaxChannel = dataLCH[0];
|
|
|
- float cMaxChannel = dataLCH[1];
|
|
|
- for (unsigned int i = 1; i < width * height; i++)
|
|
|
- {
|
|
|
- if (dataLCH[i * 3] > lMaxChannel)
|
|
|
- lMaxChannel = dataLCH[i * 3];
|
|
|
- if (dataLCH[i * 3 + 1] > cMaxChannel)
|
|
|
- cMaxChannel = dataLCH[i * 3 + 1];
|
|
|
- }
|
|
|
+ // Récupération du max du canal L et C
|
|
|
+ float lMaxChannel = dataLCH[0];
|
|
|
+ float cMaxChannel = dataLCH[1];
|
|
|
+ for (unsigned int i = 1; i < width * height; i++)
|
|
|
+ {
|
|
|
+ if (dataLCH[i * 3] > lMaxChannel)
|
|
|
+ lMaxChannel = dataLCH[i * 3];
|
|
|
+ if (dataLCH[i * 3 + 1] > cMaxChannel)
|
|
|
+ cMaxChannel = dataLCH[i * 3 + 1];
|
|
|
+ }
|
|
|
|
|
|
- if (lMaxChannel < 100.0f)
|
|
|
- lMaxChannel = 100.0f;
|
|
|
- if (cMaxChannel < 100.0f)
|
|
|
- cMaxChannel = 100.0f;
|
|
|
+ if (lMaxChannel < 100.0f)
|
|
|
+ lMaxChannel = 100.0f;
|
|
|
+ if (cMaxChannel < 100.0f)
|
|
|
+ cMaxChannel = 100.0f;
|
|
|
|
|
|
- lMax = lMax * lMaxChannel / 100.0f;
|
|
|
- cMax = cMax * cMaxChannel / 100.0f;
|
|
|
+ lMax = lMax * lMaxChannel / 100.0f;
|
|
|
+ cMax = cMax * cMaxChannel / 100.0f;
|
|
|
|
|
|
- float* lightnessMask = Utils::NPlinearWeightMask(lChannel, width * height, lMin, lMax, lightTolerance);
|
|
|
+ float* lightnessMask = Utils::NPlinearWeightMask(lChannel, width * height, lMin, lMax, lightTolerance);
|
|
|
|
|
|
|
|
|
- float* chromaMask = Utils::NPlinearWeightMask(cChannel, width * height, cMin, cMax, chromaTolerance);
|
|
|
+ float* chromaMask = Utils::NPlinearWeightMask(cChannel, width * height, cMin, cMax, chromaTolerance);
|
|
|
|
|
|
|
|
|
- float* hueMask = Utils::NPlinearWeightMask(hChannel, width * height, hMin, hMax, hueTolerance);
|
|
|
+ float* hueMask = Utils::NPlinearWeightMask(hChannel, width * height, hMin, hMax, hueTolerance);
|
|
|
|
|
|
|
|
|
- minMask = new float[width * height];
|
|
|
- compMask = new float[width * height];
|
|
|
+ minMask = new float[width * height];
|
|
|
+ compMask = new float[width * height];
|
|
|
+ for (unsigned int i = 0; i < width * height; i++)
|
|
|
+ {
|
|
|
+ minMask[i] = lightnessMask[i];
|
|
|
+ if (chromaMask[i] < minMask[i])
|
|
|
+ minMask[i] = chromaMask[i];
|
|
|
+ if (hueMask[i] < minMask[i])
|
|
|
+ minMask[i] = hueMask[i];
|
|
|
+ compMask[i] = 1.0f - minMask[i];
|
|
|
+ }
|
|
|
+
|
|
|
+ delete[](lightnessMask);
|
|
|
+ delete[](chromaMask);
|
|
|
+ delete[](hueMask);
|
|
|
+
|
|
|
+ float hueShift = edit_hue;
|
|
|
+
|
|
|
+ for (unsigned int i = 0; i < width * height; i++) {
|
|
|
+ float oldValue = hChannel[i];
|
|
|
+ hChannel[i] = oldValue + hueShift;
|
|
|
+ while (hChannel[i] < 0.0f)
|
|
|
+ hChannel[i] += 360.0f;
|
|
|
+ while (hChannel[i] >= 360.0f)
|
|
|
+ hChannel[i] -= 360.0f;
|
|
|
+ hChannel[i] = hChannel[i] * minMask[i] + oldValue * compMask[i];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ float saturation = edit_saturation;
|
|
|
+ float gamma = 1.0f / ((saturation / 25.0f) + 1.0f);
|
|
|
+ if (saturation < 0)
|
|
|
+ gamma = (-saturation / 25.0f) + 1.0f;
|
|
|
+
|
|
|
+ for (unsigned int i = 0; i < width * height; i++) {
|
|
|
+ cChannel[i] = powf(cChannel[i] / 100.0f, gamma) * 100 * minMask[i] + cChannel[i] * compMask[i];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ float* colorLCH = new float[width * height * 3];
|
|
|
+ for (unsigned int i = 0; i < width * height; i++)
|
|
|
+ {
|
|
|
+ colorLCH[i * 3] = lChannel[i];
|
|
|
+ colorLCH[i * 3 + 1] = cChannel[i];
|
|
|
+ colorLCH[i * 3 + 2] = hChannel[i];
|
|
|
+ }
|
|
|
+
|
|
|
+ delete[](lChannel);
|
|
|
+ delete[](cChannel);
|
|
|
+ delete[](hChannel);
|
|
|
+
|
|
|
+ float ev = edit_exposure;
|
|
|
+ float* colorRGB = NULL;
|
|
|
+
|
|
|
+ if (ev != 0)
|
|
|
+ {
|
|
|
+ colorRGB = Conversion::LCH_to_sRGB(colorLCH, width * height);
|
|
|
+
|
|
|
+ float* colorRGBev = new float[width * height * 3];
|
|
|
+ float coeff = powf(2, ev);
|
|
|
for (unsigned int i = 0; i < width * height; i++)
|
|
|
- {
|
|
|
- minMask[i] = lightnessMask[i];
|
|
|
- if (chromaMask[i] < minMask[i])
|
|
|
- minMask[i] = chromaMask[i];
|
|
|
- if (hueMask[i] < minMask[i])
|
|
|
- minMask[i] = hueMask[i];
|
|
|
- compMask[i] = 1.0f - minMask[i];
|
|
|
- }
|
|
|
-
|
|
|
- delete[](lightnessMask);
|
|
|
- delete[](chromaMask);
|
|
|
- delete[](hueMask);
|
|
|
-
|
|
|
- float hueShift = edit_hue;
|
|
|
-
|
|
|
- for (unsigned int i = 0; i < width * height; i++) {
|
|
|
- float oldValue = hChannel[i];
|
|
|
- hChannel[i] = oldValue + hueShift;
|
|
|
- while (hChannel[i] < 0.0f)
|
|
|
- hChannel[i] += 360.0f;
|
|
|
- while (hChannel[i] >= 360.0f)
|
|
|
- hChannel[i] -= 360.0f;
|
|
|
- hChannel[i] = hChannel[i] * minMask[i] + oldValue * compMask[i];
|
|
|
+ {
|
|
|
+ colorRGBev[i * 3] = colorRGB[i * 3] * coeff * minMask[i];
|
|
|
+ colorRGBev[i * 3 + 1] = colorRGB[i * 3 + 1] * coeff * minMask[i];
|
|
|
+ colorRGBev[i * 3 + 2] = colorRGB[i * 3 + 2] * coeff * minMask[i];
|
|
|
+
|
|
|
+ colorRGB[i * 3] = colorRGB[i * 3] * compMask[i] + colorRGBev[i * 3];
|
|
|
+ colorRGB[i * 3 + 1] = colorRGB[i * 3 + 1] * compMask[i] + colorRGBev[i * 3 + 1];
|
|
|
+ colorRGB[i * 3 + 2] = colorRGB[i * 3 + 2] * compMask[i] + colorRGBev[i * 3 + 2];
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ delete[](colorRGBev);
|
|
|
|
|
|
- float saturation = edit_saturation;
|
|
|
- float gamma = 1.0f / ((saturation / 25.0f) + 1.0f);
|
|
|
- if (saturation < 0)
|
|
|
- gamma = (-saturation / 25.0f) + 1.0f;
|
|
|
+ }
|
|
|
|
|
|
- for (unsigned int i = 0; i < width * height; i++) {
|
|
|
- cChannel[i] = powf(cChannel[i] / 100.0f, gamma) * 100 * minMask[i] + cChannel[i] * compMask[i];
|
|
|
+ if (edit_contrast != 0)
|
|
|
+ {
|
|
|
+ float contrast = edit_contrast / 100.0f;
|
|
|
+ float maxContrastFactor = 2.0f;
|
|
|
+ float scalingFactor = (1.0f - contrast) + maxContrastFactor * contrast;
|
|
|
+ if (contrast < 0.0f)
|
|
|
+ {
|
|
|
+ contrast = -contrast;
|
|
|
+ scalingFactor = 1.0f / scalingFactor;
|
|
|
}
|
|
|
|
|
|
+ float pivot = powf(2, ev) * (lMin + lMax) / 2.0f / 100.0f;
|
|
|
+
|
|
|
|
|
|
+ if (colorRGB == NULL)
|
|
|
+ colorRGB = Conversion::LCH_to_sRGB(colorLCH, width * height);
|
|
|
|
|
|
- float* colorLCH = new float[width * height * 3];
|
|
|
+ float* colorRGB2 = Conversion::linear_to_non_linear(colorRGB, width * height * 3);
|
|
|
+ delete[](colorRGB);
|
|
|
+ colorRGB = colorRGB2;
|
|
|
+
|
|
|
+
|
|
|
+ float* colorRGBcon = new float[width * height * 3];
|
|
|
for (unsigned int i = 0; i < width * height; i++)
|
|
|
- {
|
|
|
- colorLCH[i * 3] = lChannel[i];
|
|
|
- colorLCH[i * 3 + 1] = cChannel[i];
|
|
|
- colorLCH[i * 3 + 2] = hChannel[i];
|
|
|
- }
|
|
|
-
|
|
|
- delete[](lChannel);
|
|
|
- delete[](cChannel);
|
|
|
- delete[](hChannel);
|
|
|
-
|
|
|
- float ev = edit_exposure;
|
|
|
- float* colorRGB = NULL;
|
|
|
-
|
|
|
- if (ev != 0)
|
|
|
- {
|
|
|
- colorRGB = Conversion::LCH_to_sRGB(colorLCH, width * height);
|
|
|
-
|
|
|
- float* colorRGBev = new float[width * height * 3];
|
|
|
- float coeff = powf(2, ev);
|
|
|
- for (unsigned int i = 0; i < width * height; i++)
|
|
|
- {
|
|
|
- colorRGBev[i * 3] = colorRGB[i * 3] * coeff * minMask[i];
|
|
|
- colorRGBev[i * 3 + 1] = colorRGB[i * 3 + 1] * coeff * minMask[i];
|
|
|
- colorRGBev[i * 3 + 2] = colorRGB[i * 3 + 2] * coeff * minMask[i];
|
|
|
-
|
|
|
- colorRGB[i * 3] = colorRGB[i * 3] * compMask[i] + colorRGBev[i * 3];
|
|
|
- colorRGB[i * 3 + 1] = colorRGB[i * 3 + 1] * compMask[i] + colorRGBev[i * 3 + 1];
|
|
|
- colorRGB[i * 3 + 2] = colorRGB[i * 3 + 2] * compMask[i] + colorRGBev[i * 3 + 2];
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- delete[](colorRGBev);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if (edit_contrast != 0)
|
|
|
- {
|
|
|
- float contrast = edit_contrast / 100.0f;
|
|
|
- float maxContrastFactor = 2.0f;
|
|
|
- float scalingFactor = (1.0f - contrast) + maxContrastFactor * contrast;
|
|
|
- if (contrast < 0.0f)
|
|
|
- {
|
|
|
- contrast = -contrast;
|
|
|
- scalingFactor = 1.0f / scalingFactor;
|
|
|
- }
|
|
|
-
|
|
|
- float pivot = powf(2, ev) * (lMin + lMax) / 2.0f / 100.0f;
|
|
|
-
|
|
|
-
|
|
|
- if (colorRGB == NULL)
|
|
|
- colorRGB = Conversion::LCH_to_sRGB(colorLCH, width * height);
|
|
|
-
|
|
|
- float* colorRGB2 = Conversion::linear_to_non_linear(colorRGB, width * height * 3);
|
|
|
- delete[](colorRGB);
|
|
|
- colorRGB=colorRGB2;
|
|
|
-
|
|
|
-
|
|
|
- float* colorRGBcon = new float[width * height * 3];
|
|
|
- for (unsigned int i = 0; i < width * height; i++)
|
|
|
- {
|
|
|
- colorRGBcon[i * 3] = (colorRGB[i * 3] - pivot) * scalingFactor + pivot;
|
|
|
- colorRGBcon[i * 3 + 1] = (colorRGB[i * 3 + 1] - pivot) * scalingFactor + pivot;
|
|
|
- colorRGBcon[i * 3 + 2] = (colorRGB[i * 3 + 2] - pivot) * scalingFactor + pivot;
|
|
|
- colorRGB[i * 3] = colorRGBcon[i * 3] * minMask[i] + colorRGB[i * 3] * compMask[i];
|
|
|
- colorRGB[i * 3 + 1] = colorRGBcon[i * 3 + 1] * minMask[i] + colorRGB[i * 3 + 1] * compMask[i];
|
|
|
- colorRGB[i * 3 + 2] = colorRGBcon[i * 3 + 2] * minMask[i] + colorRGB[i * 3 + 2] * compMask[i];
|
|
|
- }
|
|
|
-
|
|
|
- delete[](colorRGBcon);
|
|
|
-
|
|
|
- colorRGB2 = Conversion::non_linear_to_linear(colorRGB, width * height * 3);
|
|
|
- delete[](colorRGB);
|
|
|
- colorRGB=colorRGB2;
|
|
|
-
|
|
|
- }
|
|
|
+ {
|
|
|
+ colorRGBcon[i * 3] = (colorRGB[i * 3] - pivot) * scalingFactor + pivot;
|
|
|
+ colorRGBcon[i * 3 + 1] = (colorRGB[i * 3 + 1] - pivot) * scalingFactor + pivot;
|
|
|
+ colorRGBcon[i * 3 + 2] = (colorRGB[i * 3 + 2] - pivot) * scalingFactor + pivot;
|
|
|
+ colorRGB[i * 3] = colorRGBcon[i * 3] * minMask[i] + colorRGB[i * 3] * compMask[i];
|
|
|
+ colorRGB[i * 3 + 1] = colorRGBcon[i * 3 + 1] * minMask[i] + colorRGB[i * 3 + 1] * compMask[i];
|
|
|
+ colorRGB[i * 3 + 2] = colorRGBcon[i * 3 + 2] * minMask[i] + colorRGB[i * 3 + 2] * compMask[i];
|
|
|
+ }
|
|
|
|
|
|
- if (colorRGB == NULL)
|
|
|
- colorRGB = Conversion::LCH_to_sRGB(colorLCH, width * height);
|
|
|
-
|
|
|
- for (unsigned int i = 0; i < width*height * 3; i++)
|
|
|
- {
|
|
|
- data[i] = colorRGB[i];
|
|
|
- }
|
|
|
+ delete[](colorRGBcon);
|
|
|
|
|
|
+ colorRGB2 = Conversion::non_linear_to_linear(colorRGB, width * height * 3);
|
|
|
delete[](colorRGB);
|
|
|
- delete[](colorLCH);
|
|
|
- colorspace = Colorspace::RGB;
|
|
|
- linear = true;
|
|
|
+ colorRGB = colorRGB2;
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ if (colorRGB == NULL)
|
|
|
+ colorRGB = Conversion::LCH_to_sRGB(colorLCH, width * height);
|
|
|
+
|
|
|
+ for (unsigned int i = 0; i < width * height * 3; i++)
|
|
|
+ {
|
|
|
+ data[i] = colorRGB[i];
|
|
|
+ }
|
|
|
+
|
|
|
+ delete[](colorRGB);
|
|
|
+ delete[](colorLCH);
|
|
|
+ colorspace = Colorspace::RGB;
|
|
|
+ linear = true;
|
|
|
+
|
|
|
+ }
|
|
|
else
|
|
|
+ {
|
|
|
+ if (colorspace == Colorspace::LCH)
|
|
|
{
|
|
|
- if (colorspace == Colorspace::LCH)
|
|
|
- {
|
|
|
- float* colorRGB = Conversion::LCH_to_sRGB(data, width * height);
|
|
|
-
|
|
|
- for (unsigned int i = 0; i < width*height * 3; i++)
|
|
|
- {
|
|
|
- data[i] = colorRGB[i];
|
|
|
- }
|
|
|
-
|
|
|
- delete[](colorRGB);
|
|
|
- colorspace = Colorspace::RGB;
|
|
|
- linear = true;
|
|
|
- }
|
|
|
+ float* colorRGB = Conversion::LCH_to_sRGB(data, width * height);
|
|
|
+
|
|
|
+ for (unsigned int i = 0; i < width * height * 3; i++)
|
|
|
+ {
|
|
|
+ data[i] = colorRGB[i];
|
|
|
+ }
|
|
|
+
|
|
|
+ delete[](colorRGB);
|
|
|
+ colorspace = Colorspace::RGB;
|
|
|
+ linear = true;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
if (mask)
|
|
|
+ {
|
|
|
+ for (unsigned int i = 0; i < width * height; i++)
|
|
|
{
|
|
|
- for (unsigned int i = 0; i < width * height; i++)
|
|
|
- {
|
|
|
- data[i * 3] = minMask[i];
|
|
|
- data[i * 3 + 1] = minMask[i];
|
|
|
- data[i * 3 + 2] = minMask[i];
|
|
|
- }
|
|
|
- colorspace = Colorspace::RGB;
|
|
|
- linear = false;
|
|
|
+ data[i * 3] = minMask[i];
|
|
|
+ data[i * 3 + 1] = minMask[i];
|
|
|
+ data[i * 3 + 2] = minMask[i];
|
|
|
}
|
|
|
+ colorspace = Colorspace::RGB;
|
|
|
+ linear = false;
|
|
|
+ }
|
|
|
|
|
|
delete[](minMask);
|
|
|
delete[](compMask);
|