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.

264 lines
6.1 KiB

10 months ago
1 year ago
9 months ago
10 months ago
11 months ago
10 months ago
10 months ago
  1. /*
  2. * FONDERIE
  3. */
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include <glob.h>
  9. #include "../floatimg.h"
  10. #include "fifo.h"
  11. #include "glitches.h"
  12. #include "crapulator.h"
  13. #include "filterstack.h"
  14. int verbosity;
  15. /* -------------------------------------------------------------- */
  16. /*
  17. * this is the real worker ? or just a wrapper ?
  18. */
  19. int traite_une_image(FloatImg *image, char *outd)
  20. {
  21. static int numero;
  22. int foo;
  23. char ligne[200];
  24. #if DEBUG_LEVEL
  25. fprintf(stderr, "\n>>> %s ( %p '%s' )\n", __func__, image, outd);
  26. #endif
  27. /* here, we put the picz in the fifo machinery */
  28. foo = insert_picture(image);
  29. if (foo) {
  30. fprintf(stderr, "%s: err %d on insert\n", __func__, foo);
  31. return foo;
  32. }
  33. /* and now, we pull the result on the magic computation
  34. */
  35. sprintf(ligne, "%s/%05d.png", outd, numero);
  36. if (verbosity > 1) fprintf(stderr, " exporting to '%s'\n", ligne);
  37. foo = export_fifo(ligne, 1);
  38. if (foo) {
  39. fprintf(stderr, "%s: err %d on export\n", __func__, foo);
  40. return foo;
  41. }
  42. numero++; /* VERY IMPORTANT :) */
  43. return 0;
  44. }
  45. /* -------------------------------------------------------------- */
  46. int insert_blank(FloatImg *image, int nbre, char *outd)
  47. {
  48. int idx, foo;
  49. #if DEBUG_LEVEL
  50. fprintf(stderr, ">>> %s ( %p %d '%s' )\n", __func__,
  51. image, nbre, outd);
  52. #endif
  53. fimg_clear(image);
  54. for (idx=0; idx<nbre; idx++) {
  55. if ((foo=traite_une_image(image, outd))) {
  56. fprintf(stderr, "%s : err %d from 'traite_une_image'\n",
  57. __func__, foo);
  58. break;
  59. }
  60. printf("\t%c\r", "ABCDEFGH"[idx%8]); fflush(stdout);
  61. }
  62. puts("");
  63. return 0;
  64. }
  65. /* -------------------------------------------------------------- */
  66. int demarre_la_machine(char *pattern, char *outdir, int szfifo,
  67. int outfmt, int blk)
  68. {
  69. int foo, idx, width, height;
  70. glob_t globbuf;
  71. char *cptr;
  72. FloatImg input;
  73. double fin;
  74. float maxvalue;
  75. int datas[3];
  76. #if DEBUG_LEVEL
  77. fprintf(stderr, "\n>>> %s ( '%s' -> '%s' %d )\n", __func__,
  78. pattern, outdir, szfifo);
  79. #endif
  80. (void)fimg_timer_set(0);
  81. memset(&globbuf, 0, sizeof(glob_t));
  82. foo = glob(pattern, 0, NULL, &globbuf);
  83. if (foo) {
  84. fprintf(stderr, "glob (%s) failure %d\n", pattern, foo);
  85. exit(1);
  86. }
  87. fprintf(stderr, "glob '%s' -> %d, %d files found\n", pattern, foo,
  88. (int)globbuf.gl_pathc);
  89. /* get the size of the inputs images */
  90. foo = fimg_fileinfos(globbuf.gl_pathv[0], datas);
  91. width = datas[0]; height = datas[1];
  92. fprintf(stderr, "first image size %dx%d\n", width, height);
  93. fimg_create(&input, width, height, 3);
  94. /* get the maximum value of the first pic */
  95. foo = fimg_load_from_dump(globbuf.gl_pathv[0], &input);
  96. if (foo) {
  97. fprintf(stderr, "%s: err %d loading %s\n",
  98. __func__, foo, globbuf.gl_pathv[0]);
  99. exit(1);
  100. }
  101. maxvalue = fimg_get_maxvalue(&input);
  102. fprintf(stderr, "first image maxvalue %f\n", maxvalue);
  103. foo = create_fifo(szfifo, width, height, FIMG_TYPE_RGB);
  104. fprintf(stderr, "init fifo (%d slots) --> %d\n", szfifo, foo);
  105. /* XXX inject a few strange pics in the fifo */
  106. insert_blank(&input, blk, outdir);
  107. for (idx=0; idx<globbuf.gl_pathc; idx++) {
  108. cptr = globbuf.gl_pathv[idx];
  109. /* first step : read the current grabed picz from disk,
  110. and put it in our private buffer */
  111. // fprintf(stderr, "\n######### loading '%s'\n", cptr);
  112. foo = fimg_load_from_dump(cptr, &input);
  113. if (foo) {
  114. fprintf(stderr, "load #%d from dump -> %d\n", idx, foo);
  115. continue;
  116. }
  117. /* fscking input filter here */
  118. foo = filterstack_run(0, &input, 0);
  119. if (foo) {
  120. fprintf(stderr, "%s: input filter -> %d\n", __func__, foo);
  121. exit(1);
  122. }
  123. #if 0
  124. if (idx==42) fimg_dump_to_file(&input, "inputXXX.fimg", 0);
  125. #endif
  126. foo = traite_une_image(&input, outdir);
  127. if (foo) {
  128. fprintf(stderr, "traitement %s -> %d WTF?\n", cptr, foo);
  129. break;
  130. }
  131. fprintf(stderr, "\t%5d / %5d\r", idx, (int)globbuf.gl_pathc);
  132. }
  133. fputs("\n", stderr);
  134. insert_blank(&input, blk, outdir);
  135. /*
  136. * PLEASE, FLUSH THE FIFO !
  137. */
  138. fin = fimg_timer_get(0);
  139. if (idx) {
  140. fprintf(stderr, "\nelapsed %.2f seconds, %.2f s/pic\n", fin, fin/idx);
  141. }
  142. else {
  143. fprintf(stderr, "\nelapsed %.2f seconds\n", fin);
  144. }
  145. return 8; /* why 9 ? */
  146. }
  147. /* -------------------------------------------------------------- */
  148. void help(void)
  149. {
  150. puts("\tFONDERIE\noptions:");
  151. puts("\t-E\tinput:filter:chain");
  152. puts("\t-F\toutput:filter:chain");
  153. // puts("\t-g\tconvert to gray");
  154. puts("\t-I\tinput glob pattern");
  155. puts("\t-L\tlist available filters");
  156. puts("\t-O\toutput directory");
  157. puts("\t-T\tfifo size");
  158. puts("\t-v\tincrease verbosity");
  159. exit(0);
  160. }
  161. /* -------------------------------------------------------------- */
  162. int main (int argc, char *argv[])
  163. {
  164. int foo, opt;
  165. int fifosize = 10;
  166. char *in_pattern = "capture/?????.fimg";
  167. char *out_dir = "p8";
  168. int outfmt = FILE_TYPE_PNG;
  169. int blanks = 20;
  170. char *InFchain = "none";
  171. char *OutFchain = "none";
  172. fprintf(stderr, "*** %s\n\tcompiled %s, %s, pid %d\n",
  173. argv[0], __DATE__, __TIME__, getpid());
  174. fimg_print_version(2);
  175. while ((opt = getopt(argc, argv, "B:E:F:ghI:LO:T:vw:x:")) != -1) {
  176. switch(opt) {
  177. case 'E': InFchain = optarg; break;
  178. case 'F': OutFchain = optarg; break;
  179. case 'B': blanks = atoi(optarg);
  180. break;
  181. case 'g': // convert_to_gray = 1;
  182. break;
  183. case 'h': help();
  184. break;
  185. case 'I': in_pattern = optarg;
  186. break;
  187. case 'L':
  188. list_crapulors("available filters");
  189. exit(0);
  190. case 'O': out_dir = optarg;
  191. break;
  192. case 'T': fifosize = atoi(optarg);
  193. break;
  194. case 'v': verbosity++;
  195. break;
  196. }
  197. }
  198. if (verbosity) {
  199. fprintf(stderr, "\tinput glob '%s'\n", in_pattern);
  200. fprintf(stderr, "\toutput dir '%s'\n", out_dir);
  201. fprintf(stderr, "\tsrc filter '%s'\n", InFchain);
  202. fprintf(stderr, "\tout filter '%s'\n", OutFchain);
  203. }
  204. foo = parse_filter_chain(0, InFchain);
  205. if (foo) {
  206. fprintf(stderr, "err %d parsing '%s'\n", foo, InFchain);
  207. exit(1);
  208. }
  209. foo = parse_filter_chain(1, OutFchain);
  210. if (foo) {
  211. fprintf(stderr, "err %d parsing '%s'\n", foo, OutFchain);
  212. exit(1);
  213. }
  214. if (verbosity > 1) {
  215. filterstack_list(0, "input");
  216. filterstack_list(1, "ouput");
  217. fprintf(stderr, ".\n");
  218. }
  219. foo = demarre_la_machine(in_pattern, out_dir, fifosize, outfmt, blanks);
  220. fprintf(stderr, "retour du big-run de la machine -> %d\n", foo);
  221. return 0;
  222. }
  223. /* -------------------------------------------------------------- */