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.

111 lines
3.0KB

  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 AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms,
  30. int w, int h)
  31. {
  32. AVFilterBufferRef *picref =
  33. ff_default_get_video_buffer(link, perms, w, h);
  34. FFSWAP(uint8_t*, picref->data[1], picref->data[2]);
  35. FFSWAP(int, picref->linesize[1], picref->linesize[2]);
  36. return picref;
  37. }
  38. static int filter_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
  39. {
  40. FFSWAP(uint8_t*, inpicref->data[1], inpicref->data[2]);
  41. FFSWAP(int, inpicref->linesize[1], inpicref->linesize[2]);
  42. return ff_filter_frame(link->dst->outputs[0], inpicref);
  43. }
  44. static int is_planar_yuv(const AVPixFmtDescriptor *desc)
  45. {
  46. int i;
  47. if (desc->flags & ~(PIX_FMT_BE | PIX_FMT_PLANAR | PIX_FMT_ALPHA) ||
  48. desc->nb_components < 3 ||
  49. (desc->comp[1].depth_minus1 != desc->comp[2].depth_minus1))
  50. return 0;
  51. for (i = 0; i < desc->nb_components; i++) {
  52. if (desc->comp[i].offset_plus1 != 1 ||
  53. desc->comp[i].shift != 0 ||
  54. desc->comp[i].plane != i)
  55. return 0;
  56. }
  57. return 1;
  58. }
  59. static int query_formats(AVFilterContext *ctx)
  60. {
  61. AVFilterFormats *formats = NULL;
  62. int fmt;
  63. for (fmt = 0; fmt < AV_PIX_FMT_NB; fmt++) {
  64. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
  65. if (is_planar_yuv(desc))
  66. ff_add_format(&formats, fmt);
  67. }
  68. ff_set_common_formats(ctx, formats);
  69. return 0;
  70. }
  71. static const AVFilterPad swapuv_inputs[] = {
  72. {
  73. .name = "default",
  74. .type = AVMEDIA_TYPE_VIDEO,
  75. .get_video_buffer = get_video_buffer,
  76. .filter_frame = filter_frame,
  77. },
  78. { NULL }
  79. };
  80. static const AVFilterPad swapuv_outputs[] = {
  81. {
  82. .name = "default",
  83. .type = AVMEDIA_TYPE_VIDEO,
  84. },
  85. { NULL }
  86. };
  87. AVFilter avfilter_vf_swapuv = {
  88. .name = "swapuv",
  89. .description = NULL_IF_CONFIG_SMALL("Swap U and V components."),
  90. .priv_size = 0,
  91. .query_formats = query_formats,
  92. .inputs = swapuv_inputs,
  93. .outputs = swapuv_outputs,
  94. };