pixdesc_query.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. };
  46. static int cmp_str(const void *a, const void *b)
  47. {
  48. const char *s1 = *(const char **)a;
  49. const char *s2 = *(const char **)b;
  50. return strcmp(s1, s2);
  51. }
  52. int main(void)
  53. {
  54. int i, j;
  55. for (i = 0; i < FF_ARRAY_ELEMS(query_tab); i++) {
  56. const char **pix_fmts = NULL;
  57. int nb_pix_fmts = 0;
  58. const AVPixFmtDescriptor *pix_desc = NULL;
  59. while ((pix_desc = av_pix_fmt_desc_next(pix_desc))) {
  60. enum AVPixelFormat pix_fmt = av_pix_fmt_desc_get_id(pix_desc);
  61. if (query_tab[i].cond(pix_fmt)) {
  62. const char *pix_name = pix_desc->name;
  63. if (pix_fmt == AV_PIX_FMT_RGB32) pix_name = "rgb32";
  64. else if (pix_fmt == AV_PIX_FMT_RGB32_1) pix_name = "rgb32_1";
  65. else if (pix_fmt == AV_PIX_FMT_BGR32) pix_name = "bgr32";
  66. else if (pix_fmt == AV_PIX_FMT_BGR32_1) pix_name = "bgr32_1";
  67. av_dynarray_add(&pix_fmts, &nb_pix_fmts, (void *)pix_name);
  68. }
  69. }
  70. if (pix_fmts) {
  71. qsort(pix_fmts, nb_pix_fmts, sizeof(*pix_fmts), cmp_str);
  72. printf("%s:\n", query_tab[i].class);
  73. for (j = 0; j < nb_pix_fmts; j++)
  74. printf(" %s\n", pix_fmts[j]);
  75. printf("\n");
  76. av_free(pix_fmts);
  77. }
  78. }
  79. return 0;
  80. }