25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

173 satır
3.4 KiB

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include "offsets.h"
  4. typedef struct {
  5. float h, s, v;
  6. } hsvpix_t;
  7. static void HSVtoRGB(float *r, float *g, float *b, hsvpix_t pix)
  8. {
  9. int i;
  10. double f, p, q, t, h;
  11. if (pix.s == 0) {
  12. // achromatic (grey)
  13. *r = *g = *b = pix.v;
  14. return;
  15. }
  16. h = pix.h / 60; // sector 0 to 5
  17. i = floor(h);
  18. f = h - i; // factorial part of h
  19. p = pix.v * (1 - pix.s);
  20. q = pix.v * (1 - pix.s * f);
  21. t = pix.v * (1 - pix.s * (1 - f));
  22. switch (i) {
  23. case 0:
  24. *r = pix.v;
  25. *g = t;
  26. *b = p;
  27. break;
  28. case 1:
  29. *r = q;
  30. *g = pix.v;
  31. *b = p;
  32. break;
  33. case 2:
  34. *r = p;
  35. *g = pix.v;
  36. *b = t;
  37. break;
  38. case 3:
  39. *r = p;
  40. *g = q;
  41. *b = pix.v;
  42. break;
  43. case 4:
  44. *r = t;
  45. *g = p;
  46. *b = pix.v;
  47. break;
  48. default: // case 5:
  49. *r = pix.v;
  50. *g = p;
  51. *b = q;
  52. break;
  53. }
  54. }
  55. static struct {
  56. float Seathresold;
  57. float Landthresold;
  58. float Tthresold;
  59. hsvpix_t CloudTop;
  60. hsvpix_t CloudBot;
  61. hsvpix_t SeaTop;
  62. hsvpix_t SeaBot;
  63. hsvpix_t GroundTop;
  64. hsvpix_t GroundBot;
  65. } fcinfo = {
  66. 30.0, 90.0, 155.0, {
  67. 230, 0.2, 0.3}, {
  68. 230, 0.0, 1.0}, {
  69. 200.0, 0.7, 0.6}, {
  70. 240.0, 0.6, 0.4}, {
  71. 60.0, 0.6, 0.2}, {
  72. 100.0, 0.0, 0.5}
  73. };
  74. void readfconf(char *file)
  75. {
  76. FILE *fin;
  77. fin = fopen(file, "r");
  78. if (fin == NULL)
  79. return;
  80. fscanf(fin, "%g\n", &fcinfo.Seathresold);
  81. fscanf(fin, "%g\n", &fcinfo.Landthresold);
  82. fscanf(fin, "%g\n", &fcinfo.Tthresold);
  83. fscanf(fin, "%g %g %g\n", &fcinfo.CloudTop.h, &fcinfo.CloudTop.s,
  84. &fcinfo.CloudTop.v);
  85. fscanf(fin, "%g %g %g\n", &fcinfo.CloudBot.h, &fcinfo.CloudBot.s,
  86. &fcinfo.CloudBot.v);
  87. fscanf(fin, "%g %g %g\n", &fcinfo.SeaTop.h, &fcinfo.SeaTop.s,
  88. &fcinfo.SeaTop.v);
  89. fscanf(fin, "%g %g %g\n", &fcinfo.SeaBot.h, &fcinfo.SeaBot.s,
  90. &fcinfo.SeaBot.v);
  91. fscanf(fin, "%g %g %g\n", &fcinfo.GroundTop.h, &fcinfo.GroundTop.s,
  92. &fcinfo.GroundTop.v);
  93. fscanf(fin, "%g %g %g\n", &fcinfo.GroundBot.h, &fcinfo.GroundBot.s,
  94. &fcinfo.GroundBot.v);
  95. fclose(fin);
  96. };
  97. void falsecolor(double v, double t, float *r, float *g, float *b)
  98. {
  99. hsvpix_t top, bot, c;
  100. double scv, sct;
  101. if (t > fcinfo.Tthresold) {
  102. if (v < fcinfo.Seathresold) {
  103. /* sea */
  104. top = fcinfo.SeaTop, bot = fcinfo.SeaBot;
  105. scv = v / fcinfo.Seathresold;
  106. sct = (256.0-t) / (256.0-fcinfo.Tthresold);
  107. } else {
  108. /* ground */
  109. top = fcinfo.GroundTop, bot = fcinfo.GroundBot;
  110. scv =
  111. (v - fcinfo.Seathresold) / (fcinfo.Landthresold -
  112. fcinfo.Seathresold);
  113. sct = (256.0-t) / (256.0-fcinfo.Tthresold);
  114. }
  115. } else {
  116. /* clouds */
  117. top = fcinfo.CloudTop, bot = fcinfo.CloudBot;
  118. scv = v / 256.0;
  119. sct = (256.0-t) / 256.0;
  120. }
  121. c.s = top.s + sct * (bot.s - top.s);
  122. c.v = top.v + scv * (bot.v - top.v);
  123. c.h = top.h + scv * sct * (bot.h - top.h);
  124. HSVtoRGB(r, g, b, c);
  125. };
  126. void Ngvi(float **prow, int nrow)
  127. {
  128. int n;
  129. printf("GVI ... ");
  130. fflush(stdout);
  131. for (n = 0; n < nrow; n++) {
  132. float *pixelv;
  133. int i;
  134. pixelv = prow[n];
  135. for (i = 0; i < CH_WIDTH; i++) {
  136. float pv;
  137. double gvi;
  138. gvi = (pixelv[i + CHA_OFFSET]-pixelv[i + CHB_OFFSET])/(pixelv[i + CHA_OFFSET]+pixelv[i + CHB_OFFSET]);
  139. pv = (gvi+0.1)*340.0;
  140. if (pv > 255.0)
  141. pv = 255.0;
  142. if (pv < 0.0)
  143. pv = 0.0;
  144. pixelv[i + CHB_OFFSET] = pv;
  145. }
  146. }
  147. printf("Done\n");
  148. };