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