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.

107 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 "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. uint8_t *tmp;
  34. int tmp2;
  35. tmp = picref->data[2];
  36. picref->data[2] = picref->data[1];
  37. picref->data[1] = tmp;
  38. tmp2 = picref->linesize[2];
  39. picref->linesize[2] = picref->linesize[1];
  40. picref->linesize[1] = tmp2;
  41. return picref;
  42. }
  43. static int filter_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
  44. {
  45. uint8_t *tmp_data;
  46. int tmp_linesize;
  47. tmp_data = inpicref->data[1];
  48. inpicref->data[1] = inpicref->data[2];
  49. inpicref->data[2] = tmp_data;
  50. tmp_linesize = inpicref->linesize[1];
  51. inpicref->linesize[1] = inpicref->linesize[2];
  52. inpicref->linesize[2] = tmp_linesize;
  53. return ff_filter_frame(link->dst->outputs[0], inpicref);
  54. }
  55. static int query_formats(AVFilterContext *ctx)
  56. {
  57. static const enum AVPixelFormat pix_fmts[] = {
  58. AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVA420P,
  59. AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVA444P,
  60. AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUVJ440P,
  61. AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVJ422P,
  62. AV_PIX_FMT_YUV411P,
  63. AV_PIX_FMT_NONE,
  64. };
  65. ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
  66. return 0;
  67. }
  68. static const AVFilterPad swapuv_inputs[] = {
  69. {
  70. .name = "default",
  71. .type = AVMEDIA_TYPE_VIDEO,
  72. .get_video_buffer = get_video_buffer,
  73. .filter_frame = filter_frame,
  74. },
  75. { NULL }
  76. };
  77. static const AVFilterPad swapuv_outputs[] = {
  78. {
  79. .name = "default",
  80. .type = AVMEDIA_TYPE_VIDEO,
  81. },
  82. { NULL }
  83. };
  84. AVFilter avfilter_vf_swapuv = {
  85. .name = "swapuv",
  86. .description = NULL_IF_CONFIG_SMALL("Swap U and V components."),
  87. .priv_size = 0,
  88. .query_formats = query_formats,
  89. .inputs = swapuv_inputs,
  90. .outputs = swapuv_outputs,
  91. };