Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

124 linhas
3.6 KiB

  1. /*
  2. * This file is part of Aptdec.
  3. * Copyright (c) 2004-2009 Thierry Leconte (F4DWV), Xerbo (xerbo@protonmail.com) 2019
  4. *
  5. * Aptdec is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. *
  18. */
  19. #include <stdio.h>
  20. #include <math.h>
  21. #include "offsets.h"
  22. typedef struct {
  23. float r, g, b, a;
  24. } rgba;
  25. static struct {
  26. rgba Sea;
  27. rgba Land;
  28. rgba Cloud;
  29. int Seaintensity;
  30. float Seaoffset;
  31. int Landthreshold;
  32. int Landintensity;
  33. int Landoffset;
  34. int Cloudthreshold;
  35. int Cloudintensity;
  36. } fcinfo = {
  37. {28, 44, 95, 1},
  38. {23, 78, 37, 1},
  39. {240, 250, 255, 1},
  40. 50,
  41. 0.5,
  42. 24,
  43. 34,
  44. 14,
  45. 141,
  46. 114
  47. };
  48. // Read the config file
  49. void readfcconf(char *file) {
  50. FILE *fin;
  51. fin = fopen(file, "r");
  52. if (fin == NULL)
  53. return;
  54. fscanf(fin, "%g %g %g\n", &fcinfo.Sea.r, &fcinfo.Sea.g, &fcinfo.Sea.b);
  55. fscanf(fin, "%g %g %g\n", &fcinfo.Land.r, &fcinfo.Land.g, &fcinfo.Land.b);
  56. fscanf(fin, "%g %g %g\n", &fcinfo.Cloud.r, &fcinfo.Cloud.g, &fcinfo.Cloud.b);
  57. fscanf(fin, "%d\n", &fcinfo.Seaintensity);
  58. fscanf(fin, "%g\n", &fcinfo.Seaoffset);
  59. fscanf(fin, "%d\n", &fcinfo.Landthreshold);
  60. fscanf(fin, "%d\n", &fcinfo.Landintensity);
  61. fscanf(fin, "%d\n", &fcinfo.Landoffset);
  62. fscanf(fin, "%d\n", &fcinfo.Cloudthreshold);
  63. fscanf(fin, "%d", &fcinfo.Cloudintensity);
  64. fclose(fin);
  65. };
  66. // RGBA Composite
  67. rgba composite(rgba top, rgba bottom){
  68. rgba composite;
  69. composite.r = MCOMPOSITE(top.r, top.a, bottom.r, bottom.a);
  70. composite.g = MCOMPOSITE(top.g, top.a, bottom.g, bottom.a);
  71. composite.b = MCOMPOSITE(top.b, top.a, bottom.b, bottom.a);
  72. composite.a = bottom.a == 1 || top.a == 1 ? 1 : (top.a+bottom.a)/2;
  73. return composite;
  74. }
  75. void falsecolor(float vis, float temp, float *r, float *g, float *b){
  76. rgba buffer;
  77. fcinfo.Land.a = 0.0f; fcinfo.Sea.a = 0.0f;
  78. // Calculate intensity of sea and land
  79. fcinfo.Sea.a = CLIP(vis, 0, 20)/fcinfo.Seaintensity + fcinfo.Seaoffset;
  80. if(vis > fcinfo.Landthreshold) fcinfo.Land.a = CLIP(vis-fcinfo.Landoffset, 0, fcinfo.Landintensity)/fcinfo.Landintensity;
  81. // Composite land on top of sea
  82. buffer = composite(fcinfo.Land, fcinfo.Sea);
  83. buffer.a = 1.0f;
  84. // Composite clouds on top
  85. fcinfo.Cloud.a = CLIP(temp-fcinfo.Cloudthreshold, 0, fcinfo.Cloudintensity)/fcinfo.Cloudintensity;
  86. buffer = composite(fcinfo.Cloud, buffer);
  87. *r = buffer.r;
  88. *g = buffer.g;
  89. *b = buffer.b;
  90. }
  91. // GVI (global vegetation index) false color
  92. void Ngvi(float **prow, int nrow) {
  93. printf("Computing GVI false color\n");
  94. fflush(stdout);
  95. for (int n = 0; n < nrow; n++) {
  96. float *pixelv = prow[n];
  97. for (int i = 0; i < CH_WIDTH; i++) {
  98. float pv;
  99. double gvi;
  100. gvi = (pixelv[i + CHA_OFFSET] - pixelv[i + CHB_OFFSET]) / (pixelv[i + CHA_OFFSET] + pixelv[i + CHB_OFFSET]);
  101. pv = (gvi + 0.1) * 340.0;
  102. pv = CLIP(pv, 0, 255);
  103. pixelv[i + CHB_OFFSET] = pv;
  104. }
  105. }
  106. };