aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/img2dec.c
diff options
context:
space:
mode:
authorCarl Eugen Hoyos <cehoyos@ag.or.at>2014-09-25 23:02:06 +0200
committerCarl Eugen Hoyos <cehoyos@ag.or.at>2014-09-26 00:06:41 +0200
commit88c937fdc8a8c887ca482aa26a9d6862e72d0dd3 (patch)
tree934c17421aad7de7ec40456de72b186f043c06bf /libavformat/img2dec.c
parent475e3799cdcc90a38f9bbc4c6b9159a028b1ad44 (diff)
downloadffmpeg-88c937fdc8a8c887ca482aa26a9d6862e72d0dd3.tar.gz
Autodetect jpg images.
Based on 2d3842f5 by Michael Niedermayer. Fixes ticket #2541.
Diffstat (limited to 'libavformat/img2dec.c')
-rw-r--r--libavformat/img2dec.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index 70bef9d405..16bd699c98 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -620,6 +620,57 @@ static int j2k_probe(AVProbeData *p)
return 0;
}
+static int jpeg_probe(AVProbeData *p)
+{
+ const uint8_t *b = p->buf;
+ int i, state = 0xD8;
+
+ if (AV_RB16(b) != 0xFFD8 ||
+ AV_RB32(b) == 0xFFD8FFF7)
+ return 0;
+
+ b += 2;
+ for (i = 0; i < p->buf_size - 2; i++) {
+ int c;
+ if (b[i] != 0xFF)
+ continue;
+ c = b[i + 1];
+ switch (c) {
+ case 0xD8:
+ return 0;
+ case 0xC0:
+ case 0xC1:
+ case 0xC2:
+ case 0xC3:
+ case 0xC5:
+ case 0xC6:
+ case 0xC7:
+ if (state != 0xD8)
+ return 0;
+ state = 0xC0;
+ break;
+ case 0xDA:
+ if (state != 0xC0)
+ return 0;
+ state = 0xDA;
+ break;
+ case 0xD9:
+ if (state != 0xDA)
+ return 0;
+ state = 0xD9;
+ break;
+ default:
+ if ( (c >= 0x02 && c <= 0xBF)
+ || c == 0xC8)
+ return 0;
+ }
+ }
+
+ if (state == 0xD9)
+ return AVPROBE_SCORE_EXTENSION + 1;
+ return AVPROBE_SCORE_EXTENSION / 8;
+}
+
static int jpegls_probe(AVProbeData *p)
{
const uint8_t *b = p->buf;
@@ -711,6 +762,7 @@ IMAGEAUTO_DEMUXER(bmp, AV_CODEC_ID_BMP)
IMAGEAUTO_DEMUXER(dpx, AV_CODEC_ID_DPX)
IMAGEAUTO_DEMUXER(exr, AV_CODEC_ID_EXR)
IMAGEAUTO_DEMUXER(j2k, AV_CODEC_ID_JPEG2000)
+IMAGEAUTO_DEMUXER(jpeg, AV_CODEC_ID_MJPEG)
IMAGEAUTO_DEMUXER(jpegls, AV_CODEC_ID_JPEGLS)
IMAGEAUTO_DEMUXER(pictor, AV_CODEC_ID_PICTOR)
IMAGEAUTO_DEMUXER(png, AV_CODEC_ID_PNG)