Compare commits

...

2 Commits

Author SHA1 Message Date
cef00ac04e added normalize function, need more tests 2020-01-07 13:46:09 +01:00
6d13293ef2 cosmetic change 2020-01-07 13:45:18 +01:00
4 changed files with 77 additions and 17 deletions

View File

@ -2,7 +2,7 @@
* floatimg.h
*/
#define FIMG_VERSION 85
#define FIMG_VERSION 86
/*
* in memory descriptor
@ -107,6 +107,7 @@ int fimg_meanvalues(FloatImg *head, float means[4]);
int fimg_to_gray(FloatImg *head);
void fimg_add_cste(FloatImg *fi, float value);
void fimg_mul_cste(FloatImg *fi, float value);
int fimg_normalize(FloatImg *fi, double maxima, int notused);
void fimg_drand48(FloatImg *fi, float kmul);
int fimg_count_negativ(FloatImg *fi);

View File

@ -158,14 +158,43 @@ if (fi->type != FIMG_TYPE_RGB) {
}
nbre = fi->width * fi->height * fi->type;
// #if DEBUG_LEVEL
fprintf(stderr, "%s, nbre is %d\n", __func__, nbre);
// #endif
#if DEBUG_LEVEL
fprintf(stderr, "%s, nbre of datum is %d\n", __func__, nbre);
#endif
for (idx=0; idx<nbre; idx++) {
fi->R[idx] *= value;
}
}
/* ---------------------------------------------------------------- */
int fimg_normalize(FloatImg *fi, double maxima, int notused)
{
double coef;
if (fi->type != FIMG_TYPE_RGB) {
fprintf(stderr, "%s : type %d invalide\n",
__func__, fi->type);
return -99;
}
if (fi->count < 1) {
fprintf(stderr, "%s : count %d is invalid\n", __func__, fi->count);
return -98;
}
coef = 1.0 / ((double)fi->count * (double)fi->fval);
if (verbosity) {
fprintf(stderr, "image @ %p\n", fi);
fprintf(stderr, "fval %f\n", fi->fval);
fprintf(stderr, "count %d\n", fi->count);
fprintf(stderr, "coef %f\n", coef);
}
fimg_mul_cste(fi, coef);
return 0;
}
/* ---------------------------------------------------------------- */
/* Warning: this function is _very_ slow */
void fimg_drand48(FloatImg *fi, float kmul)
{

View File

@ -21,7 +21,7 @@ extern int verbosity; /* must be declared around main() */
*/
int fimg_add(FloatImg *a, FloatImg *b, FloatImg *d)
{
int idx, nbiter;
int idx, nbpixels;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, a, b, d);
@ -32,9 +32,9 @@ if (3 != a->type || 3 != b->type || 3 != d->type) {
return -8;
}
nbiter = a->width * a->height;
nbpixels = a->width * a->height;
for (idx=0; idx<nbiter; idx++) {
for (idx=0; idx<nbpixels; idx++) {
d->R[idx] = a->R[idx] + b->R[idx];
d->G[idx] = a->G[idx] + b->G[idx];
d->B[idx] = a->B[idx] + b->B[idx];
@ -48,7 +48,7 @@ return 0;
*/
int fimg_sub(FloatImg *a, FloatImg *b, FloatImg *d)
{
int idx, nbiter;
int idx, nbpixels;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, a, b, d);
@ -59,12 +59,12 @@ if (3 != a->type || 3 != b->type || 3 != d->type) {
return -8;
}
nbiter = a->width * a->height;
nbpixels = a->width * a->height;
/* maybe we can speedup this loop for
* avoiding the cache strashing ?
*/
for (idx=0; idx<nbiter; idx++) {
for (idx=0; idx<nbpixels; idx++) {
d->R[idx] = fabs(a->R[idx] - b->R[idx]);
d->G[idx] = fabs(a->G[idx] - b->G[idx]);
d->B[idx] = fabs(a->B[idx] - b->B[idx]);
@ -78,7 +78,7 @@ return 0;
*/
int fimg_mul(FloatImg *a, FloatImg *b, FloatImg *d)
{
int idx, nbiter;
int idx, nbpixels;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, a, b, d);
@ -89,9 +89,9 @@ if (3 != a->type || 3 != b->type || 3 != d->type) {
return -8;
}
nbiter = a->width * a->height;
nbpixels = a->width * a->height;
for (idx=0; idx<nbiter; idx++) {
for (idx=0; idx<nbpixels; idx++) {
d->R[idx] = a->R[idx] * b->R[idx];
d->G[idx] = a->G[idx] * b->G[idx];
d->B[idx] = a->B[idx] * b->B[idx];

36
lib/t.c
View File

@ -13,6 +13,36 @@
int verbosity;
/* ---------------------------------------------------------------- */
int essai_normalize(void)
{
FloatImg A;
float val;
int foo;
foo = fimg_create(&A, 512, 512, FIMG_TYPE_RGB);
if (foo) {
fprintf(stderr, "%s err create A %d\n", __func__, foo);
return foo;
}
fimg_drand48(&A, 255.0);
val = fimg_get_maxvalue(&A);
fprintf(stderr, "BEFORE max pixel %f\n", val);
A.fval = 255.0; A.count = 1;
foo = fimg_normalize(&A, 1.0, 0);
if (foo) {
fprintf(stderr, "%s err normalize A %d\n", __func__, foo);
return foo;
}
val = fimg_get_maxvalue(&A);
fprintf(stderr, "AFTER max pixel %f\n", val);
return 0;
}
/* ---------------------------------------------------------------- */
int essai_2gray(FloatImg *picz, char *outname)
@ -126,7 +156,7 @@ return -1;
#define H 240
int main(int argc, char *argv[])
{
int foo, idx, opt;
int foo, opt;
// char outname[100];
int gray = 0;
@ -140,8 +170,8 @@ while ((opt = getopt(argc, argv, "gn:v")) != -1) {
if (verbosity) fimg_print_version(0);
foo = essai_clone_et_copy(0);
fprintf(stderr, "retour essai clone_et_copy -> %d\n", foo);
foo = essai_normalize();
fprintf(stderr, "retour essai normalize -> %d\n", foo);
return 0;
}