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.

218 lines
4.9 KiB

2 years ago
2 years ago
11 months ago
11 months ago
11 months ago
11 months ago
2 years ago
11 months ago
11 months ago
11 months ago
1 year ago
11 months ago
11 months ago
12 months ago
11 months ago
11 months ago
2 years ago
11 months ago
11 months ago
  1. /*
  2. * tests des fonctions diverses - main file
  3. see also: tests.c
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <pam.h>
  9. #undef DEBUG_LEVEL
  10. #define DEBUG_LEVEL 1
  11. #include "../floatimg.h"
  12. #include "tests.h"
  13. int verbosity;
  14. float global_fvalue;
  15. /* --------------------------------------------------------------------- */
  16. /* --------------------------------------------------------------------- */
  17. enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff,
  18. Histo, Hsv, Classif, Ctr2x2, Qsortrgb,
  19. Displace, ReadPNG, Plasmas, Hilight, OpenEXR };
  20. typedef struct {
  21. char *name;
  22. int Cmd;
  23. } Command;
  24. Command commands[] = {
  25. { "equalize", Equalize },
  26. { "rotate", Rotate },
  27. { "sfx0", Sfx0 },
  28. { "f3x3", F3x3 },
  29. { "mire", MIRE },
  30. { "wfits", Wfits },
  31. { "wpng", Wpng },
  32. { "wtiff", Wtiff },
  33. { "histo", Histo },
  34. { "hsv", Hsv },
  35. { "classif", Classif },
  36. { "ctr2x2", Ctr2x2 },
  37. { "qsortrgb", Qsortrgb },
  38. { "displace", Displace },
  39. { "readpng", ReadPNG },
  40. { "plasma", Plasmas },
  41. { "hilight", Hilight },
  42. { "openexr", OpenEXR },
  43. { NULL, 0 }
  44. } ;
  45. /* --------------------------------------------------------------------- */
  46. int lookup_cmd(char *cmdtxt)
  47. {
  48. Command *pcmd;
  49. pcmd = commands;
  50. while (pcmd->name) {
  51. if (!strcmp(pcmd->name, cmdtxt)) return pcmd->Cmd;
  52. pcmd++;
  53. }
  54. return -1;
  55. }
  56. /* --------------------------------------------------------------------- */
  57. void list_tests(void)
  58. {
  59. Command *pcmd = commands;
  60. while (pcmd->name) {
  61. printf("%s\n", pcmd->name);
  62. pcmd++;
  63. }
  64. exit(0);
  65. }
  66. /* --------------------------------------------------------------------- */
  67. void help(int k)
  68. {
  69. Command *pcmd;
  70. fprintf(stderr, "usage:\n\t./t [options] command [filename]\n");
  71. fprintf(stderr, "options:\n");
  72. fprintf(stderr, "\t-k 1.414\tset float value\n");
  73. fprintf(stderr, "\t-l\t\tlist tests\n");
  74. fprintf(stderr, "\t-o \t\toutfile\n");
  75. fprintf(stderr, "commands:\n");
  76. pcmd = commands;
  77. while (pcmd->name) {
  78. fprintf(stderr, "\t%-15s %d\n", pcmd->name, pcmd->Cmd);
  79. pcmd++;
  80. }
  81. fprintf(stderr, "\ncompiled on "__DATE__" at "__TIME__"\n");
  82. exit(0);
  83. }
  84. /* --------------------------------------------------------------------- */
  85. int main(int argc, char *argv[])
  86. {
  87. int foo, opt;
  88. char *filename, *command, *outfile;
  89. fprintf(stderr, "++++++++ test des fonctions pid=%d\n", getpid());
  90. fprintf(stderr, "++++++++ compiled "__DATE__" at " __TIME__ "\n");
  91. global_fvalue = 1.0;
  92. outfile = "out.pnm";
  93. command = "none";
  94. filename = "in.fimg";
  95. while ((opt = getopt(argc, argv, "hk:lo:p:v")) != -1) {
  96. // fprintf(stderr, "opt = %c\n", opt);
  97. switch(opt) {
  98. case 'h': help(0); break;
  99. case 'k': global_fvalue = atof(optarg); break;
  100. case 'l': list_tests(); break;
  101. case 'o': outfile = optarg; break;
  102. case 'v': verbosity++; break;
  103. }
  104. }
  105. // fprintf(stderr, "argc %d optind %d\n", argc, optind);
  106. switch (argc-optind) {
  107. case 1: /* only command */
  108. command = argv[optind];
  109. break;
  110. case 2:
  111. command = argv[optind];
  112. filename = argv[optind+1];
  113. break;
  114. default:
  115. fprintf(stderr, "%s: bad command line ?\n", argv[0]);
  116. help(1);
  117. break;
  118. }
  119. if (verbosity) {
  120. fprintf(stderr, "++++++++ %s : running command '%s' on '%s'\n",
  121. argv[0], command, filename);
  122. fprintf(stderr, "global fvalue : %f\n", global_fvalue);
  123. }
  124. opt = lookup_cmd(command);
  125. // fprintf(stderr, "lookup '%s' --> %d\n", command, opt);
  126. switch(opt) {
  127. case Equalize:
  128. foo = essai_equalize(filename); break;
  129. case Sfx0:
  130. foo = essai_sfx0(filename); break;
  131. case F3x3:
  132. foo = essai_filtrage_3x3(filename); break;
  133. case MIRE:
  134. foo = essai_mire(filename, 0);
  135. break;
  136. case Wfits:
  137. foo = essai_ecriture_fits("out.fits");
  138. break;
  139. case Wpng:
  140. foo = essai_ecriture_png("out.png");
  141. break;
  142. case Wtiff:
  143. foo = essai_ecriture_tiff("out.tiff");
  144. break;
  145. case Histo:
  146. foo = essai_histogramme(filename, 98765);
  147. break;
  148. case Hsv:
  149. // not ready for primtime
  150. // foo = fimg_essai_hsv(filename);
  151. foo = 0;
  152. break;
  153. case Classif:
  154. foo = essai_classif(filename, outfile, global_fvalue);
  155. break;
  156. case Ctr2x2:
  157. foo = essai_contour_2x2(filename, outfile);
  158. break;
  159. case Qsortrgb:
  160. foo = essai_qsort_rgb(filename, outfile);
  161. break;
  162. case Displace:
  163. foo = essai_displacement(filename, outfile);
  164. break;
  165. case ReadPNG:
  166. // not ready for primetime
  167. // foo = essai_lecture_png("in.png", outfile, 0);
  168. foo = 0;
  169. break;
  170. case Plasmas:
  171. foo = essai_plasma(filename, outfile, 1, global_fvalue);
  172. fprintf(stderr, "we are all plasmafields\n");
  173. break;
  174. case Rotate:
  175. fprintf(stderr, "rotate not implemented (%d)\n", rand());
  176. foo = 0;
  177. break;
  178. case Hilight:
  179. foo = essai_highlights(filename, outfile, 0, global_fvalue);
  180. break;
  181. case OpenEXR:
  182. foo = essai_openexr(filename, outfile, 0x55);
  183. break;
  184. default:
  185. fprintf(stderr, "'%s' is a bad command\n", command);
  186. exit(1);
  187. }
  188. if (foo) {
  189. fprintf(stderr, "******* Essai --> %d\n", foo);
  190. }
  191. fprintf(stderr, "++++++++++++ end of '%s' pid %d\n", command, getpid());
  192. return 0;
  193. }
  194. /* --------------------------------------------------------------------- */