Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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