6915e433f6ea83a7551e73879b0f9b69c4d4ea5b
[libav.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 CodecID id;
28 const char *str;
29 } IdStrMap;
30
31 static const IdStrMap img_tags[] = {
32 { CODEC_ID_MJPEG , "jpeg"},
33 { CODEC_ID_MJPEG , "jpg"},
34 { CODEC_ID_LJPEG , "ljpg"},
35 { CODEC_ID_PNG , "png"},
36 { CODEC_ID_PNG , "mng"},
37 { CODEC_ID_PPM , "ppm"},
38 { CODEC_ID_PPM , "pnm"},
39 { CODEC_ID_PGM , "pgm"},
40 { CODEC_ID_PGMYUV , "pgmyuv"},
41 { CODEC_ID_PBM , "pbm"},
42 { CODEC_ID_PAM , "pam"},
43 { CODEC_ID_MPEG1VIDEO, "mpg1-img"},
44 { CODEC_ID_MPEG2VIDEO, "mpg2-img"},
45 { CODEC_ID_MPEG4 , "mpg4-img"},
46 { CODEC_ID_FFV1 , "ffv1-img"},
47 { CODEC_ID_RAWVIDEO , "y"},
48 { CODEC_ID_BMP , "bmp"},
49 { CODEC_ID_GIF , "gif"},
50 { CODEC_ID_TARGA , "tga"},
51 { CODEC_ID_TIFF , "tiff"},
52 { CODEC_ID_TIFF , "tif"},
53 { CODEC_ID_SGI , "sgi"},
54 { CODEC_ID_PTX , "ptx"},
55 { CODEC_ID_PCX , "pcx"},
56 { CODEC_ID_SUNRAST , "sun"},
57 { CODEC_ID_SUNRAST , "ras"},
58 { CODEC_ID_SUNRAST , "rs"},
59 { CODEC_ID_SUNRAST , "im1"},
60 { CODEC_ID_SUNRAST , "im8"},
61 { CODEC_ID_SUNRAST , "im24"},
62 { CODEC_ID_SUNRAST , "sunras"},
63 { CODEC_ID_JPEG2000 , "jp2"},
64 { CODEC_ID_JPEG2000 , "jpc"},
65 { CODEC_ID_DPX , "dpx"},
66 { CODEC_ID_PICTOR , "pic"},
67 { CODEC_ID_XWD , "xwd"},
68 { CODEC_ID_NONE , NULL}
69 };
70
71 static enum CodecID av_str2id(const IdStrMap *tags, const char *str)
72 {
73 str= strrchr(str, '.');
74 if(!str) return CODEC_ID_NONE;
75 str++;
76
77 while (tags->id) {
78 if (!av_strcasecmp(str, tags->str))
79 return tags->id;
80
81 tags++;
82 }
83 return CODEC_ID_NONE;
84 }
85
86 enum CodecID ff_guess_image2_codec(const char *filename)
87 {
88 return av_str2id(img_tags, filename);
89 }