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
24 * Kega Game Video decoder
25 */
26
32
37
39 {
41
44 }
45
48 {
53 int offsets[8];
55 int outcnt = 0, maxcnt;
57
60
61 w = (buf[0] + 1) * 8;
62 h = (buf[1] + 1) * 8;
63 buf += 2;
64
65 if (avpkt->
size < 2 + w*h / 513)
67
72 return res;
73 }
74
81 }
82 }
83
85
87 return res;
90
91 for (i = 0; i < 8; i++)
92 offsets[i] = -1;
93
94 while (outcnt < maxcnt && buf_end - 2 >= buf) {
96 buf += 2;
97
98 if (!(code & 0x8000)) {
99 AV_WN16A(&out[2 * outcnt], code);
// rgb555 pixel coded directly
100 outcnt++;
101 } else {
103
104 if ((code & 0x6000) == 0x6000) {
105 // copy from previous frame
106 int oidx = (code >> 10) & 7;
108
109 count = (code & 0x3FF) + 3;
110
111 if (offsets[oidx] < 0) {
112 if (buf_end - 3 < buf)
113 break;
115 buf += 3;
116 }
117
118 start = (outcnt + offsets[oidx]) % maxcnt;
119
120 if (maxcnt - start < count || maxcnt - outcnt < count)
121 break;
122
123 if (!prev) {
125 "Frame reference does not exist\n");
126 break;
127 }
128
129 memcpy(out + 2 * outcnt, prev + 2 * start, 2 * count);
130 } else {
131 // copy from earlier in this frame
132 int offset = (code & 0x1FFF) + 1;
133
134 if (!(code & 0x6000)) {
135 count = 2;
136 } else if ((code & 0x6000) == 0x2000) {
137 count = 3;
138 } else {
139 if (buf_end - 1 < buf)
140 break;
141 count = 4 + *buf++;
142 }
143
144 if (outcnt < offset || maxcnt - outcnt < count)
145 break;
146
148 }
150 }
151 }
152
153 if (outcnt - maxcnt)
155
160
161 *got_frame = 1;
162
164 }
165
167 {
169
170 return 0;
171 }
172
174 {
176 return 0;
177 }
178
190 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
static void flush(AVCodecContext *avctx)
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
static av_cold int init(AVCodecContext *avctx)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_cold int decode_end(AVCodecContext *avctx)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
const char * name
Name of the codec implementation.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_RL24
static const uint8_t offset[127][2]
int width
picture width / height.
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static void decode_flush(AVCodecContext *avctx)
static av_cold int decode_init(AVCodecContext *avctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
uint16_t * last_frame_buffer
common internal api header.
common internal and external API header
#define AV_PIX_FMT_RGB555
#define FFSWAP(type, a, b)
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.