Lines Matching defs:deshake
24 * fast deshake / depan video filter
62 #include "deshake.h"
95 AVFILTER_DEFINE_CLASS(deshake);
126 static void find_block_motion(DeshakeContext *deshake, uint8_t *src1,
135 #define CMP(i, j) deshake->c.sad[0](NULL, src1 + cy * stride + cx, \
137 deshake->blocksize)
139 if (deshake->search == EXHAUSTIVE) {
141 for (y = -deshake->ry; y <= deshake->ry; y++) {
142 for (x = -deshake->rx; x <= deshake->rx; x++) {
151 } else if (deshake->search == SMART_EXHAUSTIVE) {
153 for (y = -deshake->ry + 1; y < deshake->ry; y += 2) {
154 for (x = -deshake->rx + 1; x < deshake->rx; x += 2) {
242 static void find_motion(DeshakeContext *deshake, uint8_t *src1, uint8_t *src2,
252 double *angles = av_malloc_array(width * height / (16 * deshake->blocksize), sizeof(*angles));
257 for (x = 0; x < deshake->rx * 2 + 1; x++) {
258 for (y = 0; y < deshake->ry * 2 + 1; y++) {
265 for (y = deshake->ry; y < height - deshake->ry - (deshake->blocksize * 2); y += deshake->blocksize * 2) {
267 for (x = deshake->rx; x < width - deshake->rx - 16; x += 16) {
270 contrast = block_contrast(src2, x, y, stride, deshake->blocksize);
271 if (contrast > deshake->contrast) {
273 find_block_motion(deshake, src1, src2, x, y, stride, &mv);
275 counts[mv.x + deshake->rx][mv.y + deshake->ry] += 1;
276 if (x > deshake->rx && y > deshake->ry)
297 for (y = deshake->ry * 2; y >= 0; y--) {
298 for (x = 0; x < deshake->rx * 2 + 1; x++) {
301 t->vector.x = x - deshake->rx;
302 t->vector.y = y - deshake->ry;
315 t->vector.x = av_clipf(t->vector.x, -deshake->rx * 2, deshake->rx * 2);
316 t->vector.y = av_clipf(t->vector.y, -deshake->ry * 2, deshake->ry * 2);
352 DeshakeContext *deshake = ctx->priv;
354 deshake->refcount = 20; // XXX: add to options?
355 deshake->blocksize /= 2;
356 deshake->blocksize = av_clip(deshake->blocksize, 4, 128);
358 if (deshake->rx % 16) {
363 if (deshake->filename)
364 deshake->fp = fopen(deshake->filename, "w");
365 if (deshake->fp)
366 fwrite("Ori x, Avg x, Fin x, Ori y, Avg y, Fin y, Ori angle, Avg angle, Fin angle, Ori zoom, Avg zoom, Fin zoom\n", sizeof(char), 104, deshake->fp);
370 if (deshake->cx > 0) {
371 deshake->cw += deshake->cx - (deshake->cx & ~15);
372 deshake->cx &= ~15;
374 deshake->transform = deshake_transform_c;
375 if (!CONFIG_OPENCL && deshake->opencl) {
380 if (CONFIG_OPENCL && deshake->opencl) {
381 deshake->transform = ff_opencl_transform;
387 deshake->cx, deshake->cy, deshake->cw, deshake->ch,
388 deshake->rx, deshake->ry, deshake->edge, deshake->blocksize * 2, deshake->contrast, deshake->search);
408 DeshakeContext *deshake = link->dst->priv;
410 deshake->ref = NULL;
411 deshake->last.vector.x = 0;
412 deshake->last.vector.y = 0;
413 deshake->last.angle = 0;
414 deshake->last.zoom = 0;
416 deshake->avctx = avcodec_alloc_context3(NULL);
417 avpriv_dsputil_init(&deshake->c, deshake->avctx);
424 DeshakeContext *deshake = ctx->priv;
425 if (CONFIG_OPENCL && deshake->opencl) {
428 av_frame_free(&deshake->ref);
429 if (deshake->fp)
430 fclose(deshake->fp);
431 if (deshake->avctx)
432 avcodec_close(deshake->avctx);
433 av_freep(&deshake->avctx);
438 DeshakeContext *deshake = link->dst->priv;
443 float alpha = 2.0 / deshake->refcount;
454 if (CONFIG_OPENCL && deshake->opencl) {
460 if (deshake->cx < 0 || deshake->cy < 0 || deshake->cw < 0 || deshake->ch < 0) {
462 find_motion(deshake, (deshake->ref == NULL) ? in->data[0] : deshake->ref->data[0], in->data[0], link->w, link->h, in->linesize[0], &t);
464 uint8_t *src1 = (deshake->ref == NULL) ? in->data[0] : deshake->ref->data[0];
467 deshake->cx = FFMIN(deshake->cx, link->w);
468 deshake->cy = FFMIN(deshake->cy, link->h);
470 if ((unsigned)deshake->cx + (unsigned)deshake->cw > link->w) deshake->cw = link->w - deshake->cx;
471 if ((unsigned)deshake->cy + (unsigned)deshake->ch > link->h) deshake->ch = link->h - deshake->cy;
474 deshake->cw &= ~15;
476 src1 += deshake->cy * in->linesize[0] + deshake->cx;
477 src2 += deshake->cy * in->linesize[0] + deshake->cx;
479 find_motion(deshake, src1, src2, deshake->cw, deshake->ch, in->linesize[0], &t);
490 deshake->avg.vector.x = alpha * t.vector.x + (1.0 - alpha) * deshake->avg.vector.x;
491 deshake->avg.vector.y = alpha * t.vector.y + (1.0 - alpha) * deshake->avg.vector.y;
492 deshake->avg.angle = alpha * t.angle + (1.0 - alpha) * deshake->avg.angle;
493 deshake->avg.zoom = alpha * t.zoom + (1.0 - alpha) * deshake->avg.zoom;
497 t.vector.x -= deshake->avg.vector.x;
498 t.vector.y -= deshake->avg.vector.y;
499 t.angle -= deshake->avg.angle;
500 t.zoom -= deshake->avg.zoom;
508 if (deshake->fp) {
509 snprintf(tmp, 256, "%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f\n", orig.vector.x, deshake->avg.vector.x, t.vector.x, orig.vector.y, deshake->avg.vector.y, t.vector.y, orig.angle, deshake->avg.angle, t.angle, orig.zoom, deshake->avg.zoom, t.zoom);
510 fwrite(tmp, sizeof(char), strlen(tmp), deshake->fp);
515 t.vector.x += deshake->last.vector.x;
516 t.vector.y += deshake->last.vector.y;
517 t.angle += deshake->last.angle;
518 t.zoom += deshake->last.zoom;
526 deshake->last.vector.x = t.vector.x;
527 deshake->last.vector.y = t.vector.y;
528 deshake->last.angle = t.angle;
529 deshake->last.zoom = t.zoom;
536 ret = deshake->transform(link->dst, link->w, link->h, CHROMA_WIDTH(link), CHROMA_HEIGHT(link),
537 matrix_y, matrix_uv, INTERPOLATE_BILINEAR, deshake->edge, in, out);
540 av_frame_free(&deshake->ref);
547 deshake->ref = in;
571 .name = "deshake",