vf_swapuv.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 "video.h"
  27. static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms,
  28. int w, int h)
  29. {
  30. AVFilterBufferRef *picref =
  31. ff_default_get_video_buffer(link, perms, w, h);
  32. uint8_t *tmp;
  33. int tmp2;
  34. tmp = picref->data[2];
  35. picref->data[2] = picref->data[1];
  36. picref->data[1] = tmp;
  37. tmp2 = picref->linesize[2];
  38. picref->linesize[2] = picref->linesize[1];
  39. picref->linesize[1] = tmp2;
  40. return picref;
  41. }
  42. static int start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
  43. {
  44. AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
  45. outpicref->data[1] = inpicref->data[2];
  46. outpicref->data[2] = inpicref->data[1];
  47. outpicref->linesize[1] = inpicref->linesize[2];
  48. outpicref->linesize[2] = inpicref->linesize[1];
  49. return ff_start_frame(link->dst->outputs[0], outpicref);
  50. }
  51. static int query_formats(AVFilterContext *ctx)
  52. {
  53. static const enum PixelFormat pix_fmts[] = {
  54. PIX_FMT_YUV420P, PIX_FMT_YUVJ420P, PIX_FMT_YUVA420P,
  55. PIX_FMT_YUV444P, PIX_FMT_YUVJ444P, PIX_FMT_YUVA444P,
  56. PIX_FMT_YUV440P, PIX_FMT_YUVJ440P,
  57. PIX_FMT_YUV422P, PIX_FMT_YUVJ422P,
  58. PIX_FMT_YUV411P,
  59. PIX_FMT_NONE,
  60. };
  61. ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
  62. return 0;
  63. }
  64. AVFilter avfilter_vf_swapuv = {
  65. .name = "swapuv",
  66. .description = NULL_IF_CONFIG_SMALL("Swap U and V components."),
  67. .priv_size = 0,
  68. .query_formats = query_formats,
  69. .inputs = (const AVFilterPad[]) {
  70. { .name = "default",
  71. .type = AVMEDIA_TYPE_VIDEO,
  72. .get_video_buffer = get_video_buffer,
  73. .start_frame = start_frame, },
  74. { .name = NULL }
  75. },
  76. .outputs = (const AVFilterPad[]) {
  77. { .name = "default",
  78. .type = AVMEDIA_TYPE_VIDEO, },
  79. { .name = NULL }
  80. },
  81. };