aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHendrik Leppkes <h.leppkes@gmail.com>2015-10-03 12:22:41 +0200
committerHendrik Leppkes <h.leppkes@gmail.com>2015-10-03 12:22:41 +0200
commit4d2160c99a00af98cb09749f24831580e816eda9 (patch)
treecf897382bd18d139b6533f2fd889e25eee6eafbd
parent9825a24e5b1c34663d672961ebd2561a009b23e9 (diff)
parent9a3202a98b2e095b54dd784c3e01a09a676fc3fa (diff)
downloadffmpeg-4d2160c99a00af98cb09749f24831580e816eda9.tar.gz
Merge commit '9a3202a98b2e095b54dd784c3e01a09a676fc3fa'
* commit '9a3202a98b2e095b54dd784c3e01a09a676fc3fa': Screenpresso SPV1 decoder Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
-rw-r--r--Changelog1
-rwxr-xr-xconfigure1
-rw-r--r--doc/general.texi1
-rw-r--r--libavcodec/Makefile1
-rw-r--r--libavcodec/allcodecs.c1
-rw-r--r--libavcodec/avcodec.h1
-rw-r--r--libavcodec/codec_desc.c7
-rw-r--r--libavcodec/screenpresso.c186
-rw-r--r--libavcodec/version.h2
-rw-r--r--libavformat/riff.c1
-rw-r--r--tests/fate/video.mak3
-rw-r--r--tests/ref/fate/screenpresso5
12 files changed, 209 insertions, 1 deletions
diff --git a/Changelog b/Changelog
index 515d649d85..bbb9ed06d6 100644
--- a/Changelog
+++ b/Changelog
@@ -13,6 +13,7 @@ version <next>:
- agate filter
- chromakey filter
- maskedmerge filter
+- Screenpresso SPV1 decoding
version 2.8:
diff --git a/configure b/configure
index 552f698d6b..4ca3d61eb5 100755
--- a/configure
+++ b/configure
@@ -2325,6 +2325,7 @@ rv20_decoder_select="h263_decoder"
rv20_encoder_select="h263_encoder"
rv30_decoder_select="golomb h264pred h264qpel mpegvideo rv34dsp"
rv40_decoder_select="golomb h264pred h264qpel mpegvideo rv34dsp"
+screenpresso_decoder_deps="zlib"
shorten_decoder_select="golomb"
sipr_decoder_select="lsp"
snow_decoder_select="dwt h264qpel hpeldsp me_cmp rangecoder videodsp"
diff --git a/doc/general.texi b/doc/general.texi
index 99ba88a34c..9ea98b2079 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -475,6 +475,7 @@ library:
@item RTSP @tab X @tab X
@item SAP @tab X @tab X
@item SBG @tab @tab X
+@item Screenpresso @tab @tab X
@item SDP @tab @tab X
@item Sega FILM/CPK @tab @tab X
@tab Used in many Sega Saturn console games.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a991b2ed08..b15e431d32 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -455,6 +455,7 @@ OBJS-$(CONFIG_SAMI_DECODER) += samidec.o ass.o htmlsubtitles.o
OBJS-$(CONFIG_S302M_DECODER) += s302m.o
OBJS-$(CONFIG_S302M_ENCODER) += s302menc.o
OBJS-$(CONFIG_SANM_DECODER) += sanm.o
+OBJS-$(CONFIG_SCREENPRESSO_DECODER) += screenpresso.o
OBJS-$(CONFIG_SGI_DECODER) += sgidec.o
OBJS-$(CONFIG_SGI_ENCODER) += sgienc.o rle.o
OBJS-$(CONFIG_SGIRLE_DECODER) += sgirledec.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index f33e457ce2..3870cf6f12 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -285,6 +285,7 @@ void avcodec_register_all(void)
REGISTER_DECODER(RV40, rv40);
REGISTER_ENCDEC (S302M, s302m);
REGISTER_DECODER(SANM, sanm);
+ REGISTER_DECODER(SCREENPRESSO, screenpresso);
REGISTER_ENCDEC (SGI, sgi);
REGISTER_DECODER(SGIRLE, sgirle);
REGISTER_DECODER(SMACKER, smacker);
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 138627d8d4..ff70d254af 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -296,6 +296,7 @@ enum AVCodecID {
AV_CODEC_ID_HAP,
AV_CODEC_ID_DDS,
AV_CODEC_ID_DXV,
+ AV_CODEC_ID_SCREENPRESSO,
AV_CODEC_ID_Y41P = 0x8000,
AV_CODEC_ID_AVRP,
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index b9c2f64688..da8d65816e 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1266,6 +1266,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
.long_name = NULL_IF_CONFIG_SMALL("Resolume DXV"),
.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
},
+ {
+ .id = AV_CODEC_ID_SCREENPRESSO,
+ .type = AVMEDIA_TYPE_VIDEO,
+ .name = "screenpresso",
+ .long_name = NULL_IF_CONFIG_SMALL("Screenpresso"),
+ .props = AV_CODEC_PROP_LOSSLESS,
+ },
/* image codecs */
{
diff --git a/libavcodec/screenpresso.c b/libavcodec/screenpresso.c
new file mode 100644
index 0000000000..e3150e9b2b
--- /dev/null
+++ b/libavcodec/screenpresso.c
@@ -0,0 +1,186 @@
+/*
+ * Screenpresso decoder
+ * Copyright (C) 2015 Vittorio Giovara <vittorio.giovara@gmail.com>
+ *
+ * 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
+ * Screenpresso decoder
+ *
+ * Fourcc: SPV1
+ *
+ * Screenpresso simply horizontally flips and then deflates frames,
+ * alternating full pictures and deltas. Deltas are related to the currently
+ * rebuilt frame (not the reference), and since there is no coordinate system
+ * they contain exactly as many pixel as the keyframe.
+ *
+ * Supports: BGR24
+ */
+
+#include <stdint.h>
+#include <string.h>
+#include <zlib.h>
+
+#include "libavutil/imgutils.h"
+#include "libavutil/internal.h"
+
+#include "avcodec.h"
+#include "internal.h"
+
+typedef struct ScreenpressoContext {
+ AVFrame *current;
+
+ /* zlib interation */
+ uint8_t *inflated_buf;
+ uLongf inflated_size;
+} ScreenpressoContext;
+
+static av_cold int screenpresso_close(AVCodecContext *avctx)
+{
+ ScreenpressoContext *ctx = avctx->priv_data;
+
+ av_frame_free(&ctx->current);
+ av_freep(&ctx->inflated_buf);
+
+ return 0;
+}
+
+static av_cold int screenpresso_init(AVCodecContext *avctx)
+{
+ ScreenpressoContext *ctx = avctx->priv_data;
+
+ /* These needs to be set to estimate uncompressed buffer */
+ int ret = av_image_check_size(avctx->width, avctx->height, 0, avctx);
+ if (ret < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid image size %dx%d.\n",
+ avctx->width, avctx->height);
+ return ret;
+ }
+
+ /* Allocate current frame */
+ ctx->current = av_frame_alloc();
+ if (!ctx->current)
+ return AVERROR(ENOMEM);
+
+ avctx->pix_fmt = AV_PIX_FMT_BGR24;
+
+ return 0;
+}
+
+static void sum_delta_flipped(uint8_t *dst, int dst_linesize,
+ const uint8_t *src, int src_linesize,
+ int bytewidth, int height)
+{
+ int i;
+ for (; height > 0; height--) {
+ for (i = 0; i < bytewidth; i++)
+ dst[i] += src[(height - 1) * src_linesize + i];
+ dst += dst_linesize;
+ }
+}
+
+static int screenpresso_decode_frame(AVCodecContext *avctx, void *data,
+ int *got_frame, AVPacket *avpkt)
+{
+ ScreenpressoContext *ctx = avctx->priv_data;
+ AVFrame *frame = data;
+ int keyframe;
+ int ret;
+
+ /* Size check */
+ if (avpkt->size < 3) {
+ av_log(avctx, AV_LOG_ERROR, "Packet too small (%d)\n", avpkt->size);
+ return AVERROR_INVALIDDATA;
+ }
+
+ /* Basic sanity check, but not really harmful */
+ if ((avpkt->data[0] != 0x73 && avpkt->data[0] != 0x72) ||
+ avpkt->data[1] != 8) { // bpp probably
+ av_log(avctx, AV_LOG_WARNING, "Unknown header 0x%02X%02X\n",
+ avpkt->data[0], avpkt->data[1]);
+ }
+ keyframe = (avpkt->data[0] == 0x73);
+
+ /* Resize deflate buffer and frame on resolution change */
+ if (ctx->inflated_size != avctx->width * avctx->height * 3) {
+ av_frame_unref(ctx->current);
+ ret = ff_get_buffer(avctx, ctx->current, AV_GET_BUFFER_FLAG_REF);
+ if (ret < 0)
+ return ret;
+
+ /* If malloc fails, reset len to avoid preserving an invalid value */
+ ctx->inflated_size = avctx->width * avctx->height * 3;
+ ret = av_reallocp(&ctx->inflated_buf, ctx->inflated_size);
+ if (ret < 0) {
+ ctx->inflated_size = 0;
+ return ret;
+ }
+ }
+
+ /* Inflate the frame after the 2 byte header */
+ ret = uncompress(ctx->inflated_buf, &ctx->inflated_size,
+ avpkt->data + 2, avpkt->size - 2);
+ if (ret) {
+ av_log(avctx, AV_LOG_ERROR, "Deflate error %d.\n", ret);
+ return AVERROR_UNKNOWN;
+ }
+
+ /* When a keyframe is found, copy it (flipped) */
+ if (keyframe)
+ av_image_copy_plane(ctx->current->data[0] +
+ ctx->current->linesize[0] * (avctx->height - 1),
+ -1 * ctx->current->linesize[0],
+ ctx->inflated_buf, avctx->width * 3,
+ avctx->width * 3, avctx->height);
+ /* Otherwise sum the delta on top of the current frame */
+ else
+ sum_delta_flipped(ctx->current->data[0], ctx->current->linesize[0],
+ ctx->inflated_buf, avctx->width * 3,
+ avctx->width * 3, avctx->height);
+
+ /* Frame is ready to be output */
+ ret = av_frame_ref(frame, ctx->current);
+ if (ret < 0)
+ return ret;
+
+ /* Usual properties */
+ if (keyframe) {
+ frame->pict_type = AV_PICTURE_TYPE_I;
+ frame->key_frame = 1;
+ } else {
+ frame->pict_type = AV_PICTURE_TYPE_P;
+ }
+ *got_frame = 1;
+
+ return 0;
+}
+
+AVCodec ff_screenpresso_decoder = {
+ .name = "screenpresso",
+ .long_name = NULL_IF_CONFIG_SMALL("Screenpresso"),
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_SCREENPRESSO,
+ .init = screenpresso_init,
+ .decode = screenpresso_decode_frame,
+ .close = screenpresso_close,
+ .priv_data_size = sizeof(ScreenpressoContext),
+ .capabilities = AV_CODEC_CAP_DR1,
+ .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
+ FF_CODEC_CAP_INIT_CLEANUP,
+};
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 9c0ed3492a..1c97a1e5d2 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
#include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 57
-#define LIBAVCODEC_VERSION_MINOR 3
+#define LIBAVCODEC_VERSION_MINOR 4
#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
diff --git a/libavformat/riff.c b/libavformat/riff.c
index be76b0aa3d..a9197e76a3 100644
--- a/libavformat/riff.c
+++ b/libavformat/riff.c
@@ -374,6 +374,7 @@ const AVCodecTag ff_codec_bmp_tags[] = {
{ AV_CODEC_ID_TDSC, MKTAG('T', 'D', 'S', 'C') },
{ AV_CODEC_ID_HQ_HQA, MKTAG('C', 'U', 'V', 'C') },
{ AV_CODEC_ID_RV40, MKTAG('R', 'V', '4', '0') },
+ { AV_CODEC_ID_SCREENPRESSO, MKTAG('S', 'P', 'V', '1') },
{ AV_CODEC_ID_NONE, 0 }
};
diff --git a/tests/fate/video.mak b/tests/fate/video.mak
index f8218fbf94..a5754341fb 100644
--- a/tests/fate/video.mak
+++ b/tests/fate/video.mak
@@ -286,6 +286,9 @@ fate-roqvideo: CMD = framecrc -i $(TARGET_SAMPLES)/idroq/idlogo.roq -an
FATE_VIDEO-$(call DEMDEC, SMUSH, SANM) += fate-sanm
fate-sanm: CMD = framecrc -i $(TARGET_SAMPLES)/smush/ronin_part.znm -an -pix_fmt rgb24
+FATE_VIDEO-$(call DEMDEC, AVI, SCREENPRESSO) += fate-screenpresso
+fate-screenpresso: CMD = framecrc -i $(TARGET_SAMPLES)/spv1/bunny.avi
+
FATE_VIDEO-$(call DEMDEC, VMD, VMDVIDEO) += fate-sierra-vmd-video
fate-sierra-vmd-video: CMD = framecrc -i $(TARGET_SAMPLES)/vmd/12.vmd -pix_fmt rgb24 -an
diff --git a/tests/ref/fate/screenpresso b/tests/ref/fate/screenpresso
new file mode 100644
index 0000000000..bbdffb4433
--- /dev/null
+++ b/tests/ref/fate/screenpresso
@@ -0,0 +1,5 @@
+#tb 0: 1/15
+0, 0, 0, 1, 691200, 0xfdbdfad6
+0, 1, 1, 1, 691200, 0xc5feb961
+0, 4, 4, 1, 691200, 0x4c8c7e23
+0, 8, 8, 1, 691200, 0xd95c89f8