History

avcodec: add Simbiosis IMX video decoder

Paul B Mahol committed 5 years ago

Commit 8651bf81 parent 5a4f0d97 files · +165 −1Browse files

Unified · Split

7 files
  1. Changelog +1 −0
  2. libavcodec/Makefile +1 −0
  3. libavcodec/allcodecs.c +1 −0
  4. libavcodec/codec_desc.c +7 −0
  5. libavcodec/codec_id.h +1 −0
  6. libavcodec/imx.c +153 −0
  7. libavcodec/version.h +1 −1
Changelog+1−0
@@ -75,6 +75,7 @@ version <next>: · 74 unmodified lines
7575 - setts bitstream filter
7676 - vif video filter
7777 - OpenEXR image encoder
78+- Simbiosis IMX decoder
7879
7980
8081 version 4.3:
libavcodec/Makefile+1−0
@@ -620,6 +620,7 @@ OBJS-$(CONFIG_SIPR_DECODER) += sipr.o acelp_pitch_delay.o \ · 619 unmodified lines
620620 acelp_filters.o celp_filters.o \
621621 sipr16k.o
622622 OBJS-$(CONFIG_SIREN_DECODER) += siren.o
623+OBJS-$(CONFIG_SIMBIOSIS_IMX_DECODER) += imx.o
623624 OBJS-$(CONFIG_SMACKAUD_DECODER) += smacker.o
624625 OBJS-$(CONFIG_SMACKER_DECODER) += smacker.o
625626 OBJS-$(CONFIG_SMC_DECODER) += smc.o
libavcodec/allcodecs.c+1−0
@@ -293,6 +293,7 @@ extern AVCodec ff_sgi_encoder; · 292 unmodified lines
293293 extern AVCodec ff_sgi_decoder;
294294 extern AVCodec ff_sgirle_decoder;
295295 extern AVCodec ff_sheervideo_decoder;
296+extern AVCodec ff_simbiosis_imx_decoder;
296297 extern AVCodec ff_smacker_decoder;
297298 extern AVCodec ff_smc_decoder;
298299 extern AVCodec ff_smvjpeg_decoder;
libavcodec/codec_desc.c+7−0
@@ -1842,6 +1842,13 @@ static const AVCodecDescriptor codec_descriptors[] = { · 1841 unmodified lines
18421842 .long_name = NULL_IF_CONFIG_SMALL("Cintel RAW"),
18431843 .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_LOSSLESS,
18441844 },
1845+ {
1846+ .id = AV_CODEC_ID_SIMBIOSIS_IMX,
1847+ .type = AVMEDIA_TYPE_VIDEO,
1848+ .name = "simbiosis_imx",
1849+ .long_name = NULL_IF_CONFIG_SMALL("Simbiosis Interactive IMX Video"),
1850+ .props = AV_CODEC_PROP_LOSSY,
1851+ },
18451852
18461853 /* various PCM "codecs" */
18471854 {
libavcodec/codec_id.h+1−0
@@ -305,6 +305,7 @@ enum AVCodecID { · 304 unmodified lines
305305 AV_CODEC_ID_IPU,
306306 AV_CODEC_ID_ARGO,
307307 AV_CODEC_ID_CRI,
308+ AV_CODEC_ID_SIMBIOSIS_IMX,
308309
309310 /* various PCM "codecs" */
310311 AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs
libavcodec/imx.c+153−0
@@ -0,0 +1,153 @@
1+/*
2+ * Copyright (c) 2021 Paul B Mahol
3+ *
4+ * This file is part of FFmpeg.
5+ *
6+ * FFmpeg is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser General Public
8+ * License as published by the Free Software Foundation; either
9+ * version 2.1 of the License, or (at your option) any later version.
10+ *
11+ * FFmpeg is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+ * Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with FFmpeg; if not, write to the Free Software
18+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+ */
20+
21+#include "libavutil/common.h"
22+#include "avcodec.h"
23+#include "bytestream.h"
24+#include "internal.h"
25+
26+typedef struct SimbiosisIMXContext {
27+ uint32_t pal[256];
28+ uint8_t history[32768];
29+ int pos;
30+} SimbiosisIMXContext;
31+
32+static av_cold int imx_decode_init(AVCodecContext *avctx)
33+{
34+ avctx->pix_fmt = AV_PIX_FMT_PAL8;
35+ avctx->width = 320;
36+ avctx->height = 160;
37+ return 0;
38+}
39+
40+static int imx_decode_frame(AVCodecContext *avctx, void *data,
41+ int *got_frame, AVPacket *avpkt)
42+{
43+ SimbiosisIMXContext *imx = avctx->priv_data;
44+ int ret, x, y, pal_size;
45+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &pal_size);
46+ AVFrame *frame = data;
47+ GetByteContext gb;
48+
49+ if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
50+ return ret;
51+
52+ if (pal && pal_size == AVPALETTE_SIZE) {
53+ memcpy(imx->pal, pal, pal_size);
54+ frame->palette_has_changed = 1;
55+ }
56+
57+ bytestream2_init(&gb, avpkt->data, avpkt->size);
58+
59+ memcpy(frame->data[1], imx->pal, AVPALETTE_SIZE);
60+
61+ x = 0, y = 0;
62+ while (bytestream2_get_bytes_left(&gb) > 0 &&
63+ x < 320 && y < 160) {
64+ int b = bytestream2_get_byte(&gb);
65+ int len = b & 0x3f;
66+ int op = b >> 6;
67+ int fill;
68+
69+ switch (op) {
70+ case 3:
71+ len = len * 64 + bytestream2_get_byte(&gb);
72+ case 0:
73+ while (len > 0) {
74+ x++;
75+ len--;
76+ if (x >= 320) {
77+ x = 0;
78+ y++;
79+ }
80+ if (y >= 160)
81+ break;
82+ }
83+ break;
84+ case 1:
85+ if (len == 0) {
86+ int offset = bytestream2_get_le16(&gb);
87+
88+ if (offset < 0 || offset >= 32768)
89+ return AVERROR_INVALIDDATA;
90+
91+ len = bytestream2_get_byte(&gb);
92+ while (len > 0 && offset < 32768) {
93+ frame->data[0][x + y * frame->linesize[0]] = imx->history[offset++];
94+ x++;
95+ len--;
96+ if (x >= 320) {
97+ x = 0;
98+ y++;
99+ }
100+ if (y >= 160)
101+ break;
102+ }
103+ } else {
104+ while (len > 0) {
105+ fill = bytestream2_get_byte(&gb);
106+ frame->data[0][x + y * frame->linesize[0]] = fill;
107+ if (imx->pos < 32768)
108+ imx->history[imx->pos++] = fill;
109+ x++;
110+ len--;
111+ if (x >= 320) {
112+ x = 0;
113+ y++;
114+ }
115+ if (y >= 160)
116+ break;
117+ }
118+ }
119+ break;
120+ case 2:
121+ fill = bytestream2_get_byte(&gb);
122+
123+ while (len > 0) {
124+ frame->data[0][x + y * frame->linesize[0]] = fill;
125+ x++;
126+ len--;
127+ if (x >= 320) {
128+ x = 0;
129+ y++;
130+ }
131+ if (y >= 160)
132+ break;
133+ }
134+ break;
135+ }
136+ }
137+
138+ *got_frame = 1;
139+
140+ return avpkt->size;
141+}
142+
143+AVCodec ff_simbiosis_imx_decoder = {
144+ .name = "simbiosis_imx",
145+ .long_name = NULL_IF_CONFIG_SMALL("Simbiosis Interactive IMX Video"),
146+ .type = AVMEDIA_TYPE_VIDEO,
147+ .id = AV_CODEC_ID_SIMBIOSIS_IMX,
148+ .priv_data_size = sizeof(SimbiosisIMXContext),
149+ .init = imx_decode_init,
150+ .decode = imx_decode_frame,
151+ .capabilities = AV_CODEC_CAP_DR1,
152+ .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
153+};
libavcodec/version.h+1−1
@@ -28,7 +28,7 @@ · 27 unmodified lines
2828 #include "libavutil/version.h"
2929
3030 #define LIBAVCODEC_VERSION_MAJOR 58
31−#define LIBAVCODEC_VERSION_MINOR 124
31+#define LIBAVCODEC_VERSION_MINOR 125
3232 #define LIBAVCODEC_VERSION_MICRO 100
3333
3434 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t