Mercurial > mplayer.hg
annotate libmpcodecs/native/svq1.c @ 6505:e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
svq1_cb.h (was: svq1_codebooks.h)
TODO: use libavcodec's MC and bit parsing routines, maybe VLC too,
finally move the whole decoder to libavcodec
author | arpi |
---|---|
date | Sat, 22 Jun 2002 23:07:41 +0000 |
parents | |
children | 4f23a6c3cda4 |
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 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
28 #include "bswap.h" |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
29 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
30 /* variable length (bit) code */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
31 typedef struct vlc_code_s { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
32 int16_t value :10, |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
33 length :6; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
34 } vlc_code_t; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
35 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
36 #define VIDEOBUFSIZE 128 * 1024 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
37 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
38 #define MEDIAN(a,b,c) ((a < b != b >= c) ? b : ((a < c != c > b) ? c : a)) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
39 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
40 #include "svq1.h" |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
41 #include "svq1_cb.h" |
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 /* memory bit stream */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
44 typedef struct bit_buffer_s { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
45 uint8_t *buffer; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
46 uint32_t bitpos; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
47 } bit_buffer_t; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
48 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
49 /* standard video sizes */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
50 static struct { int width; int height; } frame_size_table[8] = { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
51 { 160, 120 }, { 128, 96 }, { 176, 144 }, { 352, 288 }, |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
52 { 704, 576 }, { 240, 180 }, { 320, 240 }, { -1, -1 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
53 }; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
54 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
55 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
56 static uint32_t get_bits (bit_buffer_t *bitbuf, int count) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
57 uint32_t result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
58 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
59 /* load 32 bits of data (byte-aligned) */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
60 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
|
61 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
62 /* compensate for sub-byte offset */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
63 result <<= (bitbuf->bitpos & 0x7); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
64 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
65 /* flush num bits */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
66 bitbuf->bitpos += count; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
67 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
68 /* return num bits */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
69 return result >> (32 - count); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
70 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
71 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
72 /* |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
73 * Return next 32 bits (left aligned). |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
74 */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
75 static uint32_t get_bit_cache(bit_buffer_t *bitbuf) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
76 uint32_t result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
77 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
78 /* load 32 bits of data (byte-aligned) */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
79 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
|
80 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
81 /* compensate for sub-byte offset */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
82 result <<= (bitbuf->bitpos & 0x7); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
83 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
84 return result; |
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 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
87 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
|
88 uint32_t bit_cache; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
89 vlc_code_t *vlc; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
90 uint8_t *list[63]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
91 uint32_t *dst; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
92 uint32_t *codebook; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
93 int entries[6]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
94 int i, j, m, n; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
95 int mean, stages; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
96 int x, y, width, height, level; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
97 uint32_t n1, n2, n3, n4; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
98 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
99 /* initialize list for breadth first processing of vectors */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
100 list[0] = pixels; |
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 /* recursively process vector */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
103 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
|
104 for (; level > 0; i++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
105 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
106 /* process next depth */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
107 if (i == m) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
108 m = n; |
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 if (--level == 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
111 break; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
112 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
113 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
114 /* divide block if next bit set */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
115 if (get_bits (bitbuf, 1) == 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
116 break; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
117 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
118 /* add child nodes */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
119 list[n++] = list[i]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
120 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
|
121 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
122 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
123 /* destination address and vector size */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
124 dst = (uint32_t *) list[i]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
125 width = 1 << ((4 + level) /2); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
126 height = 1 << ((3 + level) /2); |
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 /* 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
|
129 bit_cache = get_bit_cache (bitbuf); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
130 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
131 if (intra) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
132 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
|
133 else |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
134 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
|
135 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
136 /* flush bits */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
137 stages = vlc->value; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
138 bitbuf->bitpos += vlc->length; |
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 if (stages == -1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
141 if (intra) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
142 for (y=0; y < height; y++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
143 memset (&dst[y*(pitch / 4)], 0, width); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
144 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
145 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
146 continue; /* skip vector */ |
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 if ((stages > 0) && (level >= 4)) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
150 return -1; /* invalid vector */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
151 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
152 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
153 /* get mean value for vector */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
154 bit_cache = get_bit_cache (bitbuf); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
155 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
156 if (intra) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
157 if (bit_cache >= 0x25000000) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
158 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
|
159 else if (bit_cache >= 0x03400000) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
160 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
|
161 else if (bit_cache >= 0x00040000) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
162 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
|
163 else |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
164 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
|
165 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
166 if (bit_cache >= 0x0B000000) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
167 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
|
168 else if (bit_cache >= 0x01200000) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
169 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
|
170 else if (bit_cache >= 0x002E0000) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
171 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
|
172 else if (bit_cache >= 0x00094000) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
173 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
|
174 else if (bit_cache >= 0x00049000) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
175 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
|
176 else |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
177 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
|
178 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
179 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
180 /* flush bits */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
181 mean = vlc->value; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
182 bitbuf->bitpos += vlc->length; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
183 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
184 if (intra && stages == 0) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
185 for (y=0; y < height; y++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
186 memset (&dst[y*(pitch / 4)], mean, width); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
187 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
188 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
189 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
|
190 bit_cache = get_bits (bitbuf, 4*stages); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
191 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
192 /* calculate codebook entries for this vector */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
193 for (j=0; j < stages; j++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
194 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
|
195 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
196 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
197 mean -= (stages * 128); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
198 n4 = ((mean + (mean >> 31)) << 16) | (mean & 0xFFFF); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
199 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
200 for (y=0; y < height; y++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
201 for (x=0; x < (width / 4); x++, codebook++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
202 if (intra) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
203 n1 = n4; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
204 n2 = n4; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
205 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
206 n3 = dst[x]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
207 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
208 /* add mean value to vector */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
209 n1 = ((n3 & 0xFF00FF00) >> 8) + n4; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
210 n2 = (n3 & 0x00FF00FF) + n4; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
211 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
212 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
213 /* add codebook entries to vector */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
214 for (j=0; j < stages; j++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
215 n3 = codebook[entries[j]] ^ 0x80808080; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
216 n1 += ((n3 & 0xFF00FF00) >> 8); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
217 n2 += (n3 & 0x00FF00FF); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
218 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
219 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
220 /* clip to [0..255] */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
221 if (n1 & 0xFF00FF00) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
222 n3 = ((( n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
223 n1 += 0x7F007F00; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
224 n1 |= (((~n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
225 n1 &= (n3 & 0x00FF00FF); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
226 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
227 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
228 if (n2 & 0xFF00FF00) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
229 n3 = ((( n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
230 n2 += 0x7F007F00; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
231 n2 |= (((~n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
232 n2 &= (n3 & 0x00FF00FF); |
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 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
235 /* store result */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
236 dst[x] = (n1 << 8) | n2; |
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 dst += (pitch / 4); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
240 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
241 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
242 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
243 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
244 return 0; |
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 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
247 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
|
248 uint32_t bit_cache; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
249 vlc_code_t *vlc; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
250 int diff, sign; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
251 int i; |
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 for (i=0; i < 2; i++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
254 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
255 /* get motion code */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
256 bit_cache = get_bit_cache (bitbuf); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
257 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
258 if (!(bit_cache & 0xFFE00000)) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
259 return -1; /* invalid vlc code */ |
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 if (bit_cache & 0x80000000) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
262 diff = 0; |
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 /* flush bit */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
265 bitbuf->bitpos++; |
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 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
268 if (bit_cache >= 0x06000000) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
269 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
|
270 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
271 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
|
272 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
273 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
274 /* decode motion vector differential */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
275 sign = (int) (bit_cache << (vlc->length - 1)) >> 31; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
276 diff = (vlc->value ^ sign) - sign; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
277 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
278 /* flush bits */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
279 bitbuf->bitpos += vlc->length; |
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 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
282 /* 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
|
283 if (i == 1) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
284 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
|
285 else |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
286 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
|
287 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
288 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
289 return 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
290 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
291 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
292 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
|
293 uint8_t *src; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
294 uint8_t *dst; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
295 int i; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
296 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
297 src = &previous[x + y*pitch]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
298 dst = current; |
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 for (i=0; i < 16; i++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
301 memcpy (dst, src, 16); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
302 src += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
303 dst += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
304 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
305 } |
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 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
|
308 uint8_t *current, uint8_t *previous, int pitch, |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
309 svq1_pmv_t *motion, int x, int y) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
310 uint8_t *src; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
311 uint8_t *dst; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
312 svq1_pmv_t mv; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
313 svq1_pmv_t *pmv[3]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
314 int sx, sy; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
315 int result; |
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 /* predict and decode motion vector */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
318 pmv[0] = &motion[0]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
319 pmv[1] = &motion[(x / 8) + 2]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
320 pmv[2] = &motion[(x / 8) + 4]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
321 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
322 if (y == 0) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
323 pmv[1] = pmv[0]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
324 pmv[2] = pmv[0]; |
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 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
327 result = decode_motion_vector (bitbuf, &mv, pmv); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
328 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
329 if (result != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
330 return result; |
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 motion[0].x = mv.x; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
333 motion[0].y = mv.y; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
334 motion[(x / 8) + 2].x = mv.x; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
335 motion[(x / 8) + 2].y = mv.y; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
336 motion[(x / 8) + 3].x = mv.x; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
337 motion[(x / 8) + 3].y = mv.y; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
338 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
339 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
|
340 dst = current; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
341 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
342 /* form prediction */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
343 if (mv.y & 0x1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
344 if (mv.x & 0x1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
345 for (sy=0; sy < 16; sy++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
346 for (sx=0; sx < 16; sx++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
347 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
|
348 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
349 src += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
350 dst += pitch; |
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 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
353 for (sy=0; sy < 16; sy++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
354 for (sx=0; sx < 16; sx++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
355 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
|
356 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
357 src += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
358 dst += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
359 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
360 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
361 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
362 if (mv.x & 0x1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
363 for (sy=0; sy < 16; sy++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
364 for (sx=0; sx < 16; sx++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
365 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
|
366 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
367 src += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
368 dst += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
369 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
370 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
371 for (sy=0; sy < 16; sy++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
372 memcpy (dst, src, 16); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
373 src += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
374 dst += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
375 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
376 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
377 } |
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 return 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
380 } |
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 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
|
383 uint8_t *current, uint8_t *previous, int pitch, |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
384 svq1_pmv_t *motion,int x, int y) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
385 uint8_t *src; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
386 uint8_t *dst; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
387 svq1_pmv_t mv; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
388 svq1_pmv_t *pmv[4]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
389 int sx, sy; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
390 int i, result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
391 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
392 /* predict and decode motion vector (0) */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
393 pmv[0] = &motion[0]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
394 pmv[1] = &motion[(x / 8) + 2]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
395 pmv[2] = &motion[(x / 8) + 4]; |
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 if (y == 0) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
398 pmv[1] = pmv[0]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
399 pmv[2] = pmv[0]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
400 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
401 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
402 result = decode_motion_vector (bitbuf, &mv, pmv); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
403 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
404 if (result != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
405 return result; |
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 /* predict and decode motion vector (1) */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
408 pmv[0] = &mv; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
409 pmv[1] = &motion[(x / 8) + 3]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
410 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
411 if (y == 0) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
412 pmv[1] = pmv[0]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
413 pmv[2] = pmv[0]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
414 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
415 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
416 result = decode_motion_vector (bitbuf, &motion[0], pmv); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
417 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
418 if (result != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
419 return result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
420 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
421 /* predict and decode motion vector (2) */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
422 pmv[1] = &motion[0]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
423 pmv[2] = &motion[(x / 8) + 1]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
424 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
425 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
|
426 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
427 if (result != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
428 return result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
429 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
430 /* predict and decode motion vector (3) */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
431 pmv[2] = &motion[(x / 8) + 2]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
432 pmv[3] = &motion[(x / 8) + 3]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
433 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
434 result = decode_motion_vector (bitbuf, pmv[3], pmv); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
435 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
436 if (result != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
437 return result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
438 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
439 /* form predictions */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
440 for (i=0; i < 4; i++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
441 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
|
442 dst = current; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
443 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
444 if (pmv[i]->y & 0x1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
445 if (pmv[i]->x & 0x1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
446 for (sy=0; sy < 8; sy++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
447 for (sx=0; sx < 8; sx++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
448 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
|
449 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
450 src += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
451 dst += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
452 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
453 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
454 for (sy=0; sy < 8; sy++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
455 for (sx=0; sx < 8; sx++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
456 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
|
457 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
458 src += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
459 dst += pitch; |
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 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
462 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
463 if (pmv[i]->x & 0x1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
464 for (sy=0; sy < 8; sy++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
465 for (sx=0; sx < 8; sx++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
466 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
|
467 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
468 src += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
469 dst += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
470 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
471 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
472 for (sy=0; sy < 8; sy++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
473 memcpy (dst, src, 8); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
474 src += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
475 dst += pitch; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
476 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
477 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
478 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
479 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
480 /* select next block */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
481 if (i & 1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
482 current += 8*(pitch - 1); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
483 previous += 8*(pitch - 1); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
484 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
485 current += 8; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
486 previous += 8; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
487 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
488 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
489 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
490 return 0; |
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 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
493 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
|
494 uint8_t *current, uint8_t *previous, int pitch, |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
495 svq1_pmv_t *motion, int x, int y) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
496 uint32_t bit_cache; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
497 uint32_t block_type; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
498 int result = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
499 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
500 /* get block type */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
501 bit_cache = get_bit_cache (bitbuf); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
502 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
503 bit_cache >>= (32 - 3); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
504 block_type = block_type_table[bit_cache].value; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
505 bitbuf->bitpos += block_type_table[bit_cache].length; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
506 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
507 /* reset motion vectors */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
508 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
|
509 motion[0].x = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
510 motion[0].y = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
511 motion[(x / 8) + 2].x = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
512 motion[(x / 8) + 2].y = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
513 motion[(x / 8) + 3].x = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
514 motion[(x / 8) + 3].y = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
515 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
516 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
517 switch (block_type) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
518 case SVQ1_BLOCK_SKIP: |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
519 skip_block (current, previous, pitch, x, y); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
520 break; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
521 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
522 case SVQ1_BLOCK_INTER: |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
523 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
|
524 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
525 if (result != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
526 break; |
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 result = decode_svq1_block (bitbuf, current, pitch, 0); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
529 break; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
530 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
531 case SVQ1_BLOCK_INTER_4V: |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
532 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
|
533 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
534 if (result != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
535 break; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
536 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
537 result = decode_svq1_block (bitbuf, current, pitch, 0); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
538 break; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
539 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
540 case SVQ1_BLOCK_INTRA: |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
541 result = decode_svq1_block (bitbuf, current, pitch, 1); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
542 break; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
543 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
544 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
545 return result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
546 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
547 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
548 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
|
549 int frame_size_code; |
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 /* unknown field */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
552 get_bits (bitbuf, 8); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
553 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
554 /* frame type */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
555 svq1->frame_type = get_bits (bitbuf, 2); |
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 if (svq1->frame_type == 3) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
558 return -1; |
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 (svq1->frame_type == SVQ1_FRAME_INTRA) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
561 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
562 /* unknown fields */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
563 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
|
564 get_bits (bitbuf, 16); |
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 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
567 if ((svq1->frame_code ^ 0x10) >= 0x50) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
568 bitbuf->bitpos += 8*get_bits (bitbuf, 8); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
569 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
570 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
571 get_bits (bitbuf, 2); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
572 get_bits (bitbuf, 2); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
573 get_bits (bitbuf, 1); |
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 /* load frame size */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
576 frame_size_code = get_bits (bitbuf, 3); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
577 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
578 if (frame_size_code == 7) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
579 /* load width, height (12 bits each) */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
580 svq1->frame_width = get_bits (bitbuf, 12); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
581 svq1->frame_height = get_bits (bitbuf, 12); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
582 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
583 if (!svq1->frame_width || !svq1->frame_height) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
584 return -1; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
585 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
586 /* get width, height from table */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
587 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
|
588 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
|
589 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
590 } |
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 fields */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
593 if (get_bits (bitbuf, 1) == 1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
594 get_bits (bitbuf, 1); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
595 get_bits (bitbuf, 1); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
596 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
597 if (get_bits (bitbuf, 2) != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
598 return -1; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
599 } |
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 (get_bits (bitbuf, 1) == 1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
602 get_bits (bitbuf, 1); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
603 get_bits (bitbuf, 4); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
604 get_bits (bitbuf, 1); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
605 get_bits (bitbuf, 2); |
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 while (get_bits (bitbuf, 1) == 1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
608 get_bits (bitbuf, 8); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
609 } |
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 return 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
613 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
614 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
615 int svq1_decode_frame (svq1_t *svq1, uint8_t *buffer) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
616 bit_buffer_t bitbuf; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
617 uint8_t *current, *previous; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
618 int result, i, x, y, width, height; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
619 int luma_size, chroma_size; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
620 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
621 /* initialize bit buffer */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
622 bitbuf.buffer = buffer; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
623 bitbuf.bitpos = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
624 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
625 /* decode frame header */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
626 svq1->frame_code = get_bits (&bitbuf, 22); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
627 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
628 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
|
629 return -1; |
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 /* swap some header bytes (why?) */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
632 if (svq1->frame_code != 0x20) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
633 uint32_t *src = (uint32_t *) (buffer + 4); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
634 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
635 for (i=0; i < 4; i++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
636 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
|
637 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
638 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
639 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
640 result = decode_frame_header (&bitbuf, svq1); |
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 (result != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
643 return result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
644 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
645 /* check frame size (changed?) */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
646 if (((svq1->frame_width + 3) & ~0x3) != svq1->width || |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
647 ((svq1->frame_height + 3) & ~0x3) != svq1->height) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
648 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
649 /* free current buffers */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
650 free (svq1->current); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
651 free (svq1->previous); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
652 free (svq1->motion); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
653 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
654 svq1->width = (svq1->frame_width + 3) & ~0x3; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
655 svq1->height = (svq1->frame_height + 3) & ~0x3; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
656 svq1->luma_width = (svq1->width + 15) & ~0xF; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
657 svq1->luma_height = (svq1->height + 15) & ~0xF; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
658 svq1->chroma_width = ((svq1->width / 4) + 15) & ~0xF; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
659 svq1->chroma_height = ((svq1->height / 4) + 15) & ~0xF; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
660 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
661 /* 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
|
662 luma_size = svq1->luma_width * svq1->luma_height; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
663 chroma_size = svq1->chroma_width * svq1->chroma_height; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
664 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
665 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
|
666 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
|
667 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
|
668 svq1->offsets[0] = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
669 svq1->offsets[1] = luma_size; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
670 svq1->offsets[2] = luma_size + chroma_size; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
671 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
672 for (i=0; i < 3; i++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
673 svq1->base[i] = svq1->current + svq1->offsets[i]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
674 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
675 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
676 svq1->reference_frame = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
677 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
678 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
679 /* delta frame requires reference frame */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
680 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
|
681 return -1; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
682 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
683 /* decode y, u and v components */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
684 for (i=0; i < 3; i++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
685 if (i == 0) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
686 width = svq1->luma_width; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
687 height = svq1->luma_height; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
688 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
689 width = svq1->chroma_width; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
690 height = svq1->chroma_height; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
691 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
692 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
693 current = svq1->current + svq1->offsets[i]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
694 previous = svq1->previous + svq1->offsets[i]; |
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 if (svq1->frame_type == SVQ1_FRAME_INTRA) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
697 /* keyframe */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
698 for (y=0; y < height; y+=16) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
699 for (x=0; x < width; x+=16) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
700 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
|
701 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
702 if (result != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
703 return result; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
704 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
705 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
706 current += 16*width; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
707 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
708 } else { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
709 /* delta frame */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
710 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
|
711 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
712 for (y=0; y < height; y+=16) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
713 for (x=0; x < width; x+=16) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
714 result = decode_delta_block (&bitbuf, ¤t[x], previous, |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
715 width, svq1->motion, x, y); |
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 if (result != 0) |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
718 return result; |
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 svq1->motion[0].x = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
722 svq1->motion[0].y = 0; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
723 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
724 current += 16*width; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
725 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
726 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
727 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
728 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
729 /* update pixel buffers for frame copy */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
730 for (i=0; i < 3; i++) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
731 svq1->base[i] = svq1->current + svq1->offsets[i]; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
732 } |
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 /* update backward reference frame */ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
735 if (svq1->frame_type != SVQ1_FRAME_DROPPABLE) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
736 uint8_t *tmp = svq1->previous; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
737 svq1->previous = svq1->current; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
738 svq1->current = tmp; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
739 svq1->reference_frame = 1; |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
740 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
741 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
742 return 0; |
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 |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
745 void svq1_free (svq1_t *svq1){ |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
746 if (svq1) { |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
747 free (svq1->current); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
748 free (svq1->previous); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
749 free (svq1->motion); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
750 free (svq1); |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
751 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
752 } |
e3a166f8e81f
imported from xine, generalized, created header file, all tables moved to
arpi
parents:
diff
changeset
|
753 |