| @@ -18,6 +18,7 @@ · 17 unmodified lines |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ | 19 | */ |
| 20 | | 20 | |
| | 21 | #include "libavutil/avassert.h" |
| 21 | #include "libavutil/colorspace.h" | 22 | #include "libavutil/colorspace.h" |
| 22 | #include "libavutil/common.h" | 23 | #include "libavutil/common.h" |
| 23 | #include "libavutil/opt.h" | 24 | #include "libavutil/opt.h" |
| @@ -31,7 +32,7 @@ · 7 unmodified lines |
| 31 | enum { Y, U, V, A }; | 32 | enum { Y, U, V, A }; |
| 32 | enum { R, G, B }; | 33 | enum { R, G, B }; |
| 33 | | 34 | |
| 34 | enum FillMode { FM_SMEAR, FM_MIRROR, FM_FIXED, FM_NB_MODES }; | 35 | enum FillMode { FM_SMEAR, FM_MIRROR, FM_FIXED, FM_REFLECT, FM_WRAP, FM_NB_MODES }; |
| 35 | | 36 | |
| 36 | typedef struct Borders { | 37 | typedef struct Borders { |
| 37 | int left, right, top, bottom; | 38 | int left, right, top, bottom; |
| @@ -269,6 +270,138 @@ static void fixed_borders16(FillBordersContext *s, AVFrame *frame) · 231 unmodified lines |
| 269 | } | 270 | } |
| 270 | } | 271 | } |
| 271 | | 272 | |
| | 273 | static void reflect_borders8(FillBordersContext *s, AVFrame *frame) |
| | 274 | { |
| | 275 | int p, y, x; |
| | 276 | |
| | 277 | for (p = 0; p < s->nb_planes; p++) { |
| | 278 | uint8_t *ptr = frame->data[p]; |
| | 279 | int linesize = frame->linesize[p]; |
| | 280 | |
| | 281 | for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) { |
| | 282 | for (x = 0; x < s->borders[p].left; x++) { |
| | 283 | ptr[y * linesize + x] = ptr[y * linesize + s->borders[p].left * 2 - x]; |
| | 284 | } |
| | 285 | |
| | 286 | for (x = 0; x < s->borders[p].right; x++) { |
| | 287 | ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] = |
| | 288 | ptr[y * linesize + s->planewidth[p] - s->borders[p].right - 2 - x]; |
| | 289 | } |
| | 290 | } |
| | 291 | |
| | 292 | for (y = 0; y < s->borders[p].top; y++) { |
| | 293 | memcpy(ptr + y * linesize, |
| | 294 | ptr + (s->borders[p].top * 2 - y) * linesize, |
| | 295 | s->planewidth[p]); |
| | 296 | } |
| | 297 | |
| | 298 | for (y = 0; y < s->borders[p].bottom; y++) { |
| | 299 | memcpy(ptr + (s->planeheight[p] - s->borders[p].bottom + y) * linesize, |
| | 300 | ptr + (s->planeheight[p] - s->borders[p].bottom - 2 - y) * linesize, |
| | 301 | s->planewidth[p]); |
| | 302 | } |
| | 303 | } |
| | 304 | } |
| | 305 | |
| | 306 | static void reflect_borders16(FillBordersContext *s, AVFrame *frame) |
| | 307 | { |
| | 308 | int p, y, x; |
| | 309 | |
| | 310 | for (p = 0; p < s->nb_planes; p++) { |
| | 311 | uint16_t *ptr = (uint16_t *)frame->data[p]; |
| | 312 | int linesize = frame->linesize[p] / 2; |
| | 313 | |
| | 314 | for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) { |
| | 315 | for (x = 0; x < s->borders[p].left; x++) { |
| | 316 | ptr[y * linesize + x] = ptr[y * linesize + s->borders[p].left * 2 - x]; |
| | 317 | } |
| | 318 | |
| | 319 | for (x = 0; x < s->borders[p].right; x++) { |
| | 320 | ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] = |
| | 321 | ptr[y * linesize + s->planewidth[p] - s->borders[p].right - 2 - x]; |
| | 322 | } |
| | 323 | } |
| | 324 | |
| | 325 | for (y = 0; y < s->borders[p].top; y++) { |
| | 326 | memcpy(ptr + y * linesize, |
| | 327 | ptr + (s->borders[p].top * 2 - y) * linesize, |
| | 328 | s->planewidth[p] * 2); |
| | 329 | } |
| | 330 | |
| | 331 | for (y = 0; y < s->borders[p].bottom; y++) { |
| | 332 | memcpy(ptr + (s->planeheight[p] - s->borders[p].bottom + y) * linesize, |
| | 333 | ptr + (s->planeheight[p] - s->borders[p].bottom - 2 - y) * linesize, |
| | 334 | s->planewidth[p] * 2); |
| | 335 | } |
| | 336 | } |
| | 337 | } |
| | 338 | |
| | 339 | static void wrap_borders8(FillBordersContext *s, AVFrame *frame) |
| | 340 | { |
| | 341 | int p, y, x; |
| | 342 | |
| | 343 | for (p = 0; p < s->nb_planes; p++) { |
| | 344 | uint8_t *ptr = frame->data[p]; |
| | 345 | int linesize = frame->linesize[p]; |
| | 346 | |
| | 347 | for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) { |
| | 348 | for (x = 0; x < s->borders[p].left; x++) { |
| | 349 | ptr[y * linesize + x] = ptr[y * linesize + s->planewidth[p] - s->borders[p].right - s->borders[p].left + x]; |
| | 350 | } |
| | 351 | |
| | 352 | for (x = 0; x < s->borders[p].right; x++) { |
| | 353 | ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] = |
| | 354 | ptr[y * linesize + s->borders[p].left + x]; |
| | 355 | } |
| | 356 | } |
| | 357 | |
| | 358 | for (y = 0; y < s->borders[p].top; y++) { |
| | 359 | memcpy(ptr + y * linesize, |
| | 360 | ptr + (s->planeheight[p] - s->borders[p].bottom - s->borders[p].top + y) * linesize, |
| | 361 | s->planewidth[p]); |
| | 362 | } |
| | 363 | |
| | 364 | for (y = 0; y < s->borders[p].bottom; y++) { |
| | 365 | memcpy(ptr + (s->planeheight[p] - s->borders[p].bottom + y) * linesize, |
| | 366 | ptr + (s->borders[p].top + y) * linesize, |
| | 367 | s->planewidth[p]); |
| | 368 | } |
| | 369 | } |
| | 370 | } |
| | 371 | |
| | 372 | static void wrap_borders16(FillBordersContext *s, AVFrame *frame) |
| | 373 | { |
| | 374 | int p, y, x; |
| | 375 | |
| | 376 | for (p = 0; p < s->nb_planes; p++) { |
| | 377 | uint16_t *ptr = (uint16_t *)frame->data[p]; |
| | 378 | int linesize = frame->linesize[p] / 2; |
| | 379 | |
| | 380 | for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) { |
| | 381 | for (x = 0; x < s->borders[p].left; x++) { |
| | 382 | ptr[y * linesize + x] = ptr[y * linesize + s->planewidth[p] - s->borders[p].right - s->borders[p].left + x]; |
| | 383 | } |
| | 384 | |
| | 385 | for (x = 0; x < s->borders[p].right; x++) { |
| | 386 | ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] = |
| | 387 | ptr[y * linesize + s->borders[p].left + x]; |
| | 388 | } |
| | 389 | } |
| | 390 | |
| | 391 | for (y = 0; y < s->borders[p].top; y++) { |
| | 392 | memcpy(ptr + y * linesize, |
| | 393 | ptr + (s->planeheight[p] - s->borders[p].bottom - s->borders[p].top + y) * linesize, |
| | 394 | s->planewidth[p] * 2); |
| | 395 | } |
| | 396 | |
| | 397 | for (y = 0; y < s->borders[p].bottom; y++) { |
| | 398 | memcpy(ptr + (s->planeheight[p] - s->borders[p].bottom + y) * linesize, |
| | 399 | ptr + (s->borders[p].top + y) * linesize, |
| | 400 | s->planewidth[p] * 2); |
| | 401 | } |
| | 402 | } |
| | 403 | } |
| | 404 | |
| 272 | static int filter_frame(AVFilterLink *inlink, AVFrame *frame) | 405 | static int filter_frame(AVFilterLink *inlink, AVFrame *frame) |
| 273 | { | 406 | { |
| 274 | FillBordersContext *s = inlink->dst->priv; | 407 | FillBordersContext *s = inlink->dst->priv; |
| @@ -325,6 +458,9 @@ static int config_input(AVFilterLink *inlink) · 50 unmodified lines |
| 325 | case FM_SMEAR: s->fillborders = s->depth <= 8 ? smear_borders8 : smear_borders16; break; | 458 | case FM_SMEAR: s->fillborders = s->depth <= 8 ? smear_borders8 : smear_borders16; break; |
| 326 | case FM_MIRROR: s->fillborders = s->depth <= 8 ? mirror_borders8 : mirror_borders16; break; | 459 | case FM_MIRROR: s->fillborders = s->depth <= 8 ? mirror_borders8 : mirror_borders16; break; |
| 327 | case FM_FIXED: s->fillborders = s->depth <= 8 ? fixed_borders8 : fixed_borders16; break; | 460 | case FM_FIXED: s->fillborders = s->depth <= 8 ? fixed_borders8 : fixed_borders16; break; |
| | 461 | case FM_REFLECT:s->fillborders = s->depth <= 8 ? reflect_borders8: reflect_borders16;break; |
| | 462 | case FM_WRAP: s->fillborders = s->depth <= 8 ? wrap_borders8 : wrap_borders16; break; |
| | 463 | default: av_assert0(0); |
| 328 | } | 464 | } |
| 329 | | 465 | |
| 330 | s->yuv_color[Y] = RGB_TO_Y_CCIR(s->rgba_color[R], s->rgba_color[G], s->rgba_color[B]); | 466 | s->yuv_color[Y] = RGB_TO_Y_CCIR(s->rgba_color[R], s->rgba_color[G], s->rgba_color[B]); |
| @@ -370,6 +506,8 @@ static const AVOption fillborders_options[] = { · 39 unmodified lines |
| 370 | { "smear", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_SMEAR}, 0, 0, FLAGS, "mode" }, | 506 | { "smear", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_SMEAR}, 0, 0, FLAGS, "mode" }, |
| 371 | { "mirror", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_MIRROR}, 0, 0, FLAGS, "mode" }, | 507 | { "mirror", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_MIRROR}, 0, 0, FLAGS, "mode" }, |
| 372 | { "fixed", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_FIXED}, 0, 0, FLAGS, "mode" }, | 508 | { "fixed", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_FIXED}, 0, 0, FLAGS, "mode" }, |
| | 509 | { "reflect",NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_REFLECT},0, 0, FLAGS, "mode" }, |
| | 510 | { "wrap", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_WRAP}, 0, 0, FLAGS, "mode" }, |
| 373 | { "color", "set the color for the fixed mode", OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str = "black"}, .flags = FLAGS }, | 511 | { "color", "set the color for the fixed mode", OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str = "black"}, .flags = FLAGS }, |
| 374 | { NULL } | 512 | { NULL } |
| 375 | }; | 513 | }; |