Compare commits

..

No commits in common. "cef00ac04e70cff90ab4d2cbe55c63778d121ff0" and "6dbfa418906d385fd9d977181e23589901f8d648" have entirely different histories.

4 changed files with 17 additions and 77 deletions

View File

@ -2,7 +2,7 @@
* floatimg.h * floatimg.h
*/ */
#define FIMG_VERSION 86 #define FIMG_VERSION 85
/* /*
* in memory descriptor * in memory descriptor
@ -51,7 +51,7 @@ typedef struct {
int fimg_create(FloatImg *fimg, int w, int h, int t); int fimg_create(FloatImg *fimg, int w, int h, int t);
int fimg_destroy(FloatImg *fimg); int fimg_destroy(FloatImg *fimg);
int fimg_clone(FloatImg *fimg, FloatImg *newpic, int flags); int fimg_clone(FloatImg *fimg, FloatImg *newpic, int flags);
int fimg_copy_data(FloatImg *from, FloatImg *to); int fimg_copy_data(FloatImg *from, FloatImg *to);
int fimg_print_version(int k); int fimg_print_version(int k);
void fimg_printhead(FloatImg *h); void fimg_printhead(FloatImg *h);
@ -107,7 +107,6 @@ int fimg_meanvalues(FloatImg *head, float means[4]);
int fimg_to_gray(FloatImg *head); int fimg_to_gray(FloatImg *head);
void fimg_add_cste(FloatImg *fi, float value); void fimg_add_cste(FloatImg *fi, float value);
void fimg_mul_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); void fimg_drand48(FloatImg *fi, float kmul);
int fimg_count_negativ(FloatImg *fi); int fimg_count_negativ(FloatImg *fi);

View File

@ -158,43 +158,14 @@ if (fi->type != FIMG_TYPE_RGB) {
} }
nbre = fi->width * fi->height * fi->type; nbre = fi->width * fi->height * fi->type;
#if DEBUG_LEVEL // #if DEBUG_LEVEL
fprintf(stderr, "%s, nbre of datum is %d\n", __func__, nbre); fprintf(stderr, "%s, nbre is %d\n", __func__, nbre);
#endif // #endif
for (idx=0; idx<nbre; idx++) { for (idx=0; idx<nbre; idx++) {
fi->R[idx] *= value; 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 */ /* Warning: this function is _very_ slow */
void fimg_drand48(FloatImg *fi, float kmul) 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 fimg_add(FloatImg *a, FloatImg *b, FloatImg *d)
{ {
int idx, nbpixels; int idx, nbiter;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, a, b, d); 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; return -8;
} }
nbpixels = a->width * a->height; nbiter = a->width * a->height;
for (idx=0; idx<nbpixels; idx++) { for (idx=0; idx<nbiter; idx++) {
d->R[idx] = a->R[idx] + b->R[idx]; d->R[idx] = a->R[idx] + b->R[idx];
d->G[idx] = a->G[idx] + b->G[idx]; d->G[idx] = a->G[idx] + b->G[idx];
d->B[idx] = a->B[idx] + b->B[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 fimg_sub(FloatImg *a, FloatImg *b, FloatImg *d)
{ {
int idx, nbpixels; int idx, nbiter;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, a, b, d); 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; return -8;
} }
nbpixels = a->width * a->height; nbiter = a->width * a->height;
/* maybe we can speedup this loop for /* maybe we can speedup this loop for
* avoiding the cache strashing ? * avoiding the cache strashing ?
*/ */
for (idx=0; idx<nbpixels; idx++) { for (idx=0; idx<nbiter; idx++) {
d->R[idx] = fabs(a->R[idx] - b->R[idx]); d->R[idx] = fabs(a->R[idx] - b->R[idx]);
d->G[idx] = fabs(a->G[idx] - b->G[idx]); d->G[idx] = fabs(a->G[idx] - b->G[idx]);
d->B[idx] = fabs(a->B[idx] - b->B[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 fimg_mul(FloatImg *a, FloatImg *b, FloatImg *d)
{ {
int idx, nbpixels; int idx, nbiter;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, a, b, d); 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; return -8;
} }
nbpixels = a->width * a->height; nbiter = a->width * a->height;
for (idx=0; idx<nbpixels; idx++) { for (idx=0; idx<nbiter; idx++) {
d->R[idx] = a->R[idx] * b->R[idx]; d->R[idx] = a->R[idx] * b->R[idx];
d->G[idx] = a->G[idx] * b->G[idx]; d->G[idx] = a->G[idx] * b->G[idx];
d->B[idx] = a->B[idx] * b->B[idx]; d->B[idx] = a->B[idx] * b->B[idx];

36
lib/t.c
View File

@ -13,36 +13,6 @@
int verbosity; 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) int essai_2gray(FloatImg *picz, char *outname)
@ -156,7 +126,7 @@ return -1;
#define H 240 #define H 240
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int foo, opt; int foo, idx, opt;
// char outname[100]; // char outname[100];
int gray = 0; int gray = 0;
@ -170,8 +140,8 @@ while ((opt = getopt(argc, argv, "gn:v")) != -1) {
if (verbosity) fimg_print_version(0); if (verbosity) fimg_print_version(0);
foo = essai_normalize(); foo = essai_clone_et_copy(0);
fprintf(stderr, "retour essai normalize -> %d\n", foo); fprintf(stderr, "retour essai clone_et_copy -> %d\n", foo);
return 0; return 0;
} }