Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Commit

Permalink
Separate stable shift option
Browse files Browse the repository at this point in the history
  • Loading branch information
tuorqai committed Feb 13, 2024
1 parent ac5b3f6 commit ce010d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions libsecam.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// Width should be divisible by 8, height should be divisible by 2.
//
// Version history:
// 3.4 2024.02.13 Separate stable shift option
// 3.3 2023.11.20 apply_fire() updated
// 3.2 2023.11.20 New fixes:
// * Fires on cyan and yellow backgrounds
Expand Down Expand Up @@ -64,6 +65,7 @@
#define LIBSECAM_DEFAULT_CHROMA_FIRE_FACTOR 4.0
#define LIBSECAM_DEFAULT_CHROMA_LOSS_CHANCE 0.03 /* unused */
#define LIBSECAM_DEFAULT_ECHO_OFFSET 4
#define LIBSECAM_DEFAULT_STABLE_SHIFT 2
#define LIBSECAM_DEFAULT_HORIZONTAL_INSTABILITY 0

//------------------------------------------------------------------------------
Expand All @@ -86,6 +88,7 @@ typedef struct libsecam_options
double chroma_fire_factor; /* range: 0.0 to 100.0 */
double chroma_loss_chance; /* unused */
int echo_offset; /* range: 0 to whatever */
int stable_shift; /* range: 0 to whatever */
int horizontal_instability; /* range: 0 to whatever */
} libsecam_options_t;

Expand Down Expand Up @@ -569,6 +572,7 @@ libsecam_t *libsecam_init(int width, int height)
self->options.chroma_noise_factor = LIBSECAM_DEFAULT_CHROMA_NOISE_FACTOR;
self->options.chroma_fire_factor = LIBSECAM_DEFAULT_CHROMA_FIRE_FACTOR;
self->options.echo_offset = LIBSECAM_DEFAULT_ECHO_OFFSET;
self->options.stable_shift = LIBSECAM_DEFAULT_STABLE_SHIFT;
self->options.horizontal_instability = LIBSECAM_DEFAULT_HORIZONTAL_INSTABILITY;

self->luma_loss = luma_loss;
Expand Down Expand Up @@ -645,8 +649,8 @@ void libsecam_filter_to_buffer(libsecam_t *self, unsigned char const *src, unsig
double *chroma = &self->chroma[y * chroma_width];

// Stable shift.
if (self->options.echo_offset) {
int const shift = self->stable_shift_buffer[y] * self->options.echo_offset * 4;
if (self->options.stable_shift > 0) {
int const shift = self->stable_shift_buffer[y] * self->options.stable_shift * 4;
libsecam_apply_shift(luma, luma_width, 0, luma_width, shift / self->luma_loss, 0.0);
libsecam_apply_shift(chroma, chroma_width, 0, chroma_width, shift / self->chroma_loss, 0.5);
}
Expand Down
2 changes: 2 additions & 0 deletions secamiz0r/secamiz0r.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ static void update_libsecam_options(libsecam_t *libsecam, double intensity)
options->chroma_noise_factor = 0.125;
options->chroma_fire_factor = 1.0 * x; /* 0.0 to 1.0 */
options->echo_offset = 2;
options->stable_shift = 0;
options->horizontal_instability = (x < 0.25) ? 0 : 2; /* 0 or 2 */
} else {
double const x = (intensity - 0.25) / 0.75;
Expand All @@ -39,6 +40,7 @@ static void update_libsecam_options(libsecam_t *libsecam, double intensity)
options->chroma_noise_factor = 0.125;
options->chroma_fire_factor = 1.0 + (19.0 * x); /* 1.0 to 20.0 */
options->echo_offset = (int) ceilf(2.0 + (6.0 * xs)); /* 2 to 8, non-linear */
options->stable_shift = options->echo_offset / 2;
options->horizontal_instability = (int) ceilf(2.0 + (6.0 * xs)); /* 2 to 8, non-linear */
}
}
Expand Down

0 comments on commit ce010d8

Please sign in to comment.