Browse Source

commit du soir, espoir

tonton Th 3 months ago
parent
commit
83af701479
8 changed files with 189 additions and 24 deletions
  1. 1
    1
      doc/the_floatimg_hack.tex
  2. 7
    2
      floatimg.h
  3. 6
    2
      funcs/Makefile
  4. 39
    0
      funcs/equalize.c
  5. 116
    14
      funcs/t.c
  6. 1
    1
      lib/fimg-core.c
  7. 18
    3
      lib/fimg-math.c
  8. 1
    1
      scripts/shoot.sh

+ 1
- 1
doc/the_floatimg_hack.tex View File

@@ -956,7 +956,7 @@ encore un peu rudimentaire
956 956
 vers le programme de capture d'image décrit page \pageref{grabvidseq}.
957 957
 Il utilise deux fichiers dans le répertoire de travail~:
958 958
 \textit{reglages} et \textit{compteur}. Le premier est, en fait,
959
-un bout de shell affectant quelques variables, ou plutôt, les surchargent.
959
+un bout de shell affectant quelques variables, ou plutôt, les surchargant.
960 960
 
961 961
 \begin{lstlisting}
962 962
 OPTIONS="${OPTIONS} -v -c pow2 "

+ 7
- 2
floatimg.h View File

@@ -1,8 +1,9 @@
1 1
 /*
2
- *	floatimg.h
2
+ *			floatimg.h
3
+ *			ugly code from tTh
3 4
  */
4 5
 
5
-#define		FIMG_VERSION	98
6
+#define		FIMG_VERSION	100
6 7
 
7 8
 /*
8 9
  *	in memory descriptor
@@ -115,6 +116,10 @@ int fimg_power_2(FloatImg *s, FloatImg *d, double maxval);
115 116
 int fimg_cos_01(FloatImg *s, FloatImg *d, double maxval);
116 117
 int fimg_cos_010(FloatImg *s, FloatImg *d, double maxval);
117 118
 
119
+/*	module funcs/geometry.c		*/
120
+int fimg_equalize_compute(FloatImg *src, void *vptr);
121
+
122
+
118 123
 int fimg_mk_gray_from(FloatImg *src, FloatImg*dst, int k);
119 124
 int fimg_desaturate(FloatImg *src, FloatImg *dst, int k);
120 125
 

+ 6
- 2
funcs/Makefile View File

@@ -1,9 +1,10 @@
1 1
 #---------------------------------------------------------------
2 2
 
3
-COPT = -Wall -fpic -g -pg -no-pie -DDEBUG_LEVEL=0
3
+COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0
4 4
 DEPS = ../floatimg.h Makefile
5 5
 OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o	\
6
-	fimg-libpnm.o rampes.o sfx0.o geometry.o rotate.o
6
+	fimg-libpnm.o rampes.o sfx0.o geometry.o rotate.o	\
7
+	equalize.o
7 8
 
8 9
 #---------------------------------------------------------------
9 10
 
@@ -36,6 +37,9 @@ geometry.o:		geometry.c $(DEPS)
36 37
 rotate.o:		rotate.c $(DEPS)
37 38
 	gcc $(COPT) -c $<
38 39
 
40
+equalize.o:		equalize.c $(DEPS)
41
+	gcc $(COPT) -c $<
42
+
39 43
 sfx0.o:			sfx0.c $(DEPS)
40 44
 	gcc $(COPT) -c $<
41 45
 

+ 39
- 0
funcs/equalize.c View File

