Browse Source

vibrancy correctly implemented

master
Joshua Moerman 13 years ago
parent
commit
3b1135274b
  1. 24
      canvae/PNG.hpp

24
canvae/PNG.hpp

@ -107,14 +107,6 @@ public:
}
const double vibrancy = v;
double averagePower = 0;
for(unsigned int i = 0; i < num_colors; i++) {
averagePower += power[i];
}
averagePower /= (double)num_colors;
for(unsigned int i = 0; i < num_colors; i++) {
power[i] = vibrancy*power[i] + (1.0 - vibrancy)*averagePower;
}
// TODO: find a way to set these things:
// pngFile->setcompressionlevel(9);
@ -137,16 +129,24 @@ public:
double r = 0.0;
double g = 0.0;
double b = 0.0;
double average_norm_value = 0.0;
for(unsigned int c = 0; c < num_colors; ++c){
average_norm_value += (double)int_array[x + y*width + c*width*height]/max_int[c];
}
average_norm_value /= (double) num_colors;
for(unsigned int c = 0; c < num_colors; c++) {
const double norm_value = (double)int_array[x + y*width + c*width*height]/max_int[c];
double norm_value = (double)int_array[x + y*width + c*width*height]/max_int[c];
norm_value = vibrancy*norm_value + (1.0 - vibrancy) * average_norm_value;
norm_value = std::max(0.0, norm_value);
r += (std::pow(norm_value, power[c]*power_matrix[c+0]))*output_matrix[c+0];
g += (std::pow(norm_value, power[c]*power_matrix[c+2]))*output_matrix[c+2];
b += (std::pow(norm_value, power[c]*power_matrix[c+4]))*output_matrix[c+4];
}
// TODO: also clamp is below 0 ?
r = std::min(1.0, r);
b = std::min(1.0, b);
g = std::min(1.0, g);
r = std::max(0.0, std::min(1.0, r));
b = std::max(0.0, std::min(1.0, b));
g = std::max(0.0, std::min(1.0, g));
image[y][x] = png::rgb_pixel(r*255, g*255, b*255);
}
}