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 <assert.h>
24 
25 #include "libavutil/avstring.h"
26 #include "internal.h"
27 #include "img2.h"
28 
29 #define IMG_TAGS(TAG) \
30  TAG(MJPEG, jpeg ) \
31  TAG(MJPEG, jpg ) \
32  TAG(MJPEG, jps ) \
33  TAG(MJPEG, mpo ) \
34  TAG(LJPEG, ljpg ) \
35  TAG(JPEGLS, jls ) \
36  TAG(PNG, png ) \
37  TAG(PNG, pns ) \
38  TAG(PNG, mng ) \
39  TAG(PPM, ppm ) \
40  TAG(PPM, pnm ) \
41  TAG(PGM, pgm ) \
42  TAG(PGMYUV, pgmyuv ) \
43  TAG(PBM, pbm ) \
44  TAG(PAM, pam ) \
45  TAG(PFM, pfm ) \
46  TAG(PHM, phm ) \
47  TAG(CRI, cri ) \
48  TAG(ALIAS_PIX, pix ) \
49  TAG(DDS, dds ) \
50  TAG(MPEG1VIDEO, mpg1-img ) \
51  TAG(MPEG2VIDEO, mpg2-img ) \
52  TAG(MPEG4, mpg4-img ) \
53  TAG(RAWVIDEO, y ) \
54  TAG(RAWVIDEO, raw ) \
55  TAG(BMP, bmp ) \
56  TAG(TARGA, tga ) \
57  TAG(TIFF, tiff ) \
58  TAG(TIFF, tif ) \
59  TAG(TIFF, dng ) \
60  TAG(SGI, sgi ) \
61  TAG(PTX, ptx ) \
62  TAG(PHOTOCD, pcd ) \
63  TAG(PCX, pcx ) \
64  TAG(QDRAW, pic ) \
65  TAG(QDRAW, pct ) \
66  TAG(QDRAW, pict ) \
67  TAG(SUNRAST, sun ) \
68  TAG(SUNRAST, ras ) \
69  TAG(SUNRAST, rs ) \
70  TAG(SUNRAST, im1 ) \
71  TAG(SUNRAST, im8 ) \
72  TAG(SUNRAST, im24 ) \
73  TAG(SUNRAST, im32 ) \
74  TAG(SUNRAST, sunras ) \
75  TAG(SVG, svg ) \
76  TAG(SVG, svgz ) \
77  TAG(JPEG2000, j2c ) \
78  TAG(JPEG2000, jp2 ) \
79  TAG(JPEG2000, jpc ) \
80  TAG(JPEG2000, j2k ) \
81  TAG(DPX, dpx ) \
82  TAG(EXR, exr ) \
83  TAG(PICTOR, pic ) \
84  TAG(V210X, yuv10 ) \
85  TAG(WEBP, webp ) \
86  TAG(XBM, xbm ) \
87  TAG(XPM, xpm ) \
88  TAG(XFACE, xface ) \
89  TAG(XWD, xwd ) \
90  TAG(GEM, img ) \
91  TAG(GEM, ximg ) \
92  TAG(GEM, timg ) \
93  TAG(VBN, vbn ) \
94  TAG(JPEGXL, jxl ) \
95  TAG(QOI, qoi ) \
96  TAG(RADIANCE_HDR, hdr ) \
97  TAG(WBMP, wbmp ) \
98  TAG(NONE, )
99 
100 #define LENGTH_CHECK(CODECID, STR) \
101  static_assert(sizeof(#STR) <= sizeof(ff_img_tags->str), #STR " does not fit into IdStrMap.str\n");
103 
105 #define TAG(CODECID, STR) { AV_CODEC_ID_ ## CODECID, #STR },
106 IMG_TAGS(TAG)
107 };
108 
109 static enum AVCodecID str2id(const IdStrMap *tags, const char *str)
110 {
111  str = strrchr(str, '.');
112  if (!str)
113  return AV_CODEC_ID_NONE;
114  str++;
115 
116  while (tags->id) {
117  if (!av_strcasecmp(str, tags->str))
118  return tags->id;
119 
120  tags++;
121  }
122  return AV_CODEC_ID_NONE;
123 }
124 
125 enum AVCodecID ff_guess_image2_codec(const char *filename)
126 {
127  return str2id(ff_img_tags, filename);
128 }
av_strcasecmp
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:207
ff_guess_image2_codec
enum AVCodecID ff_guess_image2_codec(const char *filename)
Definition: img2.c:125
ff_img_tags
const IdStrMap ff_img_tags[]
Definition: img2.c:104
str2id
static enum AVCodecID str2id(const IdStrMap *tags, const char *str)
Definition: img2.c:109
internal.h
IdStrMap::id
enum AVCodecID id
Definition: img2.h:68
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
TAG
#define TAG(CODECID, STR)
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
img2.h
IMG_TAGS
#define IMG_TAGS(TAG)
Definition: img2.c:29
IdStrMap::str
char str[12]
Definition: img2.h:69
LENGTH_CHECK
#define LENGTH_CHECK(CODECID, STR)
Definition: img2.c:100
IdStrMap
Definition: img2.h:67
avstring.h