added and debugged first filter function

This commit is contained in:
2020-02-26 00:14:47 +01:00
parent 8975639b73
commit 7c378f1f7e
4 changed files with 130 additions and 12 deletions

View File

@@ -10,6 +10,8 @@
int fimg_lissage_2x2(FloatImg *img)
{
int x, y, offset;
float cr, cg, cb;
float *pr, *pg, *pb;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p )\n", __func__, img);
@@ -17,15 +19,77 @@ fprintf(stderr," type %d size %dx%d\n", img->type,
img->width, img->height);
#endif
for (y=1; y<img->height; y++) {
pr = img->R; pg = img->G; pb = img->B;
for (x=1; x<img->width; x++) {
for (y=1; y < img->height-1; y++) {
for (x=1; x < img->width-1; x++) {
offset = x + (y * img->width);
cr = pr[offset] + pr[offset+1] +
pr[offset+img->width] + pr[offset+img->width+1];
cg = pg[offset] + pg[offset+1] +
pg[offset+img->width] + pg[offset+img->width+1];
cb = pb[offset] + pb[offset+1] +
pb[offset+img->width] + pb[offset+img->width+1];
pr[offset] = cr / 4.0;
pg[offset] = cg / 4.0;
pb[offset] = cb / 4.0;
}
}
return 0;
}
/* -------------------------------------------------------------------- */
int fimg_killborders(FloatImg *img)
{
int idx, h, w, o;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p )\n", __func__, img);
fprintf(stderr," type %d size %dx%d\n", img->type,
img->width, img->height);
#endif
h = img->height; w = img->width;
for (idx=0; idx<h; idx++) {
#define FAST 1
#if FAST
img->R[idx*w] = 0.0;
img->G[idx*w] = 0.0;
img->B[idx*w] = 0.0;
img->R[(idx*w)+w-1] = 0.0;
img->G[(idx*w)+w-1] = 0.0;
img->B[(idx*w)+w-1] = 0.0;
#else
fimg_plot_rgb(img, 0, idx, 0.0, 0.0, 0.0);
fimg_plot_rgb(img, w-1, idx, 0.0, 0.0, 0.0);
#endif
}
o = w * (h - 1);
for (idx=0; idx<w; idx++) {
#if FAST
img->R[idx] = 0.0;
img->G[idx] = 0.0;
img->B[idx] = 0.0;
img->R[idx+o] = 0.0;
img->G[idx+o] = 0.0;
img->B[idx+o] = 0.0;
#else
fimg_plot_rgb(img, idx, 0, 0.0, 0.0, 0.0);
fimg_plot_rgb(img, idx, h-1, 0.0, 0.0, 0.0);
#endif
}
return -1;
}
/* -------------------------------------------------------------------- */

View File

@@ -12,6 +12,40 @@ int verbosity;
float global_fvalue;
/* --------------------------------------------------------------------- */
int essai_filtrage(char *infile)
{
FloatImg fimg;
int foo, idx;
char buffer[100];
if (NULL != infile) {
fprintf(stderr, "loading %s\n", infile);
foo = fimg_create_from_dump(infile, &fimg);
if (foo) {
fprintf(stderr, "%s: err load '%s'\n", __func__, infile);
return foo;
}
}
else {
fprintf(stderr, "%s is creating the picz\n", __func__);
fimg_create(&fimg, 512, 512, FIMG_TYPE_RGB);
fimg_draw_something(&fimg);
}
foo = fimg_save_as_pnm(&fimg, "source.pnm", 0);
for (idx=0; idx<20; idx++) {
foo = fimg_lissage_2x2(&fimg);
foo = fimg_killborders(&fimg);
sprintf(buffer, "filter%03d.pnm", idx);
foo = fimg_save_as_pnm(&fimg, buffer, 0);
}
fimg_destroy(&fimg);
return 0;
}
/* --------------------------------------------------------------------- */
int essai_geometrie(char *infile)
{
@@ -173,6 +207,7 @@ return 0;
int main(int argc, char *argv[])
{
int foo, opt;
char *filename;
puts("++++++++++++++++++++++++++++++++");
@@ -186,9 +221,14 @@ while ((opt = getopt(argc, argv, "hk:v")) != -1) {
}
}
foo = essai_geometrie("foo.fimg");
fprintf(stderr, "argc %d optind %d\n", argc, optind);
filename = NULL;
if (1 == argc-optind) filename = argv[optind];
foo = essai_filtrage(filename);
if (foo) {
fprintf(stderr, "************ %d\n", foo);
fprintf(stderr, "====> %d\n", foo);
}
return 0;