SatDump 2.0.0-alpha-520736c72
Loading...
Searching...
No Matches
xrit_file.h
1#pragma once
2
3#include "libs/others/strptime.h"
4#include <cstdint>
5#include <ctime>
6#include <map>
7#include <string>
8#include <vector>
9
10namespace satdump
11{
12 namespace xrit
13 {
15 struct PrimaryHeader
16 {
17 static constexpr int TYPE = 0;
18
19 uint8_t type;
20 uint16_t record_length;
21 uint8_t file_type_code;
22 uint32_t total_header_length;
23 uint64_t data_field_length;
24
25 PrimaryHeader(uint8_t *data)
26 {
27 type = data[0];
28 record_length = data[1] << 8 | data[2];
29 file_type_code = data[3];
30 total_header_length = (uint32_t)data[4] << 24 | (uint32_t)data[5] << 16 | (uint32_t)data[6] << 8 | (uint32_t)data[7];
31 data_field_length = (uint64_t)data[8] << 56 | (uint64_t)data[9] << 48 | (uint64_t)data[10] << 40 | (uint64_t)data[11] << 32 | (uint64_t)data[12] << 24 | (uint64_t)data[13] << 16 |
32 (uint64_t)data[14] << 8 | (uint64_t)data[15];
33 }
34 };
35
36 struct ImageStructureRecord
37 {
38 static constexpr int TYPE = 1;
39
40 uint8_t type;
41 uint16_t record_length;
42 uint8_t bit_per_pixel;
43 uint16_t columns_count;
44 uint16_t lines_count;
45 uint8_t compression_flag;
46
47 ImageStructureRecord(uint8_t *data)
48 {
49 type = data[0];
50 record_length = data[1] << 8 | data[2];
51 bit_per_pixel = data[3];
52 columns_count = data[4] << 8 | data[5];
53 lines_count = data[6] << 8 | data[7];
54 compression_flag = data[8];
55 }
56 };
57
58 struct ImageNavigationRecord
59 {
60 static constexpr int TYPE = 2;
61
62 uint8_t type;
63 uint16_t record_length;
64 std::string projection_name;
65 int32_t column_scaling_factor;
66 int32_t line_scaling_factor;
67 double column_offset;
68 double line_offset;
69
70 // Pre-computed projection information
71 double column_scalar;
72 double line_scalar;
73
74 ImageNavigationRecord(uint8_t *data)
75 {
76 type = data[0];
77 record_length = data[1] << 8 | data[2];
78 projection_name = std::string((char *)&data[3], (char *)&data[3 + 32]);
79 column_scaling_factor = data[35] << 24 | data[36] << 16 | data[37] << 8 | data[38];
80 line_scaling_factor = data[39] << 24 | data[40] << 16 | data[41] << 8 | data[42];
81 column_offset = (int32_t)(data[43] << 24 | data[44] << 16 | data[45] << 8 | data[46]);
82 line_offset = (int32_t)(data[47] << 24 | data[48] << 16 | data[49] << 8 | data[50]);
83 column_scalar = line_scalar = 0.0;
84 }
85 };
86
87 struct ImageDataFunctionRecord
88 {
89 static constexpr int TYPE = 3;
90
91 uint8_t type;
92 uint16_t record_length;
93 std::string datas;
94
95 ImageDataFunctionRecord(uint8_t *data)
96 {
97 type = data[0];
98 record_length = data[1] << 8 | data[2];
99 datas = std::string((char *)&data[3], (char *)&data[3 + record_length - 3]);
100 }
101 };
102
103 struct AnnotationRecord
104 {
105 static constexpr int TYPE = 4;
106
107 uint8_t type;
108 uint16_t record_length;
109 std::string annotation_text;
110
111 AnnotationRecord(uint8_t *data)
112 {
113 type = data[0];
114 record_length = data[1] << 8 | data[2];
115 annotation_text.insert(annotation_text.end(), &data[3], &data[record_length]);
116 }
117 };
118
119 struct TimeStampRecord
120 {
121 static constexpr int TYPE = 5;
122
123 uint8_t type;
124 uint16_t record_length;
125 uint16_t days;
126 uint32_t milliseconds_of_day;
127
128 time_t timestamp;
129
130 TimeStampRecord(uint8_t *data)
131 {
132 type = data[0];
133 record_length = data[1] << 8 | data[2];
134 uint16_t days = data[3] << 8 | data[4];
135 uint32_t milliseconds_of_day = data[5] << 24 | data[6] << 16 | data[7] << 8 | data[8];
136
137 timestamp = (days - 4383) * 86400 + milliseconds_of_day;
138 }
139 };
140
141
142 struct XRITFile
143 {
144 int vcid = -1;
145 int last_tracked_counter = -1;
146
147 bool file_in_progress = false;
148 bool header_parsed = false;
149
150 std::map<int, int> custom_flags;
151
152 std::string filename;
153 int total_header_length;
154 std::map<int, int> all_headers;
155 std::vector<uint8_t> lrit_data;
156
157 template <typename T>
158 T getHeader()
159 {
160 if constexpr (std::is_same_v<T, PrimaryHeader>)
161 return PrimaryHeader(&lrit_data[0]);
162 else
163 return T(&lrit_data[all_headers[T::TYPE]]);
164 }
165
166 template <typename T>
167 bool hasHeader()
168 {
169 return all_headers.count(T::TYPE);
170 }
171
172 void parseHeaders(bool safe = false);
173 };
174 } // namespace xrit
175} // namespace satdump
Definition xrit_file.h:16
Definition xrit_file.h:143