Coverage Report

Created: 2025-06-15 00:57

/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
949k
{
41
949k
  if (!x)
42
3.21k
    return -1U;
43
44
946k
  return 31 - (unsigned int)__builtin_clz(x);
45
949k
}
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
196k
{
61
196k
  return (((v) & ((v) - 1)) == 0);
62
196k
}
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
288k
{
75
288k
  if (data_type <= DATA_TYPE_UNKNOWN || data_type > DATA_TYPE_CHUNK)
76
34
    return 1;
77
78
288k
  return 0;
79
288k
}
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
683k
{
92
683k
  if (cmp_mode == CMP_MODE_MODEL_ZERO ||
93
683k
      cmp_mode == CMP_MODE_MODEL_MULTI)
94
386k
    return 1;
95
96
296k
  return 0;
97
683k
}
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
122k
{
110
122k
  if (cmp_mode == CMP_MODE_RAW)
111
52.4k
    return 1;
112
113
69.6k
  return 0;
114
122k
}
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
231k
{
127
231k
  switch (data_type) {
128
14.7k
  case DATA_TYPE_IMAGETTE:
129
14.8k
  case DATA_TYPE_IMAGETTE_ADAPTIVE:
130
77.6k
  case DATA_TYPE_SAT_IMAGETTE:
131
77.7k
  case DATA_TYPE_SAT_IMAGETTE_ADAPTIVE:
132
81.8k
  case DATA_TYPE_F_CAM_IMAGETTE:
133
81.8k
  case DATA_TYPE_F_CAM_IMAGETTE_ADAPTIVE:
134
81.8k
    return 1;
135
149k
  default:
136
149k
    return 0;
137
231k
  }
138
231k
}
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
195k
{
151
195k
  switch (cmp_mode) {
152
64.2k
  case CMP_MODE_RAW:
153
129k
  case CMP_MODE_MODEL_ZERO:
154
154k
  case CMP_MODE_DIFF_ZERO:
155
181k
  case CMP_MODE_MODEL_MULTI:
156
195k
  case CMP_MODE_DIFF_MULTI:
157
195k
    return 1;
158
5
  default:
159
5
    return 0;
160
195k
  }
161
195k
}
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
50.2k
{
174
50.2k
  if (cmp_mode == CMP_MODE_MODEL_ZERO ||
175
50.2k
      cmp_mode == CMP_MODE_DIFF_ZERO)
176
37.3k
    return 1;
177
178
12.8k
  return 0;
179
50.2k
}
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
23.4k
{
192
23.4k
  if (cmp_mode == CMP_MODE_MODEL_MULTI ||
193
23.4k
      cmp_mode == CMP_MODE_DIFF_MULTI)
194
4.59k
    return 1;
195
196
18.8k
  return 0;
197
23.4k
}
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
231k
{
211
231k
  return rdcu_supported_data_type_is_used(data_type);
212
231k
}
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
66
{
225
66
  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
66
  default:
231
66
    return 0;
232
66
  }
