Mercurial > libavcodec.hg
annotate interplayvideo.c @ 10717:4b1bc4a1ff14 libavcodec
10l trocadero: forgot one case where picture linesize should be used
author | kostya |
---|---|
date | Sun, 27 Dec 2009 08:56:06 +0000 |
parents | e64842a691d8 |
children | 1b91df81bda4 |
rev | line source |
---|---|
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
1 /* |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
2 * Interplay MVE Video Decoder |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
3 * Copyright (C) 2003 the ffmpeg project |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
4 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
5 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
6 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
16 * |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2962
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
20 */ |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
21 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
22 /** |
8718
e9d9d946f213
Use full internal pathname in doxygen @file directives.
diego
parents:
7040
diff
changeset
|
23 * @file libavcodec/interplayvideo.c |
1468 | 24 * Interplay MVE Video Decoder by Mike Melanson (melanson@pcisys.net) |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
25 * For more information about the Interplay MVE format, visit: |
1468 | 26 * http://www.pcisys.net/~melanson/codecs/interplay-mve.txt |
27 * This code is written in such a way that the identifiers match up | |
28 * with the encoding descriptions in the document. | |
29 * | |
30 * This decoder presently only supports a PAL8 output colorspace. | |
31 * | |
32 * An Interplay video frame consists of 2 parts: The decoding map and | |
33 * the video data. A demuxer must load these 2 parts together in a single | |
34 * buffer before sending it through the stream to this decoder. | |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
35 */ |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
36 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
37 #include <stdio.h> |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
38 #include <stdlib.h> |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
39 #include <string.h> |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
40 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
41 #include "avcodec.h" |
5089 | 42 #include "bytestream.h" |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
43 #include "dsputil.h" |
9494
e09e4c095fdb
Simplify ipvideo_decode_opcodes by using get_bits, this might be slower
reimar
parents:
9493
diff
changeset
|
44 #define ALT_BITSTREAM_READER_LE |
e09e4c095fdb
Simplify ipvideo_decode_opcodes by using get_bits, this might be slower
reimar
parents:
9493
diff
changeset
|
45 #include "get_bits.h" |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
46 |
1468 | 47 #define PALETTE_COUNT 256 |
48 | |
49 /* debugging support */ | |
50 #define DEBUG_INTERPLAY 0 | |
51 #if DEBUG_INTERPLAY | |
2515 | 52 #define debug_interplay(x,...) av_log(NULL, AV_LOG_DEBUG, x, __VA_ARGS__) |
1468 | 53 #else |
54 static inline void debug_interplay(const char *format, ...) { } | |
55 #endif | |
56 | |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
57 typedef struct IpvideoContext { |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
58 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
59 AVCodecContext *avctx; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
60 DSPContext dsp; |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
61 AVFrame second_last_frame; |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
62 AVFrame last_frame; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
63 AVFrame current_frame; |
6218 | 64 const unsigned char *decoding_map; |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
65 int decoding_map_size; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
66 |
6218 | 67 const unsigned char *buf; |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
68 int size; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
69 |
10712 | 70 int is_16bpp; |
6218 | 71 const unsigned char *stream_ptr; |
72 const unsigned char *stream_end; | |
1475 | 73 unsigned char *pixel_ptr; |
74 int line_inc; | |
75 int stride; | |
76 int upper_motion_limit_offset; | |
77 | |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
78 } IpvideoContext; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
79 |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
80 #define CHECK_STREAM_PTR(stream_ptr, stream_end, n) \ |
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
81 if (stream_end - stream_ptr < n) { \ |
10709 | 82 av_log(s->avctx, AV_LOG_ERROR, "Interplay video warning: stream_ptr out of bounds (%p >= %p)\n", \ |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
83 stream_ptr + n, stream_end); \ |
10709 | 84 return -1; \ |
85 } | |
1468 | 86 |
9277
b8e5b7edb2d5
Merge the 3 COPY_FROM_* macros with lots of duplicated code into a single
reimar
parents:
9276
diff
changeset
|
87 static int copy_from(IpvideoContext *s, AVFrame *src, int delta_x, int delta_y) |
b8e5b7edb2d5
Merge the 3 COPY_FROM_* macros with lots of duplicated code into a single
reimar
parents:
9276
diff
changeset
|
88 { |
b8e5b7edb2d5
Merge the 3 COPY_FROM_* macros with lots of duplicated code into a single
reimar
parents:
9276
diff
changeset
|
89 int current_offset = s->pixel_ptr - s->current_frame.data[0]; |
10716
e64842a691d8
cosmetics: reindent and break long lines after last commits
kostya
parents:
10715
diff
changeset
|
90 int motion_offset = current_offset + delta_y * s->current_frame.linesize[0] |
e64842a691d8
cosmetics: reindent and break long lines after last commits
kostya
parents:
10715
diff
changeset
|
91 + delta_x * (1 + s->is_16bpp); |
9277
b8e5b7edb2d5
Merge the 3 COPY_FROM_* macros with lots of duplicated code into a single
reimar
parents:
9276
diff
changeset
|
92 if (motion_offset < 0) { |
b8e5b7edb2d5
Merge the 3 COPY_FROM_* macros with lots of duplicated code into a single
reimar
parents:
9276
diff
changeset
|
93 av_log(s->avctx, AV_LOG_ERROR, " Interplay video: motion offset < 0 (%d)\n", motion_offset); |
b8e5b7edb2d5
Merge the 3 COPY_FROM_* macros with lots of duplicated code into a single
reimar
parents:
9276
diff
changeset
|
94 return -1; |
b8e5b7edb2d5
Merge the 3 COPY_FROM_* macros with lots of duplicated code into a single
reimar
parents:
9276
diff
changeset
|
95 } else if (motion_offset > s->upper_motion_limit_offset) { |
b8e5b7edb2d5
Merge the 3 COPY_FROM_* macros with lots of duplicated code into a single
reimar
parents:
9276
diff
changeset
|
96 av_log(s->avctx, AV_LOG_ERROR, " Interplay video: motion offset above limit (%d >= %d)\n", |
b8e5b7edb2d5
Merge the 3 COPY_FROM_* macros with lots of duplicated code into a single
reimar
parents:
9276
diff
changeset
|
97 motion_offset, s->upper_motion_limit_offset); |
b8e5b7edb2d5
Merge the 3 COPY_FROM_* macros with lots of duplicated code into a single
reimar
parents:
9276
diff
changeset
|
98 return -1; |
b8e5b7edb2d5
Merge the 3 COPY_FROM_* macros with lots of duplicated code into a single
reimar
parents:
9276
diff
changeset
|
99 } |
10716
e64842a691d8
cosmetics: reindent and break long lines after last commits
kostya
parents:
10715
diff
changeset
|
100 s->dsp.put_pixels_tab[!s->is_16bpp][0](s->pixel_ptr, src->data[0] + motion_offset, |
e64842a691d8
cosmetics: reindent and break long lines after last commits
kostya
parents:
10715
diff
changeset
|
101 s->current_frame.linesize[0], 8); |
9277
b8e5b7edb2d5
Merge the 3 COPY_FROM_* macros with lots of duplicated code into a single
reimar
parents:
9276
diff
changeset
|
102 return 0; |
b8e5b7edb2d5
Merge the 3 COPY_FROM_* macros with lots of duplicated code into a single
reimar
parents:
9276
diff
changeset
|
103 } |
1475 | 104 |
105 static int ipvideo_decode_block_opcode_0x0(IpvideoContext *s) | |
1468 | 106 { |
9277
b8e5b7edb2d5
Merge the 3 COPY_FROM_* macros with lots of duplicated code into a single
reimar
parents:
9276
diff
changeset
|
107 return copy_from(s, &s->last_frame, 0, 0); |
1468 | 108 } |
109 | |
1475 | 110 static int ipvideo_decode_block_opcode_0x1(IpvideoContext *s) |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
111 { |
9277
b8e5b7edb2d5
Merge the 3 COPY_FROM_* macros with lots of duplicated code into a single
reimar
parents:
9276
diff
changeset
|
112 return copy_from(s, &s->second_last_frame, 0, 0); |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
113 } |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
114 |
1475 | 115 static int ipvideo_decode_block_opcode_0x2(IpvideoContext *s) |
1468 | 116 { |
117 unsigned char B; | |
118 int x, y; | |
119 | |
1475 | 120 /* copy block from 2 frames ago using a motion vector; need 1 more byte */ |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
121 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 1); |
1475 | 122 B = *s->stream_ptr++; |
1468 | 123 |
124 if (B < 56) { | |
125 x = 8 + (B % 7); | |
126 y = B / 7; | |
127 } else { | |
128 x = -14 + ((B - 56) % 29); | |
129 y = 8 + ((B - 56) / 29); | |
130 } | |
131 | |
132 debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y); | |
9277
b8e5b7edb2d5
Merge the 3 COPY_FROM_* macros with lots of duplicated code into a single
reimar
parents:
9276
diff
changeset
|
133 return copy_from(s, &s->second_last_frame, x, y); |
1468 | 134 } |
135 | |
1475 | 136 static int ipvideo_decode_block_opcode_0x3(IpvideoContext *s) |
1468 | 137 { |
138 unsigned char B; | |
139 int x, y; | |
140 | |
141 /* copy 8x8 block from current frame from an up/left block */ | |
142 | |
143 /* need 1 more byte for motion */ | |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
144 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 1); |
1475 | 145 B = *s->stream_ptr++; |
1468 | 146 |
147 if (B < 56) { | |
148 x = -(8 + (B % 7)); | |
149 y = -(B / 7); | |
150 } else { | |
151 x = -(-14 + ((B - 56) % 29)); | |
152 y = -( 8 + ((B - 56) / 29)); | |
153 } | |
154 | |
155 debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y); | |
9277
b8e5b7edb2d5
Merge the 3 COPY_FROM_* macros with lots of duplicated code into a single
reimar
parents:
9276
diff
changeset
|
156 return copy_from(s, &s->current_frame, x, y); |
1468 | 157 } |
158 | |
1475 | 159 static int ipvideo_decode_block_opcode_0x4(IpvideoContext *s) |
1468 | 160 { |
161 int x, y; | |
162 unsigned char B, BL, BH; | |
163 | |
164 /* copy a block from the previous frame; need 1 more byte */ | |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
165 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 1); |
1468 | 166 |
1475 | 167 B = *s->stream_ptr++; |
1468 | 168 BL = B & 0x0F; |
169 BH = (B >> 4) & 0x0F; | |
170 x = -8 + BL; | |
171 y = -8 + BH; | |
172 | |
173 debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y); | |
9277
b8e5b7edb2d5
Merge the 3 COPY_FROM_* macros with lots of duplicated code into a single
reimar
parents:
9276
diff
changeset
|
174 return copy_from(s, &s->last_frame, x, y); |
1468 | 175 } |
176 | |
1475 | 177 static int ipvideo_decode_block_opcode_0x5(IpvideoContext *s) |
1468 | 178 { |
179 signed char x, y; | |
180 | |
181 /* copy a block from the previous frame using an expanded range; | |
182 * need 2 more bytes */ | |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
183 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 2); |
1468 | 184 |
1475 | 185 x = *s->stream_ptr++; |
186 y = *s->stream_ptr++; | |
1468 | 187 |
188 debug_interplay (" motion bytes = %d, %d\n", x, y); | |
9277
b8e5b7edb2d5
Merge the 3 COPY_FROM_* macros with lots of duplicated code into a single
reimar
parents:
9276
diff
changeset
|
189 return copy_from(s, &s->last_frame, x, y); |
1468 | 190 } |
191 | |
1475 | 192 static int ipvideo_decode_block_opcode_0x6(IpvideoContext *s) |
1468 | 193 { |
194 /* mystery opcode? skip multiple blocks? */ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1585
diff
changeset
|
195 av_log(s->avctx, AV_LOG_ERROR, " Interplay video: Help! Mystery opcode 0x6 seen\n"); |
1468 | 196 |
197 /* report success */ | |
198 return 0; | |
199 } | |
200 | |
1475 | 201 static int ipvideo_decode_block_opcode_0x7(IpvideoContext *s) |
1468 | 202 { |
203 int x, y; | |
9298
9698f0d03ed9
Avoid code duplication by using ?: and array indexing instead of if..else
reimar
parents:
9297
diff
changeset
|
204 unsigned char P[2]; |
1468 | 205 unsigned int flags; |
206 | |
207 /* 2-color encoding */ | |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
208 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 2); |
1468 | 209 |
9298
9698f0d03ed9
Avoid code duplication by using ?: and array indexing instead of if..else
reimar
parents:
9297
diff
changeset
|
210 P[0] = *s->stream_ptr++; |
9698f0d03ed9
Avoid code duplication by using ?: and array indexing instead of if..else
reimar
parents:
9297
diff
changeset
|
211 P[1] = *s->stream_ptr++; |
1468 | 212 |
9298
9698f0d03ed9
Avoid code duplication by using ?: and array indexing instead of if..else
reimar
parents:
9297
diff
changeset
|
213 if (P[0] <= P[1]) { |
1468 | 214 |
215 /* need 8 more bytes from the stream */ | |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
216 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 8); |
1468 | 217 |
218 for (y = 0; y < 8; y++) { | |
9307
851ca5db8327
Avoid the last two uses of bitmasks in interplayvideo
reimar
parents:
9306
diff
changeset
|
219 flags = *s->stream_ptr++ | 0x100; |
9319 | 220 for (; flags != 1; flags >>= 1) |
9307
851ca5db8327
Avoid the last two uses of bitmasks in interplayvideo
reimar
parents:
9306
diff
changeset
|
221 *s->pixel_ptr++ = P[flags & 1]; |
1475 | 222 s->pixel_ptr += s->line_inc; |
1468 | 223 } |
224 | |
225 } else { | |
226 | |
227 /* need 2 more bytes from the stream */ | |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
228 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 2); |
1468 | 229 |
5089 | 230 flags = bytestream_get_le16(&s->stream_ptr); |
1468 | 231 for (y = 0; y < 8; y += 2) { |
9296
2129ee5b7e0d
Get rid of some pointless bitmask/shifter variables in interplayvideo.c
reimar
parents:
9277
diff
changeset
|
232 for (x = 0; x < 8; x += 2, flags >>= 1) { |
9299 | 233 s->pixel_ptr[x ] = |
234 s->pixel_ptr[x + 1 ] = | |
235 s->pixel_ptr[x + s->stride] = | |
236 s->pixel_ptr[x + 1 + s->stride] = P[flags & 1]; | |
1468 | 237 } |
1475 | 238 s->pixel_ptr += s->stride * 2; |
1468 | 239 } |
240 } | |
241 | |
242 /* report success */ | |
243 return 0; | |
244 } | |
245 | |
1475 | 246 static int ipvideo_decode_block_opcode_0x8(IpvideoContext *s) |
1468 | 247 { |
248 int x, y; | |
9312
601e91e470e7
Make ipvideo_decode_block_opcode_0x8 a lot simpler by decoding the pixels
reimar
parents:
9311
diff
changeset
|
249 unsigned char P[2]; |
1468 | 250 unsigned int flags = 0; |
251 | |
252 /* 2-color encoding for each 4x4 quadrant, or 2-color encoding on | |
253 * either top and bottom or left and right halves */ | |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
254 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 2); |
1468 | 255 |
1475 | 256 P[0] = *s->stream_ptr++; |
257 P[1] = *s->stream_ptr++; | |
1468 | 258 |
259 if (P[0] <= P[1]) { | |
260 | |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
261 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 14); |
9312
601e91e470e7
Make ipvideo_decode_block_opcode_0x8 a lot simpler by decoding the pixels
reimar
parents:
9311
diff
changeset
|
262 s->stream_ptr -= 2; |
1468 | 263 |
9312
601e91e470e7
Make ipvideo_decode_block_opcode_0x8 a lot simpler by decoding the pixels
reimar
parents:
9311
diff
changeset
|
264 for (y = 0; y < 16; y++) { |
601e91e470e7
Make ipvideo_decode_block_opcode_0x8 a lot simpler by decoding the pixels
reimar
parents:
9311
diff
changeset
|
265 // new values for each 4x4 block |
601e91e470e7
Make ipvideo_decode_block_opcode_0x8 a lot simpler by decoding the pixels
reimar
parents:
9311
diff
changeset
|
266 if (!(y & 3)) { |
601e91e470e7
Make ipvideo_decode_block_opcode_0x8 a lot simpler by decoding the pixels
reimar
parents:
9311
diff
changeset
|
267 P[0] = *s->stream_ptr++; P[1] = *s->stream_ptr++; |
601e91e470e7
Make ipvideo_decode_block_opcode_0x8 a lot simpler by decoding the pixels
reimar
parents:
9311
diff
changeset
|
268 flags = bytestream_get_le16(&s->stream_ptr); |
1468 | 269 } |
270 | |
9319 | 271 for (x = 0; x < 4; x++, flags >>= 1) |
9312
601e91e470e7
Make ipvideo_decode_block_opcode_0x8 a lot simpler by decoding the pixels
reimar
parents:
9311
diff
changeset
|
272 *s->pixel_ptr++ = P[flags & 1]; |
601e91e470e7
Make ipvideo_decode_block_opcode_0x8 a lot simpler by decoding the pixels
reimar
parents:
9311
diff
changeset
|
273 s->pixel_ptr += s->stride - 4; |
601e91e470e7
Make ipvideo_decode_block_opcode_0x8 a lot simpler by decoding the pixels
reimar
parents:
9311
diff
changeset
|
274 // switch to right half |
601e91e470e7
Make ipvideo_decode_block_opcode_0x8 a lot simpler by decoding the pixels
reimar
parents:
9311
diff
changeset
|
275 if (y == 7) s->pixel_ptr -= 8 * s->stride - 4; |
1468 | 276 } |
277 | |
278 } else { | |
279 | |
280 /* need 10 more bytes */ | |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
281 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 10); |
1468 | 282 |
9306 | 283 if (s->stream_ptr[4] <= s->stream_ptr[5]) { |
1468 | 284 |
9312
601e91e470e7
Make ipvideo_decode_block_opcode_0x8 a lot simpler by decoding the pixels
reimar
parents:
9311
diff
changeset
|
285 flags = bytestream_get_le32(&s->stream_ptr); |
9300
6a1aacfa3043
Slightly simplify part of ipvideo_decode_block_opcode_0x8
reimar
parents:
9299
diff
changeset
|
286 |
1468 | 287 /* vertical split; left & right halves are 2-color encoded */ |
288 | |
9312
601e91e470e7
Make ipvideo_decode_block_opcode_0x8 a lot simpler by decoding the pixels
reimar
parents:
9311
diff
changeset
|
289 for (y = 0; y < 16; y++) { |
9319 | 290 for (x = 0; x < 4; x++, flags >>= 1) |
9312
601e91e470e7
Make ipvideo_decode_block_opcode_0x8 a lot simpler by decoding the pixels
reimar
parents:
9311
diff
changeset
|
291 *s->pixel_ptr++ = P[flags & 1]; |
601e91e470e7
Make ipvideo_decode_block_opcode_0x8 a lot simpler by decoding the pixels
reimar
parents:
9311
diff
changeset
|
292 s->pixel_ptr += s->stride - 4; |
601e91e470e7
Make ipvideo_decode_block_opcode_0x8 a lot simpler by decoding the pixels
reimar
parents:
9311
diff
changeset
|
293 // switch to right half |
601e91e470e7
Make ipvideo_decode_block_opcode_0x8 a lot simpler by decoding the pixels
reimar
parents:
9311
diff
changeset
|
294 if (y == 7) { |
601e91e470e7
Make ipvideo_decode_block_opcode_0x8 a lot simpler by decoding the pixels
reimar
parents:
9311
diff
changeset
|
295 s->pixel_ptr -= 8 * s->stride - 4; |
601e91e470e7
Make ipvideo_decode_block_opcode_0x8 a lot simpler by decoding the pixels
reimar
parents:
9311
diff
changeset
|
296 P[0] = *s->stream_ptr++; P[1] = *s->stream_ptr++; |
601e91e470e7
Make ipvideo_decode_block_opcode_0x8 a lot simpler by decoding the pixels
reimar
parents:
9311
diff
changeset
|
297 flags = bytestream_get_le32(&s->stream_ptr); |
1468 | 298 } |
299 } | |
300 | |
301 } else { | |
302 | |
303 /* horizontal split; top & bottom halves are 2-color encoded */ | |
304 | |
305 for (y = 0; y < 8; y++) { | |
9300
6a1aacfa3043
Slightly simplify part of ipvideo_decode_block_opcode_0x8
reimar
parents:
9299
diff
changeset
|
306 if (y == 4) { |
6a1aacfa3043
Slightly simplify part of ipvideo_decode_block_opcode_0x8
reimar
parents:
9299
diff
changeset
|
307 P[0] = *s->stream_ptr++; |
6a1aacfa3043
Slightly simplify part of ipvideo_decode_block_opcode_0x8
reimar
parents:
9299
diff
changeset
|
308 P[1] = *s->stream_ptr++; |
1468 | 309 } |
9307
851ca5db8327
Avoid the last two uses of bitmasks in interplayvideo
reimar
parents:
9306
diff
changeset
|
310 flags = *s->stream_ptr++ | 0x100; |
1468 | 311 |
9319 | 312 for (; flags != 1; flags >>= 1) |
9307
851ca5db8327
Avoid the last two uses of bitmasks in interplayvideo
reimar
parents:
9306
diff
changeset
|
313 *s->pixel_ptr++ = P[flags & 1]; |
1475 | 314 s->pixel_ptr += s->line_inc; |
1468 | 315 } |
316 } | |
317 } | |
318 | |
319 /* report success */ | |
320 return 0; | |
321 } | |
322 | |
1475 | 323 static int ipvideo_decode_block_opcode_0x9(IpvideoContext *s) |
1468 | 324 { |
325 int x, y; | |
326 unsigned char P[4]; | |
327 | |
328 /* 4-color encoding */ | |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
329 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 4); |
1468 | 330 |
9273
42c63846b321
Replace many tiny loops in the interplayvideo decoder by memset, memcpy
reimar
parents:
9272
diff
changeset
|
331 memcpy(P, s->stream_ptr, 4); |
42c63846b321
Replace many tiny loops in the interplayvideo decoder by memset, memcpy
reimar
parents:
9272
diff
changeset
|
332 s->stream_ptr += 4; |
1468 | 333 |
9303
2ae6ab3fa3ba
Rearrange how the different cases are checked to reduce the number of
reimar
parents:
9302
diff
changeset
|
334 if (P[0] <= P[1]) { |
2ae6ab3fa3ba
Rearrange how the different cases are checked to reduce the number of
reimar
parents:
9302
diff
changeset
|
335 if (P[2] <= P[3]) { |
1468 | 336 |
9305 | 337 /* 1 of 4 colors for each pixel, need 16 more bytes */ |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
338 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 16); |
1468 | 339 |
9305 | 340 for (y = 0; y < 8; y++) { |
341 /* get the next set of 8 2-bit flags */ | |
342 int flags = bytestream_get_le16(&s->stream_ptr); | |
9319 | 343 for (x = 0; x < 8; x++, flags >>= 2) |
9305 | 344 *s->pixel_ptr++ = P[flags & 0x03]; |
345 s->pixel_ptr += s->line_inc; | |
1468 | 346 } |
347 | |
9303
2ae6ab3fa3ba
Rearrange how the different cases are checked to reduce the number of
reimar
parents:
9302
diff
changeset
|
348 } else { |
9305 | 349 uint32_t flags; |
1468 | 350 |
9305 | 351 /* 1 of 4 colors for each 2x2 block, need 4 more bytes */ |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
352 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 4); |
1468 | 353 |
9305 | 354 flags = bytestream_get_le32(&s->stream_ptr); |
1468 | 355 |
9305 | 356 for (y = 0; y < 8; y += 2) { |
357 for (x = 0; x < 8; x += 2, flags >>= 2) { | |
358 s->pixel_ptr[x ] = | |
359 s->pixel_ptr[x + 1 ] = | |
360 s->pixel_ptr[x + s->stride] = | |
361 s->pixel_ptr[x + 1 + s->stride] = P[flags & 0x03]; | |
362 } | |
363 s->pixel_ptr += s->stride * 2; | |
1468 | 364 } |
365 | |
9303
2ae6ab3fa3ba
Rearrange how the different cases are checked to reduce the number of
reimar
parents:
9302
diff
changeset
|
366 } |
2ae6ab3fa3ba
Rearrange how the different cases are checked to reduce the number of
reimar
parents:
9302
diff
changeset
|
367 } else { |
9302
0469949a5224
Avoid "reloading" code by using a 64 bit type for the flags and loading all at once.
reimar
parents:
9301
diff
changeset
|
368 uint64_t flags; |
1468 | 369 |
9304 | 370 /* 1 of 4 colors for each 2x1 or 1x2 block, need 8 more bytes */ |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
371 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 8); |
1468 | 372 |
9302
0469949a5224
Avoid "reloading" code by using a 64 bit type for the flags and loading all at once.
reimar
parents:
9301
diff
changeset
|
373 flags = bytestream_get_le64(&s->stream_ptr); |
9304 | 374 if (P[2] <= P[3]) { |
9305 | 375 for (y = 0; y < 8; y++) { |
376 for (x = 0; x < 8; x += 2, flags >>= 2) { | |
377 s->pixel_ptr[x ] = | |
378 s->pixel_ptr[x + 1] = P[flags & 0x03]; | |
379 } | |
380 s->pixel_ptr += s->stride; | |
1468 | 381 } |
9303
2ae6ab3fa3ba
Rearrange how the different cases are checked to reduce the number of
reimar
parents:
9302
diff
changeset
|
382 } else { |
9305 | 383 for (y = 0; y < 8; y += 2) { |
384 for (x = 0; x < 8; x++, flags >>= 2) { | |
385 s->pixel_ptr[x ] = | |
386 s->pixel_ptr[x + s->stride] = P[flags & 0x03]; | |
387 } | |
388 s->pixel_ptr += s->stride * 2; | |
1468 | 389 } |
9303
2ae6ab3fa3ba
Rearrange how the different cases are checked to reduce the number of
reimar
parents:
9302
diff
changeset
|
390 } |
1468 | 391 } |
392 | |
393 /* report success */ | |
394 return 0; | |
395 } | |
396 | |
1475 | 397 static int ipvideo_decode_block_opcode_0xA(IpvideoContext *s) |
1468 | 398 { |
399 int x, y; | |
9317
2c06c31c8664
One more simplification for ipvideo_decode_block_opcode_0xA
reimar
parents:
9315
diff
changeset
|
400 unsigned char P[4]; |
1468 | 401 int flags = 0; |
402 | |
403 /* 4-color encoding for each 4x4 quadrant, or 4-color encoding on | |
404 * either top and bottom or left and right halves */ | |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
405 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 24); |
1468 | 406 |
9317
2c06c31c8664
One more simplification for ipvideo_decode_block_opcode_0xA
reimar
parents:
9315
diff
changeset
|
407 if (s->stream_ptr[0] <= s->stream_ptr[1]) { |
1468 | 408 |
9317
2c06c31c8664
One more simplification for ipvideo_decode_block_opcode_0xA
reimar
parents:
9315
diff
changeset
|
409 /* 4-color encoding for each quadrant; need 32 bytes */ |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
410 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 32); |
1468 | 411 |
9315
a476e5590725
Slightly simplify first part of ipvideo_decode_block_opcode_0xA,
reimar
parents:
9312
diff
changeset
|
412 for (y = 0; y < 16; y++) { |
a476e5590725
Slightly simplify first part of ipvideo_decode_block_opcode_0xA,
reimar
parents:
9312
diff
changeset
|
413 // new values for each 4x4 block |
a476e5590725
Slightly simplify first part of ipvideo_decode_block_opcode_0xA,
reimar
parents:
9312
diff
changeset
|
414 if (!(y & 3)) { |
a476e5590725
Slightly simplify first part of ipvideo_decode_block_opcode_0xA,
reimar
parents:
9312
diff
changeset
|
415 memcpy(P, s->stream_ptr, 4); |
a476e5590725
Slightly simplify first part of ipvideo_decode_block_opcode_0xA,
reimar
parents:
9312
diff
changeset
|
416 s->stream_ptr += 4; |
a476e5590725
Slightly simplify first part of ipvideo_decode_block_opcode_0xA,
reimar
parents:
9312
diff
changeset
|
417 flags = bytestream_get_le32(&s->stream_ptr); |
1468 | 418 } |
419 | |
9319 | 420 for (x = 0; x < 4; x++, flags >>= 2) |
9315
a476e5590725
Slightly simplify first part of ipvideo_decode_block_opcode_0xA,
reimar
parents:
9312
diff
changeset
|
421 *s->pixel_ptr++ = P[flags & 0x03]; |
a476e5590725
Slightly simplify first part of ipvideo_decode_block_opcode_0xA,
reimar
parents:
9312
diff
changeset
|
422 |
a476e5590725
Slightly simplify first part of ipvideo_decode_block_opcode_0xA,
reimar
parents:
9312
diff
changeset
|
423 s->pixel_ptr += s->stride - 4; |
a476e5590725
Slightly simplify first part of ipvideo_decode_block_opcode_0xA,
reimar
parents:
9312
diff
changeset
|
424 // switch to right half |
a476e5590725
Slightly simplify first part of ipvideo_decode_block_opcode_0xA,
reimar
parents:
9312
diff
changeset
|
425 if (y == 7) s->pixel_ptr -= 8 * s->stride - 4; |
1468 | 426 } |
427 | |
428 } else { | |
9317
2c06c31c8664
One more simplification for ipvideo_decode_block_opcode_0xA
reimar
parents:
9315
diff
changeset
|
429 // vertical split? |
2c06c31c8664
One more simplification for ipvideo_decode_block_opcode_0xA
reimar
parents:
9315
diff
changeset
|
430 int vert = s->stream_ptr[12] <= s->stream_ptr[13]; |
2c06c31c8664
One more simplification for ipvideo_decode_block_opcode_0xA
reimar
parents:
9315
diff
changeset
|
431 uint64_t flags = 0; |
1468 | 432 |
433 /* 4-color encoding for either left and right or top and bottom | |
9317
2c06c31c8664
One more simplification for ipvideo_decode_block_opcode_0xA
reimar
parents:
9315
diff
changeset
|
434 * halves */ |
1468 | 435 |
9317
2c06c31c8664
One more simplification for ipvideo_decode_block_opcode_0xA
reimar
parents:
9315
diff
changeset
|
436 for (y = 0; y < 16; y++) { |
2c06c31c8664
One more simplification for ipvideo_decode_block_opcode_0xA
reimar
parents:
9315
diff
changeset
|
437 // load values for each half |
2c06c31c8664
One more simplification for ipvideo_decode_block_opcode_0xA
reimar
parents:
9315
diff
changeset
|
438 if (!(y & 7)) { |
2c06c31c8664
One more simplification for ipvideo_decode_block_opcode_0xA
reimar
parents:
9315
diff
changeset
|
439 memcpy(P, s->stream_ptr, 4); |
2c06c31c8664
One more simplification for ipvideo_decode_block_opcode_0xA
reimar
parents:
9315
diff
changeset
|
440 s->stream_ptr += 4; |
2c06c31c8664
One more simplification for ipvideo_decode_block_opcode_0xA
reimar
parents:
9315
diff
changeset
|
441 flags = bytestream_get_le64(&s->stream_ptr); |
1468 | 442 } |
443 | |
9317
2c06c31c8664
One more simplification for ipvideo_decode_block_opcode_0xA
reimar
parents:
9315
diff
changeset
|
444 for (x = 0; x < 4; x++, flags >>= 2) |
2c06c31c8664
One more simplification for ipvideo_decode_block_opcode_0xA
reimar
parents:
9315
diff
changeset
|
445 *s->pixel_ptr++ = P[flags & 0x03]; |
1468 | 446 |
9317
2c06c31c8664
One more simplification for ipvideo_decode_block_opcode_0xA
reimar
parents:
9315
diff
changeset
|
447 if (vert) { |
2c06c31c8664
One more simplification for ipvideo_decode_block_opcode_0xA
reimar
parents:
9315
diff
changeset
|
448 s->pixel_ptr += s->stride - 4; |
2c06c31c8664
One more simplification for ipvideo_decode_block_opcode_0xA
reimar
parents:
9315
diff
changeset
|
449 // switch to right half |
2c06c31c8664
One more simplification for ipvideo_decode_block_opcode_0xA
reimar
parents:
9315
diff
changeset
|
450 if (y == 7) s->pixel_ptr -= 8 * s->stride - 4; |
2c06c31c8664
One more simplification for ipvideo_decode_block_opcode_0xA
reimar
parents:
9315
diff
changeset
|
451 } else if (y & 1) s->pixel_ptr += s->line_inc; |
1468 | 452 } |
453 } | |
454 | |
455 /* report success */ | |
456 return 0; | |
457 } | |
458 | |
1475 | 459 static int ipvideo_decode_block_opcode_0xB(IpvideoContext *s) |
1468 | 460 { |
9273
42c63846b321
Replace many tiny loops in the interplayvideo decoder by memset, memcpy
reimar
parents:
9272
diff
changeset
|
461 int y; |
1468 | 462 |
463 /* 64-color encoding (each pixel in block is a different color) */ | |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
464 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 64); |
1468 | 465 |
466 for (y = 0; y < 8; y++) { | |
9273
42c63846b321
Replace many tiny loops in the interplayvideo decoder by memset, memcpy
reimar
parents:
9272
diff
changeset
|
467 memcpy(s->pixel_ptr, s->stream_ptr, 8); |
42c63846b321
Replace many tiny loops in the interplayvideo decoder by memset, memcpy
reimar
parents:
9272
diff
changeset
|
468 s->stream_ptr += 8; |
42c63846b321
Replace many tiny loops in the interplayvideo decoder by memset, memcpy
reimar
parents:
9272
diff
changeset
|
469 s->pixel_ptr += s->stride; |
1468 | 470 } |
471 | |
472 /* report success */ | |
473 return 0; | |
474 } | |
475 | |
1475 | 476 static int ipvideo_decode_block_opcode_0xC(IpvideoContext *s) |
1468 | 477 { |
478 int x, y; | |
479 | |
480 /* 16-color block encoding: each 2x2 block is a different color */ | |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
481 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 16); |
1468 | 482 |
483 for (y = 0; y < 8; y += 2) { | |
484 for (x = 0; x < 8; x += 2) { | |
9297 | 485 s->pixel_ptr[x ] = |
486 s->pixel_ptr[x + 1 ] = | |
487 s->pixel_ptr[x + s->stride] = | |
9301 | 488 s->pixel_ptr[x + 1 + s->stride] = *s->stream_ptr++; |
1468 | 489 } |
1475 | 490 s->pixel_ptr += s->stride * 2; |
1468 | 491 } |
492 | |
493 /* report success */ | |
494 return 0; | |
495 } | |
496 | |
1475 | 497 static int ipvideo_decode_block_opcode_0xD(IpvideoContext *s) |
1468 | 498 { |
9273
42c63846b321
Replace many tiny loops in the interplayvideo decoder by memset, memcpy
reimar
parents:
9272
diff
changeset
|
499 int y; |
9322 | 500 unsigned char P[2]; |
1468 | 501 |
502 /* 4-color block encoding: each 4x4 block is a different color */ | |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
503 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 4); |
1468 | 504 |
9322 | 505 for (y = 0; y < 8; y++) { |
506 if (!(y & 3)) { | |
507 P[0] = *s->stream_ptr++; | |
508 P[1] = *s->stream_ptr++; | |
509 } | |
510 memset(s->pixel_ptr, P[0], 4); | |
511 memset(s->pixel_ptr + 4, P[1], 4); | |
9273
42c63846b321
Replace many tiny loops in the interplayvideo decoder by memset, memcpy
reimar
parents:
9272
diff
changeset
|
512 s->pixel_ptr += s->stride; |
1468 | 513 } |
514 | |
515 /* report success */ | |
516 return 0; | |
517 } | |
518 | |
1475 | 519 static int ipvideo_decode_block_opcode_0xE(IpvideoContext *s) |
1468 | 520 { |
9273
42c63846b321
Replace many tiny loops in the interplayvideo decoder by memset, memcpy
reimar
parents:
9272
diff
changeset
|
521 int y; |
1468 | 522 unsigned char pix; |
523 | |
524 /* 1-color encoding: the whole block is 1 solid color */ | |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
525 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 1); |
1475 | 526 pix = *s->stream_ptr++; |
1468 | 527 |
528 for (y = 0; y < 8; y++) { | |
9273
42c63846b321
Replace many tiny loops in the interplayvideo decoder by memset, memcpy
reimar
parents:
9272
diff
changeset
|
529 memset(s->pixel_ptr, pix, 8); |
42c63846b321
Replace many tiny loops in the interplayvideo decoder by memset, memcpy
reimar
parents:
9272
diff
changeset
|
530 s->pixel_ptr += s->stride; |
1468 | 531 } |
532 | |
533 /* report success */ | |
534 return 0; | |
535 } | |
536 | |
1475 | 537 static int ipvideo_decode_block_opcode_0xF(IpvideoContext *s) |
1468 | 538 { |
539 int x, y; | |
9298
9698f0d03ed9
Avoid code duplication by using ?: and array indexing instead of if..else
reimar
parents:
9297
diff
changeset
|
540 unsigned char sample[2]; |
1468 | 541 |
542 /* dithered encoding */ | |
10713
b703476cd4df
Make CHECK_STREAM_PTR macro in Interplay Video decoder usable with
kostya
parents:
10712
diff
changeset
|
543 CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 2); |
9298
9698f0d03ed9
Avoid code duplication by using ?: and array indexing instead of if..else
reimar
parents:
9297
diff
changeset
|
544 sample[0] = *s->stream_ptr++; |
9698f0d03ed9
Avoid code duplication by using ?: and array indexing instead of if..else
reimar
parents:
9297
diff
changeset
|
545 sample[1] = *s->stream_ptr++; |
1468 | 546 |
547 for (y = 0; y < 8; y++) { | |
548 for (x = 0; x < 8; x += 2) { | |
9298
9698f0d03ed9
Avoid code duplication by using ?: and array indexing instead of if..else
reimar
parents:
9297
diff
changeset
|
549 *s->pixel_ptr++ = sample[ y & 1 ]; |
9698f0d03ed9
Avoid code duplication by using ?: and array indexing instead of if..else
reimar
parents:
9297
diff
changeset
|
550 *s->pixel_ptr++ = sample[!(y & 1)]; |
1468 | 551 } |
1475 | 552 s->pixel_ptr += s->line_inc; |
1468 | 553 } |
554 | |
555 /* report success */ | |
556 return 0; | |
557 } | |
558 | |
9272
bb2fa003a336
Make ipvideo_decode_block array constant, compile-time initialized instead
reimar
parents:
9127
diff
changeset
|
559 static int (* const ipvideo_decode_block[])(IpvideoContext *s) = { |
bb2fa003a336
Make ipvideo_decode_block array constant, compile-time initialized instead
reimar
parents:
9127
diff
changeset
|
560 ipvideo_decode_block_opcode_0x0, ipvideo_decode_block_opcode_0x1, |
bb2fa003a336
Make ipvideo_decode_block array constant, compile-time initialized instead
reimar
parents:
9127
diff
changeset
|
561 ipvideo_decode_block_opcode_0x2, ipvideo_decode_block_opcode_0x3, |
bb2fa003a336
Make ipvideo_decode_block array constant, compile-time initialized instead
reimar
parents:
9127
diff
changeset
|
562 ipvideo_decode_block_opcode_0x4, ipvideo_decode_block_opcode_0x5, |
bb2fa003a336
Make ipvideo_decode_block array constant, compile-time initialized instead
reimar
parents:
9127
diff
changeset
|
563 ipvideo_decode_block_opcode_0x6, ipvideo_decode_block_opcode_0x7, |
bb2fa003a336
Make ipvideo_decode_block array constant, compile-time initialized instead
reimar
parents:
9127
diff
changeset
|
564 ipvideo_decode_block_opcode_0x8, ipvideo_decode_block_opcode_0x9, |
bb2fa003a336
Make ipvideo_decode_block array constant, compile-time initialized instead
reimar
parents:
9127
diff
changeset
|
565 ipvideo_decode_block_opcode_0xA, ipvideo_decode_block_opcode_0xB, |
bb2fa003a336
Make ipvideo_decode_block array constant, compile-time initialized instead
reimar
parents:
9127
diff
changeset
|
566 ipvideo_decode_block_opcode_0xC, ipvideo_decode_block_opcode_0xD, |
bb2fa003a336
Make ipvideo_decode_block array constant, compile-time initialized instead
reimar
parents:
9127
diff
changeset
|
567 ipvideo_decode_block_opcode_0xE, ipvideo_decode_block_opcode_0xF, |
bb2fa003a336
Make ipvideo_decode_block array constant, compile-time initialized instead
reimar
parents:
9127
diff
changeset
|
568 }; |
1468 | 569 |
570 static void ipvideo_decode_opcodes(IpvideoContext *s) | |
571 { | |
572 int x, y; | |
573 unsigned char opcode; | |
574 int ret; | |
575 static int frame = 0; | |
9494
e09e4c095fdb
Simplify ipvideo_decode_opcodes by using get_bits, this might be slower
reimar
parents:
9493
diff
changeset
|
576 GetBitContext gb; |
1468 | 577 |
578 debug_interplay("------------------ frame %d\n", frame); | |
579 frame++; | |
580 | |
10715
4f455f478398
Add 16-bit image data handling (but not decoding yet) to Interplay Video
kostya
parents:
10714
diff
changeset
|
581 if (!s->is_16bpp) { |
10716
e64842a691d8
cosmetics: reindent and break long lines after last commits
kostya
parents:
10715
diff
changeset
|
582 /* this is PAL8, so make the palette available */ |
e64842a691d8
cosmetics: reindent and break long lines after last commits
kostya
parents:
10715
diff
changeset
|
583 memcpy(s->current_frame.data[1], s->avctx->palctrl->palette, PALETTE_COUNT * 4); |
1468 | 584 |
10716
e64842a691d8
cosmetics: reindent and break long lines after last commits
kostya
parents:
10715
diff
changeset
|
585 s->stride = s->current_frame.linesize[0]; |
e64842a691d8
cosmetics: reindent and break long lines after last commits
kostya
parents:
10715
diff
changeset
|
586 s->stream_ptr = s->buf + 14; /* data starts 14 bytes in */ |
e64842a691d8
cosmetics: reindent and break long lines after last commits
kostya
parents:
10715
diff
changeset
|
587 s->stream_end = s->buf + s->size; |
10715
4f455f478398
Add 16-bit image data handling (but not decoding yet) to Interplay Video
kostya
parents:
10714
diff
changeset
|
588 } else { |
4f455f478398
Add 16-bit image data handling (but not decoding yet) to Interplay Video
kostya
parents:
10714
diff
changeset
|
589 s->stride = s->current_frame.linesize[0] >> 1; |
4f455f478398
Add 16-bit image data handling (but not decoding yet) to Interplay Video
kostya
parents:
10714
diff
changeset
|
590 } |
1475 | 591 s->line_inc = s->stride - 8; |
10717
4b1bc4a1ff14
10l trocadero: forgot one case where picture linesize should be used
kostya
parents:
10716
diff
changeset
|
592 s->upper_motion_limit_offset = (s->avctx->height - 8) * s->current_frame.linesize[0] |
10716
e64842a691d8
cosmetics: reindent and break long lines after last commits
kostya
parents:
10715
diff
changeset
|
593 + (s->avctx->width - 8) * (1 + s->is_16bpp); |
1468 | 594 |
9494
e09e4c095fdb
Simplify ipvideo_decode_opcodes by using get_bits, this might be slower
reimar
parents:
9493
diff
changeset
|
595 init_get_bits(&gb, s->decoding_map, s->decoding_map_size * 8); |
10711
d2c20d24abbd
Change main loop in Interplay Video decoder, so variables x and y really mean
kostya
parents:
10709
diff
changeset
|
596 for (y = 0; y < s->avctx->height; y += 8) { |
d2c20d24abbd
Change main loop in Interplay Video decoder, so variables x and y really mean
kostya
parents:
10709
diff
changeset
|
597 for (x = 0; x < s->avctx->width; x += 8) { |
9494
e09e4c095fdb
Simplify ipvideo_decode_opcodes by using get_bits, this might be slower
reimar
parents:
9493
diff
changeset
|
598 opcode = get_bits(&gb, 4); |
1468 | 599 |
1475 | 600 debug_interplay(" block @ (%3d, %3d): encoding 0x%X, data ptr @ %p\n", |
10711
d2c20d24abbd
Change main loop in Interplay Video decoder, so variables x and y really mean
kostya
parents:
10709
diff
changeset
|
601 x, y, opcode, s->stream_ptr); |
1468 | 602 |
10715
4f455f478398
Add 16-bit image data handling (but not decoding yet) to Interplay Video
kostya
parents:
10714
diff
changeset
|
603 if (!s->is_16bpp) { |
10716
e64842a691d8
cosmetics: reindent and break long lines after last commits
kostya
parents:
10715
diff
changeset
|
604 s->pixel_ptr = s->current_frame.data[0] + x |
e64842a691d8
cosmetics: reindent and break long lines after last commits
kostya
parents:
10715
diff
changeset
|
605 + y*s->current_frame.linesize[0]; |
e64842a691d8
cosmetics: reindent and break long lines after last commits
kostya
parents:
10715
diff
changeset
|
606 ret = ipvideo_decode_block[opcode](s); |
10715
4f455f478398
Add 16-bit image data handling (but not decoding yet) to Interplay Video
kostya
parents:
10714
diff
changeset
|
607 } else { |
10716
e64842a691d8
cosmetics: reindent and break long lines after last commits
kostya
parents:
10715
diff
changeset
|
608 s->pixel_ptr = s->current_frame.data[0] + x*2 |
e64842a691d8
cosmetics: reindent and break long lines after last commits
kostya
parents:
10715
diff
changeset
|
609 + y*s->current_frame.linesize[0]; |
10715
4f455f478398
Add 16-bit image data handling (but not decoding yet) to Interplay Video
kostya
parents:
10714
diff
changeset
|
610 } |
1475 | 611 if (ret != 0) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1585
diff
changeset
|
612 av_log(s->avctx, AV_LOG_ERROR, " Interplay video: decode problem on frame %d, @ block (%d, %d)\n", |
10711
d2c20d24abbd
Change main loop in Interplay Video decoder, so variables x and y really mean
kostya
parents:
10709
diff
changeset
|
613 frame, x, y); |
1475 | 614 return; |
1468 | 615 } |
616 } | |
617 } | |
9275
67cf9d31724c
Simplify check for leftover bytes after decoding for interplayvideo.
reimar
parents:
9274
diff
changeset
|
618 if (s->stream_end - s->stream_ptr > 1) { |
2962 | 619 av_log(s->avctx, AV_LOG_ERROR, " Interplay video: decode finished with %td bytes left over\n", |
10709 | 620 s->stream_end - s->stream_ptr); |
1475 | 621 } |
1468 | 622 } |
623 | |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6483
diff
changeset
|
624 static av_cold int ipvideo_decode_init(AVCodecContext *avctx) |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
625 { |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
626 IpvideoContext *s = avctx->priv_data; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
627 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
628 s->avctx = avctx; |
1468 | 629 |
1585
6b224ca24033
revised palette API, courtesy of Roberto Togni (rtogni at freemail.it)
melanson
parents:
1545
diff
changeset
|
630 if (s->avctx->palctrl == NULL) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1585
diff
changeset
|
631 av_log(avctx, AV_LOG_ERROR, " Interplay video: palette expected.\n"); |
1468 | 632 return -1; |
633 } | |
634 | |
10712 | 635 s->is_16bpp = avctx->bits_per_coded_sample == 16; |
636 avctx->pix_fmt = s->is_16bpp ? PIX_FMT_RGB555 : PIX_FMT_PAL8; | |
637 if (s->is_16bpp) { | |
638 av_log(avctx, AV_LOG_ERROR, "16-bit Interplay video is not supported yet.\n"); | |
639 return -1; | |
640 } | |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
641 dsputil_init(&s->dsp, avctx); |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
642 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
643 /* decoding map contains 4 bits of information per 8x8 block */ |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
644 s->decoding_map_size = avctx->width * avctx->height / (8 * 8 * 2); |
1468 | 645 |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
646 s->current_frame.data[0] = s->last_frame.data[0] = |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
647 s->second_last_frame.data[0] = NULL; |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
648 |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
649 return 0; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
650 } |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
651 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
652 static int ipvideo_decode_frame(AVCodecContext *avctx, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
653 void *data, int *data_size, |
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
9322
diff
changeset
|
654 AVPacket *avpkt) |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
655 { |
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
9322
diff
changeset
|
656 const uint8_t *buf = avpkt->data; |
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
9322
diff
changeset
|
657 int buf_size = avpkt->size; |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
658 IpvideoContext *s = avctx->priv_data; |
1585
6b224ca24033
revised palette API, courtesy of Roberto Togni (rtogni at freemail.it)
melanson
parents:
1545
diff
changeset
|
659 AVPaletteControl *palette_control = avctx->palctrl; |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
660 |
1770 | 661 /* compressed buffer needs to be large enough to at least hold an entire |
662 * decoding map */ | |
663 if (buf_size < s->decoding_map_size) | |
664 return buf_size; | |
665 | |
1468 | 666 s->decoding_map = buf; |
667 s->buf = buf + s->decoding_map_size; | |
668 s->size = buf_size - s->decoding_map_size; | |
669 | |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
670 s->current_frame.reference = 3; |
1468 | 671 if (avctx->get_buffer(avctx, &s->current_frame)) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1585
diff
changeset
|
672 av_log(avctx, AV_LOG_ERROR, " Interplay Video: get_buffer() failed\n"); |
1468 | 673 return -1; |
674 } | |
675 | |
676 ipvideo_decode_opcodes(s); | |
677 | |
10715
4f455f478398
Add 16-bit image data handling (but not decoding yet) to Interplay Video
kostya
parents:
10714
diff
changeset
|
678 if (!s->is_16bpp && palette_control->palette_changed) { |
1585
6b224ca24033
revised palette API, courtesy of Roberto Togni (rtogni at freemail.it)
melanson
parents:
1545
diff
changeset
|
679 palette_control->palette_changed = 0; |
6b224ca24033
revised palette API, courtesy of Roberto Togni (rtogni at freemail.it)
melanson
parents:
1545
diff
changeset
|
680 s->current_frame.palette_has_changed = 1; |
6b224ca24033
revised palette API, courtesy of Roberto Togni (rtogni at freemail.it)
melanson
parents:
1545
diff
changeset
|
681 } |
6b224ca24033
revised palette API, courtesy of Roberto Togni (rtogni at freemail.it)
melanson
parents:
1545
diff
changeset
|
682 |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
683 *data_size = sizeof(AVFrame); |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
684 *(AVFrame*)data = s->current_frame; |
1468 | 685 |
686 /* shuffle frames */ | |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
687 if (s->second_last_frame.data[0]) |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
688 avctx->release_buffer(avctx, &s->second_last_frame); |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
689 s->second_last_frame = s->last_frame; |
1468 | 690 s->last_frame = s->current_frame; |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
691 s->current_frame.data[0] = NULL; /* catch any access attempts */ |
1468 | 692 |
693 /* report that the buffer was completely consumed */ | |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
694 return buf_size; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
695 } |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
696 |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6483
diff
changeset
|
697 static av_cold int ipvideo_decode_end(AVCodecContext *avctx) |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
698 { |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
699 IpvideoContext *s = avctx->priv_data; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
700 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
701 /* release the last frame */ |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
702 if (s->last_frame.data[0]) |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
703 avctx->release_buffer(avctx, &s->last_frame); |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
704 if (s->second_last_frame.data[0]) |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
705 avctx->release_buffer(avctx, &s->second_last_frame); |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
706 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
707 return 0; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
708 } |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
709 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
710 AVCodec interplay_video_decoder = { |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
711 "interplayvideo", |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
712 CODEC_TYPE_VIDEO, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
713 CODEC_ID_INTERPLAY_VIDEO, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
714 sizeof(IpvideoContext), |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
715 ipvideo_decode_init, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
716 NULL, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
717 ipvideo_decode_end, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
718 ipvideo_decode_frame, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
719 CODEC_CAP_DR1, |
9083
bf274494b66e
Change a bunch of codec long_names to be more consistent and descriptive.
diego
parents:
8718
diff
changeset
|
720 .long_name = NULL_IF_CONFIG_SMALL("Interplay MVE video"), |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
721 }; |