Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .checkpatch.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--emacs
--summary-file
--show-types
--max-line-length=100
--min-conf-desc-length=1
--typedefsfile=scripts/checkpatch/typedefsfile
--strict

--ignore PRINTK_WITHOUT_KERN_LEVEL
--ignore SPLIT_STRING
--ignore VOLATILE
--ignore CONFIG_EXPERIMENTAL
--ignore PREFER_KERNEL_TYPES
--ignore PREFER_SECTION
--ignore AVOID_EXTERNS
--ignore NETWORKING_BLOCK_COMMENT_STYLE
--ignore DATE_TIME
--ignore MINMAX
--ignore CONST_STRUCT
--ignore FILE_PATH_CHANGES
--ignore SPDX_LICENSE_TAG
--ignore C99_COMMENT_TOLERANCE
--ignore REPEATED_WORD
--ignore UNDOCUMENTED_DT_STRING
--ignore DT_SPLIT_BINDING_PATCH
--ignore DT_SCHEMA_BINDING_PATCH
--ignore TRAILING_SEMICOLON
--ignore COMPLEX_MACRO
--ignore MULTISTATEMENT_MACRO_USE_DO_WHILE
--ignore ENOSYS
--ignore IS_ENABLED_CONFIG
--ignore EXPORT_SYMBOL
--ignore UNNECESSARY_ELSE
--ignore NEW_TYPEDEFS
--ignore BRACES
8 changes: 5 additions & 3 deletions lib/ccsds123b/src/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

static void compute_k(int accumulator, int counter, int *k)
{
if (2 * counter > accumulator + (int32_t)(49/128.0 * counter)) {
if (2 * counter > accumulator + (int32_t)(49 / 128.0 * counter)) {
*k = 0;
} else {
for (*k = 1; *k <= D - 2; ++(*k)) {
if (counter * (1 << *k) > accumulator + (int32_t)(49/128.0 * counter)) {
if (counter * (1 << *k) > accumulator + (int32_t)(49 / 128.0 * counter)) {
*k -= 1;
break;
}
Expand Down Expand Up @@ -52,7 +52,9 @@ void encode_prediction(const vec3 *N, Predictions prediction, EncoderOut out)
}
}

// [5.4.3.2.2] Sample adaptive entropy encoder
/*
* [5.4.3.2.2] Sample adaptive entropy encoder
*/
int32_t j = get_predictions(prediction, z, y, x);
int32_t k;

Expand Down
65 changes: 41 additions & 24 deletions lib/ccsds123b/src/predictor.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ void predict_image(const vec3 *N, Predictions p)
int ph = -6 + (int32_t)((t - N->x) / 16) + 10 - Omega;

weights[t + 1] = update_weight(
weights[t + 1], // omega_t: current weight
ez, // e_z_t: prediction error
ph, // p_t: scaling exponent
0, // xi_z_i: default to 0
get_local_diffs(local_diffs, z, y, x).central, // d_z_i_t1: central local difference
-(1 << (Omega + 2)), // omega_min: -2^(Omega+2)
(1 << (Omega + 2)) - 1 // omega_max: 2^(Omega+2) - 1
weights[t + 1], /* omega_t: current weight */
ez, /* e_z_t: prediction error */
ph, /* p_t: scaling exponent */
0, /* xi_z_i: default to 0 */
get_local_diffs(local_diffs, z, y, x).central, /* d_z_i_t1: central local difference */
-(1 << (Omega + 2)), /* omega_min: -2^(Omega+2) */
(1 << (Omega + 2)) - 1 /* omega_max: 2^(Omega+2) - 1 */
);
}

Expand Down Expand Up @@ -109,7 +109,6 @@ void predict_image(const vec3 *N, Predictions p)
double_res_pred_sample,
predicted_sample_value);


/*
* Prediction
*/
Expand Down Expand Up @@ -140,8 +139,10 @@ int32_t compute_local_sum(int z, int y, int x)
return img_get_pxl(z, y, x - 1) + img_get_pxl(z, y - 1, x - 1) +
(2 * img_get_pxl(z, y - 1, x));
} else {
// The value of local sum at t=0 is undefined since it is not
// needed, so we return 0.
/*
* The value of local sum at t=0 is undefined since it is not
* needed, so we return 0.
*/
return 0;
}

