63 #define CHROMA_WIDTH(link) -((-link->w) >> av_pix_fmt_desc_get(link->format)->log2_chroma_w)
64 #define CHROMA_HEIGHT(link) -((-link->h) >> av_pix_fmt_desc_get(link->format)->log2_chroma_h)
109 static int cmp(
const double *
a,
const double *
b)
111 return *a < *b ? -1 : ( *a > *b ? 1 : 0 );
123 qsort(values, count,
sizeof(
double), (
void*)
cmp);
125 for (x = cut; x < count - cut; x++) {
129 return mean / (count - cut * 2);
144 int smallest = INT_MAX;
147 #define CMP(i, j) deshake->c.sad[0](deshake, src1 + cy * stride + cx, \
148 src2 + (j) * stride + (i), stride, \
153 for (y = -deshake->
ry; y <= deshake->ry; y++) {
154 for (x = -deshake->
rx; x <= deshake->rx; x++) {
155 diff =
CMP(cx - x, cy - y);
156 if (diff < smallest) {
165 for (y = -deshake->
ry + 1; y < deshake->ry - 2; y += 2) {
166 for (x = -deshake->
rx + 1; x < deshake->rx - 2; x += 2) {
167 diff =
CMP(cx - x, cy - y);
168 if (diff < smallest) {
180 for (y = tmp2 - 1; y <= tmp2 + 1; y++) {
181 for (x = tmp - 1; x <= tmp + 1; x++) {
182 if (x == tmp && y == tmp2)
185 diff =
CMP(cx - x, cy - y);
186 if (diff < smallest) {
195 if (smallest > 512) {
215 for (i = 0; i <= blocksize * 2; i++) {
217 for (j = 0; i <= 15; i++) {
218 pos = (y - i) * stride + (x - j);
219 if (src[pos] < lowest)
221 else if (src[pos] > highest) {
227 return highest - lowest;
237 a1 = atan2(y - cy, x - cx);
238 a2 = atan2(y - cy + shift->
y, x - cx + shift->
x);
242 return (diff >
M_PI) ? diff - 2 *
M_PI :
259 int counts[128][128];
260 int count_max_value = 0;
264 double *angles =
av_malloc(
sizeof(*angles) * width * height / (16 * deshake->
blocksize));
265 int center_x = 0, center_y = 0;
269 for (x = 0; x < deshake->
rx * 2 + 1; x++) {
270 for (y = 0; y < deshake->
ry * 2 + 1; y++) {
277 for (y = deshake->
ry; y < height - deshake->ry - (deshake->
blocksize * 2); y += deshake->
blocksize * 2) {
279 for (x = deshake->
rx; x < width - deshake->rx - 16; x += 16) {
286 if (mv.
x != -1 && mv.
y != -1) {
287 counts[mv.
x + deshake->
rx][mv.
y + deshake->
ry] += 1;
288 if (x > deshake->
rx && y > deshake->
ry)
302 if (t->
angle < 0.001)
309 for (y = deshake->
ry * 2; y >= 0; y--) {
310 for (x = 0; x < deshake->
rx * 2 + 1; x++) {
312 if (counts[x][y] > count_max_value) {
315 count_max_value = counts[x][y];
321 p_x = (center_x - width / 2);
322 p_y = (center_y - height / 2);
338 char filename[256] = {0};
354 sscanf(args,
"%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%255s",
355 &deshake->
cx, &deshake->
cy, &deshake->
cw, &deshake->
ch,
356 &deshake->
rx, &deshake->
ry, &deshake->
edge,
361 deshake->
rx = av_clip(deshake->
rx, 0, 64);
362 deshake->
ry = av_clip(deshake->
ry, 0, 64);
370 deshake->
fp = fopen(filename,
"w");
372 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);
376 if (deshake->
cx > 0) {
377 deshake->
cw += deshake->
cx - (deshake->
cx & ~15);
381 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",
382 deshake->
cx, deshake->
cy, deshake->
cw, deshake->
ch,
436 float alpha = 2.0 / deshake->
refcount;
446 if (deshake->
cx < 0 || deshake->
cy < 0 || deshake->
cw < 0 || deshake->
ch < 0) {
456 if ((
unsigned)deshake->
cx + (
unsigned)deshake->
cw > link->
w) deshake->
cw = link->
w - deshake->
cx;
457 if ((
unsigned)deshake->
cy + (
unsigned)deshake->
ch > link->
h) deshake->
ch = link->
h - deshake->
cy;
472 orig.angle = t.
angle;
495 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);
496 fwrite(tmp,
sizeof(
char), strlen(tmp), deshake->
fp);