2004-07-15 21:32:54 +03:00
|
|
|
/*
|
|
|
|
* Image format
|
2009-01-19 17:46:40 +02:00
|
|
|
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
|
2004-07-15 21:32:54 +03:00
|
|
|
* Copyright (c) 2004 Michael Niedermayer
|
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2004-07-15 21:32:54 +03:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 18:30:46 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2004-07-15 21:32:54 +03:00
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2004-07-15 21:32:54 +03:00
|
|
|
* 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
|
2006-10-07 18:30:46 +03:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-13 00:43:26 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2004-07-15 21:32:54 +03:00
|
|
|
*/
|
2008-05-09 14:56:36 +03:00
|
|
|
|
2024-04-07 21:53:54 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
2008-05-09 14:56:36 +03:00
|
|
|
#include "libavutil/avstring.h"
|
2011-04-05 14:13:53 +03:00
|
|
|
#include "internal.h"
|
2015-09-06 17:07:20 +02:00
|
|
|
#include "img2.h"
|
2004-07-15 21:32:54 +03:00
|
|
|
|
2024-04-07 21:53:54 +02:00
|
|
|
#define IMG_TAGS(TAG) \
|
|
|
|
TAG(MJPEG, jpeg ) \
|
|
|
|
TAG(MJPEG, jpg ) \
|
|
|
|
TAG(MJPEG, jps ) \
|
|
|
|
TAG(MJPEG, mpo ) \
|
|
|
|
TAG(LJPEG, ljpg ) \
|
|
|
|
TAG(JPEGLS, jls ) \
|
|
|
|
TAG(PNG, png ) \
|
|
|
|
TAG(PNG, pns ) \
|
|
|
|
TAG(PNG, mng ) \
|
|
|
|
TAG(PPM, ppm ) \
|
|
|
|
TAG(PPM, pnm ) \
|
|
|
|
TAG(PGM, pgm ) \
|
|
|
|
TAG(PGMYUV, pgmyuv ) \
|
|
|
|
TAG(PBM, pbm ) \
|
|
|
|
TAG(PAM, pam ) \
|
|
|
|
TAG(PFM, pfm ) \
|
|
|
|
TAG(PHM, phm ) \
|
|
|
|
TAG(CRI, cri ) \
|
|
|
|
TAG(ALIAS_PIX, pix ) \
|
|
|
|
TAG(DDS, dds ) \
|
|
|
|
TAG(MPEG1VIDEO, mpg1-img ) \
|
|
|
|
TAG(MPEG2VIDEO, mpg2-img ) \
|
|
|
|
TAG(MPEG4, mpg4-img ) \
|
|
|
|
TAG(RAWVIDEO, y ) \
|
|
|
|
TAG(RAWVIDEO, raw ) \
|
|
|
|
TAG(BMP, bmp ) \
|
|
|
|
TAG(TARGA, tga ) \
|
|
|
|
TAG(TIFF, tiff ) \
|
|
|
|
TAG(TIFF, tif ) \
|
|
|
|
TAG(TIFF, dng ) \
|
|
|
|
TAG(SGI, sgi ) \
|
|
|
|
TAG(PTX, ptx ) \
|
|
|
|
TAG(PHOTOCD, pcd ) \
|
|
|
|
TAG(PCX, pcx ) \
|
|
|
|
TAG(QDRAW, pic ) \
|
|
|
|
TAG(QDRAW, pct ) \
|
|
|
|
TAG(QDRAW, pict ) \
|
|
|
|
TAG(SUNRAST, sun ) \
|
|
|
|
TAG(SUNRAST, ras ) \
|
|
|
|
TAG(SUNRAST, rs ) \
|
|
|
|
TAG(SUNRAST, im1 ) \
|
|
|
|
TAG(SUNRAST, im8 ) \
|
|
|
|
TAG(SUNRAST, im24 ) \
|
|
|
|
TAG(SUNRAST, im32 ) \
|
|
|
|
TAG(SUNRAST, sunras ) \
|
|
|
|
TAG(SVG, svg ) \
|
|
|
|
TAG(SVG, svgz ) \
|
|
|
|
TAG(JPEG2000, j2c ) \
|
|
|
|
TAG(JPEG2000, jp2 ) \
|
|
|
|
TAG(JPEG2000, jpc ) \
|
|
|
|
TAG(JPEG2000, j2k ) \
|
|
|
|
TAG(DPX, dpx ) \
|
|
|
|
TAG(EXR, exr ) \
|
|
|
|
TAG(PICTOR, pic ) \
|
|
|
|
TAG(V210X, yuv10 ) \
|
|
|
|
TAG(WEBP, webp ) \
|
|
|
|
TAG(XBM, xbm ) \
|
|
|
|
TAG(XPM, xpm ) \
|
|
|
|
TAG(XFACE, xface ) \
|
|
|
|
TAG(XWD, xwd ) \
|
|
|
|
TAG(GEM, img ) \
|
|
|
|
TAG(GEM, ximg ) \
|
|
|
|
TAG(GEM, timg ) \
|
|
|
|
TAG(VBN, vbn ) \
|
|
|
|
TAG(JPEGXL, jxl ) \
|
|
|
|
TAG(QOI, qoi ) \
|
|
|
|
TAG(RADIANCE_HDR, hdr ) \
|
|
|
|
TAG(WBMP, wbmp ) \
|
|
|
|
TAG(NONE, )
|
|
|
|
|
|
|
|
#define LENGTH_CHECK(CODECID, STR) \
|
|
|
|
static_assert(sizeof(#STR) <= sizeof(ff_img_tags->str), #STR " does not fit into IdStrMap.str\n");
|
|
|
|
IMG_TAGS(LENGTH_CHECK)
|
|
|
|
|
2015-09-06 17:07:20 +02:00
|
|
|
const IdStrMap ff_img_tags[] = {
|
2024-04-07 21:53:54 +02:00
|
|
|
#define TAG(CODECID, STR) { AV_CODEC_ID_ ## CODECID, #STR },
|
|
|
|
IMG_TAGS(TAG)
|
2004-07-15 21:32:54 +03:00
|
|
|
};
|
|
|
|
|
2016-02-24 02:44:18 +02:00
|
|
|
static enum AVCodecID str2id(const IdStrMap *tags, const char *str)
|
2004-07-15 21:32:54 +03:00
|
|
|
{
|
2012-11-29 06:56:40 +03:00
|
|
|
str = strrchr(str, '.');
|
|
|
|
if (!str)
|
|
|
|
return AV_CODEC_ID_NONE;
|
2004-09-23 00:25:09 +03:00
|
|
|
str++;
|
2004-07-15 21:32:54 +03:00
|
|
|
|
|
|
|
while (tags->id) {
|
2011-11-02 22:17:25 +03:00
|
|
|
if (!av_strcasecmp(str, tags->str))
|
2008-05-12 04:17:00 +03:00
|
|
|
return tags->id;
|
2004-07-15 21:32:54 +03:00
|
|
|
|
|
|
|
tags++;
|
|
|
|
}
|
2012-08-05 12:11:04 +03:00
|
|
|
return AV_CODEC_ID_NONE;
|
2004-07-15 21:32:54 +03:00
|
|
|
}
|
|
|
|
|
2012-08-05 12:11:04 +03:00
|
|
|
enum AVCodecID ff_guess_image2_codec(const char *filename)
|
2012-02-21 17:49:41 +03:00
|
|
|
{
|
2016-04-11 15:59:58 +02:00
|
|
|
return str2id(ff_img_tags, filename);
|
2012-02-21 17:49:41 +03:00
|
|
|
}
|