233
66
}
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
266k
{
246
266k
  switch (data_type) {
247
136k
  case DATA_TYPE_S_FX:
248
147k
  case DATA_TYPE_S_FX_EFX:
249
166k
  case DATA_TYPE_S_FX_NCOB:
250
179k
  case DATA_TYPE_S_FX_EFX_NCOB_ECOB:
251
207k
  case DATA_TYPE_L_FX:
252
214k
  case DATA_TYPE_L_FX_EFX:
253
220k
  case DATA_TYPE_L_FX_NCOB:
254
233k
  case DATA_TYPE_L_FX_EFX_NCOB_ECOB:
255
233k
  case DATA_TYPE_F_FX:
256
233k
  case DATA_TYPE_F_FX_EFX:
257
233k
  case DATA_TYPE_F_FX_NCOB:
258
233k
  case DATA_TYPE_F_FX_EFX_NCOB_ECOB:
259
233k
    return 1;
260
33.0k
  default:
261
33.0k
    return 0;
262
266k
  }
263
266k
}
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
10.5k
{
276
10.5k
  switch (data_type) {
277
747
  case DATA_TYPE_OFFSET:
278
1.30k
  case DATA_TYPE_BACKGROUND:
279
2.53k
  case DATA_TYPE_SMEARING:
280
3.67k
  case DATA_TYPE_F_CAM_OFFSET:
281
10.5k
  case DATA_TYPE_F_CAM_BACKGROUND:
282
10.5k
    return 1;
283
0
  default:
284
0
    return 0;
285
10.5k
  }
286
10.5k
}
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
1.65k
{
301
  /* the RDCU can only generate 16 bit long code words -> lower max spill needed */
302
1.65k
  const uint32_t LUT_MAX_RDCU[MAX_IMA_GOLOMB_PAR+1] = { 0, 8, 22, 35, 48,
303
1.65k
    60, 72, 84, 96, 107, 118, 129, 140, 151, 162, 173, 184, 194,
304
1.65k
    204, 214, 224, 234, 244, 254, 264, 274, 284, 294, 304, 314, 324,
305
1.65k
    334, 344, 353, 362, 371, 380, 389, 398, 407, 416, 425, 434, 443,
306
1.65k
    452, 461, 470, 479, 488, 497, 506, 515, 524, 533, 542, 551, 560,
307
1.65k
    569, 578, 587, 596, 605, 614, 623 };
308
309
1.65k
  if (golomb_par >= ARRAY_SIZE(LUT_MAX_RDCU))
310
0
    return 0;
311
312
1.65k
  return LUT_MAX_RDCU[golomb_par];
313
1.65k
}
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
340k
{
328
  /* the ICU compressor can generate code words with a length of maximal 32 bits. */
329
340k
  unsigned int const max_cw_bits = 32;
330
340k
  unsigned int const cutoff = (0x2U << (ilog_2(cmp_par) & 0x1FU)) - cmp_par;
331
340k
  unsigned int const max_n_sym_offset = (max_cw_bits/2) - 1;
332
333
340k
  if (!cmp_par || cmp_par > MAX_NON_IMA_GOLOMB_PAR)
334
7.32k
    return 0;
335
336
333k
  return ((max_cw_bits-1-ilog_2(cmp_par))*cmp_par) + cutoff
337
333k
    - max_n_sym_offset - 1;
338
340k
}
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
113k
{
351
113k
  return (cmp_size_bit + 7) / 8;
352
113k
}
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
194k
{
369
194k
  int cfg_invalid = 0;
370
371
194k
  if (!cfg)
372
0
    return 1;
373
374
194k
  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
194k
  if (!cmp_mode_is_supported(cfg->cmp_mode)) {
380
4
    debug_print("Error: selected cmp_mode: %i is not supported.", cfg->cmp_mode);
381
4
    cfg_invalid++;
382
4
  }
383
384
194k
  if (model_mode_is_used(cfg->cmp_mode)) {
385
91.6k
    if (cfg->model_value > MAX_MODEL_VALUE) {
386
17
      debug_print("Error: selected model_value: %" PRIu32 " is invalid. The largest supported value is: %u.",
387
17
            cfg->model_value, MAX_MODEL_VALUE);
388
17
      cfg_invalid++;
389
17
    }
390
91.6k
  }
391
392
194k
  if (cfg->round > MAX_ICU_ROUND) {
393
12
    debug_print("Error: selected lossy parameter: %" PRIu32 " is not supported. The largest supported value is: %" PRIu32 ".",
394
12
          cfg->round, MAX_ICU_ROUND);
395
12
    cfg_invalid++;
396
12
  }
397
398
#ifdef SKIP_CMP_PAR_CHECK
399
  return 0;
400
#endif
401
194k
  return cfg_invalid;
402
194k
}
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
453k
{
420
453k
  int cfg_invalid = 0;
421
422
453k
  switch (cmp_mode) {
423
141k
  case CMP_MODE_RAW:
424
    /* no checks needed */
425
141k
    break;
426
71.2k
  case CMP_MODE_DIFF_ZERO:
427
108k
  case CMP_MODE_DIFF_MULTI:
428
265k
  case CMP_MODE_MODEL_ZERO:
429
312k
  case CMP_MODE_MODEL_MULTI:
430
312k
    if (cmp_par < MIN_NON_IMA_GOLOMB_PAR || cmp_par > MAX_NON_IMA_GOLOMB_PAR) {
431
383
      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
383
            par_name, cmp_par, MIN_NON_IMA_GOLOMB_PAR, MAX_NON_IMA_GOLOMB_PAR);
433
383
      cfg_invalid++;
434
383
    }
435
312k
    if (spill < MIN_NON_IMA_SPILL) {
436
377
      debug_print("Error: The selected %s spillover threshold value: %" PRIu32 " is too small. The smallest possible spillover value is: %" PRIu32 ".",
437
377
            par_name, spill, MIN_NON_IMA_SPILL);
438
377
      cfg_invalid++;
439
377
    }
440
312k
    if (spill > cmp_icu_max_spill(cmp_par)) {
441
63
      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
63
            par_name, spill, par_name, cmp_par, cmp_icu_max_spill(cmp_par));
443
63
      cfg_invalid++;
444
63
    }
