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.

110 lines
2.5 KiB

8 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
8 months ago
1 year ago
  1. /*
  2. * FloatImg library from tTh - really ugly code inside
  3. */
  4. #include <stdio.h>
  5. #include <stdint.h>
  6. #include "../floatimg.h"
  7. /* -------------------------------------------------------------- */
  8. /* global vars exported from main
  9. */
  10. extern int verbosity;
  11. /* -------------------------------------------------------------- */
  12. /*
  13. * parameter mix is between 0.0 and 1.0 but other
  14. * values give sometime good vibrations.
  15. */
  16. int fimg_mix_rgb_gray(FloatImg *img, float mix)
  17. {
  18. int x, y, p;
  19. float gr;
  20. if (FIMG_TYPE_RGB != img->type) {
  21. fprintf(stderr, "%s bad type\n", __func__);
  22. return -6;
  23. }
  24. for (y=0; y<img->height; y++) {
  25. p = y * img->width; /* first pixel of the row */
  26. for (x=0; x<img->width; x++) {
  27. gr = (img->R[p] + img->G[p] + img->R[p]) / 3.0;
  28. img->R[p] = ((gr * mix) + (img->R[p] * (1.0-mix))) / 2.0;
  29. img->G[p] = ((gr * mix) + (img->G[p] * (1.0-mix))) / 2.0;
  30. img->B[p] = ((gr * mix) + (img->B[p] * (1.0-mix))) / 2.0;
  31. p++; /* next pixel in the row */
  32. }
  33. }
  34. return 0;
  35. }
  36. /* -------------------------------------------------------------- */
  37. /*
  38. * The third parameter was a six value array with min and max
  39. * values maybe computed by the 'fimg_get_minmax_rgb' function.
  40. */
  41. int fimg_shift_to_zero(FloatImg *s, FloatImg *d, float coefs[6])
  42. {
  43. int sz, idx;
  44. if (FIMG_TYPE_RGB != s->type) {
  45. fprintf(stderr, "%s bad type\n", __func__);
  46. return -6;
  47. }
  48. sz = s->width * s->height;
  49. for (idx=0; idx<sz; idx++) {
  50. d->R[idx] = s->R[idx] - coefs[0];
  51. d->G[idx] = s->G[idx] - coefs[2];
  52. d->B[idx] = s->B[idx] - coefs[4];
  53. }
  54. return 0;
  55. }
  56. /* -------------------------------------------------------------- */
  57. /*
  58. * I think that this function is fully buggy, and need
  59. * more explanations.
  60. */
  61. int fimg_auto_shift_to_zero(FloatImg *src, FloatImg *dst)
  62. {
  63. float coefs[6];
  64. int foo;
  65. float minima = 1e7; /* magic value ? */
  66. #if DEBUG_LEVEL
  67. fprintf(stderr, ">>> %s ( %p %p )\n", __func__, src, dst);
  68. #endif
  69. if (FIMG_TYPE_RGB != src->type) {
  70. fprintf(stderr, "%s: bad image type %d\n", __func__, src->type);
  71. return -6;
  72. }
  73. foo = fimg_get_minmax_rgb(src, coefs);
  74. if (foo) {
  75. fprintf(stderr, "%s: err %d get minmax\n", __func__, foo);
  76. return foo;
  77. }
  78. /* crude hack for now */
  79. if (coefs[0] < minima) minima = coefs[0];
  80. if (coefs[2] < minima) minima = coefs[2];
  81. if (coefs[4] < minima) minima = coefs[4];
  82. coefs[0] = coefs[2] = coefs[4] = minima;
  83. foo = fimg_shift_to_zero(src, dst, coefs);
  84. if (foo) {
  85. fprintf(stderr, "%s WTF? %d\n", __func__, foo);
  86. return foo;
  87. }
  88. return 0;
  89. }
  90. /* -------------------------------------------------------------- */