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_PHM, "phm" },
45  { AV_CODEC_ID_CRI, "cri" },
46  { AV_CODEC_ID_ALIAS_PIX, "pix" },
47  { AV_CODEC_ID_DDS, "dds" },
48  { AV_CODEC_ID_MPEG1VIDEO, "mpg1-img" },
49  { AV_CODEC_ID_MPEG2VIDEO, "mpg2-img" },
50  { AV_CODEC_ID_MPEG4, "mpg4-img" },
51  { AV_CODEC_ID_RAWVIDEO, "y" },
52  { AV_CODEC_ID_RAWVIDEO, "raw" },
53  { AV_CODEC_ID_BMP, "bmp" },
54  { AV_CODEC_ID_TARGA, "tga" },
55  { AV_CODEC_ID_TIFF, "tiff" },
56  { AV_CODEC_ID_TIFF, "tif" },
57  { AV_CODEC_ID_TIFF, "dng" },
58  { AV_CODEC_ID_SGI, "sgi" },
59  { AV_CODEC_ID_PTX, "ptx" },
60  { AV_CODEC_ID_PHOTOCD, "pcd" },
61  { AV_CODEC_ID_PCX, "pcx" },
62  { AV_CODEC_ID_QDRAW, "pic" },
63  { AV_CODEC_ID_QDRAW, "pct" },
64  { AV_CODEC_ID_QDRAW, "pict" },
65  { AV_CODEC_ID_SUNRAST, "sun" },
66  { AV_CODEC_ID_SUNRAST, "ras" },
67  { AV_CODEC_ID_SUNRAST, "rs" },
68  { AV_CODEC_ID_SUNRAST, "im1" },
69  { AV_CODEC_ID_SUNRAST, "im8" },
70  { AV_CODEC_ID_SUNRAST, "im24" },
71  { AV_CODEC_ID_SUNRAST, "im32" },
72  { AV_CODEC_ID_SUNRAST, "sunras" },
73  { AV_CODEC_ID_SVG, "svg" },
74  { AV_CODEC_ID_SVG, "svgz" },
75  { AV_CODEC_ID_JPEG2000, "j2c" },
76  { AV_CODEC_ID_JPEG2000, "jp2" },
77  { AV_CODEC_ID_JPEG2000, "jpc" },
78  { AV_CODEC_ID_JPEG2000, "j2k" },
79  { AV_CODEC_ID_DPX, "dpx" },
80  { AV_CODEC_ID_EXR, "exr" },
81  { AV_CODEC_ID_PICTOR, "pic" },
82  { AV_CODEC_ID_V210X, "yuv10" },
83  { AV_CODEC_ID_WEBP, "webp" },
84  { AV_CODEC_ID_XBM, "xbm" },
85  { AV_CODEC_ID_XPM, "xpm" },
86  { AV_CODEC_ID_XFACE, "xface" },
87  { AV_CODEC_ID_XWD, "xwd" },
88  { AV_CODEC_ID_GEM, "img" },
89  { AV_CODEC_ID_GEM, "ximg" },
90  { AV_CODEC_ID_GEM, "timg" },
91  { AV_CODEC_ID_VBN, "vbn" },
92  { AV_CODEC_ID_JPEGXL, "jxl" },
93  { AV_CODEC_ID_QOI, "qoi" },
94  { AV_CODEC_ID_RADIANCE_HDR, "hdr" },
95  { AV_CODEC_ID_WBMP, "wbmp" },
97 };
98 
99 static enum AVCodecID str2id(const IdStrMap *tags, const char *str)
100 {
101  str = strrchr(str, '.');
102  if (!str)
103  return AV_CODEC_ID_NONE;
104  str++;
105 
106  while (tags->id) {
107  if (!av_strcasecmp(str, tags->str))
108  return tags->id;
109 
110  tags++;
111  }
112  return AV_CODEC_ID_NONE;
113 }
114 
115 enum AVCodecID ff_guess_image2_codec(const char *filename)
116 {
117  return str2id(ff_img_tags, filename);
118 }
AV_CODEC_ID_DPX
@ AV_CODEC_ID_DPX
Definition: codec_id.h:180
AV_CODEC_ID_PBM
@ AV_CODEC_ID_PBM
Definition: codec_id.h:115
av_strcasecmp
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:218
AV_CODEC_ID_PFM
@ AV_CODEC_ID_PFM
Definition: codec_id.h:306
AV_CODEC_ID_RAWVIDEO
@ AV_CODEC_ID_RAWVIDEO
Definition: codec_id.h:65
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:64
AV_CODEC_ID_PPM
@ AV_CODEC_ID_PPM
Definition: codec_id.h:114
AV_CODEC_ID_PGM
@ AV_CODEC_ID_PGM
Definition: codec_id.h:116
ff_guess_image2_codec
enum AVCodecID ff_guess_image2_codec(const char *filename)
Definition: img2.c:115
AV_CODEC_ID_PHM
@ AV_CODEC_ID_PHM
Definition: codec_id.h:318
AV_CODEC_ID_XFACE
@ AV_CODEC_ID_XFACE
Definition: codec_id.h:265
ff_img_tags
const IdStrMap ff_img_tags[]
Definition: img2.c:27
AV_CODEC_ID_BMP
@ AV_CODEC_ID_BMP
Definition: codec_id.h:130
AV_CODEC_ID_ALIAS_PIX
@ AV_CODEC_ID_ALIAS_PIX
Definition: codec_id.h:229
str2id
static enum AVCodecID str2id(const IdStrMap *tags, const char *str)
Definition: img2.c:99
AV_CODEC_ID_PNG
@ AV_CODEC_ID_PNG
Definition: codec_id.h:113
internal.h
AV_CODEC_ID_EXR
@ AV_CODEC_ID_EXR
Definition: codec_id.h:232
NULL
#define NULL
Definition: coverity.c:32
AV_CODEC_ID_XWD
@ AV_CODEC_ID_XWD
Definition: codec_id.h:210
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:193
AV_CODEC_ID_PGMYUV
@ AV_CODEC_ID_PGMYUV
Definition: codec_id.h:117
AV_CODEC_ID_MPEG1VIDEO
@ AV_CODEC_ID_MPEG1VIDEO
Definition: codec_id.h:53
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
AV_CODEC_ID_PHOTOCD
@ AV_CODEC_ID_PHOTOCD
Definition: codec_id.h:308
AV_CODEC_ID_PAM
@ AV_CODEC_ID_PAM
Definition: codec_id.h:118
AV_CODEC_ID_PCX
@ AV_CODEC_ID_PCX
Definition: codec_id.h:161
AV_CODEC_ID_QOI
@ AV_CODEC_ID_QOI
Definition: codec_id.h:317
AV_CODEC_ID_QDRAW
@ AV_CODEC_ID_QDRAW
Definition: codec_id.h:110
AV_CODEC_ID_V210X
@ AV_CODEC_ID_V210X
Definition: codec_id.h:177
AV_CODEC_ID_XPM
@ AV_CODEC_ID_XPM
Definition: codec_id.h:282
AV_CODEC_ID_SVG
@ AV_CODEC_ID_SVG
Definition: codec_id.h:287
AV_CODEC_ID_MJPEG
@ AV_CODEC_ID_MJPEG
Definition: codec_id.h:59
AV_CODEC_ID_CRI
@ AV_CODEC_ID_CRI
Definition: codec_id.h:311
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
img2.h
AV_CODEC_ID_JPEGXL
@ AV_CODEC_ID_JPEGXL
Definition: codec_id.h:316
AV_CODEC_ID_WEBP
@ AV_CODEC_ID_WEBP
Definition: codec_id.h:224
AV_CODEC_ID_JPEG2000
@ AV_CODEC_ID_JPEG2000
Definition: codec_id.h:140
AV_CODEC_ID_XBM
@ AV_CODEC_ID_XBM
Definition: codec_id.h:212
AV_CODEC_ID_VBN
@ AV_CODEC_ID_VBN
Definition: codec_id.h:315
AV_CODEC_ID_JPEGLS
@ AV_CODEC_ID_JPEGLS
Definition: codec_id.h:63
AV_CODEC_ID_WBMP
@ AV_CODEC_ID_WBMP
Definition: codec_id.h:320
AV_CODEC_ID_DDS
@ AV_CODEC_ID_DDS
Definition: codec_id.h:242
AV_CODEC_ID_GEM
@ AV_CODEC_ID_GEM
Definition: codec_id.h:314
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:153
AV_CODEC_ID_SUNRAST
@ AV_CODEC_ID_SUNRAST
Definition: codec_id.h:162
AV_CODEC_ID_TARGA
@ AV_CODEC_ID_TARGA
Definition: codec_id.h:145
AV_CODEC_ID_TIFF
@ AV_CODEC_ID_TIFF
Definition: codec_id.h:148
AV_CODEC_ID_RADIANCE_HDR
@ AV_CODEC_ID_RADIANCE_HDR
Definition: codec_id.h:319
avstring.h
AV_CODEC_ID_MPEG2VIDEO
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: codec_id.h:54
AV_CODEC_ID_LJPEG
@ AV_CODEC_ID_LJPEG
Definition: codec_id.h:61
AV_CODEC_ID_PTX
@ AV_CODEC_ID_PTX
Definition: codec_id.h:156