aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Ross <pross@xvid.org>2020-10-08 21:04:58 +1100
committerPeter Ross <pross@xvid.org>2020-12-06 20:03:47 +1100
commit2aab42bc40ebed79a661285f69506b06850629df (patch)
tree8dd5f1941a58217f66ca796e80c233a0833b6a9e
parent85b442e231ea065410312ce6a04ac241cced4765 (diff)
downloadffmpeg-2aab42bc40ebed79a661285f69506b06850629df.tar.gz
avformat/mspdec: Microsoft Paint (MSP) demuxer
Signed-off-by: Peter Ross <pross@xvid.org>
-rw-r--r--Changelog1
-rw-r--r--doc/general_contents.texi2
-rw-r--r--libavformat/Makefile1
-rw-r--r--libavformat/allformats.c1
-rw-r--r--libavformat/mspdec.c116
-rw-r--r--libavformat/version.h2
6 files changed, 122 insertions, 1 deletions
diff --git a/Changelog b/Changelog
index e0f6e8e299..503317dfae 100644
--- a/Changelog
+++ b/Changelog
@@ -50,6 +50,7 @@ version <next>:
- asupercut filter
- asubcut filter
- Microsoft Paint (MSP) version 2 decoder
+- Microsoft Paint (MSP) demuxer
version 4.3:
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index 1be6f9b683..443e8ed8d1 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -735,6 +735,8 @@ following image formats are supported:
@item JPEG-LS @tab X @tab X
@item LJPEG @tab X @tab
@tab Lossless JPEG
+@item MSP @tab @tab X
+ @tab Microsoft Paint image
@item PAM @tab X @tab X
@tab PAM is a PNM extension with alpha support.
@item PBM @tab X @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index be5a482b01..97d868081b 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -357,6 +357,7 @@ OBJS-$(CONFIG_MPL2_DEMUXER) += mpl2dec.o subtitles.o
OBJS-$(CONFIG_MSF_DEMUXER) += msf.o
OBJS-$(CONFIG_MPSUB_DEMUXER) += mpsubdec.o subtitles.o
OBJS-$(CONFIG_MSNWC_TCP_DEMUXER) += msnwc_tcp.o
+OBJS-$(CONFIG_MSP_DEMUXER) += mspdec.o
OBJS-$(CONFIG_MTAF_DEMUXER) += mtaf.o
OBJS-$(CONFIG_MTV_DEMUXER) += mtv.o
OBJS-$(CONFIG_MUSX_DEMUXER) += musx.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 53e5374255..0e0caaad39 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -286,6 +286,7 @@ extern AVInputFormat ff_mpl2_demuxer;
extern AVInputFormat ff_mpsub_demuxer;
extern AVInputFormat ff_msf_demuxer;
extern AVInputFormat ff_msnwc_tcp_demuxer;
+extern AVInputFormat ff_msp_demuxer;
extern AVInputFormat ff_mtaf_demuxer;
extern AVInputFormat ff_mtv_demuxer;
extern AVInputFormat ff_musx_demuxer;
diff --git a/libavformat/mspdec.c b/libavformat/mspdec.c
new file mode 100644
index 0000000000..b81d835a63
--- /dev/null
+++ b/libavformat/mspdec.c
@@ -0,0 +1,116 @@
+/*
+ * Microsoft Paint (MSP) demuxer
+ * Copyright (c) 2020 Peter Ross (pross@xvid.org)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * 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
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Microsoft Paint (MSP) demuxer
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "libavutil/imgutils.h"
+#include "avformat.h"
+#include "internal.h"
+
+typedef struct {
+ int packet_size;
+} MSPContext;
+
+static int msp_probe(const AVProbeData *p)
+{
+ unsigned int i, sum;
+
+ if (p->buf_size <= 32 || (memcmp(p->buf, "DanM", 4) && memcmp(p->buf, "LinS", 4)))
+ return 0;
+
+ sum = 0;
+ for (i = 0; i < 24; i += 2)
+ sum ^= AV_RL16(p->buf + i);
+
+ return AV_RL16(p->buf + 24) == sum ? AVPROBE_SCORE_MAX : 0;
+}
+
+static int msp_read_header(AVFormatContext *s)
+{
+ MSPContext * cntx = s->priv_data;
+ AVIOContext *pb = s->pb;
+ AVStream *st;
+
+ st = avformat_new_stream(s, NULL);
+ if (!st)
+ return AVERROR(ENOMEM);
+
+ st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+ st->codecpar->codec_id = avio_rl32(pb) == MKTAG('D', 'a', 'n', 'M') ? AV_CODEC_ID_RAWVIDEO : AV_CODEC_ID_MSP2;
+
+ st->codecpar->width = avio_rl16(pb);
+ st->codecpar->height = avio_rl16(pb);
+ st->codecpar->format = AV_PIX_FMT_MONOBLACK;
+
+ st->sample_aspect_ratio.num = avio_rl16(pb);
+ st->sample_aspect_ratio.den = avio_rl16(pb);
+ avio_skip(pb, 20);
+
+ if (st->codecpar->codec_id == AV_CODEC_ID_RAWVIDEO) {
+ cntx->packet_size = av_image_get_buffer_size(st->codecpar->format, st->codecpar->width, st->codecpar->height, 1);
+ if (cntx->packet_size < 0)
+ return cntx->packet_size;
+ } else
+ cntx->packet_size = 2 * st->codecpar->height;
+
+ return 0;
+}
+
+static int msp_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ AVStream *st = s->streams[0];
+ MSPContext *cntx = s->priv_data;
+ int ret;
+
+ ret = av_get_packet(s->pb, pkt, cntx->packet_size);
+ if (ret < 0)
+ return ret;
+
+ if (st->codecpar->codec_id == AV_CODEC_ID_MSP2) {
+ unsigned int size, i;
+ if (pkt->size != 2 * st->codecpar->height)
+ return AVERROR_INVALIDDATA;
+ size = 0;
+ for (i = 0; i < st->codecpar->height; i++)
+ size += AV_RL16(&pkt->data[i * 2]);
+ ret = av_append_packet(s->pb, pkt, size);
+ if (ret < 0)
+ return ret;
+ }
+
+ pkt->stream_index = 0;
+ pkt->flags |= AV_PKT_FLAG_KEY;
+ return 0;
+}
+
+AVInputFormat ff_msp_demuxer = {
+ .name = "msp",
+ .long_name = NULL_IF_CONFIG_SMALL("Microsoft Paint (MSP))"),
+ .read_probe = msp_probe,
+ .read_header = msp_read_header,
+ .read_packet = msp_read_packet,
+ .flags = AVFMT_NOTIMESTAMPS,
+ .priv_data_size = sizeof(MSPContext),
+};
diff --git a/libavformat/version.h b/libavformat/version.h
index ddcca9ae50..b43193bcb1 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
// Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
// Also please add any ticket numbers that you believe might be affected here
#define LIBAVFORMAT_VERSION_MAJOR 58
-#define LIBAVFORMAT_VERSION_MINOR 64
+#define LIBAVFORMAT_VERSION_MINOR 65
#define LIBAVFORMAT_VERSION_MICRO 100
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \