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
12.2k
{
41
12.2k
  if (!x)
42
1.12k
    return -1U;
43
44
11.1k
  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
3.21k
{
61
3.21k
  return (((v) & ((v) - 1)) == 0);
62
3.21k
}
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
5.04k
{
75
5.04k
  if (data_type <= DATA_TYPE_UNKNOWN || data_type > DATA_TYPE_CHUNK)
76
31
    return 1;
77
78
5.01k
  return 0;
79
5.04k
}
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
14.0k
{
92
14.0k
  if (cmp_mode == CMP_MODE_MODEL_ZERO ||
93
14.0k
      cmp_mode == CMP_MODE_MODEL_MULTI)
94
3.35k
    return 1;
95
96
10.6k
  return 0;
97
14.0k
}
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
4.06k
{
110
4.06k
  if (cmp_mode == CMP_MODE_RAW)
111
701
    return 1;
112
113
3.36k
  return 0;
114
4.06k
}
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
7.67k
{
127
7.67k
  switch (data_type) {
128
6.53k
  case DATA_TYPE_IMAGETTE:
129
6.54k
  case DATA_TYPE_IMAGETTE_ADAPTIVE:
130
6.59k
  case DATA_TYPE_SAT_IMAGETTE:
131
6.59k
  case DATA_TYPE_SAT_IMAGETTE_ADAPTIVE:
132
6.63k
  case DATA_TYPE_F_CAM_IMAGETTE:
133
6.63k
  case DATA_TYPE_F_CAM_IMAGETTE_ADAPTIVE:
134
6.63k
    return 1;
135
1.03k
  default:
136
1.03k
    return 0;
137
7.67k
  }
138
7.67k
}
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
4.82k
{
151
4.82k
  switch (cmp_mode) {
152
1.14k
  case CMP_MODE_RAW:
153
1.66k
  case CMP_MODE_MODEL_ZERO:
154
3.23k
  case CMP_MODE_DIFF_ZERO:
155
3.87k
  case CMP_MODE_MODEL_MULTI:
156
4.82k
  case CMP_MODE_DIFF_MULTI:
157
4.82k
    return 1;
158
2
  default:
159
2
    return 0;
160
4.82k
  }
161
4.82k
}
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
4.22k
{
174
4.22k
  if (cmp_mode == CMP_MODE_MODEL_ZERO ||
175
4.22k
      cmp_mode == CMP_MODE_DIFF_ZERO)
176
2.00k
    return 1;
177
178
2.21k
  return 0;
179
4.22k
}
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
0
{
192
0
  if (cmp_mode == CMP_MODE_MODEL_MULTI ||
193
0
      cmp_mode == CMP_MODE_DIFF_MULTI)
194
0
    return 1;
195
196
0
  return 0;
197
0
}
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
7.54k
{
211
7.54k
  return rdcu_supported_data_type_is_used(data_type);
212
7.54k
}
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
1.93k
{
246
1.93k
  switch (data_type) {
247
326
  case DATA_TYPE_S_FX:
248
634
  case DATA_TYPE_S_FX_EFX:
249
686
  case DATA_TYPE_S_FX_NCOB:
250
794
  case DATA_TYPE_S_FX_EFX_NCOB_ECOB:
251
864
  case DATA_TYPE_L_FX:
252
1.68k
  case DATA_TYPE_L_FX_EFX:
253
1.77k
  case DATA_TYPE_L_FX_NCOB:
254
1.80k
  case DATA_TYPE_L_FX_EFX_NCOB_ECOB:
255
1.80k
  case DATA_TYPE_F_FX:
256
1.80k
  case DATA_TYPE_F_FX_EFX:
257
1.80k
  case DATA_TYPE_F_FX_NCOB:
258
1.80k
  case DATA_TYPE_F_FX_EFX_NCOB_ECOB:
259
1.80k
    return 1;
260
132
  default:
261
132
    return 0;
262
1.93k
  }
263
1.93k
}
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
0
{
276
0
  switch (data_type) {
277
0
  case DATA_TYPE_OFFSET:
278
0
  case DATA_TYPE_BACKGROUND:
279
0
  case DATA_TYPE_SMEARING:
280
0
  case DATA_TYPE_F_CAM_OFFSET:
281
0
  case DATA_TYPE_F_CAM_BACKGROUND:
282
0
    return 1;
283
0
  default:
284
0
    return 0;
285
0
  }
286
0
}
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
5.04k
{
328
  /* the ICU compressor can generate code words with a length of maximal 32 bits. */
329
5.04k
  unsigned int const max_cw_bits = 32;
330
5.04k
  unsigned int const cutoff = (0x2U << (ilog_2(cmp_par) & 0x1FU)) - cmp_par;
331
5.04k
  unsigned int const max_n_sym_offset = (max_cw_bits/2) - 1;
332
333
5.04k
  if (!cmp_par || cmp_par > MAX_NON_IMA_GOLOMB_PAR)
334
1.18k
    return 0;
335
336
3.86k
  return ((max_cw_bits-1-ilog_2(cmp_par))*cmp_par) + cutoff
337
3.86k
    - max_n_sym_offset - 1;
338
5.04k
}
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
1.43k
{
351
1.43k
  return (cmp_size_bit + 7) / 8;
352
1.43k
}
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
4.31k
{
369
4.31k
  int cfg_invalid = 0;
370
371
4.31k
  if (!cfg)
372
0
    return 1;
373
374
4.31k
  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
4.31k
  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
4.31k
  if (model_mode_is_used(cfg->cmp_mode)) {
385
1.07k
    if (cfg->model_value > MAX_MODEL_VALUE) {
386
11
      debug_print("Error: selected model_value: %" PRIu32 " is invalid. The largest supported value is: %u.",
387
11
            cfg->model_value, MAX_MODEL_VALUE);
388
11
      cfg_invalid++;
389
11
    }
390
1.07k
  }
391
392
4.31k
  if (cfg->round > MAX_ICU_ROUND) {
393
9
    debug_print("Error: selected lossy parameter: %" PRIu32 " is not supported. The largest supported value is: %" PRIu32 ".",
394
9
          cfg->round, MAX_ICU_ROUND);
395
9
    cfg_invalid++;
396
9
  }
397
398
#ifdef SKIP_CMP_PAR_CHECK
399
  return 0;
400
#endif
401
4.31k
  return cfg_invalid;
402
4.31k
}
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.76k
{
420
6.76k
  int cfg_invalid = 0;
421
422
6.76k
  switch (cmp_mode) {
423
2.99k
  case CMP_MODE_RAW:
424
    /* no checks needed */
425
2.99k
    break;
426
1.69k
  case CMP_MODE_DIFF_ZERO:
427
2.68k
  case CMP_MODE_DIFF_MULTI:
428
3.16k
  case CMP_MODE_MODEL_ZERO:
429
3.77k
  case CMP_MODE_MODEL_MULTI:
430
3.77k
    if (cmp_par < MIN_NON_IMA_GOLOMB_PAR || cmp_par > MAX_NON_IMA_GOLOMB_PAR) {
431
193
      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
193
            par_name, cmp_par, MIN_NON_IMA_GOLOMB_PAR, MAX_NON_IMA_GOLOMB_PAR);
433
193
      cfg_invalid++;
434
193
    }
435
3.77k
    if (spill < MIN_NON_IMA_SPILL) {
436
198
      debug_print("Error: The selected %s spillover threshold value: %" PRIu32 " is too small. The smallest possible spillover value is: %" PRIu32 ".",
437
198
            par_name, spill, MIN_NON_IMA_SPILL);
438
198
      cfg_invalid++;
439
198
    }
440
3.77k
    if (spill > cmp_icu_max_spill(cmp_par)) {
441
16
      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
16
            par_name, spill, par_name, cmp_par, cmp_icu_max_spill(cmp_par));
443
16
      cfg_invalid++;
444
16
    }
445
446
3.77k
    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.76k
  }
