38 #define MAX_NOISE 5120
39 #define MAX_SHIFT 1024
40 #define MAX_RES (MAX_NOISE-MAX_SHIFT)
42 #define NOISE_UNIFORM 1
43 #define NOISE_TEMPORAL 2
44 #define NOISE_AVERAGED 8
45 #define NOISE_PATTERN 16
73 #define OFFSET(x) offsetof(NoiseContext, x)
74 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
76 #define NOISE_PARAMS(name, x, param) \
77 {#name"_seed", "set component #"#x" noise seed", OFFSET(param.seed), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, FLAGS}, \
78 {#name"_strength", "set component #"#x" strength", OFFSET(param.strength), AV_OPT_TYPE_INT, {.i64=0}, 0, 100, FLAGS}, \
79 {#name"s", "set component #"#x" strength", OFFSET(param.strength), AV_OPT_TYPE_INT, {.i64=0}, 0, 100, FLAGS}, \
80 {#name"_flags", "set component #"#x" flags", OFFSET(param.flags), AV_OPT_TYPE_FLAGS, {.i64=0}, 0, 31, FLAGS, #name"_flags"}, \
81 {#name"f", "set component #"#x" flags", OFFSET(param.flags), AV_OPT_TYPE_FLAGS, {.i64=0}, 0, 31, FLAGS, #name"_flags"}, \
82 {"a", "averaged noise", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_AVERAGED}, 0, 0, FLAGS, #name"_flags"}, \
83 {"p", "(semi)regular pattern", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_PATTERN}, 0, 0, FLAGS, #name"_flags"}, \
84 {"t", "temporal noise", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_TEMPORAL}, 0, 0, FLAGS, #name"_flags"}, \
85 {"u", "uniform noise", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_UNIFORM}, 0, 0, FLAGS, #name"_flags"},
98 static const int8_t
patt[4] = { -1, 0, 1, 0 };
100 #define RAND_N(range) ((int) ((double) range * av_lfg_get(lfg) / (UINT_MAX + 1.0)))
115 for (i = 0, j = 0; i <
MAX_NOISE; i++, j++) {
119 noise[i] = (
RAND_N(strength) - strength / 2) / 6
120 +
patt[j % 4] * strength * 0.25 / 3;
122 noise[i] = (
RAND_N(strength) - strength / 2) / 3;
126 noise[i] = (
RAND_N(strength) - strength / 2) / 2
127 +
patt[j % 4] * strength * 0.25;
129 noise[i] =
RAND_N(strength) - strength / 2;
133 double x1, x2, w, y1;
135 x1 = 2.0 *
av_lfg_get(lfg) / (float)UINT_MAX - 1.0;
136 x2 = 2.0 *
av_lfg_get(lfg) / (float)UINT_MAX - 1.0;
137 w = x1 * x1 + x2 * x2;
140 w = sqrt((-2.0 * log(w)) / w);
142 y1 *= strength / sqrt(3.0);
145 y1 +=
patt[j % 4] * strength * 0.35;
147 y1 = av_clipf(y1, -128, 127);
157 for (j = 0; j < 3; j++)
208 for (i = 0; i <
len; i++) {
209 int v = src[i] + noise[i];
211 dst[i] = av_clip_uint8(v);
215 #define ASMALIGN(ZEROBITS) ".p2align " #ZEROBITS "\n\t"
225 "mov %3, %%"REG_a
" \n\t"
226 "pcmpeqb %%mm7, %%mm7 \n\t"
227 "psllw $15, %%mm7 \n\t"
228 "packsswb %%mm7, %%mm7 \n\t"
231 "movq (%0, %%"REG_a
"), %%mm0 \n\t"
232 "movq (%1, %%"REG_a
"), %%mm1 \n\t"
233 "pxor %%mm7, %%mm0 \n\t"
234 "paddsb %%mm1, %%mm0 \n\t"
235 "pxor %%mm7, %%mm0 \n\t"
236 "movq %%mm0, (%2, %%"REG_a
") \n\t"
237 "add $8, %%"REG_a
" \n\t"
239 ::
"r" (src+mmx_len),
"r" (noise+mmx_len),
"r" (dst+mmx_len),
"g" (-mmx_len)
243 line_noise_c(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0);
250 #if HAVE_MMXEXT_INLINE
255 "mov %3, %%"REG_a
" \n\t"
256 "pcmpeqb %%mm7, %%mm7 \n\t"
257 "psllw $15, %%mm7 \n\t"
258 "packsswb %%mm7, %%mm7 \n\t"
261 "movq (%0, %%"REG_a
"), %%mm0 \n\t"
262 "movq (%1, %%"REG_a
"), %%mm1 \n\t"
263 "pxor %%mm7, %%mm0 \n\t"
264 "paddsb %%mm1, %%mm0 \n\t"
265 "pxor %%mm7, %%mm0 \n\t"
266 "movntq %%mm0, (%2, %%"REG_a
") \n\t"
267 "add $8, %%"REG_a
" \n\t"
269 ::
"r" (src+mmx_len),
"r" (noise+mmx_len),
"r" (dst+mmx_len),
"g" (-mmx_len)
273 line_noise_c(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0);
278 int len,
const int8_t *
const *
shift)
281 const int8_t *src2 = (
const int8_t*)src;
283 for (i = 0; i <
len; i++) {
284 const int n = shift[0][i] + shift[1][i] + shift[2][i];
285 dst[i] = src2[i] + ((n * src2[i]) >> 7);
290 int len,
const int8_t *
const *
shift)
292 #if HAVE_MMX_INLINE && HAVE_6REGS
296 "mov %5, %%"REG_a
" \n\t"
299 "movq (%1, %%"REG_a
"), %%mm1 \n\t"
300 "movq (%0, %%"REG_a
"), %%mm0 \n\t"
301 "paddb (%2, %%"REG_a
"), %%mm1 \n\t"
302 "paddb (%3, %%"REG_a
"), %%mm1 \n\t"
303 "movq %%mm0, %%mm2 \n\t"
304 "movq %%mm1, %%mm3 \n\t"
305 "punpcklbw %%mm0, %%mm0 \n\t"
306 "punpckhbw %%mm2, %%mm2 \n\t"
307 "punpcklbw %%mm1, %%mm1 \n\t"
308 "punpckhbw %%mm3, %%mm3 \n\t"
309 "pmulhw %%mm0, %%mm1 \n\t"
310 "pmulhw %%mm2, %%mm3 \n\t"
311 "paddw %%mm1, %%mm1 \n\t"
312 "paddw %%mm3, %%mm3 \n\t"
313 "paddw %%mm0, %%mm1 \n\t"
314 "paddw %%mm2, %%mm3 \n\t"
315 "psrlw $8, %%mm1 \n\t"
316 "psrlw $8, %%mm3 \n\t"
317 "packuswb %%mm3, %%mm1 \n\t"
318 "movq %%mm1, (%4, %%"REG_a
") \n\t"
319 "add $8, %%"REG_a
" \n\t"
321 ::
"r" (src+mmx_len),
"r" (shift[0]+mmx_len),
"r" (shift[1]+mmx_len),
"r" (shift[2]+mmx_len),
322 "r" (dst+mmx_len),
"g" (-mmx_len)
327 const int8_t *
shift2[3]={shift[0]+mmx_len, shift[1]+mmx_len, shift[2]+mmx_len};
334 int dst_linesize,
int src_linesize,
349 for (y = start; y <
end; y++) {
350 const int ix = y & (
MAX_RES - 1);
373 for (plane = 0; plane < s->
nb_planes; plane++) {
375 const int start = (height * jobnr ) / nb_jobs;
376 const int end = (height * (jobnr+1)) / nb_jobs;
380 s->
bytewidth[plane], start, end, s, plane);
419 for (i = 0; i < 4; i++) {
430 for (i = 0; i < 4; i++) {
438 if (HAVE_MMX_INLINE &&
445 if (HAVE_MMXEXT_INLINE &&
457 for (i = 0; i < 4; i++)
488 .priv_class = &noise_class,