Mercurial > mplayer.hg
annotate libmpcodecs/native/svq1.c @ 7942:b582c6fb0053
Unified BSD sections, expanded Cygwin section, small fixes.
author | diego |
---|---|
date | Mon, 28 Oct 2002 00:44:17 +0000 |
parents | da6af57c48fc |
children | b465ba5897a3 |
rev | line source |
---|---|
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
1 /* |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
2 * Copyright (C) 2002 the xine project |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
3 * |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
4 * This file is part of xine, a unix video player. |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
5 * |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
6 * xine is free software; you can redistribute it and/or modify |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
8 * the Free Software Foundation; either version 2 of the License, or |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
9 * (at your option) any later version. |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
10 * |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
11 * xine is distributed in the hope that it will be useful, |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
14 * GNU General Public License for more details. |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
15 * |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
16 * You should have received a copy of the GNU General Public License |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
17 * along with this program; if not, write to the Free Software |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
19 * |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
20 * $Id$ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
21 */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
22 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
23 #include <stdio.h> |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
24 #include <stdlib.h> |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
25 #include <string.h> |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
26 #include <unistd.h> |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
27 |
6510 | 28 #include "../../config.h" |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
29 #include "bswap.h" |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
30 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
31 /* variable length (bit) code */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
32 typedef struct vlc_code_s { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
33 int16_t value :10, |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
34 length :6; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
35 } vlc_code_t; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
36 |
6511
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
37 #define VIDEOBUFSIZE 1280 * 1024 |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
38 |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
39 //char temp_buf[VIDEOBUFSIZE]; |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
40 |
6684
da6af57c48fc
Small fix: Correct mathematical order in MEDIAN macro (gcc 3.1 didn't like it).
atmos4
parents:
6511
diff
changeset
|
41 #define MEDIAN(a,b,c) (((a < b) != (b >= c)) ? b : (((a < c) != (c > b)) ? c : a)) |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
42 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
43 #include "svq1.h" |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
44 #include "svq1_cb.h" |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
45 |
6510 | 46 #ifdef USE_LIBAVCODEC |
47 typedef void (*op_pixels_func)(unsigned char *block, const unsigned char *pixels, int line_size, int h); | |
48 extern op_pixels_func put_pixels_tab[4]; | |
49 extern op_pixels_func put_no_rnd_pixels_tab[4]; | |
6511
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
50 //#define HAVE_AV_CONFIG_H |
6510 | 51 #endif |
52 | |
6511
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
53 #ifdef HAVE_AV_CONFIG_H |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
54 // use libavcodec's get_bits(): |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
55 //#define ALT_BITSTREAM_READER |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
56 //#define ALIGNED_BITSTREAM |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
57 #include "../../libavcodec/common.h" |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
58 #define bit_buffer_t GetBitContext |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
59 #define get_bit_cache(buf) (show_bits(buf,24)<<8) |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
60 //#define get_bit_cache(buf) show_bits(buf,32) |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
61 #else |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
62 // use built-in version: |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
63 |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
64 /* memory bit stream */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
65 typedef struct bit_buffer_s { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
66 uint8_t *buffer; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
67 uint32_t bitpos; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
68 } bit_buffer_t; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
69 |
6511
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
70 static inline void skip_bits(bit_buffer_t *bitbuf, int n){ |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
71 bitbuf->bitpos+=n; |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
72 } |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
73 |
6511
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
74 static void init_get_bits(bit_buffer_t *bitbuf, |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
75 unsigned char *buffer, int buffer_size){ |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
76 bitbuf->buffer=buffer; |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
77 bitbuf->bitpos=0; |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
78 } |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
79 |
6511
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
80 static inline uint32_t get_bits (bit_buffer_t *bitbuf, int count) { |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
81 uint32_t result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
82 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
83 /* load 32 bits of data (byte-aligned) */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
84 result = be2me_32 (*((uint32_t *) &bitbuf->buffer[bitbuf->bitpos >> 3])); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
85 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
86 /* compensate for sub-byte offset */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
87 result <<= (bitbuf->bitpos & 0x7); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
88 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
89 /* flush num bits */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
90 bitbuf->bitpos += count; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
91 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
92 /* return num bits */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
93 return result >> (32 - count); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
94 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
95 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
96 /* |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
97 * Return next 32 bits (left aligned). |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
98 */ |
6511
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
99 static inline uint32_t get_bit_cache(bit_buffer_t *bitbuf) { |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
100 uint32_t result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
101 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
102 /* load 32 bits of data (byte-aligned) */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
103 result = be2me_32 (*((uint32_t *) &bitbuf->buffer[bitbuf->bitpos >> 3])); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
104 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
105 /* compensate for sub-byte offset */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
106 result <<= (bitbuf->bitpos & 0x7); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
107 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
108 return result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
109 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
110 |
6511
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
111 #endif |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
112 |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
113 static int decode_svq1_block (bit_buffer_t *bitbuf, uint8_t *pixels, int pitch, int intra) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
114 uint32_t bit_cache; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
115 vlc_code_t *vlc; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
116 uint8_t *list[63]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
117 uint32_t *dst; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
118 uint32_t *codebook; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
119 int entries[6]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
120 int i, j, m, n; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
121 int mean, stages; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
122 int x, y, width, height, level; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
123 uint32_t n1, n2, n3, n4; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
124 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
125 /* initialize list for breadth first processing of vectors */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
126 list[0] = pixels; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
127 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
128 /* recursively process vector */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
129 for (i=0, m=1, n=1, level=5; i < n; i++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
130 for (; level > 0; i++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
131 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
132 /* process next depth */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
133 if (i == m) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
134 m = n; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
135 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
136 if (--level == 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
137 break; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
138 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
139 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
140 /* divide block if next bit set */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
141 if (get_bits (bitbuf, 1) == 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
142 break; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
143 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
144 /* add child nodes */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
145 list[n++] = list[i]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
146 list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level / 2) + 1)); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
147 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
148 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
149 /* destination address and vector size */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
150 dst = (uint32_t *) list[i]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
151 width = 1 << ((4 + level) /2); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
152 height = 1 << ((3 + level) /2); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
153 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
154 /* get number of stages (-1 skips vector, 0 for mean only) */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
155 bit_cache = get_bit_cache (bitbuf); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
156 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
157 if (intra) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
158 vlc = &intra_vector_tables[level][bit_cache >> (32 - 7)]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
159 else |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
160 vlc = &inter_vector_tables[level][bit_cache >> (32 - 6)]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
161 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
162 /* flush bits */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
163 stages = vlc->value; |
6511
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
164 skip_bits(bitbuf,vlc->length); |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
165 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
166 if (stages == -1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
167 if (intra) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
168 for (y=0; y < height; y++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
169 memset (&dst[y*(pitch / 4)], 0, width); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
170 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
171 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
172 continue; /* skip vector */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
173 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
174 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
175 if ((stages > 0) && (level >= 4)) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
176 return -1; /* invalid vector */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
177 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
178 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
179 /* get mean value for vector */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
180 bit_cache = get_bit_cache (bitbuf); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
181 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
182 if (intra) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
183 if (bit_cache >= 0x25000000) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
184 vlc = &intra_mean_table_0[(bit_cache >> (32 - 8)) - 37]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
185 else if (bit_cache >= 0x03400000) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
186 vlc = &intra_mean_table_1[(bit_cache >> (32 - 10)) - 13]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
187 else if (bit_cache >= 0x00040000) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
188 vlc = &intra_mean_table_2[(bit_cache >> (32 - 14)) - 1]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
189 else |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
190 vlc = &intra_mean_table_3[bit_cache >> (32 - 20)]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
191 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
192 if (bit_cache >= 0x0B000000) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
193 vlc = &inter_mean_table_0[(bit_cache >> (32 - 8)) - 11]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
194 else if (bit_cache >= 0x01200000) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
195 vlc = &inter_mean_table_1[(bit_cache >> (32 - 12)) - 18]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
196 else if (bit_cache >= 0x002E0000) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
197 vlc = &inter_mean_table_2[(bit_cache >> (32 - 15)) - 23]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
198 else if (bit_cache >= 0x00094000) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
199 vlc = &inter_mean_table_3[(bit_cache >> (32 - 18)) - 37]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
200 else if (bit_cache >= 0x00049000) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
201 vlc = &inter_mean_table_4[(bit_cache >> (32 - 20)) - 73]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
202 else |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
203 vlc = &inter_mean_table_5[bit_cache >> (32 - 22)]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
204 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
205 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
206 /* flush bits */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
207 mean = vlc->value; |
6511
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
208 skip_bits(bitbuf,vlc->length); |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
209 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
210 if (intra && stages == 0) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
211 for (y=0; y < height; y++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
212 memset (&dst[y*(pitch / 4)], mean, width); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
213 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
214 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
215 codebook = (uint32_t *) (intra ? intra_codebooks[level] : inter_codebooks[level]); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
216 bit_cache = get_bits (bitbuf, 4*stages); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
217 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
218 /* calculate codebook entries for this vector */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
219 for (j=0; j < stages; j++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
220 entries[j] = (((bit_cache >> (4*(stages - j - 1))) & 0xF) + 16*j) << (level + 1); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
221 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
222 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
223 mean -= (stages * 128); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
224 n4 = ((mean + (mean >> 31)) << 16) | (mean & 0xFFFF); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
225 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
226 for (y=0; y < height; y++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
227 for (x=0; x < (width / 4); x++, codebook++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
228 if (intra) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
229 n1 = n4; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
230 n2 = n4; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
231 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
232 n3 = dst[x]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
233 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
234 /* add mean value to vector */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
235 n1 = ((n3 & 0xFF00FF00) >> 8) + n4; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
236 n2 = (n3 & 0x00FF00FF) + n4; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
237 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
238 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
239 /* add codebook entries to vector */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
240 for (j=0; j < stages; j++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
241 n3 = codebook[entries[j]] ^ 0x80808080; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
242 n1 += ((n3 & 0xFF00FF00) >> 8); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
243 n2 += (n3 & 0x00FF00FF); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
244 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
245 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
246 /* clip to [0..255] */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
247 if (n1 & 0xFF00FF00) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
248 n3 = ((( n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
249 n1 += 0x7F007F00; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
250 n1 |= (((~n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
251 n1 &= (n3 & 0x00FF00FF); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
252 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
253 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
254 if (n2 & 0xFF00FF00) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
255 n3 = ((( n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
256 n2 += 0x7F007F00; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
257 n2 |= (((~n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
258 n2 &= (n3 & 0x00FF00FF); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
259 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
260 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
261 /* store result */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
262 dst[x] = (n1 << 8) | n2; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
263 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
264 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
265 dst += (pitch / 4); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
266 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
267 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
268 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
269 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
270 return 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
271 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
272 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
273 static int decode_motion_vector (bit_buffer_t *bitbuf, svq1_pmv_t *mv, svq1_pmv_t **pmv) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
274 uint32_t bit_cache; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
275 vlc_code_t *vlc; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
276 int diff, sign; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
277 int i; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
278 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
279 for (i=0; i < 2; i++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
280 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
281 /* get motion code */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
282 bit_cache = get_bit_cache (bitbuf); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
283 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
284 if (!(bit_cache & 0xFFE00000)) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
285 return -1; /* invalid vlc code */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
286 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
287 if (bit_cache & 0x80000000) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
288 diff = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
289 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
290 /* flush bit */ |
6511
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
291 skip_bits(bitbuf,1); |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
292 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
293 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
294 if (bit_cache >= 0x06000000) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
295 vlc = &motion_table_0[(bit_cache >> (32 - 7)) - 3]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
296 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
297 vlc = &motion_table_1[(bit_cache >> (32 - 12)) - 2]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
298 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
299 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
300 /* decode motion vector differential */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
301 sign = (int) (bit_cache << (vlc->length - 1)) >> 31; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
302 diff = (vlc->value ^ sign) - sign; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
303 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
304 /* flush bits */ |
6511
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
305 skip_bits(bitbuf,vlc->length); |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
306 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
307 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
308 /* add median of motion vector predictors and clip result */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
309 if (i == 1) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
310 mv->y = ((diff + MEDIAN(pmv[0]->y, pmv[1]->y, pmv[2]->y)) << 26) >> 26; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
311 else |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
312 mv->x = ((diff + MEDIAN(pmv[0]->x, pmv[1]->x, pmv[2]->x)) << 26) >> 26; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
313 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
314 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
315 return 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
316 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
317 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
318 static void skip_block (uint8_t *current, uint8_t *previous, int pitch, int x, int y) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
319 uint8_t *src; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
320 uint8_t *dst; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
321 int i; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
322 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
323 src = &previous[x + y*pitch]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
324 dst = current; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
325 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
326 for (i=0; i < 16; i++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
327 memcpy (dst, src, 16); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
328 src += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
329 dst += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
330 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
331 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
332 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
333 static int motion_inter_block (bit_buffer_t *bitbuf, |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
334 uint8_t *current, uint8_t *previous, int pitch, |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
335 svq1_pmv_t *motion, int x, int y) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
336 uint8_t *src; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
337 uint8_t *dst; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
338 svq1_pmv_t mv; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
339 svq1_pmv_t *pmv[3]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
340 int sx, sy; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
341 int result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
342 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
343 /* predict and decode motion vector */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
344 pmv[0] = &motion[0]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
345 pmv[1] = &motion[(x / 8) + 2]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
346 pmv[2] = &motion[(x / 8) + 4]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
347 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
348 if (y == 0) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
349 pmv[1] = pmv[0]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
350 pmv[2] = pmv[0]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
351 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
352 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
353 result = decode_motion_vector (bitbuf, &mv, pmv); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
354 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
355 if (result != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
356 return result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
357 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
358 motion[0].x = mv.x; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
359 motion[0].y = mv.y; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
360 motion[(x / 8) + 2].x = mv.x; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
361 motion[(x / 8) + 2].y = mv.y; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
362 motion[(x / 8) + 3].x = mv.x; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
363 motion[(x / 8) + 3].y = mv.y; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
364 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
365 src = &previous[(x + (mv.x >> 1)) + (y + (mv.y >> 1))*pitch]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
366 dst = current; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
367 |
6510 | 368 #ifdef USE_LIBAVCODEC |
369 put_pixels_tab[((mv.y & 1) << 1) | (mv.x & 1)](dst,src,pitch,16); | |
370 put_pixels_tab[((mv.y & 1) << 1) | (mv.x & 1)](dst+8,src+8,pitch,16); | |
371 #else | |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
372 /* form prediction */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
373 if (mv.y & 0x1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
374 if (mv.x & 0x1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
375 for (sy=0; sy < 16; sy++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
376 for (sx=0; sx < 16; sx++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
377 dst[sx] = (src[sx] + src[sx + 1] + src[sx + pitch] + src[sx + pitch + 1] + 2) >> 2; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
378 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
379 src += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
380 dst += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
381 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
382 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
383 for (sy=0; sy < 16; sy++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
384 for (sx=0; sx < 16; sx++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
385 dst[sx] = (src[sx] + src[sx + pitch] + 1) >> 1; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
386 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
387 src += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
388 dst += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
389 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
390 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
391 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
392 if (mv.x & 0x1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
393 for (sy=0; sy < 16; sy++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
394 for (sx=0; sx < 16; sx++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
395 dst[sx] = (src[sx] + src[sx + 1] + 1) >> 1; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
396 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
397 src += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
398 dst += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
399 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
400 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
401 for (sy=0; sy < 16; sy++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
402 memcpy (dst, src, 16); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
403 src += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
404 dst += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
405 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
406 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
407 } |
6510 | 408 #endif |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
409 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
410 return 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
411 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
412 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
413 static int motion_inter_4v_block (bit_buffer_t *bitbuf, |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
414 uint8_t *current, uint8_t *previous, int pitch, |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
415 svq1_pmv_t *motion,int x, int y) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
416 uint8_t *src; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
417 uint8_t *dst; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
418 svq1_pmv_t mv; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
419 svq1_pmv_t *pmv[4]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
420 int sx, sy; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
421 int i, result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
422 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
423 /* predict and decode motion vector (0) */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
424 pmv[0] = &motion[0]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
425 pmv[1] = &motion[(x / 8) + 2]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
426 pmv[2] = &motion[(x / 8) + 4]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
427 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
428 if (y == 0) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
429 pmv[1] = pmv[0]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
430 pmv[2] = pmv[0]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
431 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
432 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
433 result = decode_motion_vector (bitbuf, &mv, pmv); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
434 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
435 if (result != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
436 return result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
437 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
438 /* predict and decode motion vector (1) */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
439 pmv[0] = &mv; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
440 pmv[1] = &motion[(x / 8) + 3]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
441 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
442 if (y == 0) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
443 pmv[1] = pmv[0]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
444 pmv[2] = pmv[0]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
445 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
446 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
447 result = decode_motion_vector (bitbuf, &motion[0], pmv); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
448 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
449 if (result != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
450 return result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
451 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
452 /* predict and decode motion vector (2) */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
453 pmv[1] = &motion[0]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
454 pmv[2] = &motion[(x / 8) + 1]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
455 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
456 result = decode_motion_vector (bitbuf, &motion[(x / 8) + 2], pmv); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
457 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
458 if (result != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
459 return result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
460 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
461 /* predict and decode motion vector (3) */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
462 pmv[2] = &motion[(x / 8) + 2]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
463 pmv[3] = &motion[(x / 8) + 3]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
464 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
465 result = decode_motion_vector (bitbuf, pmv[3], pmv); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
466 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
467 if (result != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
468 return result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
469 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
470 /* form predictions */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
471 for (i=0; i < 4; i++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
472 src = &previous[(x + (pmv[i]->x >> 1)) + (y + (pmv[i]->y >> 1))*pitch]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
473 dst = current; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
474 |
6510 | 475 #ifdef USE_LIBAVCODEC |
476 put_pixels_tab[((pmv[i]->y & 1) << 1) | (pmv[i]->x & 1)](dst,src,pitch,8); | |
477 #else | |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
478 if (pmv[i]->y & 0x1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
479 if (pmv[i]->x & 0x1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
480 for (sy=0; sy < 8; sy++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
481 for (sx=0; sx < 8; sx++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
482 dst[sx] = (src[sx] + src[sx + 1] + src[sx + pitch] + src[sx + pitch + 1] + 2) >> 2; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
483 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
484 src += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
485 dst += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
486 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
487 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
488 for (sy=0; sy < 8; sy++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
489 for (sx=0; sx < 8; sx++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
490 dst[sx] = (src[sx] + src[sx + pitch] + 1) >> 1; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
491 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
492 src += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
493 dst += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
494 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
495 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
496 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
497 if (pmv[i]->x & 0x1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
498 for (sy=0; sy < 8; sy++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
499 for (sx=0; sx < 8; sx++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
500 dst[sx] = (src[sx] + src[sx + 1] + 1) >> 1; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
501 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
502 src += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
503 dst += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
504 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
505 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
506 for (sy=0; sy < 8; sy++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
507 memcpy (dst, src, 8); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
508 src += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
509 dst += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
510 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
511 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
512 } |
6510 | 513 #endif |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
514 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
515 /* select next block */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
516 if (i & 1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
517 current += 8*(pitch - 1); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
518 previous += 8*(pitch - 1); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
519 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
520 current += 8; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
521 previous += 8; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
522 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
523 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
524 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
525 return 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
526 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
527 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
528 static int decode_delta_block (bit_buffer_t *bitbuf, |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
529 uint8_t *current, uint8_t *previous, int pitch, |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
530 svq1_pmv_t *motion, int x, int y) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
531 uint32_t bit_cache; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
532 uint32_t block_type; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
533 int result = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
534 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
535 /* get block type */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
536 bit_cache = get_bit_cache (bitbuf); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
537 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
538 bit_cache >>= (32 - 3); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
539 block_type = block_type_table[bit_cache].value; |
6511
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
540 skip_bits(bitbuf,block_type_table[bit_cache].length); |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
541 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
542 /* reset motion vectors */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
543 if (block_type == SVQ1_BLOCK_SKIP || block_type == SVQ1_BLOCK_INTRA) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
544 motion[0].x = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
545 motion[0].y = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
546 motion[(x / 8) + 2].x = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
547 motion[(x / 8) + 2].y = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
548 motion[(x / 8) + 3].x = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
549 motion[(x / 8) + 3].y = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
550 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
551 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
552 switch (block_type) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
553 case SVQ1_BLOCK_SKIP: |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
554 skip_block (current, previous, pitch, x, y); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
555 break; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
556 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
557 case SVQ1_BLOCK_INTER: |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
558 result = motion_inter_block (bitbuf, current, previous, pitch, motion, x, y); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
559 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
560 if (result != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
561 break; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
562 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
563 result = decode_svq1_block (bitbuf, current, pitch, 0); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
564 break; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
565 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
566 case SVQ1_BLOCK_INTER_4V: |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
567 result = motion_inter_4v_block (bitbuf, current, previous, pitch, motion, x, y); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
568 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
569 if (result != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
570 break; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
571 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
572 result = decode_svq1_block (bitbuf, current, pitch, 0); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
573 break; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
574 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
575 case SVQ1_BLOCK_INTRA: |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
576 result = decode_svq1_block (bitbuf, current, pitch, 1); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
577 break; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
578 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
579 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
580 return result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
581 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
582 |
6511
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
583 /* standard video sizes */ |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
584 static struct { int width; int height; } frame_size_table[8] = { |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
585 { 160, 120 }, { 128, 96 }, { 176, 144 }, { 352, 288 }, |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
586 { 704, 576 }, { 240, 180 }, { 320, 240 }, { -1, -1 } |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
587 }; |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
588 |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
589 static int decode_frame_header (bit_buffer_t *bitbuf, svq1_t *svq1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
590 int frame_size_code; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
591 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
592 /* unknown field */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
593 get_bits (bitbuf, 8); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
594 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
595 /* frame type */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
596 svq1->frame_type = get_bits (bitbuf, 2); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
597 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
598 if (svq1->frame_type == 3) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
599 return -1; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
600 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
601 if (svq1->frame_type == SVQ1_FRAME_INTRA) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
602 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
603 /* unknown fields */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
604 if (svq1->frame_code == 0x50 || svq1->frame_code == 0x60) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
605 get_bits (bitbuf, 16); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
606 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
607 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
608 if ((svq1->frame_code ^ 0x10) >= 0x50) { |
6511
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
609 skip_bits(bitbuf,8*get_bits (bitbuf, 8)); |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
610 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
611 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
612 get_bits (bitbuf, 2); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
613 get_bits (bitbuf, 2); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
614 get_bits (bitbuf, 1); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
615 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
616 /* load frame size */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
617 frame_size_code = get_bits (bitbuf, 3); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
618 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
619 if (frame_size_code == 7) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
620 /* load width, height (12 bits each) */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
621 svq1->frame_width = get_bits (bitbuf, 12); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
622 svq1->frame_height = get_bits (bitbuf, 12); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
623 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
624 if (!svq1->frame_width || !svq1->frame_height) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
625 return -1; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
626 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
627 /* get width, height from table */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
628 svq1->frame_width = frame_size_table[frame_size_code].width; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
629 svq1->frame_height = frame_size_table[frame_size_code].height; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
630 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
631 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
632 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
633 /* unknown fields */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
634 if (get_bits (bitbuf, 1) == 1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
635 get_bits (bitbuf, 1); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
636 get_bits (bitbuf, 1); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
637 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
638 if (get_bits (bitbuf, 2) != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
639 return -1; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
640 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
641 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
642 if (get_bits (bitbuf, 1) == 1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
643 get_bits (bitbuf, 1); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
644 get_bits (bitbuf, 4); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
645 get_bits (bitbuf, 1); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
646 get_bits (bitbuf, 2); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
647 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
648 while (get_bits (bitbuf, 1) == 1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
649 get_bits (bitbuf, 8); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
650 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
651 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
652 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
653 return 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
654 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
655 |
6511
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
656 int svq1_decode_frame (svq1_t *svq1, uint8_t *buffer,int buffer_len) { |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
657 bit_buffer_t bitbuf; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
658 uint8_t *current, *previous; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
659 int result, i, x, y, width, height; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
660 int luma_size, chroma_size; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
661 |
6511
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
662 // memcpy(temp_buf,buffer,buffer_len); buffer=temp_buf; |
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
663 |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
664 /* initialize bit buffer */ |
6511
a2086150099b
use libavcodec's get_bits() code (optional, disabled by default)
arpi
parents:
6510
diff
changeset
|
665 init_get_bits(&bitbuf,buffer,buffer_len); |
6505
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
666 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
667 /* decode frame header */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
668 svq1->frame_code = get_bits (&bitbuf, 22); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
669 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
670 if ((svq1->frame_code & ~0x70) || !(svq1->frame_code & 0x60)) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
671 return -1; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
672 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
673 /* swap some header bytes (why?) */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
674 if (svq1->frame_code != 0x20) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
675 uint32_t *src = (uint32_t *) (buffer + 4); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
676 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
677 for (i=0; i < 4; i++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
678 src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
679 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
680 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
681 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
682 result = decode_frame_header (&bitbuf, svq1); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
683 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
684 if (result != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
685 return result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
686 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
687 /* check frame size (changed?) */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
688 if (((svq1->frame_width + 3) & ~0x3) != svq1->width || |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
689 ((svq1->frame_height + 3) & ~0x3) != svq1->height) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
690 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
691 /* free current buffers */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
692 free (svq1->current); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
693 free (svq1->previous); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
694 free (svq1->motion); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
695 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
696 svq1->width = (svq1->frame_width + 3) & ~0x3; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
697 svq1->height = (svq1->frame_height + 3) & ~0x3; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
698 svq1->luma_width = (svq1->width + 15) & ~0xF; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
699 svq1->luma_height = (svq1->height + 15) & ~0xF; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
700 svq1->chroma_width = ((svq1->width / 4) + 15) & ~0xF; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
701 svq1->chroma_height = ((svq1->height / 4) + 15) & ~0xF; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
702 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
703 /* allocate new pixel and motion buffers for updated frame size */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
704 luma_size = svq1->luma_width * svq1->luma_height; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
705 chroma_size = svq1->chroma_width * svq1->chroma_height; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
706 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
707 svq1->motion = (svq1_pmv_t *) malloc (((svq1->luma_width / 8) + 3) * sizeof(svq1_pmv_t)); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
708 svq1->current = (uint8_t *) malloc (luma_size + 2*chroma_size); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
709 svq1->previous = (uint8_t *) malloc (luma_size + 2*chroma_size); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
710 svq1->offsets[0] = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
711 svq1->offsets[1] = luma_size; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
712 svq1->offsets[2] = luma_size + chroma_size; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
713 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
714 for (i=0; i < 3; i++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
715 svq1->base[i] = svq1->current + svq1->offsets[i]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
716 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
717 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
718 svq1->reference_frame = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
719 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
720 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
721 /* delta frame requires reference frame */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
722 if (svq1->frame_type != SVQ1_FRAME_INTRA && !svq1->reference_frame) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
723 return -1; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
724 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
725 /* decode y, u and v components */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
726 for (i=0; i < 3; i++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
727 if (i == 0) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
728 width = svq1->luma_width; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
729 height = svq1->luma_height; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
730 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
731 width = svq1->chroma_width; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
732 height = svq1->chroma_height; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
733 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
734 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
735 current = svq1->current + svq1->offsets[i]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
736 previous = svq1->previous + svq1->offsets[i]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
737 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
738 if (svq1->frame_type == SVQ1_FRAME_INTRA) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
739 /* keyframe */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
740 for (y=0; y < height; y+=16) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
741 for (x=0; x < width; x+=16) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
742 result = decode_svq1_block (&bitbuf, ¤t[x], width, 1); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
743 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
744 if (result != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
745 return result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
746 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
747 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
748 current += 16*width; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
749 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
750 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
751 /* delta frame */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
752 memset (svq1->motion, 0, ((width / 8) + 3) * sizeof(svq1_pmv_t)); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
753 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
754 for (y=0; y < height; y+=16) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
755 for (x=0; x < width; x+=16) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
756 result = decode_delta_block (&bitbuf, ¤t[x], previous, |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
757 width, svq1->motion, x, y); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
758 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
759 if (result != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
760 return result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
761 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
762 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
763 svq1->motion[0].x = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
764 svq1->motion[0].y = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
765 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
766 current += 16*width; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
767 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
768 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
769 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
770 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
771 /* update pixel buffers for frame copy */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
772 for (i=0; i < 3; i++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
773 svq1->base[i] = svq1->current + svq1->offsets[i]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
774 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
775 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
776 /* update backward reference frame */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
777 if (svq1->frame_type != SVQ1_FRAME_DROPPABLE) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
778 uint8_t *tmp = svq1->previous; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
779 svq1->previous = svq1->current; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
780 svq1->current = tmp; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
781 svq1->reference_frame = 1; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
782 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
783 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
784 return 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
785 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
786 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
787 void svq1_free (svq1_t *svq1){ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
788 if (svq1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
789 free (svq1->current); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
790 free (svq1->previous); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
791 free (svq1->motion); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
792 free (svq1); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
793 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
794 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
795 |