diff --git a/floatimg.h b/floatimg.h index 49da061..af4fb35 100644 --- a/floatimg.h +++ b/floatimg.h @@ -59,6 +59,8 @@ double fimg_timer_set(int whot); double fimg_timer_get(int whot); +int fimg_mk_gray_from(FloatImg *src, FloatImg*dst, int k); + /* FIMG files module */ int fimg_fileinfos(char *fname, int *datas); int fimg_dump_to_file(FloatImg *head, char *fname, int notused); diff --git a/lib/fimg-2gray.c b/lib/fimg-2gray.c new file mode 100644 index 0000000..49414cf --- /dev/null +++ b/lib/fimg-2gray.c @@ -0,0 +1,56 @@ +/* + * fimg-2gray.c + */ + +#include +#include +#include +#include "string.h" + +#include "../floatimg.h" + +extern int verbosity; /* must be declared around main() */ + +/* --------------------------------------------------------------------- */ +/* + * floating img MUST be allocated. + */ +int fimg_mk_gray_from(FloatImg *src, FloatImg*dst, int k) +{ +float kr, kg, kb, kdiv; +int nbb, foo; + +kr = kg = kb = 1.0; /* canonic random values */ +kdiv = kr + kg + kb; + +/* we must check the validity of our parameters */ +if (FIMG_TYPE_RGB != src->type) { + fprintf(stderr, "%s : bad src type %d on %p\n", __func__, + src->type, src); + return -8; + } + +if (FIMG_TYPE_GRAY != dst->type) { + fprintf(stderr, "%s : bad dst type %d on %p\n", __func__, + dst->type, dst); + return -9; + } + +/* entering the main processing loop */ +nbb = src->width * src->height; + +for (foo=0; fooR[foo] = ( (src->R[foo] * kr) + + (src->G[foo] * kg) + + (src->B[foo] * kb) ) / + kdiv; + } + +return -1; +} +/* --------------------------------------------------------------------- */ + + + + diff --git a/lib/t.c b/lib/t.c index a1d5544..b2f2013 100644 --- a/lib/t.c +++ b/lib/t.c @@ -30,6 +30,16 @@ for (y=0; yheight; y++) { } return -1; +} +/* ---------------------------------------------------------------- */ + +int essai_2gray(FloatImg *picz, char *outname) +{ + + + +return -1; + } /* ---------------------------------------------------------------- */ #define W 4000 @@ -56,6 +66,10 @@ foo = fimg_create(&result, W, H, 3); foo = fimg_add(&dessin, &noise, &result); fimg_save_as_pnm(&result, "r_add.pnm", 0); + +essai_2gray(&result, "gray.pnm"); + + foo = fimg_sub(&dessin, &noise, &result); fimg_save_as_pnm(&result, "r_sub.pnm", 0); foo = fimg_mul(&dessin, &noise, &result);