|
|
608c44 |
|
|
|
608c44 |
|
|
|
608c44 |
void filterNoise(Img *img) {
|
|
|
608c44 |
if (!img->data) return;
|
|
|
608c44 |
for(double *p = img->data, *e = p + 4*img->w*img->h; p < e; p += 4) {
|
|
|
608c44 |
p[0] = randomFloat();
|
|
|
608c44 |
p[1] = randomFloat();
|
|
|
608c44 |
p[2] = randomFloat();
|
|
|
608c44 |
p[3] = randomFloat();
|
|
|
608c44 |
}
|
|
|
608c44 |
}
|
|
|
608c44 |
|
|
|
608c44 |
|
|
|
608c44 |
void filterMulNoise(Img *img, int w, int h, double vmin, double vmax) {
|
|
|
608c44 |
if (!img->data || w <= 0 || h <= 0) return;
|
|
|
608c44 |
Img imgC = {};
|
|
|
608c44 |
imgInit(&imgC, w, h);
|
|
|
608c44 |
filterNoise(&imgC);
|
|
|
608c44 |
for(int y = 0; y < img->h; ++y) {
|
|
|
608c44 |
for(int x = 0; x < img->w; ++x) {
|
|
|
608c44 |
double pn[4];
|
|
|
608c44 |
imgCubic(&imgC, (double)x/img->w*w, (double)y/img->h*h, pn);
|
|
|
608c44 |
double *p = imgPixel(img, x, y);
|
|
|
608c44 |
p[0] *= vmin + (vmax - vmin)*pn[0];
|
|
|
608c44 |
p[1] *= vmin + (vmax - vmin)*pn[1];
|
|
|
608c44 |
p[2] *= vmin + (vmax - vmin)*pn[2];
|
|
|
608c44 |
p[3] *= vmin + (vmax - vmin)*pn[3];
|
|
|
608c44 |
}
|
|
|
608c44 |
}
|
|
|
608c44 |
imgDestroy(&imgC);
|
|
|
608c44 |
}
|
|
|
608c44 |
|
|
|
608c44 |
|
|
|
608c44 |
void filterMulNoiseGray(Img *img, int w, int h, double vmin, double vmax) {
|
|
|
608c44 |
if (!img->data || w <= 0 || h <= 0) return;
|
|
|
608c44 |
Img imgC = {};
|
|
|
608c44 |
imgInit(&imgC, w, h);
|
|
|
608c44 |
filterNoise(&imgC);
|
|
|
608c44 |
for(int y = 0; y < img->h; ++y) {
|
|
|
608c44 |
for(int x = 0; x < img->w; ++x) {
|
|
|
608c44 |
double pn = vmin + (vmax - vmin)*imgCubicCh(&imgC, 0, (double)x/img->w*w, (double)y/img->h*h);
|
|
|
608c44 |
double *p = imgPixel(img, x, y);
|
|
|
608c44 |
p[0] *= pn;
|
|
|
608c44 |
p[1] *= pn;
|
|
|
608c44 |
p[2] *= pn;
|
|
|
608c44 |
//p[3] *= pn;
|
|
|
608c44 |
}
|
|
|
608c44 |
}
|
|
|
608c44 |
imgDestroy(&imgC);
|
|
|
608c44 |
}
|
|
|
608c44 |
|
|
|
608c44 |
|