vf_vflip.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * copyright (c) 2007 Bobby Bingham
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file
  22. * video vertical flip filter
  23. */
  24. #include "libavutil/pixdesc.h"
  25. #include "avfilter.h"
  26. typedef struct {
  27. int vsub; ///< vertical chroma subsampling
  28. } FlipContext;
  29. static int config_input(AVFilterLink *link)
  30. {
  31. FlipContext *flip = link->dst->priv;
  32. flip->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;
  33. return 0;
  34. }
  35. static AVFilterPicRef *get_video_buffer(AVFilterLink *link, int perms,
  36. int w, int h)
  37. {
  38. FlipContext *flip = link->dst->priv;
  39. int i;
  40. AVFilterPicRef *picref = avfilter_get_video_buffer(link->dst->outputs[0],
  41. perms, w, h);
  42. for (i = 0; i < 4; i ++) {
  43. int vsub = i == 1 || i == 2 ? flip->vsub : 0;
  44. if (picref->data[i]) {
  45. picref->data[i] += ((h >> vsub)-1) * picref->linesize[i];
  46. picref->linesize[i] = -picref->linesize[i];
  47. }
  48. }
  49. return picref;
  50. }
  51. static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
  52. {
  53. FlipContext *flip = link->dst->priv;
  54. int i;
  55. for (i = 0; i < 4; i ++) {
  56. int vsub = i == 1 || i == 2 ? flip->vsub : 0;
  57. if (picref->data[i]) {
  58. picref->data[i] += ((link->h >> vsub)-1) * picref->linesize[i];
  59. picref->linesize[i] = -picref->linesize[i];
  60. }
  61. }
  62. avfilter_start_frame(link->dst->outputs[0], picref);
  63. }
  64. static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
  65. {
  66. AVFilterContext *ctx = link->dst;
  67. avfilter_draw_slice(ctx->outputs[0], link->h - (y+h), h, -1 * slice_dir);
  68. }
  69. AVFilter avfilter_vf_vflip = {
  70. .name = "vflip",
  71. .description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
  72. .priv_size = sizeof(FlipContext),
  73. .inputs = (AVFilterPad[]) {{ .name = "default",
  74. .type = AVMEDIA_TYPE_VIDEO,
  75. .get_video_buffer = get_video_buffer,
  76. .start_frame = start_frame,
  77. .draw_slice = draw_slice,
  78. .end_frame = avfilter_null_end_frame,
  79. .config_props = config_input, },
  80. { .name = NULL}},
  81. .outputs = (AVFilterPad[]) {{ .name = "default",
  82. .type = AVMEDIA_TYPE_VIDEO, },
  83. { .name = NULL}},
  84. };