History

Kega Game Video (KGV1) decoder

Originally committed as revision 22364 to svn://svn.ffmpeg.org/ffmpeg/trunk

Daniel Verkamp committed 16 years ago

Commit bf354121 parent 987e8577 files · +183 −0Browse files

Unified · Split

7 files
  1. Changelog +1 −0
  2. doc/general.texi +2 −0
  3. libavcodec/Makefile +1 −0
  4. libavcodec/allcodecs.c +1 −0
  5. libavcodec/avcodec.h +1 −0
  6. libavcodec/kgv1dec.c +176 −0
  7. libavformat/riff.c +1 −0
Changelog+1−0
@@ -62,6 +62,7 @@ version <next>: · 61 unmodified lines
62- AMR-NB decoder62- AMR-NB decoder
63- RTSP muxer63- RTSP muxer
64- HE-AAC v1 decoder64- HE-AAC v1 decoder
65- Kega Game Video (KGV1) decoder
65 66
66 67
67 68
doc/general.texi+2−0
@@ -403,6 +403,8 @@ following image formats are supported: · 402 unmodified lines
403 @tab Used in Interplay .MVE files.403 @tab Used in Interplay .MVE files.
404@item Karl Morton's video codec @tab @tab X404@item Karl Morton's video codec @tab @tab X
405 @tab Codec used in Worms games.405 @tab Codec used in Worms games.
406@item Kega Game Video (KGV1) @tab @tab X
407 @tab Kega emulator screen capture codec.
406@item LCL (LossLess Codec Library) MSZH @tab @tab X408@item LCL (LossLess Codec Library) MSZH @tab @tab X
407@item LCL (LossLess Codec Library) ZLIB @tab E @tab E409@item LCL (LossLess Codec Library) ZLIB @tab E @tab E
408@item LOCO @tab @tab X410@item LOCO @tab @tab X
libavcodec/Makefile+1−0
@@ -167,6 +167,7 @@ OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o · 166 unmodified lines
167OBJS-$(CONFIG_JPEGLS_DECODER) += jpeglsdec.o jpegls.o \167OBJS-$(CONFIG_JPEGLS_DECODER) += jpeglsdec.o jpegls.o \
168 mjpegdec.o mjpeg.o168 mjpegdec.o mjpeg.o
169OBJS-$(CONFIG_JPEGLS_ENCODER) += jpeglsenc.o jpegls.o169OBJS-$(CONFIG_JPEGLS_ENCODER) += jpeglsenc.o jpegls.o
170OBJS-$(CONFIG_KGV1_DECODER) += kgv1dec.o
170OBJS-$(CONFIG_KMVC_DECODER) += kmvc.o171OBJS-$(CONFIG_KMVC_DECODER) += kmvc.o
171OBJS-$(CONFIG_LJPEG_ENCODER) += ljpegenc.o mjpegenc.o mjpeg.o \172OBJS-$(CONFIG_LJPEG_ENCODER) += ljpegenc.o mjpegenc.o mjpeg.o \
172 mpegvideo_enc.o motion_est.o \173 mpegvideo_enc.o motion_est.o \
libavcodec/allcodecs.c+1−0
@@ -122,6 +122,7 @@ void avcodec_register_all(void) · 121 unmodified lines
122 REGISTER_DECODER (INDEO5, indeo5);122 REGISTER_DECODER (INDEO5, indeo5);
123 REGISTER_DECODER (INTERPLAY_VIDEO, interplay_video);123 REGISTER_DECODER (INTERPLAY_VIDEO, interplay_video);
124 REGISTER_ENCDEC (JPEGLS, jpegls);124 REGISTER_ENCDEC (JPEGLS, jpegls);
125 REGISTER_DECODER (KGV1, kgv1);
125 REGISTER_DECODER (KMVC, kmvc);126 REGISTER_DECODER (KMVC, kmvc);
126 REGISTER_ENCODER (LJPEG, ljpeg);127 REGISTER_ENCODER (LJPEG, ljpeg);
127 REGISTER_DECODER (LOCO, loco);128 REGISTER_DECODER (LOCO, loco);
libavcodec/avcodec.h+1−0
@@ -206,6 +206,7 @@ enum CodecID { · 205 unmodified lines
206 CODEC_ID_BINKVIDEO,206 CODEC_ID_BINKVIDEO,
207 CODEC_ID_IFF_ILBM,207 CODEC_ID_IFF_ILBM,
208 CODEC_ID_IFF_BYTERUN1,208 CODEC_ID_IFF_BYTERUN1,
209 CODEC_ID_KGV1,
209 210
210 /* various PCM "codecs" */211 /* various PCM "codecs" */
211 CODEC_ID_PCM_S16LE= 0x10000,212 CODEC_ID_PCM_S16LE= 0x10000,
libavcodec/kgv1dec.c+176−0
@@ -0,0 +1,176 @@
1/*
2 * Kega Game Video (KGV1) decoder
3 * Copyright (c) 2010 Daniel Verkamp
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22/**
23 * @file libavcodec/kgv1dec.c
24 * Kega Game Video decoder
25 */
26
27#include "libavutil/intreadwrite.h"
28#include "avcodec.h"
29
30typedef struct {
31 AVCodecContext *avctx;
32 AVFrame pic;
33 uint16_t *prev, *cur;
34} KgvContext;
35
36static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
37{
38 const uint8_t *buf = avpkt->data;
39 const uint8_t *buf_end = buf + avpkt->size;
40 KgvContext * const c = avctx->priv_data;
41 int offsets[7];
42 uint16_t *out, *prev;
43 int outcnt = 0, maxcnt;
44 int w, h, i;
45
46 if (avpkt->size < 2)
47 return -1;
48
49 w = (buf[0] + 1) * 8;
50 h = (buf[1] + 1) * 8;
51 buf += 2;
52
53 if (avcodec_check_dimensions(avctx, w, h))
54 return -1;
55
56 if (w != avctx->width || h != avctx->height)
57 avcodec_set_dimensions(avctx, w, h);
58
59 maxcnt = w * h;
60
61 out = av_realloc(c->cur, w * h * 2);
62 if (!out)
63 return -1;
64 c->cur = out;
65
66 prev = av_realloc(c->prev, w * h * 2);
67 if (!prev)
68 return -1;
69 c->prev = prev;
70
71 for (i = 0; i < 7; i++)
72 offsets[i] = -1;
73
74 while (outcnt < maxcnt && buf_end - 2 > buf) {
75 int code = AV_RL16(buf);
76 buf += 2;
77
78 if (!(code & 0x8000)) {
79 out[outcnt++] = code; // rgb555 pixel coded directly
80 } else {
81 int count;
82 uint16_t *inp;
83
84 if ((code & 0x6000) == 0x6000) {
85 // copy from previous frame
86 int oidx = (code >> 10) & 7;
87 int start;
88
89 count = (code & 0x3FF) + 3;
90
91 if (offsets[oidx] < 0) {
92 if (buf_end - 3 < buf)
93 break;
94 offsets[oidx] = AV_RL24(buf);
95 buf += 3;
96 }
97
98 start = (outcnt + offsets[oidx]) % maxcnt;
99
100 if (maxcnt - start < count)
101 break;
102
103 inp = prev + start;
104 } else {
105 // copy from earlier in this frame
106 int offset = (code & 0x1FFF) + 1;
107
108 if (!(code & 0x6000)) {
109 count = 2;
110 } else if ((code & 0x6000) == 0x2000) {
111 count = 3;
112 } else {
113 if (buf_end - 1 < buf)
114 break;
115 count = 4 + *buf++;
116 }
117
118 if (outcnt < offset)
119 break;
120
121 inp = out + outcnt - offset;
122 }
123
124 if (maxcnt - outcnt < count)
125 break;
126
127 for (i = 0; i < count; i++)
128 out[outcnt++] = inp[i];
129 }
130 }
131
132 if (outcnt - maxcnt)
133 av_log(avctx, AV_LOG_DEBUG, "frame finished with %d diff\n", outcnt - maxcnt);
134
135 c->pic.data[0] = (uint8_t *)c->cur;
136 c->pic.linesize[0] = w * 2;
137
138 *data_size = sizeof(AVFrame);
139 *(AVFrame*)data = c->pic;
140
141 FFSWAP(uint16_t *, c->cur, c->prev);
142
143 return avpkt->size;
144}
145
146static av_cold int decode_init(AVCodecContext *avctx)
147{
148 KgvContext * const c = avctx->priv_data;
149
150 c->avctx = avctx;
151 avctx->pix_fmt = PIX_FMT_RGB555;
152
153 return 0;
154}
155
156static av_cold int decode_end(AVCodecContext *avctx)
157{
158 KgvContext * const c = avctx->priv_data;
159
160 av_freep(&c->cur);
161 av_freep(&c->prev);
162
163 return 0;
164}
165
166AVCodec kgv1_decoder = {
167 "kgv1",
168 CODEC_TYPE_VIDEO,
169 CODEC_ID_KGV1,
170 sizeof(KgvContext),
171 decode_init,
172 NULL,
173 decode_end,
174 decode_frame,
175 .long_name = NULL_IF_CONFIG_SMALL("Kega Game Video"),
176};
libavformat/riff.c+1−0
@@ -240,6 +240,7 @@ const AVCodecTag ff_codec_bmp_tags[] = { · 239 unmodified lines
240 { CODEC_ID_AURA, MKTAG('A', 'U', 'R', 'A') },240 { CODEC_ID_AURA, MKTAG('A', 'U', 'R', 'A') },
241 { CODEC_ID_AURA2, MKTAG('A', 'U', 'R', '2') },241 { CODEC_ID_AURA2, MKTAG('A', 'U', 'R', '2') },
242 { CODEC_ID_DPX, MKTAG('d', 'p', 'x', ' ') },242 { CODEC_ID_DPX, MKTAG('d', 'p', 'x', ' ') },
243 { CODEC_ID_KGV1, MKTAG('K', 'G', 'V', '1') },
243 { CODEC_ID_NONE, 0 }244 { CODEC_ID_NONE, 0 }
244};245};
245 246

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