37 #define MAX_NOISE 4096
38 #define MAX_SHIFT 1024
39 #define MAX_RES (MAX_NOISE-MAX_SHIFT)
41 #define NOISE_UNIFORM 1
42 #define NOISE_TEMPORAL 2
43 #define NOISE_QUALITY 4
44 #define NOISE_AVERAGED 8
45 #define NOISE_PATTERN 16
68 #define OFFSET(x) offsetof(NoiseContext, x)
69 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
71 #define NOISE_PARAMS(name, x, param) \
72 {#name"_seed", "set component #"#x" noise seed", OFFSET(param.seed), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, FLAGS}, \
73 {#name"_strength", "set component #"#x" strength", OFFSET(param.strength), AV_OPT_TYPE_INT, {.i64=0}, 0, 100, FLAGS}, \
74 {#name"s", "set component #"#x" strength", OFFSET(param.strength), AV_OPT_TYPE_INT, {.i64=0}, 0, 100, FLAGS}, \
75 {#name"_flags", "set component #"#x" flags", OFFSET(param.flags), AV_OPT_TYPE_FLAGS, {.i64=0}, 0, 31, FLAGS, #name"_flags"}, \
76 {#name"f", "set component #"#x" flags", OFFSET(param.flags), AV_OPT_TYPE_FLAGS, {.i64=0}, 0, 31, FLAGS, #name"_flags"}, \
77 {"a", "averaged noise", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_AVERAGED}, 0, 0, FLAGS, #name"_flags"}, \
78 {"p", "(semi)regular pattern", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_PATTERN}, 0, 0, FLAGS, #name"_flags"}, \
79 {"q", "high quality", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_QUALITY}, 0, 0, FLAGS, #name"_flags"}, \
80 {"t", "temporal noise", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_TEMPORAL}, 0, 0, FLAGS, #name"_flags"}, \
81 {"u", "uniform noise", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_UNIFORM}, 0, 0, FLAGS, #name"_flags"},
94 static const int8_t
patt[4] = { -1, 0, 1, 0 };
96 #define RAND_N(range) ((int) ((double) range * av_lfg_get(lfg) / (UINT_MAX + 1.0)))
111 for (i = 0, j = 0; i <
MAX_NOISE; i++, j++) {
115 noise[i] = (
RAND_N(strength) - strength / 2) / 6
116 +
patt[j % 4] * strength * 0.25 / 3;
118 noise[i] = (
RAND_N(strength) - strength / 2) / 3;
122 noise[i] = (
RAND_N(strength) - strength / 2) / 2
123 +
patt[j % 4] * strength * 0.25;
125 noise[i] =
RAND_N(strength) - strength / 2;
129 double x1, x2, w, y1;
131 x1 = 2.0 *
av_lfg_get(lfg) / (float)RAND_MAX - 1.0;
132 x2 = 2.0 *
av_lfg_get(lfg) / (float)RAND_MAX - 1.0;
133 w = x1 * x1 + x2 * x2;
136 w = sqrt((-2.0 * log(w)) / w);
138 y1 *= strength / sqrt(3.0);
141 y1 +=
patt[j % 4] * strength * 0.35;
143 y1 = av_clipf(y1, -128, 127);
153 for (j = 0; j < 3; j++)
172 n->
class = &noise_class;
178 for (i = 0; i < 4; i++) {
189 for (i = 0; i < 4; i++) {
237 for (i = 0; i <
len; i++) {
238 int v = src[i] + noise[i];
240 dst[i] = av_clip_uint8(v);
248 int8_t *src2 = (int8_t*)src;
250 for (i = 0; i <
len; i++) {
251 const int n = shift[0][i] + shift[1][i] + shift[2][i];
252 dst[i] = src2[i] + ((n * src2[i]) >> 7);
257 int dst_linesize,
int src_linesize,
267 for (y = 0; y <
height; y++) {
268 memcpy(dst, src, width);
277 for (y = 0; y <
height; y++) {
334 for (i = 0; i < 4; i++)
368 .priv_class = &noise_class,