pixdesc_query.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) 2017 Clément Bœsch <u pkh me>
  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 <stdlib.h>
  21. #include "libavutil/mem.h"
  22. #include "libswscale/swscale_internal.h"
  23. static const struct {
  24. const char *class;
  25. int (*cond)(enum AVPixelFormat pix_fmt);
  26. } query_tab[] = {
  27. {"is16BPS", is16BPS},
  28. {"isNBPS", isNBPS},
  29. {"isBE", isBE},
  30. {"isYUV", isYUV},
  31. {"isPlanarYUV", isPlanarYUV},
  32. {"isSemiPlanarYUV", isSemiPlanarYUV},
  33. {"isRGB", isRGB},
  34. {"Gray", isGray},
  35. {"RGBinInt", isRGBinInt},
  36. {"BGRinInt", isBGRinInt},
  37. {"Bayer", isBayer},
  38. {"AnyRGB", isAnyRGB},
  39. {"ALPHA", isALPHA},
  40. {"Packed", isPacked},
  41. {"Planar", isPlanar},
  42. {"PackedRGB", isPackedRGB},
  43. {"PlanarRGB", isPlanarRGB},
  44. {"usePal", usePal},
  45. {"DataInHighBits", isDataInHighBits},
  46. {"SwappedChroma", isSwappedChroma},
  47. };
  48. static int cmp_str(const void *a, const void *b)
  49. {
  50. const char *s1 = *(const char **)a;
  51. const char *s2 = *(const char **)b;
  52. return strcmp(s1, s2);
  53. }
  54. int main(void)
  55. {
  56. int i, j;
  57. for (i = 0; i < FF_ARRAY_ELEMS(query_tab); i++) {
  58. const char **pix_fmts = NULL;
  59. int nb_pix_fmts = 0;
  60. const AVPixFmtDescriptor *pix_desc = NULL;
  61. while ((pix_desc = av_pix_fmt_desc_next(pix_desc))) {
  62. enum AVPixelFormat pix_fmt = av_pix_fmt_desc_get_id(pix_desc);
  63. if (query_tab[i].cond(pix_fmt)) {
  64. const char *pix_name = pix_desc->name;
  65. if (pix_fmt == AV_PIX_FMT_RGB32) pix_name = "rgb32";
  66. else if (pix_fmt == AV_PIX_FMT_RGB32_1) pix_name = "rgb32_1";
  67. else if (pix_fmt == AV_PIX_FMT_BGR32) pix_name = "bgr32";
  68. else if (pix_fmt == AV_PIX_FMT_BGR32_1) pix_name = "bgr32_1";
  69. av_dynarray_add(&pix_fmts, &nb_pix_fmts, (void *)pix_name);
  70. }
  71. }
  72. if (pix_fmts) {
  73. qsort(pix_fmts, nb_pix_fmts, sizeof(*pix_fmts), cmp_str);
  74. printf("%s:\n", query_tab[i].class);
  75. for (j = 0; j < nb_pix_fmts; j++)
  76. printf(" %s\n", pix_fmts[j]);
  77. printf("\n");
  78. av_free(pix_fmts);
  79. }
  80. }
  81. return 0;
  82. }