FFmpeg
img2.c
Go to the documentation of this file.
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 
23 #include "libavutil/avstring.h"
24 #include "internal.h"
25 #include "img2.h"
26 
27 const IdStrMap ff_img_tags[] = {
28  { AV_CODEC_ID_MJPEG, "jpeg" },
29  { AV_CODEC_ID_MJPEG, "jpg" },
30  { AV_CODEC_ID_MJPEG, "jps" },
31  { AV_CODEC_ID_MJPEG, "mpo" },
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_PFM, "pfm" },
44  { AV_CODEC_ID_CRI, "cri" },
45  { AV_CODEC_ID_ALIAS_PIX, "pix" },
46  { AV_CODEC_ID_DDS, "dds" },
47  { AV_CODEC_ID_MPEG1VIDEO, "mpg1-img" },
48  { AV_CODEC_ID_MPEG2VIDEO, "mpg2-img" },
49  { AV_CODEC_ID_MPEG4, "mpg4-img" },
50  { AV_CODEC_ID_RAWVIDEO, "y" },
51  { AV_CODEC_ID_RAWVIDEO, "raw" },
52  { AV_CODEC_ID_BMP, "bmp" },
53  { AV_CODEC_ID_TARGA, "tga" },
54  { AV_CODEC_ID_TIFF, "tiff" },
55  { AV_CODEC_ID_TIFF, "tif" },
56  { AV_CODEC_ID_TIFF, "dng" },
57  { AV_CODEC_ID_SGI, "sgi" },
58  { AV_CODEC_ID_PTX, "ptx" },
59  { AV_CODEC_ID_PHOTOCD, "pcd" },
60  { AV_CODEC_ID_PCX, "pcx" },
61  { AV_CODEC_ID_QDRAW, "pic" },
62  { AV_CODEC_ID_QDRAW, "pct" },
63  { AV_CODEC_ID_QDRAW, "pict" },
64  { AV_CODEC_ID_SUNRAST, "sun" },
65  { AV_CODEC_ID_SUNRAST, "ras" },
66  { AV_CODEC_ID_SUNRAST, "rs" },
67  { AV_CODEC_ID_SUNRAST, "im1" },
68  { AV_CODEC_ID_SUNRAST, "im8" },
69  { AV_CODEC_ID_SUNRAST, "im24" },
70  { AV_CODEC_ID_SUNRAST, "im32" },
71  { AV_CODEC_ID_SUNRAST, "sunras" },
72  { AV_CODEC_ID_SVG, "svg" },
73  { AV_CODEC_ID_SVG, "svgz" },
74  { AV_CODEC_ID_JPEG2000, "j2c" },
75  { AV_CODEC_ID_JPEG2000, "jp2" },
76  { AV_CODEC_ID_JPEG2000, "jpc" },
77  { AV_CODEC_ID_JPEG2000, "j2k" },
78  { AV_CODEC_ID_DPX, "dpx" },
79  { AV_CODEC_ID_EXR, "exr" },
80  { AV_CODEC_ID_PICTOR, "pic" },
81  { AV_CODEC_ID_V210X, "yuv10" },
82  { AV_CODEC_ID_WEBP, "webp" },
83  { AV_CODEC_ID_XBM, "xbm" },
84  { AV_CODEC_ID_XPM, "xpm" },
85  { AV_CODEC_ID_XFACE, "xface" },
86  { AV_CODEC_ID_XWD, "xwd" },
87  { AV_CODEC_ID_GEM, "img" },
88  { AV_CODEC_ID_GEM, "ximg" },
89  { AV_CODEC_ID_GEM, "timg" },
91 };
92 
93 static enum AVCodecID str2id(const IdStrMap *tags, const char *str)
94 {
95  str = strrchr(str, '.');
96  if (!str)
97  return AV_CODEC_ID_NONE;
98  str++;
99 
100  while (tags->id) {
101  if (!av_strcasecmp(str, tags->str))
102  return tags->id;
103 
104  tags++;
105  }
106  return AV_CODEC_ID_NONE;
107 }
108 
109 enum AVCodecID ff_guess_image2_codec(const char *filename)
110 {
111  return str2id(ff_img_tags, filename);
112 }
AV_CODEC_ID_DPX
@ AV_CODEC_ID_DPX
Definition: codec_id.h:178
AV_CODEC_ID_PBM
@ AV_CODEC_ID_PBM
Definition: codec_id.h:113
av_strcasecmp
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:215
AV_CODEC_ID_PFM
@ AV_CODEC_ID_PFM
Definition: codec_id.h:302
AV_CODEC_ID_RAWVIDEO
@ AV_CODEC_ID_RAWVIDEO
Definition: codec_id.h:63
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:62
AV_CODEC_ID_PPM
@ AV_CODEC_ID_PPM
Definition: codec_id.h:112
AV_CODEC_ID_PGM
@ AV_CODEC_ID_PGM
Definition: codec_id.h:114
ff_guess_image2_codec
enum AVCodecID ff_guess_image2_codec(const char *filename)
Definition: img2.c:109
AV_CODEC_ID_XFACE
@ AV_CODEC_ID_XFACE
Definition: codec_id.h:261
ff_img_tags
const IdStrMap ff_img_tags[]
Definition: img2.c:27
AV_CODEC_ID_BMP
@ AV_CODEC_ID_BMP
Definition: codec_id.h:128
AV_CODEC_ID_ALIAS_PIX
@ AV_CODEC_ID_ALIAS_PIX
Definition: codec_id.h:227
str2id
static enum AVCodecID str2id(const IdStrMap *tags, const char *str)
Definition: img2.c:93
AV_CODEC_ID_PNG
@ AV_CODEC_ID_PNG
Definition: codec_id.h:111
internal.h
AV_CODEC_ID_EXR
@ AV_CODEC_ID_EXR
Definition: codec_id.h:230
NULL
#define NULL
Definition: coverity.c:32
AV_CODEC_ID_XWD
@ AV_CODEC_ID_XWD
Definition: codec_id.h:208
IdStrMap::id
enum AVCodecID id
Definition: img2.h:68
IdStrMap::str
const char * str
Definition: img2.h:69
AV_CODEC_ID_PICTOR
@ AV_CODEC_ID_PICTOR
Definition: codec_id.h:191
AV_CODEC_ID_PGMYUV
@ AV_CODEC_ID_PGMYUV
Definition: codec_id.h:115
AV_CODEC_ID_MPEG1VIDEO
@ AV_CODEC_ID_MPEG1VIDEO
Definition: codec_id.h:51
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:47
AV_CODEC_ID_PHOTOCD
@ AV_CODEC_ID_PHOTOCD
Definition: codec_id.h:304
AV_CODEC_ID_PAM
@ AV_CODEC_ID_PAM
Definition: codec_id.h:116
AV_CODEC_ID_PCX
@ AV_CODEC_ID_PCX
Definition: codec_id.h:159
AV_CODEC_ID_QDRAW
@ AV_CODEC_ID_QDRAW
Definition: codec_id.h:108
AV_CODEC_ID_V210X
@ AV_CODEC_ID_V210X
Definition: codec_id.h:175
AV_CODEC_ID_XPM
@ AV_CODEC_ID_XPM
Definition: codec_id.h:278
AV_CODEC_ID_SVG
@ AV_CODEC_ID_SVG
Definition: codec_id.h:283
AV_CODEC_ID_MJPEG
@ AV_CODEC_ID_MJPEG
Definition: codec_id.h:57
AV_CODEC_ID_CRI
@ AV_CODEC_ID_CRI
Definition: codec_id.h:307
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:48
img2.h
AV_CODEC_ID_WEBP
@ AV_CODEC_ID_WEBP
Definition: codec_id.h:222
AV_CODEC_ID_JPEG2000
@ AV_CODEC_ID_JPEG2000
Definition: codec_id.h:138
AV_CODEC_ID_XBM
@ AV_CODEC_ID_XBM
Definition: codec_id.h:210
AV_CODEC_ID_JPEGLS
@ AV_CODEC_ID_JPEGLS
Definition: codec_id.h:61
AV_CODEC_ID_DDS
@ AV_CODEC_ID_DDS
Definition: codec_id.h:240
AV_CODEC_ID_GEM
@ AV_CODEC_ID_GEM
Definition: codec_id.h:310
IdStrMap
Definition: img2.h:67
convert_header.str
string str
Definition: convert_header.py:20
AV_CODEC_ID_SGI
@ AV_CODEC_ID_SGI
Definition: codec_id.h:151
AV_CODEC_ID_SUNRAST
@ AV_CODEC_ID_SUNRAST
Definition: codec_id.h:160
AV_CODEC_ID_TARGA
@ AV_CODEC_ID_TARGA
Definition: codec_id.h:143
AV_CODEC_ID_TIFF
@ AV_CODEC_ID_TIFF
Definition: codec_id.h:146
avstring.h
AV_CODEC_ID_MPEG2VIDEO
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: codec_id.h:52
AV_CODEC_ID_LJPEG
@ AV_CODEC_ID_LJPEG
Definition: codec_id.h:59
AV_CODEC_ID_PTX
@ AV_CODEC_ID_PTX
Definition: codec_id.h:154