/src/cmp_tool/lib/common/cmp_support.c
Line | Count | Source (jump to first uncovered line) |
1 | | /** |
2 | | * @file cmp_support.c |
3 | | * @author Dominik Loidolt (dominik.loidolt@univie.ac.at) |
4 | | * @date 2019 |
5 | | * |
6 | | * @copyright GPLv2 |
7 | | * This program is free software; you can redistribute it and/or modify it |
8 | | * under the terms and conditions of the GNU General Public License, |
9 | | * version 2, as published by the Free Software Foundation. |
10 | | * |
11 | | * This program is distributed in the hope it will be useful, but WITHOUT |
12 | | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
13 | | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
14 | | * more details. |
15 | | * |
16 | | * @brief compressor support library |
17 | | * @see Data Compression User Manual PLATO-UVIE-PL-UM-0001 |
18 | | */ |
19 | | |
20 | | #include <stdint.h> |
21 | | |
22 | | #include "compiler.h" |
23 | | |
24 | | #include "cmp_support.h" |
25 | | #include "cmp_debug.h" |
26 | | #include "leon_inttypes.h" |
27 | | #include "cmp_cal_up_model.h" |
28 | | |
29 | | |
30 | | /** |
31 | | * @brief implementation of the logarithm base of floor(log2(x)) for integers |
32 | | * @note ilog_2(0) = -1 defined |
33 | | * |
34 | | * @param x input parameter |
35 | | * |
36 | | * @returns the result of floor(log2(x)) |
37 | | */ |
38 | | |
39 | | unsigned int ilog_2(uint32_t x) |
40 | 12.2k | { |
41 | 12.2k | if (!x) |
42 | 42 | return -1U; |
43 | | |
44 | 12.2k | return 31 - (unsigned int)__builtin_clz(x); |
45 | 12.2k | } |
46 | | |
47 | | |
48 | | /** |
49 | | * @brief determining if an integer is a power of 2 |
50 | | * @note 0 is incorrectly considered a power of 2 here |
51 | | * |
52 | | * @param v we want to see if v is a power of 2 |
53 | | * |
54 | | * @returns 1 if v is a power of 2, otherwise 0 |
55 | | * |
56 | | * @note see: https://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2 |
57 | | */ |
58 | | |
59 | | int is_a_pow_of_2(unsigned int v) |
60 | 1.37k | { |
61 | 1.37k | return (((v) & ((v) - 1)) == 0); |
62 | 1.37k | } |
63 | | |
64 | | |
65 | | /** |
66 | | * @brief check if the compression entity data product type is supported |
67 | | * |
68 | | * @param data_type compression entity data product type to check |
69 | | * |
70 | | * @returns non-zero if data_type is invalid; zero if data_type is valid |
71 | | */ |
72 | | |
73 | | int cmp_data_type_is_invalid(enum cmp_data_type data_type) |
74 | 11.8k | { |
75 | 11.8k | if (data_type <= DATA_TYPE_UNKNOWN || data_type > DATA_TYPE_CHUNK) |
76 | 3 | return 1; |
77 | | |
78 | 11.8k | return 0; |
79 | 11.8k | } |
80 | | |
81 | | |
82 | | /** |
83 | | * @brief check if a model mode is selected |
84 | | * |
85 | | * @param cmp_mode compression mode |
86 | | * |
87 | | * @returns 1 when the model mode is used, otherwise 0 |
88 | | */ |
89 | | |
90 | | int model_mode_is_used(enum cmp_mode cmp_mode) |
91 | 7.21k | { |
92 | 7.21k | if (cmp_mode == CMP_MODE_MODEL_ZERO || |
93 | 7.21k | cmp_mode == CMP_MODE_MODEL_MULTI) |
94 | 3.22k | return 1; |
95 | | |
96 | 3.99k | return 0; |
97 | 7.21k | } |
98 | | |
99 | | |
100 | | /** |
101 | | * @brief check if the raw mode is selected |
102 | | * |
103 | | * @param cmp_mode compression mode |
104 | | * |
105 | | * @returns 1 when the raw mode is used, otherwise 0 |
106 | | */ |
107 | | |
108 | | int raw_mode_is_used(enum cmp_mode cmp_mode) |
109 | 0 | { |
110 | 0 | if (cmp_mode == CMP_MODE_RAW) |
111 | 0 | return 1; |
112 | | |
113 | 0 | return 0; |
114 | 0 | } |
115 | | |
116 | | |
117 | | /** |
118 | | * @brief check if the data product data type is supported by the RDCU compressor |
119 | | * |
120 | | * @param data_type compression data product type |
121 | | * |
122 | | * @returns 1 when the data type is supported by the RDCU, otherwise 0 |
123 | | */ |
124 | | |
125 | | int rdcu_supported_data_type_is_used(enum cmp_data_type data_type) |
126 | 3.06k | { |
127 | 3.06k | switch (data_type) { |
128 | 330 | case DATA_TYPE_IMAGETTE: |
129 | 381 | case DATA_TYPE_IMAGETTE_ADAPTIVE: |
130 | 493 | case DATA_TYPE_SAT_IMAGETTE: |
131 | 597 | case DATA_TYPE_SAT_IMAGETTE_ADAPTIVE: |
132 | 1.02k | case DATA_TYPE_F_CAM_IMAGETTE: |
133 | 1.04k | case DATA_TYPE_F_CAM_IMAGETTE_ADAPTIVE: |
134 | 1.04k | return 1; |
135 | 2.02k | default: |
136 | 2.02k | return 0; |
137 | 3.06k | } |
138 | 3.06k | } |
139 | | |
140 | | |
141 | | /** |
142 | | * @brief check if the compression mode is supported for an ICU compression |
143 | | * |
144 | | * @param cmp_mode compression mode |
145 | | * |
146 | | * @returns 1 when the compression mode is supported, otherwise 0 |
147 | | */ |
148 | | |
149 | | int cmp_mode_is_supported(enum cmp_mode cmp_mode) |
150 | 3.64k | { |
151 | 3.64k | switch (cmp_mode) { |
152 | 1.30k | case CMP_MODE_RAW: |
153 | 1.89k | case CMP_MODE_MODEL_ZERO: |
154 | 2.31k | case CMP_MODE_DIFF_ZERO: |
155 | 3.27k | case CMP_MODE_MODEL_MULTI: |
156 | 3.64k | case CMP_MODE_DIFF_MULTI: |
157 | 3.64k | return 1; |
158 | 1 | default: |
159 | 1 | return 0; |
160 | 3.64k | } |
161 | 3.64k | } |
162 | | |
163 | | |
164 | | /** |
165 | | * @brief check if zero escape symbol mechanism mode is used |
166 | | * |
167 | | * @param cmp_mode compression mode |
168 | | * |
169 | | * @returns 1 when zero escape symbol mechanism is set, otherwise 0 |
170 | | */ |
171 | | |
172 | | int zero_escape_mech_is_used(enum cmp_mode cmp_mode) |
173 | 532 | { |
174 | 532 | if (cmp_mode == CMP_MODE_MODEL_ZERO || |
175 | 532 | cmp_mode == CMP_MODE_DIFF_ZERO) |
176 | 532 | return 1; |
177 | | |
178 | 0 | return 0; |
179 | 532 | } |
180 | | |
181 | | |
182 | | /** |
183 | | * @brief check if multi escape symbol mechanism mode is used |
184 | | * |
185 | | * @param cmp_mode compression mode |
186 | | * |
187 | | * @returns 1 when multi escape symbol mechanism is set, otherwise 0 |
188 | | */ |
189 | | |
190 | | int multi_escape_mech_is_used(enum cmp_mode cmp_mode) |
191 | 1.46k | { |
192 | 1.46k | if (cmp_mode == CMP_MODE_MODEL_MULTI || |
193 | 1.46k | cmp_mode == CMP_MODE_DIFF_MULTI) |
194 | 928 | return 1; |
195 | | |
196 | 532 | return 0; |
197 | 1.46k | } |
198 | | |
199 | | |
200 | | /** |
201 | | * @brief check if an imagette compression data type is used |
202 | | * @note adaptive imagette compression data types included |
203 | | * |
204 | | * @param data_type compression data type |
205 | | * |
206 | | * @returns 1 when data_type is an imagette data type, otherwise 0 |
207 | | */ |
208 | | |
209 | | int cmp_imagette_data_type_is_used(enum cmp_data_type data_type) |
210 | 2.78k | { |
211 | 2.78k | return rdcu_supported_data_type_is_used(data_type); |
212 | 2.78k | } |
213 | | |
214 | | |
215 | | /** |
216 | | * @brief check if an adaptive imagette compression data type is used |
217 | | * |
218 | | * @param data_type compression data type |
219 | | * |
220 | | * @returns 1 when data_type is an adaptive imagette data type, otherwise 0 |
221 | | */ |
222 | | |
223 | | int cmp_ap_imagette_data_type_is_used(enum cmp_data_type data_type) |
224 | 0 | { |
225 | 0 | switch (data_type) { |
226 | 0 | case DATA_TYPE_IMAGETTE_ADAPTIVE: |
227 | 0 | case DATA_TYPE_SAT_IMAGETTE_ADAPTIVE: |
228 | 0 | case DATA_TYPE_F_CAM_IMAGETTE_ADAPTIVE: |
229 | 0 | return 1; |
230 | 0 | default: |
231 | 0 | return 0; |
232 | 0 | } |
233 | 0 | } |
234 | | |
235 | | |
236 | | /** |
237 | | * @brief check if a flux/center of brightness compression data type is used |
238 | | * |
239 | | * @param data_type compression data type |
240 | | * |
241 | | * @returns 1 when data_type is a flux/center of brightness data type, otherwise 0 |
242 | | */ |
243 | | |
244 | | int cmp_fx_cob_data_type_is_used(enum cmp_data_type data_type) |
245 | 3.42k | { |
246 | 3.42k | switch (data_type) { |
247 | 280 | case DATA_TYPE_S_FX: |
248 | 532 | case DATA_TYPE_S_FX_EFX: |
249 | 806 | case DATA_TYPE_S_FX_NCOB: |
250 | 1.19k | case DATA_TYPE_S_FX_EFX_NCOB_ECOB: |
251 | 1.39k | case DATA_TYPE_L_FX: |
252 | 1.83k | case DATA_TYPE_L_FX_EFX: |
253 | 1.99k | case DATA_TYPE_L_FX_NCOB: |
254 | 2.20k | case DATA_TYPE_L_FX_EFX_NCOB_ECOB: |
255 | 2.54k | case DATA_TYPE_F_FX: |
256 | 2.63k | case DATA_TYPE_F_FX_EFX: |
257 | 2.69k | case DATA_TYPE_F_FX_NCOB: |
258 | 2.80k | case DATA_TYPE_F_FX_EFX_NCOB_ECOB: |
259 | 2.80k | return 1; |
260 | 617 | default: |
261 | 617 | return 0; |
262 | 3.42k | } |
263 | 3.42k | } |
264 | | |
265 | | |
266 | | /** |
267 | | * @brief check if an auxiliary science compression data type is used |
268 | | * |
269 | | * @param data_type compression data type |
270 | | * |
271 | | * @returns 1 when data_type is an auxiliary science data type, otherwise 0 |
272 | | */ |
273 | | |
274 | | int cmp_aux_data_type_is_used(enum cmp_data_type data_type) |
275 | 617 | { |
276 | 617 | switch (data_type) { |
277 | 51 | case DATA_TYPE_OFFSET: |
278 | 278 | case DATA_TYPE_BACKGROUND: |
279 | 380 | case DATA_TYPE_SMEARING: |
280 | 490 | case DATA_TYPE_F_CAM_OFFSET: |
281 | 617 | case DATA_TYPE_F_CAM_BACKGROUND: |
282 | 617 | return 1; |
283 | 0 | default: |
284 | 0 | return 0; |
285 | 617 | } |
286 | 617 | } |
287 | | |
288 | | |
289 | | /** |
290 | | * @brief get the maximum valid spill threshold value for a imagette |
291 | | * compression in diff or model mode |
292 | | * |
293 | | * @param golomb_par Golomb parameter |
294 | | * |
295 | | * @returns the highest still valid spill threshold value for a diff of model |
296 | | * mode compression; 0 if golomb_par is invalid |
297 | | */ |
298 | | |
299 | | uint32_t cmp_ima_max_spill(unsigned int golomb_par) |
300 | 0 | { |
301 | | /* the RDCU can only generate 16 bit long code words -> lower max spill needed */ |
302 | 0 | const uint32_t LUT_MAX_RDCU[MAX_IMA_GOLOMB_PAR+1] = { 0, 8, 22, 35, 48, |
303 | 0 | 60, 72, 84, 96, 107, 118, 129, 140, 151, 162, 173, 184, 194, |
304 | 0 | 204, 214, 224, 234, 244, 254, 264, 274, 284, 294, 304, 314, 324, |
305 | 0 | 334, 344, 353, 362, 371, 380, 389, 398, 407, 416, 425, 434, 443, |
306 | 0 | 452, 461, 470, 479, 488, 497, 506, 515, 524, 533, 542, 551, 560, |
307 | 0 | 569, 578, 587, 596, 605, 614, 623 }; |
308 | |
|
309 | 0 | if (golomb_par >= ARRAY_SIZE(LUT_MAX_RDCU)) |
310 | 0 | return 0; |
311 | | |
312 | 0 | return LUT_MAX_RDCU[golomb_par]; |
313 | 0 | } |
314 | | |
315 | | |
316 | | /** |
317 | | * @brief get the maximum valid spill threshold value for a non-imagette compression |
318 | | * in diff or model mode |
319 | | * |
320 | | * @param cmp_par compression parameter |
321 | | * |
322 | | * @returns the highest still valid spill threshold value for diff or model |
323 | | * mode compression; 0 if the cmp_par is not valid |
324 | | */ |
325 | | |
326 | | uint32_t cmp_icu_max_spill(unsigned int cmp_par) |
327 | 3.44k | { |
328 | | /* the ICU compressor can generate code words with a length of maximal 32 bits. */ |
329 | 3.44k | unsigned int const max_cw_bits = 32; |
330 | 3.44k | unsigned int const cutoff = (0x2U << (ilog_2(cmp_par) & 0x1FU)) - cmp_par; |
331 | 3.44k | unsigned int const max_n_sym_offset = (max_cw_bits/2) - 1; |
332 | | |
333 | 3.44k | if (!cmp_par || cmp_par > MAX_NON_IMA_GOLOMB_PAR) |
334 | 42 | return 0; |
335 | | |
336 | 3.40k | return ((max_cw_bits-1-ilog_2(cmp_par))*cmp_par) + cutoff |
337 | 3.40k | - max_n_sym_offset - 1; |
338 | 3.44k | } |
339 | | |
340 | | |
341 | | /** |
342 | | * @brief calculate the need bytes to hold a bitstream |
343 | | * |
344 | | * @param cmp_size_bit compressed data size, measured in bits |
345 | | * |
346 | | * @returns the size in bytes to store the hole bitstream |
347 | | */ |
348 | | |
349 | | unsigned int cmp_bit_to_byte(unsigned int cmp_size_bit) |
350 | 0 | { |
351 | 0 | return (cmp_size_bit + 7) / 8; |
352 | 0 | } |
353 | | |
354 | | |
355 | | /** |
356 | | * @brief check if the compression data type, compression mode, model value and |
357 | | * the lossy rounding parameters are invalid for a RDCU or ICU compression |
358 | | * |
359 | | * @param cfg pointer to a compression configuration containing the compression |
360 | | * data product type, compression mode, model value and the rounding parameters |
361 | | * |
362 | | * @returns 0 if the compression data type, compression mode, model value and |
363 | | * the lossy rounding parameters are valid for an RDCU or ICU compression, |
364 | | * non-zero if parameters are invalid |
365 | | */ |
366 | | |
367 | | int cmp_cfg_gen_par_is_invalid(const struct cmp_cfg *cfg) |
368 | 3.64k | { |
369 | 3.64k | int cfg_invalid = 0; |
370 | | |
371 | 3.64k | if (!cfg) |
372 | 0 | return 1; |
373 | | |
374 | 3.64k | if (cmp_data_type_is_invalid(cfg->data_type)) { |
375 | 0 | debug_print("Error: selected compression data type is not supported."); |
376 | 0 | cfg_invalid++; |
377 | 0 | } |
378 | | |
379 | 3.64k | if (!cmp_mode_is_supported(cfg->cmp_mode)) { |
380 | 1 | debug_print("Error: selected cmp_mode: %i is not supported.", cfg->cmp_mode); |
381 | 1 | cfg_invalid++; |
382 | 1 | } |
383 | | |
384 | 3.64k | if (model_mode_is_used(cfg->cmp_mode)) { |
385 | 1.54k | if (cfg->model_value > MAX_MODEL_VALUE) { |
386 | 1 | debug_print("Error: selected model_value: %" PRIu32 " is invalid. The largest supported value is: %u.", |
387 | 1 | cfg->model_value, MAX_MODEL_VALUE); |
388 | 1 | cfg_invalid++; |
389 | 1 | } |
390 | 1.54k | } |
391 | | |
392 | 3.64k | if (cfg->round > MAX_ICU_ROUND) { |
393 | 3 | debug_print("Error: selected lossy parameter: %" PRIu32 " is not supported. The largest supported value is: %" PRIu32 ".", |
394 | 3 | cfg->round, MAX_ICU_ROUND); |
395 | 3 | cfg_invalid++; |
396 | 3 | } |
397 | | |
398 | | #ifdef SKIP_CMP_PAR_CHECK |
399 | | return 0; |
400 | | #endif |
401 | 3.64k | return cfg_invalid; |
402 | 3.64k | } |
403 | | |
404 | | |
405 | | /** |
406 | | * @brief check if the combination of the different compression parameters is invalid |
407 | | * |
408 | | * @param cmp_par compression parameter |
409 | | * @param spill spillover threshold parameter |
410 | | * @param cmp_mode compression mode |
411 | | * @param par_name string describing the use of the compression par. for |
412 | | * debug messages (can be NULL) |
413 | | * |
414 | | * @returns 0 if the parameter combination is valid, otherwise the combination is invalid |
415 | | */ |
416 | | |
417 | | static int cmp_pars_are_invalid(uint32_t cmp_par, uint32_t spill, enum cmp_mode cmp_mode, |
418 | | const char *par_name MAYBE_UNUSED) |
419 | 6.78k | { |
420 | 6.78k | int cfg_invalid = 0; |
421 | | |
422 | 6.78k | switch (cmp_mode) { |
423 | 3.34k | case CMP_MODE_RAW: |
424 | | /* no checks needed */ |
425 | 3.34k | break; |
426 | 728 | case CMP_MODE_DIFF_ZERO: |
427 | 1.16k | case CMP_MODE_DIFF_MULTI: |
428 | 1.79k | case CMP_MODE_MODEL_ZERO: |
429 | 3.44k | case CMP_MODE_MODEL_MULTI: |
430 | 3.44k | if (cmp_par < MIN_NON_IMA_GOLOMB_PAR || cmp_par > MAX_NON_IMA_GOLOMB_PAR) { |
431 | 42 | debug_print("Error: The selected %s compression parameter: %" PRIu32 " is not supported in the selected compression mode. The compression parameter has to be between [%" PRIu32 ", %" PRIu32 "] in this mode.", |
432 | 42 | par_name, cmp_par, MIN_NON_IMA_GOLOMB_PAR, MAX_NON_IMA_GOLOMB_PAR); |
433 | 42 | cfg_invalid++; |
434 | 42 | } |
435 | 3.44k | if (spill < MIN_NON_IMA_SPILL) { |
436 | 31 | debug_print("Error: The selected %s spillover threshold value: %" PRIu32 " is too small. The smallest possible spillover value is: %" PRIu32 ".", |
437 | 31 | par_name, spill, MIN_NON_IMA_SPILL); |
438 | 31 | cfg_invalid++; |
439 | 31 | } |
440 | 3.44k | if (spill > cmp_icu_max_spill(cmp_par)) { |
441 | 47 | debug_print("Error: The selected %s spillover threshold value: %" PRIu32 " is too large for the selected %s compression parameter: %" PRIu32 ". The largest possible spillover value in the selected compression mode is: %" PRIu32 ".", |
442 | 47 | par_name, spill, par_name, cmp_par, cmp_icu_max_spill(cmp_par)); |
443 | 47 | cfg_invalid++; |
444 | 47 | } |
445 | | |
446 | 3.44k | break; |
447 | 0 | default: |
448 | 0 | debug_print("Error: selected cmp_mode: %i is not supported.", cmp_mode); |
449 | 0 | cfg_invalid++; |
450 | 0 | break; |
451 | 6.78k | } |
452 | | |
453 | | #ifdef SKIP_CMP_PAR_CHECK |
454 | | return 0; |
455 | | #endif |
456 | 6.78k | return cfg_invalid; |
457 | 6.78k | } |
458 | | |
459 | | |
460 | | /** |
461 | | * @brief check if the imagette specific compression parameters are invalid |
462 | | * |
463 | | * @param cfg pointer to a compressor configuration |
464 | | * |
465 | | * @returns 0 if the imagette specific parameters are valid, otherwise invalid |
466 | | */ |
467 | | |
468 | | int cmp_cfg_imagette_is_invalid(const struct cmp_cfg *cfg) |
469 | 384 | { |
470 | 384 | int cfg_invalid = 0; |
471 | | |
472 | 384 | if (!cfg) |
473 | 0 | return 1; |
474 | | |
475 | 384 | if (!cmp_imagette_data_type_is_used(cfg->data_type)) { |
476 | 0 | debug_print("Error: The compression data type is not an imagette compression data type."); |
477 | 0 | cfg_invalid++; |
478 | 0 | } |
479 | | |
480 | 384 | cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_imagette, cfg->spill_imagette, |
481 | 384 | cfg->cmp_mode, "imagette"); |
482 | 384 | return cfg_invalid; |
483 | 384 | } |
484 | | |
485 | | |
486 | | /** |
487 | | * @brief get needed compression parameter pairs for a flux/center of brightness |
488 | | * data type |
489 | | * |
490 | | * @param data_type a flux/center of brightness data type |
491 | | * @param par pointer to a structure containing flux/COB compression |
492 | | * parameters pairs |
493 | | * |
494 | | * @returns 0 on success and sets the needed compression parameter pairs in the |
495 | | * par struct, otherwise error |
496 | | */ |
497 | | |
498 | | int cmp_cfg_fx_cob_get_need_pars(enum cmp_data_type data_type, struct fx_cob_par *par) |
499 | 1.40k | { |
500 | 1.40k | if (!par) |
501 | 0 | return -1; |
502 | | |
503 | 1.40k | par->exp_flags = 0; |
504 | 1.40k | par->fx = 0; |
505 | 1.40k | par->ncob = 0; |
506 | 1.40k | par->efx = 0; |
507 | 1.40k | par->ecob = 0; |
508 | 1.40k | par->fx_cob_variance = 0; |
509 | | |
510 | | /* flux parameter is needed for every fx_cob data_type */ |
511 | 1.40k | par->fx = 1; |
512 | | |
513 | 1.40k | switch (data_type) { |
514 | 140 | case DATA_TYPE_S_FX: |
515 | 140 | par->exp_flags = 1; |
516 | 140 | break; |
517 | 126 | case DATA_TYPE_S_FX_EFX: |
518 | 126 | par->exp_flags = 1; |
519 | 126 | par->efx = 1; |
520 | 126 | break; |
521 | 137 | case DATA_TYPE_S_FX_NCOB: |
522 | 137 | par->exp_flags = 1; |
523 | 137 | par->ncob = 1; |
524 | 137 | break; |
525 | 192 | case DATA_TYPE_S_FX_EFX_NCOB_ECOB: |
526 | 192 | par->exp_flags = 1; |
527 | 192 | par->ncob = 1; |
528 | 192 | par->efx = 1; |
529 | 192 | par->ecob = 1; |
530 | 192 | break; |
531 | 102 | case DATA_TYPE_L_FX: |
532 | 102 | par->exp_flags = 1; |
533 | 102 | par->fx_cob_variance = 1; |
534 | 102 | break; |
535 | 220 | case DATA_TYPE_L_FX_EFX: |
536 | 220 | par->exp_flags = 1; |
537 | 220 | par->efx = 1; |
538 | 220 | par->fx_cob_variance = 1; |
539 | 220 | break; |
540 | 79 | case DATA_TYPE_L_FX_NCOB: |
541 | 79 | par->exp_flags = 1; |
542 | 79 | par->ncob = 1; |
543 | 79 | par->fx_cob_variance = 1; |
544 | 79 | break; |
545 | 106 | case DATA_TYPE_L_FX_EFX_NCOB_ECOB: |
546 | 106 | par->exp_flags = 1; |
547 | 106 | par->ncob = 1; |
548 | 106 | par->efx = 1; |
549 | 106 | par->ecob = 1; |
550 | 106 | par->fx_cob_variance = 1; |
551 | 106 | break; |
552 | 170 | case DATA_TYPE_F_FX: |
553 | 170 | break; |
554 | 43 | case DATA_TYPE_F_FX_EFX: |
555 | 43 | par->efx = 1; |
556 | 43 | break; |
557 | 30 | case DATA_TYPE_F_FX_NCOB: |
558 | 30 | par->ncob = 1; |
559 | 30 | break; |
560 | 58 | case DATA_TYPE_F_FX_EFX_NCOB_ECOB: |
561 | 58 | par->ncob = 1; |
562 | 58 | par->efx = 1; |
563 | 58 | par->ecob = 1; |
564 | 58 | break; |
565 | 0 | default: |
566 | 0 | return -1; |
567 | 1.40k | } |
568 | 1.40k | return 0; |
569 | 1.40k | } |
570 | | |
571 | | |
572 | | /** |
573 | | * @brief check if the flux/center of brightness specific compression parameters |
574 | | * are invalid |
575 | | * |
576 | | * @param cfg pointer to the compressor configuration |
577 | | * |
578 | | * @returns 0 if the flux/center of brightness specific parameters are valid, otherwise invalid |
579 | | */ |
580 | | |
581 | | int cmp_cfg_fx_cob_is_invalid(const struct cmp_cfg *cfg) |
582 | 1.40k | { |
583 | 1.40k | int cfg_invalid = 0; |
584 | 1.40k | struct fx_cob_par needed_pars; |
585 | | |
586 | 1.40k | if (!cfg) |
587 | 0 | return 1; |
588 | | |
589 | 1.40k | if (!cmp_fx_cob_data_type_is_used(cfg->data_type)) { |
590 | 0 | debug_print("Error: The compression data type is not a flux/center of brightness compression data type."); |
591 | 0 | cfg_invalid++; |
592 | 0 | } |
593 | | |
594 | 1.40k | cmp_cfg_fx_cob_get_need_pars(cfg->data_type, &needed_pars); |
595 | | |
596 | 1.40k | if (needed_pars.fx) /* this is always true because every flux/center of brightness data type contains a flux parameter */ |
597 | 1.40k | cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_fx, cfg->spill_fx, |
598 | 1.40k | cfg->cmp_mode, "flux"); |
599 | 1.40k | if (needed_pars.exp_flags) |
600 | 1.10k | cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_exp_flags, cfg->spill_exp_flags, |
601 | 1.10k | cfg->cmp_mode, "exposure flags"); |
602 | 1.40k | if (needed_pars.ncob) |
603 | 602 | cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_ncob, cfg->spill_ncob, |
604 | 602 | cfg->cmp_mode, "center of brightness"); |
605 | 1.40k | if (needed_pars.efx) |
606 | 745 | cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_efx, cfg->spill_efx, |
607 | 745 | cfg->cmp_mode, "extended flux"); |
608 | 1.40k | if (needed_pars.ecob) |
609 | 356 | cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_ecob, cfg->spill_ecob, |
610 | 356 | cfg->cmp_mode, "extended center of brightness"); |
611 | 1.40k | if (needed_pars.fx_cob_variance) |
612 | 507 | cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_fx_cob_variance, |
613 | 507 | cfg->spill_fx_cob_variance, cfg->cmp_mode, "flux/COB variance"); |
614 | | |
615 | 1.40k | return cfg_invalid; |
616 | 1.40k | } |
617 | | |
618 | | |
619 | | /** |
620 | | * @brief check if the auxiliary science specific compression parameters are invalid |
621 | | * |
622 | | * @param cfg pointer to the compressor configuration |
623 | | * |
624 | | * @returns 0 if the auxiliary science specific parameters are valid, otherwise |
625 | | * invalid |
626 | | */ |
627 | | |
628 | | int cmp_cfg_aux_is_invalid(const struct cmp_cfg *cfg) |
629 | 617 | { |
630 | 617 | int cfg_invalid = 0; |
631 | | |
632 | 617 | if (!cfg) |
633 | 0 | return 1; |
634 | | |
635 | 617 | switch (cfg->data_type) { |
636 | 51 | case DATA_TYPE_OFFSET: |
637 | 161 | case DATA_TYPE_F_CAM_OFFSET: |
638 | 161 | cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_offset_mean, cfg->spill_offset_mean, |
639 | 161 | cfg->cmp_mode, "offset mean"); |
640 | 161 | cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_offset_variance, cfg->spill_offset_variance, |
641 | 161 | cfg->cmp_mode, "offset variance"); |
642 | 161 | break; |
643 | 227 | case DATA_TYPE_BACKGROUND: |
644 | 354 | case DATA_TYPE_F_CAM_BACKGROUND: |
645 | 354 | cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_background_mean, cfg->spill_background_mean, |
646 | 354 | cfg->cmp_mode, "background mean"); |
647 | 354 | cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_background_variance, cfg->spill_background_variance, |
648 | 354 | cfg->cmp_mode, "background variance"); |
649 | 354 | cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_background_pixels_error, cfg->spill_background_pixels_error, |
650 | 354 | cfg->cmp_mode, "background outlier pixls num"); |
651 | 354 | break; |
652 | 102 | case DATA_TYPE_SMEARING: |
653 | 102 | cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_smearing_mean, cfg->spill_smearing_mean, |
654 | 102 | cfg->cmp_mode, "smearing mean"); |
655 | 102 | cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_smearing_variance, cfg->spill_smearing_variance, |
656 | 102 | cfg->cmp_mode, "smearing variance"); |
657 | 102 | cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_smearing_pixels_error, cfg->spill_smearing_pixels_error, |
658 | 102 | cfg->cmp_mode, "smearing outlier pixls num"); |
659 | 102 | break; |
660 | 0 | default: |
661 | 0 | debug_print("Error: The compression data type is not an auxiliary science compression data type."); |
662 | 0 | cfg_invalid++; |
663 | 617 | } |
664 | 617 | return cfg_invalid; |
665 | 617 | } |
666 | | |
667 | | |
668 | | /** |
669 | | * @brief print the cmp_info structure |
670 | | * |
671 | | * @param info pointer to a compressor information contains information of an |
672 | | * executed RDCU compression |
673 | | */ |
674 | | |
675 | | void print_cmp_info(const struct cmp_info *info) |
676 | 0 | { |
677 | 0 | if (!info) { |
678 | 0 | debug_print("Pointer to the compressor information is NULL."); |
679 | 0 | return; |
680 | 0 | } |
681 | | |
682 | 0 | debug_print("cmp_mode_used: %" PRIu32 "", info->cmp_mode_used); |
683 | 0 | debug_print("spill_used: %" PRIu32 "", info->spill_used); |
684 | 0 | debug_print("golomb_par_used: %" PRIu32 "", info->golomb_par_used); |
685 | 0 | debug_print("samples_used: %" PRIu32 "", info->samples_used); |
686 | 0 | debug_print("cmp_size: %" PRIu32 "", info->cmp_size); |
687 | 0 | debug_print("ap1_cmp_size: %" PRIu32 "", info->ap1_cmp_size); |
688 | 0 | debug_print("ap2_cmp_size: %" PRIu32 "", info->ap2_cmp_size); |
689 | 0 | debug_print("rdcu_new_model_adr_used: 0x%06"PRIX32"", info->rdcu_new_model_adr_used); |
690 | 0 | debug_print("rdcu_cmp_adr_used: 0x%06"PRIX32"", info->rdcu_cmp_adr_used); |
691 | 0 | debug_print("model_value_used: %u", info->model_value_used); |
692 | 0 | debug_print("round_used: %u", info->round_used); |
693 | 0 | debug_print("cmp_err: %#X", info->cmp_err); |
694 | 0 | } |