FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/img2.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 12 12 100.0%
Functions: 2 2 100.0%
Branches: 6 6 100.0%

Line Branch Exec Source
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");
102 IMG_TAGS(LENGTH_CHECK)
103
104 const IdStrMap ff_img_tags[] = {
105 #define TAG(CODECID, STR) { AV_CODEC_ID_ ## CODECID, #STR },
106 IMG_TAGS(TAG)
107 };
108
109 8281 static enum AVCodecID str2id(const IdStrMap *tags, const char *str)
110 {
111 8281 str = strrchr(str, '.');
112
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 8242 times.
8281 if (!str)
113 39 return AV_CODEC_ID_NONE;
114 8242 str++;
115
116
2/2
✓ Branch 0 taken 522840 times.
✓ Branch 1 taken 7226 times.
530066 while (tags->id) {
117
2/2
✓ Branch 1 taken 1016 times.
✓ Branch 2 taken 521824 times.
522840 if (!av_strcasecmp(str, tags->str))
118 1016 return tags->id;
119
120 521824 tags++;
121 }
122 7226 return AV_CODEC_ID_NONE;
123 }
124
125 8281 enum AVCodecID ff_guess_image2_codec(const char *filename)
126 {
127 8281 return str2id(ff_img_tags, filename);
128 }
129