452
453
#ifdef SKIP_CMP_PAR_CHECK
454
  return 0;
455
#endif
456
6.76k
  return cfg_invalid;
457
6.76k
}
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
3.25k
{
470
3.25k
  int cfg_invalid = 0;
471
472
3.25k
  if (!cfg)
473
0
    return 1;
474
475
3.25k
  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
3.25k
  cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_imagette, cfg->spill_imagette,
481
3.25k
              cfg->cmp_mode, "imagette");
482
3.25k
  return cfg_invalid;
483
3.25k
}
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
902
{
500
902
  if (!par)
501
0
    return -1;
502
503
902
  par->exp_flags = 0;
504
902
  par->fx = 0;
505
902
  par->ncob = 0;
506
902
  par->efx = 0;
507
902
  par->ecob = 0;
508
902
  par->fx_cob_variance = 0;
509
510
  /* flux parameter is needed for every fx_cob data_type */
511
902
  par->fx = 1;
512
513
902
  switch (data_type) {
514
163
  case DATA_TYPE_S_FX:
515
163
    par->exp_flags = 1;
516
163
    break;
517
154
  case DATA_TYPE_S_FX_EFX:
518
154
    par->exp_flags = 1;
519
154
    par->efx = 1;
520
154
    break;
521
26
  case DATA_TYPE_S_FX_NCOB:
522
26
    par->exp_flags = 1;
523
26
    par->ncob = 1;
524
26
    break;
525
54
  case DATA_TYPE_S_FX_EFX_NCOB_ECOB:
526
54
    par->exp_flags = 1;
527
54
    par->ncob = 1;
528
54
    par->efx = 1;
529
54
    par->ecob = 1;
530
54
    break;
531
35
  case DATA_TYPE_L_FX:
532
35
    par->exp_flags = 1;
533
35
    par->fx_cob_variance = 1;
534
35
    break;
535
412
  case DATA_TYPE_L_FX_EFX:
536
412
    par->exp_flags = 1;
537
412
    par->efx = 1;
538
412
    par->fx_cob_variance = 1;
539
412
    break;
540
41
  case DATA_TYPE_L_FX_NCOB:
541
41
    par->exp_flags = 1;
542
41
    par->ncob = 1;
543
41
    par->fx_cob_variance = 1;
544
41
    break;
545
17
  case DATA_TYPE_L_FX_EFX_NCOB_ECOB:
546
17
    par->exp_flags = 1;
547
17
    par->ncob = 1;
548
17
    par->efx = 1;
549
17
    par->ecob = 1;
550
17
    par->fx_cob_variance = 1;
551
17
    break;
552
0
  case DATA_TYPE_F_FX:
553
0
    break;
554
0
  case DATA_TYPE_F_FX_EFX:
555
0
    par->efx = 1;
556
0
    break;
557
0
  case DATA_TYPE_F_FX_NCOB:
558
0
    par->ncob = 1;
559
0
    break;
560
0
  case DATA_TYPE_F_FX_EFX_NCOB_ECOB:
561
0
    par->ncob = 1;
562
0
    par->efx = 1;
563
0
    par->ecob = 1;
564
0
    break;
565
0
  default:
566
0
    return -1;
567
902
  }
568
902
  return 0;
569
902
}
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
902
{
583
902
  int cfg_invalid = 0;
584
902
  struct fx_cob_par needed_pars;
585
586
902
  if (!cfg)
587
0
    return 1;
588
589
902
  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
902
  cmp_cfg_fx_cob_get_need_pars(cfg->data_type, &needed_pars);
595
596
902
  if (needed_pars.fx) /* this is always true because every flux/center of brightness data type contains a flux parameter */
597
902
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_fx, cfg->spill_fx,
598
902
                cfg->cmp_mode, "flux");