445
446
312k
    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
453k
  }
452
453
#ifdef SKIP_CMP_PAR_CHECK
454
  return 0;
455
#endif
456
453k
  return cfg_invalid;
457
453k
}
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
40.7k
{
470
40.7k
  int cfg_invalid = 0;
471
472
40.7k
  if (!cfg)
473
0
    return 1;
474
475
40.7k
  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
40.7k
  cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_imagette, cfg->spill_imagette,
481
40.7k
              cfg->cmp_mode, "imagette");
482
40.7k
  return cfg_invalid;
483
40.7k
}
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
116k
{
500
116k
  if (!par)
501
0
    return -1;
502
503
116k
  par->exp_flags = 0;
504
116k
  par->fx = 0;
505
116k
  par->ncob = 0;
506
116k
  par->efx = 0;
507
116k
  par->ecob = 0;
508
116k
  par->fx_cob_variance = 0;
509
510
  /* flux parameter is needed for every fx_cob data_type */
511
116k
  par->fx = 1;
512
513
116k
  switch (data_type) {
514
68.0k
  case DATA_TYPE_S_FX:
515
68.0k
    par->exp_flags = 1;
516
68.0k
    break;
517
5.94k
  case DATA_TYPE_S_FX_EFX:
518
5.94k
    par->exp_flags = 1;
519
5.94k
    par->efx = 1;
520
5.94k
    break;
521
9.49k
  case DATA_TYPE_S_FX_NCOB:
522
9.49k
    par->exp_flags = 1;
523
9.49k
    par->ncob = 1;
524
9.49k
    break;
525
6.52k
  case DATA_TYPE_S_FX_EFX_NCOB_ECOB:
526
6.52k
    par->exp_flags = 1;
527
6.52k
    par->ncob = 1;
528
6.52k
    par->efx = 1;
529
6.52k
    par->ecob = 1;
530
6.52k
    break;
531
13.9k
  case DATA_TYPE_L_FX:
532
13.9k
    par->exp_flags = 1;
533
13.9k
    par->fx_cob_variance = 1;
534
13.9k
    break;
535
3.42k
  case DATA_TYPE_L_FX_EFX:
536
3.42k
    par->exp_flags = 1;
537
3.42k
    par->efx = 1;
538
3.42k
    par->fx_cob_variance = 1;
539
3.42k
    break;
540
2.69k
  case DATA_TYPE_L_FX_NCOB:
541
2.69k
    par->exp_flags = 1;
542
2.69k
    par->ncob = 1;
543
2.69k
    par->fx_cob_variance = 1;
544
2.69k
    break;
545
6.50k
  case DATA_TYPE_L_FX_EFX_NCOB_ECOB:
546
6.50k
    par->exp_flags = 1;
547
6.50k
    par->ncob = 1;
548
6.50k
    par->efx = 1;
549
6.50k
    par->ecob = 1;
550
6.50k
    par->fx_cob_variance = 1;
551
6.50k
    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
116k
  }
568
116k
  return 0;
569
116k
}
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
116k
{
583
116k
  int cfg_invalid = 0;
584
116k
  struct fx_cob_par needed_pars;
585
586
116k
  if (!cfg)
587
0
    return 1;
588
589
116k
  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
116k
  cmp_cfg_fx_cob_get_need_pars(cfg->data_type, &needed_pars);
595
596
116k
  if (needed_pars.fx) /* this is always true because every flux/center of brightness data type contains a flux parameter */
597
116k
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_fx, cfg->spill_fx,
598
116k
                cfg->cmp_mode, "flux");
