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.

221 lines
5.0 KiB

10 months ago
1 year ago
10 months ago
10 months ago
11 months ago
11 months ago
  1. /*
  2. * +-------------------------+
  3. * | S I N G L E P A S S |
  4. * +-------------------------+
  5. */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <unistd.h>
  9. #include <string.h>
  10. #include <glob.h>
  11. #include "../floatimg.h"
  12. #include "crapulator.h"
  13. #include "filterstack.h"
  14. #include "single.h"
  15. #include "glitches.h"
  16. /* ----------------------------------------------------------- */
  17. #define FILTERS 0
  18. int verbosity;
  19. /* ----------------------------------------------------------- */
  20. int run_the_singlepass(char *globber, char *destdir, int duplic,
  21. int fchain, int outfmt)
  22. {
  23. FloatImg image = { 0 };
  24. int idx, foo, loop;
  25. glob_t globbuf;
  26. char *fname;
  27. double elapsed;
  28. #if DEBUG_LEVEL
  29. fprintf(stderr, ">>> %s ( '%s' '%s' %d %d )\n", __func__,
  30. globber, destdir, fchain, outfmt);
  31. #endif
  32. // filterstack_list(fchain, "Run the single pass");
  33. (void)fimg_timer_set(0);
  34. foo = single_init(0, destdir, fchain, outfmt);
  35. if (foo) {
  36. fprintf(stderr, "erreur %d single_init\n", foo);
  37. return foo;
  38. }
  39. // single_print_state("just after init", 0);
  40. memset(&globbuf, 0, sizeof(glob_t));
  41. foo = glob(globber, 0, NULL, &globbuf);
  42. // fprintf(stderr, "globbing '%s' -> %d, %d files found\n",
  43. // globber, foo, (int)globbuf.gl_pathc);
  44. switch (foo) {
  45. case GLOB_NOSPACE:
  46. fprintf(stderr, "%s: glob run out of memory\n", __func__);
  47. break;
  48. case GLOB_ABORTED:
  49. fprintf(stderr, "%s: glob read error\n", __func__);
  50. break;
  51. case GLOB_NOMATCH:
  52. fprintf(stderr, "%s: glob found no matches\n", __func__);
  53. break;
  54. }
  55. if (0 == globbuf.gl_pathc) {
  56. fprintf(stderr, "%s: no file found, aborting\n", __func__);
  57. return -1;
  58. }
  59. for (idx=0; idx<globbuf.gl_pathc; idx++) {
  60. fname = globbuf.gl_pathv[idx]; /* alias of filename */
  61. if (0==image.width && 0==image.height) {
  62. foo = fimg_create_from_dump(fname, &image);
  63. }
  64. else {
  65. foo = fimg_load_from_dump(fname, &image);
  66. }
  67. if (foo) {
  68. fprintf(stderr, "get image -> %d\n", foo);
  69. return -1;
  70. }
  71. if (0 == idx) {
  72. fprintf(stderr, "image size %dx%d\n",
  73. image.width, image.height);
  74. }
  75. fprintf(stderr, " %6ld %s\r", (long)globbuf.gl_pathc-idx, fname);
  76. foo = filterstack_run(fchain, &image, 0);
  77. if (foo) {
  78. fprintf(stderr, "%s: filterstack run --> %d\n",
  79. __func__, foo);
  80. return foo;
  81. }
  82. /* HERE WE CAN REPEAT THE INSERT OF THE PICZ */
  83. for (loop=0; loop<duplic; loop++) {
  84. foo = single_push_picture(&image);
  85. if (foo) {
  86. fprintf(stderr, "error %d on push_picture\n", foo);
  87. return foo;
  88. }
  89. if (loop) {
  90. /* this is just a wip XXX */
  91. microglitch(&image, loop);
  92. }
  93. }
  94. }
  95. fprintf(stderr, "\n");
  96. globfree(&globbuf);
  97. fimg_destroy(&image);
  98. single_print_state("end of run", 0);
  99. elapsed = fimg_timer_get(0);
  100. fprintf(stderr, "%s: %ld frames, elapsed %.3f s, %.3f fps\n",
  101. __func__,
  102. (long)globbuf.gl_pathc, elapsed,
  103. (double)globbuf.gl_pathc/elapsed);
  104. return 0;
  105. }
  106. /* ----------------------------------------------------------- */
  107. static void help(void)
  108. {
  109. puts("------ Single pass serial filter ------\nusage:");
  110. puts("\t-F\tdefine:the:filter:chain");
  111. puts("\t-g\tinput glob pattern");
  112. puts("\t-L\tlist available filters");
  113. puts("\t-O\t/output/directory (default ./p8)");
  114. puts("\t-r N\trepetiiing factor");
  115. // puts("\t-s\tdo single test");
  116. puts("\t-v\tspit more messages");
  117. exit(0);
  118. }
  119. /* ----------------------------------------------------------- */
  120. int main(int argc, char *argv[])
  121. {
  122. int foo, opt;
  123. char *filterchain = "none";
  124. char *globbing = "./capture/?????.fimg";
  125. char *outdir = "./p8";
  126. // char *outtype = ".png";
  127. int do_xper = 0;
  128. int repeat = 1;
  129. fprintf(stderr, "*** %s : compiled %s %s\n", __FILE__,
  130. __DATE__, __TIME__);
  131. fimg_print_version(2);
  132. if (argc < 2) {
  133. fprintf(stderr, "\t/!\\ %s is option driven\n", argv[0]);
  134. help();
  135. }
  136. while ((opt = getopt(argc, argv, "hF:g:LO:r:svx")) != -1) {
  137. switch (opt) {
  138. case 'h': help(); break;
  139. case 'F': filterchain = optarg; break;
  140. case 'g': globbing = optarg; break;
  141. case 'L':
  142. list_crapulors("available filters");
  143. exit(0);
  144. case 'O': outdir = optarg; break;
  145. case 'r': repeat = atoi(optarg); break;
  146. case 'v': verbosity++; break;
  147. case 'x': do_xper = 1; break;
  148. default:
  149. fprintf(stderr, "%s ABEND\n", argv[0]);
  150. exit(1);
  151. }
  152. }
  153. if (repeat < 1) {
  154. fprintf(stderr, "%s: loop %d invalid\n", argv[0], repeat);
  155. exit(2);
  156. }
  157. foo = parse_filter_chain(FILTERS, filterchain);
  158. if (foo) {
  159. fprintf(stderr, "err %d in parse_filter_chain\n", foo);
  160. exit(1);
  161. }
  162. if (verbosity) {
  163. fprintf(stderr, "\tpid %d\n", getpid());
  164. fprintf(stderr, "\tinput glob %s\n", globbing);
  165. fprintf(stderr, "\tfilter chain %s\n", filterchain);
  166. fprintf(stderr, "\toutput dir %s\n", outdir);
  167. fprintf(stderr, "\trepeat %d\n", repeat);
  168. // fprintf(stderr, "\toutput type %s\n", outtype);
  169. fprintf(stderr, "\tdo xper %d\n", do_xper);
  170. }
  171. foo = run_the_singlepass(globbing, outdir, repeat,
  172. FILTERS, FILE_TYPE_PNG);
  173. fprintf(stderr, "\n\tRun the single pass --> %d\n", foo);
  174. return 0;
  175. }
  176. /* ----------------------------------------------------------- */