FFmpeg
Loading...
Searching...
No Matches
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(JPEGXS, jxs ) \
96 TAG(QOI, qoi ) \
97 TAG(RADIANCE_HDR, hdr ) \
98 TAG(WBMP, wbmp ) \
99 TAG(NONE, )
100
101#define LENGTH_CHECK(CODECID, STR) \
102 static_assert(sizeof(#STR) <= sizeof(ff_img_tags->str), #STR " does not fit into IdStrMap.str\n");
104
106#define TAG(CODECID, STR) { AV_CODEC_ID_ ## CODECID, #STR },
108};
109
110static enum AVCodecID str2id(const IdStrMap *tags, const char *str)
111{
112 str = strrchr(str, '.');
113 if (!str)
114 return AV_CODEC_ID_NONE;
115 str++;
116
117 while (tags->id) {
118 if (!av_strcasecmp(str, tags->str))
119 return tags->id;
120
121 tags++;
122 }
123 return AV_CODEC_ID_NONE;
124}
125
126enum AVCodecID ff_guess_image2_codec(const char *filename)
127{
128 return str2id(ff_img_tags, filename);
129}
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition codec_id.h:47
@ AV_CODEC_ID_NONE
Definition codec_id.h:48
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition avstring.c:208
#define LENGTH_CHECK(CODECID, STR)
Definition img2.c:101
#define IMG_TAGS(TAG)
Definition img2.c:29
enum AVCodecID ff_guess_image2_codec(const char *filename)
Definition img2.c:126
#define TAG(CODECID, STR)
static enum AVCodecID str2id(const IdStrMap *tags, const char *str)
Definition img2.c:110
const IdStrMap ff_img_tags[]
Definition img2.c:105
enum AVCodecID id
Definition img2.h:66
char str[12]
Definition img2.h:67