aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2021-02-17 17:32:57 +0100
committerPaul B Mahol <onemda@gmail.com>2021-02-20 17:42:00 +0100
commit8651bf8a2ed120bfdf81b4c498b0c2452de54b4e (patch)
treea7b6d30345c0e5b51ea004675c07bb2ff70cfe36
parent5a4f0d9b94e1f9b927a5468ac441ceb515e99fcd (diff)
downloadffmpeg-8651bf8a2ed120bfdf81b4c498b0c2452de54b4e.tar.gz
avcodec: add Simbiosis IMX video decoder
-rw-r--r--Changelog1
-rw-r--r--libavcodec/Makefile1
-rw-r--r--libavcodec/allcodecs.c1
-rw-r--r--libavcodec/codec_desc.c7
-rw-r--r--libavcodec/codec_id.h1
-rw-r--r--libavcodec/imx.c153
-rw-r--r--libavcodec/version.h2
7 files changed, 165 insertions, 1 deletions
diff --git a/Changelog b/Changelog
index ed8f1f448d..3067d951ed 100644
--- a/Changelog
+++ b/Changelog
@@ -75,6 +75,7 @@ version <next>:
- setts bitstream filter
- vif video filter
- OpenEXR image encoder
+- Simbiosis IMX decoder
version 4.3:
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index dac76f4465..6ec1d360ac 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -620,6 +620,7 @@ OBJS-$(CONFIG_SIPR_DECODER) += sipr.o acelp_pitch_delay.o \
acelp_filters.o celp_filters.o \
sipr16k.o
OBJS-$(CONFIG_SIREN_DECODER) += siren.o
+OBJS-$(CONFIG_SIMBIOSIS_IMX_DECODER) += imx.o
OBJS-$(CONFIG_SMACKAUD_DECODER) += smacker.o
OBJS-$(CONFIG_SMACKER_DECODER) += smacker.o
OBJS-$(CONFIG_SMC_DECODER) += smc.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index cb3f0e7c18..354d146379 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -293,6 +293,7 @@ extern AVCodec ff_sgi_encoder;
extern AVCodec ff_sgi_decoder;
extern AVCodec ff_sgirle_decoder;
extern AVCodec ff_sheervideo_decoder;
+extern AVCodec ff_simbiosis_imx_decoder;
extern AVCodec ff_smacker_decoder;
extern AVCodec ff_smc_decoder;
extern AVCodec ff_smvjpeg_decoder;
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index a7594f9004..8e695b11d2 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1842,6 +1842,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
.long_name = NULL_IF_CONFIG_SMALL("Cintel RAW"),
.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_LOSSLESS,
},
+ {
+ .id = AV_CODEC_ID_SIMBIOSIS_IMX,
+ .type = AVMEDIA_TYPE_VIDEO,
+ .name = "simbiosis_imx",
+ .long_name = NULL_IF_CONFIG_SMALL("Simbiosis Interactive IMX Video"),
+ .props = AV_CODEC_PROP_LOSSY,
+ },
/* various PCM "codecs" */
{
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index 7a8a896bfe..56a69cf1c2 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -305,6 +305,7 @@ enum AVCodecID {
AV_CODEC_ID_IPU,
AV_CODEC_ID_ARGO,
AV_CODEC_ID_CRI,
+ AV_CODEC_ID_SIMBIOSIS_IMX,
/* various PCM "codecs" */
AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs
diff --git a/libavcodec/imx.c b/libavcodec/imx.c
new file mode 100644
index 0000000000..1552a4ebea
--- /dev/null
+++ b/libavcodec/imx.c
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2021 Paul B Mahol
+ *
+ * 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
+ */
+
+#include "libavutil/common.h"
+#include "avcodec.h"
+#include "bytestream.h"
+#include "internal.h"
+
+typedef struct SimbiosisIMXContext {
+ uint32_t pal[256];
+ uint8_t history[32768];
+ int pos;
+} SimbiosisIMXContext;
+
+static av_cold int imx_decode_init(AVCodecContext *avctx)
+{
+ avctx->pix_fmt = AV_PIX_FMT_PAL8;
+ avctx->width = 320;
+ avctx->height = 160;
+ return 0;
+}
+
+static int imx_decode_frame(AVCodecContext *avctx, void *data,
+ int *got_frame, AVPacket *avpkt)
+{
+ SimbiosisIMXContext *imx = avctx->priv_data;
+ int ret, x, y, pal_size;
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &pal_size);
+ AVFrame *frame = data;
+ GetByteContext gb;
+
+ if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
+ return ret;
+
+ if (pal && pal_size == AVPALETTE_SIZE) {
+ memcpy(imx->pal, pal, pal_size);
+ frame->palette_has_changed = 1;
+ }
+
+ bytestream2_init(&gb, avpkt->data, avpkt->size);
+
+ memcpy(frame->data[1], imx->pal, AVPALETTE_SIZE);
+
+ x = 0, y = 0;
+ while (bytestream2_get_bytes_left(&gb) > 0 &&
+ x < 320 && y < 160) {
+ int b = bytestream2_get_byte(&gb);
+ int len = b & 0x3f;
+ int op = b >> 6;
+ int fill;
+
+ switch (op) {
+ case 3:
+ len = len * 64 + bytestream2_get_byte(&gb);
+ case 0:
+ while (len > 0) {
+ x++;
+ len--;
+ if (x >= 320) {
+ x = 0;
+ y++;
+ }
+ if (y >= 160)
+ break;
+ }
+ break;
+ case 1:
+ if (len == 0) {
+ int offset = bytestream2_get_le16(&gb);
+
+ if (offset < 0 || offset >= 32768)
+ return AVERROR_INVALIDDATA;
+
+ len = bytestream2_get_byte(&gb);
+ while (len > 0 && offset < 32768) {
+ frame->data[0][x + y * frame->linesize[0]] = imx->history[offset++];
+ x++;
+ len--;
+ if (x >= 320) {
+ x = 0;
+ y++;
+ }
+ if (y >= 160)
+ break;
+ }
+ } else {
+ while (len > 0) {
+ fill = bytestream2_get_byte(&gb);
+ frame->data[0][x + y * frame->linesize[0]] = fill;
+ if (imx->pos < 32768)
+ imx->history[imx->pos++] = fill;
+ x++;
+ len--;
+ if (x >= 320) {
+ x = 0;
+ y++;
+ }
+ if (y >= 160)
+ break;
+ }
+ }
+ break;
+ case 2:
+ fill = bytestream2_get_byte(&gb);
+
+ while (len > 0) {
+ frame->data[0][x + y * frame->linesize[0]] = fill;
+ x++;
+ len--;
+ if (x >= 320) {
+ x = 0;
+ y++;
+ }
+ if (y >= 160)
+ break;
+ }
+ break;
+ }
+ }
+
+ *got_frame = 1;
+
+ return avpkt->size;
+}
+
+AVCodec ff_simbiosis_imx_decoder = {
+ .name = "simbiosis_imx",
+ .long_name = NULL_IF_CONFIG_SMALL("Simbiosis Interactive IMX Video"),
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_SIMBIOSIS_IMX,
+ .priv_data_size = sizeof(SimbiosisIMXContext),
+ .init = imx_decode_init,
+ .decode = imx_decode_frame,
+ .capabilities = AV_CODEC_CAP_DR1,
+ .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
+};
diff --git a/libavcodec/version.h b/libavcodec/version.h
index d4fe2da937..9325da1028 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
#include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 58
-#define LIBAVCODEC_VERSION_MINOR 124
+#define LIBAVCODEC_VERSION_MINOR 125
#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \