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.

113 lines
3.1KB

  1. /*
  2. * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
  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. * swap UV filter
  23. */
  24. #include "libavutil/pixdesc.h"
  25. #include "avfilter.h"
  26. #include "formats.h"
  27. #include "internal.h"
  28. #include "video.h"
  29. static void do_swap(AVFrame *frame)
  30. {
  31. FFSWAP(uint8_t*, frame->data[1], frame->data[2]);
  32. FFSWAP(int, frame->linesize[1], frame->linesize[2]);
  33. FFSWAP(uint8_t*, frame->base[1], frame->base[2]);
  34. FFSWAP(uint64_t, frame->error[1], frame->error[2]);
  35. FFSWAP(AVBufferRef*, frame->buf[1], frame->buf[2]);
  36. }
  37. static AVFrame *get_video_buffer(AVFilterLink *link, int w, int h)
  38. {
  39. AVFrame *picref = ff_default_get_video_buffer(link, w, h);
  40. do_swap(picref);
  41. return picref;
  42. }
  43. static int filter_frame(AVFilterLink *link, AVFrame *inpicref)
  44. {
  45. do_swap(inpicref);
  46. return ff_filter_frame(link->dst->outputs[0], inpicref);
  47. }
  48. static int is_planar_yuv(const AVPixFmtDescriptor *desc)
  49. {
  50. int i;
  51. if (desc->flags & ~(PIX_FMT_BE | PIX_FMT_PLANAR | PIX_FMT_ALPHA) ||
  52. desc->nb_components < 3 ||
  53. (desc->comp[1].depth_minus1 != desc->comp[2].depth_minus1))
  54. return 0;
  55. for (i = 0; i < desc->nb_components; i++) {
  56. if (desc->comp[i].offset_plus1 != 1 ||
  57. desc->comp[i].shift != 0 ||
  58. desc->comp[i].plane != i)
  59. return 0;
  60. }
  61. return 1;
  62. }
  63. static int query_formats(AVFilterContext *ctx)
  64. {
  65. AVFilterFormats *formats = NULL;
  66. int fmt;
  67. for (fmt = 0; fmt < AV_PIX_FMT_NB; fmt++) {
  68. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
  69. if (is_planar_yuv(desc))
  70. ff_add_format(&formats, fmt);
  71. }
  72. ff_set_common_formats(ctx, formats);
  73. return 0;
  74. }
  75. static const AVFilterPad swapuv_inputs[] = {
  76. {
  77. .name = "default",
  78. .type = AVMEDIA_TYPE_VIDEO,
  79. .get_video_buffer = get_video_buffer,
  80. .filter_frame = filter_frame,
  81. },
  82. { NULL }
  83. };
  84. static const AVFilterPad swapuv_outputs[] = {
  85. {
  86. .name = "default",
  87. .type = AVMEDIA_TYPE_VIDEO,
  88. },
  89. { NULL }
  90. };
  91. AVFilter avfilter_vf_swapuv = {
  92. .name = "swapuv",
  93. .description = NULL_IF_CONFIG_SMALL("Swap U and V components."),
  94. .priv_size = 0,
  95. .query_formats = query_formats,
  96. .inputs = swapuv_inputs,
  97. .outputs = swapuv_outputs,
  98. };