Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

před 1 rokem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 APT_WEDGE_HEIGHT 8
  39. // Numbers of wedges in a frame
  40. #define APT_FRAME_WEDGES 16
  41. // Height of a telemetry frame
  42. #define APT_FRAME_LEN (APT_WEDGE_HEIGHT * APT_FRAME_WEDGES)
  43. // Width of the overall image
  44. #define APT_IMG_WIDTH 2080
  45. // Width of sync marker
  46. #define APT_SYNC_WIDTH 39
  47. // Width of space view
  48. #define APT_SPC_WIDTH 47
  49. // Width of telemetry
  50. #define APT_TELEMETRY_WIDTH 45
  51. // Width of a single video channel
  52. #define APT_CH_WIDTH 909
  53. // Offset to channel A video data
  54. #define APT_CHA_OFFSET (APT_SYNC_WIDTH + APT_SPC_WIDTH)
  55. // Offset to channel B video data
  56. #define APT_CHB_OFFSET (APT_SYNC_WIDTH + APT_SPC_WIDTH + APT_CH_WIDTH + APT_TELEMETRY_WIDTH + APT_SYNC_WIDTH + APT_SPC_WIDTH)
  57. // Number of rows needed for apt_normalize to (reliably) work
  58. #define APTDEC_NORMALIZE_ROWS (APT_FRAME_LEN * 2)
  59. // Channel 1: visible (0.58-0.68 um)
  60. // Channel 2: near-IR (0.725-1.0 um)
  61. // Channel 3A: near-IR (1.58-1.64 um)
  62. // Channel 3B: mid-infrared (3.55-3.93 um)
  63. // Channel 4: thermal-infrared (10.3-11.3 um)
  64. // Channel 5: thermal-infrared (11.5-12.5 um)
  65. typedef enum apt_channel {
  66. AVHRR_CHANNEL_UNKNOWN,
  67. AVHRR_CHANNEL_1,
  68. AVHRR_CHANNEL_2,
  69. AVHRR_CHANNEL_3A,
  70. AVHRR_CHANNEL_4,
  71. AVHRR_CHANNEL_5,
  72. AVHRR_CHANNEL_3B
  73. } avhrr_channel_t;
  74. typedef enum apt_satellite {
  75. NOAA15,
  76. NOAA18,
  77. NOAA19
  78. } apt_satellite_t;
  79. typedef struct {
  80. uint8_t *data; // Image data
  81. size_t rows; // Number of rows
  82. // Telemetry
  83. apt_satellite_t satellite;
  84. avhrr_channel_t ch[2];
  85. float space_view[2];
  86. float telemetry[2][16];
  87. } apt_image_t;
  88. typedef struct {
  89. uint8_t r, g, b;
  90. } apt_rgb_t;
  91. typedef struct {
  92. size_t offset;
  93. size_t width;
  94. } apt_region_t;
  95. typedef struct aptdec_t aptdec_t;
  96. // Callback function to get samples
  97. // `context` is the same as passed to aptdec_getrow
  98. typedef size_t (*aptdec_callback_t)(float *samples, size_t count, void *context);
  99. // Clone an apt_image_t struct
  100. // Useful for calibration
  101. apt_image_t apt_image_clone(apt_image_t img);
  102. // Returns version of libaptdec in git tag format
  103. // i.e. v2.0.0 or v2.0.0-1-xxxxxx
  104. APTDEC_API char *aptdec_get_version(void);
  105. // Create and destroy libaptdec instances
  106. // If aptdec_init fails it will return NULL
  107. APTDEC_API aptdec_t *aptdec_init(float sample_rate);
  108. APTDEC_API void aptdec_free(aptdec_t *apt);
  109. // Normalize and quantize raw image data
  110. // Data is arranged so that each row starts at APT_IMG_WIDTH*y
  111. APTDEC_API apt_image_t apt_normalize(const float *data, size_t rows, apt_satellite_t satellite, int *error);
  112. // Get an entire row of pixels
  113. // Requires that `row` has enough space to store APT_IMG_WIDTH*2
  114. // Returns 0 when `callback` return value != count
  115. APTDEC_API int aptdec_getrow(aptdec_t *apt, float *row, aptdec_callback_t callback, void *context);
  116. // Calibrate channels
  117. APTDEC_API int apt_calibrate_thermal(apt_image_t *img, apt_region_t region);
  118. APTDEC_API int apt_calibrate_visible(apt_image_t *img, apt_region_t region);
  119. APTDEC_API void apt_denoise (apt_image_t *img, apt_region_t region);
  120. APTDEC_API void apt_flip (apt_image_t *img, apt_region_t region);
  121. APTDEC_API void apt_stretch (apt_image_t *img, apt_region_t region);
  122. APTDEC_API void apt_equalize(apt_image_t *img, apt_region_t region);
  123. APTDEC_API int apt_crop (apt_image_t *img);
  124. // Composite two RGB values as layers, in most cases bottom_a will be 1.0f
  125. APTDEC_API apt_rgb_t apt_composite_rgb(apt_rgb_t top, float top_a, apt_rgb_t bottom, float bottom_a);
  126. // Apply a gradient such as temperature_gradient
  127. // If gradient is less than 256 elements it is the callers responsibility
  128. // that `val` does not exceed the length of the gradient
  129. APTDEC_API apt_rgb_t apt_gradient(const uint32_t *gradient, uint8_t val);
  130. static const apt_region_t APT_REGION_CHA = { APT_CHA_OFFSET, APT_CH_WIDTH };
  131. static const apt_region_t APT_REGION_CHB = { APT_CHB_OFFSET, APT_CH_WIDTH };
  132. static const apt_region_t APT_REGION_CHA_FULL = { 0, APT_IMG_WIDTH/2 };
  133. static const apt_region_t APT_REGION_CHB_FULL = { APT_IMG_WIDTH/2, APT_IMG_WIDTH/2 };
  134. static const apt_region_t APT_REGION_FULL = { 0, APT_IMG_WIDTH };
  135. extern const uint32_t temperature_gradient[256];
  136. extern const uint32_t precipitation_gradient[58];
  137. #ifdef __cplusplus
  138. }
  139. #endif
  140. #endif