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.

109 lines
3.4KB

  1. /*
  2. * Copyright (c) 2007 Bobby Bingham
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; 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. for (i = 0; i < 4; i ++) {
  47. int vsub = i == 1 || i == 2 ? flip->vsub : 0;
  48. if (picref->data[i]) {
  49. picref->data[i] += ((h >> vsub)-1) * picref->linesize[i];
  50. picref->linesize[i] = -picref->linesize[i];
  51. }
  52. }
  53. return picref;
  54. }
  55. static void start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
  56. {
  57. FlipContext *flip = link->dst->priv;
  58. AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
  59. int i;
  60. for (i = 0; i < 4; i ++) {
  61. int vsub = i == 1 || i == 2 ? flip->vsub : 0;
  62. if (outpicref->data[i]) {
  63. outpicref->data[i] += ((link->h >> vsub)-1) * outpicref->linesize[i];
  64. outpicref->linesize[i] = -outpicref->linesize[i];
  65. }
  66. }
  67. ff_start_frame(link->dst->outputs[0], outpicref);
  68. }
  69. static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
  70. {
  71. AVFilterContext *ctx = link->dst;
  72. ff_draw_slice(ctx->outputs[0], link->h - (y+h), h, -1 * slice_dir);
  73. }
  74. AVFilter avfilter_vf_vflip = {
  75. .name = "vflip",
  76. .description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
  77. .priv_size = sizeof(FlipContext),
  78. .inputs = (AVFilterPad[]) {{ .name = "default",
  79. .type = AVMEDIA_TYPE_VIDEO,
  80. .get_video_buffer = get_video_buffer,
  81. .start_frame = start_frame,
  82. .draw_slice = draw_slice,
  83. .config_props = config_input, },
  84. { .name = NULL}},
  85. .outputs = (AVFilterPad[]) {{ .name = "default",
  86. .type = AVMEDIA_TYPE_VIDEO, },
  87. { .name = NULL}},
  88. };