Expand Down Expand Up @@ -170,7 +171,9 @@ int32_t compute_local_sum(int z, int y, int x)

LocalDiff compute_local_diffs(int z, int y, int x, int32_t local_sum)
{
// t=0 is not defined.
/*
* t=0 is not defined.
*/
if (x == 0 && y == 0) {
return (LocalDiff){ 0, 0, 0, 0 };
}
Expand Down Expand Up @@ -256,31 +259,43 @@ void initialize_weights(int32_t *weights, int32_t weights_size, int z, int32_t o
int32_t update_weight(int32_t omega_t, int32_t e_z_t, int32_t p_t, int32_t xi_z_i,
int32_t d_z_i_t1, int32_t omega_min, int32_t omega_max)
{
// Step 1: Compute sgn[e_z(t)]
/*
* Step 1: Compute sgn[e_z(t)]
*/
int32_t sign = sgn_pos(e_z_t);

// Step 2: Compute the exponent -p(t) + xi_z^(i)
/*
* Step 2: Compute the exponent -p(t) + xi_z^(i)
*/
int32_t exponent = -p_t + xi_z_i;

// Step 3: Compute 2^(-p(t) + xi_z^(i)) * d_z-i(t+1)
// Since 2^exponent can be a left or right shift:
/*
* Step 3: Compute 2^(-p(t) + xi_z^(i)) * d_z-i(t+1)
* Since 2^exponent can be a left or right shift:
*/
int32_t scaling_factor;

if (exponent >= 0) {
scaling_factor = d_z_i_t1 << exponent; // 2^exponent * d_z-i(t+1)
scaling_factor = d_z_i_t1 << exponent; /* 2^exponent * d_z-i(t+1) */
} else {
scaling_factor = d_z_i_t1 >> (-exponent); // 2^(-|exponent|) * d_z-i(t+1)
scaling_factor = d_z_i_t1 >> (-exponent); /* 2^(-|exponent|) * d_z-i(t+1) */
}

// Step 4: Compute the update term: (1/2) * sgn[e_z(t)] * 2^(-p(t) + xi_z^(i)) * d_z-i(t+1)
// 1/2 is a right shift by 1
/*
* Step 4: Compute the update term: (1/2) * sgn[e_z(t)] * 2^(-p(t) + xi_z^(i)) * d_z-i(t+1)
* 1/2 is a right shift by 1
*/
int32_t update_term = (sign * scaling_factor) >> 1;

// Step 5: Update omega: omega(t) + floor(update_term)
// Since we're using integers, the floor is implicit
/*
* Step 5: Update omega: omega(t) + floor(update_term)
* Since we're using integers, the floor is implicit
*/
int32_t new_omega = omega_t + update_term;

// Step 6: Clip the result to [omega_min, omega_max]
/*
* Step 6: Clip the result to [omega_min, omega_max]
*/
new_omega = clip(new_omega, omega_min, omega_max);

return new_omega;
Expand All @@ -293,8 +308,10 @@ int64_t mod(int64_t M, int64_t n)

int64_t compute_high_res_pred_sample(int32_t pred_cent_local_diff, int32_t local_sum, int32_t Omega, int32_t R, int32_t Smid, int32_t Smax, int32_t Smin)
{
// The calculation shown at 4.7.2 can be represented in this format,
// clip(modR(c1) + c2 + c3, {clip_min, clip_max})
/*
* The calculation shown at 4.7.2 can be represented in this format,
* clip(modR(c1) + c2 + c3, {clip_min, clip_max})
*/

uint64_t const two_R = 1ULL << R;
uint64_t const two_R_minus_1 = 1ULL << (R - 1);
Expand Down
Loading
Loading