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.

198 lines
4.2 KiB

8 months ago
  1. /*
  2. * Fonctions de la Fonderie du Cumul
  3. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. * Du code bien cracra / tTh / Tetalab
  5. */
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <stdint.h>
  9. #include <stdlib.h>
  10. #include <malloc.h>
  11. #include "../floatimg.h"
  12. #include "fifo.h"
  13. #include "crapulator.h"
  14. #include "filterstack.h"
  15. /* -------------------------------------------------------------- */
  16. /* global vars from main
  17. */
  18. extern int verbosity;
  19. /* private vars of this module - it was very dirty,
  20. * but simple and efficient.
  21. */
  22. static A_Fifo g_fifo;
  23. /* -------------------------------------------------------------- */
  24. static int big_adder(FloatImg *from, FloatImg *to)
  25. {
  26. int size, idx;
  27. size = from->width * from->height;
  28. for (idx=0; idx<size; idx++) to->R[idx] += from->R[idx];
  29. for (idx=0; idx<size; idx++) to->G[idx] += from->G[idx];
  30. for (idx=0; idx<size; idx++) to->B[idx] += from->B[idx];
  31. return 0;
  32. }
  33. /* -------------------------------------------------------------- */
  34. /*
  35. * 97% of the total run time was in that function \o_
  36. */
  37. int faire_la_somme(A_Fifo *pfifo, FloatImg *destination, int step)
  38. {
  39. int idx, foo;
  40. FloatImg *pdest;
  41. #if DEBUG_LEVEL
  42. fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__,
  43. pfifo, destination, step);
  44. #endif
  45. if (step<1){
  46. fprintf(stderr, "***** %s invalid step %d\n", __func__, step);
  47. exit(1);
  48. }
  49. if (NULL==destination) {
  50. pdest = &(pfifo->total); }
  51. else {
  52. pdest = destination; }
  53. fimg_clear(pdest);
  54. for (idx=0; idx<pfifo->nbslots; idx += step) {
  55. foo = big_adder(&(pfifo->slots[idx]), pdest);
  56. if (foo)
  57. {
  58. fprintf(stderr, "%s: err %d on add_2\n", __func__, foo);
  59. abort();
  60. }
  61. }
  62. #if 0
  63. fprintf(stderr, "*** %s:%s writing debugB file ***\n",
  64. __FILE__, __func__);
  65. fimg_dump_to_file(&g_fifo.total, "debugB.fimg", 0);
  66. #endif
  67. return 0;
  68. }
  69. /* -------------------------------------------------------------- */
  70. /* called by 'fonderie.c'
  71. */
  72. int export_fifo(char *fname, int notused)
  73. {
  74. int foo, type;
  75. #if DEBUG_LEVEL
  76. fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, step);
  77. #endif
  78. foo = faire_la_somme(&g_fifo, NULL, 1);
  79. foo = filterstack_run(1, &g_fifo.total, 0);
  80. if (foo) {
  81. fprintf(stderr, "%s: ERR post process picture -> %d\n",
  82. __func__, foo);
  83. return foo;
  84. }
  85. #if 0
  86. fimg_dump_to_file(&g_fifo.total, "outputXXX.fimg", 0);
  87. #endif
  88. foo = fimg_export_picture(&g_fifo.total, fname, 0);
  89. if (foo) {
  90. fprintf(stderr, "ERR EXPORT '%s' is %d\n", fname, foo);
  91. exit(3);
  92. }
  93. return 0;
  94. }
  95. /* -------------------------------------------------------------- */
  96. int insert_picture(FloatImg *src)
  97. {
  98. FloatImg *dst;
  99. int nbre, foo;
  100. #if DEBUG_LEVEL
  101. fprintf(stderr, ">>> %s ( %p )\n", __func__, src);
  102. #endif
  103. dst = &g_fifo.slots[g_fifo.next];
  104. nbre = dst->width * dst->height * sizeof(float);
  105. memcpy(dst->R, src->R, nbre);
  106. memcpy(dst->G, src->G, nbre);
  107. memcpy(dst->B, src->B, nbre);
  108. /* XXX
  109. fprintf(stderr, "*** %s:%s writing debugA file ***\n",
  110. __FILE__, __func__);
  111. foo = fimg_dump_to_file(dst, "debugA.fimg", 0);
  112. fprintf(stderr, " ok file dumped %d\n", foo);
  113. XXX */
  114. g_fifo.next++; g_fifo.next %= g_fifo.nbslots;
  115. if (verbosity > 2) fprintf(stderr, "%s : next slot %d\n",
  116. __func__, g_fifo.next);
  117. return 0;
  118. }
  119. /* -------------------------------------------------------------- */
  120. /*
  121. * this function must have a lot of new parameters,
  122. * -- filetype of exported pictures...
  123. */
  124. int create_fifo(int nbslot, int w, int h, int imgtype)
  125. {
  126. int foo, idx;
  127. #if DEBUG_LEVEL
  128. fprintf(stderr, ">>> %s ( %d %dx%d %d )\n", __func__,
  129. nbslot, w, h, imgtype);
  130. #endif
  131. memset(&g_fifo, 0, sizeof(A_Fifo));
  132. g_fifo.nbslots = nbslot;
  133. g_fifo.slots = calloc(nbslot, sizeof(FloatImg));
  134. if (NULL==g_fifo.slots) abort();
  135. for (idx=0; idx<nbslot; idx++) {
  136. foo = fimg_create(&g_fifo.slots[idx], w, h, imgtype);
  137. if (foo) {
  138. fprintf(stderr, "%s idx %d err%d\n", __func__, idx, foo);
  139. return foo;
  140. }
  141. fimg_clear(&g_fifo.slots[idx]);
  142. }
  143. foo = fimg_create(&g_fifo.total, w, h, imgtype);
  144. g_fifo.next = 0;
  145. g_fifo.magic = MAGIC_FIFO;
  146. return 0;
  147. }
  148. /* -------------------------------------------------------------- */
  149. /*
  150. * omfg ! I've write a setter !
  151. */
  152. int set_fifo_output_format(int filetype)
  153. {
  154. #if DEBUG_LEVEL
  155. fprintf(stderr, ">>> %s ( %d )\n", __func__, filetype);
  156. #endif
  157. g_fifo.export_type = filetype;
  158. return -1;
  159. }