vidstabutils.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) 2013 Georg Martius <georg dot martius at web dot de>
  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. #include "vidstabutils.h"
  21. /** convert AV's pixelformat to vid.stab pixelformat */
  22. VSPixelFormat ff_av2vs_pixfmt(AVFilterContext *ctx, enum AVPixelFormat pf)
  23. {
  24. switch (pf) {
  25. case AV_PIX_FMT_YUV420P: return PF_YUV420P;
  26. case AV_PIX_FMT_YUV422P: return PF_YUV422P;
  27. case AV_PIX_FMT_YUV444P: return PF_YUV444P;
  28. case AV_PIX_FMT_YUV410P: return PF_YUV410P;
  29. case AV_PIX_FMT_YUV411P: return PF_YUV411P;
  30. case AV_PIX_FMT_YUV440P: return PF_YUV440P;
  31. case AV_PIX_FMT_YUVA420P: return PF_YUVA420P;
  32. case AV_PIX_FMT_GRAY8: return PF_GRAY8;
  33. case AV_PIX_FMT_RGB24: return PF_RGB24;
  34. case AV_PIX_FMT_BGR24: return PF_BGR24;
  35. case AV_PIX_FMT_RGBA: return PF_RGBA;
  36. default:
  37. av_log(ctx, AV_LOG_ERROR, "cannot deal with pixel format %i\n", pf);
  38. return PF_NONE;
  39. }
  40. }
  41. /** struct to hold a valid context for logging from within vid.stab lib */
  42. typedef struct VS2AVLogCtx {
  43. const AVClass *class;
  44. } VS2AVLogCtx;
  45. /** wrapper to log vs_log into av_log */
  46. static int vs2av_log(int type, const char *tag, const char *format, ...)
  47. {
  48. va_list ap;
  49. VS2AVLogCtx ctx;
  50. AVClass class = {
  51. .class_name = tag,
  52. .item_name = av_default_item_name,
  53. .option = 0,
  54. .version = LIBAVUTIL_VERSION_INT,
  55. .category = AV_CLASS_CATEGORY_FILTER,
  56. };
  57. ctx.class = &class;
  58. va_start(ap, format);
  59. av_vlog(&ctx, type, format, ap);
  60. va_end(ap);
  61. return VS_OK;
  62. }
  63. /** sets the memory allocation function and logging constants to av versions */
  64. void ff_vs_init(void)
  65. {
  66. vs_malloc = av_malloc;
  67. vs_zalloc = av_mallocz;
  68. vs_realloc = av_realloc;
  69. vs_free = av_free;
  70. VS_ERROR_TYPE = AV_LOG_ERROR;
  71. VS_WARN_TYPE = AV_LOG_WARNING;
  72. VS_INFO_TYPE = AV_LOG_INFO;
  73. VS_MSG_TYPE = AV_LOG_VERBOSE;
  74. vs_log = vs2av_log;
  75. VS_ERROR = 0;
  76. VS_OK = 1;
  77. }