599
902
  if (needed_pars.exp_flags)
600
902
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_exp_flags, cfg->spill_exp_flags,
601
902
      cfg->cmp_mode, "exposure flags");
602
902
  if (needed_pars.ncob)
603
138
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_ncob, cfg->spill_ncob,
604
138
      cfg->cmp_mode, "center of brightness");
605
902
  if (needed_pars.efx)
606
637
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_efx, cfg->spill_efx,
607
637
      cfg->cmp_mode, "extended flux");
608
902
  if (needed_pars.ecob)
609
71
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_ecob, cfg->spill_ecob,
610
71
      cfg->cmp_mode, "extended center of brightness");
611
902
  if (needed_pars.fx_cob_variance)
612
505
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_fx_cob_variance,
613
505
      cfg->spill_fx_cob_variance, cfg->cmp_mode, "flux/COB variance");
614
615
902
  return cfg_invalid;
616
902
}
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
132
{
630
132
  int cfg_invalid = 0;
631
632
132
  if (!cfg)
633
0
    return 1;
634
635
132
  switch (cfg->data_type) {
636
15
  case DATA_TYPE_OFFSET:
637
41
  case DATA_TYPE_F_CAM_OFFSET:
638
41
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_offset_mean, cfg->spill_offset_mean,
639
41
        cfg->cmp_mode, "offset mean");
640
41
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_offset_variance, cfg->spill_offset_variance,
641
41
        cfg->cmp_mode, "offset variance");
642
41
    break;
643
35
  case DATA_TYPE_BACKGROUND:
644
56
  case DATA_TYPE_F_CAM_BACKGROUND:
645
56
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_background_mean, cfg->spill_background_mean,
646
56
        cfg->cmp_mode, "background mean");
647
56
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_background_variance, cfg->spill_background_variance,
648
56
        cfg->cmp_mode, "background variance");
649
56
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_background_pixels_error, cfg->spill_background_pixels_error,
650
56
        cfg->cmp_mode, "background outlier pixls num");
651
56
    break;
652
35
  case DATA_TYPE_SMEARING:
653
35
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_smearing_mean, cfg->spill_smearing_mean,
654
35
        cfg->cmp_mode, "smearing mean");
655
35
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_smearing_variance, cfg->spill_smearing_variance,
656
35
        cfg->cmp_mode, "smearing variance");
657
35
    cfg_invalid += cmp_pars_are_invalid(cfg->cmp_par_smearing_pixels_error, cfg->spill_smearing_pixels_error,
658
35
        cfg->cmp_mode, "smearing outlier pixls num");
659
35
    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
132
  }
664
132
  return cfg_invalid;
665
132
}
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
}