From patchwork Thu Oct 8 11:02:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Ross X-Patchwork-Id: 22750 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 777C14486EA for ; Thu, 8 Oct 2020 14:02:27 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 60D5C68B891; Thu, 8 Oct 2020 14:02:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mx.sdf.org (mx.sdf.org [205.166.94.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2481968B869 for ; Thu, 8 Oct 2020 14:02:19 +0300 (EEST) Received: from c7d0f849702daedbd8e8965c75194fea ([1.152.248.40]) (authenticated (128 bits)) by mx.sdf.org (8.15.2/8.14.5) with ESMTPSA id 098B26oK008201 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO) for ; Thu, 8 Oct 2020 11:02:10 GMT Date: Thu, 8 Oct 2020 22:02:02 +1100 From: Peter Ross To: ffmpeg-devel@ffmpeg.org Message-ID: <539afb6014cf511aa6011044b9109eaea3f6f4d9.1602154882.git.pross@xvid.org> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avformat/mspdec: Microsoft Paint (MSP) demuxer X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Peter Ross --- Week nine or so of lockdown... Changelog | 1 + doc/general_contents.texi | 2 + libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/mspdec.c | 95 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+) create mode 100644 libavformat/mspdec.c diff --git a/Changelog b/Changelog index 0ecda9ed52..84690791af 100644 --- a/Changelog +++ b/Changelog @@ -35,6 +35,7 @@ version : - AVS3 demuxer - AVS3 video decoder via libuavs3d - Cintel RAW decoder +- Microsoft Paint (MSP) demuxer version 4.3: diff --git a/doc/general_contents.texi b/doc/general_contents.texi index 598e0e74da..cd3391fc8d 100644 --- a/doc/general_contents.texi +++ b/doc/general_contents.texi @@ -727,6 +727,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 a5e8bddb87..5cf3db630e 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -352,6 +352,7 @@ OBJS-$(CONFIG_MPEGVIDEO_DEMUXER) += mpegvideodec.o rawdec.o OBJS-$(CONFIG_MPJPEG_DEMUXER) += mpjpegdec.o OBJS-$(CONFIG_MPJPEG_MUXER) += mpjpeg.o OBJS-$(CONFIG_MPL2_DEMUXER) += mpl2dec.o subtitles.o +OBJS-$(CONFIG_MSP_DEMUXER) += mspdec.o rawdec.o OBJS-$(CONFIG_MSF_DEMUXER) += msf.o OBJS-$(CONFIG_MPSUB_DEMUXER) += mpsubdec.o subtitles.o OBJS-$(CONFIG_MSNWC_TCP_DEMUXER) += msnwc_tcp.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 96b9bc2a0c..1ba00439b9 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -282,6 +282,7 @@ extern AVInputFormat ff_mpjpeg_demuxer; extern AVOutputFormat ff_mpjpeg_muxer; extern AVInputFormat ff_mpl2_demuxer; extern AVInputFormat ff_mpsub_demuxer; +extern AVInputFormat ff_msp_demuxer; extern AVInputFormat ff_msf_demuxer; extern AVInputFormat ff_msnwc_tcp_demuxer; extern AVInputFormat ff_mtaf_demuxer; diff --git a/libavformat/mspdec.c b/libavformat/mspdec.c new file mode 100644 index 0000000000..8f67a82424 --- /dev/null +++ b/libavformat/mspdec.c @@ -0,0 +1,95 @@ +/* + * 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" +#include "rawdec.h" + +static int msp_probe(const AVProbeData *p) +{ + unsigned int i, sum; + + if (p->buf_size <= 32 || memcmp(p->buf, "DanM", 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) +{ + FFRawDemuxerContext * cntx = s->priv_data; + AVIOContext *pb = s->pb; + AVStream *st; + + st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + avio_skip(pb, 4); + + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = s->iformat->raw_codec_id; + 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); + + cntx->raw_packet_size = av_image_get_buffer_size(st->codecpar->format, st->codecpar->width, st->codecpar->height, 1); + if (cntx->raw_packet_size < 0) + return cntx->raw_packet_size; + + return 0; +} + +static int msp_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + FFRawDemuxerContext *cntx = s->priv_data; + int ret = av_get_packet(s->pb, pkt, cntx->raw_packet_size); + if (ret < 0) + return ret; + pkt->stream_index = 0; + 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_GENERIC_INDEX | AVFMT_NO_BYTE_SEEK, + .raw_codec_id = AV_CODEC_ID_RAWVIDEO, + .priv_data_size = sizeof(FFRawDemuxerContext), +};