vf_vflip.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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/internal.h"
  25. #include "libavutil/opt.h"
  26. #include "libavutil/pixdesc.h"
  27. #include "avfilter.h"
  28. #include "internal.h"
  29. #include "video.h"
  30. typedef struct FlipContext {
  31. const AVClass *class;
  32. int vsub; ///< vertical chroma subsampling
  33. } FlipContext;
  34. static const AVOption vflip_options[] = {
  35. { NULL }
  36. };
  37. AVFILTER_DEFINE_CLASS(vflip);
  38. static int config_input(AVFilterLink *link)
  39. {
  40. FlipContext *flip = link->dst->priv;
  41. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format);
  42. flip->vsub = desc->log2_chroma_h;
  43. return 0;
  44. }
  45. static AVFrame *get_video_buffer(AVFilterLink *link, int w, int h)
  46. {
  47. FlipContext *flip = link->dst->priv;
  48. AVFrame *frame;
  49. int i;
  50. frame = ff_get_video_buffer(link->dst->outputs[0], w, h);
  51. if (!frame)
  52. return NULL;
  53. for (i = 0; i < 4; i ++) {
  54. int vsub = i == 1 || i == 2 ? flip->vsub : 0;
  55. int height = AV_CEIL_RSHIFT(h, vsub);
  56. if (frame->data[i]) {
  57. frame->data[i] += (height - 1) * frame->linesize[i];
  58. frame->linesize[i] = -frame->linesize[i];
  59. }
  60. }
  61. return frame;
  62. }
  63. static int filter_frame(AVFilterLink *link, AVFrame *frame)
  64. {
  65. FlipContext *flip = link->dst->priv;
  66. int i;
  67. for (i = 0; i < 4; i ++) {
  68. int vsub = i == 1 || i == 2 ? flip->vsub : 0;
  69. int height = AV_CEIL_RSHIFT(link->h, vsub);
  70. if (frame->data[i]) {
  71. frame->data[i] += (height - 1) * frame->linesize[i];
  72. frame->linesize[i] = -frame->linesize[i];
  73. }
  74. }
  75. return ff_filter_frame(link->dst->outputs[0], frame);
  76. }
  77. static const AVFilterPad avfilter_vf_vflip_inputs[] = {
  78. {
  79. .name = "default",
  80. .type = AVMEDIA_TYPE_VIDEO,
  81. .get_video_buffer = get_video_buffer,
  82. .filter_frame = filter_frame,
  83. .config_props = config_input,
  84. },
  85. { NULL }
  86. };
  87. static const AVFilterPad avfilter_vf_vflip_outputs[] = {
  88. {
  89. .name = "default",
  90. .type = AVMEDIA_TYPE_VIDEO,
  91. },
  92. { NULL }
  93. };
  94. AVFilter ff_vf_vflip = {
  95. .name = "vflip",
  96. .description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
  97. .priv_size = sizeof(FlipContext),
  98. .priv_class = &vflip_class,
  99. .inputs = avfilter_vf_vflip_inputs,
  100. .outputs = avfilter_vf_vflip_outputs,
  101. .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
  102. };