@@ -0,0 +1,39 @@
1
+/*
2
+ *		FLOATIMG
3
+ *	egalisation dinamique approximative
4
+ *	#coronamaison  Thu 09 Apr 2020 03:37:10 PM CEST
5
+ */
6
+
7
+#include  <stdio.h>
8
+#include  <string.h>
9
+
10
+#include  "../floatimg.h"
11
+
12
+extern int		verbosity;
13
+
14
+/* --------------------------------------------------------------------- */
15
+int fimg_equalize_compute(FloatImg *src, void *vptr)
16
+{
17
+float			minmax[6];
18
+int			foo;
19
+
20
+#if DEBUG_LEVEL
21
+fprintf(stderr, ">>> %s ( %p )\n", __func__, src);
22
+#endif
23
+
24
+foo = fimg_get_minmax_rgb(src, minmax);
25
+printf("Rmin  %12.4g    Rmax  %12.4g\n", minmax[0], minmax[1]);
26
+printf("Gmin  %12.4g    Gmax  %12.4g\n", minmax[2], minmax[3]);
27
+printf("Bmin  %12.4g    Bmax  %12.4g\n", minmax[4], minmax[5]);
28
+
29
+if ( (minmax[0]<0.0) || (minmax[2]<0.0) || (minmax[4]<0.0) ) {
30
+	fprintf(stderr, "%s: negative value ?\n", __func__);
31
+	return -4;
32
+	}
33
+
34
+return 0;
35
+}
36
+/* --------------------------------------------------------------------- */
37
+/* --------------------------------------------------------------------- */
38
+/* --------------------------------------------------------------------- */
39
+

+ 116
- 14
funcs/t.c View File

@@ -12,6 +12,37 @@ int		verbosity;
12 12
 
13 13
 float		global_fvalue;
14 14
 
15
+/* --------------------------------------------------------------------- */
16
+/*
17
+ *	egalisation dynamique approximative
18
+ *	#coronamaison  Thu 09 Apr 2020 03:37:10 PM CEST
19
+ */
20
+int essai_equalize(char *infile)
21
+{
22
+FloatImg	src;
23
+int		foo;
24
+
25
+if (NULL != infile) {
26
+	fprintf(stderr, "%s: loading %s\n", __func__, infile);
27
+	foo = fimg_create_from_dump(infile, &src);
28
+	if (foo) {
29
+		fprintf(stderr, "%s: err load '%s'\n", __func__, infile);
30
+		return foo;
31
+		}
32
+	}
33
+else	{
34
+	fprintf(stderr, "%s : NOT INPUT FILE, FUBAR\n", __func__);
35
+	abort();
36
+	}
37
+
38
+foo = fimg_equalize_compute(&src, NULL);
39
+fprintf(stderr, "equalize compute --> %d\n", foo);
40
+
41
+
42
+fimg_destroy(&src);
43
+
44
+return -1;
45
+}
15 46
 /* --------------------------------------------------------------------- */
16 47
 int essai_rotate(char *infile)
17 48
 {
@@ -82,19 +113,24 @@ else	{
82 113
 	fimg_test_pattern(&src, 0, 255.0);
83 114
 	}
84 115
 
85
-fimg_save_as_png(&src, "test.png", 0);
116
+// fimg_save_as_png(&src, "test.png", 0);
86 117
 
87 118
 foo = fimg_clone(&src, &dst, 0);
88 119
 if (foo) {
89 120
 	fprintf(stderr, "%s: err clone %p\n", __func__, &src);
90 121
 	return -44;
91 122
 	}
123
+
124
+
92 125
 fimg_filter_3x3(&src, &dst, &filter_a);
126
+
127
+
93 128
 foo = fimg_clamp_negativ(&dst);
129
+
94 130
 if (foo) {
95 131
 	fprintf(stderr, "clamped %d negative pixels\n", foo);
96 132
 	}
97
-foo = fimg_save_as_png(&dst, "f3x3a.png", 0);
133
+// foo = fimg_save_as_png(&dst, "f3x3a.png", 0);
98 134
 // foo = fimg_save_as_pnm(&dst, "f3x3a.pnm", 0);
99 135
 
100 136
 fimg_filter_3x3(&src, &dst, &filter_b);
@@ -102,7 +138,7 @@ foo = fimg_clamp_negativ(&dst);
102 138
 if (foo) {
103 139
 	fprintf(stderr, "clamped %d negative pixels\n", foo);
104 140
 	}
105
-foo = fimg_save_as_png(&dst, "f3x3b.png", 0);
141
+// foo = fimg_save_as_png(&dst, "f3x3b.png", 0);
106 142
 // foo = fimg_save_as_pnm(&dst, "f3x3a.pnm", 0);
107 143
 
108 144
 fimg_destroy(&src);	fimg_destroy(&dst);
@@ -315,36 +351,102 @@ fprintf(stderr, "save as png -> %d\n", foo);
315 351
 return 0;
316 352
 }
