Não pode escolher mais do que 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.
 
 
 
 
 

173 linhas
5.9 KiB

  1. /*
  2. * aptdec - A lightweight FOSS (NOAA) APT decoder
  3. * Copyright (C) 2004-2009 Thierry Leconte (F4DWV) 2019-2023 Xerbo (xerbo@protonmail.com)
  4. * Copyright (C) 2021 Jon Beniston (M7RCE)
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #ifndef APTDEC_H_
  20. #define APTDEC_H_
  21. #include <stddef.h>
  22. #include <stdint.h>
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. #if defined(__GNUC__) && (__GNUC__ >= 4)
  27. # define APTDEC_API __attribute__((visibility("default")))
  28. #elif defined(_MSC_VER)
  29. # ifdef APTDEC_API_EXPORT
  30. # define APTDEC_API __declspec(dllexport)
  31. # else
  32. # define APTDEC_API __declspec(dllimport)
  33. # endif
  34. #else
  35. # define APTDEC_API
  36. #endif
  37. // Height of a single telemetry wedge
  38. #define APTDEC_WEDGE_HEIGHT 8
  39. // Numbers of wedges in a frame
  40. #define APTDEC_FRAME_WEDGES 16
  41. // Height of a telemetry frame
  42. #define APTDEC_FRAME_LEN (APTDEC_WEDGE_HEIGHT * APTDEC_FRAME_WEDGES)
  43. // Width of the overall image
  44. #define APTDEC_IMG_WIDTH 2080
  45. // Width of sync marker
  46. #define APTDEC_SYNC_WIDTH 39
  47. // Width of space view
  48. #define APTDEC_SPC_WIDTH 47
  49. // Width of telemetry
  50. #define APTDEC_TELEMETRY_WIDTH 45
  51. // Width of a single video channel
  52. #define APTDEC_CH_WIDTH 909
  53. // Offset to channel A video data
  54. #define APTDEC_CHA_OFFSET (APTDEC_SYNC_WIDTH + APTDEC_SPC_WIDTH)
  55. // Offset to channel B video data
  56. #define APTDEC_CHB_OFFSET (APTDEC_SYNC_WIDTH + APTDEC_SPC_WIDTH + APTDEC_CH_WIDTH + APTDEC_TELEMETRY_WIDTH + APTDEC_SYNC_WIDTH + APTDEC_SPC_WIDTH)
  57. // Number of rows needed for aptdec_normalize to (reliably) work
  58. #define APTDEC_NORMALIZE_ROWS (APTDEC_FRAME_LEN * 2)
  59. // Maximum amount of samples that will be requested from aptdec_callback_t
  60. #define APTDEC_BUFFER_SIZE 16384
  61. // Channel 1: visible (0.58-0.68 um)
  62. // Channel 2: near-IR (0.725-1.0 um)
  63. // Channel 3A: near-IR (1.58-1.64 um)
  64. // Channel 3B: mid-infrared (3.55-3.93 um)
  65. // Channel 4: thermal-infrared (10.3-11.3 um)
  66. // Channel 5: thermal-infrared (11.5-12.5 um)
  67. typedef enum aptdec_channel {
  68. AVHRR_CHANNEL_UNKNOWN,
  69. AVHRR_CHANNEL_1,
  70. AVHRR_CHANNEL_2,
  71. AVHRR_CHANNEL_3A,
  72. AVHRR_CHANNEL_4,
  73. AVHRR_CHANNEL_5,
  74. AVHRR_CHANNEL_3B
  75. } avhrr_channel_t;
  76. typedef enum aptdec_satellite {
  77. NOAA15,
  78. NOAA18,
  79. NOAA19
  80. } aptdec_satellite_t;
  81. typedef struct aptdec_image {
  82. uint8_t *data; // Image data
  83. size_t rows; // Number of rows
  84. // Telemetry
  85. aptdec_satellite_t satellite;
  86. avhrr_channel_t ch[2];
  87. float space_view[2];
  88. float telemetry[2][16];
  89. } aptdec_image_t;
  90. typedef struct aptdec_rgb {
  91. uint8_t r, g, b;
  92. } aptdec_rgb_t;
  93. typedef struct aptdec_region {
  94. size_t offset;
  95. size_t width;
  96. } aptdec_region_t;
  97. typedef struct aptdec aptdec_t;
  98. // Callback function to get samples
  99. // `context` is the same as passed to aptdec_getrow
  100. typedef size_t (*aptdec_callback_t)(float *samples, size_t count, void *context);
  101. // Clone an aptdec_image_t struct
  102. // Useful for calibration
  103. APTDEC_API aptdec_image_t aptdec_image_clone(aptdec_image_t img);
  104. // Returns version of libaptdec in git tag format
  105. // i.e. v2.0.0 or v2.0.0-1-xxxxxx
  106. APTDEC_API char *aptdec_get_version(void);
  107. // Create and destroy libaptdec instances
  108. // If aptdec_init fails it will return NULL
  109. APTDEC_API aptdec_t *aptdec_init(float sample_rate);
  110. APTDEC_API void aptdec_free(aptdec_t *aptdec);
  111. // Normalize and quantize raw image data
  112. // Data is arranged so that each row starts at APTDEC_IMG_WIDTH*y
  113. APTDEC_API aptdec_image_t aptdec_normalize(const float *data, size_t rows, aptdec_satellite_t satellite, int *error);
  114. // Get an entire row of pixels
  115. // Requires that `row` has enough space to store APTDEC_IMG_WIDTH*2
  116. // Returns 0 when `callback` return value != count
  117. APTDEC_API int aptdec_getrow(aptdec_t *aptdec, float *row, aptdec_callback_t callback, void *context);
  118. // Calibrate channels
  119. APTDEC_API int aptdec_calibrate_thermal(aptdec_image_t *img, aptdec_region_t region);
  120. APTDEC_API int aptdec_calibrate_visible(aptdec_image_t *img, aptdec_region_t region);
  121. APTDEC_API void aptdec_denoise (aptdec_image_t *img, aptdec_region_t region);
  122. APTDEC_API void aptdec_flip (aptdec_image_t *img, aptdec_region_t region);
  123. APTDEC_API void aptdec_stretch (aptdec_image_t *img, aptdec_region_t region);
  124. APTDEC_API void aptdec_equalize(aptdec_image_t *img, aptdec_region_t region);
  125. APTDEC_API int aptdec_crop (aptdec_image_t *img);
  126. APTDEC_API void aptdec_strip (aptdec_image_t* img);
  127. // Composite two RGB values as layers, in most cases bottom_a will be 1.0f
  128. APTDEC_API aptdec_rgb_t aptdec_composite_rgb(aptdec_rgb_t top, float top_a, aptdec_rgb_t bottom, float bottom_a);
  129. // Apply a gradient such as aptdec_temperature_gradient
  130. // If gradient is less than 256 elements it is the callers responsibility
  131. // that `val` does not exceed the length of the gradient
  132. APTDEC_API aptdec_rgb_t aptdec_gradient(const uint32_t *gradient, uint8_t val);
  133. static const aptdec_region_t APTDEC_REGION_CHA = { APTDEC_CHA_OFFSET, APTDEC_CH_WIDTH };
  134. static const aptdec_region_t APTDEC_REGION_CHB = { APTDEC_CHB_OFFSET, APTDEC_CH_WIDTH };
  135. static const aptdec_region_t APTDEC_REGION_CHA_FULL = { 0, APTDEC_IMG_WIDTH/2 };
  136. static const aptdec_region_t APTDEC_REGION_CHB_FULL = { APTDEC_IMG_WIDTH/2, APTDEC_IMG_WIDTH/2 };
  137. static const aptdec_region_t APTDEC_REGION_FULL = { 0, APTDEC_IMG_WIDTH };
  138. APTDEC_API extern const uint32_t aptdec_temperature_gradient[256];
  139. APTDEC_API extern const uint32_t aptdec_precipitation_gradient[58];
  140. #ifdef __cplusplus
  141. }
  142. #endif
  143. #endif