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.

fcolor.c 3.1 KiB

4 jaren geleden
20 jaren geleden
20 jaren geleden
20 jaren geleden
20 jaren geleden
20 jaren geleden
20 jaren geleden
4 jaren geleden
4 jaren geleden
20 jaren geleden
4 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * This file is part of Aptdec.
  3. * Copyright (c) 2004-2009 Thierry Leconte (F4DWV), Xerbo (xerbo@protonmail.com) 2019-2020
  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;
  24. } rgb_t;
  25. extern rgb_t RGBcomposite(rgb_t top, float top_a, rgb_t bottom, float bottom_a);
  26. static struct {
  27. rgb_t Sea, Land, Cloud;
  28. int Seaintensity, Seaoffset;
  29. int Landthreshold, Landintensity, Landoffset;
  30. int Cloudthreshold, Cloudintensity;
  31. } fcinfo = {
  32. {28, 44, 95},
  33. {23, 78, 37},
  34. {240, 250, 255},
  35. 50, 10,
  36. 24, 34, 14,
  37. 141, 114
  38. };
  39. // Read the config file
  40. int readfcconf(char *file) {
  41. FILE *fin;
  42. fin = fopen(file, "r");
  43. if (fin == NULL)
  44. return 0;
  45. fscanf(fin, "%g %g %g\n", &fcinfo.Sea.r, &fcinfo.Sea.g, &fcinfo.Sea.b);
  46. fscanf(fin, "%g %g %g\n", &fcinfo.Land.r, &fcinfo.Land.g, &fcinfo.Land.b);
  47. fscanf(fin, "%g %g %g\n", &fcinfo.Cloud.r, &fcinfo.Cloud.g, &fcinfo.Cloud.b);
  48. fscanf(fin, "%d\n", &fcinfo.Seaintensity);
  49. fscanf(fin, "%d\n", &fcinfo.Seaoffset);
  50. fscanf(fin, "%d\n", &fcinfo.Landthreshold);
  51. fscanf(fin, "%d\n", &fcinfo.Landintensity);
  52. fscanf(fin, "%d\n", &fcinfo.Landoffset);
  53. fscanf(fin, "%d\n", &fcinfo.Cloudthreshold);
  54. fscanf(fin, "%d", &fcinfo.Cloudintensity);
  55. fclose(fin);
  56. return 1;
  57. };
  58. rgb_t falsecolor(float vis, float temp){
  59. rgb_t buffer;
  60. float land = 0.0, sea, cloud;
  61. // Calculate intensity of sea
  62. sea = CLIP(vis+fcinfo.Seaoffset, 0, fcinfo.Seaintensity)/fcinfo.Seaintensity;
  63. // Land
  64. if(vis > fcinfo.Landthreshold)
  65. land = CLIP(vis-fcinfo.Landoffset, 0, fcinfo.Landintensity)/fcinfo.Landintensity;
  66. // Composite land on sea
  67. buffer = RGBcomposite(fcinfo.Land, land, fcinfo.Sea, sea);
  68. // Composite clouds on top
  69. cloud = CLIP(temp-fcinfo.Cloudthreshold, 0, fcinfo.Cloudintensity)/fcinfo.Cloudintensity;
  70. buffer = RGBcomposite(fcinfo.Cloud, cloud, buffer, 1);
  71. return buffer;
  72. }
  73. // GVI (global vegetation index) false color
  74. void Ngvi(float **prow, int nrow) {
  75. printf("Computing GVI false color");
  76. for (int n = 0; n < nrow; n++) {
  77. float *pixelv = prow[n];
  78. for (int i = 0; i < CH_WIDTH; i++) {
  79. double gvi = (pixelv[i + CHA_OFFSET] - pixelv[i + CHB_OFFSET])/
  80. (pixelv[i + CHA_OFFSET] + pixelv[i + CHB_OFFSET]);
  81. gvi = (gvi + 0.1) * 340.0;
  82. pixelv[i + CHB_OFFSET] = CLIP(gvi, 0, 255);
  83. }
  84. }
  85. printf("\nDone\n");
  86. };