25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

107 lines
2.8 KiB

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include "offsets.h"
  4. typedef struct {
  5. float r, g, b, a;
  6. } rgba;
  7. static struct {
  8. rgba Sea;
  9. rgba Land;
  10. rgba Cloud;
  11. int Seaintensity;
  12. float Seaoffset;
  13. int Landthreshold;
  14. int Landintensity;
  15. int Landoffset;
  16. int Cloudthreshold;
  17. int Cloudintensity;
  18. } fcinfo = {
  19. {28, 44, 95, 1},
  20. {23, 78, 37, 1},
  21. {240, 250, 255, 1},
  22. 50,
  23. 0.5,
  24. 24,
  25. 34,
  26. 14,
  27. 141,
  28. 114
  29. };
  30. // Read the config file
  31. void readfcconf(char *file) {
  32. FILE *fin;
  33. fin = fopen(file, "r");
  34. if (fin == NULL)
  35. return;
  36. fscanf(fin, "%g %g %g\n", &fcinfo.Sea.r, &fcinfo.Sea.g, &fcinfo.Sea.b);
  37. fscanf(fin, "%g %g %g\n", &fcinfo.Land.r, &fcinfo.Land.g, &fcinfo.Land.b);
  38. fscanf(fin, "%g %g %g\n", &fcinfo.Cloud.r, &fcinfo.Cloud.g, &fcinfo.Cloud.b);
  39. fscanf(fin, "%d\n", &fcinfo.Seaintensity);
  40. fscanf(fin, "%g\n", &fcinfo.Seaoffset);
  41. fscanf(fin, "%d\n", &fcinfo.Landthreshold);
  42. fscanf(fin, "%d\n", &fcinfo.Landintensity);
  43. fscanf(fin, "%d\n", &fcinfo.Landoffset);
  44. fscanf(fin, "%d\n", &fcinfo.Cloudthreshold);
  45. fscanf(fin, "%d", &fcinfo.Cloudintensity);
  46. fclose(fin);
  47. };
  48. // RGBA Composite
  49. rgba composite(rgba top, rgba bottom){
  50. rgba composite;
  51. composite.r = MCOMPOSITE(top.r, top.a, bottom.r, bottom.a);
  52. composite.g = MCOMPOSITE(top.g, top.a, bottom.g, bottom.a);
  53. composite.b = MCOMPOSITE(top.b, top.a, bottom.b, bottom.a);
  54. composite.a = bottom.a == 1 || top.a == 1 ? 1 : (top.a+bottom.a)/2;
  55. return composite;
  56. }
  57. void falsecolor(float vis, float temp, float *r, float *g, float *b){
  58. rgba buffer;
  59. fcinfo.Land.a = 0; fcinfo.Sea.a = 0;
  60. // Calculate intensity of sea and land
  61. fcinfo.Sea.a = CLIP(vis, 0, 20)/fcinfo.Seaintensity + fcinfo.Seaoffset;
  62. if(vis > fcinfo.Landthreshold) fcinfo.Land.a = CLIP(vis-fcinfo.Landoffset, 0, fcinfo.Landintensity)/fcinfo.Landintensity;
  63. // Composite land on top of sea
  64. buffer = composite(fcinfo.Land, fcinfo.Sea);
  65. buffer.a = 1;
  66. // Composite clouds on top
  67. fcinfo.Cloud.a = CLIP(temp-fcinfo.Cloudthreshold, 0, fcinfo.Cloudintensity)/fcinfo.Cloudintensity;
  68. buffer = composite(fcinfo.Cloud, buffer);
  69. *r = buffer.r;
  70. *g = buffer.g;
  71. *b = buffer.b;
  72. }
  73. // GVI (global vegetation index) false color
  74. void Ngvi(float **prow, int nrow) {
  75. printf("Computing GVI false color\n");
  76. fflush(stdout);
  77. for (int n = 0; n < nrow; n++) {
  78. float *pixelv;
  79. pixelv = prow[n];
  80. for (int i = 0; i < CH_WIDTH; i++) {
  81. float pv;
  82. double gvi;
  83. gvi = (pixelv[i + CHA_OFFSET] - pixelv[i + CHB_OFFSET]) / (pixelv[i + CHA_OFFSET] + pixelv[i + CHB_OFFSET]);
  84. pv = (gvi + 0.1) * 340.0;
  85. pv = CLIP(pv, 0, 255);
  86. pixelv[i + CHB_OFFSET] = pv;
  87. }
  88. }
  89. };