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.

92 lines
2.6KB

  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 "avfilter.h"
  25. #include "formats.h"
  26. #include "internal.h"
  27. #include "video.h"
  28. static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms,
  29. int w, int h)
  30. {
  31. AVFilterBufferRef *picref =
  32. ff_default_get_video_buffer(link, perms, w, h);
  33. FFSWAP(uint8_t*, picref->data[1], picref->data[2]);
  34. FFSWAP(int, picref->linesize[1], picref->linesize[2]);
  35. return picref;
  36. }
  37. static int filter_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
  38. {
  39. FFSWAP(uint8_t*, inpicref->data[1], inpicref->data[2]);
  40. FFSWAP(int, inpicref->linesize[1], inpicref->linesize[2]);
  41. return ff_filter_frame(link->dst->outputs[0], inpicref);
  42. }
  43. static int query_formats(AVFilterContext *ctx)
  44. {
  45. static const enum AVPixelFormat pix_fmts[] = {
  46. AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVA420P,
  47. AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVA444P,
  48. AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUVJ440P,
  49. AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVJ422P,
  50. AV_PIX_FMT_YUV411P,
  51. AV_PIX_FMT_NONE,
  52. };
  53. ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
  54. return 0;
  55. }
  56. static const AVFilterPad swapuv_inputs[] = {
  57. {
  58. .name = "default",
  59. .type = AVMEDIA_TYPE_VIDEO,
  60. .get_video_buffer = get_video_buffer,
  61. .filter_frame = filter_frame,
  62. },
  63. { NULL }
  64. };
  65. static const AVFilterPad swapuv_outputs[] = {
  66. {
  67. .name = "default",
  68. .type = AVMEDIA_TYPE_VIDEO,
  69. },
  70. { NULL }
  71. };
  72. AVFilter avfilter_vf_swapuv = {
  73. .name = "swapuv",
  74. .description = NULL_IF_CONFIG_SMALL("Swap U and V components."),
  75. .priv_size = 0,
  76. .query_formats = query_formats,
  77. .inputs = swapuv_inputs,
  78. .outputs = swapuv_outputs,
  79. };