adding a "2 gray" function

This commit is contained in:
Tonton Th 2019-08-24 13:06:51 +02:00
parent 8f65f414dc
commit d1e9999e1c
3 changed files with 72 additions and 0 deletions

View File

@ -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);

56
lib/fimg-2gray.c Normal file
View File

@ -0,0 +1,56 @@
/*
* fimg-2gray.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#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; foo<nbb; foo++) {
dst->R[foo] = ( (src->R[foo] * kr) +
(src->G[foo] * kg) +
(src->B[foo] * kb) ) /
kdiv;
}
return -1;
}
/* --------------------------------------------------------------------- */

14
lib/t.c
View File

@ -30,6 +30,16 @@ for (y=0; y<img->height; 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);