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.

115 lines
3.6KB

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