oops overflow
This commit is contained in:
parent
048652e215
commit
7e6e491907
@ -37,6 +37,7 @@
|
|||||||
#include <stb_image.h>
|
#include <stb_image.h>
|
||||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
#include <stb_image_write.h>
|
#include <stb_image_write.h>
|
||||||
|
#define DEBUG (0)
|
||||||
|
|
||||||
unsigned char min(unsigned char a, unsigned char b) {
|
unsigned char min(unsigned char a, unsigned char b) {
|
||||||
return a < b ? a : b;
|
return a < b ? a : b;
|
||||||
@ -81,10 +82,10 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
//As an example, we just scan the pixels of the source image
|
//As an example, we just scan the pixels of the source image
|
||||||
//and swap the color channels.
|
//and swap the color channels.
|
||||||
unsigned int cum_r[255];
|
unsigned int cum_r[256];
|
||||||
unsigned int cum_g[255];
|
unsigned int cum_g[256];
|
||||||
unsigned int cum_b[255];
|
unsigned int cum_b[256];
|
||||||
for (auto i=0; i < 255; i++) {
|
for (auto i=0; i < 256; i++) {
|
||||||
cum_r[i] = cum_g[i] = cum_b[i] = 0;
|
cum_r[i] = cum_g[i] = cum_b[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,20 +98,61 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int distrib_r[255];
|
if DEBUG {
|
||||||
unsigned int distrib_g[255];
|
bool seenB, seenR, seenG;
|
||||||
unsigned int distrib_b[255];
|
seenB = seenR = seenG = false;
|
||||||
|
int i=256;
|
||||||
|
while (i>0 && (!seenR || !seenG || !seenB)) {
|
||||||
|
if (!seenR && cum_r[i] != 0) {
|
||||||
|
printf("maxR: %d\n", i);
|
||||||
|
seenR=true;
|
||||||
|
}
|
||||||
|
if (!seenG && cum_g[i] != 0) {
|
||||||
|
printf("maxG: %d\n", i);
|
||||||
|
seenG=true;
|
||||||
|
}
|
||||||
|
if (!seenB && cum_b[i] != 0) {
|
||||||
|
printf("maxB: %d\n", i);
|
||||||
|
seenB=true;
|
||||||
|
}
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
|
||||||
|
seenB = seenR = seenG = false;
|
||||||
|
i=0;
|
||||||
|
while (i<=256 && (!seenR || !seenG || !seenB)) {
|
||||||
|
if (!seenR && cum_r[i] != 0) {
|
||||||
|
printf("minR: %d\n", i);
|
||||||
|
seenR=true;
|
||||||
|
}
|
||||||
|
if (!seenG && cum_g[i] != 0) {
|
||||||
|
printf("minG: %d\n", i);
|
||||||
|
seenG=true;
|
||||||
|
}
|
||||||
|
if (!seenB && cum_b[i] != 0) {
|
||||||
|
printf("minB: %d\n", i);
|
||||||
|
seenB=true;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int distrib_r[256];
|
||||||
|
unsigned int distrib_g[256];
|
||||||
|
unsigned int distrib_b[256];
|
||||||
|
|
||||||
int total_px = width*height;
|
int total_px = width*height;
|
||||||
float 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;
|
cur_cum_r, cur_cum_g, cur_cum_b = 0;
|
||||||
for (auto i=0; i < 255; i++) {
|
if DEBUG printf("Distrib: R G B\n");
|
||||||
|
for (auto i=0; i < 256; i++) {
|
||||||
cur_cum_r += cum_r[i]/(float)total_px;
|
cur_cum_r += cum_r[i]/(float)total_px;
|
||||||
cur_cum_g += cum_g[i]/(float)total_px;
|
cur_cum_g += cum_g[i]/(float)total_px;
|
||||||
cur_cum_b += cum_b[i]/(float)total_px;
|
cur_cum_b += cum_b[i]/(float)total_px;
|
||||||
distrib_r[i] = 255*cur_cum_r;
|
distrib_r[i] = 255*cur_cum_r;
|
||||||
distrib_g[i] = 255*cur_cum_g;
|
distrib_g[i] = 255*cur_cum_g;
|
||||||
distrib_b[i] = 255*cur_cum_b;
|
distrib_b[i] = 255*cur_cum_b;
|
||||||
|
if DEBUG printf("%d\t%3d %3d %3d\n", i,distrib_r[i], distrib_g[i], distrib_b[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto i = 0 ; i < width ; ++i)
|
for(auto i = 0 ; i < width ; ++i)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user