42 #define OFFSET(x) offsetof(NoiseContext, x)
43 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
45 #define NOISE_PARAMS(name, x, param) \
46 {#name"_seed", "set component #"#x" noise seed", OFFSET(param.seed), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, FLAGS}, \
47 {#name"_strength", "set component #"#x" strength", OFFSET(param.strength), AV_OPT_TYPE_INT, {.i64=0}, 0, 100, FLAGS}, \
48 {#name"s", "set component #"#x" strength", OFFSET(param.strength), AV_OPT_TYPE_INT, {.i64=0}, 0, 100, FLAGS}, \
49 {#name"_flags", "set component #"#x" flags", OFFSET(param.flags), AV_OPT_TYPE_FLAGS, {.i64=0}, 0, 31, FLAGS, #name"_flags"}, \
50 {#name"f", "set component #"#x" flags", OFFSET(param.flags), AV_OPT_TYPE_FLAGS, {.i64=0}, 0, 31, FLAGS, #name"_flags"}, \
51 {"a", "averaged noise", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_AVERAGED}, 0, 0, FLAGS, #name"_flags"}, \
52 {"p", "(semi)regular pattern", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_PATTERN}, 0, 0, FLAGS, #name"_flags"}, \
53 {"t", "temporal noise", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_TEMPORAL}, 0, 0, FLAGS, #name"_flags"}, \
54 {"u", "uniform noise", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_UNIFORM}, 0, 0, FLAGS, #name"_flags"},
67 static const int8_t
patt[4] = { -1, 0, 1, 0 };
69 #define RAND_N(range) ((int) ((double) range * av_lfg_get(lfg) / (UINT_MAX + 1.0)))
84 for (i = 0, j = 0; i <
MAX_NOISE; i++, j++) {
88 noise[i] = (
RAND_N(strength) - strength / 2) / 6
89 +
patt[j % 4] * strength * 0.25 / 3;
91 noise[i] = (
RAND_N(strength) - strength / 2) / 3;
95 noise[i] = (
RAND_N(strength) - strength / 2) / 2
96 +
patt[j % 4] * strength * 0.25;
98 noise[i] =
RAND_N(strength) - strength / 2;
102 double x1, x2, w, y1;
104 x1 = 2.0 *
av_lfg_get(lfg) / (float)UINT_MAX - 1.0;
105 x2 = 2.0 *
av_lfg_get(lfg) / (float)UINT_MAX - 1.0;
106 w = x1 * x1 + x2 * x2;
109 w = sqrt((-2.0 * log(w)) / w);
111 y1 *= strength / sqrt(3.0);
114 y1 +=
patt[j % 4] * strength * 0.35;
116 y1 = av_clipf(y1, -128, 127);
126 for (j = 0; j < 3; j++)
171 for (i = 0; i <
len; i++) {
172 int v = src[i] + noise[i];
174 dst[i] = av_clip_uint8(v);
179 int len,
const int8_t *
const *
shift)
182 const int8_t *src2 = (
const int8_t*)src;
184 for (i = 0; i <
len; i++) {
185 const int n = shift[0][i] + shift[1][i] + shift[2][i];
186 dst[i] = src2[i] + ((n * src2[i]) >> 7);
191 int dst_linesize,
int src_linesize,
205 for (y = start; y <
end; y++) {
206 const int ix = y & (
MAX_RES - 1);
216 n->
line_noise(dst + x, src + x, noise, w, shift);
230 for (plane = 0; plane < s->
nb_planes; plane++) {
232 const int start = (height * jobnr ) / nb_jobs;
233 const int end = (height * (jobnr+1)) / nb_jobs;
237 s->
bytewidth[plane], start, end, s, plane);
262 for (comp = 0; comp < 4; comp++) {
267 for (i = 0; i <
MAX_RES; i++) {
288 for (i = 0; i < 4; i++) {
299 for (i = 0; i < 4; i++) {
318 for (i = 0; i < 4; i++)
349 .priv_class = &noise_class,