64 #define CHROMA_WIDTH(link) -((-link->w) >> av_pix_fmt_desc_get(link->format)->log2_chroma_w)
65 #define CHROMA_HEIGHT(link) -((-link->h) >> av_pix_fmt_desc_get(link->format)->log2_chroma_h)
111 #define OFFSET(x) offsetof(DeshakeContext, x)
112 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
137 static int cmp(
const double *
a,
const double *
b)
139 return *a < *b ? -1 : ( *a > *b ? 1 : 0 );
151 qsort(values, count,
sizeof(
double), (
void*)
cmp);
153 for (x = cut; x < count - cut; x++) {
157 return mean / (count - cut * 2);
172 int smallest = INT_MAX;
175 #define CMP(i, j) deshake->c.sad[0](deshake, src1 + cy * stride + cx, \
176 src2 + (j) * stride + (i), stride, \
181 for (y = -deshake->
ry; y <= deshake->ry; y++) {
182 for (x = -deshake->
rx; x <= deshake->rx; x++) {
183 diff =
CMP(cx - x, cy - y);
184 if (diff < smallest) {
193 for (y = -deshake->
ry + 1; y < deshake->ry - 2; y += 2) {
194 for (x = -deshake->
rx + 1; x < deshake->rx - 2; x += 2) {
195 diff =
CMP(cx - x, cy - y);
196 if (diff < smallest) {
208 for (y = tmp2 - 1; y <= tmp2 + 1; y++) {
209 for (x = tmp - 1; x <= tmp + 1; x++) {
210 if (x == tmp && y == tmp2)
213 diff =
CMP(cx - x, cy - y);
214 if (diff < smallest) {
223 if (smallest > 512) {
243 for (i = 0; i <= blocksize * 2; i++) {
245 for (j = 0; i <= 15; i++) {
246 pos = (y - i) * stride + (x - j);
247 if (src[pos] < lowest)
249 else if (src[pos] > highest) {
255 return highest - lowest;
265 a1 = atan2(y - cy, x - cx);
266 a2 = atan2(y - cy + shift->
y, x - cx + shift->
x);
270 return (diff >
M_PI) ? diff - 2 *
M_PI :
287 int counts[128][128];
288 int count_max_value = 0;
292 double *angles =
av_malloc(
sizeof(*angles) * width * height / (16 * deshake->
blocksize));
293 int center_x = 0, center_y = 0;
297 for (x = 0; x < deshake->
rx * 2 + 1; x++) {
298 for (y = 0; y < deshake->
ry * 2 + 1; y++) {
305 for (y = deshake->
ry; y < height - deshake->ry - (deshake->
blocksize * 2); y += deshake->
blocksize * 2) {
307 for (x = deshake->
rx; x < width - deshake->rx - 16; x += 16) {
314 if (mv.
x != -1 && mv.
y != -1) {
315 counts[mv.
x + deshake->
rx][mv.
y + deshake->
ry] += 1;
316 if (x > deshake->
rx && y > deshake->
ry)
330 if (t->
angle < 0.001)
337 for (y = deshake->
ry * 2; y >= 0; y--) {
338 for (x = 0; x < deshake->
rx * 2 + 1; x++) {
340 if (counts[x][y] > count_max_value) {
343 count_max_value = counts[x][
y];
349 p_x = (center_x - width / 2);
350 p_y = (center_y - height / 2);
367 static const char *shorthand[] = {
368 "x",
"y",
"w",
"h",
"rx",
"ry",
"edge",
369 "blocksize",
"contrast",
"search",
"filename",
375 deshake->
class = &deshake_class;
388 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);
392 if (deshake->
cx > 0) {
393 deshake->
cw += deshake->
cx - (deshake->
cx & ~15);
397 av_log(ctx,
AV_LOG_VERBOSE,
"cx: %d, cy: %d, cw: %d, ch: %d, rx: %d, ry: %d, edge: %d blocksize: %d contrast: %d search: %d\n",
398 deshake->
cx, deshake->
cy, deshake->
cw, deshake->
ch,
463 if (deshake->
cx < 0 || deshake->
cy < 0 || deshake->
cw < 0 || deshake->
ch < 0) {
473 if ((
unsigned)deshake->
cx + (
unsigned)deshake->
cw > link->
w) deshake->
cw = link->
w - deshake->
cx;
474 if ((
unsigned)deshake->
cy + (
unsigned)deshake->
ch > link->
h) deshake->
ch = link->
h - deshake->
cy;
489 orig.angle = t.
angle;
512 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);
513 fwrite(tmp,
sizeof(
char), strlen(tmp), deshake->
fp);
585 .priv_class = &deshake_class,