You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
3.5KB

  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/pixdesc.h"
  26. #include "avfilter.h"
  27. #include "internal.h"
  28. #include "video.h"
  29. typedef struct {
  30. int vsub; ///< vertical chroma subsampling
  31. } FlipContext;
  32. static int config_input(AVFilterLink *link)
  33. {
  34. FlipContext *flip = link->dst->priv;
  35. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format);
  36. flip->vsub = desc->log2_chroma_h;
  37. return 0;
  38. }
  39. static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms,
  40. int w, int h)
  41. {
  42. FlipContext *flip = link->dst->priv;
  43. AVFilterBufferRef *picref;
  44. int i;
  45. if (!(perms & AV_PERM_NEG_LINESIZES))
  46. return ff_default_get_video_buffer(link, perms, w, h);
  47. picref = ff_get_video_buffer(link->dst->outputs[0], perms, w, h);
  48. if (!picref)
  49. return NULL;
  50. for (i = 0; i < 4; i ++) {
  51. int vsub = i == 1 || i == 2 ? flip->vsub : 0;
  52. if (picref->data[i]) {
  53. picref->data[i] += (((h + (1<<vsub)-1) >> vsub)-1) * picref->linesize[i];
  54. picref->linesize[i] = -picref->linesize[i];
  55. }
  56. }
  57. return picref;
  58. }
  59. static int start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
  60. {
  61. FlipContext *flip = link->dst->priv;
  62. AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
  63. int i;
  64. if (!outpicref)
  65. return AVERROR(ENOMEM);
  66. for (i = 0; i < 4; i ++) {
  67. int vsub = i == 1 || i == 2 ? flip->vsub : 0;
  68. if (outpicref->data[i]) {
  69. outpicref->data[i] += (((link->h + (1<<vsub)-1)>> vsub)-1) * outpicref->linesize[i];
  70. outpicref->linesize[i] = -outpicref->linesize[i];
  71. }
  72. }
  73. return ff_start_frame(link->dst->outputs[0], outpicref);
  74. }
  75. static int draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
  76. {
  77. AVFilterContext *ctx = link->dst;
  78. return ff_draw_slice(ctx->outputs[0], link->h - (y+h), h, -1 * slice_dir);
  79. }
  80. static const AVFilterPad avfilter_vf_vflip_inputs[] = {
  81. {
  82. .name = "default",
  83. .type = AVMEDIA_TYPE_VIDEO,
  84. .get_video_buffer = get_video_buffer,
  85. .start_frame = start_frame,
  86. .draw_slice = draw_slice,
  87. .config_props = config_input,
  88. },
  89. { NULL }
  90. };
  91. static const AVFilterPad avfilter_vf_vflip_outputs[] = {
  92. {
  93. .name = "default",
  94. .type = AVMEDIA_TYPE_VIDEO,
  95. },
  96. { NULL }
  97. };
  98. AVFilter avfilter_vf_vflip = {
  99. .name = "vflip",
  100. .description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
  101. .priv_size = sizeof(FlipContext),
  102. .inputs = avfilter_vf_vflip_inputs,
  103. .outputs = avfilter_vf_vflip_outputs,
  104. };