img2.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Image format
  3. * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
  4. * Copyright (c) 2004 Michael Niedermayer
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include "libavutil/avstring.h"
  23. #include "internal.h"
  24. typedef struct {
  25. enum AVCodecID id;
  26. const char *str;
  27. } IdStrMap;
  28. static const IdStrMap img_tags[] = {
  29. { AV_CODEC_ID_MJPEG , "jpeg"},
  30. { AV_CODEC_ID_MJPEG , "jpg"},
  31. { AV_CODEC_ID_MJPEG , "jps"},
  32. { AV_CODEC_ID_LJPEG , "ljpg"},
  33. { AV_CODEC_ID_JPEGLS , "jls"},
  34. { AV_CODEC_ID_PNG , "png"},
  35. { AV_CODEC_ID_PNG , "pns"},
  36. { AV_CODEC_ID_PNG , "mng"},
  37. { AV_CODEC_ID_PPM , "ppm"},
  38. { AV_CODEC_ID_PPM , "pnm"},
  39. { AV_CODEC_ID_PGM , "pgm"},
  40. { AV_CODEC_ID_PGMYUV , "pgmyuv"},
  41. { AV_CODEC_ID_PBM , "pbm"},
  42. { AV_CODEC_ID_PAM , "pam"},
  43. { AV_CODEC_ID_MPEG1VIDEO, "mpg1-img"},
  44. { AV_CODEC_ID_MPEG2VIDEO, "mpg2-img"},
  45. { AV_CODEC_ID_MPEG4 , "mpg4-img"},
  46. { AV_CODEC_ID_FFV1 , "ffv1-img"},
  47. { AV_CODEC_ID_RAWVIDEO , "y"},
  48. { AV_CODEC_ID_RAWVIDEO , "raw"},
  49. { AV_CODEC_ID_BMP , "bmp"},
  50. { AV_CODEC_ID_GIF , "gif"},
  51. { AV_CODEC_ID_TARGA , "tga"},
  52. { AV_CODEC_ID_TIFF , "tiff"},
  53. { AV_CODEC_ID_TIFF , "tif"},
  54. { AV_CODEC_ID_SGI , "sgi"},
  55. { AV_CODEC_ID_PTX , "ptx"},
  56. { AV_CODEC_ID_PCX , "pcx"},
  57. { AV_CODEC_ID_SUNRAST , "sun"},
  58. { AV_CODEC_ID_SUNRAST , "ras"},
  59. { AV_CODEC_ID_SUNRAST , "rs"},
  60. { AV_CODEC_ID_SUNRAST , "im1"},
  61. { AV_CODEC_ID_SUNRAST , "im8"},
  62. { AV_CODEC_ID_SUNRAST , "im24"},
  63. { AV_CODEC_ID_SUNRAST , "im32"},
  64. { AV_CODEC_ID_SUNRAST , "sunras"},
  65. { AV_CODEC_ID_JPEG2000 , "j2c"},
  66. { AV_CODEC_ID_JPEG2000 , "j2k"},
  67. { AV_CODEC_ID_JPEG2000 , "jp2"},
  68. { AV_CODEC_ID_JPEG2000 , "jpc"},
  69. { AV_CODEC_ID_DPX , "dpx"},
  70. { AV_CODEC_ID_EXR , "exr"},
  71. { AV_CODEC_ID_PICTOR , "pic"},
  72. { AV_CODEC_ID_V210X , "yuv10"},
  73. { AV_CODEC_ID_XBM , "xbm"},
  74. { AV_CODEC_ID_XWD , "xwd"},
  75. { AV_CODEC_ID_NONE , NULL}
  76. };
  77. static enum AVCodecID av_str2id(const IdStrMap *tags, const char *str)
  78. {
  79. str= strrchr(str, '.');
  80. if(!str) return AV_CODEC_ID_NONE;
  81. str++;
  82. while (tags->id) {
  83. if (!av_strcasecmp(str, tags->str))
  84. return tags->id;
  85. tags++;
  86. }
  87. return AV_CODEC_ID_NONE;
  88. }
  89. enum AVCodecID ff_guess_image2_codec(const char *filename)
  90. {
  91. return av_str2id(img_tags, filename);
  92. }