1 /*
2 * RL2 Video Decoder
3 * Copyright (C) 2008 Sascha Sommer (saschasommer@freenet.de)
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 * RL2 Video Decoder
25 * @author Sascha Sommer (saschasommer@freenet.de)
26 * @see http://wiki.multimedia.cx/index.php?title=RL2
27 */
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32
38
39
40 #define EXTRADATA1_SIZE (6 + 256 * 3) ///< video base, clr count, palette
41
44
46 uint32_t
clr_count;
///< number of used colors (currently unused)
50
51 /**
52 * Run Length Decode a single 320x200 frame
53 * @param s rl2 context
54 * @param in input buffer
55 * @param size input buffer size
56 * @param out output buffer
57 * @param stride stride of the output buffer
58 * @param video_base offset of the rle data inside the frame
59 */
62 {
66 int i;
71
72 /** copy start of the background frame */
73 for (i = 0; i <= base_y; i++) {
76 out += stride;
78 }
80 line_end = out - stride_adj;
81 out += base_x - stride;
82
83 /** decode the variable part of the frame */
84 while (in < in_end) {
87 if (val >= 0x80) {
88 if (in >= in_end)
89 break;
90 len = *in++;
91 if (!len)
92 break;
93 }
94
95 if (len >= out_end - out)
96 break;
97
99 val |= 0x80;
100 else
101 val &= ~0x80;
102
103 while (len--) {
104 *out++ = (val == 0x80) ? *back_frame : val;
105 back_frame++;
106 if (out == line_end) {
107 out += stride_adj;
108 line_end += stride;
109 if (len >= out_end - out)
110 break;
111 }
112 }
113 }
114
115 /** copy the rest from the background frame */
117 while (out < out_end) {
118 memcpy(out, back_frame, line_end - out);
119 back_frame += line_end -
out;
120 out = line_end + stride_adj;
121 line_end += stride;
122 }
123 }
124 }
125
126
127 /**
128 * Initialize the decoder
129 * @param avctx decoder context
130 * @return 0 success, -1 on error
131 */
133 {
135 int back_size;
136 int i;
137
140
141 /** parse extra data */
145 }
146
147 /** get frame_offset */
150
154 }
155
156 /** initialize palette */
159
160 /** decode background frame if present */
162
163 if (back_size > 0) {
165 if (!back_frame)
168 back_frame, avctx->
width, 0);
170 }
171 return 0;
172 }
173
174
176 void *
data,
int *got_frame,
178 {
181 int ret, buf_size = avpkt->
size;
183
186
187 /** run length decode */
190
191 /** make the palette available on the way out */
193
194 *got_frame = 1;
195
196 /** report that the buffer was completely consumed */
197 return buf_size;
198 }
199
200
201 /**
202 * Uninit decoder
203 * @param avctx decoder context
204 * @return 0 success, -1 on error
205 */
207 {
209
211
212 return 0;
213 }
214
215
226 };