Bibliothèque de traitements d'images en virgule flottante.
http://la.buvette.org/photos/cumul/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.1 KiB
55 lines
1.1 KiB
/* |
|
* 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 imgs MUST be allocated before calling this func. |
|
*/ |
|
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 0; |
|
} |
|
/* --------------------------------------------------------------------- */ |
|
|
|
|
|
|
|
|
|
|