317 353
 /* --------------------------------------------------------------------- */
354
+enum nCmd { Equalize=1, Rotate, Sfx0, F3x3 };
355
+typedef struct {
356
+	char	*name;
357
+	int	Cmd;
358
+	} Command;
359
+
360
+Command commands[] = {
361
+	{ "equalize",	Equalize	},
362
+	{ "rotate",	Rotate		},
363
+	{ "sfx0",	Sfx0		},
364
+	{ "f3x3",	F3x3		},
365
+	{ NULL,		0		}
366
+	} ;
367
+
368
+/* --------------------------------------------------------------------- */
369
+int lookup_cmd(char *cmdtxt)
370
+{
371
+Command *pcmd;
372
+
373
+pcmd = commands;
374
+while (pcmd->name) {
375
+	if (!strcmp(pcmd->name, cmdtxt)) return pcmd->Cmd;
376
+	pcmd++;
377
+	}
378
+
379
+return -1;
380
+}
381
+/* --------------------------------------------------------------------- */
382
+void help(int k)
383
+{
384
+Command *pcmd;
385
+
386
+fprintf(stderr, "usage:\n\t./t command in-filename\n");
387
+
388
+fprintf(stderr, "commands:\n");
389
+pcmd = commands;
390
+while (pcmd->name) {
391
+	fprintf(stderr, "\t%-15s   %d\n", pcmd->name, pcmd->Cmd);
392
+	pcmd++;
393
+	}
394
+fprintf(stderr, "\ncompiled on "__DATE__" at "__TIME__"\n");
395
+
396
+exit(0);
397
+}
398
+/* --------------------------------------------------------------------- */
318 399
 int main(int argc, char *argv[])
