Avoid overflow on large images
This commit is contained in:
parent
b5c2318646
commit
048652e215
@ -58,9 +58,13 @@ int main(int argc, char **argv)
|
||||
app.add_option("-o,--output", outputImage, "Output image")->required();
|
||||
unsigned int nbSteps = 3;
|
||||
app.add_option("-n,--nbsteps", nbSteps, "Number of sliced steps (3)");
|
||||
float ratio = 1.0;
|
||||
app.add_option("-r,--ratio", ratio, "Ratio of base/objective color (1.0)");
|
||||
silent = false;
|
||||
app.add_flag("--silent", silent, "No verbose messages");
|
||||
CLI11_PARSE(app, argc, argv);
|
||||
|
||||
assert(ratio <= 1 && ratio >= 0);
|
||||
|
||||
//Image loading
|
||||
int width,height, nbChannels;
|
||||
@ -98,15 +102,15 @@ int main(int argc, char **argv)
|
||||
unsigned int distrib_b[255];
|
||||
|
||||
int total_px = width*height;
|
||||
int cur_cum_r, cur_cum_g, cur_cum_b;
|
||||
float cur_cum_r, cur_cum_g, cur_cum_b;
|
||||
cur_cum_r, cur_cum_g, cur_cum_b = 0;
|
||||
for (auto i=0; i < 255; i++) {
|
||||
cur_cum_r += cum_r[i];
|
||||
cur_cum_g += cum_g[i];
|
||||
cur_cum_b += cum_b[i];
|
||||
distrib_r[i] = 255*cur_cum_r/total_px;
|
||||
distrib_g[i] = 255*cur_cum_g/total_px;
|
||||
distrib_b[i] = 255*cur_cum_b/total_px;
|
||||
cur_cum_r += cum_r[i]/(float)total_px;
|
||||
cur_cum_g += cum_g[i]/(float)total_px;
|
||||
cur_cum_b += cum_b[i]/(float)total_px;
|
||||
distrib_r[i] = 255*cur_cum_r;
|
||||
distrib_g[i] = 255*cur_cum_g;
|
||||
distrib_b[i] = 255*cur_cum_b;
|
||||
}
|
||||
|
||||
for(auto i = 0 ; i < width ; ++i)
|
||||
@ -118,9 +122,9 @@ int main(int argc, char **argv)
|
||||
unsigned char g = source[ indexPixel + 1];
|
||||
unsigned char b = source[ indexPixel + 2];
|
||||
//Swapping the channels
|
||||
output[ indexPixel ] = distrib_r[r];
|
||||
output[ indexPixel + 1 ] = distrib_g[g];
|
||||
output[ indexPixel + 2 ] = distrib_b[b];
|
||||
output[ indexPixel ] = ratio*distrib_r[r]+(1-ratio)*r;
|
||||
output[ indexPixel + 1 ] = ratio*distrib_g[g]+(1-ratio)*g;
|
||||
output[ indexPixel + 2 ] = ratio*distrib_b[b]+(1-ratio)*b;
|
||||
if (nbChannels == 4) //just copying the alpha value if any
|
||||
output[ indexPixel + 3] = source[ indexPixel + 3];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user