img2.c 3 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 27 28 29 30 31 32 33

typedef struct {
    enum CodecID id;
    const char *str;
} IdStrMap;

static const IdStrMap img_tags[] = {
    { CODEC_ID_MJPEG     , "jpeg"},
    { CODEC_ID_MJPEG     , "jpg"},
34
    { CODEC_ID_MJPEG     , "jps"},
35
    { CODEC_ID_LJPEG     , "ljpg"},
36
    { CODEC_ID_JPEGLS    , "jls"},
37
    { CODEC_ID_PNG       , "png"},
38
    { CODEC_ID_PNG       , "pns"},
39
    { CODEC_ID_PNG       , "mng"},
40
    { CODEC_ID_PPM       , "ppm"},
41
    { CODEC_ID_PPM       , "pnm"},
42 43 44 45
    { CODEC_ID_PGM       , "pgm"},
    { CODEC_ID_PGMYUV    , "pgmyuv"},
    { CODEC_ID_PBM       , "pbm"},
    { CODEC_ID_PAM       , "pam"},
46 47 48 49
    { CODEC_ID_MPEG1VIDEO, "mpg1-img"},
    { CODEC_ID_MPEG2VIDEO, "mpg2-img"},
    { CODEC_ID_MPEG4     , "mpg4-img"},
    { CODEC_ID_FFV1      , "ffv1-img"},
50
    { CODEC_ID_RAWVIDEO  , "y"},
51
    { CODEC_ID_RAWVIDEO  , "raw"},
Måns Rullgård's avatar
Måns Rullgård committed
52
    { CODEC_ID_BMP       , "bmp"},
Baptiste Coudurier's avatar
Baptiste Coudurier committed
53
    { CODEC_ID_GIF       , "gif"},
54 55
    { CODEC_ID_TARGA     , "tga"},
    { CODEC_ID_TIFF      , "tiff"},
56
    { CODEC_ID_TIFF      , "tif"},
57
    { CODEC_ID_SGI       , "sgi"},
Ivo van Poorten's avatar
Ivo van Poorten committed
58
    { CODEC_ID_PTX       , "ptx"},
59
    { CODEC_ID_PCX       , "pcx"},
Ivo van Poorten's avatar
Ivo van Poorten committed
60 61 62 63 64 65
    { CODEC_ID_SUNRAST   , "sun"},
    { CODEC_ID_SUNRAST   , "ras"},
    { CODEC_ID_SUNRAST   , "rs"},
    { CODEC_ID_SUNRAST   , "im1"},
    { CODEC_ID_SUNRAST   , "im8"},
    { CODEC_ID_SUNRAST   , "im24"},
66
    { CODEC_ID_SUNRAST   , "im32"},
Ivo van Poorten's avatar
Ivo van Poorten committed
67
    { CODEC_ID_SUNRAST   , "sunras"},
68
    { CODEC_ID_JPEG2000  , "j2c"},
69
    { CODEC_ID_JPEG2000  , "j2k"},
70
    { CODEC_ID_JPEG2000  , "jp2"},
71
    { CODEC_ID_JPEG2000  , "jpc"},
72
    { CODEC_ID_DPX       , "dpx"},
73
    { CODEC_ID_EXR       , "exr"},
74
    { CODEC_ID_PICTOR    , "pic"},
Paul B Mahol's avatar
Paul B Mahol committed
75
    { CODEC_ID_XBM       , "xbm"},
Paul B Mahol's avatar
Paul B Mahol committed
76
    { CODEC_ID_XWD       , "xwd"},
77
    { CODEC_ID_NONE      , NULL}
78 79 80 81
};

static enum CodecID av_str2id(const IdStrMap *tags, const char *str)
{
Michael Niedermayer's avatar
Michael Niedermayer committed
82 83 84
    str= strrchr(str, '.');
    if(!str) return CODEC_ID_NONE;
    str++;
85 86

    while (tags->id) {
87
        if (!av_strcasecmp(str, tags->str))
88
            return tags->id;
89 90 91 92 93 94

        tags++;
    }
    return CODEC_ID_NONE;
}

95 96 97 98
enum CodecID ff_guess_image2_codec(const char *filename)
{
    return av_str2id(img_tags, filename);
}