319 400
 {
320 401
 int		foo, opt;
321
-char		*filename;
402
+char		*filename, *command;
322 403
 
323
-puts("++++++++++++++++++++++++++++++++");
404
+puts("++++++++ test des fonctions +++++++");
324 405
 
325 406
 global_fvalue = 1.0;
326 407
 
327 408
 while ((opt = getopt(argc, argv, "hk:v")) != -1) {
328 409
 	switch(opt) {
329
-		// case 'h':	help(0);			break;
410
+		case 'h':	help(0);			break;
330 411
 		case 'k':	global_fvalue = atof(optarg);	break;
331 412
 		case 'v':	verbosity++;			break;
332 413
 		}
333 414
 	}
334 415
 
335
-fprintf(stderr, "argc %d   optind %d\n", argc, optind);
416
+// fprintf(stderr, "argc %d   optind %d\n", argc, optind);
336 417
 
337 418
 filename = NULL;
338
-if (1 == argc-optind)	filename = argv[optind];
419
+if (2 != argc-optind) {
420
+	fprintf(stderr, "%s: bad command line\n", argv[0]);
421
+	help(1);
422
+	}
423
+
424
+command  = argv[optind];
425
+filename = argv[optind+1];
426
+
427
+if (verbosity) {
428
+	fprintf(stderr, "running command '%s' on '%s'\n", command, filename);
429
+	}
430
+
431
+opt = lookup_cmd(command);
432
+fprintf(stderr, "lookup '%s' --> %d\n", command, opt);
433
+
434
+switch(opt) {
435
+	case Equalize:
436
+		foo = essai_equalize(filename);		break;
437
+
438
+	case Sfx0:
439
+		foo = essai_sfx0(filename);		break;
440
+	case F3x3:
441
+		foo = essai_filtrage_3x3(filename);	break;
442
+
443
+
444
+	default:
445
+		fprintf(stderr, "%s : bad command\n", command);
446
+		exit(1);
339 447
 
340
-/*
341
-foo = essai_filtrage_2x2(filename);
342
-if (foo) {
343
-	fprintf(stderr, "Filtre 2x2 ====> %d\n", foo);
344 448
 	}
345
-*/
346 449
 
347
-foo = essai_rotate(filename);
348 450
 if (foo) {
349 451
 	fprintf(stderr, "Essai ====> %d\n", foo);
350 452
 	}

+ 1
- 1
lib/fimg-core.c View File

@@ -111,7 +111,7 @@ if (NULL==fptr) {
111 111
 	}
112 112
 
113 113
 #if DEBUG_LEVEL > 1
114
-fprintf(stderr, "    got %d bytes at %p\n", size, fptr);
114
+fprintf(stderr, "   %s: got %d bytes at %p\n", __func__, size, fptr);
115 115
 #endif
116 116
 
117 117
 fimg->width = w;	fimg->height = h;

+ 18
- 3
lib/fimg-math.c View File

@@ -19,7 +19,7 @@ extern int verbosity;		/* must be declared around main() */
19 19
 float fimg_get_maxvalue(FloatImg *head)
20 20
 {
21 21
 float		maxval;
22
-int		foo;
22
+int		foo, surface;
23 23
 
24 24
 if (head->type != FIMG_TYPE_RGB && head->type != FIMG_TYPE_GRAY) {
25 25
 	fprintf(stderr, "%s : type %d invalide\n",
@@ -29,15 +29,17 @@ if (head->type != FIMG_TYPE_RGB && head->type != FIMG_TYPE_GRAY) {
29 29
 
30 30
 maxval = 0.0;		/* no negative values allowed */
31 31
 
32
+surface = head->width*head->height;
33
+
32 34
 switch (head->type) {
33 35
 	case FIMG_TYPE_RGB:
34
-		for (foo=0; foo<(head->width*head->height); foo++) {
36
+		for (foo=0; foo<surface; foo++) {
35 37
 		if (head->R[foo] > maxval) maxval = head->R[foo];
36 38
 		if (head->G[foo] > maxval) maxval = head->G[foo];
37 39
 		if (head->B[foo] > maxval) maxval = head->B[foo];
38 40
 		}
39 41
 	case FIMG_TYPE_GRAY:
40
-		for (foo=0; foo<(head->width*head->height); foo++) {
42
+		for (foo=0; foo<surface; foo++) {
41 43
 		if (head->R[foo] > maxval) maxval = head->R[foo];
42 44
 		}
43 45
 	}
@@ -209,6 +211,19 @@ for (idx=0; idx<nbre; idx++) {
209 211
 		}
210 212
 	}
211 213
 
214
+/* WTF 12 avril 2020, valgrind me cause mal ?
215
+==28943== Conditional jump or move depends on uninitialised value(s)
216
+==28943==    at 0x4045E9: fimg_clamp_negativ (fimg-math.c:208)
217
+==28943==    by 0x4018C9: essai_filtrage_3x3 (t.c:128)
218
+==28943==    by 0x4024D5: main (t.c:444)
219
+==28943==  Uninitialised value was created by a heap allocation
220
+==28943==    at 0x483577F: malloc (vg_replace_malloc.c:299)
221
+==28943==    by 0x40284D: fimg_create (fimg-core.c:107)
222
+==28943==    by 0x402AB3: fimg_clone (fimg-core.c:174)
223
+==28943==    by 0x401861: essai_filtrage_3x3 (t.c:118)
224
+==28943==    by 0x4024D5: main (t.c:444)
225
+*/
226
+
212 227
 return count;
213 228
 }
214 229
 /* ---------------------------------------------------------------- */

+ 1
- 1
scripts/shoot.sh View File

@@ -48,7 +48,7 @@ else
48 48
 fi
49 49
 
50 50
 #	------------------------------------
51
-#	take and display the fancy picture
51
+#	grab and display the fancy picture
52 52
 $GVS -d $DEV -n $NBRE -p $PERIOD $OPTIONS -s $SZ -o $outfile
53 53
 
54 54
 if [ ${SHOW} == "yes" ]

Loading…
Cancel
Save