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 <string.h>
30
37
38
39 #define EXTRADATA1_SIZE (6 + 256 * 3) ///< video base, clr count, palette
40
43
45 uint32_t
clr_count;
///< number of used colors (currently unused)
49
50 /**
51 * Run Length Decode a single 320x200 frame
52 * @param s rl2 context
53 * @param in input buffer
54 * @param size input buffer size
55 * @param out output buffer
56 * @param stride stride of the output buffer
57 * @param video_base offset of the rle data inside the frame
58 */
60 uint8_t *
out, ptrdiff_t
stride,
int video_base)
61 {
62 int base_x = video_base %
s->avctx->width;
63 int base_y = video_base /
s->avctx->width;
64 ptrdiff_t stride_adj =
stride -
s->avctx->width;
65 const uint8_t *back_frame =
s->back_frame;
66 const uint8_t *in_end = in +
size;
67 const uint8_t *out_end =
out +
stride *
s->avctx->height - stride_adj;
68 uint8_t *line_end;
69
70 /** copy start of the background frame */
72 for (
int i = 0;
i <= base_y;
i++) {
73 memcpy(
out, back_frame,
s->avctx->width);
75 back_frame +=
s->avctx->width;
76 }
77 back_frame += base_x -
s->avctx->width;
78 } else {
80 }
81 line_end =
out - stride_adj;
83
84 /** decode the variable part of the frame */
85 while (in < in_end) {
89 if (in >= in_end)
90 break;
93 break;
95 }
96
97 if (back_frame) {
99 do {
105 if (
out == line_end) {
107 return;
110 }
112 continue;
113 }
116 }
117
120 if (
out == line_end) {
122 return;
125 }
126 }
127 }
128
129 /** copy the rest from the background frame */
131 while (1) {
132 memcpy(
out, back_frame, line_end -
out);
133 if (line_end == out_end)
134 break;
135 back_frame += line_end -
out;
136 out = line_end + stride_adj;
138 }
139 }
140 }
141
142
143 /**
144 * Initialize the decoder
145 * @param avctx decoder context
146 * @return 0 success, -1 on error
147 */
149 {
151 int back_size;
154
157
161
162 /** parse extra data */
166 }
167
168 /** get frame_offset */
171
175 }
176
177 /** initialize palette */
180
181 /** decode background frame if present */
183
184 if (back_size > 0) {
185 /* The 254 are padding to ensure that pointer arithmetic stays within
186 * the buffer. */
188 if (!back_frame)
191 back_frame, avctx->
width, 0);
192 s->back_frame = back_frame;
193 }
194 return 0;
195 }
196
197
200 {
201 const uint8_t *buf = avpkt->
data;
202 int ret, buf_size = avpkt->
size;
204
207
208 /** run length decode */
211
212 /** make the palette available on the way out */
214
215 *got_frame = 1;
216
217 /** report that the buffer was completely consumed */
218 return buf_size;
219 }
220
221
222 /**
223 * Uninit decoder
224 * @param avctx decoder context
225 * @return 0 success, -1 on error
226 */
228 {
230
232
233 return 0;
234 }
235
236
247 };