img2.c 3.58 KB
Newer Older
1 2
/*
 * Image format
3
 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4 5
 * Copyright (c) 2004 Michael Niedermayer
 *
6 7 8
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
9 10
 * modify it under the terms of the GNU Lesser General Public
 * 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 15 16 17 18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * 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 26

typedef struct {
27
    enum AVCodecID id;
28 29 30 31
    const char *str;
} IdStrMap;

static const IdStrMap img_tags[] = {
32 33
    { AV_CODEC_ID_MJPEG,      "jpeg"     },
    { AV_CODEC_ID_MJPEG,      "jpg"      },
34
    { AV_CODEC_ID_MJPEG,      "jps"      },
35
    { AV_CODEC_ID_MJPEG,      "mpo"      },
36
    { AV_CODEC_ID_LJPEG,      "ljpg"     },
37
    { AV_CODEC_ID_JPEGLS,     "jls"      },
38
    { AV_CODEC_ID_PNG,        "png"      },
39
    { AV_CODEC_ID_PNG,        "pns"      },
40 41 42 43 44 45 46 47 48 49 50 51
    { AV_CODEC_ID_PNG,        "mng"      },
    { AV_CODEC_ID_PPM,        "ppm"      },
    { AV_CODEC_ID_PPM,        "pnm"      },
    { AV_CODEC_ID_PGM,        "pgm"      },
    { AV_CODEC_ID_PGMYUV,     "pgmyuv"   },
    { AV_CODEC_ID_PBM,        "pbm"      },
    { AV_CODEC_ID_PAM,        "pam"      },
    { AV_CODEC_ID_MPEG1VIDEO, "mpg1-img" },
    { AV_CODEC_ID_MPEG2VIDEO, "mpg2-img" },
    { AV_CODEC_ID_MPEG4,      "mpg4-img" },
    { AV_CODEC_ID_FFV1,       "ffv1-img" },
    { AV_CODEC_ID_RAWVIDEO,   "y"        },
52
    { AV_CODEC_ID_RAWVIDEO,   "raw"      },
53 54 55 56 57 58 59
    { AV_CODEC_ID_BMP,        "bmp"      },
    { AV_CODEC_ID_TARGA,      "tga"      },
    { AV_CODEC_ID_TIFF,       "tiff"     },
    { AV_CODEC_ID_TIFF,       "tif"      },
    { AV_CODEC_ID_SGI,        "sgi"      },
    { AV_CODEC_ID_PTX,        "ptx"      },
    { AV_CODEC_ID_PCX,        "pcx"      },
60
    { AV_CODEC_ID_BRENDER_PIX, "pix"     },
61 62 63 64 65 66
    { AV_CODEC_ID_SUNRAST,    "sun"      },
    { AV_CODEC_ID_SUNRAST,    "ras"      },
    { AV_CODEC_ID_SUNRAST,    "rs"       },
    { AV_CODEC_ID_SUNRAST,    "im1"      },
    { AV_CODEC_ID_SUNRAST,    "im8"      },
    { AV_CODEC_ID_SUNRAST,    "im24"     },
67
    { AV_CODEC_ID_SUNRAST,    "im32"     },
68
    { AV_CODEC_ID_SUNRAST,    "sunras"   },
69
    { AV_CODEC_ID_JPEG2000,   "j2c"      },
70 71
    { AV_CODEC_ID_JPEG2000,   "jp2"      },
    { AV_CODEC_ID_JPEG2000,   "jpc"      },
72
    { AV_CODEC_ID_JPEG2000,   "j2k"      },
73
    { AV_CODEC_ID_DPX,        "dpx"      },
74
    { AV_CODEC_ID_EXR,        "exr"      },
75
    { AV_CODEC_ID_PICTOR,     "pic"      },
76
    { AV_CODEC_ID_V210X,      "yuv10"    },
Michael Niedermayer's avatar
Michael Niedermayer committed
77
    { AV_CODEC_ID_WEBP,       "webp"     },
78
    { AV_CODEC_ID_XBM,        "xbm"      },
79
    { AV_CODEC_ID_XFACE,      "xface"    },
80 81
    { AV_CODEC_ID_XWD,        "xwd"      },
    { AV_CODEC_ID_NONE,       NULL       }
82 83
};

84
static enum AVCodecID av_str2id(const IdStrMap *tags, const char *str)
85
{
86 87 88
    str = strrchr(str, '.');
    if (!str)
        return AV_CODEC_ID_NONE;
Michael Niedermayer's avatar
Michael Niedermayer committed
89
    str++;
90 91

    while (tags->id) {
92
        if (!av_strcasecmp(str, tags->str))
93
            return tags->id;
94 95 96

        tags++;
    }
97
    return AV_CODEC_ID_NONE;
98 99
}

100
enum AVCodecID ff_guess_image2_codec(const char *filename)
101 102 103
{
    return av_str2id(img_tags, filename);
}