| @@ -72,7 +72,8 @@ static const enum AVPixelFormat pix_fmts[] = { · 71 unmodified lines |
| 72 | AV_PIX_FMT_NONE | 72 | AV_PIX_FMT_NONE |
| 73 | }; | 73 | }; |
| 74 | | 74 | |
| 75 | #define SQR(x) ((x)*(x)) | 75 | #define MANHATTAN_DISTANCE(x, y, z) ((x) + (y) + (z)) |
| | 76 | #define EUCLIDEAN_DISTANCE(x, y, z) (sqrtf((x)*(x) + (y)*(y) + (z)*(z))) |
| 76 | | 77 | |
| 77 | #define FILTER_FUNC(distance, name, ctype, type, fun) \ | 78 | #define FILTER_FUNC(distance, name, ctype, type, fun) \ |
| 78 | static int distance ## _slice##name(AVFilterContext *ctx, void *arg, \ | 79 | static int distance ## _slice##name(AVFilterContext *ctx, void *arg, \ |
| @@ -136,19 +137,22 @@ static int distance ## _slice##name(AVFilterContext *ctx, void *arg, · 57 unmodified lines |
| 136 | int sv = cv; \ | 137 | int sv = cv; \ |
| 137 | int cn = 1; \ | 138 | int cn = 1; \ |
| 138 | \ | 139 | \ |
| 139 | for (int yy = FFMAX(0, y - sizeh); yy < FFMIN(y + sizeh, h); yy += steph) { \ | 140 | for (int yy = FFMAX(0, y - sizeh); yy <= FFMIN(y + sizeh, h - 1); yy += steph) { \ |
| 140 | const type *in_yptr = (const type *)(in->data[0] + yy * chroma_h * in_ylinesize); \ | 141 | const type *in_yptr = (const type *)(in->data[0] + yy * chroma_h * in_ylinesize); \ |
| 141 | const type *in_uptr = (const type *)(in->data[1] + yy * in_ulinesize); \ | 142 | const type *in_uptr = (const type *)(in->data[1] + yy * in_ulinesize); \ |
| 142 | const type *in_vptr = (const type *)(in->data[2] + yy * in_vlinesize); \ | 143 | const type *in_vptr = (const type *)(in->data[2] + yy * in_vlinesize); \ |
| 143 | \ | 144 | \ |
| 144 | for (int xx = FFMAX(0, x - sizew); xx < FFMIN(x + sizew, w); xx += stepw) { \ | 145 | for (int xx = FFMAX(0, x - sizew); xx <= FFMIN(x + sizew, w - 1); xx += stepw) { \ |
| 145 | const ctype Y = in_yptr[xx * chroma_w]; \ | 146 | const ctype Y = in_yptr[xx * chroma_w]; \ |
| 146 | const ctype U = in_uptr[xx]; \ | 147 | const ctype U = in_uptr[xx]; \ |
| 147 | const ctype V = in_vptr[xx]; \ | 148 | const ctype V = in_vptr[xx]; \ |
| | 149 | const ctype cyY = FFABS(cy - Y); \ |
| | 150 | const ctype cuU = FFABS(cu - U); \ |
| | 151 | const ctype cvV = FFABS(cv - V); \ |
| 148 | \ | 152 | \ |
| 149 | if (fun(cu - U) + fun(cv - V) + fun(cy - Y) < thres && \ | 153 | if (fun(cyY, cuU, cvV) < thres && \ |
| 150 | fun(cu - U) < thres_u && fun(cv - V) < thres_v && \ | 154 | cuU < thres_u && cvV < thres_v && \ |
| 151 | fun(cy - Y) < thres_y && \ | 155 | cyY < thres_y && \ |
| 152 | xx != x && yy != y) { \ | 156 | xx != x && yy != y) { \ |
| 153 | su += U; \ | 157 | su += U; \ |
| 154 | sv += V; \ | 158 | sv += V; \ |
| @@ -168,11 +172,11 @@ static int distance ## _slice##name(AVFilterContext *ctx, void *arg, · 13 unmodified lines |
| 168 | return 0; \ | 172 | return 0; \ |
| 169 | } | 173 | } |
| 170 | | 174 | |
| 171 | FILTER_FUNC(manhattan, 8, int, uint8_t, FFABS) | 175 | FILTER_FUNC(manhattan, 8, int, uint8_t, MANHATTAN_DISTANCE) |
| 172 | FILTER_FUNC(manhattan, 16, int, uint16_t, FFABS) | 176 | FILTER_FUNC(manhattan, 16, int, uint16_t, MANHATTAN_DISTANCE) |
| 173 | | 177 | |
| 174 | FILTER_FUNC(euclidean, 8, int, uint8_t, SQR) | 178 | FILTER_FUNC(euclidean, 8, int, uint8_t, EUCLIDEAN_DISTANCE) |
| 175 | FILTER_FUNC(euclidean, 16, int64_t, uint16_t, SQR) | 179 | FILTER_FUNC(euclidean, 16, int64_t, uint16_t, EUCLIDEAN_DISTANCE) |
| 176 | | 180 | |
| 177 | static int filter_frame(AVFilterLink *inlink, AVFrame *in) | 181 | static int filter_frame(AVFilterLink *inlink, AVFrame *in) |
| 178 | { | 182 | { |
| @@ -238,14 +242,14 @@ static int config_input(AVFilterLink *inlink) · 59 unmodified lines |
| 238 | #define VF AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM | 242 | #define VF AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM |
| 239 | | 243 | |
| 240 | static const AVOption chromanr_options[] = { | 244 | static const AVOption chromanr_options[] = { |
| 241 | { "thres", "set y+u+v threshold", OFFSET(threshold), AV_OPT_TYPE_FLOAT, {.dbl=30}, 1, 5000, VF }, | 245 | { "thres", "set y+u+v threshold", OFFSET(threshold), AV_OPT_TYPE_FLOAT, {.dbl=30}, 1, 200, VF }, |
| 242 | { "sizew", "set horizontal size", OFFSET(sizew), AV_OPT_TYPE_INT, {.i64=5}, 1, 100, VF }, | 246 | { "sizew", "set horizontal size", OFFSET(sizew), AV_OPT_TYPE_INT, {.i64=5}, 1, 100, VF }, |
| 243 | { "sizeh", "set vertical size", OFFSET(sizeh), AV_OPT_TYPE_INT, {.i64=5}, 1, 100, VF }, | 247 | { "sizeh", "set vertical size", OFFSET(sizeh), AV_OPT_TYPE_INT, {.i64=5}, 1, 100, VF }, |
| 244 | { "stepw", "set horizontal step", OFFSET(stepw), AV_OPT_TYPE_INT, {.i64=1}, 1, 50, VF }, | 248 | { "stepw", "set horizontal step", OFFSET(stepw), AV_OPT_TYPE_INT, {.i64=1}, 1, 50, VF }, |
| 245 | { "steph", "set vertical step", OFFSET(steph), AV_OPT_TYPE_INT, {.i64=1}, 1, 50, VF }, | 249 | { "steph", "set vertical step", OFFSET(steph), AV_OPT_TYPE_INT, {.i64=1}, 1, 50, VF }, |
| 246 | { "threy", "set y threshold", OFFSET(threshold_y), AV_OPT_TYPE_FLOAT, {.dbl=5000},1, 5000, VF }, | 250 | { "threy", "set y threshold", OFFSET(threshold_y), AV_OPT_TYPE_FLOAT, {.dbl=200},1, 200, VF }, |
| 247 | { "threu", "set u threshold", OFFSET(threshold_u), AV_OPT_TYPE_FLOAT, {.dbl=5000},1, 5000, VF }, | 251 | { "threu", "set u threshold", OFFSET(threshold_u), AV_OPT_TYPE_FLOAT, {.dbl=200},1, 200, VF }, |
| 248 | { "threv", "set v threshold", OFFSET(threshold_v), AV_OPT_TYPE_FLOAT, {.dbl=5000},1, 5000, VF }, | 252 | { "threv", "set v threshold", OFFSET(threshold_v), AV_OPT_TYPE_FLOAT, {.dbl=200},1, 200, VF }, |
| 249 | { "distance", "set distance type", OFFSET(distance), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, VF, "distance" }, | 253 | { "distance", "set distance type", OFFSET(distance), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, VF, "distance" }, |
| 250 | { "manhattan", "", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, VF, "distance" }, | 254 | { "manhattan", "", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, VF, "distance" }, |
| 251 | { "euclidean", "", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, VF, "distance" }, | 255 | { "euclidean", "", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, VF, "distance" }, |