Browse Source

1) renommer quelques fonctions dans lib/operators.c

2) ajouter une fonction d'additin d'images (maybe ?) plus rapide
3) reparation d'un bug dans tools/fimgops.c
tth 6 months ago
parent
commit
d624a45fc4
4 changed files with 41 additions and 13 deletions
  1. 1
    1
      essai.c
  2. 5
    4
      floatimg.h
  3. 32
    5
      lib/operators.c
  4. 3
    3
      tools/fimgops.c

+ 1
- 1
essai.c View File

@@ -62,7 +62,7 @@ for (foo=0; foo<NBP; foo++) {
62 62
 		printf("%5d / %5d\n", foo, NBP);
63 63
 		}
64 64
 	fait_un_dessin(&fimgB);
65
-	fimg_add(&fimgA, &fimgB, &fimgA);
65
+	fimg_add_3(&fimgA, &fimgB, &fimgA);
66 66
 	// fimg_mul(&fimgA, &fimgB, &fimgA);
67 67
 	}
68 68
 tb = fimg_timer_get(0);

+ 5
- 4
floatimg.h View File

@@ -2,7 +2,7 @@
2 2
  *	floatimg.h
3 3
  */
4 4
 
5
-#define		FIMG_VERSION	86
5
+#define		FIMG_VERSION	87
6 6
 
7 7
 /*
8 8
  *	in memory descriptor
@@ -69,9 +69,10 @@ int fimg_images_compatible(FloatImg *a, FloatImg *b);
69 69
 int fimg_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef);
70 70
 
71 71
 /*	'operats' module 		*/
72
-int fimg_add(FloatImg *a, FloatImg *b, FloatImg *d);
73
-int fimg_sub(FloatImg *a, FloatImg *b, FloatImg *d);
74
-int fimg_mul(FloatImg *a, FloatImg *b, FloatImg *d);
72
+int fimg_add_3(FloatImg *a, FloatImg *b, FloatImg *d);
73
+int fimg_add_2(FloatImg *a, FloatImg *b);			/* B+=A */
74
+int fimg_sub_3(FloatImg *a, FloatImg *b, FloatImg *d);
75
+int fimg_mul_3(FloatImg *a, FloatImg *b, FloatImg *d);
75 76
 int fimg_minimum(FloatImg *a, FloatImg *b, FloatImg *d);
76 77
 int fimg_maximum(FloatImg *a, FloatImg *b, FloatImg *d);
77 78
 

+ 32
- 5
lib/operators.c View File

@@ -16,10 +16,10 @@ extern int verbosity;		/* must be declared around main() */
16 16
 
17 17
 /* ---------------------------------------------------------------- */
18 18
 /*
19
- * 	A + B -> D
19
+ * 		A + B -> D
20 20
  * 				why is this func so slow ?
21 21
  */
22
-int fimg_add(FloatImg *a, FloatImg *b, FloatImg *d)
22
+int fimg_add_3(FloatImg *a, FloatImg *b, FloatImg *d)
23 23
 {
24 24
 int		idx, nbpixels;
25 25
 
@@ -40,13 +40,40 @@ for (idx=0; idx<nbpixels; idx++) {
40 40
 	d->B[idx] = a->B[idx] + b->B[idx];
41 41
 	}
42 42
 
43
+return 0;
44
+}
45
+/* ---------------------------------------------------------------- */
46
+/*
47
+ * 		B += A		may be faster than fimg_add_3 ?
48
+ */
49
+int fimg_add_2(FloatImg *a, FloatImg *b)
50
+{
51
+int		idx, nbpixels;
52
+
53
+#if DEBUG_LEVEL
54
+fprintf(stderr, ">>> %s ( %p %p )\n", __func__, a, b);
55
+#endif
56
+
57
+if (3 != a->type || 3 != b->type) {
58
+	fprintf(stderr, "%s : got a bad type fimg\n", __func__);
59
+	return -8;
60
+	}
61
+
62
+nbpixels = a->width * a->height;
63
+
64
+for (idx=0; idx<nbpixels; idx++) {
65
+	b->R[idx] += a->R[idx];
66
+	b->G[idx] += a->G[idx];
67
+	b->B[idx] += a->B[idx];
68
+	}
69
+
43 70
 return 0;
44 71
 }
45 72
 /* ---------------------------------------------------------------- */
46 73
 /*
47 74
  *		A - B -> D
48 75
  */
49
-int fimg_sub(FloatImg *a, FloatImg *b, FloatImg *d)
76
+int fimg_sub_3(FloatImg *a, FloatImg *b, FloatImg *d)
50 77
 {
51 78
 int		idx, nbpixels;
52 79
 
@@ -57,7 +84,7 @@ fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, a, b, d);
57 84
 if (3 != a->type || 3 != b->type || 3 != d->type) {
58 85
 	fprintf(stderr, "%s : got a bad type fimg\n", __func__);
59 86
 	return -8;
60
-	} 
87
+	}
61 88
 
62 89
 nbpixels = a->width * a->height;
63 90
 
@@ -76,7 +103,7 @@ return 0;
76 103
 /*
77 104
  *		A * B -> D
78 105
  */
79
-int fimg_mul(FloatImg *a, FloatImg *b, FloatImg *d)
106
+int fimg_mul_3(FloatImg *a, FloatImg *b, FloatImg *d)
80 107
 {
81 108
 int		idx, nbpixels;
82 109
 

+ 3
- 3
tools/fimgops.c View File

@@ -80,16 +80,16 @@ int	foo;
80 80
 switch (action)	{
81 81
 
82 82
 	case OP_ADD:
83
-		foo = fimg_add(A, B, D);		break;
83
+		foo = fimg_add_3(A, B, D);		break;
84 84
 	case OP_SUB:
85
-		foo = fimg_sub(A, B, D);		break;
85
+		foo = fimg_sub_3(A, B, D);		break;
86 86
 	case OP_MIX:
87 87
 		if (verbosity) fprintf(stderr, "fvalue is %f\n",
88 88
 							global_fvalue);
89 89
 		foo = fimg_interpolate(A, B, D, global_fvalue);
90 90
 		break;
91 91
 	case OP_MUL:
92
-		foo = fimg_add(A, B, D);		break;
92
+		foo = fimg_mul_3(A, B, D);		break;
93 93
 	case OP_MINI:
94 94
 		foo = fimg_maximum(A, B, D);		break;
95 95
 	case OP_MAXI:

Loading…
Cancel
Save