img2: add stereo 3d still picture file extensions
[ffmpeg.git] / libavformat / img2.c
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 Libav.
7  *
8  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22
23 #include "libavutil/avstring.h"
24 #include "internal.h"
25
26 typedef struct {
27     enum AVCodecID id;
28     const char *str;
29 } IdStrMap;
30
31 static const IdStrMap img_tags[] = {
32     { AV_CODEC_ID_MJPEG,      "jpeg"     },
33     { AV_CODEC_ID_MJPEG,      "jpg"      },
34     { AV_CODEC_ID_MJPEG,      "jps"      },
35     { AV_CODEC_ID_MJPEG,      "mpo"      },
36     { AV_CODEC_ID_LJPEG,      "ljpg"     },
37     { AV_CODEC_ID_PNG,        "png"      },
38     { AV_CODEC_ID_PNG,        "pns"      },
39     { AV_CODEC_ID_PNG,        "mng"      },
40     { AV_CODEC_ID_PPM,        "ppm"      },
41     { AV_CODEC_ID_PPM,        "pnm"      },
42     { AV_CODEC_ID_PGM,        "pgm"      },
43     { AV_CODEC_ID_PGMYUV,     "pgmyuv"   },
44     { AV_CODEC_ID_PBM,        "pbm"      },
45     { AV_CODEC_ID_PAM,        "pam"      },
46     { AV_CODEC_ID_MPEG1VIDEO, "mpg1-img" },
47     { AV_CODEC_ID_MPEG2VIDEO, "mpg2-img" },
48     { AV_CODEC_ID_MPEG4,      "mpg4-img" },
49     { AV_CODEC_ID_FFV1,       "ffv1-img" },
50     { AV_CODEC_ID_RAWVIDEO,   "y"        },
51     { AV_CODEC_ID_BMP,        "bmp"      },
52     { AV_CODEC_ID_GIF,        "gif"      },
53     { AV_CODEC_ID_TARGA,      "tga"      },
54     { AV_CODEC_ID_TIFF,       "tiff"     },
55     { AV_CODEC_ID_TIFF,       "tif"      },
56     { AV_CODEC_ID_SGI,        "sgi"      },
57     { AV_CODEC_ID_PTX,        "ptx"      },
58     { AV_CODEC_ID_PCX,        "pcx"      },
59     { AV_CODEC_ID_SUNRAST,    "sun"      },
60     { AV_CODEC_ID_SUNRAST,    "ras"      },
61     { AV_CODEC_ID_SUNRAST,    "rs"       },
62     { AV_CODEC_ID_SUNRAST,    "im1"      },
63     { AV_CODEC_ID_SUNRAST,    "im8"      },
64     { AV_CODEC_ID_SUNRAST,    "im24"     },
65     { AV_CODEC_ID_SUNRAST,    "sunras"   },
66     { AV_CODEC_ID_JPEG2000,   "jp2"      },
67     { AV_CODEC_ID_JPEG2000,   "jpc"      },
68     { AV_CODEC_ID_JPEG2000,   "j2k"      },
69     { AV_CODEC_ID_DPX,        "dpx"      },
70     { AV_CODEC_ID_PICTOR,     "pic"      },
71     { AV_CODEC_ID_WEBP,       "webp"     },
72     { AV_CODEC_ID_XBM,        "xbm"      },
73     { AV_CODEC_ID_XWD,        "xwd"      },
74     { AV_CODEC_ID_NONE,       NULL       }
75 };
76
77 static enum AVCodecID av_str2id(const IdStrMap *tags, const char *str)
78 {
79     str = strrchr(str, '.');
80     if (!str)
81         return AV_CODEC_ID_NONE;
82     str++;
83
84     while (tags->id) {
85         if (!av_strcasecmp(str, tags->str))
86             return tags->id;
87
88         tags++;
89     }
90     return AV_CODEC_ID_NONE;
91 }
92
93 enum AVCodecID ff_guess_image2_codec(const char *filename)
94 {
95     return av_str2id(img_tags, filename);
96 }