utils.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (C) 2024 Niklas Haas
  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. #ifndef SWSCALE_UTILS_H
  21. #define SWSCALE_UTILS_H
  22. #include "libavutil/pixdesc.h"
  23. #include "swscale.h"
  24. enum {
  25. FIELD_TOP, /* top/even rows, or progressive */
  26. FIELD_BOTTOM, /* bottom/odd rows */
  27. };
  28. /* Subset of AVFrame parameters that uniquely determine pixel representation */
  29. typedef struct SwsFormat {
  30. int width, height;
  31. int interlaced;
  32. enum AVPixelFormat format;
  33. enum AVColorRange range;
  34. enum AVColorPrimaries prim;
  35. enum AVColorTransferCharacteristic trc;
  36. enum AVColorSpace csp;
  37. enum AVChromaLocation loc;
  38. const AVPixFmtDescriptor *desc; /* convenience */
  39. } SwsFormat;
  40. /**
  41. * This function also sanitizes and strips the input data, removing irrelevant
  42. * fields for certain formats.
  43. */
  44. SwsFormat ff_fmt_from_frame(const AVFrame *frame, int field);
  45. static inline int ff_fmt_equal(const SwsFormat *fmt1, const SwsFormat *fmt2)
  46. {
  47. return fmt1->width == fmt2->width &&
  48. fmt1->height == fmt2->height &&
  49. fmt1->interlaced == fmt2->interlaced &&
  50. fmt1->format == fmt2->format &&
  51. fmt1->range == fmt2->range &&
  52. fmt1->prim == fmt2->prim &&
  53. fmt1->trc == fmt2->trc &&
  54. fmt1->csp == fmt2->csp &&
  55. fmt1->loc == fmt2->loc;
  56. }
  57. static inline int ff_fmt_align(enum AVPixelFormat fmt)
  58. {
  59. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
  60. if (desc->flags & AV_PIX_FMT_FLAG_BAYER) {
  61. return 2;
  62. } else {
  63. return 1 << desc->log2_chroma_h;
  64. }
  65. }
  66. int ff_test_fmt(const SwsFormat *fmt, int output);
  67. #endif /* SWSCALE_UTILS_H */