599
116k
  if (needed_pars.exp_flags)
600
116k
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_exp_flags, cfg->spill_exp_flags,
601
116k
      cfg->cmp_mode, "exposure flags");
602
116k
  if (needed_pars.ncob)
603
25.3k
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_ncob, cfg->spill_ncob,
604
25.3k
      cfg->cmp_mode, "center of brightness");
605
116k
  if (needed_pars.efx)
606
22.5k
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_efx, cfg->spill_efx,
607
22.5k
      cfg->cmp_mode, "extended flux");
608
116k
  if (needed_pars.ecob)
609
13.0k
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_ecob, cfg->spill_ecob,
610
13.0k
      cfg->cmp_mode, "extended center of brightness");
611
116k
  if (needed_pars.fx_cob_variance)
612
26.6k
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_fx_cob_variance,
613
26.6k
      cfg->spill_fx_cob_variance, cfg->cmp_mode, "flux/COB variance");
614
615
116k
  return cfg_invalid;
616
116k
}
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
33.0k
{
630
33.0k
  int cfg_invalid = 0;
631
632
33.0k
  if (!cfg)
633
0
    return 1;
634
635
33.0k
  switch (cfg->data_type) {
636
3.95k
  case DATA_TYPE_OFFSET:
637
6.79k
  case DATA_TYPE_F_CAM_OFFSET:
638
6.79k
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_offset_mean, cfg->spill_offset_mean,
639
6.79k
        cfg->cmp_mode, "offset mean");
640
6.79k
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_offset_variance, cfg->spill_offset_variance,
641
6.79k
        cfg->cmp_mode, "offset variance");
642
6.79k
    break;
643
2.30k
  case DATA_TYPE_BACKGROUND:
644
18.0k
  case DATA_TYPE_F_CAM_BACKGROUND:
645
18.0k
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_background_mean, cfg->spill_background_mean,
646
18.0k
        cfg->cmp_mode, "background mean");
647
18.0k
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_background_variance, cfg->spill_background_variance,
648
18.0k
        cfg->cmp_mode, "background variance");
649
18.0k
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_background_pixels_error, cfg->spill_background_pixels_error,
650
18.0k
        cfg->cmp_mode, "background outlier pixls num");
651
18.0k
    break;
652
8.15k
  case DATA_TYPE_SMEARING:
653
8.15k
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_smearing_mean, cfg->spill_smearing_mean,
654
8.15k
        cfg->cmp_mode, "smearing mean");
655
8.15k
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_smearing_variance, cfg->spill_smearing_variance,
656
8.15k
        cfg->cmp_mode, "smearing variance");
657
8.15k
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_smearing_pixels_error, cfg->spill_smearing_pixels_error,
658
8.15k
        cfg->cmp_mode, "smearing outlier pixls num");
659
8.15k
    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
33.0k
  }
664
33.0k
  return cfg_invalid;
665
33.0k
}
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
}